コード例 #1
0
 public SimulationEdgeListener(int id, double loss_prob, TAAuthorizer ta_auth, bool use_delay) :
     this(id, loss_prob, ta_auth, use_delay, TransportAddress.TAType.S,
          new PublicNat(TransportAddressFactory.CreateInstance(
                            String.Format("b.{0}://{1}",
                                          TransportAddress.TATypeToString(TransportAddress.TAType.S), id))))
 {
 }
コード例 #2
0
        public void Init()
        {
            Console.WriteLine("Initializing...");
            ArrayList RemoteTA = new ArrayList();

            for (int i = 0; i < network_size; i++)
            {
                RemoteTA.Add(TransportAddressFactory.CreateInstance("brunet.udp://127.0.0.1:" + (base_port + i)));
            }

            for (int i = 0; i < network_size; i++)
            {
                Address addr = (Address) new AHAddress(new RNGCryptoServiceProvider());
                Node    node = new StructuredNode((AHAddress)addr, brunet_namespace);
                nodes.Add(addr, node);
                node.AddEdgeListener(new UdpEdgeListener(base_port + i));
                node.RemoteTAs = RemoteTA;
                tables[addr]   = new TableServer(node);
                (new Thread(node.Connect)).Start();
//        if(i < network_size / ((Dht)dhts.GetByIndex(i)).DEGREE) {
//          ((Dht)dhts.GetByIndex(i)).debug = true;
//        }
            }
            default_dht = new Dht((Node)nodes.GetByIndex(0), degree);
        }
コード例 #3
0
        static public Node AddNode(Simulator sim, NatTypes type0, NatTypes type1, bool relay)
        {
            Node node = sim.AddNode();

            NatFactory.AddNat(node.EdgeListenerList, type0);

            if (relay)
            {
                Relay.IRelayOverlap ito = new Relay.SimpleRelayOverlap();
                EdgeListener        el  = new Relay.RelayEdgeListener(node, ito);
                node.AddEdgeListener(el);
                el.Start();
            }

            if (type1 != NatTypes.Disabled)
            {
                NodeMapping            nm  = sim.Nodes[node.Address];
                int                    id  = nm.ID;
                string                 tas = SimulationTransportAddress.GetString(TransportAddress.TAType.SO, id);
                INat                   nat = GetNat(TransportAddressFactory.CreateInstance(tas), type1);
                SimulationEdgeListener el  = new SimulationEdgeListener(id, 0, null,
                                                                        true, TransportAddress.TAType.SO, nat);
                node.AddEdgeListener(el);
                el.Start();
            }
            return(node);
        }
コード例 #4
0
        public void Test()
        {
            string           ta_string = "brunet.tunnel://UBU72YLHU5C3SY7JMYMJRTKK4D5BGW22/FE4QWASN+FE4QWASM";
            TransportAddress ta        = TransportAddressFactory.CreateInstance("brunet.tunnel://UBU72YLHU5C3SY7JMYMJRTKK4D5BGW22/FE4QWASN+FE4QWASM");

            Assert.AreEqual(ta.ToString(), ta_string, "testing tunnel TA parsing");
            //Console.WriteLine(ta);

            RelayTransportAddress tun_ta = (RelayTransportAddress)TransportAddressFactory.CreateInstance("brunet.tunnel://OIHZCNNUAXTLLARQIOBNCUWXYNAS62LO/CADSL6GV+CADSL6GU");

            ArrayList fwd = new ArrayList();

            fwd.Add(new AHAddress(Base32.Decode("CADSL6GVVBM6V442CETP4JTEAWACLC5A")));
            fwd.Add(new AHAddress(Base32.Decode("CADSL6GUVBM6V442CETP4JTEAWACLC5A")));

            RelayTransportAddress test_ta = new RelayTransportAddress(tun_ta.Target, fwd);

            Assert.AreEqual(tun_ta, test_ta, "testing tunnel TA compression enhancements");
            //Console.WriteLine(tun_ta.ToString());
            //Console.WriteLine(test_ta.ToString());
            Assert.AreEqual(tun_ta.ToString(), test_ta.ToString(), "testing tunnel TA compression enhancements (toString)");

            Assert.AreEqual(tun_ta.ContainsForwarder(new AHAddress(Base32.Decode("CADSL6GVVBM6V442CETP4JTEAWACLC5A"))), true,
                            "testing tunnel TA contains forwarder (1)");

            Assert.AreEqual(tun_ta.ContainsForwarder(new AHAddress(Base32.Decode("CADSL6GUVBM6V442CETP4JTEAWACLC5A"))), true,
                            "testing tunnel TA contains forwarder (2)");
        }
コード例 #5
0
        public void Test()
        {
            SimulationTransportAddress.Enable();
            SimulationTransportAddressOther.Enable();
            TransportAddress tas = TransportAddressFactory.CreateInstance("b.s://234580");

            Assert.AreEqual(tas.ToString(), "b.s://234580", "Simulation string");
            Assert.AreEqual((tas as SimulationTransportAddress).ID, 234580, "Simulation id");
            Assert.AreEqual(TransportAddress.TAType.S, tas.TransportAddressType, "Simulation ta type");

            TransportAddress taso = TransportAddressFactory.CreateInstance("b.so://234580");

            Assert.AreEqual(taso.ToString(), "b.so://234580", "Simulation string");
            Assert.AreEqual((taso as SimulationTransportAddressOther).ID, 234580, "Simulation id");
            Assert.AreEqual(TransportAddress.TAType.SO, taso.TransportAddressType, "Simulation ta type");

            Assert.AreNotEqual(taso, tas, "TAs not equal");
            Assert.AreNotEqual(taso.TransportAddressType, tas.TransportAddressType, "Type not equal");

            var tas1 = TransportAddressFactory.CreateInstance("b.s://-234581");

            Assert.AreEqual(-234581, (tas1 as SimulationTransportAddress).ID);
            var tas2 = (tas as SimulationTransportAddress).Invert();

            Assert.AreEqual(tas1, tas2, "Invert equal");
        }
