示例#1
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);
        }
示例#2
0
        /**
         * When a node is out of the range, this method is called.
         * This method tries to find the nearest node to the middle of range using greedty algorithm.
         * return list of MapReduceInfo
         */
        private List <MapReduceInfo> GenerateTreeOutRange(AHAddress start, AHAddress end, MapReduceArgs mr_args)
        {
            List <MapReduceInfo> retval    = new List <MapReduceInfo>();
            BigInteger           up        = start.ToBigInteger();
            BigInteger           down      = end.ToBigInteger();
            BigInteger           mid_range = (up + down) / 2;

            if (mid_range % 2 == 1)
            {
                mid_range = mid_range - 1;
            }
            AHAddress mid_addr = new AHAddress(mid_range);

            //if (!mid_addr.IsBetweenFromLeft(start, end) ) {
            if (!InRange(mid_addr, start, end))
            {
                mid_range += Address.Half;
                mid_addr   = new AHAddress(mid_range);
            }
            ArrayList gen_arg = new ArrayList();

            if (NextGreedyClosest(mid_addr) != null)
            {
                AHGreedySender ags         = new AHGreedySender(_node, mid_addr);
                string         start_range = start.ToString();
                string         end_range   = end.ToString();
                gen_arg.Add(start_range);
                gen_arg.Add(end_range);
                MapReduceInfo mr_info = new MapReduceInfo((ISender)ags,
                                                          new MapReduceArgs(this.TaskName,
                                                                            mr_args.MapArg,
                                                                            gen_arg,
                                                                            mr_args.ReduceArg));
                Log("{0}: {1}, out of range, moving to the closest node to mid_range: {2} to target node, range start: {3}, range end: {4}",
                    this.TaskName, _node.Address, mid_addr, start, end);
                retval.Add(mr_info);
            }
            else
            {
                // cannot find a node in the range.
            }
            return(retval);
        }
示例#3
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);
        }
示例#4
0
        private string GetRandomNodeAddr()
        {
            AHAddress addr = new AHAddress(new RNGCryptoServiceProvider());

            return(addr.ToString());
        }
示例#5
0
        /**
         * Recursive function to compute the latency of an Rpc call
         * by accumulating measured latencies of individual hops.
         * @param target address of the target
         */
        public void ComputePathLatencyTo(AHAddress a, object req_state)
        {
            /*
             * First find the Connection pointing to the node closest to dest, if
             * there is one closer than us
             */

            ConnectionTable tab          = _node.ConnectionTable;
            ConnectionList  structs      = tab.GetConnections(ConnectionType.Structured);
            Connection      next_closest = structs.GetNearestTo((AHAddress)_node.Address, a);
            //Okay, we have the next closest:
            ListDictionary my_entry = new ListDictionary();

            my_entry["node"] = _node.Address.ToString();
            if (next_closest != null)
            {
                my_entry["next_latency"] = GetMeasuredLatency(next_closest.Address);
                my_entry["next_contype"] = next_closest.ConType;
                Channel result = new Channel();
                //We only want one result, so close the queue after we get the first
                result.CloseAfterEnqueue();
                result.CloseEvent += delegate(object o, EventArgs args) {
                    Channel q = (Channel)o;
                    if (q.Count > 0)
                    {
                        try {
                            RpcResult rres    = (RpcResult)q.Dequeue();
                            IList     l       = (IList)rres.Result;
                            ArrayList results = new ArrayList(l.Count + 1);
                            results.Add(my_entry);
                            results.AddRange(l);
                            _rpc.SendResult(req_state, results);
                        }
                        catch (Exception x) {
                            string    m  = String.Format("<node>{0}</node> trying <connection>{1}</connection> got <exception>{2}</exception>", _node.Address, next_closest, x);
                            Exception nx = new Exception(m);
                            _rpc.SendResult(req_state, nx);
                        }
                    }
                    else
                    {
                        //We got no results.
                        IList l = new ArrayList(1);
                        l.Add(my_entry);
                        _rpc.SendResult(req_state, l);
                    }
                };
                _rpc.Invoke(next_closest.Edge, result, "ncserver.ComputePathLatencyTo", a.ToString());
            }
            else
            {
                //We are the end of the line, send the result:
                ArrayList l = new ArrayList();
                l.Add(my_entry);
                _rpc.SendResult(req_state, l);
            }
        }
