示例#1
0
			public void RestoreAddresses(ServerAsyncEventArgs e)
			{
				e.ConnectionId = connectionId;
				e.LocalEndPoint = localEndPoint;
				e.RemoteEndPoint = remoteEndPoint;

				localEndPoint = null;
				remoteEndPoint = null;
			}
示例#2
0
        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)
 {
 }
示例#4
0
 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;
 }
示例#5
0
 /// <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;
 }
示例#6
0
 protected internal override ServerTransport OpenServerEndpoint(ServerEndPoint epoint)
 {
     return new InProcServerTransport(this, epoint);
 }
示例#7
0
        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);
        }
示例#8
0
 private string GetKey(ServerEndPoint local, IPEndPoint remote)
 {
     return(local.ToString() + @"|" + remote.ToString());
 }
示例#9
0
 internal ServerInfoEventArgs(ServerEndPoint serverEndPoint, SocketException error)
     : base(serverEndPoint)
 {
     SocketError = error.SocketErrorCode;
     Exception = error;
 }
示例#10
0
 public PhotonServerPeer(InitRequest initRequest) : base(initRequest)
 {
     ServerEndPoint = new ServerEndPoint(new PhotonServerCommunicationInterface(this));
     ServerEndPoint.LastConnectedIPAddress = RemoteIPAddress;
     EndPointFactory.Instance.EndPointConnect(ServerEndPoint);
 }
示例#11
0
 public PipeClient(ServerEndPoint endpoint, ILoggerFactory loggerFactory)
 {
     _endpoint      = (NamedPipeEndPoint)endpoint.EndPoint;
     ServerEndPoint = endpoint;
     _loggerFactory = loggerFactory;
 }
示例#12
0
 public static bool IsTransportUnreliable(this ServerEndPoint endPoint)
 {
     return(endPoint.Protocol == ServerProtocol.Udp);
 }
示例#13
0
			public void StoreAddresses(Connection connection)
			{
				connectionId = connection.Id;
				localEndPoint = connection.LocalEndPoint;
				remoteEndPoint = connection.RemoteEndPoint;
			}
示例#14
0
 public ServerChangeEventArgs(ServerEndPoint serverEndPoint)
 {
     ServerEndPoint = serverEndPoint;
 }
示例#15
0
文件: NOPGlue.cs 项目: vlapchenko/nfx
        public void UnregisterServerEndpoint(ServerEndPoint ep)
        {

        }
示例#16
0
 protected internal override void CloseServerEndpoint(ServerEndPoint epoint)
 {
   var t = epoint.Transport;
   if (t!=null) t.Dispose();
 }
示例#17
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,
                },
            });
        }
示例#18
0
 internal ServerInfoEventArgs(ServerEndPoint serverEndPoint, string api, string function, uint error)
     : base(serverEndPoint)
 {
     Error = Format(api, function, error);
 }
示例#19
0
        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;
        }
示例#20
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,
                },
            };
        }
示例#21
0
        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;
        }
示例#22
0
            public ServerCallStub(ServerEndPoint endPoint)
            {
                Assert(endPoint != null);

                _endPoint = endPoint;
            }
示例#23
0
 private string GetKey(ServerEndPoint local, IPEndPoint remote)
 {
     return local.ToString() + @"|" + remote.ToString();
 }
示例#24
0
 public InProcServerTransport(InProcBinding binding, ServerEndPoint serverEndpoint) : base(binding, serverEndpoint)
 {
     Node = serverEndpoint.Node;
 }
示例#25
0
            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;


            }
示例#26
0
 public void UnregisterServerEndpoint(ServerEndPoint ep)
 {
     m_Servers.Unregister(ep);
 }
示例#27
0
 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;
 }
示例#28
0
 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;
 }
示例#29
0
 public void RegisterServerEndpoint(ServerEndPoint ep)
 {
     if (!m_Servers.Register(ep))
         throw new GlueException(StringConsts.GLUE_DUPLICATE_NAMED_INSTANCE_ERROR +
             "ServerEndPoint = " + ep.Name);
 }
示例#30
0
 public SingleBlockEnumerable(RedisBase redis, ServerEndPoint server,
                              Task <T[]> pending, int pageOffset) : base(redis, server, 0, int.MaxValue, 0, pageOffset, default)
 {
     _pending = pending;
 }
示例#31
0
 public void UnregisterServerEndpoint(ServerEndPoint ep)
 {
     m_Servers.Unregister(ep);
 }
示例#32
0
          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;
          }
示例#33
0
 public SocketClient(ServerEndPoint specifiedEndPoint, ILoggerFactory loggerFactory)
 {
     ServerEndPoint = specifiedEndPoint;
     _loggerFactory = loggerFactory;
 }
示例#34
0
 internal ServerInfoEventArgs(ServerEndPoint serverEndPoint, Exception error)
     : base(serverEndPoint)
 {
     Exception = error;
 }
示例#35
0
 protected internal override ServerTransport OpenServerEndpoint(ServerEndPoint epoint)
 {
     return(new InProcServerTransport(this, epoint));
 }
示例#36
0
 internal ServerInfoEventArgs(ServerEndPoint serverEndPoint, string error)
     : base(serverEndPoint)
 {
     Error = error;
 }
示例#37
0
        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;
        }
示例#38
0
 internal ServerInfoEventArgs(ServerEndPoint serverEndPoint, SocketError error)
     : base(serverEndPoint)
 {
     SocketError = error;
 }
示例#39
0
 public void StoreAddresses(Connection connection)
 {
     connectionId   = connection.Id;
     localEndPoint  = connection.LocalEndPoint;
     remoteEndPoint = connection.RemoteEndPoint;
 }