コード例 #6
0
ファイル: NodeInfo.cs プロジェクト: ikaragkiozoglou/brunet
        public void TestWriteAndParse()
        {
            RandomNumberGenerator rng = new RNGCryptoServiceProvider();
            Address          a        = new AHAddress(rng);
            TransportAddress ta       = TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:5000");
            NodeInfo         ni       = NodeInfo.CreateInstance(a, ta);

            RoundTripHT(ni);
            RoundTrip(ni);

            //Test multiple tas:
            ArrayList tas = new ArrayList();

            tas.Add(ta);
            for (int i = 5001; i < 5010; i++)
            {
                tas.Add(TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:" + i.ToString()));
            }
            NodeInfo ni3 = NodeInfo.CreateInstance(a, tas);

            RoundTripHT(ni3);
            RoundTrip(ni3);

            //Test null address:
            NodeInfo ni4 = NodeInfo.CreateInstance(null, ta);

            RoundTripHT(ni4);
            RoundTrip(ni4);

            //No TAs:
            NodeInfo ni5 = NodeInfo.CreateInstance(a);

            RoundTripHT(ni5);
            RoundTrip(ni5);
        }
コード例 #7
0
ファイル: NodeInfo.cs プロジェクト: ikaragkiozoglou/brunet
        public static NodeInfo CreateInstance(IDictionary d)
        {
            Address address = null;
            IList   tas;
            object  addr_str = d["address"];

            if (addr_str != null)
            {
                address = AddressParser.Parse((string)addr_str);
            }
            IList trans = d["transports"] as IList;

            if (trans != null)
            {
                int count = trans.Count;
                tas = new TransportAddress[count];
                for (int i = 0; i < count; i++)
                {
                    tas[i] = TransportAddressFactory.CreateInstance((string)trans[i]);
                }
                NodeInfo ni = CreateInstance(address, tas);
                return(ni);
            }
            else
            {
                NodeInfo ni = CreateInstance(address);
                return(ni);
            }
        }
コード例 #8
0
        public void SMTest()
        {
            Address          a  = new DirectionalAddress(DirectionalAddress.Direction.Left);
            TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:5000");
            NodeInfo         ni = NodeInfo.CreateInstance(a, ta);

            //Test with one neighbor:
            ArrayList neighbors = new ArrayList();

            neighbors.Add(ni);
            StatusMessage sm1 = new StatusMessage(ConnectionType.Structured, neighbors);

            RoundTripHT(sm1);
            //Console.Error.WriteLine("\n{0}\n", sm1);
            //Test with many neighbors:

            for (int i = 5001; i < 5010; i++)
            {
                neighbors.Add(NodeInfo.CreateInstance(a,
                                                      TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:"
                                                                                             + i.ToString())));
            }
            StatusMessage sm2 = new StatusMessage(ConnectionType.Unstructured, neighbors);

            RoundTripHT(sm2);
            //Console.Error.WriteLine("\n{0}\n", sm2);

            //Here is a StatusMessage with no neighbors (that has to be a possibility)
            StatusMessage sm3 = new StatusMessage("structured", new ArrayList());

            RoundTripHT(sm3);
            //Console.Error.WriteLine("\n{0}\n", sm3);
        }
コード例 #9
0
ファイル: SimulationEdge.cs プロジェクト: kingctan/brunet
        protected TransportAddress GetTransportAddress(int id)
        {
            string tas = String.Format("b.{0}://{1}",
                                       TransportAddress.TATypeToString(TAType), id);

            return(TransportAddressFactory.CreateInstance(tas));
        }
コード例 #10
0
        protected void Start()
        {
            _start = true;
            for (int i = 0; i < _parameters.Size; i++)
            {
                AddNode();
            }

            TransportAddress broken_ta = TransportAddressFactory.CreateInstance("b.s://" + 0);

            for (int idx = 0; idx < Nodes.Count; idx++)
            {
                NodeMapping nm   = Nodes.Values[idx];
                var         tas  = new List <TransportAddress>();
                int         cidx = idx + 1;
                cidx = cidx == Nodes.Count ? 0 : cidx;
                tas.Add(Nodes.Values[cidx].Node.LocalTAs[0]);
                if (_broken != 0)
                {
                    tas.Add(broken_ta);
                }
                nm.Node.RemoteTAs = tas;
            }
            foreach (NodeMapping nm in Nodes.Values)
            {
                nm.Node.Connect();
            }
            _start = false;
        }
コード例 #11
0
ファイル: PathEdgeListener.cs プロジェクト: pcbing/brunet
        /** return the base TransportAddress and the path associated with it
         */
        public static TransportAddress SplitPath(TransportAddress ta, out string path)
        {
            Uri orig_u = ta.Uri;

            path = orig_u.AbsolutePath;
            string base_uri = String.Format("{0}://{1}", orig_u.Scheme, orig_u.Authority);

            return(TransportAddressFactory.CreateInstance(base_uri));
        }
コード例 #12
0
ファイル: NodeInfo.cs プロジェクト: ikaragkiozoglou/brunet
        public void CacheTest()
        {
            RandomNumberGenerator rng = new RNGCryptoServiceProvider();
            Address          a        = new AHAddress(rng);
            Address          a2       = new AHAddress(a.ToMemBlock());
            TransportAddress ta       = TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:5000");
            TransportAddress ta2      = TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:5000");
            NodeInfo         ni       = NodeInfo.CreateInstance(a, ta);
            NodeInfo         ni2      = NodeInfo.CreateInstance(a2, ta2);

            Assert.AreSame(ni, ni2, "Reference equality of NodeInfo objects");
        }
コード例 #13
0
ファイル: LinkMessage.cs プロジェクト: ikaragkiozoglou/brunet
        public void LMSerializationTest()
        {
            NodeInfo n1 = NodeInfo.CreateInstance(null, TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:45"));
            RandomNumberGenerator rng     = new RNGCryptoServiceProvider();
            AHAddress             tmp_add = new AHAddress(rng);
            LinkMessage           l1      = new LinkMessage(ConnectionType.Structured, n1,
                                                            NodeInfo.CreateInstance(new DirectionalAddress(DirectionalAddress.Direction.Left),
                                                                                    TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:837")), string.Empty,
                                                            tmp_add.ToString());

            RoundTripHT(l1);
        }
コード例 #14
0
        public void Test()
        {
            SubringTransportAddress sta = new SubringTransportAddress(
                new AHAddress(Base32.Decode("CADSL6GVVBM6V442CETP4JTEAWACLC5A")),
                "ns.ns0.ns1");
            string           ta_string = "brunet.subring://CADSL6GVVBM6V442CETP4JTEAWACLC5A.ns.ns0.ns1";
            TransportAddress ta        = TransportAddressFactory.CreateInstance(ta_string);

            Assert.AreEqual(ta, sta, "TA == STA -- 1");

            ta_string = "brunet.subring://CADSL6GVVBM6V442CETP4JTEAWACLC5A.ns.ns0.ns1/";
            ta        = TransportAddressFactory.CreateInstance(ta_string);
            Assert.AreEqual(ta, sta, "TA == STA -- 2");
        }
コード例 #15
0
        public void WrapperEdgeRegressionTest()
        {
            AHAddress        addr  = new AHAddress(new System.Security.Cryptography.RNGCryptoServiceProvider());
            TransportAddress ta    = TransportAddressFactory.CreateInstance("brunet.tcp://169.0.5.1:5000");
            FakeEdge         fe    = new FakeEdge(ta, ta);
            WrapperEdge      we_fe = new WrapperEdge(fe);
            Connection       fcon  = new Connection(we_fe, addr, "structured", null, null);

            List <Connection> overlap = new List <Connection>();

            overlap.Add(fcon);
            RelayTransportAddress tta    = new RelayTransportAddress(addr, overlap);
            RelayEdge             te1    = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap);
            WrapperEdge           we_te1 = new WrapperEdge(te1);
            Connection            t1con  = new Connection(we_te1, addr, "structured", null, null);

            overlap = new List <Connection>();
            overlap.Add(t1con);
            RelayEdge   te2    = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap);
            WrapperEdge we_te2 = new WrapperEdge(te2);
            Connection  t2con  = new Connection(we_te2, addr, "structured", null, null);

            overlap = new List <Connection>();
            overlap.Add(t2con);
            RelayEdge   te3    = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap);
            WrapperEdge we_te3 = new WrapperEdge(te3);
            Connection  t3con  = new Connection(we_te3, addr, "structured", null, null);

            overlap = new List <Connection>();
            overlap.Add(t3con);
            RelayEdge   te4    = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap);
            WrapperEdge we_te4 = new WrapperEdge(te4);
            Connection  t4con  = new Connection(we_te4, addr, "structured", null, null);

            overlap = new List <Connection>();
            overlap.Add(t4con);
            RelayEdge   te5    = new RelayEdge(null, tta, tta, new SimpleForwarderSelector(), overlap);
            WrapperEdge we_te5 = new WrapperEdge(te5);
            Connection  t5con  = new Connection(we_te5, addr, "structured", null, null);

            Assert.AreEqual(te5.ShouldClose(), false, "Shouldn't close yet...");
            te1.DisconnectionHandler(fcon);
            Assert.AreEqual(te5.ShouldClose(), true, "Should close...");

            overlap.Add(t5con);
            overlap.Add(t3con);
            overlap.Add(t1con);
            te2.UpdateNeighborIntersection(overlap);
            Assert.AreEqual(te5.ShouldClose(), true, "Should close... 2");
        }