示例#6
0
 /**
  * Recursive function to compute the latency of an Rpc call
  * by accumulating measured latencies of individual hops.
  * @param target address of the target
  */
 public void ComputePathLatencyTo(AHAddress a, object req_state) {
   /*
    * First find the Connection pointing to the node closest to dest, if
    * there is one closer than us
    */
   
   ConnectionTable tab = _node.ConnectionTable;
   ConnectionList structs = tab.GetConnections(ConnectionType.Structured);
   Connection next_closest = structs.GetNearestTo((AHAddress) _node.Address, a);
   //Okay, we have the next closest:
   ListDictionary my_entry = new ListDictionary();
   my_entry["node"] = _node.Address.ToString();
   if( next_closest != null ) {
     my_entry["next_latency"] = GetMeasuredLatency(next_closest.Address);
     my_entry["next_contype"] = next_closest.ConType;
     Channel result = new Channel();
     //We only want one result, so close the queue after we get the first
     result.CloseAfterEnqueue();
     result.CloseEvent += delegate(object o, EventArgs args) {
       Channel q = (Channel)o;
       if( q.Count > 0 ) {
         try {
           RpcResult rres = (RpcResult)q.Dequeue();
           IList l = (IList) rres.Result;
           ArrayList results = new ArrayList( l.Count + 1);
           results.Add(my_entry);
           results.AddRange(l);
           _rpc.SendResult(req_state, results);
         }
         catch(Exception x) {
           string m = String.Format("<node>{0}</node> trying <connection>{1}</connection> got <exception>{2}</exception>", _node.Address, next_closest, x);
           Exception nx = new Exception(m);
           _rpc.SendResult(req_state, nx);
         }
       }
         else {
           //We got no results.
           IList l = new ArrayList(1);
           l.Add( my_entry );
           _rpc.SendResult(req_state, l);
         }
     };
     _rpc.Invoke(next_closest.Edge, result, "ncserver.ComputePathLatencyTo", a.ToString());
   }
   else {
     //We are the end of the line, send the result:
     ArrayList l = new ArrayList();
     l.Add(my_entry);
     _rpc.SendResult(req_state, l);  
   }
 }
示例#7
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
    }
示例#8
0
 private string GetRandomNodeAddr() {
   AHAddress addr = new AHAddress(new RNGCryptoServiceProvider());
   return addr.ToString();
 }
示例#9
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);
        }
示例#10
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);
        }
示例#11
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);
    }
