Beispiel #1
0
        public void ValidHelloMessage ()
        {
            var responseStream = new MemoryStream ();
            var stream = new TestStream (new MemoryStream (helloMessage), responseStream);

            // Create mock byte server and client
            var mockByteServer = new Mock<IServer<byte,byte>> ();
            var byteServer = mockByteServer.Object;
            var byteClient = new TestClient (stream);

            var server = new RPCServer (byteServer);
            server.OnClientRequestingConnection += (sender, e) => e.Request.Allow ();
            server.Start ();

            // Fire a client connection event
            var eventArgs = new ClientRequestingConnectionEventArgs<byte,byte> (byteClient);
            mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs);

            Assert.IsTrue (eventArgs.Request.ShouldAllow);
            Assert.IsFalse (eventArgs.Request.ShouldDeny);

            server.Update ();
            Assert.AreEqual (1, server.Clients.Count ());
            Assert.AreEqual ("Jebediah Kerman!!!", server.Clients.First ().Name);

            byte[] bytes = responseStream.ToArray ();
            byte[] responseBytes = byteClient.Guid.ToByteArray ();
            Assert.IsTrue (responseBytes.SequenceEqual (bytes));
        }
Beispiel #2
0
        static void Init()
        {
            if (config != null)
            {
                return;
            }

            // Load config
            config = new Configuration("PluginData/settings.cfg");
            config.Load();

            // Set up core
            core = Core.Instance;
            core.OneRPCPerUpdate     = config.OneRPCPerUpdate;
            core.MaxTimePerUpdate    = config.MaxTimePerUpdate;
            core.AdaptiveRateControl = config.AdaptiveRateControl;
            core.BlockingRecv        = config.BlockingRecv;
            core.RecvTimeout         = config.RecvTimeout;

            // Set up server
            rpcTcpServer    = new TCPServer("RPCServer", config.Address, config.RPCPort);
            streamTcpServer = new TCPServer("StreamServer", config.Address, config.StreamPort);
            rpcServer       = new Server.ProtocolBuffers.RPCServer(rpcTcpServer);
            streamServer    = new Server.ProtocolBuffers.StreamServer(streamTcpServer);
            server          = new Server.Server(rpcServer, streamServer);
        }
Beispiel #3
0
        public void InvalidHelloMessageHeader ()
        {
            helloMessage [4] = 0x42;

            var responseStream = new MemoryStream ();
            var stream = new TestStream (new MemoryStream (helloMessage), responseStream);

            // Create mock byte server and client
            var mockByteServer = new Mock<IServer<byte,byte>> ();
            var byteServer = mockByteServer.Object;
            var mockByteClient = new Mock<IClient<byte,byte>> ();
            mockByteClient.Setup (x => x.Stream).Returns (stream);
            var byteClient = mockByteClient.Object;

            var server = new RPCServer (byteServer);
            server.OnClientRequestingConnection += (sender, e) => e.Request.Allow ();
            server.Start ();

            // Fire a client connection event
            var eventArgs = new ClientRequestingConnectionEventArgs<byte,byte> (byteClient);
            mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs);

            Assert.IsFalse (eventArgs.Request.ShouldAllow);
            Assert.IsTrue (eventArgs.Request.ShouldDeny);

            Assert.AreEqual (0, responseStream.Length);
        }