private IEnumerable <EndpointInfo> GetEndpointInfos(ProtocolPort pp) { foreach (var address in NetworkAddresses) { yield return(new EndpointInfo(pp, address)); } }
private IEnumerable <ServersManager <C> .EndpointInfo> GetEndpointInfos(ProtocolPort pp) { foreach (UnicastIPAddressInformation current in this.NetworkAddresses) { yield return(new ServersManager <C> .EndpointInfo(pp, current)); } yield break; }
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)); } } }
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); } } }
//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); } }
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); }
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); }
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); } }
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, }, }; }
public EndpointInfo(ProtocolPort protocolPort, UnicastIPAddressInformation addressInformation) { this.ProtocolPort = protocolPort; this.AddressInformation = addressInformation; this.ServerEndPoint = new ServerEndPoint(this.ProtocolPort, this.AddressInformation.Address); }
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); }