/// <summary>Given a EdgeListener info and a list of addresses to advertise, /// returns an EdgeListener.</summary> protected EdgeListener CreateBaseEdgeListener(NodeConfig.EdgeListener el_info, ApplicationNode node, IEnumerable addresses) { EdgeListener el = null; int port = el_info.port; if (el_info.type == "tcp") { try { el = new TcpEdgeListener(port, addresses); } catch { el = new TcpEdgeListener(0, addresses); } } else if (el_info.type == "udp") { try { el = new UdpEdgeListener(port, addresses); } catch { el = new UdpEdgeListener(0, addresses); } } else if (el_info.type == "function") { port = port == 0 ? (new Random()).Next(1024, 65535) : port; el = new FunctionEdgeListener(port, 0, null); } else { throw new Exception("Unrecognized transport: " + el_info.type); } return(el); }
/// <summary>Given a EdgeListener info and a list of addresses to advertise, /// returns an EdgeListener.</summary> protected EdgeListener CreateBaseEdgeListener(NodeConfig.EdgeListener el_info, ApplicationNode node, IEnumerable addresses) { EdgeListener el = null; int port = el_info.port; if (el_info.type == "tcp") { try { el = new TcpEdgeListener(port, addresses); } catch { el = new TcpEdgeListener(0, addresses); } } else if (el_info.type == "udp") { try { el = new UdpEdgeListener(port, addresses); } catch { el = new UdpEdgeListener(0, addresses); } } else if (el_info.type == "function") { port = port == 0 ? (new Random()).Next(1024, 65535) : port; el = new FunctionEdgeListener(port, 0, null); } else if (el_info.type == "xmpp") { if (!_node_config.XmppServices.Enabled) { throw new Exception("XmppServices must be enabled to use XmppEL"); } el = new XmppEdgeListener(XmppService); node.Node.AddTADiscovery(new XmppDiscovery(node.Node, XmppService, node.Node.Realm)); } else { throw new Exception("Unrecognized transport: " + el_info.type); } return(el); }
/// <summary>Given a EdgeListener info and a list of addresses to advertise, /// returns an EdgeListener.</summary> protected EdgeListener CreateBaseEdgeListener(NodeConfig.EdgeListener el_info, ApplicationNode node, IEnumerable addresses) { EdgeListener el = null; int port = el_info.port; if(el_info.type == "tcp") { try { el = new TcpEdgeListener(port, addresses); } catch { el = new TcpEdgeListener(0, addresses); } } else if(el_info.type == "udp") { try { el = new UdpEdgeListener(port, addresses); } catch { el = new UdpEdgeListener(0, addresses); } } else if(el_info.type == "function") { port = port == 0 ? (new Random()).Next(1024, 65535) : port; el = new FunctionEdgeListener(port, 0, null); } else if(el_info.type == "xmpp") { if(!_node_config.XmppServices.Enabled) { throw new Exception("XmppServices must be enabled to use XmppEL"); } el = new XmppEdgeListener(XmppService); node.Node.AddTADiscovery(new XmppDiscovery(node.Node, XmppService, node.Node.Realm)); } else { throw new Exception("Unrecognized transport: " + el_info.type); } return el; }
static void Main(string[] args) { RandomNumberGenerator rng = new RNGCryptoServiceProvider(); //Initialize hosts Console.WriteLine("\n\n---------------------------------------\n\n"); int port = 20287; int net_size = 3; string net_type = "function"; if (args.Length > 0) { net_size = Int32.Parse(args[0]); } if (args.Length > 1) { net_type = args[1]; } int ms_sleep = 0; if (args.Length > 2) { ms_sleep = Int32.Parse(args[2]); } bool wait_after_connect = true; if (args.Length > 3) { ///@todo we really need better option parsing here wait_after_connect = false; } ArrayList node_list = new ArrayList(); Hashtable add_to_node = new Hashtable(); PathELManager pem = null; for (int loop = 0; loop < net_size; loop++) { //create and initialize new host //create one new node for each host AHAddress tmp_add = new AHAddress(rng); Node tmp_node = new StructuredNode(tmp_add, "bstland"); //Node tmp_node = new HybridNode(tmp_add, "bstland"); node_list.Add(tmp_node); add_to_node[tmp_add] = tmp_node; //long small_add = 2*(loop+1); //Node tmp_node = new StructuredNode(new AHAddress( new BigInteger(small_add)) ); PType path_p = PType.Protocol.Pathing; switch (net_type) { case "tcp": tmp_node.AddEdgeListener(new TcpEdgeListener(port + loop)); break; case "udp": tmp_node.AddEdgeListener(new UdpEdgeListener(port + loop)); break; case "function": tmp_node.AddEdgeListener(new FunctionEdgeListener(port + loop)); break; case "path": if (pem == null) { EdgeListener el = new UdpEdgeListener(port); pem = new PathELManager(el); pem.Start(); } //Pass path messages to the pem: tmp_node.DemuxHandler.GetTypeSource(path_p).Subscribe(pem, path_p); tmp_node.AddEdgeListener(pem.CreatePath((port + loop).ToString())); Console.WriteLine(port + loop); break; case "single_path": EdgeListener myel = new UdpEdgeListener(port + loop); //Test "default" path edge listener: pem = new PathELManager(myel); pem.Start(); tmp_node.DemuxHandler.GetTypeSource(path_p).Subscribe(pem, path_p); //Make the default path: tmp_node.AddEdgeListener(pem.CreateRootPath()); break; default: throw new Exception("Unknown net type: " + net_type); } //tmp_node.AddEdgeListener(new FunctionEdgeListener(port+loop)); for (int loop2 = 0; loop2 < net_size; loop2++) { if (loop == loop2) { continue; } int other_port = port + loop2; string ta_str = null; switch (net_type) { case "tcp": ta_str = "brunet.tcp://127.0.0.1:"; break; case "udp": ta_str = "brunet.udp://127.0.0.1:"; break; case "function": ta_str = "brunet.function://localhost:"; break; case "path": ta_str = String.Format("brunet.udp://127.0.0.1:{0}/", port); break; case "single_path": ta_str = "brunet.udp://127.0.0.1:"; break; default: throw new Exception("Unknown net type: " + net_type); } ta_str = ta_str + other_port.ToString(); TransportAddress this_ta = TransportAddressFactory.CreateInstance(ta_str); tmp_node.RemoteTAs.Add(this_ta); } } //This logs the changes in connection table BootStrapTester bst = new BootStrapTester(node_list); if (bst != null) { //This is just here to prevent a warning for //not using bst, which is just an observer } //Get Connected: int total_started = 0; ArrayList rnd_list = (ArrayList)node_list.Clone(); Random rnd = new Random(); for (int j = 0; j < rnd_list.Count; j++) { //Swap the j^th position with this position: int i = rnd.Next(j, rnd_list.Count); if (i != j) { object o = rnd_list[i]; rnd_list[i] = rnd_list[j]; rnd_list[j] = o; } } ArrayList c_threads = new ArrayList(); //var xrms = new Brunet.Rpc.XmlRpcManagerServer(20000); int cnt = 0; foreach (Node item in rnd_list) { Thread t = new Thread(item.Connect); c_threads.Add(t); t.Start(); //xrms.Add(item, "xm" + cnt++ + ".rem"); Console.WriteLine(item.Address.ToString() + " RemoteTAs count: " + item.RemoteTAs.Count); total_started++; Console.WriteLine("Started: " + total_started.ToString()); //Thread.Sleep(10000); Thread.Sleep(ms_sleep); //Console.ReadLine(); //foreach (TransportAddress item2 in item.RemoteTAs) // Console.WriteLine(item2); } System.Console.Out.WriteLine("Finished with BootStrapTester.Main"); string[] this_command = new string[] { "Q" }; if (wait_after_connect) { Console.WriteLine("Enter Q to stop"); this_command = Console.ReadLine().Split(' '); } while (this_command[0] != "Q") { if (this_command[0] == "D") { //Disconnect a node: int node = -1; try { node = Int32.Parse(this_command[1]); Node to_disconnect = (Node)node_list[node]; Console.WriteLine("About to Disconnect: {0}", to_disconnect.Address); to_disconnect.Disconnect(); bst.Remove(to_disconnect); } catch (Exception) { } } if (this_command[0] == "abort") { //Disconnect a node: int node = -1; try { node = Int32.Parse(this_command[1]); Node to_abort = (Node)node_list[node]; Console.WriteLine("About to Abort: {0}", to_abort.Address); to_abort.Abort(); bst.Remove(to_abort); } catch (Exception) { } } if (this_command[0] == "P") { //Pick a random pair of nodes to ping: Ping(node_list); } if (this_command[0] == "BP") { try { int reps = Int32.Parse(this_command[1]); bst.BenchmarkPing(reps); } catch (Exception x) { Console.WriteLine(x); } } if (this_command[0] == "BH") { try { int reps = Int32.Parse(this_command[1]); bst.BenchmarkHops(reps); } catch (Exception x) { Console.WriteLine(x); } } if (this_command[0] == "T") { //Pick a random pair of nodes to ping: TraceRoute(node_list); } if (wait_after_connect) { this_command = Console.ReadLine().Split(' '); } } foreach (Node n in node_list) { n.Disconnect(); } if (pem != null) { pem.Stop(); } //Block until all Connect threads finish. //foreach(Thread t in c_threads) { // t.Join(); //} }
static void Main(string[] args) { RandomNumberGenerator rng = new RNGCryptoServiceProvider(); //Initialize hosts Console.WriteLine("\n\n---------------------------------------\n\n"); int port = 20287; int net_size = 3; string net_type = "function"; if( args.Length > 0 ) { net_size = Int32.Parse(args[0]); } if( args.Length > 1 ) { net_type = args[1]; } int ms_sleep = 0; if( args.Length > 2 ) { ms_sleep = Int32.Parse(args[2]); } bool wait_after_connect = true; if( args.Length > 3 ) { ///@todo we really need better option parsing here wait_after_connect = false; } ArrayList node_list = new ArrayList(); Hashtable add_to_node = new Hashtable(); PathELManager pem = null; for (int loop=0;loop<net_size;loop++) { //create and initialize new host //create one new node for each host AHAddress tmp_add = new AHAddress(rng); Node tmp_node = new StructuredNode(tmp_add, "bstland"); //Node tmp_node = new HybridNode(tmp_add, "bstland"); node_list.Add(tmp_node); add_to_node[tmp_add] = tmp_node; //long small_add = 2*(loop+1); //Node tmp_node = new StructuredNode(new AHAddress( new BigInteger(small_add)) ); PType path_p = PType.Protocol.Pathing; switch(net_type) { case "tcp": tmp_node.AddEdgeListener(new TcpEdgeListener(port+loop)); break; case "udp": tmp_node.AddEdgeListener(new UdpEdgeListener(port+loop)); break; case "function": tmp_node.AddEdgeListener(new FunctionEdgeListener(port+loop)); break; case "path": if( pem == null ) { EdgeListener el = new UdpEdgeListener(port); pem = new PathELManager(el); pem.Start(); } //Pass path messages to the pem: tmp_node.DemuxHandler.GetTypeSource(path_p).Subscribe(pem, path_p); tmp_node.AddEdgeListener(pem.CreatePath( (port+loop).ToString() )); Console.WriteLine(port+loop); break; case "single_path": EdgeListener myel = new UdpEdgeListener(port+loop); //Test "default" path edge listener: pem = new PathELManager(myel); pem.Start(); tmp_node.DemuxHandler.GetTypeSource(path_p).Subscribe(pem, path_p); //Make the default path: tmp_node.AddEdgeListener(pem.CreateRootPath()); break; default: throw new Exception("Unknown net type: " + net_type); } //tmp_node.AddEdgeListener(new FunctionEdgeListener(port+loop)); for (int loop2=0;loop2<net_size;loop2++) { if (loop == loop2) { continue; } int other_port = port+loop2; string ta_str = null; switch(net_type) { case "tcp": ta_str = "brunet.tcp://127.0.0.1:"; break; case "udp": ta_str = "brunet.udp://127.0.0.1:"; break; case "function": ta_str = "brunet.function://localhost:"; break; case "path": ta_str = String.Format("brunet.udp://127.0.0.1:{0}/",port); break; case "single_path": ta_str = "brunet.udp://127.0.0.1:"; break; default: throw new Exception("Unknown net type: " + net_type); } ta_str = ta_str + other_port.ToString(); TransportAddress this_ta = TransportAddressFactory.CreateInstance(ta_str); tmp_node.RemoteTAs.Add(this_ta); } } //This logs the changes in connection table BootStrapTester bst = new BootStrapTester(node_list); if( bst != null ) { //This is just here to prevent a warning for //not using bst, which is just an observer } //Get Connected: int total_started = 0; ArrayList rnd_list = (ArrayList)node_list.Clone(); Random rnd = new Random(); for(int j = 0; j < rnd_list.Count; j++) { //Swap the j^th position with this position: int i = rnd.Next(j, rnd_list.Count); if( i != j ) { object o = rnd_list[i]; rnd_list[i] = rnd_list[j]; rnd_list[j] = o; } } ArrayList c_threads = new ArrayList(); //var xrms = new Brunet.Rpc.XmlRpcManagerServer(20000); int cnt = 0; foreach( Node item in rnd_list) { Thread t = new Thread( item.Connect ); c_threads.Add(t); t.Start(); //xrms.Add(item, "xm" + cnt++ + ".rem"); Console.WriteLine(item.Address.ToString() + " RemoteTAs count: " + item.RemoteTAs.Count); total_started++; Console.WriteLine("Started: " + total_started.ToString()); //Thread.Sleep(10000); Thread.Sleep(ms_sleep); //Console.ReadLine(); //foreach (TransportAddress item2 in item.RemoteTAs) // Console.WriteLine(item2); } System.Console.Out.WriteLine("Finished with BootStrapTester.Main"); string[] this_command = new string[] { "Q" }; if( wait_after_connect) { Console.WriteLine("Enter Q to stop"); this_command = Console.ReadLine().Split(' '); } while( this_command[0] != "Q" ) { if( this_command[0] == "D" ) { //Disconnect a node: int node = -1; try { node = Int32.Parse(this_command[1]); Node to_disconnect = (Node)node_list[node]; Console.WriteLine("About to Disconnect: {0}", to_disconnect.Address); to_disconnect.Disconnect(); bst.Remove(to_disconnect); } catch(Exception) { } } if( this_command[0] == "abort" ) { //Disconnect a node: int node = -1; try { node = Int32.Parse(this_command[1]); Node to_abort = (Node)node_list[node]; Console.WriteLine("About to Abort: {0}", to_abort.Address); to_abort.Abort(); bst.Remove(to_abort); } catch(Exception) { } } if( this_command[0] == "P" ) { //Pick a random pair of nodes to ping: Ping(node_list); } if( this_command[0] == "BP" ) { try { int reps = Int32.Parse(this_command[1]); bst.BenchmarkPing(reps); } catch(Exception x) { Console.WriteLine(x); } } if( this_command[0] == "BH" ) { try { int reps = Int32.Parse(this_command[1]); bst.BenchmarkHops(reps); } catch(Exception x) { Console.WriteLine(x); } } if( this_command[0] == "T" ) { //Pick a random pair of nodes to ping: TraceRoute(node_list); } if( wait_after_connect ) { this_command = Console.ReadLine().Split(' '); } } foreach(Node n in node_list) { n.Disconnect(); } if( pem != null ) { pem.Stop(); } //Block until all Connect threads finish. //foreach(Thread t in c_threads) { // t.Join(); //} }
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: */ EdgeListener el = null; int port = Int32.Parse(args[1]); if (args[0].ToLower() == "tcp") { el = new TcpEdgeListener(port); } else if (args[0].ToLower() == "udp") { el = new 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(); AHAddress tmp_add = new AHAddress(rng); Console.WriteLine("Address: {0}", tmp_add); /** * Make the node that lives in a particular * using Brunet.Messaging; * namespace (or realm) called "testspace" */ Node tmp_node = new StructuredNode(tmp_add, "testspace"); ReqrepManager rrman = tmp_node.Rrm; 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); }
/// <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); } } 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 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); } }
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: */ EdgeListener el = null; int port = Int32.Parse( args[1] ); if( args[0].ToLower() == "tcp" ) { el = new TcpEdgeListener(port); } else if( args[0].ToLower() == "udp" ) { el = new 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(); AHAddress tmp_add = new AHAddress(rng); Console.WriteLine("Address: {0}", tmp_add); /** * Make the node that lives in a particular using Brunet.Messaging; * namespace (or realm) called "testspace" */ Node tmp_node = new StructuredNode(tmp_add, "testspace"); ReqrepManager rrman = tmp_node.Rrm; 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; }
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(string type) { NodeConfig node_config = null; StructuredNode current_node = null; AHAddress address = null; ProtocolSecurityOverlord bso; if (type == "cache") { node_config = _c_node_config; //Node configuration file: the description of service that node provides address = (AHAddress) AddressParser.Parse(node_config.NodeAddress); current_node = new StructuredNode(address, node_config.BrunetNamespace); // DeetooNode consists of two Structured Nodes bso = _c_bso; } else if ( type == "query" ) { node_config = _q_node_config; address = (AHAddress) AddressParser.Parse(node_config.NodeAddress); current_node = new StructuredNode(address, node_config.BrunetNamespace); bso = _q_bso; } else { throw new Exception("Unrecognized node type: " + type); } 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(current_node, rsa_private, current_node.Rrm, ch); bso.Subscribe(current_node, null); current_node.GetTypeSource(SecurityOverlord.Security).Subscribe(bso, null); current_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); } } 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); } 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; } ITunnelOverlap ito = null; ito = new SimpleTunnelOverlap(); el = new Tunnel.TunnelEdgeListener(current_node, ito); if(node_config.Security.SecureEdgesEnabled) { current_node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName; el = new SecureEdgeListener(el, bso); } current_node.AddEdgeListener(el); new TableServer(current_node); if (type == "cache") { _c_dht = new Dht(current_node, 3, 20); _c_dht_proxy = new RpcDhtProxy(_c_dht, current_node); _cs = new CacheList(current_node); //_cll = new ClusterList(current_node); //current_node.MapReduce.SubscribeTask(new MapReduceClusterCache(current_node, _cll)); current_node.MapReduce.SubscribeTask(new MapReduceCache(current_node,_cs)); Console.WriteLine("MapReduceCacheTask is subscribed at {0}", current_node.Address); _c_node = current_node; } else { _q_dht = new Dht(current_node, 3, 20); _q_dht_proxy = new RpcDhtProxy(_c_dht, current_node); CacheList q_cs = new CacheList(current_node); //current_node.MapReduce.SubscribeTask(new MapReduceClusterQuery(current_node, _cll)); current_node.MapReduce.SubscribeTask(new MapReduceQuery(current_node,_cs)); Console.WriteLine("MapReduceQueryTask is subscribed at {0}", current_node.Address); _q_node = current_node; } }
/// <summary>Given a EdgeListener info and a list of addresses to advertise, /// returns an EdgeListener.</summary> protected EdgeListener CreateBaseEdgeListener(NodeConfig.EdgeListener el_info, ApplicationNode node, IEnumerable addresses) { EdgeListener el = null; int port = el_info.port; if(el_info.type == "tcp") { try { el = new TcpEdgeListener(port, addresses); } catch { el = new TcpEdgeListener(0, addresses); } } else if(el_info.type == "udp") { try { el = new UdpEdgeListener(port, addresses); } catch { el = new UdpEdgeListener(0, addresses); } } else if(el_info.type == "function") { port = port == 0 ? (new Random()).Next(1024, 65535) : port; el = new FunctionEdgeListener(port, 0, null); } else { throw new Exception("Unrecognized transport: " + el_info.type); } return el; }