示例#12
0
        /**
         * Generate tree within the range.
         * return list of MapReduceInfo
         */
        private List <MapReduceInfo> GenerateTreeInRange(AHAddress start, AHAddress end, List <Connection> cons, bool left, MapReduceArgs mr_args)
        {
            //Divide the range and trigger bounded broadcasting again in divided range starting with neighbor.
            //Deivided ranges are (start, n_1), (n_1, n_2), ... , (n_m, end)
            AHAddress            this_minus2 = new AHAddress(_this_addr.ToBigInteger() - 2);
            AHAddress            this_plus2  = new AHAddress(_this_addr.ToBigInteger() + 2);
            List <MapReduceInfo> retval      = new List <MapReduceInfo>();

            if (cons.Count != 0) //make sure if connection list is not empty!
            {
                //con_list is sorted.
                AHAddress last;
                if (left)
                {
                    last = end;
                }
                else
                {
                    last = start;
                }
                string rg_start, rg_end;
                //the first element of cons is the nearest.
                //Let's start with the farthest neighbor first.
                for (int i = (cons.Count - 1); i >= 0; i--)
                {
                    ArrayList  gen_arg   = new ArrayList();
                    Connection next_c    = cons[i];
                    AHAddress  next_addr = (AHAddress)next_c.Address;
                    ISender    sender    = next_c.State.Edge;
                    if (i == 0) // The last bit
                    {
                        if (left)
                        {
                            // the left nearest neighbor
                            rg_start = this_plus2.ToString();
                            rg_end   = last.ToString();
                        }
                        else
                        {
                            // the right nearest neighbor
                            rg_start = last.ToString();
                            rg_end   = this_minus2.ToString();
                        }
                    }
                    else
                    {
                        if (left) //left connections
                        {
                            rg_start = next_addr.ToString();
                            rg_end   = last.ToString();
                        }
                        else //right connections
                        {
                            rg_start = last.ToString();
                            rg_end   = next_addr.ToString();
                        }
                    }
                    gen_arg.Add(rg_start);
                    gen_arg.Add(rg_end);
                    MapReduceInfo mr_info = new MapReduceInfo(sender,
                                                              new MapReduceArgs(this.TaskName,
                                                                                mr_args.MapArg,
                                                                                gen_arg,
                                                                                mr_args.ReduceArg));
                    Log("{0}: {1}, adding address: {2} to sender list, range start: {3}, range end: {4}",
                        this.TaskName, _node.Address, next_c.Address,
                        gen_arg[0], gen_arg[1]);
                    if (left)
                    {
                        last = new AHAddress(next_addr.ToBigInteger() - 2);
                    }
                    else
                    {
                        last = new AHAddress(next_addr.ToBigInteger() + 2);
                    }
                    retval.Add(mr_info);
                }
            }
            return(retval);
        }
示例#13
0
        /// <summary>Make sure there are no entries in the Dht, who we should be
        /// connected to, but aren't.</summary>
        protected void CheckAndUpdateRemoteTAs(List <TransportAddress> tas)
        {
            AHAddress  right = null, left = null;
            BigInteger right_dist = null, left_dist = null;
            AHAddress  addr = _node.Address as AHAddress;

            // Find the closest left and right nodes
            foreach (TransportAddress ta in tas)
            {
                AHAddress target = (ta as SubringTransportAddress).Target;
                if (target.Equals(addr))
                {
                    continue;
                }
                BigInteger ldist = addr.LeftDistanceTo(target);
                BigInteger rdist = addr.RightDistanceTo(target);

                if (left_dist == null || ldist < left_dist)
                {
                    left_dist = ldist;
                    left      = target;
                }

                if (right_dist == null || rdist < right_dist)
                {
                    right_dist = rdist;
                    right      = target;
                }
            }

            ConnectionList cl        = _node.ConnectionTable.GetConnections(ConnectionType.Structured);
            int            local_idx = ~cl.IndexOf(_node.Address);

            if (left != null)
            {
                int remote_idx = ~cl.IndexOf(left);
                // If we're not connected to the left closest and its closer than any
                // of our current peers, let's connect to it
                if (remote_idx > 0 && Math.Abs(local_idx - remote_idx) < 2)
                {
                    List <TransportAddress> tmp_tas = new List <TransportAddress>(1);
                    tmp_tas.Add(new SubringTransportAddress(left, _shared_namespace));
                    Linker linker = new Linker(_node, null, tmp_tas, "leaf", addr.ToString());
                    linker.Start();
                }
            }

            if (right != null && right != left)
            {
                int remote_idx = ~cl.IndexOf(right);
                // If we're not connected to the right closest and its closer than any
                // of our current peers, let's connect to it
                if (remote_idx > 0 && Math.Abs(local_idx - remote_idx) < 2)
                {
                    List <TransportAddress> tmp_tas = new List <TransportAddress>(1);
                    tas.Add(new SubringTransportAddress(right, _shared_namespace));
                    Linker linker = new Linker(_node, null, tmp_tas, "leaf", addr.ToString());
                    linker.Start();
                }
            }

            UpdateRemoteTAs(tas);
        }
示例#14
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 Brunet.DistributedServices.TableServer(node);
      return node;
    }