/// <summary>
 /// Create a new Operational Socket
 /// </summary>
 /// <param name="Client">The Client to use</param>
 public OperationalSocket(SSPClient Client)
 {
     this.Client         = Client;
     this.PacketQueue    = new TaskQueue <PayloadInfo>(onPacketQueue, 50); //Payload x 10 = Memory in use
     this.MessageHandler = new MessageHandler(Client.Connection.messageHandler.Seed);
     this.Headers        = new HeaderList(Client.Connection);
 }
        public Connection(SSPClient client)
        {
            this.Client = client;
            this.State  = ConnectionState.Open;
            this.DPI    = new DeepPacketInspection();
            this.Client.Handle.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
            this.Client.Handle.NoDelay = true;

            this.packetQueue           = new PacketQueue(this);
            this.ChannelPayloadQueue   = new TaskQueue <ChannelRecvInfo>(client, onChannelPayloadQueue, 100);
            this.DisconnectedQueue     = new TaskQueue <IMessage>(client, onDisconnectedQueue, 100);
            this.ResponseQueue         = new TaskQueue <IMessage>(client, onResponseQueue, 100);
            this.PacketTaskQueue       = new TaskQueue <IMessage>(client, onPacketTaskQueue, 10);
            this.PayloadQueue          = new TaskQueue <IMessage>(client, onPayloadQueue, 100);
            this.KeepAliveQueue        = new TaskQueue <IMessage>(client, onKeepAliveQueue, 10);
            this.PluginDataQueue       = new TaskQueue <PluginRecvInfo>(client, onPluginDataQueue, 100);
            this.StreamQueue           = new TaskQueue <IMessage>(client, onStreamQueue, 5); //making it 5 on purpose
            this.LiteCodeQueue         = new TaskQueue <IMessage>(client, onLiteCodeQueue, 100);
            this.LiteCodeDelegateQueue = new TaskQueue <IMessage>(client, onLiteCodeDelegateQueue, 100);
            this.RootSocketQueue       = new TaskQueue <IPeerMessage>(client, onRootSocketQueue, 100);
            this.RequestQueue          = new TaskQueue <IMessage>(client, onRequestQueue, 100);

            this.messageHandler     = new MessageHandler(0);
            this.pluginSystem       = new PluginSystem(client);
            this.protection         = new Protection(this);
            this.Streams            = new SortedList <decimal, SecureStream>();
            this.Requests           = new SortedList <decimal, SyncObject>();
            this.SharedClasses      = new SortedList <string, SharedClass>();
            this.InitializedClasses = new SortedList <int, SharedClass>();
        }
Пример #3
0
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            LiteCodeClient Client = OpSocket as LiteCodeClient;

            lock (Client.InitializedClasses)
            {
                if (Client.InitializedClasses.ContainsKey(SharedClassId))
                {
                    Client.InitializedClasses[SharedClassId].IsDisposed = true;

                    SharedClass localSharedClass = null;
                    lock (Client.SharedClasses)
                    {
                        if (Client.SharedClasses.TryGetValue(Client.InitializedClasses[SharedClassId].SharedName, out localSharedClass))
                        {
                            localSharedClass.SharedInitializeCounter--;
                        }
                    }

                    Client.InitializedClasses[SharedClassId] = null;
                    Client.InitializedClasses.Remove(SharedClassId);
                }
                else
                {
                    //strange client behavior
                    Client.Disconnect();
                }
            }
        }
 /// <summary>
 /// Create a new Operational Socket
 /// </summary>
 /// <param name="Client">The Client to use</param>
 public OperationalSocket(SSPClient Client)
 {
     this.Client = Client;
     this.PacketQueue = new TaskQueue<PayloadInfo>(onPacketQueue, 50); //Payload x 10 = Memory in use
     this.MessageHandler = new MessageHandler(Client.Connection.messageHandler.Seed);
     this.Headers = new HeaderList(Client.Connection);
 }
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
     RequestHeader reqHeader = Header as RequestHeader;
     if (reqHeader != null)
     {
         reqHeader.HandleResponse(client, Number);
     }
 }
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            RequestHeader reqHeader = Header as RequestHeader;

            if (reqHeader != null)
            {
                reqHeader.HandleResponse(client, Number);
            }
        }
