public DirectConnectAsyncResult(int bufferSize, Uri uri, TimeSpan timeout, Binding innerBinding, AsyncCallback callback, object state) : base(callback, state)
            {
                this.bufferSize = bufferSize;
                ProbingClient probingClient = new ProbingClient(uri.Host, ConnectConstants.DefaultProbePorts);

                this.session        = new DirectConnectionSession(Guid.NewGuid(), probingClient, this);
                this.channelFactory = new DuplexChannelFactory <IDirectConnectionControl>(this.session, innerBinding, new EndpointAddress(uri, new AddressHeader[0]));
            }
        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 DirectConnectWaiter(int bufferSize, Uri uri, TimeSpan timeout, Binding innerBinding)
            {
                this.bufferSize = bufferSize;
                ProbingClient probingClient = new ProbingClient(uri.Host, ConnectConstants.DefaultProbePorts);

                this.session        = new DirectConnectionSession(Guid.NewGuid(), probingClient, this);
                this.channelFactory = new DuplexChannelFactory <IDirectConnectionControl>(this.session, innerBinding, new EndpointAddress(uri, new AddressHeader[0]));
                this.timeoutHelper  = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
                this.socketEvent    = new ManualResetEvent(false);
                this.mutex          = new object();
            }
        public DirectSocketListener(int bufferSize, Uri uri, Binding innerBinding)
        {
            this.bufferSize    = bufferSize;
            this.probingClient = new ProbingClient(uri.Host, ConnectConstants.DefaultProbePorts);
            Uri[] uriArray = new Uri[] { uri };
            this.serviceHost = new ConfigurationlessServiceHost(this, uriArray);
            ServiceErrorHandlerBehavior serviceErrorHandlerBehavior = new ServiceErrorHandlerBehavior();

            serviceErrorHandlerBehavior.HandleError += new EventHandler <ServiceErrorEventArgs>((object s, ServiceErrorEventArgs e) => Fx.Exception.TraceHandled(e.Exception, "DirectSocketListener.IErrorHandler.HandleError", null));
            this.serviceHost.Description.Behaviors.Add(serviceErrorHandlerBehavior);
            this.serviceHost.AddServiceEndpoint(typeof(IDirectConnectionControl), innerBinding, "");
            this.connectionSessions = new Dictionary <string, DirectConnectionSession>();
            this.socketQueue        = new InputQueue <Microsoft.ServiceBus.Channels.IConnection>();
            this.mutex    = new object();
            this.Activity = new EventTraceActivity();
        }
 public bool PredictNextExternalPort(DerivedEndpoint derivedEndpoint)
 {
     return(ProbingClient.PredictNextExternalPort(this.probeAddress, this.probePorts, derivedEndpoint));
 }
 public ProbingClient(string hostName, int[] probePorts)
 {
     this.probeAddress = ProbingClient.GetAddress(hostName, probePorts[0]);
     this.probePorts   = probePorts;
 }