コード例 #16
0
ファイル: PathEdgeListener.cs プロジェクト: pcbing/brunet
        /** Join a path to the end of a TransportAddress
         */
        public static TransportAddress JoinPath(TransportAddress ta, string path)
        {
            Uri    orig_u = ta.Uri;
            string s      = orig_u.ToString();

            if (s[s.Length - 1] == '/')
            {
                s = s.Substring(0, s.Length - 1);
            }
            if (path[0] == '/')
            {
                path = path.Substring(1);
            }
            return(TransportAddressFactory.CreateInstance(String.Format("{0}/{1}", s, path)));
        }
コード例 #17
0
        protected virtual ArrayList GetRemoteTAs()
        {
            ArrayList RemoteTAs = new ArrayList();

            for (int i = 0; i < 5 && i < TakenIDs.Count; i++)
            {
                int rid = (int)TakenIDs.GetByIndex(_rand.Next(0, TakenIDs.Count));
                RemoteTAs.Add(TransportAddressFactory.CreateInstance("b.s://" + rid));
            }
            if (_broken != 0)
            {
                RemoteTAs.Add(TransportAddressFactory.CreateInstance("b.s://" + 0));
            }

            return(RemoteTAs);
        }
コード例 #18
0
        /// <summary>Return a small list of random TAs.</summary>
        protected virtual List <TransportAddress> GetRemoteTAs()
        {
            var RemoteTAs = new List <TransportAddress>();

            for (int i = 0; i < 5 && i < TakenIDs.Count; i++)
            {
                int rid = TakenIDs.Keys[_rand.Next(0, TakenIDs.Count)];
                RemoteTAs.Add(TransportAddressFactory.CreateInstance("b.s://" + rid));
            }
            if (_broken != 0)
            {
                RemoteTAs.Add(TransportAddressFactory.CreateInstance("b.s://" + 0));
            }

            return(RemoteTAs);
        }