Пример #7
0
        public SSPClient ProcessClient(SSPServer Server, Socket TcpServer, IAsyncResult result)
        {
            try
            {
                Socket    AcceptSocket = TcpServer.EndAccept(result); //<- can throw a error
                SSPClient client       = Server.GetNewClient();
                client.Handle = AcceptSocket;

                if (AcceptSocket.AddressFamily == AddressFamily.InterNetworkV6)
                {
                    client.RemoteIp = ((IPEndPoint)AcceptSocket.RemoteEndPoint).Address.ToString();
                }
                else
                {
                    client.RemoteIp = AcceptSocket.RemoteEndPoint.ToString().Split(':')[0];
                }


                client.Server     = Server;
                client.Connection = new Network.Connection(client);
                client.ClientId   = Server.randomDecimal.NextDecimal();

                client.serverHS = new ServerMaze(Server.serverProperties.Handshake_Maze_Size, Server.serverProperties.Handshake_MazeCount, Server.serverProperties.Handshake_StepSize);
                client.serverHS.onFindKeyInDatabase += Server.serverHS_onFindKeyInDatabase;

                SysLogger.Log("Accepted peer " + client.RemoteIp, SysLogType.Debug);

                lock (Server.Clients)
                {
                    while (Server.Clients.ContainsKey(client.ClientId))
                    {
                        client.ClientId = Server.randomDecimal.NextDecimal();
                    }
                    Server.Clients.Add(client.ClientId, client);
                }

                try
                {
                    client.onBeforeConnect();
                }
                catch (Exception ex)
                {
                    SysLogger.Log(ex.Message, SysLogType.Error);
                    client.onException(ex, ErrorType.UserLand);
                }

                client.Connection.StartReceiver();
                return(client);
            }
            catch (Exception ex)
            {
                SysLogger.Log(ex.Message, SysLogType.Error);
                return(null);
            }
        }
Пример #8
0
        public override bool onAuthentication(SSPClient client, string Username, string Password)
        {
            Console.WriteLine("Authenication, Username:"******", Password:"******"Dergan" && Password == "1AF77DC7E7DDAB416977FA0CACE6840FBA7CA9D8FC580933DB74A8B58BED60F71B4E7FE85414E269E426E8C75A907EFB4021F2248FB9BEA5")
            {
                return(true);
            }

            return(false);
        }
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
     RequestHeader ReqHeader = Header as RequestHeader;
     if (ReqHeader != null)
     {
         if (client.IsServerSided)
         {
             client.Connection.SendMessage(new MsgGetNextIdResponse(client.Server.randomDecimal.NextDecimal()), new RequestHeader(ReqHeader.RequestId, true));
         }
     }
 }
Пример #10
0
 public SyncObject(SSPClient connection)
 {
     if (connection == null)
     {
         throw new ArgumentNullException("connection");
     }
     if (connection.Connection == null)
     {
         throw new ArgumentException("connection.Connection is null");
     }
     this.connection = connection.Connection;
 }
