Ejemplo n.º 1
0
        public static void Run(RelayOverlapSimulator sim, Address addr1, Address addr2)
        {
            Console.WriteLine("Beginning");
            sim.Complete(false);

            SimpleTimer.RunSteps(1000000, false);
            StructuredNode node1 = (sim.Nodes[addr1] as NodeMapping).Node as StructuredNode;
            StructuredNode node2 = (sim.Nodes[addr2] as NodeMapping).Node as StructuredNode;

            sim.Complete(true);

            ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node1);

            mco.Start();
            node1.AddConnectionOverlord(mco);
            mco.Set(addr2);

            Connection con1 = node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2);

            while (con1 == null)
            {
                SimpleTimer.RunStep();
                con1 = node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2);
            }

            Console.WriteLine(addr1 + "<=>" + addr2 + ":");
            Console.WriteLine("\t" + node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) + "\n");
            sim.FindOverlap(node1, node2);
            node1.Disconnect();
            node2.Disconnect();
            SimpleTimer.RunSteps(100000);
            Console.WriteLine("End");
        }
Ejemplo n.º 2
0
        private void TestNat(Simulator sim, NatTypes n0type0, NatTypes n0type1,
                             NatTypes n1type0, NatTypes n1type1, bool relay)
        {
            string fail_s = String.Format("{0}/{1} and {2}/{3}", n0type0, n0type1,
                                          n1type0, n1type1);
            Node node0 = null;
            Node node1 = null;

            while (true)
            {
                node0 = NatFactory.AddNode(sim, n0type0, n0type1, relay);
                node1 = NatFactory.AddNode(sim, n1type0, n1type1, relay);

                Assert.IsTrue(sim.Complete(true), fail_s + " nodes are connected to the overlay");
                if (!Simulator.AreConnected(node0, node1))
                {
                    break;
                }
            }

            ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node0);

            mco.Start();
            node0.AddConnectionOverlord(mco);
            mco.Set(node1.Address);

            Assert.IsTrue(AreConnected(node0, node1), fail_s + " nodes were unable to connect.");
        }
Ejemplo n.º 3
0
        protected Result DoNatTest(Simulator sim, Node node0, Node node1)
        {
            sim.Complete(true);
//      SimpleTimer.RunSteps(3600000);
            SimpleTimer.RunSteps(600000);
            long     throughput = Throughput(node0.EdgeListenerList) + Throughput(node1.EdgeListenerList);
            DateTime start      = DateTime.UtcNow;

            ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node0);

            mco.Start();
            node0.AddConnectionOverlord(mco);
            mco.Set(node1.Address);

            AreConnected connected = new AreConnected(node0, node1, null);

            connected.Start();
            connected.Run(120);

            long   time           = (DateTime.UtcNow - start).Ticks / TimeSpan.TicksPerMillisecond;
            double avg_throughput = 0;

            if (time > 0)
            {
                throughput = Throughput(node0.EdgeListenerList) +
                             Throughput(node1.EdgeListenerList) - throughput;
                avg_throughput = (1.0 * throughput) / time / 1000;
            }

            sim.Disconnect();
            return(new Result(connected.TATypeAsString, time, avg_throughput));
        }