コード例 #19
0
        public void CTMSerializationTest()
        {
            Address          a  = new DirectionalAddress(DirectionalAddress.Direction.Left);
            TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:5000");
            NodeInfo         ni = NodeInfo.CreateInstance(a, ta);

            RandomNumberGenerator rng     = new RNGCryptoServiceProvider();
            AHAddress             tmp_add = new AHAddress(rng);
            ConnectToMessage      ctm1    = new ConnectToMessage(ConnectionType.Unstructured, ni, tmp_add.ToString());

            HTRoundTrip(ctm1);

            //Test multiple tas:
            ArrayList tas = new ArrayList();

            tas.Add(ta);
            for (int i = 5001; i < 5010; i++)
            {
                tas.Add(TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:" + i.ToString()));
            }
            NodeInfo ni2 = NodeInfo.CreateInstance(a, tas);

            ConnectToMessage ctm2 = new ConnectToMessage(ConnectionType.Structured, ni2, tmp_add.ToString());

            HTRoundTrip(ctm2);
            //Here is a ConnectTo message with a neighbor list:
            NodeInfo[] neighs = new NodeInfo[5];
            for (int i = 0; i < 5; i++)
            {
                string   ta_tmp = "brunet.tcp://127.0.0.1:" + (i + 80).ToString();
                NodeInfo tmp    =
                    NodeInfo.CreateInstance(new DirectionalAddress(DirectionalAddress.Direction.Left),
                                            TransportAddressFactory.CreateInstance(ta_tmp)
                                            );
                neighs[i] = tmp;
            }
            ConnectToMessage ctm3 = new ConnectToMessage("structured", ni, neighs, tmp_add.ToString());

            HTRoundTrip(ctm3);
#if false
            Console.Error.WriteLine(ctm3.ToString());
            foreach (NodeInfo tni in ctm3a.Neighbors)
            {
                Console.Error.WriteLine(tni.ToString());
            }
#endif
        }
コード例 #20
0
        public void LMSerializationTest()
        {
            NodeInfo n1 = NodeInfo.CreateInstance(null, TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:45"));
            RandomNumberGenerator rng     = new RNGCryptoServiceProvider();
            AHAddress             tmp_add = new AHAddress(rng);
            LinkMessage           l1      = new LinkMessage(ConnectionType.Structured, n1,
                                                            NodeInfo.CreateInstance(new DirectionalAddress(DirectionalAddress.Direction.Left),
                                                                                    TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:837")), tmp_add.ToString());

            RoundTripHT(l1);
            StringDictionary attrs = new StringDictionary();

            attrs["realm"] = "test_realm";
            attrs["type"]  = "structured.near";
            LinkMessage l3 = new LinkMessage(attrs, n1, n1, tmp_add.ToString());

            RoundTripHT(l3);
        }
コード例 #21
0
        public void Test()
        {
            TransportAddress ta =
                TransportAddressFactory.CreateInstance("brunet.tcp://169.0.5.1:5000");
            FakeEdge fe   = new FakeEdge(ta, ta);
            var      rng  = new System.Security.Cryptography.RNGCryptoServiceProvider();
            var      cons = new List <Connection>();

            for (int i = 0; i < 50; i++)
            {
                var addr = new AHAddress(rng);
                cons.Add(new Connection(fe, addr, "structured", null, null));
            }

            var start_addr = new AHAddress(rng);
            IComparer <Connection> distance_comparer =
                new BroadcastSender.AbsoluteDistanceComparer(start_addr);

            cons.Sort(distance_comparer);
            BigInteger current_distance = new BigInteger(0);

            foreach (Connection con in cons)
            {
                AHAddress  addr          = con.Address as AHAddress;
                BigInteger next_distance = start_addr.DistanceTo(addr).abs();
                Assert.IsTrue(current_distance < next_distance, "DistanceComparer");
                current_distance = next_distance;
            }

            IComparer <Connection> address_comparer =
                new BroadcastSender.LeftDistanceComparer(start_addr);

            cons.Sort(address_comparer);
            current_distance = new BigInteger(0);
            foreach (Connection con in cons)
            {
                AHAddress  addr          = con.Address as AHAddress;
                BigInteger next_distance = start_addr.LeftDistanceTo(addr).abs();
                Assert.IsTrue(current_distance < next_distance, "AddressComparer");
                current_distance = next_distance;
            }
        }
コード例 #22
0
        protected void HandleGetInformation(Object o, EventArgs ea)
        {
            Channel   queue = (Channel)o;
            Hashtable ht    = null;

            try {
                RpcResult rpc_reply = (RpcResult)queue.Dequeue();
                ht = (Hashtable)rpc_reply.Result;
            }
            catch {
                // Remote end point doesn't have LocalCO enabled.
                return;
            }

            try {
                string remote_realm = (string)ht["namespace"];
                if (!remote_realm.Equals(_node.Realm))
                {
                    return;
                }
                ArrayList string_tas = (ArrayList)ht["tas"];
                ArrayList remote_tas = new ArrayList();
                foreach (string ta in string_tas)
                {
                    remote_tas.Add(TransportAddressFactory.CreateInstance(ta));
                }
                _node.UpdateRemoteTAs(remote_tas);

                AHAddress new_address = (AHAddress)AddressParser.Parse((string)ht["address"]);
                lock (_sync) {
                    int pos = _local_addresses.BinarySearch(new_address, addr_compare);
                    if (pos < 0)
                    {
                        pos = ~pos;
                        _local_addresses.Insert(pos, new_address);
                    }
                }
            }
            catch (Exception e) {
                ProtocolLog.WriteIf(ProtocolLog.Exceptions, "Unexpected exception: " + e);
            }
        }
コード例 #23
0
        public void Test()
        {
            SimulationTransportAddress.Enable();
            SimulationTransportAddressOther.Enable();
            var ta  = TransportAddressFactory.CreateInstance("b.s://234580") as SimulationTransportAddress;
            var tai = ta.Invert();

            TransportAddress[] tas = new TransportAddress[2] {
                tai, ta
            };
            var ta_oth  = TransportAddressFactory.CreateInstance("b.s://234581");
            var ta_oth0 = TransportAddressFactory.CreateInstance("b.s://234582");
            var nat     = new SymmetricNat(ta, 30000);

            Assert.IsFalse(nat.Incoming(ta_oth), "No outbound yet...");
            Assert.IsTrue(nat.Outgoing(ta_oth), "outbound...");
            Assert.IsFalse(nat.AllowingIncomingConnections, "SymmetricNat does not allow incoming cons");
            Assert.AreEqual(nat.InternalTransportAddresses, nat.KnownTransportAddresses, "ITA and KTA match");

            nat.UpdateTAs(ta_oth, ta);
            Assert.IsTrue(nat.Incoming(ta_oth), "Allowed incoming");
            Assert.IsFalse(nat.Incoming(ta_oth0), "Port mapped systems must send out a packet first...");
            Assert.IsFalse(nat.AllowingIncomingConnections, "SymmetricNat does not allow incoming cons");
            Assert.AreEqual(tas, nat.KnownTransportAddresses, "Two TAs!");
            Assert.IsTrue(nat.Outgoing(ta_oth0), "outbound...");

            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Assert.IsFalse(nat.AllowingIncomingConnections, "SymmetricNat does not allow incoming cons");
            Assert.AreEqual(tas, nat.KnownTransportAddresses, "Two TAs!");

            Brunet.Util.SimpleTimer.RunSteps(60000);
            Assert.IsFalse(nat.AllowingIncomingConnections, "SymmetricNat does not allow incoming cons");
            Assert.IsFalse(nat.Incoming(ta_oth), "Incoming:  Timed out....");
        }
コード例 #24
0
ファイル: ConeNat.cs プロジェクト: kingctan/brunet
        public void Test()
        {
            SimulationTransportAddress.Enable();
            SimulationTransportAddressOther.Enable();
            var ta  = TransportAddressFactory.CreateInstance("b.s://234580") as SimulationTransportAddress;
            var tai = ta.Invert();

            TransportAddress[] tas = new TransportAddress[2] {
                tai, ta
            };
            var     ta_oth  = TransportAddressFactory.CreateInstance("b.s://234581");
            var     ta_oth0 = TransportAddressFactory.CreateInstance("b.s://234582");
            ConeNat nat     = new ConeNat(ta, 30000);

            Assert.IsFalse(nat.Incoming(ta_oth), "No outbound yet...");
            Assert.IsTrue(nat.Outgoing(ta_oth), "outbound...");
            Assert.IsFalse(nat.AllowingIncomingConnections, "Have not received external ta.");
            Assert.AreEqual(nat.InternalTransportAddresses, nat.KnownTransportAddresses, "ITA and KTA match");

            nat.UpdateTAs(ta_oth, ta);
            Assert.IsTrue(nat.Incoming(ta_oth), "Allowed incoming");
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Assert.IsTrue(nat.AllowingIncomingConnections, "Have received external ta.");
            Assert.AreEqual(tas, nat.KnownTransportAddresses, "Two TAs!");

            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Brunet.Util.SimpleTimer.RunSteps(7500);
            Assert.IsTrue(nat.Incoming(ta_oth0), "Allowed incoming 0");
            Assert.IsTrue(nat.AllowingIncomingConnections, "Have received external ta.");
            Assert.AreEqual(tas, nat.KnownTransportAddresses, "Two TAs!");

            Brunet.Util.SimpleTimer.RunSteps(60000);
            Assert.IsFalse(nat.AllowingIncomingConnections, "AllowIC:  Timed out...");
            Assert.IsFalse(nat.Incoming(ta_oth), "Incoming:  Timed out....");
        }
コード例 #25
0
ファイル: TunnelOverlap.cs プロジェクト: pcbing/brunet
        public void Test()
        {
            ITunnelOverlap _ito   = new SimpleTunnelOverlap();
            Address        addr_x = new AHAddress(new RNGCryptoServiceProvider());

            byte[] addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (Address.Full / 2));
            Address.SetClass(addrbuff, AHAddress._class);
            Address addr_y = new AHAddress(addrbuff);

            ArrayList       addresses = new ArrayList();
            ConnectionTable ct_x      = new ConnectionTable();
            ConnectionTable ct_y      = new ConnectionTable();
            ConnectionTable ct_empty  = new ConnectionTable();

            for (int i = 1; i <= 10; i++)
            {
                addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (i * Address.Full / 16));
                Address.SetClass(addrbuff, AHAddress._class);
                addresses.Add(new AHAddress(addrbuff));

                TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://158.7.0.1:5000");
                Edge             fe = new FakeEdge(ta, ta, TransportAddress.TAType.Tcp);
                ct_x.Add(new Connection(fe, addresses[i - 1] as AHAddress, "structured", null, null));
                if (i == 10)
                {
                    ct_y.Add(new Connection(fe, addresses[i - 1] as AHAddress, "structured", null, null));
                }
            }


            ConnectionType con_type = ConnectionType.Structured;
            IDictionary    id       = _ito.GetSyncMessage(null, addr_x, ct_x.GetConnections(con_type));

            Assert.AreEqual(_ito.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0].Address, addresses[9], "Have an overlap!");
            Assert.AreEqual(_ito.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!");
            Assert.AreEqual(addresses.Contains(_ito.EvaluatePotentialOverlap(id)), true, "EvaluatePotentialOverlap returns valid!");
        }
コード例 #26
0
ファイル: EdgeTester.cs プロジェクト: tristion/brunet
        public static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: edgetester.exe " +
                                  "[client|server] [tcp|udp|function] port " +
                                  "localhost|qubit|cantor|starsky|behnam|kupka)");
                return;
            }

            if (args.Length >= 5)
            {
                delay = Int32.Parse(args[4]);
            }

            EdgeFactory ef   = new EdgeFactory();
            int         port = System.Int16.Parse(args[2]);

            _threads = ArrayList.Synchronized(new ArrayList());
            EdgeListener el = null;

            if (args[1] == "function")
            {
                //This is a special case, it only works in one thread
                el            = new FunctionEdgeListener(port);
                el.EdgeEvent += new EventHandler(HandleEdge);
                //Start listening:
                el.Start();
                ef.AddListener(el);
                el.CreateEdgeTo(
                    TransportAddressFactory.CreateInstance("brunet.function://localhost:" + port),
                    ClientLoop);
            }
            else if (args[0] == "server")
            {
                if (args[1] == "tcp")
                {
                    el = new TcpEdgeListener(port);
                }
                else if (args[1] == "udp")
                {
                    el = new UdpEdgeListener(port);
                }
                else
                {
                    el = null;
                }
                el.EdgeEvent += new EventHandler(HandleEdge);
//Start listening:
                el.Start();
                _el = el;
                Console.WriteLine("Press Q to quit");
                Console.ReadLine();
                el.Stop();
            }
            else if (args[0] == "client")
            {
                TransportAddress ta = null;
                if (args[1] == "tcp")
                {
                    el = new TcpEdgeListener(port + 1);
                }
                else if (args[1] == "udp")
                {
                    el = new UdpEdgeListener(port + 1);
                }
                else
                {
                    el = null;
                }
                ef.AddListener(el);
                _el = el;
                string uri = "brunet." + args[1] + "://" + NameToIP(args[3]) + ":" + port;
                ta = TransportAddressFactory.CreateInstance(uri);
                System.Console.WriteLine("Making edge to {0}\n", ta.ToString());
                el.Start();
                ef.CreateEdgeTo(ta, ClientLoop);
            }
        }