Пример #11
0
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            RequestHeader ReqHeader = Header as RequestHeader;

            if (ReqHeader != null)
            {
                if (client.IsServerSided)
                {
                    client.Connection.SendMessage(new MsgGetNextIdResponse(client.Server.randomDecimal.NextDecimal()), new RequestHeader(ReqHeader.RequestId, true));
                }
            }
        }
 public ClientSideHandshake(SSPClient client, ClientProperties Properties)
 {
     this.Client     = client;
     this.HandShakes = new List <Handshake>();
     this.HandShakes.Add(new CHS_Validation(client));
     this.HandShakes.Add(new CHS_Seed(client));
     this.HandShakes.Add(new CHS_KeyExchange(client));
     this.HandShakes.Add(new CHS_Authentication(client, Properties));
     this.HandShakes.Add(new CHS_TimeSynchronisation(client));
     this.HandShakes.Add(new CHS_ClientInfo(client));
     this.HandShakes.Add(new CHS_UDP(client, Properties));
     this.HandShakes.Add(new CHS_Plugins(client));
     this.HandShakes.Add(new CHS_ShareClasses(client));
 }
 public ServerSideHandshake(SSPClient client, ServerProperties serverProperties, Socket UdpClient, GetClientsDelegate getClientsDelegate, PrivateKeyHandler KeyHandler)
 {
     this.Client     = client;
     this.HandShakes = new List <Handshake>();
     this.HandShakes.Add(new SHS_Validation(client));
     this.HandShakes.Add(new SHS_Seed(client));
     this.HandShakes.Add(new SHS_KeyExchange(client, serverProperties, KeyHandler));
     this.HandShakes.Add(new SHS_Authentication(client, serverProperties));
     this.HandShakes.Add(new SHS_TimeSynchronisation(client));
     this.HandShakes.Add(new SHS_ClientInfo(client, serverProperties));
     this.HandShakes.Add(new SHS_UDP(client, serverProperties, UdpClient));
     this.HandShakes.Add(new SHS_Plugins(client, getClientsDelegate));
     this.HandShakes.Add(new SHS_ShareClasses(client));
 }
Пример #14
0
        public override void ProcessPayload(IClient client, Plugin.IPlugin plugin = null)
        {
            SSPClient c = client as SSPClient;

            if (c != null)
            {
                c.ConnectionClosedNormal = true;
                if (!client.Connection.InvokedOnDisconnect)
                {
                    client.Connection.InvokedOnDisconnect = true;
                    c.Disconnect(Reason);
                }
            }
            base.ProcessPayload(client, plugin);
        }
Пример #15
0
        public override void ProcessPayload(IClient client, IPlugin plugin = null)
        {
            SSPClient Client = client as SSPClient;

            lock (Client.Connection.Requests)
            {
                if (Client.Connection.Requests.ContainsKey(RequestId))
                {
                    Client.Connection.Requests[RequestId].Value = Result;
                    Client.Connection.Requests[RequestId].Pulse();
                    Client.Connection.Requests.Remove(RequestId);
                }
            }
            base.ProcessPayload(client, plugin);
        }
 public void HandleResponse(SSPClient Client, object ResponseObj)
 {
     if (isResponse)
     {
         lock (Client.Connection.Requests)
         {
             SyncObject syncObj = null;
             if (Client.Connection.Requests.TryGetValue(RequestId, out syncObj))
             {
                 syncObj.Value = ResponseObj;
                 syncObj.Pulse();
                 Client.Connection.Requests.Remove(RequestId);
             }
         }
     }
 }
