예제 #1
0
        public void SecureRingTest()
        {
            Parameters p = new Parameters("Test", "Test");

            string[] args = "-b=.2 -c --secure_edges -s=25".Split(' ');
            Assert.AreNotEqual(-1, p.Parse(args), "Unable to parse" + p.ErrorMessage);
            Simulator sim = new Simulator(p);

            _sim = sim;
            Assert.IsTrue(sim.Complete(true), "Simulation failed to complete the ring");
            var         nm0 = sim.TakenIDs.Values[0];
            int         idx = 1;
            NodeMapping nm1 = null;

            do
            {
                nm1 = sim.TakenIDs.Values[idx++];
            } while(Simulator.AreConnected(nm0.Node, nm1.Node) && idx < sim.TakenIDs.Count);
            Assert.IsFalse(Simulator.AreConnected(nm0.Node, nm1.Node), "Sanity check");
            var ptype = new PType("chtest");
            var ch0   = new ConnectionHandler(ptype, (StructuredNode)nm0.Node);
            var ch1   = new ConnectionHandler(ptype, (StructuredNode)nm1.Node);

            ConnectionHandlerTest(nm0.Node, nm1.Node, ch0, ch1);
        }
예제 #2
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;
        }
예제 #3
0
        /// <summary>Create a new node in the public overlay and a matching one in
        /// the private overlay.</summary>
        override public Node AddNode()
        {
            Node        snode = _shared_overlay.AddNode();
            NodeMapping snm   = _shared_overlay.Nodes[snode.Address];

            // Must do this to remove it after successfully creating the new node
            Node.StateChangeHandler add_node = null;

            // Delayed add, removes ~15 seconds off bootstrapping time
            add_node = delegate(Node n, Node.ConnectionState cs) {
                if (cs != Node.ConnectionState.Connected)
                {
                    return;
                }
                snm.Node.StateChangeEvent -= add_node;

                Node         node = AddNode(snm.ID, snode.Address as AHAddress);
                EdgeListener el   = new SubringEdgeListener(snode, node);
                if (_secure_edges)
                {
                    NodeMapping pnm = Nodes[node.Address] as NodeMapping;
                    el = new SecureEdgeListener(el, pnm.SO);
                }
                node.AddEdgeListener(el);
                node.AddTADiscovery(new DhtDiscovery(node as StructuredNode,
                                                     snm.Dht, snm.Node.Realm, snm.DhtProxy));
                CurrentNetworkSize--;
            };

            // Check will return true, since the Node is unregistered
            CurrentNetworkSize++;
            snm.Node.StateChangeEvent += add_node;
            return(snode);
        }
예제 #4
0
        protected void AddBrokenNode(ref NodeMapping nm, Address addr, int broken_port, bool nctunnel)
        {
            nm.Node = new StructuredNode(addr as AHAddress, BrunetNamespace);

            TAAuthorizer auth = new IDTAAuthorizer(broken_port);

            nm.Node.AddEdgeListener(new SimulationEdgeListener(nm.ID, 0, auth, true));

            IRelayOverlap ito = null;

            if (NCEnable)
            {
                nm.NCService = new NCService(nm.Node, new Point());
// Until we figure out what's going on with VivaldiTargetSelector its not quite useful for these purposes
//        (nm.Node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(nm.Node, ncservice);
            }
            if (nctunnel && NCEnable)
            {
                ito = new NCRelayOverlap(nm.NCService);
            }
            else
            {
                ito = new SimpleRelayOverlap();
            }

            nm.Node.AddEdgeListener(new Relay.RelayEdgeListener(nm.Node, ito));
            nm.Node.RemoteTAs = GetRemoteTAs();
            nm.Node.Connect();
            CurrentNetworkSize++;
        }
예제 #5
0
        public void RemoveNode(bool cleanly, bool output)
        {
            int         index = _rand.Next(0, Nodes.Count);
            NodeMapping nm    = Nodes.Values[index];

            RemoveNode(nm.Node, cleanly, output);
        }
