|
@@ -38,6 +38,7 @@ public class RFC5780ViewModel : ViewModelBase, IRoutableViewModel
|
|
|
|
|
|
private StunResult5389 _udpResult;
|
|
|
private StunResult5389 _tcpResult;
|
|
|
+ private StunResult5389 _tlsResult;
|
|
|
|
|
|
private TransportType _transportType;
|
|
|
public TransportType TransportType
|
|
@@ -52,13 +53,14 @@ public class RFC5780ViewModel : ViewModelBase, IRoutableViewModel
|
|
|
{
|
|
|
_udpResult = new StunResult5389();
|
|
|
_tcpResult = new StunResult5389();
|
|
|
+ _tlsResult = new StunResult5389();
|
|
|
_result5389 = _udpResult;
|
|
|
DiscoveryNatType = ReactiveCommand.CreateFromTask(DiscoveryNatTypeAsync);
|
|
|
}
|
|
|
|
|
|
private async Task DiscoveryNatTypeAsync(CancellationToken token)
|
|
|
{
|
|
|
- Verify.Operation(StunServer.TryParse(Config.StunServer, out StunServer? server), @"Wrong STUN Server!");
|
|
|
+ Verify.Operation(StunServer.TryParse(Config.StunServer, out StunServer? server, TransportType is TransportType.Tls ? StunServer.DefaultTlsPort : StunServer.DefaultPort), @"Wrong STUN Server!");
|
|
|
|
|
|
if (!HostnameEndpoint.TryParse(Config.ProxyServer, out HostnameEndpoint? proxyIpe))
|
|
|
{
|
|
@@ -94,7 +96,8 @@ public class RFC5780ViewModel : ViewModelBase, IRoutableViewModel
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (TransportType is TransportType.Udp)
|
|
|
+ TransportType transport = TransportType;
|
|
|
+ if (transport is TransportType.Udp)
|
|
|
{
|
|
|
using IUdpProxy proxy = ProxyFactory.CreateProxy(Config.ProxyType, Result5389.LocalEndPoint, socks5Option);
|
|
|
using StunClient5389UDP client = new(new IPEndPoint(serverIp, server.Port), Result5389.LocalEndPoint, proxy);
|
|
@@ -124,28 +127,46 @@ public class RFC5780ViewModel : ViewModelBase, IRoutableViewModel
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- using ITcpProxy proxy = ProxyFactory.CreateProxy(Config.ProxyType, socks5Option);
|
|
|
+ using ITcpProxy proxy = ProxyFactory.CreateProxy(transport, Config.ProxyType, socks5Option, server.Hostname);
|
|
|
using IStunClient5389 client = new StunClient5389TCP(new IPEndPoint(serverIp, server.Port), Result5389.LocalEndPoint, proxy);
|
|
|
|
|
|
try
|
|
|
{
|
|
|
using (Observable.Interval(TimeSpan.FromSeconds(0.1))
|
|
|
.ObserveOn(RxApp.MainThreadScheduler)
|
|
|
- // ReSharper disable once AccessToDisposedClosure
|
|
|
- .Subscribe(_ => Result5389 = _tcpResult = client.State with { }))
|
|
|
+ .Subscribe(_ => UpdateData()))
|
|
|
{
|
|
|
await client.QueryAsync(token);
|
|
|
}
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
- Result5389 = _tcpResult = client.State with { };
|
|
|
+ UpdateData();
|
|
|
+ }
|
|
|
+
|
|
|
+ void UpdateData()
|
|
|
+ {
|
|
|
+ // ReSharper disable once AccessToDisposedClosure
|
|
|
+ Result5389 = client.State with { };
|
|
|
+ if (transport is TransportType.Tcp)
|
|
|
+ {
|
|
|
+ _tcpResult = Result5389;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _tlsResult = Result5389;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void ResetResult()
|
|
|
{
|
|
|
- Result5389 = TransportType is TransportType.Udp ? _udpResult : _tcpResult;
|
|
|
+ Result5389 = TransportType switch
|
|
|
+ {
|
|
|
+ TransportType.Tcp => _tcpResult,
|
|
|
+ TransportType.Tls => _tlsResult,
|
|
|
+ _ => _udpResult
|
|
|
+ };
|
|
|
}
|
|
|
}
|