exclude DNS over HTTPS protocol

This commit is contained in:
wanghongenpin
2025-06-06 01:53:58 +08:00
parent 6000d407dd
commit eee49f4abe
4 changed files with 37 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:proxypin/network/channel/host_port.dart';
import 'package:proxypin/network/util/process_info.dart';
class ProcessInfoPlugin {
@@ -14,7 +15,14 @@ class ProcessInfoPlugin {
os: Platform.operatingSystem,
icon: process['icon'],
remoteHost: process['remoteHost'],
remotePost: process['remotePost']);
remotePost: process['remotePort']);
});
}
static Future<HostAndPort?> getRemoteAddressByPort(int port) {
return _methodChannel.invokeMethod<Map>('getRemoteAddressByPort', {"port": port}).then((process) {
if (process == null) return null;
return HostAndPort.host(process['remoteHost'], process['remotePort']);
});
}
}

View File

@@ -18,6 +18,7 @@ import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:proxypin/native/process_info.dart';
import 'package:proxypin/network/bin/configuration.dart';
import 'package:proxypin/network/channel/channel.dart';
import 'package:proxypin/network/channel/channel_context.dart';
@@ -141,17 +142,24 @@ class Server extends Network {
var hostAndPort = channelContext.host;
try {
String? serviceName = TLS.getDomain(data) ?? hostAndPort?.host;
bool isHttp = true;
if (hostAndPort == null) {
var domain = serviceName;
var port = 443;
if (domain == null) {
var process = await ProcessInfoUtils.getProcessByPort(
channel.remoteSocketAddress, channel.remoteSocketAddress.toString());
domain = process?.remoteHost;
port = process?.remotePost ?? port;
var remote = await ProcessInfoPlugin.getRemoteAddressByPort(channel.remoteSocketAddress.port);
domain = remote?.host;
port = remote?.port ?? port;
serviceName = domain;
// DNS over HTTPS
if (remote?.port == 853 && TLS.supportProtocols(data)?.contains("http/1.1") == false) {
isHttp = false;
}
}
hostAndPort = HostAndPort.host(domain!, port, scheme: HostAndPort.httpsScheme);
}