예제 #6
0
    public void AddDisconnectedPair(Address address1, Address address2, bool nctunnel)
    {
      NodeMapping nm1 = new NodeMapping();
      nm1.ID = TakeID();
      TakenIDs[nm1.ID] = nm1;
      NodeMapping nm2 = new NodeMapping();
      nm2.ID = TakeID();
      TakenIDs[nm2.ID] = nm2;

      AddBrokenNode(ref nm1, address1, nm2.ID, nctunnel);
      Nodes[address1] = nm1;

      AddBrokenNode(ref nm2, address2, nm1.ID, nctunnel);
      Nodes[address2] = nm2;
    }
예제 #7
0
        public void RemoveNode(Node node, bool cleanly)
        {
            NodeMapping nm = (NodeMapping)Nodes[node.Address];

            if (cleanly)
            {
                node.Disconnect();
            }
            else
            {
                node.Abort();
            }
            TakenIDs.Remove(nm.ID);
            Nodes.Remove(node.Address);
            CurrentNetworkSize--;
        }
예제 #8
0
        /// <summary>Overriden to setup PathELs.</summary>
        protected override EdgeListener CreateEdgeListener(int id)
        {
            NodeMapping snm = _shared_overlay.TakenIDs[id];

            if (snm.PathEM == null)
            {
                throw new Exception("Pathing should be enabled");
            }
            NodeMapping pnm = TakenIDs[id];

            pnm.PathEM = snm.PathEM;
            PType path_p = PType.Protocol.Pathing;

            pnm.Node.DemuxHandler.GetTypeSource(path_p).Subscribe(pnm.PathEM, path_p);
            return(snm.PathEM.CreatePath());
        }
예제 #9
0
        public void AddDisconnectedPair(Address address1, Address address2, bool nctunnel)
        {
            NodeMapping nm1 = new NodeMapping();

            nm1.ID           = TakeID();
            TakenIDs[nm1.ID] = nm1;
            NodeMapping nm2 = new NodeMapping();

            nm2.ID           = TakeID();
            TakenIDs[nm2.ID] = nm2;

            AddBrokenNode(ref nm1, address1, nm2.ID, nctunnel);
            Nodes[address1] = nm1;

            AddBrokenNode(ref nm2, address2, nm1.ID, nctunnel);
            Nodes[address2] = nm2;
        }
예제 #10
0
        public bool Crawl(bool log, bool secure)
        {
            NodeMapping nm = (NodeMapping)Nodes.GetByIndex(0);
            ProtocolSecurityOverlord bso = null;

            if (secure)
            {
                bso = nm.BSO;
            }

            CrawlHelper ch = new CrawlHelper(nm.Node, Nodes.Count, bso, log);

            ch.Start();
            while (ch.Done == 0)
            {
                SimpleTimer.RunStep();
            }

            return(ch.Success);
        }
예제 #11
0
        // removes a node from the pool
        public void RemoveNode(bool output, bool cleanly)
        {
            int         index = _rand.Next(0, Nodes.Count);
            NodeMapping nm    = (NodeMapping)Nodes.GetByIndex(index);

            if (output)
            {
                Console.WriteLine("Removing: " + nm.Node.Address);
            }
            if (cleanly)
            {
                nm.Node.Disconnect();
            }
            else
            {
                nm.Node.Abort();
            }
            TakenIDs.Remove(nm.ID);
            Nodes.RemoveAt(index);
            CurrentNetworkSize--;
        }
예제 #12
0
        /// <summary>Revoke a random node from a random node.</summary>
        public NodeMapping Revoke(bool log)
        {
            NodeMapping revoked = Nodes.Values[_rand.Next(0, Nodes.Count)];
            NodeMapping revoker = Nodes.Values[_rand.Next(0, Nodes.Count)];

            while (revoked != revoker)
            {
                revoker = Nodes.Values[_rand.Next(0, Nodes.Count)];
            }

            string username           = revoked.Node.Address.ToString().Replace('=', '0');
            UserRevocationMessage urm = new UserRevocationMessage(_se_key, username);
            BroadcastSender       bs  = new BroadcastSender(revoker.Node as StructuredNode);

            bs.Send(new CopyList(BroadcastRevocationHandler.PType, urm));
            if (log)
            {
                Console.WriteLine("Revoked: " + revoked.Node.Address);
            }
            return(revoked);
        }
