Ejemplo n.º 1
0
        public UdpSession(UdpServer Server, Socket ServerSocket, IPEndPoint RemoteEndPoint, Func <ISessionContext, IBinaryTransformer, KeyValuePair <IServerImplementation, IStreamedVirtualTransportServer> > VirtualTransportServerFactory, Action <Action> QueueUserWorkItem)
        {
            this.Server              = Server;
            this.ServerSocket        = ServerSocket;
            this.RemoteEndPoint      = RemoteEndPoint;
            this.LastActiveTimeValue = new LockedVariable <DateTime>(DateTime.UtcNow);
            ssm = new SessionStateMachine <StreamedVirtualTransportServerHandleResult, Unit>(ex => ex is SocketException, OnCriticalError, OnShutdownRead, OnShutdownWrite, OnWrite, OnExecute, OnStartRawRead, OnExit, QueueUserWorkItem);

            Context                = Server.ServerContext.CreateSessionContext();
            Context.Quit          += ssm.NotifyExit;
            Context.Authenticated += () => Server.NotifySessionAuthenticated(this);

            var rpst = new Rc4PacketServerTransformer();
            var Pair = VirtualTransportServerFactory(Context, rpst);

            si  = Pair.Key;
            vts = Pair.Value;
            Context.SecureConnectionRequired += c =>
            {
                rpst.SetSecureContext(c);
                NextSecureContext = c;
            };
            vts.ServerEvent           += () => ssm.NotifyWrite(new Unit());
            vts.InputByteLengthReport += (CommandName, ByteLength) => Server.ServerContext.RaiseSessionLog(new SessionLogEntry {
                Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "InBytes", Name = CommandName, Message = ByteLength.ToInvariantString()
            });
            vts.OutputByteLengthReport += (CommandName, ByteLength) => Server.ServerContext.RaiseSessionLog(new SessionLogEntry {
                Token = Context.SessionTokenString, RemoteEndPoint = RemoteEndPoint, Time = DateTime.UtcNow, Type = "OutBytes", Name = CommandName, Message = ByteLength.ToInvariantString()
            });
        }