コード例 #1
0
        private static Message CreateMessageSetKey640()
        {
            ICollection <Number160> sampleCollection1 = new List <Number160>();

            sampleCollection1.Add(_sample160_1);
            sampleCollection1.Add(_sample160_2);
            sampleCollection1.Add(_sample160_3);

            ICollection <Number160> sampleCollection2 = new List <Number160>();

            sampleCollection2.Add(_sample160_2);
            sampleCollection2.Add(_sample160_3);
            sampleCollection2.Add(_sample160_4);

            ICollection <Number160> sampleCollection3 = new List <Number160>();

            sampleCollection3.Add(_sample160_3);
            sampleCollection3.Add(_sample160_4);
            sampleCollection3.Add(_sample160_5);

            var m = Utils2.CreateDummyMessage();

            m.SetKeyCollection(new KeyCollection(_sample160_1, _sample160_1, _sample160_1, sampleCollection1));
            m.SetKeyCollection(new KeyCollection(_sample160_2, _sample160_2, _sample160_2, sampleCollection2));
            m.SetKeyCollection(new KeyCollection(_sample160_3, _sample160_3, _sample160_3, sampleCollection3));
            m.SetKeyCollection(new KeyCollection(_sample160_4, _sample160_4, _sample160_4, sampleCollection1));
            m.SetKeyCollection(new KeyCollection(_sample160_5, _sample160_5, _sample160_5, sampleCollection2));
            m.SetKeyCollection(new KeyCollection(_sample160_1, _sample160_2, _sample160_3, sampleCollection3));
            m.SetKeyCollection(new KeyCollection(_sample160_2, _sample160_3, _sample160_4, sampleCollection1));
            m.SetKeyCollection(new KeyCollection(_sample160_3, _sample160_4, _sample160_5, sampleCollection2));
            return(m);
        }
コード例 #2
0
        private static Message CreateMessageMapKey640Keys()
        {
            var keysMap = new SortedDictionary <Number640, ICollection <Number160> >();
            var set     = new HashSet <Number160>();

            set.Add(_sample160_1);
            keysMap.Add(_sample640_1, set);

            set = new HashSet <Number160>();
            set.Add(_sample160_2);
            set.Add(_sample160_3);
            keysMap.Add(_sample640_2, set);

            set = new HashSet <Number160>();
            set.Add(_sample160_1);
            set.Add(_sample160_2);
            set.Add(_sample160_3);
            set.Add(_sample160_4);
            set.Add(_sample160_5);
            keysMap.Add(_sample640_3, set);

            var m = Utils2.CreateDummyMessage();

            m.SetKeyMap640Keys(new KeyMap640Keys(keysMap));
            m.SetKeyMap640Keys(new KeyMap640Keys(keysMap));
            m.SetKeyMap640Keys(new KeyMap640Keys(keysMap));
            m.SetKeyMap640Keys(new KeyMap640Keys(keysMap));
            m.SetKeyMap640Keys(new KeyMap640Keys(keysMap));
            m.SetKeyMap640Keys(new KeyMap640Keys(keysMap));
            m.SetKeyMap640Keys(new KeyMap640Keys(keysMap));
            m.SetKeyMap640Keys(new KeyMap640Keys(keysMap));
            return(m);
        }
コード例 #3
0
        public void TestMessageEncodeEmpty()
        {
            // create same message object as in Java
            var m     = Utils2.CreateDummyMessage();
            var bytes = EncodeMessage(m);

            // validate decoding in Java
            Assert.IsTrue(JarRunner.WriteBytesAndTestInterop(bytes));
        }
コード例 #4
0
        public void TestMessageDecodeEmpty()
        {
            // create same message object as in Java
            var m1 = Utils2.CreateDummyMessage();

            // compare Java encoded and .NET decoded objects
            var m2 = DecodeMessage(JarRunner.RequestJavaBytes());

            Assert.IsTrue(CheckSameContentTypes(m1, m2));
        }