예제 #13
0
        protected void Start()
        {
            for (int i = 0; i < _parameters.Size; i++)
            {
                AddNode();
            }

            if (_start)
            {
                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 ? cidx - Nodes.Count : cidx;
                    tas.Add(Nodes.Values[cidx].Node.LocalTAs[0]);

                    cidx = idx + 2;
                    cidx = cidx >= Nodes.Count ? cidx - Nodes.Count : cidx;
                    tas.Add(Nodes.Values[cidx].Node.LocalTAs[0]);

                    cidx = idx - 1;
                    cidx = cidx >= 0 ? cidx : cidx + Nodes.Count;
                    tas.Add(Nodes.Values[cidx].Node.LocalTAs[0]);

                    cidx = idx - 2;
                    cidx = cidx >= 0 ? cidx : cidx + Nodes.Count;
                    tas.Add(Nodes.Values[cidx].Node.LocalTAs[0]);

                    nm.Node.RemoteTAs = tas;
                }
                foreach (NodeMapping nm in Nodes.Values)
                {
                    nm.Node.Connect();
                }
            }
        }
예제 #14
0
        // The next set of methods handle the removal of nodes from the simulation

        // removes a node from the pool
        public void RemoveNode(Node node, bool cleanly, bool output)
        {
            NodeMapping nm = Nodes[node.Address];

            if (output)
            {
                Console.WriteLine("Removing: " + nm.Node.Address);
            }
            if (cleanly)
            {
                node.Disconnect();
            }
            else
            {
                node.Abort();
            }
            TakenIDs.Remove(nm.ID);
            Nodes.Remove(node.Address);
            if (_pathing)
            {
                nm.PathEM.Stop();
            }
            CurrentNetworkSize--;
        }
예제 #15
0
    protected virtual StructuredNode PrepareNode(int id, AHAddress address)
    {
      if(TakenIDs.Contains(id)) {
        throw new Exception("ID already taken");
      }

      StructuredNode node = new StructuredNode(address, BrunetNamespace);

      NodeMapping nm = new NodeMapping();
      TakenIDs[id] = nm.ID = id;
      nm.Node = node;
      Nodes.Add((Address) address, nm);

      EdgeListener el = CreateEdgeListener(nm.ID);

      if(SecureEdges || SecureSenders) {
        byte[] blob = SEKey.ExportCspBlob(true);
        RSACryptoServiceProvider rsa_copy = new RSACryptoServiceProvider();
        rsa_copy.ImportCspBlob(blob);

        CertificateMaker cm = new CertificateMaker("United States", "UFL", 
          "ACIS", "David Wolinsky", "*****@*****.**", rsa_copy,
          address.ToString());
        Certificate cert = cm.Sign(CACert, SEKey);

        CertificateHandler ch = new CertificateHandler();
        ch.AddCACertificate(CACert.X509);
        ch.AddSignedCertificate(cert.X509);

        ProtocolSecurityOverlord so = new ProtocolSecurityOverlord(node, rsa_copy, node.Rrm, ch);
        so.Subscribe(node, null);
        node.GetTypeSource(SecurityOverlord.Security).Subscribe(so, null);
        nm.BSO = so;
        node.HeartBeatEvent += so.Heartbeat;
      }

      if(SecureEdges) {
        node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
        el = new SecureEdgeListener(el, nm.BSO);
      }

      node.AddEdgeListener(el);

      node.RemoteTAs = GetRemoteTAs();

      ITunnelOverlap ito = null;
      if(NCEnable) {
        nm.NCService = new NCService(node, new Point());
// My evaluations show that when this is enabled the system sucks
//        (node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
        ito = new NCTunnelOverlap(nm.NCService);
      } else {
        ito = new SimpleTunnelOverlap();
      }

      if(Broken != 0) {
        el = new Tunnel.TunnelEdgeListener(node, ito);
        node.AddEdgeListener(el);
      }
      // Enables Dht data store
      new TableServer(node);
      return node;
    }
