public void RestoreAddresses(ServerAsyncEventArgs e) { e.ConnectionId = connectionId; e.LocalEndPoint = localEndPoint; e.RemoteEndPoint = remoteEndPoint; localEndPoint = null; remoteEndPoint = null; }
public static ConnectionId Generate(ServerEndPoint reflexive, IPEndPoint local) { if (sha1 == null) sha1 = new HMACSHA1(sha1Key); string hashData = reflexive.ToString() + local.ToString() + Interlocked.Increment(ref count).ToString(); var bytes = sha1.ComputeHash(Encoding.UTF8.GetBytes(hashData)); return new ConnectionId() { Value1 = BitConverter.ToInt64(bytes, 0), Value2 = BitConverter.ToInt64(bytes, 8), Value3 = BitConverter.ToInt32(bytes, 16), }; }
public AppTermServerTransport(SyncBinding binding, ServerEndPoint serverEndpoint, IPAddress localAddr, int port) : base(binding, serverEndpoint, localAddr, port) { }
public RequestMsg ServerDispatchRequest(ServerEndPoint endpoint, RequestMsg request) { NFX.ApplicationModel.ExecutionContext.Application.Log.Write( new NFX.Log.Message{ Type=NFX.Log.MessageType.TraceA, From ="ServeInspector", Text="Received " + request.ServerTransport.StatBytesReceived.ToString() + " bytes"}); return request; }
/// <summary> /// Allocates a listener transport /// </summary> public SyncServerTransport(SyncBinding binding, ServerEndPoint serverEndpoint, IPAddress localAddr, int port) : base(binding, serverEndpoint) { Node = serverEndpoint.Node; m_IPAddress = localAddr; m_Port = port; }
protected internal override ServerTransport OpenServerEndpoint(ServerEndPoint epoint) { return new InProcServerTransport(this, epoint); }
private void SendTurn(TurnMessage message, ServerEndPoint local, IPEndPoint remote) { ServerAsyncEventArgs p; int offset; message.ComputeMessageLength(); GetBuffer(local, remote, message.TotalMessageLength, out p, out offset); message.GetBytes(p.Buffer, offset, Authentificater.Key2); turnServer.SendAsync(p); }
private string GetKey(ServerEndPoint local, IPEndPoint remote) { return(local.ToString() + @"|" + remote.ToString()); }
internal ServerInfoEventArgs(ServerEndPoint serverEndPoint, SocketException error) : base(serverEndPoint) { SocketError = error.SocketErrorCode; Exception = error; }
public PhotonServerPeer(InitRequest initRequest) : base(initRequest) { ServerEndPoint = new ServerEndPoint(new PhotonServerCommunicationInterface(this)); ServerEndPoint.LastConnectedIPAddress = RemoteIPAddress; EndPointFactory.Instance.EndPointConnect(ServerEndPoint); }
public PipeClient(ServerEndPoint endpoint, ILoggerFactory loggerFactory) { _endpoint = (NamedPipeEndPoint)endpoint.EndPoint; ServerEndPoint = endpoint; _loggerFactory = loggerFactory; }
public static bool IsTransportUnreliable(this ServerEndPoint endPoint) { return(endPoint.Protocol == ServerProtocol.Udp); }
public void StoreAddresses(Connection connection) { connectionId = connection.Id; localEndPoint = connection.LocalEndPoint; remoteEndPoint = connection.RemoteEndPoint; }
public ServerChangeEventArgs(ServerEndPoint serverEndPoint) { ServerEndPoint = serverEndPoint; }
public void UnregisterServerEndpoint(ServerEndPoint ep) { }
protected internal override void CloseServerEndpoint(ServerEndPoint epoint) { var t = epoint.Transport; if (t!=null) t.Dispose(); }
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, }, }); }
internal ServerInfoEventArgs(ServerEndPoint serverEndPoint, string api, string function, uint error) : base(serverEndPoint) { Error = Format(api, function, error); }
public Allocation Get(ServerEndPoint allocated) { Allocation allocation = null; lock (syncRoot) { if (byAllocated.TryGetValue(allocated, out allocation) == false) byReal.TryGetValue(allocated, out allocation); } return allocation != null && allocation.IsValid() ? allocation : null; }
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 Allocation GetByPeer(ServerEndPoint local, IPEndPoint remote) { Allocation allocation = null; lock (syncRoot) byKey.TryGetValue(GetKey(local, remote), out allocation); return allocation != null && allocation.IsValid() ? allocation : null; }
public ServerCallStub(ServerEndPoint endPoint) { Assert(endPoint != null); _endPoint = endPoint; }
private string GetKey(ServerEndPoint local, IPEndPoint remote) { return local.ToString() + @"|" + remote.ToString(); }
public InProcServerTransport(InProcBinding binding, ServerEndPoint serverEndpoint) : base(binding, serverEndpoint) { Node = serverEndpoint.Node; }
public serverImplementer(ServerHandler handler, ServerEndPoint sep, Type contract) { Handler = handler; ServerEndPoint = sep; Contract = contract; var implementers = sep.ContractServers.Where(ts => contract.IsAssignableFrom(ts)).ToArray(); if (implementers.Length==0) throw new ServerContractException(string.Format(StringConsts.GLUE_ENDPOINT_CONTRACT_NOT_IMPLEMENTED_ERROR, sep.Name, contract.FullName)); if (implementers.Length>1) { handler.WriteLog(LogSrc.Server, MessageType.Warning, string.Format(StringConsts.GLUE_ENDPOINT_CONTRACT_MANY_SERVERS_WARNING, contract.FullName, sep.Name), from: "serverImplementer"); } Implementation = implementers[0]; //pre-alloc Contract/Implementation method infos var intfMapping = Implementation.GetInterfaceMap(Contract); foreach(var miContract in Contract.GetMethods()) { var mspec = new MethodSpec(miContract); var miImpl = intfMapping.TargetMethods.FirstOrDefault( tmi => new MethodSpec(tmi).Equals( mspec )); if (miImpl==null) throw new ServerContractException(StringConsts.GLUE_ENDPOINT_CONTRACT_INTF_MAPPING_ERROR.Args( sep.Name, contract.FullName, miContract.Name, Implementation.FullName)); var fBody = getFBody(miContract); methodMap.Add(mspec, new mapping(miContract, miImpl, fBody));//todo DODELAT Functor! } var lifeCycle = Contract.GetCustomAttributes(typeof(LifeCycleAttribute), false).FirstOrDefault() as LifeCycleAttribute; if (lifeCycle!=null) { InstanceMode = lifeCycle.Mode; InstanceTimeoutMs = lifeCycle.TimeoutMs; } if (InstanceTimeoutMs==0) InstanceTimeoutMs = DEFAULT_INSTANCE_TIMEOUT_MS; ThreadSafe = Attribute.IsDefined(Implementation, typeof(ThreadSafeAttribute), false); AuthenticationSupport = Attribute.IsDefined(Contract, typeof(AuthenticationSupportAttribute), false); SupportsGlueCtor = Implementation.GetConstructor(ServerHandler.GLUE_CTOR_SIGNATURE) != null; }
public void UnregisterServerEndpoint(ServerEndPoint ep) { m_Servers.Unregister(ep); }
private serverImplementer getServerImplementer(ServerEndPoint sep, Type contract) { serverImplementer server; if (sep.m_ContractImplementers.TryGetValue(contract, out server)) return server; server = new serverImplementer(this, sep, contract); //throws sep.m_ContractImplementers.TryAdd(contract, server); return server; }
public ResponseMsg ServerReturnResponse(ServerEndPoint endpoint, RequestMsg request, ResponseMsg response) { response.Headers.Add( new TextInfoHeader{ Text="Response generated at " + App.LocalizedTime.ToString(), Info = "Serve Node: " + endpoint.Node } ); return response; }
public void RegisterServerEndpoint(ServerEndPoint ep) { if (!m_Servers.Register(ep)) throw new GlueException(StringConsts.GLUE_DUPLICATE_NAMED_INSTANCE_ERROR + "ServerEndPoint = " + ep.Name); }
public SingleBlockEnumerable(RedisBase redis, ServerEndPoint server, Task <T[]> pending, int pageOffset) : base(redis, server, 0, int.MaxValue, 0, pageOffset, default) { _pending = pending; }
protected internal override ServerTransport OpenServerEndpoint(ServerEndPoint epoint) { var cfg = ConfigNode.NavigateSection(CONFIG_SERVER_TRANSPORT_SECTION); if (!cfg.Exists) cfg = ConfigNode; var ipep = MpxBinding.ToIPEndPoint(epoint.Node); var transport = new MpxServerTransport(this, epoint, ipep.Address, ipep.Port); transport.Configure(cfg); transport.Start(); return transport; }
public SocketClient(ServerEndPoint specifiedEndPoint, ILoggerFactory loggerFactory) { ServerEndPoint = specifiedEndPoint; _loggerFactory = loggerFactory; }
internal ServerInfoEventArgs(ServerEndPoint serverEndPoint, Exception error) : base(serverEndPoint) { Exception = error; }
protected internal override ServerTransport OpenServerEndpoint(ServerEndPoint epoint) { return(new InProcServerTransport(this, epoint)); }
internal ServerInfoEventArgs(ServerEndPoint serverEndPoint, string error) : base(serverEndPoint) { Error = error; }
private void GetBuffer(ServerEndPoint local, IPEndPoint remote, int length, out ServerAsyncEventArgs e, out int offset) { int headerLength = (local.Protocol == ServerProtocol.Tcp) ? TcpFramingHeader.TcpFramingHeaderLength : 0; e = EventArgsManager.Get(); e.ConnectionId = ServerAsyncEventArgs.AnyConnectionId; e.LocalEndPoint = local; e.RemoteEndPoint = remote; e.Count = headerLength + length; e.AllocateBuffer(); if (headerLength > 0) TcpFramingHeader.GetBytes(e.Buffer, e.Offset, TcpFrameType.ControlMessage, length); offset = e.Offset + headerLength; }
internal ServerInfoEventArgs(ServerEndPoint serverEndPoint, SocketError error) : base(serverEndPoint) { SocketError = error; }