コード例 #27
0
ファイル: BootStrapTester.cs プロジェクト: tristion/brunet
        static void Main(string[] args)
        {
            RandomNumberGenerator rng = new RNGCryptoServiceProvider();

            //Initialize hosts
            Console.WriteLine("\n\n---------------------------------------\n\n");
            int    port     = 20287;
            int    net_size = 3;
            string net_type = "function";

            if (args.Length > 0)
            {
                net_size = Int32.Parse(args[0]);
            }
            if (args.Length > 1)
            {
                net_type = args[1];
            }
            int ms_sleep = 0;

            if (args.Length > 2)
            {
                ms_sleep = Int32.Parse(args[2]);
            }
            bool wait_after_connect = true;

            if (args.Length > 3)
            {
                ///@todo we really need better option parsing here
                wait_after_connect = false;
            }
            ArrayList     node_list   = new ArrayList();
            Hashtable     add_to_node = new Hashtable();
            PathELManager pem         = null;

            for (int loop = 0; loop < net_size; loop++)
            {
                //create and initialize new host
                //create one new node for each host
                AHAddress tmp_add  = new AHAddress(rng);
                Node      tmp_node = new StructuredNode(tmp_add, "bstland");
                //Node tmp_node = new HybridNode(tmp_add, "bstland");

                node_list.Add(tmp_node);
                add_to_node[tmp_add] = tmp_node;

                //long small_add = 2*(loop+1);
                //Node tmp_node = new StructuredNode(new AHAddress( new BigInteger(small_add)) );
                PType path_p = PType.Protocol.Pathing;
                switch (net_type)
                {
                case "tcp":
                    tmp_node.AddEdgeListener(new TcpEdgeListener(port + loop));
                    break;

                case "udp":
                    tmp_node.AddEdgeListener(new UdpEdgeListener(port + loop));
                    break;

                case "function":
                    tmp_node.AddEdgeListener(new FunctionEdgeListener(port + loop));
                    break;

                case "path":
                    if (pem == null)
                    {
                        EdgeListener el = new UdpEdgeListener(port);
                        pem = new PathELManager(el);
                        pem.Start();
                    }
                    //Pass path messages to the pem:
                    tmp_node.DemuxHandler.GetTypeSource(path_p).Subscribe(pem, path_p);
                    tmp_node.AddEdgeListener(pem.CreatePath((port + loop).ToString()));
                    Console.WriteLine(port + loop);
                    break;

                case "single_path":
                    EdgeListener myel = new UdpEdgeListener(port + loop);
                    //Test "default" path edge listener:
                    pem = new PathELManager(myel);
                    pem.Start();
                    tmp_node.DemuxHandler.GetTypeSource(path_p).Subscribe(pem, path_p);
                    //Make the default path:
                    tmp_node.AddEdgeListener(pem.CreateRootPath());
                    break;

                default:
                    throw new Exception("Unknown net type: " + net_type);
                }
                //tmp_node.AddEdgeListener(new FunctionEdgeListener(port+loop));
                for (int loop2 = 0; loop2 < net_size; loop2++)
                {
                    if (loop == loop2)
                    {
                        continue;
                    }
                    int    other_port = port + loop2;
                    string ta_str     = null;
                    switch (net_type)
                    {
                    case "tcp":
                        ta_str = "brunet.tcp://127.0.0.1:";
                        break;

                    case "udp":
                        ta_str = "brunet.udp://127.0.0.1:";
                        break;

                    case "function":
                        ta_str = "brunet.function://localhost:";
                        break;

                    case "path":
                        ta_str = String.Format("brunet.udp://127.0.0.1:{0}/", port);
                        break;

                    case "single_path":
                        ta_str = "brunet.udp://127.0.0.1:";
                        break;

                    default:
                        throw new Exception("Unknown net type: " + net_type);
                    }
                    ta_str = ta_str + other_port.ToString();
                    TransportAddress this_ta = TransportAddressFactory.CreateInstance(ta_str);
                    tmp_node.RemoteTAs.Add(this_ta);
                }
            }

            //This logs the changes in connection table
            BootStrapTester bst = new BootStrapTester(node_list);

            if (bst != null)
            {
                //This is just here to prevent a warning for
                //not using bst, which is just an observer
            }
            //Get Connected:
            int       total_started = 0;
            ArrayList rnd_list      = (ArrayList)node_list.Clone();
            Random    rnd           = new Random();

            for (int j = 0; j < rnd_list.Count; j++)
            {
                //Swap the j^th position with this position:
                int i = rnd.Next(j, rnd_list.Count);
                if (i != j)
                {
                    object o = rnd_list[i];
                    rnd_list[i] = rnd_list[j];
                    rnd_list[j] = o;
                }
            }
            ArrayList c_threads = new ArrayList();
            //var xrms = new Brunet.Rpc.XmlRpcManagerServer(20000);
            int cnt = 0;

            foreach (Node item in rnd_list)
            {
                Thread t = new Thread(item.Connect);
                c_threads.Add(t);
                t.Start();
                //xrms.Add(item, "xm" + cnt++ + ".rem");
                Console.WriteLine(item.Address.ToString()
                                  + " RemoteTAs count: " + item.RemoteTAs.Count);
                total_started++;
                Console.WriteLine("Started: " + total_started.ToString());
                //Thread.Sleep(10000);
                Thread.Sleep(ms_sleep);
                //Console.ReadLine();
                //foreach (TransportAddress item2 in item.RemoteTAs)
                //  Console.WriteLine(item2);
            }

            System.Console.Out.WriteLine("Finished with BootStrapTester.Main");
            string[] this_command = new string[] { "Q" };
            if (wait_after_connect)
            {
                Console.WriteLine("Enter Q to stop");
                this_command = Console.ReadLine().Split(' ');
            }
            while (this_command[0] != "Q")
            {
                if (this_command[0] == "D")
                {
                    //Disconnect a node:
                    int node = -1;
                    try {
                        node = Int32.Parse(this_command[1]);
                        Node to_disconnect = (Node)node_list[node];
                        Console.WriteLine("About to Disconnect: {0}", to_disconnect.Address);
                        to_disconnect.Disconnect();
                        bst.Remove(to_disconnect);
                    }
                    catch (Exception) {
                    }
                }
                if (this_command[0] == "abort")
                {
                    //Disconnect a node:
                    int node = -1;
                    try {
                        node = Int32.Parse(this_command[1]);
                        Node to_abort = (Node)node_list[node];
                        Console.WriteLine("About to Abort: {0}", to_abort.Address);
                        to_abort.Abort();
                        bst.Remove(to_abort);
                    }
                    catch (Exception) {
                    }
                }
                if (this_command[0] == "P")
                {
                    //Pick a random pair of nodes to ping:
                    Ping(node_list);
                }
                if (this_command[0] == "BP")
                {
                    try {
                        int reps = Int32.Parse(this_command[1]);
                        bst.BenchmarkPing(reps);
                    }
                    catch (Exception x) {
                        Console.WriteLine(x);
                    }
                }
                if (this_command[0] == "BH")
                {
                    try {
                        int reps = Int32.Parse(this_command[1]);
                        bst.BenchmarkHops(reps);
                    }
                    catch (Exception x) {
                        Console.WriteLine(x);
                    }
                }
                if (this_command[0] == "T")
                {
                    //Pick a random pair of nodes to ping:
                    TraceRoute(node_list);
                }
                if (wait_after_connect)
                {
                    this_command = Console.ReadLine().Split(' ');
                }
            }

            foreach (Node n in node_list)
            {
                n.Disconnect();
            }
            if (pem != null)
            {
                pem.Stop();
            }
            //Block until all Connect threads finish.
            //foreach(Thread t in c_threads) {
            //  t.Join();
            //}
        }