예제 #16
0
        protected virtual StructuredNode PrepareNode(int id, AHAddress address)
        {
            if (TakenIDs.ContainsKey(id))
            {
                throw new Exception("ID already taken");
            }

            StructuredNode node = new StructuredNode(address, BrunetNamespace);

            NodeMapping nm = new NodeMapping();

            nm.ID        = id;
            TakenIDs[id] = nm;
            nm.Node      = node;
            Nodes.Add((Address)address, nm);

            EdgeListener el = CreateEdgeListener(nm.ID);

            if (_secure_edges || _secure_senders)
            {
                byte[] blob = _se_key.ExportCspBlob(true);
                RSACryptoServiceProvider rsa_copy = new RSACryptoServiceProvider();
                rsa_copy.ImportCspBlob(blob);

                string           username = address.ToString().Replace('=', '0');
                CertificateMaker cm       = new CertificateMaker("United States", "UFL",
                                                                 "ACIS", username, "*****@*****.**", rsa_copy,
                                                                 address.ToString());
                Certificate cert = cm.Sign(_ca_cert, _se_key);

                CertificateHandler ch = null;
                if (_dtls)
                {
                    ch = new OpenSslCertificateHandler();
                }
                else
                {
                    ch = new CertificateHandler();
                }
                ch.AddCACertificate(_ca_cert.X509);
                ch.AddSignedCertificate(cert.X509);

                if (_dtls)
                {
                    nm.SO = new DtlsOverlord(rsa_copy, ch, PeerSecOverlord.Security);
                }
                else
                {
                    nm.Sso = new SymphonySecurityOverlord(node, rsa_copy, ch, node.Rrm);
                    nm.SO  = nm.Sso;
                }

                var brh = new BroadcastRevocationHandler(_ca_cert, nm.SO);
                node.GetTypeSource(BroadcastRevocationHandler.PType).Subscribe(brh, null);
                ch.AddCertificateVerification(brh);
                nm.SO.Subscribe(node, null);
                node.GetTypeSource(PeerSecOverlord.Security).Subscribe(nm.SO, null);
            }

            if (_pathing)
            {
                nm.PathEM = new PathELManager(el, nm.Node);
                nm.PathEM.Start();
                el = nm.PathEM.CreatePath();
                PType path_p = PType.Protocol.Pathing;
                nm.Node.DemuxHandler.GetTypeSource(path_p).Subscribe(nm.PathEM, path_p);
            }

            if (_secure_edges)
            {
                node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
                el = new SecureEdgeListener(el, nm.SO);
            }

            node.AddEdgeListener(el);

            if (!_start)
            {
                node.RemoteTAs = GetRemoteTAs();
            }

            IRelayOverlap ito = null;

            if (NCEnable)
            {
                nm.NCService = new NCService(node, new Point());
// My evaluations show that when this is enabled the system sucks
//        (node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
                ito = new NCRelayOverlap(nm.NCService);
            }
            else
            {
                ito = new SimpleRelayOverlap();
            }

            if (_broken != 0)
            {
                el = new Relay.RelayEdgeListener(node, ito);
                if (_secure_edges)
                {
                    el = new SecureEdgeListener(el, nm.SO);
                }
                node.AddEdgeListener(el);
            }

            BroadcastHandler bhandler = new BroadcastHandler(node as StructuredNode);

            node.DemuxHandler.GetTypeSource(BroadcastSender.PType).Subscribe(bhandler, null);
            node.DemuxHandler.GetTypeSource(SimBroadcastPType).Subscribe(SimBroadcastHandler, null);

            // Enables Dht data store
            new TableServer(node);
            nm.Dht      = new Dht(node, 3, 20);
            nm.DhtProxy = new RpcDhtProxy(nm.Dht, node);
            return(node);
        }
