/// <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; }
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; }