Пример #17
0
 public void HandleResponse(SSPClient Client, object ResponseObj)
 {
     if (isResponse)
     {
         lock (Client.Connection.Requests)
         {
             SyncObject syncObj = null;
             if (Client.Connection.Requests.TryGetValue(RequestId, out syncObj))
             {
                 syncObj.Value = ResponseObj;
                 syncObj.Pulse();
                 Client.Connection.Requests.Remove(RequestId);
             }
         }
     }
 }
        public override void ProcessPayload(IClient client, IPlugin plugin = null)
        {
            SSPClient Client = client as SSPClient;

            lock (Client.Connection.Requests)
            {
                if (Client.Connection.Requests.ContainsKey(RequestId))
                {
                    //Console.WriteLine("result is null ? " + (Result == null));
                    Client.Connection.Requests[RequestId].Value = Result;
                    Client.Connection.Requests[RequestId].Pulse();
                    Client.Connection.Requests.Remove(RequestId);
                }
            }
            base.ProcessPayload(client);
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="DnsId">Only the owner of the DNS must have this to update his IP address</param>
        /// <returns></returns>
        public bool ApplyDnsName(string name, ref uint DnsId, SSPClient peer)
        {
            name  = name.ToLower();
            DnsId = new MurmurHash2UInt32Hack().Hash(ASCIIEncoding.Unicode.GetBytes(name));
            for (int i = 0; i < DnsNames.Count; i++)
            {
                if (DnsNames.Values[i].DnsId == DnsId)
                {
                    return(false);
                }
            }

            RootDnsInfo dns = new RootDnsInfo(name, DnsId);

            dns.VirtualIp = peer.VirtualIP;
            DnsNames.Add(DnsId, dns);
            return(true);
        }
        public override void ProcessPayload(Interfaces.IClient client, Plugin.IPlugin plugin = null)
        {
            SSPClient Client = client as SSPClient;

            if (Client.PeerSide == PeerSide.Client)
            {
                if (Client.SyncNextRandomId != null)
                {
                    Client.SyncNextRandomId.Value = this;
                    Client.SyncNextRandomId.Pulse();
                }
            }
            else if (Client.PeerSide == PeerSide.Server)
            {
                RandomId = Client.Server.Random.NextDecimal();
                client.Connection.SendMessage(this, PacketId.RequestMessages);
            }
            base.ProcessPayload(client, plugin);
        }
Пример #21
0
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            RequestHeader reqHeader = Header as RequestHeader;

            if (reqHeader != null)
            {
                lock (client.Connection.OperationalSockets)
                {
                    if (!client.Connection.OperationalSockets.TryGetValue(ConnectionId, out OpSocket))
                    {
                        return;
                    }
                }


                if (!OpSocket.isConnected)
                {
                    return;
                }

                OpSocket.InternalSendMessage(new MsgOpDisconnectResponse(ConnectionId), new RequestHeader(reqHeader.RequestId, true));
                OpSocket.isConnected = false;

                lock (client.Connection.OperationalSockets)
                {
                    if (client.Connection.OperationalSockets.ContainsKey(OpSocket.ConnectionId))
                    {
                        client.Connection.OperationalSockets.Remove(OpSocket.ConnectionId);
                    }
                }

                try
                {
                    OpSocket.onDisconnect(DisconnectReason.UserDisconnection);
                    client.onOperationalSocket_Disconnected(OpSocket, DisconnectReason.UserDisconnection);
                }
                catch (Exception ex)
                {
                    SysLogger.Log(ex.Message, SysLogType.Error);
                }
            }
        }