예제 #17
0
        public static void Commands(Simulator sim)
        {
            string command = String.Empty;

            Console.WriteLine("Type HELP for a list of commands.\n");
            while (command != "Q")
            {
                bool secure = false;
                Console.Write("#: ");
                // Commands can have parameters separated by spaces
                string[] parts = Console.ReadLine().Split(' ');
                command = parts[0].ToUpper();

                try {
                    if (command.Equals("S"))
                    {
                        secure  = true;
                        command = parts[1].ToUpper();;
                    }

                    switch (command)
                    {
                    case "B":
                        int       forwarders = (parts.Length >= 2) ? Int32.Parse(parts[1]) : -1;
                        Broadcast bcast      = new Broadcast(sim.SimBroadcastHandler,
                                                             sim.RandomNode().Node, forwarders, TaskFinished);
                        bcast.Start();
                        RunUntilTaskFinished();
                        break;

                    case "C":
                        sim.CheckRing(true);
                        break;

                    case "P":
                        sim.PrintConnections();
                        break;

                    case "M":
                        Console.WriteLine("Memory Usage: " + GC.GetTotalMemory(true));
                        break;

                    case "CR":
                        NodeMapping nm = sim.Nodes.Values[0];
                        SymphonySecurityOverlord bso = null;
                        if (secure)
                        {
                            bso = nm.Sso;
                        }
                        Crawl c = new Crawl(nm.Node, sim.Nodes.Count, bso, TaskFinished);
                        c.Start();
                        RunUntilTaskFinished();
                        break;

                    case "A2A":
                        AllToAll atoa = new AllToAll(sim.Nodes, secure, TaskFinished);
                        atoa.Start();
                        RunUntilTaskFinished();
                        break;

                    case "A":
                        sim.AddNode();
                        break;

                    case "D":
                        sim.RemoveNode(true, true);
                        break;

                    case "R":
                        sim.RemoveNode(false, true);
                        break;

                    case "REVOKE":
                        sim.Revoke(true);
                        break;

                    case "RUN":
                        int steps = (parts.Length >= 2) ? Int32.Parse(parts[1]) : 0;
                        if (steps > 0)
                        {
                            SimpleTimer.RunSteps(steps);
                        }
                        else
                        {
                            SimpleTimer.RunStep();
                        }
                        break;

                    case "Q":
                        break;

                    case "CONSTATE":
                        sim.PrintConnectionState();
                        break;

                    case "H":
                        Console.WriteLine("Commands: \n");
                        Console.WriteLine("A - add a node");
                        Console.WriteLine("D - remove a node");
                        Console.WriteLine("R - abort a node");
                        Console.WriteLine("C - check the ring using ConnectionTables");
                        Console.WriteLine("P - Print connections for each node to the screen");
                        Console.WriteLine("M - Current memory usage according to the garbage collector");
                        Console.WriteLine("[S] CR - Perform a (secure) crawl of the network using RPC");
                        Console.WriteLine("[S] A2A - Perform all-to-all measurement of the network using RPC");
                        Console.WriteLine("Q - Quit");
                        break;

                    default:
                        Console.WriteLine("Invalid command");
                        break;
                    }
                } catch (Exception e) {
                    Console.WriteLine("Error: " + e);
                }
                Console.WriteLine();
            }
        }