Ejemplo n.º 4
0
        public StructuredNode(AHAddress add, string realm) : base(add, realm)
        {
            /**
             * Here are the ConnectionOverlords
             */
            _leafco = new LeafConnectionOverlord(this);
            _snco   = new StructuredNearConnectionOverlord(this);
            _ssco   = new StructuredShortcutConnectionOverlord(this);
            _cco    = new ChotaConnectionOverlord(this);
            _mco    = new ManagedConnectionOverlord(this);
#if !BRUNET_SIMULATOR
            _localco   = new LocalConnectionOverlord(this);
            _iphandler = new IPHandler();
            _iphandler.Subscribe(this, null);
#endif

            /**
             * Turn on some protocol support :
             */
            /// Turn on Packet Forwarding Support :
            GetTypeSource(PType.Protocol.Forwarding).Subscribe(new PacketForwarder(this), null);
            //Handles AHRouting:
            GetTypeSource(PType.Protocol.AH).Subscribe(new AHHandler(this), this);
            GetTypeSource(PType.Protocol.Echo).Subscribe(new EchoHandler(), this);

            //Add the standard RPC handlers:
            _rpc.AddHandler("sys:ctm", new CtmRequestHandler(this));
            sys_link = new ConnectionPacketHandler(this);
            _rpc.AddHandler("sys:link", sys_link);
            _rpc.AddHandler("trace", new TraceRpcHandler(this));
            //Serve some public information about our ConnectionTable
            _rpc.AddHandler("ConnectionTable", new ConnectionTableRpc(ConnectionTable, _rpc));
            //Add a map-reduce handlers:
            _mr_handler = new MapReduceHandler(this);
            //Subscribe it with the RPC handler:
            _rpc.AddHandler("mapreduce", _mr_handler);

            //Subscribe map-reduce tasks
            _mr_handler.SubscribeTask(new MapReduceTrace(this));
            _mr_handler.SubscribeTask(new MapReduceRangeCounter(this));


            /*
             * Handle Node state changes.
             */
            StateChangeEvent += delegate(Node n, Node.ConnectionState s) {
                if (s == Node.ConnectionState.Leaving)
                {
                    //Start our StructuredNode specific leaving:
                    Leave();
                }
            };

            _connection_table.ConnectionEvent    += new EventHandler(this.EstimateSize);
            _connection_table.ConnectionEvent    += new EventHandler(this.UpdateNeighborStatus);
            _connection_table.DisconnectionEvent += new EventHandler(this.EstimateSize);
            _connection_table.DisconnectionEvent += new EventHandler(this.UpdateNeighborStatus);
        }
Ejemplo n.º 5
0
 public SocialNode(NodeConfig brunetConfig, IpopConfig ipopConfig,
                   RSACryptoServiceProvider rsa)
     : base(brunetConfig, ipopConfig)
 {
     _friends = ImmutableDictionary <string, SocialUser> .Empty;
     _rsa     = rsa;
     _address = AppNode.Node.Address.ToString();
     _user    = new WriteOnce <SocialUser>();
     _mco     = new ManagedConnectionOverlord(AppNode.Node);
     AppNode.Node.AddConnectionOverlord(_mco);
 }
Ejemplo n.º 6
0
        protected void EstablishConnection()
        {
            var node0 = Node0.Node;
            var node1 = Node1.Node;
            ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node0);

            mco.Start();
            node0.AddConnectionOverlord(mco);
            mco.Set(node1.Address);

            EventHandler eh = delegate(object obj, EventArgs ea) { AreConnectedHandler(); };

            _are_connected = new AreConnected(node0, node1, eh);
            _are_connected.Start();
        }
Ejemplo n.º 7
0
        public void Relays()
        {
            Parameters p = new Parameters("Test", "Test");

            string[] args = "-s=100".Split(' ');
            Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);;
            RelayOverlapSimulator sim = new RelayOverlapSimulator(p);

            Address addr1 = null, addr2 = null;

            sim.AddDisconnectedPair(out addr1, out addr2, sim.NCEnable);
            sim.Complete(true);
            SimpleTimer.RunSteps(1000000, false);

            Node node1 = (sim.Nodes[addr1] as NodeMapping).Node as Node;
            Node node2 = (sim.Nodes[addr2] as NodeMapping).Node as Node;

            if (node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) != null)
            {
                Relays();
                return;
            }

            ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node1);

            mco.Start();
            node1.AddConnectionOverlord(mco);
            mco.Set(addr2);
            sim.Complete(true);
            SimpleTimer.RunSteps(100000, false);

            Assert.IsTrue(node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) != null);

            foreach (Connection con in node1.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP))
            {
                con.Edge.Close();
            }
            foreach (Connection con in node2.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP))
            {
                con.Edge.Close();
            }

            SimpleTimer.RunSteps(100000, false);
            Assert.IsTrue(node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) != null);
            sim.Disconnect();
        }