コード例 #28
0
        public static void Main(string [] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("please specify the number edge protocol.");
                Environment.Exit(0);
            }
            if (args.Length < 2)
            {
                Console.WriteLine("please specify the number of p2p nodes.");
                Environment.Exit(0);
            }
            if (args.Length < 3)
            {
                Console.WriteLine("please specify the number of missing edges.");
                Environment.Exit(0);
            }
            string proto = "function";

            try {
                proto = args[0].Trim();
            } catch (Exception) {}

            bool tunnel        = false;
            int  base_port     = 54000;
            int  network_size  = Int32.Parse(args[1]);
            int  missing_count = Int32.Parse(args[2]);

            try {
                tunnel = args[3].Trim().Equals("tunnel");
            } catch (Exception) {}

            Console.WriteLine("use tunnel edges: {0}", tunnel);

            Random rand = new Random();

            ArrayList missing_edges = new ArrayList();

            for (int i = 0; i < missing_count; i++)
            {
                int idx = -1;
                int left, right;
                do
                {
                    idx  = rand.Next(0, network_size);
                    left = (idx + 1) % network_size;
                    if (idx == 0)
                    {
                        right = network_size - 1;
                    }
                    else
                    {
                        right = idx - 1;
                    }
                } while (missing_edges.Contains(idx));// ||
                //missing_edges.Contains(left) ||
                //missing_edges.Contains(right));

                Console.WriteLine("Will drop a left edge on idx {0}: ", idx);
                missing_edges.Add(idx);
            }

            //
            // Sort missing edges.
            //
            missing_edges.Sort();
            SortedList dist = new SortedList();

            //
            // Compute the average distance between missing edges.
            //
            if (missing_count > 1)
            {
                for (int i = 0; i < missing_count; i++)
                {
                    int idx = (int)missing_edges[i];
                    int idx_next;
                    int d;
                    if (i == missing_count - 1)
                    {
                        idx_next = (int)missing_edges[0];
                        d        = (network_size - 1) - idx + idx_next;
                    }
                    else
                    {
                        idx_next = (int)missing_edges[i + 1];
                        d        = idx_next - idx - 1;
                    }
                    if (!dist.Contains(d))
                    {
                        dist[d] = 0;
                    }
                    else
                    {
                        int c = (int)dist[d];
                        dist[d] = c + 1;
                    }
                }
            }
            double sum = 0.0;
            int    num = 0;

            Console.WriteLine("distribution of missing edges separation");
            foreach (DictionaryEntry de in dist)
            {
                int k = (int)de.Key;
                int c = (int)de.Value;
                Console.WriteLine("{0} {1}", k, c);
                sum = sum + k * c;
                num = num + c;
            }

            Console.WriteLine("average separation: {0}", (double)sum / num);
            string brunet_namespace = "testing";

            Console.WriteLine("Initializing...");

            var RemoteTA = new List <TransportAddress>();

            for (int i = 0; i < network_size; i++)
            {
                if (proto.Equals("udp"))
                {
                    RemoteTA.Add(TransportAddressFactory.CreateInstance("brunet.udp://localhost:" + (base_port + i)));
                }
                else if (proto.Equals("function"))
                {
                    RemoteTA.Add(TransportAddressFactory.CreateInstance("brunet.function://localhost:" + (base_port + i)));
                }
            }

            for (int i = 0; i < network_size; i++)
            {
                AHAddress address = new AHAddress(new RNGCryptoServiceProvider());
                Node      node    = new StructuredNode(address, brunet_namespace);
                _sorted_node_list.Add((Address)address, node);
                _node_list.Add(node);
                RouteTestHandler test_handler = new RouteTestHandler();
                node.GetTypeSource(new PType(routing_test)).Subscribe(test_handler, address.ToMemBlock());
                RpcManager rpc_man = node.Rpc;
                rpc_man.AddHandler("rpc_routing_test", new  RpcRoutingTestHandler(node));
            }

            for (int i = 0; i < network_size; i++)
            {
                Node node = (Node)_sorted_node_list.GetByIndex(i);
                Console.WriteLine("Configuring node: {0} ", node.Address);
                TAAuthorizer ta_auth = null;
                if (missing_edges.Contains(i))
                {
                    int remote_port;
                    if (i == network_size - 1)
                    {
                        remote_port = base_port;
                    }
                    else
                    {
                        remote_port = base_port + i + 1;
                    }

                    PortTAAuthorizer port_auth = new PortTAAuthorizer(remote_port);
                    Console.WriteLine("Adding a port TA authorizer at: {0} for remote port: {1}", base_port + i, remote_port);
                    ArrayList arr_tas = new ArrayList();
                    arr_tas.Add(port_auth);
                    arr_tas.Add(new ConstantAuthorizer(TAAuthorizer.Decision.Allow));
                    ta_auth = new SeriesTAAuthorizer(arr_tas);
                }

                if (proto.Equals("udp"))
                {
                    node.AddEdgeListener(new UdpEdgeListener(base_port + i, null, ta_auth));
                }
                else if (proto.Equals("function"))
                {
                    node.AddEdgeListener(new FunctionEdgeListener(base_port + i, -1.00, ta_auth));
                }

                if (tunnel)
                {
                    Console.WriteLine("Adding a tunnel edge listener");
                    node.AddEdgeListener(new Relay.RelayEdgeListener(node));
                }
                _node_to_port[node] = base_port + i;
                node.RemoteTAs      = RemoteTA;
            }

            //start nodes one by one.
            for (int i = 0; i < network_size; i++)
            {
                Node node = (Node)_node_list[i];
                Console.WriteLine("Starting node: {0}, {1}", i, node.Address);
                node.Connect();
                Console.WriteLine("Going to sleep for 2 seconds.");
                System.Threading.Thread.Sleep(2000);
            }

            //wait for 300000 more seconds
            Console.WriteLine("Going to sleep for 300000 seconds.");
            System.Threading.Thread.Sleep(300000);
            bool complete = CheckStatus();

            int count = 0;

            //
            // Send a large number of packets as exact packets to random destinations
            // and make sure exact routing is perfect.
            //

            for (int i = 0; i < network_size; i++)
            {
                for (int j = 0; j < network_size; j++)
                {
                    int  src_idx   = i;
                    int  dest_idx  = j;
                    Node src_node  = (Node)_sorted_node_list.GetByIndex(src_idx);
                    Node dest_node = (Node)_sorted_node_list.GetByIndex(dest_idx);
                    //Console.WriteLine("{0} -> {1}", src_idx, dest_idx);
                    Address  dest_address = (Address)dest_node.Address;
                    ISender  s            = new AHExactSender(src_node, dest_address);
                    MemBlock p            = dest_address.ToMemBlock();
                    s.Send(new CopyList(new PType(routing_test), p));
                    _sent++;
                    //System.Threading.Thread.Sleep(10);
                    s.Send(new CopyList(new PType(routing_test), p));
                    _sent++;
                    //System.Threading.Thread.Sleep(10);
                }
            }
            //wait for 10 more seconds
            Console.WriteLine("Going to sleep for 10 seconds.");
            System.Threading.Thread.Sleep(10000);
            Console.WriteLine("Final statistics");
            lock (_class_lock) {
                Console.WriteLine("Sent: {0}, Received: {1}, Wrongly routed: {2}",
                                  _sent, _received, _wrongly_routed);
            }

            int       missing_rpcs     = 0;
            int       correct_rpcs     = 0;
            int       incorrect_rpcs   = 0;
            Hashtable queue_to_address = new Hashtable();

            for (int i = 0; i < network_size; i++)
            {
                for (int j = 0; j < network_size; j++)
                {
                    int  src_idx   = i;
                    int  dest_idx  = j;
                    Node src_node  = (Node)_sorted_node_list.GetByIndex(src_idx);
                    Node dest_node = (Node)_sorted_node_list.GetByIndex(dest_idx);
                    //Console.WriteLine("{0} -> {1}", src_idx, dest_idx);
                    Address    dest_address = (Address)dest_node.Address;
                    ISender    s            = new AHExactSender(src_node, dest_address);
                    RpcManager rpc_man      = src_node.Rpc;
                    Channel    q            = new Channel();
                    lock (_class_lock) {
                        queue_to_address[q] = dest_address;
                    }
                    q.CloseAfterEnqueue();
                    q.CloseEvent += delegate(object o, EventArgs cargs) {
                        lock (_class_lock) {
                            Channel qu = (Channel)o;
                            if (qu.Count == 0)
                            {
                                missing_rpcs++;
                            }
                            queue_to_address.Remove(qu);
                        }
                    };
                    q.EnqueueEvent += delegate(object o, EventArgs cargs) {
                        lock (_class_lock) {
                            Channel   qu        = (Channel)o;
                            RpcResult rpc_reply = (RpcResult)qu.Peek();
                            byte []   result    = (byte[])rpc_reply.Result;
                            Address   target    = new AHAddress(result);
                            if (target.Equals(queue_to_address[qu]))
                            {
                                correct_rpcs++;
                            }
                            else
                            {
                                incorrect_rpcs++;
                            }
                        }
                    };
                    rpc_man.Invoke(s, q, "rpc_routing_test.GetIdentification", new object[] {});
                }
            }

            //wait for 10 more seconds
            while (true)
            {
                int c = -1;
                lock (_class_lock) {
                    c = incorrect_rpcs + missing_rpcs + correct_rpcs;
                }
                if (c < network_size * network_size)
                {
                    Console.WriteLine("Going to sleep for 10 seconds.");
                    System.Threading.Thread.Sleep(10000);
                }
                else
                {
                    break;
                }
            }

            Console.WriteLine("Final statistics");
            Console.WriteLine("correct rpcs: {0}, incorrect rpcs: {1}, missing rpcs: {2}",
                              correct_rpcs, incorrect_rpcs, missing_rpcs);

            System.Environment.Exit(1);
        }