Пример #22
0
        public Connection(SSPClient client)
        {
            this.Client = client;

            this.Connected = true;
            this.Headers = new HeaderList(this);
            this.HandshakeSync = new SyncObject(this);
            this.InitSync = new SyncObject(this);
            this.RegisteredOperationalSockets = new SortedList<ulong, Type>();
            this.Requests = new SortedList<int, SyncObject>();
            this.OperationalSockets = new SortedList<ushort, OperationalSocket>();
            this.EncryptionAlgorithm = client.Server != null ? client.Server.serverProperties.EncryptionAlgorithm : client.Properties.EncryptionAlgorithm;
            this.CompressionAlgorithm = client.Server != null ? client.Server.serverProperties.CompressionAlgorithm : client.Properties.CompressionAlgorithm;

            //generate the header encryption
            byte[] privKey = client.Server != null ? client.Server.serverProperties.NetworkKey : client.Properties.NetworkKey;

            PrivateSeed = privKey.Length >= 4 ? BitConverter.ToInt32(privKey, 0) : 0xBEEF;

            for (int i = 0; i < privKey.Length; i++)
                PrivateSeed += privKey[i];

            byte[] SaltKey = new byte[privKey.Length];
            Array.Copy(privKey, SaltKey, SaltKey.Length);

            for (int i = 0; i < SaltKey.Length; i++)
                SaltKey[i] += (byte)PrivateSeed;

            uint CipherRounds = client.Server != null ? client.Server.serverProperties.Cipher_Rounds : client.Properties.Cipher_Rounds;
            byte[] encCode = new byte[0];
            byte[] decCode = new byte[0];
            WopEx.GenerateCryptoCode(PrivateSeed, 5, ref encCode, ref decCode);
            this.HeaderEncryption = new WopEx(privKey, SaltKey, InitialVector, encCode, decCode, WopEncMode.GenerateNewAlgorithm, CipherRounds, false);

            WopEx.GenerateCryptoCode(PrivateSeed << 3, 15, ref encCode, ref decCode);
            this.PayloadEncryption = new WopEx(privKey, SaltKey, InitialVector, encCode, decCode, WopEncMode.Simple, CipherRounds, true);

            this.EncAES = new HwAes(this, privKey, 256, System.Security.Cryptography.CipherMode.CBC, System.Security.Cryptography.PaddingMode.PKCS7);

            this.headerConfuser = new DataConfuser(PrivateSeed, Connection.HEADER_SIZE);

            this.QuickLZ = new UnsafeQuickLZ();

            this.messageHandler = new MessageHandler((uint)PrivateSeed + 0x0FA453FB);
            this.messageHandler.AddMessage(typeof(MsgHandshake), "MAZE_HAND_SHAKE");
            this.messageHandler.AddMessage(typeof(MsgCreateConnection), "CREATE_CONNECTION");
            this.messageHandler.AddMessage(typeof(MsgCreateConnectionResponse), "CREATE_CONNECTION_RESPONSE");

            this.messageHandler.AddMessage(typeof(MsgInitOk), "INIT_OK");
            this.messageHandler.AddMessage(typeof(MsgGetNextId), "GET_NEXT_NUMBER");
            this.messageHandler.AddMessage(typeof(MsgGetNextIdResponse), "GET_NEXT_NUMBER_RESPONSE");

            this.messageHandler.AddMessage(typeof(MsgOpDisconnect), "OP_DISCONNECT");
            this.messageHandler.AddMessage(typeof(MsgOpDisconnectResponse), "OP_DISCONNECT_RESPONSE");

            this.messageHandler.AddMessage(typeof(MsgKeepAlive), "KEEP_ALIVE");

            Headers.RegisterHeader(typeof(SystemHeader));
            Headers.RegisterHeader(typeof(ConnectionHeader));
            Headers.RegisterHeader(typeof(RequestHeader));
        }
Пример #23
0
 public SHS_KeyExchange(SSPClient client, ServerProperties serverProperties, PrivateKeyHandler KeyHandler)
     : base(client)
 {
     this.serverProperties = serverProperties;
     this.KeyHandler       = KeyHandler;
 }
Пример #24
0
 public abstract void ProcessPayload(SSPClient client, OperationalSocket OpSocket);
Пример #25
0
 public Feature(SSPClient Client)
 {
     this.Client = Client;
 }
Пример #26
0
 public CHS_ShareClasses(SSPClient client)
     : base(client)
 {
 }
Пример #27
0
 /// <summary>
 /// Generate the keys to identify the user and encrypt the network session
 /// </summary>
 public void GenKey(SSPClient Client, SessionSide side, Size size, int MazeCount, int MazeSteps)
 {
     this.Client = Client;
     GenKey(side, size, MazeCount, MazeSteps);
 }
Пример #28
0
 public override void onConnectionAccept(SSPClient client)
 {
     Console.WriteLine("Accepted client");
 }
Пример #29
0
 public SharedRoot(SSPClient client)
 {
     this.client = client;
 }