Ejemplo n.º 8
0
        public void Relays()
        {
            Parameters p = new Parameters("Test", "Test");

            string[] args = "-s=100".Split(' ');
            Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);
            RelayOverlapSimulator sim = new RelayOverlapSimulator(p);

            _sim = sim;

            Address addr1 = null, addr2 = null;
            Node    node1 = null, node2 = null;

            while (true)
            {
                sim.AddDisconnectedPair(out addr1, out addr2, sim.NCEnable);
                sim.Complete(true);

                node1 = (sim.Nodes[addr1] as NodeMapping).Node as Node;
                node2 = (sim.Nodes[addr2] as NodeMapping).Node as Node;

                if (!Simulator.AreConnected(node1, node2))
                {
                    break;
                }
            }

            ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node1);

            mco.Start();
            node1.AddConnectionOverlord(mco);
            mco.Set(addr2);
            Assert.IsTrue(AreConnected(node1, node2));

            foreach (Connection con in node1.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP))
            {
                con.State.Edge.Close();
            }
            foreach (Connection con in node2.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP))
            {
                con.State.Edge.Close();
            }

            Assert.IsTrue(Simulator.AreConnected(node1, node2));
        }
Ejemplo n.º 9
0
    public void Relays() {
      Parameters p = new Parameters("Test", "Test");
      string[] args = "-s=100".Split(' ');
      Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);;
      RelayOverlapSimulator sim = new RelayOverlapSimulator(p);

      Address addr1 = null, addr2 = null;
      sim.AddDisconnectedPair(out addr1, out addr2, sim.NCEnable);
      sim.Complete(true);
      SimpleTimer.RunSteps(1000000, false);

      Node node1 = (sim.Nodes[addr1] as NodeMapping).Node as Node;
      Node node2 = (sim.Nodes[addr2] as NodeMapping).Node as Node;

      if(node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) != null) {
        Relays();
        return;
      }

      ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node1);
      mco.Start();
      node1.AddConnectionOverlord(mco);
      mco.Set(addr2);
      sim.Complete(true);
      SimpleTimer.RunSteps(100000, false);

      Assert.IsTrue(node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) != null);

      foreach(Connection con in node1.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP)) {
        con.Edge.Close();
      }
      foreach(Connection con in node2.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP)) {
        con.Edge.Close();
      }

      SimpleTimer.RunSteps(100000, false);
      Assert.IsTrue(node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) != null);
      sim.Disconnect();
    }
Ejemplo n.º 10
0
        // Static Members

        public static void Simulator(RelayOverlapSimulator sim)
        {
            Address addr1 = null, addr2 = null;

            sim.AddDisconnectedPair(out addr1, out addr2, sim.NCEnable);
            sim.Complete(false);
            SimpleTimer.RunSteps(1000000, false);

            StructuredNode node1 = (sim.Nodes[addr1] as NodeMapping).Node as StructuredNode;
            StructuredNode node2 = (sim.Nodes[addr2] as NodeMapping).Node as StructuredNode;

            ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node1);

            mco.Start();
            node1.AddConnectionOverlord(mco);
            mco.Set(addr2);
            SimpleTimer.RunSteps(100000, false);

            Console.WriteLine(addr1 + "<=>" + addr2 + ":");
            Console.WriteLine("\t" + node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) + "\n");
            sim.PrintConnections(node1);
            Console.WriteLine();
            sim.PrintConnections(node2);

            Console.WriteLine("\nPhase 2 -- Disconnect...");
            sim.FindOverlap(node1, node2);
            sim.CloseOverlap(node1);
            sim.CloseOverlap(node2);

            SimpleTimer.RunSteps(100000, false);

            Console.WriteLine(addr1 + "<=>" + addr2 + ":");
            Console.WriteLine("\t" + node1.ConnectionTable.GetConnection(ConnectionType.Structured, addr2) + "\n");
            sim.PrintConnections(node1);
            Console.WriteLine();
            sim.PrintConnections(node2);

            sim.Disconnect();
        }
