Exemplo n.º 1
0
        /**
         * <summary>This method is registered as a delegate to Shutdown.OnExit and
         * will be called when ctrl-c is pressed by the user.  This stops services,
         * prevents the node from reincarnating, and then disconnects the node.
         * </summary>
         */
        public virtual void OnExit()
        {
            _running = false;

            if (_xrm != null)
            {
                _xrm.Stop();
                _xrm = null;
            }

            ApplicationNode appnode = _app_node;

            _app_node = null;

            NCService ncservice = null;

            if (appnode != null)
            {
                ncservice = appnode.NCService;
            }

            if (ncservice != null && _node_config.NCService.Checkpointing)
            {
                string checkpoint = ncservice.GetCheckpoint();
                string prev_cp    = _node_config.NCService.Checkpoint;
                string empty_cp   = (new Point()).ToString();
                if (!checkpoint.Equals(prev_cp) && !checkpoint.Equals(empty_cp))
                {
                    _node_config.NCService.Checkpoint = checkpoint;
                    _node_config.WriteConfig();
                }
            }

            _fe_stop_pem = Brunet.Util.FuzzyTimer.Instance.DoEvery(StopPem, 500, 500);
        }
Exemplo n.º 2
0
 public ApplicationNode(StructuredNode node, IDht dht, RpcDhtProxy dht_proxy,
                        NCService ncservice, ProtocolSecurityOverlord security_overlord)
 {
     Node             = node;
     Dht              = dht;
     DhtProxy         = dht_proxy;
     NCService        = ncservice;
     SecurityOverlord = security_overlord;
 }
Exemplo n.º 3
0
 public ApplicationNode(StructuredNode node, IDht dht, RpcDhtProxy dht_proxy,
                        NCService ncservice, SecurityOverlord security_overlord, NodeConfig nc)
 {
     Config                   = nc;
     Node                     = node;
     Dht                      = dht;
     DhtProxy                 = dht_proxy;
     NCService                = ncservice;
     SecurityOverlord         = security_overlord;
     SymphonySecurityOverlord = security_overlord as SymphonySecurityOverlord;
 }