コード例 #5
0
        public static Message CreateMessageInteger()
        {
            var m = Utils2.CreateDummyMessage();

            m.SetIntValue(Int32.MinValue);
            m.SetIntValue(-256);
            m.SetIntValue(-128);
            m.SetIntValue(-1);
            m.SetIntValue(0);
            m.SetIntValue(1);
            m.SetIntValue(128);
            m.SetIntValue(Int32.MaxValue);
            return(m);
        }
コード例 #6
0
        private static Message CreateMessageLong()
        {
            var m = Utils2.CreateDummyMessage();

            m.SetLongValue(Int64.MinValue);
            m.SetLongValue(-256);
            m.SetLongValue(-128);
            m.SetLongValue(-1);
            m.SetLongValue(0);
            m.SetLongValue(1);
            m.SetLongValue(128);
            m.SetLongValue(Int64.MaxValue);
            return(m);
        }
コード例 #7
0
        private static Message CreateMessageKey()
        {
            var m = Utils2.CreateDummyMessage();

            m.SetKey(_sample160_1);
            m.SetKey(_sample160_2);
            m.SetKey(_sample160_3);
            m.SetKey(_sample160_4);
            m.SetKey(_sample160_5);
            m.SetKey(_sample160_1);
            m.SetKey(_sample160_2);
            m.SetKey(_sample160_3);
            return(m);
        }
コード例 #8
0
        private static Message CreateMessageMapKey640Data()
        {
            // TODO create Data objects with BasedOn keys and other properties

            IDictionary <Number640, Data> sampleMap1 = new Dictionary <Number640, Data>();

            sampleMap1.Add(_sample640_1, _sampleData1);
            sampleMap1.Add(_sample640_2, _sampleData1);
            sampleMap1.Add(_sample640_3, _sampleData1);

            IDictionary <Number640, Data> sampleMap2 = new Dictionary <Number640, Data>();

            sampleMap2.Add(_sample640_1, _sampleData2);
            sampleMap2.Add(_sample640_2, _sampleData2);
            sampleMap2.Add(_sample640_3, _sampleData2);

            IDictionary <Number640, Data> sampleMap3 = new Dictionary <Number640, Data>();

            sampleMap3.Add(_sample640_1, _sampleData3);
            sampleMap3.Add(_sample640_2, _sampleData3);
            sampleMap3.Add(_sample640_3, _sampleData3);

            IDictionary <Number640, Data> sampleMap4 = new Dictionary <Number640, Data>();

            sampleMap4.Add(_sample640_1, _sampleData1);
            sampleMap4.Add(_sample640_2, _sampleData2);
            sampleMap4.Add(_sample640_3, _sampleData3);

            IDictionary <Number640, Data> sampleMap5 = new Dictionary <Number640, Data>();

            sampleMap5.Add(_sample640_3, _sampleData1);
            sampleMap5.Add(_sample640_2, _sampleData2);
            sampleMap5.Add(_sample640_1, _sampleData3);

            var m = Utils2.CreateDummyMessage();

            m.SetDataMap(new DataMap(sampleMap1));
            m.SetDataMap(new DataMap(sampleMap2));
            m.SetDataMap(new DataMap(sampleMap3));
            m.SetDataMap(new DataMap(sampleMap4));
            m.SetDataMap(new DataMap(sampleMap5));
            m.SetDataMap(new DataMap(sampleMap1));
            m.SetDataMap(new DataMap(sampleMap2));
            m.SetDataMap(new DataMap(sampleMap3));
            return(m);
        }
