private void ClientStartListening(DerivedEndpoint localDerivedEndpoint, List <IPEndPoint> localEndpoints) { bool flag = false; if (base.Session.ProbingClient.PredictNextExternalPort(localDerivedEndpoint)) { if (!base.Candidates.StartListening(ref localDerivedEndpoint.LocalEndpoint, "Listener.ClientLocalEndpoint", out this.localListener)) { return; } if (localDerivedEndpoint.ExternalEndpoint.Port == 0) { localDerivedEndpoint.ExternalEndpoint.Port = localDerivedEndpoint.LocalEndpoint.Port; } localEndpoints.Add(localDerivedEndpoint.LocalEndpoint); flag = true; } List <IPAddress> localAddresses = DirectConnectionSession.ConnectActivity.GetLocalAddresses(); for (int i = 0; i < localAddresses.Count; i++) { if (!flag || localAddresses[i].GetRawIPv4Address() != localDerivedEndpoint.LocalEndpoint.Address.GetRawIPv4Address()) { IPEndPoint pEndPoint = new IPEndPoint(localAddresses[i], 0); if (!base.Candidates.StartListening(ref pEndPoint, "Listener.ClientRealAddress")) { return; } localEndpoints.Add(pEndPoint); } } Thread.Sleep(200); }
private void ServerStartConnectingExternal(DerivedEndpoint localDerivedEndpoint, IPEndPoint remoteExternalEndpoint) { if (base.Session.ProbingClient.PredictNextExternalPort(localDerivedEndpoint)) { if (!base.Candidates.StartConnecting(ref localDerivedEndpoint.LocalEndpoint, remoteExternalEndpoint, "Connector.ClientExternalEndpoint")) { return; } base.Candidates.StartListening(ref localDerivedEndpoint.LocalEndpoint, "Listener.ServerLocalEndpoint"); if (localDerivedEndpoint.ExternalEndpoint.Port == 0) { localDerivedEndpoint.ExternalEndpoint.Port = localDerivedEndpoint.LocalEndpoint.Port; } } }
public static bool PredictNextExternalPort(IPEndPoint probeAddress, int[] probePorts, DerivedEndpoint derivedEndpoint) { bool flag; try { IPEndPoint pEndPoint = new IPEndPoint(IPAddress.Any, 0); IPEndPoint pEndPoint1 = new IPEndPoint(IPAddress.Any, 0); ProbingClient.SendProbeMessage(probeAddress, ProbeMessageType.GetServerAddress, ref pEndPoint, ref pEndPoint1); IPEndPoint pEndPoint2 = new IPEndPoint(pEndPoint1.Address, probePorts[0]); IPEndPoint pEndPoint3 = new IPEndPoint(pEndPoint1.Address, probePorts[1]); IPEndPoint pEndPoint4 = new IPEndPoint(IPAddress.Any, 0); IPEndPoint pEndPoint5 = new IPEndPoint(IPAddress.Any, 0); pEndPoint = new IPEndPoint(IPAddress.Any, 0); ProbingClient.SendProbeMessage(pEndPoint2, ProbeMessageType.GetClientAddress, ref pEndPoint, ref pEndPoint4); if (pEndPoint.Address.GetRawIPv4Address() == pEndPoint4.Address.GetRawIPv4Address()) { pEndPoint.Port = 0; } ProbingClient.SendProbeMessage(pEndPoint3, ProbeMessageType.GetClientAddress, ref pEndPoint, ref pEndPoint5); if (pEndPoint4.Address.GetRawIPv4Address() != pEndPoint5.Address.GetRawIPv4Address()) { flag = false; } else if (pEndPoint.Address.GetRawIPv4Address() != pEndPoint4.Address.GetRawIPv4Address()) { derivedEndpoint.LocalEndpoint = pEndPoint; derivedEndpoint.ExternalEndpoint = pEndPoint4; if (pEndPoint4.Port != pEndPoint5.Port) { int port = pEndPoint5.Port - pEndPoint4.Port; if (pEndPoint5.Port + port <= 65535) { derivedEndpoint.ExternalEndpoint.Port = pEndPoint5.Port + port; } else { flag = false; return(flag); } } flag = true; } else { pEndPoint.Port = 0; derivedEndpoint.LocalEndpoint = pEndPoint; derivedEndpoint.ExternalEndpoint = pEndPoint; flag = true; } } catch { flag = false; } return(flag); }
public bool PredictNextExternalPort(DerivedEndpoint derivedEndpoint) { return(ProbingClient.PredictNextExternalPort(this.probeAddress, this.probePorts, derivedEndpoint)); }
public ListenActivity(DirectConnectionSession session) : base(session) { this.localDerivedEndpoint = new DerivedEndpoint(); this.localEndpoints = new List <IPEndPoint>(); }
public ConnectActivity(DirectConnectionSession session) : base(session) { this.completeEvent = new ManualResetEvent(false); this.localDerivedEndpoint = new DerivedEndpoint(); this.localEndpoints = new List <IPEndPoint>(); }