private async Task DiscoveryNatTypeImpl(CancellationToken token) { var server = new StunServer(); if (!server.Parse(_config.StunServer)) { throw new Exception(@"Wrong STUN Server!"); } using var proxy = ProxyFactory.CreateProxy( _config.ProxyType, Result5389.LocalEndPoint, NetUtils.ParseEndpoint(_config.ProxyServer), _config.ProxyUser, _config.ProxyPassword ); using var client = new StunClient5389UDP(server.Hostname, server.Port, Result5389.LocalEndPoint, proxy); Result5389 = client.Status; await client.QueryAsync(); var cache = new StunResult5389(); cache.Clone(client.Status); cache.LocalEndPoint = client.LocalEndPoint; Result5389 = cache; }
public RFC5780ViewModel() { Result5389 = new StunResult5389 { LocalEndPoint = new IPEndPoint(IPAddress.Any, 0) }; DiscoveryNatType = ReactiveCommand.CreateFromTask(DiscoveryNatTypeImpl); }
public RFC5780ViewModel(IScreen hostScreen, Config config) { HostScreen = hostScreen; _config = config; Result5389 = new StunResult5389 { LocalEndPoint = new IPEndPoint(IPAddress.Any, 0) }; DiscoveryNatType = ReactiveCommand.CreateFromTask(DiscoveryNatTypeImpl); }
private static string GetSimpleResult(StunResult5389 res) { switch (res.BindingTestResult, res.MappingBehavior, res.FilteringBehavior) {
public async Task <StunResult5389> QueryAsync() { var result = new StunResult5389(); try { _bindingSubj.OnNext(result.BindingTestResult); _mappingBehaviorSubj.OnNext(result.MappingBehavior); _filteringBehaviorSubj.OnNext(result.FilteringBehavior); PubSubj.OnNext(result.PublicEndPoint); using var cts = new CancellationTokenSource(Timeout); await Proxy.ConnectAsync(cts.Token); result = await FilteringBehaviorTestBaseAsync(cts.Token); if (result.BindingTestResult != BindingTestResult.Success || result.FilteringBehavior == FilteringBehavior.UnsupportedServer ) { return(result); } if (Equals(result.PublicEndPoint, result.LocalEndPoint)) { result.MappingBehavior = MappingBehavior.Direct; return(result); } // MappingBehaviorTest test II var result2 = await BindingTestBaseAsync(new IPEndPoint(result.OtherEndPoint.Address, RemoteEndPoint.Port), false, cts.Token); if (result2.BindingTestResult != BindingTestResult.Success) { result.MappingBehavior = MappingBehavior.Fail; return(result); } if (Equals(result2.PublicEndPoint, result.PublicEndPoint)) { result.MappingBehavior = MappingBehavior.EndpointIndependent; return(result); } // MappingBehaviorTest test III var result3 = await BindingTestBaseAsync(result.OtherEndPoint, false, cts.Token); if (result3.BindingTestResult != BindingTestResult.Success) { result.MappingBehavior = MappingBehavior.Fail; return(result); } result.MappingBehavior = Equals(result3.PublicEndPoint, result2.PublicEndPoint) ? MappingBehavior.AddressDependent : MappingBehavior.AddressAndPortDependent; return(result); } finally { _mappingBehaviorSubj.OnNext(result.MappingBehavior); await Proxy.DisconnectAsync(); } }
public async Task <StunResult5389> MappingBehaviorTestAsync() { var result = new StunResult5389(); try { await Proxy.ConnectAsync(); // test I result = await BindingTestBaseAsync(RemoteEndPoint, true); if (result.BindingTestResult != BindingTestResult.Success) { return(result); } if (result.OtherEndPoint == null || Equals(result.OtherEndPoint.Address, RemoteEndPoint.Address) || result.OtherEndPoint.Port == RemoteEndPoint.Port) { result.MappingBehavior = MappingBehavior.UnsupportedServer; return(result); } if (Equals(result.PublicEndPoint, result.LocalEndPoint)) { result.MappingBehavior = MappingBehavior.Direct; return(result); } // test II var result2 = await BindingTestBaseAsync(new IPEndPoint(result.OtherEndPoint.Address, RemoteEndPoint.Port), false); if (result2.BindingTestResult != BindingTestResult.Success) { result.MappingBehavior = MappingBehavior.Fail; return(result); } if (Equals(result2.PublicEndPoint, result.PublicEndPoint)) { result.MappingBehavior = MappingBehavior.EndpointIndependent; return(result); } // test III var result3 = await BindingTestBaseAsync(result.OtherEndPoint, false); if (result3.BindingTestResult != BindingTestResult.Success) { result.MappingBehavior = MappingBehavior.Fail; return(result); } result.MappingBehavior = Equals(result3.PublicEndPoint, result2.PublicEndPoint) ? MappingBehavior.AddressDependent : MappingBehavior.AddressAndPortDependent; return(result); } finally { _mappingBehaviorSubj.OnNext(result.MappingBehavior); await Proxy.DisconnectAsync(); } }