예제 #18
0
        protected virtual StructuredNode PrepareNode(int id, AHAddress address)
        {
            if (TakenIDs.Contains(id))
            {
                throw new Exception("ID already taken");
            }

            StructuredNode node = new StructuredNode(address, BrunetNamespace);

            NodeMapping nm = new NodeMapping();

            TakenIDs[id] = nm.ID = id;
            nm.Node      = node;
            Nodes.Add((Address)address, nm);

            EdgeListener el = CreateEdgeListener(nm.ID);

            if (_secure_edges || _secure_senders)
            {
                byte[] blob = _se_key.ExportCspBlob(true);
                RSACryptoServiceProvider rsa_copy = new RSACryptoServiceProvider();
                rsa_copy.ImportCspBlob(blob);

                CertificateMaker cm = new CertificateMaker("United States", "UFL",
                                                           "ACIS", "David Wolinsky", "*****@*****.**", rsa_copy,
                                                           address.ToString());
                Certificate cert = cm.Sign(_ca_cert, _se_key);

                CertificateHandler ch = new CertificateHandler();
                ch.AddCACertificate(_ca_cert.X509);
                ch.AddSignedCertificate(cert.X509);

                ProtocolSecurityOverlord so = new ProtocolSecurityOverlord(node, rsa_copy, node.Rrm, ch);
                so.Subscribe(node, null);
                node.GetTypeSource(SecurityOverlord.Security).Subscribe(so, null);
                nm.BSO = so;
                node.HeartBeatEvent += so.Heartbeat;
            }

            if (_secure_edges)
            {
                node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
                el = new SecureEdgeListener(el, nm.BSO);
            }

            node.AddEdgeListener(el);

            node.RemoteTAs = GetRemoteTAs();

            ITunnelOverlap ito = null;

            if (NCEnable)
            {
                nm.NCService = new NCService(node, new Point());
// My evaluations show that when this is enabled the system sucks
//        (node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
                ito = new NCTunnelOverlap(nm.NCService);
            }
            else
            {
                ito = new SimpleTunnelOverlap();
            }

            if (_broken != 0)
            {
                el = new Tunnel.TunnelEdgeListener(node, ito);
                node.AddEdgeListener(el);
            }
            // Enables Dht data store
            new TableServer(node);
            return(node);
        }
예제 #19
0
    protected void AddBrokenNode(ref NodeMapping nm, Address addr, int broken_port, bool nctunnel)
    {
      nm.Node = new StructuredNode(addr as AHAddress, BrunetNamespace);

      TAAuthorizer auth = new IDTAAuthorizer(broken_port);
      nm.Node.AddEdgeListener(new SimulationEdgeListener(nm.ID, 0, auth, true));

      ITunnelOverlap ito = null;
      if(NCEnable) {
        nm.NCService = new NCService(nm.Node, new Point());
// Until we figure out what's going on with VivaldiTargetSelector its not quite useful for these purposes
//        (nm.Node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(nm.Node, ncservice);
      }
      if(nctunnel && NCEnable) {
        ito = new NCTunnelOverlap(nm.NCService);
      } else {
        ito = new SimpleTunnelOverlap();
      }

      nm.Node.AddEdgeListener(new Tunnel.TunnelEdgeListener(nm.Node, ito));

      ArrayList RemoteTAs = new ArrayList();
      for(int i = 0; i < 5 && i < TakenIDs.Count; i++) {
        int rport = (int) TakenIDs.GetByIndex(_rand.Next(0, TakenIDs.Count));
        RemoteTAs.Add(TransportAddressFactory.CreateInstance("brunet.function://127.0.0.1:" + rport));
      }
      nm.Node.RemoteTAs = RemoteTAs;

      nm.Node.Connect();
    }
예제 #20
0
    protected void AddBrokenNode(ref NodeMapping nm, Address addr, int broken_port, bool nctunnel)
    {
      nm.Node = new StructuredNode(addr as AHAddress, BrunetNamespace);

      TAAuthorizer auth = new IDTAAuthorizer(broken_port);
      nm.Node.AddEdgeListener(new SimulationEdgeListener(nm.ID, 0, auth, true));

      IRelayOverlap ito = null;
      if(NCEnable) {
        nm.NCService = new NCService(nm.Node, new Point());
// Until we figure out what's going on with VivaldiTargetSelector its not quite useful for these purposes
//        (nm.Node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(nm.Node, ncservice);
      }
      if(nctunnel && NCEnable) {
        ito = new NCRelayOverlap(nm.NCService);
      } else {
        ito = new SimpleRelayOverlap();
      }

      nm.Node.AddEdgeListener(new Relay.RelayEdgeListener(nm.Node, ito));
      nm.Node.RemoteTAs = GetRemoteTAs();
      nm.Node.Connect();
      CurrentNetworkSize++;
    }