コード例 #9
0
        private static Message CreateMessageMapKey640Byte()
        {
            IDictionary <Number640, sbyte> sampleMap1 = new Dictionary <Number640, sbyte>();

            sampleMap1.Add(_sample640_1, _sampleBytes1[0]);
            sampleMap1.Add(_sample640_2, _sampleBytes1[1]);
            sampleMap1.Add(_sample640_3, _sampleBytes1[2]);

            IDictionary <Number640, sbyte> sampleMap2 = new Dictionary <Number640, sbyte>();

            sampleMap2.Add(_sample640_1, _sampleBytes1[3]);
            sampleMap2.Add(_sample640_2, _sampleBytes1[4]);
            sampleMap2.Add(_sample640_3, _sampleBytes1[5]);

            IDictionary <Number640, sbyte> sampleMap3 = new Dictionary <Number640, sbyte>();

            sampleMap3.Add(_sample640_1, _sampleBytes1[6]);
            sampleMap3.Add(_sample640_2, _sampleBytes1[7]);
            sampleMap3.Add(_sample640_3, _sampleBytes1[8]);

            IDictionary <Number640, sbyte> sampleMap4 = new Dictionary <Number640, sbyte>();

            sampleMap4.Add(_sample640_1, _sampleBytes1[9]);
            sampleMap4.Add(_sample640_2, _sampleBytes1[10]);
            sampleMap4.Add(_sample640_3, _sampleBytes1[11]);

            IDictionary <Number640, sbyte> sampleMap5 = new Dictionary <Number640, sbyte>();

            sampleMap5.Add(_sample640_1, _sampleBytes1[12]);
            sampleMap5.Add(_sample640_2, _sampleBytes1[13]);
            sampleMap5.Add(_sample640_3, _sampleBytes1[14]);

            var m = Utils2.CreateDummyMessage();

            m.SetKeyMapByte(new KeyMapByte(sampleMap1));
            m.SetKeyMapByte(new KeyMapByte(sampleMap2));
            m.SetKeyMapByte(new KeyMapByte(sampleMap3));
            m.SetKeyMapByte(new KeyMapByte(sampleMap4));
            m.SetKeyMapByte(new KeyMapByte(sampleMap5));
            m.SetKeyMapByte(new KeyMapByte(sampleMap1));
            m.SetKeyMapByte(new KeyMapByte(sampleMap2));
            m.SetKeyMapByte(new KeyMapByte(sampleMap3));
            return(m);
        }
コード例 #10
0
        private static Message CreateMessageBloomFilter()
        {
            var sampleBf1 = new SimpleBloomFilter <Number160>(2, 5);

            sampleBf1.Add(_sample160_1);

            var sampleBf2 = new SimpleBloomFilter <Number160>(2, 5);

            sampleBf2.Add(_sample160_2);
            sampleBf2.Add(_sample160_1);

            var sampleBf3 = new SimpleBloomFilter <Number160>(2, 5);

            sampleBf3.Add(_sample160_1);
            sampleBf3.Add(_sample160_2);
            sampleBf3.Add(_sample160_3);

            var sampleBf4 = new SimpleBloomFilter <Number160>(2, 5);

            sampleBf4.Add(_sample160_1);
            sampleBf4.Add(_sample160_2);
            sampleBf4.Add(_sample160_3);
            sampleBf4.Add(_sample160_4);

            var sampleBf5 = new SimpleBloomFilter <Number160>(2, 5);

            sampleBf5.Add(_sample160_1);
            sampleBf5.Add(_sample160_2);
            sampleBf5.Add(_sample160_3);
            sampleBf5.Add(_sample160_4);
            sampleBf5.Add(_sample160_5);

            var m = Utils2.CreateDummyMessage();

            m.SetBloomFilter(sampleBf1);
            m.SetBloomFilter(sampleBf2);
            m.SetBloomFilter(sampleBf3);
            m.SetBloomFilter(sampleBf4);
            m.SetBloomFilter(sampleBf5);
            m.SetBloomFilter(sampleBf1);
            m.SetBloomFilter(sampleBf2);
            m.SetBloomFilter(sampleBf3);
            return(m);
        }
コード例 #11
0
        /// <summary>
        /// Decodes a message from the provided byte array.
        /// </summary>
        /// <param name="bytes">The message bytes from Java encoding.</param>
        /// <returns>The .NET message version.</returns>
        public static Message DecodeMessage(byte[] bytes)
        {
            var decoder = new Decoder(null);

            // mock a non-working ChannelHandlerContext
            var pipeline = new Pipeline();
            var channel  = new MyTcpClient(new IPEndPoint(IPAddress.Any, 0), pipeline);
            var session  = new PipelineSession(channel, pipeline, new List <IInboundHandler>(), new List <IOutboundHandler>());
            var ctx      = new ChannelHandlerContext(channel, session);

            // create dummy sender for decoding
            var message = Utils2.CreateDummyMessage();
            AlternativeCompositeByteBuf buf = AlternativeCompositeByteBuf.CompBuffer();

            buf.WriteBytes(bytes.ToSByteArray());
            decoder.Decode(ctx, buf, message.Recipient.CreateSocketTcp(), message.Sender.CreateSocketTcp());

            return(decoder.Message);
        }