Exemplo n.º 4
0
        /// <summary>Creates an ApplicationNode and prepares it for connection to
        /// the overlay.  For historical reasons it is linked to _node, _dht,
        /// _rpc_dht, and _bso.</summary>
        public virtual ApplicationNode CreateNode(NodeConfig node_config)
        {
            // Get a Node ID for the new Node
            AHAddress address = null;

            try {
                address = (AHAddress)AddressParser.Parse(node_config.NodeAddress);
            } catch {
                address = Utils.GenerateAHAddress();
            }

            // Create the Node state
            StructuredNode node = new StructuredNode(address, node_config.BrunetNamespace);

            _shutdown.OnExit += node.Disconnect;
            IEnumerable addresses = IPAddresses.GetIPAddresses(node_config.DevicesToBind);

            SecurityOverlord so = null;

            // Enable Security if requested
            if (node_config.Security.Enabled)
            {
                if (node_config.Security.SelfSignedCertificates)
                {
                    SecurityPolicy.SetDefaultSecurityPolicy(SecurityPolicy.DefaultEncryptor,
                                                            SecurityPolicy.DefaultAuthenticator, true);
                }

                byte[] blob = null;
                using (FileStream fs = File.Open(node_config.Security.KeyPath, FileMode.Open)) {
                    blob = new byte[fs.Length];
                    fs.Read(blob, 0, blob.Length);
                }

                RSACryptoServiceProvider rsa_private = new RSACryptoServiceProvider();
                rsa_private.ImportCspBlob(blob);

                CertificateHandler ch = null;
                if (node_config.Security.Dtls)
                {
                    ch = new OpenSslCertificateHandler(node_config.Security.CertificatePath,
                                                       address.ToString());
                }
                else
                {
                    ch = new CertificateHandler(node_config.Security.CertificatePath,
                                                address.ToString());
                }


                if (node_config.Security.SecureEdges)
                {
                    node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
                }

                // A hack to enable a test for security that doesn't require each peer
                // to exchange certificates
                if (node_config.Security.TestEnable)
                {
                    blob = rsa_private.ExportCspBlob(false);
                    RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
                    rsa_pub.ImportCspBlob(blob);
                    CertificateMaker cm = new CertificateMaker("United States", "UFL",
                                                               "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
                                                               "brunet:node:abcdefghijklmnopqrs");
                    Certificate cacert = cm.Sign(cm, rsa_private);

                    cm = new CertificateMaker("United States", "UFL",
                                              "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
                                              address.ToString());
                    Certificate cert = cm.Sign(cacert, rsa_private);
                    ch.AddCACertificate(cacert.X509);
                    ch.AddSignedCertificate(cert.X509);
                }

                if (node_config.Security.Dtls)
                {
                    OpenSslCertificateHandler ssl_ch = ch as OpenSslCertificateHandler;
                    so = new DtlsOverlord(rsa_private, ssl_ch, new PType(20));
                    node.GetTypeSource(new PType(20)).Subscribe(so, null);
                }
                else
                {
                    so = new SymphonySecurityOverlord(node, rsa_private, ch, node.Rrm);
                    node.GetTypeSource(PeerSecOverlord.Security).Subscribe(so, null);
                }
                so.Subscribe(node, null);
            }

            // Add Dht
            new TableServer(node);
            IDht        dht       = new Dht(node, 3, 20);
            RpcDhtProxy dht_proxy = new RpcDhtProxy(dht, node);

            // Setup Vivaldi if requested
            IRelayOverlap ito       = null;
            NCService     ncservice = null;

            if (node_config.NCService.Enabled)
            {
                ncservice = new NCService(node, node_config.NCService.Checkpoint);

                if (node_config.NCService.OptimizeShortcuts)
                {
                    node.Ssco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
                }
                ito = new NCRelayOverlap(ncservice);
            }
            else
            {
                ito = new SimpleRelayOverlap();
            }

            // Create the ApplicationNode
            ApplicationNode app_node = new ApplicationNode(node, dht, dht_proxy, ncservice, so);

            // Add Edge listeners
            EdgeListener el = null;

            foreach (NodeConfig.EdgeListener item in node_config.EdgeListeners)
            {
                el = CreateEdgeListener(item, app_node, addresses);
                if (node_config.Security.SecureEdgesEnabled)
                {
                    el = new SecureEdgeListener(el, so);
                }
                node.AddEdgeListener(el);
            }

            // Create the tunnel and potentially wrap it in a SecureEL
            el = new Relay.RelayEdgeListener(node, ito);
            if (node_config.Security.SecureEdgesEnabled)
            {
                el = new SecureEdgeListener(el, so);
            }
            node.AddEdgeListener(el);

            List <TransportAddress> RemoteTAs = null;

            if (node_config.RemoteTAs != null)
            {
                RemoteTAs = new List <TransportAddress>();
                foreach (String ta in node_config.RemoteTAs)
                {
                    RemoteTAs.Add(TransportAddressFactory.CreateInstance(ta));
                }
                node.RemoteTAs = RemoteTAs;
            }

            // Add XmlRpc
            if (node_config.XmlRpcManager.Enabled)
            {
                if (_xrm == null)
                {
                    _xrm = new XmlRpcManagerServer(node_config.XmlRpcManager.Port);
                }
                _xrm.Add(node, GetXmlRpcUri(app_node));
                new RpcDht(dht, node);
            }

            if (node_config.PrivateNodeConfig != null &&
                node_config.PrivateNodeConfig.Enabled)
            {
                CreatePrivateNode(app_node, NodeConfig.GetPrivateNodeConfig(node_config));
            }
            return(app_node);
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            int       net_size  = Int32.Parse(args[0]);
            string    mode      = args[1].Trim();
            ArrayList nc_list   = new ArrayList();
            ArrayList addr_list = new ArrayList();

            Console.WriteLine("Building the network...");
            for (int i = 0; i < net_size; i++)
            {
                addr_list.Add(new AHAddress(new RNGCryptoServiceProvider()));
                nc_list.Add(new NCService());
            }
            if (mode.Equals("-s"))
            {
                string sample_file = args[2].Trim();
                //
                // Start processing samples.
                //
                StreamReader br  = new StreamReader(new FileStream(sample_file, FileMode.Open, FileAccess.Read));
                DateTime     now = DateTime.Now;
                while (true)
                {
                    string s = br.ReadLine();
                    if (s == null)
                    {
                        break;
                    }
                    string[]  ss          = s.Split();
                    int       seconds     = Int32.Parse(ss[0]);
                    DateTime  o_stamp     = now + new TimeSpan(0, 0, seconds);
                    int       local_idx   = Int32.Parse(ss[1]);
                    NCService nc_local    = (NCService)nc_list[local_idx];
                    int       remote_idx  = Int32.Parse(ss[2]);
                    Address   addr_remote = (Address)addr_list[remote_idx];
                    NCService nc_remote   = (NCService)nc_list[remote_idx];
                    NCService.VivaldiState remote_state = nc_remote.State;
                    double o_rawLatency = double.Parse(ss[3]);
                    nc_local.ProcessSample(o_stamp, addr_remote, remote_state.Position,
                                           remote_state.WeightedError, o_rawLatency);
                }
            }
            else if (mode.Equals("-l"))
            {
                Random rr = new Random();
                //
                // Use pairwise latencies between nodes (assume a complete matrix).
                //
                string latency_file  = args[2].Trim();
                int    max_neighbors = Int32.Parse(args[3].Trim());
                int    max_rounds    = Int32.Parse(args[4]);

                double[][] rtt_matrix = new double[net_size][];
                ArrayList  neighbors  = new ArrayList();
                for (int i = 0; i < net_size; i++)
                {
                    neighbors.Insert(i, new ArrayList());
                    rtt_matrix[i] = new double[net_size];
                }

                //
                // Add neighbors to the nodes
                //

                for (int i = 0; i < net_size; i++)
                {
                    ArrayList i_neighbors = (ArrayList)neighbors[i];
                    ArrayList j_neighbors = null;
                    int       j           = -1;
                    while (i_neighbors.Count < max_neighbors)
                    {
                        do
                        {
                            j           = rr.Next(0, net_size);
                            j_neighbors = (ArrayList)neighbors[j];
                        } while (j == i && i_neighbors.Contains(j) && j_neighbors.Count >= max_neighbors);
                        i_neighbors.Add(j);
                        j_neighbors.Add(i);
                    }
                }


                for (int i = 0; i < net_size; i++)
                {
                    for (int j = 0; j < net_size; j++)
                    {
                        rtt_matrix[i][j] = -1.0f;
                    }
                }

                StreamReader br = new StreamReader(new FileStream(latency_file, FileMode.Open, FileAccess.Read));
                while (true)
                {
                    string s = br.ReadLine();
                    if (s == null)
                    {
                        break;
                    }
                    string[] ss         = s.Split();
                    int      local_idx  = Int32.Parse(ss[0]);
                    int      remote_idx = Int32.Parse(ss[1]);
                    rtt_matrix[local_idx][remote_idx] = double.Parse(ss[2]);
                    rtt_matrix[remote_idx][local_idx] = double.Parse(ss[2]);
                }

                //
                // Now the rounds of iteration
                //
                DateTime now = DateTime.Now;
                int      x   = 0;
                while (x < max_rounds)
                {
                    int       local_idx    = rr.Next(0, net_size);
                    ArrayList my_neighbors = (ArrayList)neighbors[local_idx];
                    int       remote_idx   = (int)my_neighbors[rr.Next(0, my_neighbors.Count)];
                    NCService nc_local     = (NCService)nc_list[local_idx];
                    Address   addr_remote  = (Address)addr_list[remote_idx];
                    NCService nc_remote    = (NCService)nc_list[remote_idx];
                    NCService.VivaldiState remote_state = nc_remote.State;
                    double o_rawLatency = rtt_matrix[local_idx][remote_idx];
                    //Console.WriteLine("{0} {1} {2}", local_idx, remote_idx, o_rawLatency);
                    nc_local.ProcessSample(now + new TimeSpan(0, 0, x), addr_remote, remote_state.Position,
                                           remote_state.WeightedError, o_rawLatency);
                    x += 1;
                }
            }

            for (int i = 0; i < net_size; i++)
            {
                NCService nc   = (NCService)nc_list[i];
                Address   addr = (Address)addr_list[i];
                NCService.VivaldiState state = nc.State;
                Console.Error.WriteLine("{0} {1}", i, state.Position);
            }
        }