예제 #21
0
파일: Simulator.cs 프로젝트: hseom/brunet
    protected virtual StructuredNode PrepareNode(int id, AHAddress address)
    {
      if(TakenIDs.ContainsKey(id)) {
        throw new Exception("ID already taken");
      }

      StructuredNode node = new StructuredNode(address, BrunetNamespace);

      NodeMapping nm = new NodeMapping();
      nm.ID = id;
      TakenIDs[id] = nm;
      nm.Node = node;
      Nodes.Add((Address) address, nm);

      EdgeListener el = CreateEdgeListener(nm.ID);

      if(_secure_edges || _secure_senders) {
        byte[] blob = _se_key.ExportCspBlob(true);
        RSACryptoServiceProvider rsa_copy = new RSACryptoServiceProvider();
        rsa_copy.ImportCspBlob(blob);

        string username = address.ToString().Replace('=', '0');
        CertificateMaker cm = new CertificateMaker("United States", "UFL", 
          "ACIS", username, "*****@*****.**", rsa_copy,
          address.ToString());
        Certificate cert = cm.Sign(_ca_cert, _se_key);

        CertificateHandler ch = null;
        if(_dtls) {
          ch = new OpenSslCertificateHandler();
        } else {
          ch = new CertificateHandler();
        }
        ch.AddCACertificate(_ca_cert.X509);
        ch.AddSignedCertificate(cert.X509);

        if(_dtls) {
          nm.SO = new DtlsOverlord(rsa_copy, ch, PeerSecOverlord.Security);
        } else {
          nm.Sso = new SymphonySecurityOverlord(node, rsa_copy, ch, node.Rrm);
          nm.SO = nm.Sso;
        }

        var brh = new BroadcastRevocationHandler(_ca_cert, nm.SO);
        node.GetTypeSource(BroadcastRevocationHandler.PType).Subscribe(brh, null);
        ch.AddCertificateVerification(brh);
        nm.SO.Subscribe(node, null);
        node.GetTypeSource(PeerSecOverlord.Security).Subscribe(nm.SO, null);
      }

      if(_pathing) {
        nm.PathEM = new PathELManager(el, nm.Node);
        nm.PathEM.Start();
        el = nm.PathEM.CreatePath();
        PType path_p = PType.Protocol.Pathing;
        nm.Node.DemuxHandler.GetTypeSource(path_p).Subscribe(nm.PathEM, path_p);
      }

      if(_secure_edges) {
        node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
        el = new SecureEdgeListener(el, nm.SO);
      }

      node.AddEdgeListener(el);

      if(!_start) {
        node.RemoteTAs = GetRemoteTAs();
      }

      IRelayOverlap ito = null;
      if(NCEnable) {
        nm.NCService = new NCService(node, new Point());
// My evaluations show that when this is enabled the system sucks
//        (node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
        ito = new NCRelayOverlap(nm.NCService);
      } else {
        ito = new SimpleRelayOverlap();
      }

      if(_broken != 0) {
        el = new Relay.RelayEdgeListener(node, ito);
        if(_secure_edges) {
          el = new SecureEdgeListener(el, nm.SO);
        }
        node.AddEdgeListener(el);
      }

      BroadcastHandler bhandler = new BroadcastHandler(node as StructuredNode);
      node.DemuxHandler.GetTypeSource(BroadcastSender.PType).Subscribe(bhandler, null);
      node.DemuxHandler.GetTypeSource(SimBroadcastPType).Subscribe(SimBroadcastHandler, null);

      // Enables Dht data store
      new TableServer(node);
      nm.Dht = new Dht(node, 3, 20);
      nm.DhtProxy = new RpcDhtProxy(nm.Dht, node);
      return node;
    }