コード例 #12
0
        private static Message CreateMessageSetPeerSocket()
        {
            IPAddress sampleAddress1 = IPAddress.Parse("192.168.1.1");
            IPAddress sampleAddress2 = IPAddress.Parse("255.255.255.255");
            IPAddress sampleAddress3 = IPAddress.Parse("127.0.0.1");
            IPAddress sampleAddress4 = IPAddress.Parse("0:1:2:3:4:5:6:7");
            IPAddress sampleAddress5 = IPAddress.Parse("7:6:5:4:3:2:1:0");

            var samplePsa1  = new PeerSocketAddress(sampleAddress1, 0, 0);
            var samplePsa2  = new PeerSocketAddress(sampleAddress2, 65535, 65535);
            var samplePsa3  = new PeerSocketAddress(sampleAddress3, 1, 1);
            var samplePsa4  = new PeerSocketAddress(sampleAddress4, 2, 2);
            var samplePsa5  = new PeerSocketAddress(sampleAddress5, 30, 40);
            var samplePsa6  = new PeerSocketAddress(sampleAddress1, 88, 88);
            var samplePsa7  = new PeerSocketAddress(sampleAddress2, 177, 177);
            var samplePsa8  = new PeerSocketAddress(sampleAddress3, 60000, 65000);
            var samplePsa9  = new PeerSocketAddress(sampleAddress4, 99, 100);
            var samplePsa10 = new PeerSocketAddress(sampleAddress5, 13, 1234);

            ICollection <PeerSocketAddress> sampleAddresses = new List <PeerSocketAddress>();

            sampleAddresses.Add(samplePsa1);
            sampleAddresses.Add(samplePsa2);
            sampleAddresses.Add(samplePsa3);
            sampleAddresses.Add(samplePsa4);
            sampleAddresses.Add(samplePsa5);
            sampleAddresses.Add(samplePsa6);
            sampleAddresses.Add(samplePsa7);
            sampleAddresses.Add(samplePsa8);
            sampleAddresses.Add(samplePsa9);
            sampleAddresses.Add(samplePsa10);

            // only 1 content is set, because per content, whole list is encoded
            var m = Utils2.CreateDummyMessage();

            m.SetPeerSocketAddresses(sampleAddresses);
            return(m);
        }
コード例 #13
0
        private static Message CreateMessageSetTrackerData()
        {
            var sampleAddress1 = new PeerAddress(_sample160_1, IPAddress.Parse("192.168.1.1"));
            var sampleAddress2 = new PeerAddress(_sample160_2, IPAddress.Parse("255.255.255.255"));
            var sampleAddress3 = new PeerAddress(_sample160_3, IPAddress.Parse("127.0.0.1"));
            var sampleAddress4 = new PeerAddress(_sample160_4, IPAddress.Parse("0:1:2:3:4:5:6:7"));
            var sampleAddress5 = new PeerAddress(_sample160_5, IPAddress.Parse("7:6:5:4:3:2:1:0"));

            IDictionary <PeerAddress, Data> sampleMap1 = new Dictionary <PeerAddress, Data>();

            sampleMap1.Add(sampleAddress1, _sampleData1);
            sampleMap1.Add(sampleAddress2, _sampleData2);
            sampleMap1.Add(sampleAddress3, _sampleData3);

            IDictionary <PeerAddress, Data> sampleMap2 = new Dictionary <PeerAddress, Data>();

            sampleMap2.Add(sampleAddress2, _sampleData1);
            sampleMap2.Add(sampleAddress3, _sampleData2);
            sampleMap2.Add(sampleAddress4, _sampleData3);

            IDictionary <PeerAddress, Data> sampleMap3 = new Dictionary <PeerAddress, Data>();

            sampleMap3.Add(sampleAddress3, _sampleData1);
            sampleMap3.Add(sampleAddress4, _sampleData2);
            sampleMap3.Add(sampleAddress5, _sampleData3);

            var m = Utils2.CreateDummyMessage();

            m.SetTrackerData(new TrackerData(sampleMap1, true));
            m.SetTrackerData(new TrackerData(sampleMap1, false));
            m.SetTrackerData(new TrackerData(sampleMap2, true));
            m.SetTrackerData(new TrackerData(sampleMap2, false));
            m.SetTrackerData(new TrackerData(sampleMap3, true));
            m.SetTrackerData(new TrackerData(sampleMap3, false));
            m.SetTrackerData(new TrackerData(sampleMap1, true));
            m.SetTrackerData(new TrackerData(sampleMap1, false));
            return(m);
        }