コード例 #29
0
        public void Test()
        {
            Address addr_x = new AHAddress(new RNGCryptoServiceProvider());

            byte[] addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (Address.Full / 2));
            Address.SetClass(addrbuff, AHAddress._class);
            Address addr_y = new AHAddress(addrbuff);

            List <Connection> connections = new List <Connection>();
            ConnectionTable   ct_x        = new ConnectionTable();
            ConnectionTable   ct_y        = new ConnectionTable();
            ConnectionTable   ct_empty    = new ConnectionTable();
            NCService         ncservice   = new NCService();

            Connection fast_con = null;

            for (int i = 1; i <= 11; i++)
            {
                addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (i * Address.Full / 16));
                Address.SetClass(addrbuff, AHAddress._class);
                Address    addr = new AHAddress(addrbuff);
                Connection con  = null;

                TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://158.7.0.1:5000");
                Edge             fe = new FakeEdge(ta, ta, TransportAddress.TAType.Tcp);
                if (i <= 10)
                {
                    con = new Connection(fe, addr, "structured", null, null);
                    ct_x.Add(con);
                    if (i % 2 == 0)
                    {
                        ncservice.ProcessSample(DateTime.UtcNow, String.Empty, addr,
                                                new Point(new double[] { 0, 0 }, 0), 0, i * 10);
                    }
                }
                else
                {
                    fast_con = new Connection(fe, addr, "structured", null, null);
                    ncservice.ProcessSample(DateTime.UtcNow, String.Empty, addr,
                                            new Point(new double[] { 0, 0 }, 0), 0, 5);
                }

                if (i == 10)
                {
                    ct_y.Add(con);
                }
                connections.Add(con);
            }

            IRelayOverlap sto = new SimpleRelayOverlap();
            IRelayOverlap nto = new NCRelayOverlap(ncservice);

            ConnectionType    con_type = ConnectionType.Structured;
            List <Connection> pre_cons = new List <Connection>();

            pre_cons.Add(connections[9]);
            IDictionary id = nto.GetSyncMessage(pre_cons, addr_x, ct_x.GetConnections(con_type));

            // We do have some pre-existing overlap
            Assert.AreEqual(nto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], connections[9], "NC: Have an overlap!");
            Assert.AreEqual(sto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], connections[9], "Simple: Have an overlap!");

            // We have no overlap with an empty connection table
            Assert.AreEqual(nto.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!");
            Assert.AreEqual(sto.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!");

            // latency[0] == -1
            Assert.AreEqual(connections[1].Address.Equals(nto.EvaluatePotentialOverlap(id)), true,
                            "NC: EvaluatePotentialOverlap returns expected!");
            Assert.AreEqual(ct_x.Contains(con_type, sto.EvaluatePotentialOverlap(id)), true,
                            "Simple: EvaluatePotentialOverlap returns valid!");

            ct_y.Add(fast_con);
            ct_x.Add(fast_con);
            id = nto.GetSyncMessage(pre_cons, addr_x, ct_x.GetConnections(con_type));
            Assert.AreEqual(fast_con.Address.Equals(nto.EvaluatePotentialOverlap(id)), true,
                            "NC: EvaluatePotentialOverlap returns expected!");
            Assert.AreEqual(nto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], fast_con, "NC: Have better overlap!");
        }