Пример #30
0
        public PeerResponse ConnectToPeer(string VirtualIpOrDns)
        {
            SSPClient TargetClient = null;

            //check if dns name
            if (!Regex.IsMatch(VirtualIpOrDns, RootPeer.IpValidationString))
            {
                RootDnsInfo inf = client.Server.RootSocket_DNS.GetDnsRecord(VirtualIpOrDns);
                if (inf != null)
                {
                    VirtualIpOrDns = inf.VirtualIp;
                }
            }

            TargetClient = client.Server.GetClient(VirtualIpOrDns);

            if (TargetClient == null)
            {
                return(new PeerResponse(PeerErrorCode.PeerNotFound, 0, ""));
            }

            //check if server side allows this connection
            if (!client.Server.onPeerConnectionRequest(client, TargetClient))
            {
                return(new PeerResponse(PeerErrorCode.PermissionDenied, 0, ""));
            }

            //check if target client allows this connection
            decimal ConnectionId  = 0;
            bool    HasPermission = false;

            lock (TargetClient.PeerConnections)
            {
                lock (client.PeerConnections)
                {
                    RandomDecimal rnd = new RandomDecimal(DateTime.Now.Millisecond);
                    ConnectionId = rnd.NextDecimal();
                    while (TargetClient.PeerConnections.ContainsKey(ConnectionId) || client.PeerConnections.ContainsKey(ConnectionId))
                    {
                        ConnectionId = rnd.NextDecimal();
                    }

                    try
                    {
                        HasPermission = TargetClient.SharedClientRoot.RequestPeerConnection(client.VirtualIP, ConnectionId);
                    }
                    catch { HasPermission = false; }


                    if (HasPermission)
                    {
                        RootPeer TargetPeer = client.onGetNewPeerObject();
                        TargetPeer._client      = TargetClient;
                        TargetPeer.FromClient   = TargetClient;
                        TargetPeer.ToClient     = client;
                        TargetPeer.VirtualIP    = client.VirtualIP;
                        TargetPeer.Connected    = true;
                        TargetPeer.ConnectionId = ConnectionId;

                        RootPeer FromPeer = client.onGetNewPeerObject();
                        FromPeer._client      = client;
                        FromPeer.FromClient   = client;
                        FromPeer.ToClient     = TargetClient;
                        FromPeer.VirtualIP    = TargetClient.VirtualIP;
                        FromPeer.Connected    = true;
                        FromPeer.ConnectionId = ConnectionId;

                        if (!TargetClient.PeerConnections.ContainsKey(ConnectionId))
                        {
                            TargetClient.PeerConnections.Add(ConnectionId, TargetPeer);
                        }

                        if (!client.PeerConnections.ContainsKey(ConnectionId))
                        {
                            client.PeerConnections.Add(ConnectionId, FromPeer);
                        }

                        TargetClient.SharedClientRoot.NewPeerconnection(ConnectionId);

                        return(new PeerResponse(PeerErrorCode.Success, ConnectionId, TargetClient.VirtualIP));
                    }
                    return(new PeerResponse(PeerErrorCode.PermissionDenied, 0, ""));
                }
            }
        }
Пример #31
0
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
     client.Connection.InitSync.Value = true;
     client.Connection.InitSync.Pulse();
 }
