예제 #1
0
 private IEnumerable <EndpointInfo> GetEndpointInfos(ProtocolPort pp)
 {
     foreach (var address in NetworkAddresses)
     {
         yield return(new EndpointInfo(pp, address));
     }
 }
예제 #2
0
 private IEnumerable <ServersManager <C> .EndpointInfo> GetEndpointInfos(ProtocolPort pp)
 {
     foreach (UnicastIPAddressInformation current in this.NetworkAddresses)
     {
         yield return(new ServersManager <C> .EndpointInfo(pp, current));
     }
     yield break;
 }
예제 #3
0
 public void Unbind(ProtocolPort pp)
 {
     lock (this.sync)
     {
         this.protocolPorts.Remove(pp);
         if (this.running)
         {
             this.servers.Remove((ServerEndPoint endpoint) => endpoint.Port == pp.Port && endpoint.Protocol == pp.Protocol, new Action <Server <C> >(this.OnServerRemoved));
         }
     }
 }
예제 #4
0
        public void Unbind(ProtocolPort pp)
        {
            lock (sync)
            {
                protocolPorts.Remove(pp);

                if (running)
                {
                    servers.Remove((endpoint) => { return(endpoint.Port == pp.Port && endpoint.Protocol == pp.Protocol); }, OnServerRemoved);
                }
            }
        }
예제 #5
0
        //public ILockFreePool<ServerAsyncEventArgs> BuffersPool
        //{
        //    get { return EventArgsManager.Pool; }
        //}

        public SocketError Bind(ProtocolPort pp)
        {
            lock (sync)
            {
                protocolPorts.Add(pp);

                if (running)
                {
                    return(AddServers(GetEndpointInfos(pp), false));
                }

                return(SocketError.Success);
            }
        }
예제 #6
0
        public SocketError Bind(ProtocolPort pp)
        {
            SocketError result;

            lock (this.sync)
            {
                this.protocolPorts.Add(pp);
                if (this.running)
                {
                    result = this.AddServers(this.GetEndpointInfos(pp), false);
                }
                else
                {
                    result = SocketError.Success;
                }
            }
            return(result);
        }
예제 #7
0
        public SocketError Bind(ref ProtocolPort pp)
        {
            SocketError result;

            lock (this.sync)
            {
                if (this.nextPort < 0)
                {
                    throw new InvalidOperationException("Port range was not assigned");
                }
                for (int i = 0; i < this.config.MaxPort - this.config.MinPort; i++)
                {
                    pp.Port = this.nextPort++;
                    SocketError socketError = this.AddServers(this.GetEndpointInfos(pp), false);
                    if (socketError != SocketError.AddressAlreadyInUse)
                    {
                        result = socketError;
                        return(result);
                    }
                }
                result = SocketError.TooManyOpenSockets;
            }
            return(result);
        }
예제 #8
0
        public SocketError Bind(ref ProtocolPort pp)
        {
            lock (sync)
            {
                if (nextPort < 0)
                {
                    throw new InvalidOperationException(@"Port range was not assigned");
                }

                for (int i = 0; i < config.MaxPort - config.MinPort; i++)
                {
                    pp.Port = nextPort++;

                    var result = AddServers(GetEndpointInfos(pp), false);

                    if (result != SocketError.AddressAlreadyInUse)
                    {
                        return(result);
                    }
                }

                return(SocketError.TooManyOpenSockets);
            }
        }
예제 #9
0
        private TurnMessage ProcessAllocateRequest(ref Allocation allocation, TurnMessage request, ServerEndPoint local, IPEndPoint remote)
        {
            uint sequenceNumber = (request.MsSequenceNumber != null) ? request.MsSequenceNumber.SequenceNumber : 0;

            {
                uint lifetime = (request.Lifetime != null) ? ((request.Lifetime.Value > MaxLifetime.Seconds) ? MaxLifetime.Seconds : request.Lifetime.Value) : DefaultLifetime.Seconds;

                if (allocation != null)
                {
                    allocation.Lifetime = lifetime;

                    if (lifetime == 0)
                        logger.WriteInformation(string.Format("Update Allocation: {2} seconds {0} <--> {1}", allocation.Alocated.ToString(), allocation.Reflexive.ToString(), lifetime));
                }
                else
                {
                    if (lifetime <= 0)
                        throw new TurnServerException(ErrorCode.NoBinding);

                    ProtocolPort pp = new ProtocolPort() { Protocol = local.Protocol, };
                    if (peerServer.Bind(ref pp) != SocketError.Success)
                        throw new TurnServerException(ErrorCode.ServerError);

                    allocation = new Allocation()
                    {
                        TransactionId = request.TransactionId,
                        ConnectionId = ConnectionIdGenerator.Generate(local, remote),

                        Local = local,
                        Alocated = new ServerEndPoint(pp, PublicIp),
                        Real = new ServerEndPoint(pp, RealIp),
                        Reflexive = new IPEndPoint(remote.Address, remote.Port),

                        Lifetime = lifetime,
                    };

                    allocations.Replace(allocation);

                    logger.WriteInformation(string.Format("Allocated: {0} <--> {1} for {2} seconds", allocation.Alocated.ToString(), allocation.Reflexive.ToString(), allocation.Lifetime));
                }
            }

            return new TurnMessage()
            {
                IsAttributePaddingDisabled = true,
                MessageType = MessageType.AllocateResponse,
                TransactionId = request.TransactionId,

                MagicCookie = new MagicCookie(),

                MappedAddress = new MappedAddress()
                {
                    IpAddress = allocation.Alocated.Address,
                    Port = (UInt16)allocation.Alocated.Port,
                },

                Lifetime = new Lifetime() { Value = allocation.Lifetime, },
                Bandwidth = new Bandwidth() { Value = 750, },

                XorMappedAddress = new XorMappedAddress(TurnMessageRfc.MsTurn)
                {
                    IpAddress = remote.Address,
                    Port = (UInt16)remote.Port,
                },

                Realm = new Realm(TurnMessageRfc.MsTurn)
                {
                    Ignore = true,
                    Value = Authentificater.Realm,
                },
                MsUsername = new MsUsername()
                {
                    Ignore = true,
                    Value = request.MsUsername.Value,
                },
                //MsUsername = allocation.Username,
                MessageIntegrity = new MessageIntegrity(),

                MsSequenceNumber = new MsSequenceNumber()
                {
                    ConnectionId = allocation.ConnectionId,
                    SequenceNumber = sequenceNumber,//allocation.SequenceNumber,
                },
            };
        }
예제 #10
0
 public EndpointInfo(ProtocolPort protocolPort, UnicastIPAddressInformation addressInformation)
 {
     this.ProtocolPort       = protocolPort;
     this.AddressInformation = addressInformation;
     this.ServerEndPoint     = new ServerEndPoint(this.ProtocolPort, this.AddressInformation.Address);
 }
예제 #11
0
 public ServerEndPoint(ProtocolPort protocolPort, IPAddress address)
     : base(address, protocolPort.Port)
 {
     Protocol = protocolPort.Protocol;
 }
			public EndpointInfo(ProtocolPort protocolPort, UnicastIPAddressInformation addressInformation)
			{
				ProtocolPort = protocolPort;
				AddressInformation = addressInformation;
				ServerEndPoint = new ServerEndPoint(ProtocolPort, AddressInformation.Address);
			}