// adds a node to the pool private static void add_node(bool output) { AHAddress address = new AHAddress(new RNGCryptoServiceProvider()); Node node = new StructuredNode(address, brunet_namespace); NodeMapping nm = new NodeMapping(); nm.Node = node; nodes.Add((Address) address, nm); nm.Port = rand.Next(1024, 65535); while(TakenPorts.Contains(nm.Port)) { nm.Port = rand.Next(1024, 65535); } EdgeListener el = null; if(edge_type.Equals("function")) { el = new FunctionEdgeListener(nm.Port, 0, null); } else if(edge_type.Equals("tcp")) { el = new TcpEdgeListener(nm.Port); } else if(edge_type.Equals("udp")) { el = new UdpEdgeListener(nm.Port); } node.AddEdgeListener(el); if(!discovery) { ArrayList RemoteTAs = new ArrayList(); for(int i = 0; i < 5 && i < TakenPorts.Count; i++) { int rport = (int) TakenPorts.GetByIndex(rand.Next(0, TakenPorts.Count)); RemoteTAs.Add(TransportAddressFactory.CreateInstance("brunet." + edge_type + "://127.0.0.1:" + rport)); } node.RemoteTAs = RemoteTAs; } TakenPorts[nm.Port] = nm.Port; if(dht_enabled) { nm.Dht = new Dht(node, 3); } if(output) { Console.WriteLine("Adding: " + nm.Node.Address); } (new Thread(node.Connect)).Start(); network_size++; }
public static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: edgetester.exe " + "[client|server] [tcp|udp|function] port " + "localhost|qubit|cantor|starsky|behnam|kupka)"); return; } if( args.Length >= 5) { delay = Int32.Parse(args[4]); } EdgeFactory ef = new EdgeFactory(); int port = System.Int16.Parse(args[2]); _threads = ArrayList.Synchronized(new ArrayList()); EdgeListener el = null; if( args[1] == "function" ) { //This is a special case, it only works in one thread el = new FunctionEdgeListener(port); el.EdgeEvent += new EventHandler(HandleEdge); //Start listening: el.Start(); ef.AddListener(el); el.CreateEdgeTo( TransportAddressFactory.CreateInstance("brunet.function://localhost:" + port), ClientLoop); } else if (args[0] == "server") { if (args[1] == "tcp") { el = new TcpEdgeListener(port); } else if (args[1] == "udp") { el = new UdpEdgeListener(port); } else { el = null; } el.EdgeEvent += new EventHandler(HandleEdge); //Start listening: el.Start(); _el = el; Console.WriteLine("Press Q to quit"); Console.ReadLine(); el.Stop(); } else if (args[0] == "client") { TransportAddress ta = null; if (args[1] == "tcp") { el = new TcpEdgeListener(port + 1); } else if (args[1] == "udp") { el = new UdpEdgeListener(port + 1); } else { el = null; } ef.AddListener(el); _el = el; string uri = "brunet." + args[1] + "://" + NameToIP(args[3]) + ":" + port; ta = TransportAddressFactory.CreateInstance(uri); System.Console.WriteLine("Making edge to {0}\n", ta.ToString()); el.Start(); ef.CreateEdgeTo(ta, ClientLoop); } }
/** <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 = (AHAddress) AddressParser.Parse(_node_config.NodeAddress); _node = new StructuredNode(address, _node_config.BrunetNamespace); IEnumerable addresses = IPAddresses.GetIPAddresses(_node_config.DevicesToBind); 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 { throw new Exception("Unrecognized transport: " + item.type); } _node.AddEdgeListener(el); } el = new TunnelEdgeListener(_node); _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; } try { if (_node_config.NCService.Enabled) { _ncservice = new NCService(_node, _node_config.NCService.Checkpoint); if (_node_config.NCService.OptimizeShortcuts) { _node.Sco.TargetSelector = new VivaldiTargetSelector(_node, _ncservice); } } } catch {} _dht = new Dht(_node, 3, 20); }
/** <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(string type) { NodeConfig node_config = null; StructuredNode current_node = null; AHAddress address = null; if (type == "cache") { node_config = _c_node_config; address = (AHAddress) AddressParser.Parse(node_config.NodeAddress); current_node = new StructuredNode(address, node_config.BrunetNamespace); } else if ( type == "query" ) { node_config = _q_node_config; address = (AHAddress) AddressParser.Parse(node_config.NodeAddress); current_node = new StructuredNode(address, node_config.BrunetNamespace); } else { throw new Exception("Unrecognized node type: " + type); } IEnumerable addresses = IPAddresses.GetIPAddresses(node_config.DevicesToBind); 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 { throw new Exception("Unrecognized transport: " + item.type); } current_node.AddEdgeListener(el); } el = new TunnelEdgeListener(current_node); current_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)); } current_node.RemoteTAs = RemoteTAs; } try { if (node_config.NCService.Enabled) { if (type == "cache") { _c_ncservice = new NCService(current_node, node_config.NCService.Checkpoint); if (node_config.NCService.OptimizeShortcuts) { current_node.Sco.TargetSelector = new VivaldiTargetSelector(current_node, _c_ncservice); } } else { _q_ncservice = new NCService(current_node, node_config.NCService.Checkpoint); if (node_config.NCService.OptimizeShortcuts) { current_node.Sco.TargetSelector = new VivaldiTargetSelector(current_node, _q_ncservice); } } } } catch {} if (type == "cache") { _c_dht = new Dht(current_node, 3, 20); _cs = new CacheList(current_node); current_node.MapReduce.SubscribeTask(new MapReduceCache(current_node,_cs)); current_node.MapReduce.SubscribeTask(new MapReduceCrawl(current_node)); _c_node = current_node; } else { _q_dht = new Dht(current_node, 3, 20); CacheList q_cs = new CacheList(current_node); current_node.MapReduce.SubscribeTask(new MapReduceQuery(current_node,_cs)); current_node.MapReduce.SubscribeTask(new MapReduceCrawl(current_node)); _q_node = current_node; } }
/// <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); }
public static int Main(string[] args) { /** * Get the arguments */ if( args.Length < 2 ) { Console.Error.WriteLine("usage: SNodeExample.exe [tcp|udp] port remota_ta0 remote_ta1 ..."); return 0; } /** * Make the edge listener: */ Brunet.EdgeListener el = null; int port = Int32.Parse( args[1] ); if( args[0].ToLower() == "tcp" ) { el = new Brunet.TcpEdgeListener(port); } else if( args[0].ToLower() == "udp" ) { el = new Brunet.UdpEdgeListener(port); } /** * Create a random address for our node. * Some other application might want to select the address * a particular way, or reuse a previously selected random * address. If the addresses are not random (or the output * of secure hashes) the network might not behave correctly. */ RandomNumberGenerator rng = new RNGCryptoServiceProvider(); Brunet.AHAddress tmp_add = new Brunet.AHAddress(rng); /** * Make the node that lives in a particular * namespace (or realm) called "testspace" */ Brunet.Node tmp_node = new Brunet.StructuredNode(tmp_add, "testspace"); /** * Add the EdgeListener */ tmp_node.AddEdgeListener( el ); /** * Tell the node who it can connect to: */ for(int i = 2; i < args.Length; i++) { tmp_node.RemoteTAs.Add( Brunet.TransportAddressFactory.CreateInstance( args[i] ) ); } /** * Now we connect, this blocks until Disconnect is called (in some * other thread or by some IDataHandler subscribed (see below). * * If you want to start Connect in its own thread do: * System.Threading.Thread t = new System.Threading.Thread( * delegate() { tmp_node.Connect(); } ); * t.Start(); */ tmp_node.Connect(); /** * In a real application, we would create some IDataHandler * objects and do: * tmp_node.GetTypeSource(PType...).Subscribe(my_handler, my_state) * * Then we can send some packets using AHSender, AHExactSender, etc... */ return 1; }
public static int Main(string[] args) { /** * Get the arguments */ if( args.Length < 2 ) { Console.Error.WriteLine("usage: SNodeExample.exe [tcp|udp] port remota_ta0 remote_ta1 ..."); return 0; } /** * Make the edge listener: */ Brunet.EdgeListener el = null; int port = Int32.Parse( args[1] ); if( args[0].ToLower() == "tcp" ) { el = new Brunet.TcpEdgeListener(port); } else if( args[0].ToLower() == "udp" ) { el = new Brunet.UdpEdgeListener(port); } /** * Create a random address for our node. * Some other application might want to select the address * a particular way, or reuse a previously selected random * address. If the addresses are not random (or the output * of secure hashes) the network might not behave correctly. */ RandomNumberGenerator rng = new RNGCryptoServiceProvider(); Brunet.AHAddress tmp_add = new Brunet.AHAddress(rng); Console.WriteLine("Address: {0}", tmp_add); /** * Make the node that lives in a particular * namespace (or realm) called "testspace" */ Brunet.Node tmp_node = new Brunet.StructuredNode(tmp_add, "testspace"); Brunet.ReqrepManager rrman = Brunet.ReqrepManager.GetInstance(tmp_node); ReqrepExample irh = new ReqrepExample(); tmp_node.GetTypeSource(PType.Protocol.Chat).Subscribe(irh, tmp_node); /** * Add the EdgeListener */ tmp_node.AddEdgeListener( el ); /** * Tell the node who it can connect to: */ for(int i = 2; i < args.Length; i++) { tmp_node.RemoteTAs.Add( TransportAddressFactory.CreateInstance( args[i] ) ); } /** * Now we connect */ tmp_node.Connect(); Console.WriteLine("Connected"); /** * In a real application, we would create some IAHPacketHandler * objects and do: * tmp_node.Subscribe( ) * finally, we could send packets using tmp_node.Send( ) or * tmp_node.SendTo( ) */ string msg = ""; System.Text.Encoding coder = new System.Text.ASCIIEncoding(); while( true ) { Console.Write("To: "); msg = Console.ReadLine(); if ( msg == "q" ) { break; } Address dest = AddressParser.Parse(msg); while( msg != "." ) { msg = Console.ReadLine(); int length = coder.GetByteCount(msg); byte[] payload = new byte[length]; coder.GetBytes(msg, 0, msg.Length, payload, 0); ISender sender = new AHSender(tmp_node, dest); rrman.SendRequest(sender, ReqrepManager.ReqrepType.Request, new CopyList(PType.Protocol.Chat, MemBlock.Reference(payload)), irh , null); } } return 1; }