public void Test() { Address addr_x = new AHAddress(new RNGCryptoServiceProvider()); byte[] addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (Address.Full / 2)); Address.SetClass(addrbuff, AHAddress._class); Address addr_y = new AHAddress(addrbuff); List<Connection> connections = new List<Connection>(); ConnectionTable ct_x = new ConnectionTable(); ConnectionTable ct_y = new ConnectionTable(); ConnectionTable ct_empty = new ConnectionTable(); NCService ncservice = new NCService(); Connection fast_con = null; for(int i = 1; i <= 11; i++) { addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (i * Address.Full / 16)); Address.SetClass(addrbuff, AHAddress._class); Address addr = new AHAddress(addrbuff); Connection con = null; TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://158.7.0.1:5000"); Edge fe = new FakeEdge(ta, ta, TransportAddress.TAType.Tcp); if(i <= 10) { con = new Connection(fe, addr, "structured", null, null); ct_x.Add(con); if(i % 2 == 0) { ncservice.ProcessSample(DateTime.UtcNow, String.Empty, addr, new Point(new double[] {0, 0}, 0), 0, i*10); } } else { fast_con = new Connection(fe, addr, "structured", null, null); ncservice.ProcessSample(DateTime.UtcNow, String.Empty, addr, new Point(new double[] {0, 0}, 0), 0, 5); } if(i == 10) { ct_y.Add(con); } connections.Add(con); } ITunnelOverlap sto = new SimpleTunnelOverlap(); ITunnelOverlap nto = new NCTunnelOverlap(ncservice); ConnectionType con_type = ConnectionType.Structured; List<Connection> pre_cons = new List<Connection>(); pre_cons.Add(connections[9]); IDictionary id = nto.GetSyncMessage(pre_cons, addr_x, ct_x.GetConnections(con_type)); // We do have some pre-existing overlap Assert.AreEqual(nto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], connections[9], "NC: Have an overlap!"); Assert.AreEqual(sto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], connections[9], "Simple: Have an overlap!"); // We have no overlap with an empty connection table Assert.AreEqual(nto.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!"); Assert.AreEqual(sto.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!"); // latency[0] == -1 Assert.AreEqual(connections[1].Address.Equals(nto.EvaluatePotentialOverlap(id)), true, "NC: EvaluatePotentialOverlap returns expected!"); Assert.AreEqual(ct_x.Contains(con_type, sto.EvaluatePotentialOverlap(id)), true, "Simple: EvaluatePotentialOverlap returns valid!"); ct_y.Add(fast_con); ct_x.Add(fast_con); id = nto.GetSyncMessage(pre_cons, addr_x, ct_x.GetConnections(con_type)); Assert.AreEqual(fast_con.Address.Equals(nto.EvaluatePotentialOverlap(id)), true, "NC: EvaluatePotentialOverlap returns expected!"); Assert.AreEqual(nto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], fast_con, "NC: Have better overlap!"); }
/// <summary>Creates a Brunet.Node, the resulting node will be available in /// the class as _node.</summary> /// <remarks>The steps to creating a node are first constructing it with a /// namespace, optionally adding local ip addresses to bind to, specifying /// local end points, specifying remote end points, and finally registering /// the dht.</remarks> public virtual void CreateNode() { AHAddress address = null; try { address = (AHAddress) AddressParser.Parse(_node_config.NodeAddress); } catch { address = Utils.GenerateAHAddress(); } _node = new StructuredNode(address, _node_config.BrunetNamespace); IEnumerable addresses = IPAddresses.GetIPAddresses(_node_config.DevicesToBind); 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 = new CertificateHandler(_node_config.Security.CertificatePath); _bso = new ProtocolSecurityOverlord(_node, rsa_private, _node.Rrm, ch); _bso.Subscribe(_node, null); _node.GetTypeSource(SecurityOverlord.Security).Subscribe(_bso, null); _node.HeartBeatEvent += _bso.Heartbeat; 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); } } Brunet.EdgeListener el = null; foreach(NodeConfig.EdgeListener item in _node_config.EdgeListeners) { int port = item.port; if(item.type == "tcp") { try { el = new TcpEdgeListener(port, addresses); } catch { el = new TcpEdgeListener(0, addresses); } } else if(item.type == "udp") { try { el = new UdpEdgeListener(port, addresses); } catch { el = new UdpEdgeListener(0, addresses); } } else if(item.type == "function") { port = port == 0 ? (new Random()).Next(1024, 65535) : port; el = new FunctionEdgeListener(port, 0, null); } else { throw new Exception("Unrecognized transport: " + item.type); } if(_node_config.Security.SecureEdgesEnabled) { el = new SecureEdgeListener(el, _bso); } _node.AddEdgeListener(el); } ArrayList RemoteTAs = null; if(_node_config.RemoteTAs != null) { RemoteTAs = new ArrayList(); foreach(String ta in _node_config.RemoteTAs) { RemoteTAs.Add(TransportAddressFactory.CreateInstance(ta)); } _node.RemoteTAs = RemoteTAs; } ITunnelOverlap ito = 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 NCTunnelOverlap(_ncservice); } else { ito = new SimpleTunnelOverlap(); } el = new Tunnel.TunnelEdgeListener(_node, ito); if(_node_config.Security.SecureEdgesEnabled) { _node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName; el = new SecureEdgeListener(el, _bso); } _node.AddEdgeListener(el); new TableServer(_node); _dht = new Dht(_node, 3, 20); _dht_proxy = new RpcDhtProxy(_dht, _node); }
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(); }
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; }