コード例 #30
0
    public static int Main(string[] args)
    {
        /**
         * Get the arguments
         */
        if (args.Length < 2)
        {
            Console.Error.WriteLine("usage: SNodeExample.exe [tcp|udp] port remota_ta0 remote_ta1 ...");
            return(0);
        }

        /**
         * Make the edge listener:
         */
        EdgeListener el   = null;
        int          port = Int32.Parse(args[1]);

        if (args[0].ToLower() == "tcp")
        {
            el = new TcpEdgeListener(port);
        }
        else if (args[0].ToLower() == "udp")
        {
            el = new UdpEdgeListener(port);
        }

        /**
         * Create a random address for our node.
         * Some other application might want to select the address
         * a particular way, or reuse a previously selected random
         * address.  If the addresses are not random (or the output
         * of secure hashes) the network might not behave correctly.
         */
        RandomNumberGenerator rng     = new RNGCryptoServiceProvider();
        AHAddress             tmp_add = new AHAddress(rng);

        Console.WriteLine("Address: {0}", tmp_add);

        /**
         * Make the node that lives in a particular
         * using Brunet.Messaging;
         * namespace (or realm) called "testspace"
         */
        Node          tmp_node = new StructuredNode(tmp_add, "testspace");
        ReqrepManager rrman    = tmp_node.Rrm;
        ReqrepExample irh      = new ReqrepExample();

        tmp_node.GetTypeSource(PType.Protocol.Chat).Subscribe(irh, tmp_node);

        /**
         * Add the EdgeListener
         */
        tmp_node.AddEdgeListener(el);

        /**
         * Tell the node who it can connect to:
         */
        for (int i = 2; i < args.Length; i++)
        {
            tmp_node.RemoteTAs.Add(TransportAddressFactory.CreateInstance(args[i]));
        }

        /**
         * Now we connect
         */
        tmp_node.Connect();
        Console.WriteLine("Connected");

        /**
         * In a real application, we would create some IAHPacketHandler
         * objects and do:
         * tmp_node.Subscribe( )
         * finally, we could send packets using tmp_node.Send( ) or
         * tmp_node.SendTo( )
         */
        string msg = "";

        System.Text.Encoding coder = new System.Text.ASCIIEncoding();
        while (true)
        {
            Console.Write("To: ");
            msg = Console.ReadLine();
            if (msg == "q")
            {
                break;
            }
            Address dest = AddressParser.Parse(msg);
            while (msg != ".")
            {
                msg = Console.ReadLine();
                int    length  = coder.GetByteCount(msg);
                byte[] payload = new byte[length];
                coder.GetBytes(msg, 0, msg.Length, payload, 0);
                ISender sender = new AHSender(tmp_node, dest);
                rrman.SendRequest(sender, ReqrepManager.ReqrepType.Request,
                                  new CopyList(PType.Protocol.Chat, MemBlock.Reference(payload)),
                                  irh, null);
            }
        }

        return(1);
    }