Пример #32
0
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            ReturnResult   result = new ReturnResult(null, false);
            LiteCodeClient Client = OpSocket as LiteCodeClient;

            try
            {
                PayloadReader pr     = new PayloadReader(Data);
                SharedClass   sClass = null;

                if (Client.InitializedClasses.TryGetValue(SharedClassId, out sClass))
                {
                    SharedMethod sharedMethod = sClass.GetMethod(MethodId);

                    if (sharedMethod != null)
                    {
                        List <object> args  = new List <object>();
                        List <Type>   types = new List <Type>();
                        SortedList <int, SharedDelegate> SharedDelegates = new SortedList <int, SharedDelegate>();
                        SmartSerializer serializer = new SmartSerializer();

                        lock (sharedMethod.Delegates)
                        {
                            SharedDelegate sharedDel = null;
                            if (sharedMethod.Delegates.TryGetValue(DelegateId, out sharedDel))
                            {
                                for (int i = 0; i < sharedDel.sharedMethod.ArgumentTypes.Length; i++)
                                {
                                    args.Add(serializer.Deserialize(pr.ReadBytes(pr.ReadInteger())));
                                }
                            }
                            else
                            {
                                for (int i = 0; i < sharedMethod.ArgumentTypes.Length; i++)
                                {
                                    args.Add(serializer.Deserialize(pr.ReadBytes(pr.ReadInteger())));
                                }
                            }
                        }

                        if (!isDelegate) //atm no support yet for delegate inside another delegate
                        {
                            for (int i = 0; i < sharedMethod.DelegateIndex.Count; i++)
                            {
                                if (pr.ReadByte() == 1)
                                {
                                    SharedDelegate del = pr.ReadObject <SharedDelegate>();
                                    del.sharedMethod.sharedClass             = sClass;
                                    args[sharedMethod.DelegateIndex.Keys[i]] = DynamicDelegateCreator.CreateDelegate(del);
                                    SharedDelegates.Add(del.sharedMethod.DelegateId, del);
                                }
                            }
                        }

                        if (isDelegate)
                        {
                            result.ReturnValue = sharedMethod.Delegates[DelegateId].Delegate.DynamicInvoke(args.ToArray());
                        }
                        else
                        {
                            if (sharedMethod.CallCache == null)
                            {
                                MethodInfo methodInf = sClass.InitializedClass.GetType().GetMethod(sharedMethod.Name, sharedMethod.ArgumentTypes);
                                sharedMethod.CallCache = methodInf.Bind();
                            }
                            result.ReturnValue = sharedMethod.CallCache(sClass.InitializedClass, args.ToArray());

                            /*MethodInfo methodInf = sClass.InitializedClass.GetType().GetMethod(sharedMethod.Name, sharedMethod.ArgumentTypes);
                             * result.ReturnValue = methodInf.Invoke(sClass.InitializedClass, args.ToArray());*/
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                result.exceptionMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                result.ExceptionOccured = true;
                client.onException(ex.InnerException != null ? ex.InnerException : ex, ErrorType.UserLand);
            }

            if (RequireResultBack)
            {
                Client.Send(new MsgExecuteMethodResponse(RequestId, result));
            }
        }
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
 }
Пример #34
0
 internal AClient(SSPClient client)
     : this()
 {
     this.Connection = client;
 }
Пример #35
0
 public override void onConnectionClosed(SSPClient client)
 {
 }
Пример #36
0
 public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
 {
     client.Connection.InitSync.Value = true;
     client.Connection.InitSync.Pulse();
 }
 public OperationSocket(SSPClient Client)
 {
     this.Client = Client;
 }
Пример #38
0
 /// <summary>
 /// Generate the keys to identify the user and encrypt the network session
 /// </summary>
 public void GenKey(SSPClient Client, SessionSide side, Size size, int MazeCount, int MazeSteps)
 {
     this.Client = Client;
     GenKey(side, size, MazeCount, MazeSteps);
 }
Пример #39
0
 public override bool onPeerConnectionRequest(SSPClient FromClient, SSPClient ToClient)
 {
     Console.WriteLine("Permission granted for connecting from " + FromClient.VirtualIP + " to " + ToClient.VirtualIP);
     return(true);
 }
        public override void ProcessPayload(SSPClient client, OperationalSocket _OpSocket)
        {
            RequestHeader reqHeader = Header as RequestHeader;
            if (reqHeader != null)
            {
                Type type = null;
                lock (client.Connection.RegisteredOperationalSockets)
                {
                    client.Connection.RegisteredOperationalSockets.TryGetValue(Identifier, out type);
                }

                if(type != null)
                {
                    bool SendedSuccess = false;
                    try
                    {
                        OperationalSocket OpSocket = (OperationalSocket)Activator.CreateInstance(type, client);

                        OpSocket.isConnected = true;

                        lock (client.Connection.OperationalSockets)
                        {
                            FastRandom rnd = new FastRandom();
                            OpSocket.ConnectionId = (ushort)rnd.Next(1, 65535);
                            while(client.Connection.OperationalSockets.ContainsKey(OpSocket.ConnectionId))
                                OpSocket.ConnectionId = (ushort)rnd.Next(1, 65535);

                            client.Connection.OperationalSockets.Add(OpSocket.ConnectionId, OpSocket);
                        }

                        try
                        {
                            OpSocket.onBeforeConnect();
                            client.onOperationalSocket_BeforeConnect(OpSocket);
                        }
                        catch (Exception ex)
                        {
                            SysLogger.Log(ex.Message, SysLogType.Error);
                            OpSocket.onException(ex, ErrorType.UserLand);
                        }

                        client.Connection.SendMessage(new MsgCreateConnectionResponse(OpSocket.ConnectionId, true), new RequestHeader(reqHeader.RequestId, true));
                        SendedSuccess = true;
                        OpSocket.onConnect();
                        client.onOperationalSocket_Connected(OpSocket);
                    }
                    catch (Exception ex)
                    {
                        SysLogger.Log(ex.Message, SysLogType.Error);

                        if (!SendedSuccess)
                        {
                            client.Connection.SendMessage(new MsgCreateConnectionResponse(0, false), new RequestHeader(reqHeader.RequestId, true));
                        }
                    }
                }
                else
                {
                    client.Connection.SendMessage(new MsgCreateConnectionResponse(0, false), new RequestHeader(reqHeader.RequestId, true));
                }
            }
        }
Пример #41
0
 public override bool onPeerCreateDnsRequest(string DnsName, SSPClient Requestor)
 {
     return(true);
 }
 public SHS_TimeSynchronisation(SSPClient client)
     : base(client)
 {
 }
        public override void ProcessPayload(SSPClient client, OperationalSocket OpSocket)
        {
            SSPClient _client = client as SSPClient;
            if (_client != null)
            {
                byte[] responseData = new byte[0];
                MazeErrorCode errorCode = MazeErrorCode.Error;
                Mazing mazeHandshake = _client.IsServerSided ? _client.serverHS : _client.clientHS;

                if (mazeHandshake == null)
                {
                    //error could occur on a unexpected disconnect
                    client.Connection.HandShakeCompleted = false;
                    client.Connection.HandshakeSync.Pulse();
                    return;
                }

                errorCode = mazeHandshake.onReceiveData(Data, ref responseData);

                if (errorCode != MazeErrorCode.Finished && errorCode != MazeErrorCode.Success && client.TimingConfiguration.Enable_Timing)
                {
                    //something went wrong, annoy the attacker
                    Thread.Sleep(client.TimingConfiguration.Authentication_WrongPassword);
                }

                if (responseData.Length > 0)
                {
                    client.Connection.SendMessage(new MsgHandshake(responseData), new SystemHeader());
                }

                if(client == null || client.Connection == null || client.Connection.HandshakeSync == null)
                {
                    //error could occur on a unexpected disconnect
                    return;
                }

                client.Connection.HandshakeSync.Value = errorCode;
                if (errorCode != MazeErrorCode.Finished && errorCode != MazeErrorCode.Success)
                {
                    client.Connection.HandshakeSync.Pulse();
                }
                else if (errorCode == MazeErrorCode.Finished)
                {
                    //let's tell it's completed and apply the new key
                    client.Connection.ApplyNewKey(mazeHandshake, mazeHandshake.FinalKey, mazeHandshake.FinalSalt);

                    if (_client.IsServerSided)
                    {
                        if (mazeHandshake as ServerMaze != null)
                        {
                            client.Username = (mazeHandshake as ServerMaze).Username;
                        }

                        client.Connection.HandShakeCompleted = true;

                        /*try
                        {
                            client.onBeforeConnect();
                        }
                        catch (Exception ex)
                        {
                            SysLogger.Log(ex.Message, SysLogType.Error);
                            client.onException(ex, ErrorType.UserLand);
                            return; //don't send that we're ready since we're clearly not at this point
                        }*/

                        client.Connection.SendMessage(new MsgInitOk(), new SystemHeader());

                        try
                        {
                            client.onConnect();
                        }
                        catch (Exception ex)
                        {
                            SysLogger.Log(ex.Message, SysLogType.Error);
                            client.onException(ex, ErrorType.UserLand);
                            return; //don't send that we're ready since we're clearly not at this point
                        }
                    }
                    else
                    {
                        client.Connection.HandShakeCompleted = true;
                        client.Connection.HandshakeSync.Pulse();
                    }
                }
            }
        }