コード例 #14
0
        private static Message CreateMessageByteBuffer()
        {
            // write some random bytes
            var buf = AlternativeCompositeByteBuf.CompBuffer();

            for (int i = 0; i < 300; i++)
            {
                switch (i % 3)
                {
                case 0:
                    buf.WriteBytes(_sampleBytes1);
                    break;

                case 1:
                    buf.WriteBytes(_sampleBytes2);
                    break;

                case 2:
                    buf.WriteBytes(_sampleBytes3);
                    break;
                }
            }

            // decompose buffer and use the resulting 8 ByteBufs in the list
            var decoms = buf.Decompose(0, buf.ReadableBytes);

            var m = Utils2.CreateDummyMessage();

            m.SetBuffer(new Buffer(decoms[0]));
            m.SetBuffer(new Buffer(decoms[1]));
            m.SetBuffer(new Buffer(decoms[2]));
            m.SetBuffer(new Buffer(decoms[3]));
            m.SetBuffer(new Buffer(decoms[4]));
            m.SetBuffer(new Buffer(decoms[5]));
            m.SetBuffer(new Buffer(decoms[6]));
            m.SetBuffer(new Buffer(decoms[7]));
            return(m);
        }
コード例 #15
0
        private static Message CreateMessageSetNeighbors()
        {
            var sampleAddress1 = new PeerAddress(_sample160_1, IPAddress.Parse("192.168.1.1"));
            var sampleAddress2 = new PeerAddress(_sample160_2, IPAddress.Parse("255.255.255.255"));
            var sampleAddress3 = new PeerAddress(_sample160_3, IPAddress.Parse("127.0.0.1"));
            var sampleAddress4 = new PeerAddress(_sample160_4, IPAddress.Parse("0:1:2:3:4:5:6:7"));
            var sampleAddress5 = new PeerAddress(_sample160_5, IPAddress.Parse("7:6:5:4:3:2:1:0"));

            ICollection <PeerAddress> sampleNeighbours1 = new List <PeerAddress>();

            sampleNeighbours1.Add(sampleAddress1);
            sampleNeighbours1.Add(sampleAddress2);
            sampleNeighbours1.Add(sampleAddress3);

            ICollection <PeerAddress> sampleNeighbours2 = new List <PeerAddress>();

            sampleNeighbours2.Add(sampleAddress2);
            sampleNeighbours2.Add(sampleAddress3);
            sampleNeighbours2.Add(sampleAddress4);

            ICollection <PeerAddress> sampleNeighbours3 = new List <PeerAddress>();

            sampleNeighbours3.Add(sampleAddress3);
            sampleNeighbours3.Add(sampleAddress4);
            sampleNeighbours3.Add(sampleAddress5);

            var m = Utils2.CreateDummyMessage();

            m.SetNeighborSet(new NeighborSet(-1, sampleNeighbours1));
            m.SetNeighborSet(new NeighborSet(-1, sampleNeighbours2));
            m.SetNeighborSet(new NeighborSet(-1, sampleNeighbours3));
            m.SetNeighborSet(new NeighborSet(-1, sampleNeighbours1));
            m.SetNeighborSet(new NeighborSet(-1, sampleNeighbours2));
            m.SetNeighborSet(new NeighborSet(-1, sampleNeighbours3));
            m.SetNeighborSet(new NeighborSet(-1, sampleNeighbours1));
            m.SetNeighborSet(new NeighborSet(-1, sampleNeighbours2));
            return(m);
        }