Ejemplo n.º 11
0
 public SocialNode(NodeConfig brunetConfig, IpopConfig ipopConfig,
   RSACryptoServiceProvider rsa) 
   : base(brunetConfig, ipopConfig) {
   _friends = ImmutableDictionary<string, SocialUser>.Empty;
   _rsa = rsa;
   _address = AppNode.Node.Address.ToString();
   _user = new WriteOnce<SocialUser>();
   _mco = new ManagedConnectionOverlord(AppNode.Node);
   AppNode.Node.AddConnectionOverlord(_mco);
 }
Ejemplo n.º 12
0
    public void Relays() {
      Parameters p = new Parameters("Test", "Test");
      string[] args = "-s=100".Split(' ');
      Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);
      RelayOverlapSimulator sim = new RelayOverlapSimulator(p);
      _sim = sim;

      Address addr1 = null, addr2 = null;
      Node node1 = null, node2 = null;
      while(true) {
        sim.AddDisconnectedPair(out addr1, out addr2, sim.NCEnable);
        sim.Complete(true);

        node1 = (sim.Nodes[addr1] as NodeMapping).Node as Node;
        node2 = (sim.Nodes[addr2] as NodeMapping).Node as Node;

        if(!Simulator.AreConnected(node1, node2)) {
          break;
        }
      }

      ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node1);
      mco.Start();
      node1.AddConnectionOverlord(mco);
      mco.Set(addr2);
      Assert.IsTrue(AreConnected(node1, node2));

      foreach(Connection con in node1.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP)) {
        con.Edge.Close();
      }
      foreach(Connection con in node2.ConnectionTable.GetConnections(Relay.OverlapConnectionOverlord.STRUC_OVERLAP)) {
        con.Edge.Close();
      }

      Assert.IsTrue(Simulator.AreConnected(node1, node2));
    }
Ejemplo n.º 13
0
    private void TestNat(Simulator sim, NatTypes n0type0, NatTypes n0type1,
        NatTypes n1type0, NatTypes n1type1, bool relay)
    {
      string fail_s = String.Format("{0}/{1} and {2}/{3}", n0type0, n0type1,
          n1type0, n1type1);
      Node node0 = null;
      Node node1 = null;
      while(true) {
        node0 = NatFactory.AddNode(sim, n0type0, n0type1, relay);
        node1 = NatFactory.AddNode(sim, n1type0, n1type1, relay);

        Assert.IsTrue(sim.Complete(true), fail_s + " nodes are connected to the overlay");
        if(!Simulator.AreConnected(node0, node1)) {
          break;
        }
      }

      ManagedConnectionOverlord mco = new ManagedConnectionOverlord(node0);
      mco.Start();
      node0.AddConnectionOverlord(mco);
      mco.Set(node1.Address);

      Assert.IsTrue(AreConnected(node0, node1), fail_s + " nodes were unable to connect.");
    }
Ejemplo n.º 14
0
 public SocialNode(NodeConfig brunetConfig, IpopConfig ipopConfig,
                   string certificate) : base(brunetConfig, ipopConfig) {
   _friends = new Dictionary<string, SocialUser>();
   _bfriends = new List<string>();
   _social_sync = new object();
   _status = StatusTypes.Offline.ToString();
   _global_block = new WriteOnce<bool>();
   _local_user = new SocialUser();
   _local_user.Certificate = certificate;
   _local_user.IP = _marad.LocalIP;
   _marad.AddDnsMapping(_local_user.Alias, _local_user.IP, true);
   _bso = AppNode.SecurityOverlord;
   _bso.CertificateHandler.AddCACertificate(_local_user.GetCert().X509);
   _bso.CertificateHandler.AddSignedCertificate(_local_user.GetCert().X509);
   _managed_co = new ManagedConnectionOverlord(AppNode.Node);
   AppNode.Node.AddConnectionOverlord(_managed_co);
 }