public void InitFixture() { ConsoleTraceListener myWriter = new ConsoleTraceListener(); Debug.Listeners.Add(myWriter); Node n = new StructuredNode(new AHAddress(new RNGCryptoServiceProvider())); _rpc = XmlRpcManagerClient.GetXmlRpcManager("127.0.0.1", Port, "xm.rem", true); _mrm = MockRpcManager.GetInstance(n); _server = new XmlRpcManagerServer(Port); _server.Add(n, _mrm, "xm1.rem"); Debug.WriteLine(string.Format("Server started at {0}", Port)); }
/** <summary>This method is registered as a delegate to Shutdown.OnExit and will be called when ctrl-c is pressed by the user. This stops services, prevents the node from reincarnating, and then disconnects the node. </summary> */ public virtual void OnExit() { _running = false; if(_xrm != null) { _xrm.Stop(); _xrm = null; } ApplicationNode appnode = _app_node; _app_node = null; NCService ncservice = null; if(appnode != null) { ncservice = appnode.NCService; } if(ncservice != null && _node_config.NCService.Checkpointing) { string checkpoint = ncservice.GetCheckpoint(); string prev_cp = _node_config.NCService.Checkpoint; string empty_cp = (new Point()).ToString(); if(!checkpoint.Equals(prev_cp) && !checkpoint.Equals(empty_cp)) { _node_config.NCService.Checkpoint = checkpoint; _node_config.WriteConfig(); } } _fe_stop_pem = Brunet.Util.FuzzyTimer.Instance.DoEvery(StopPem, 500, 500); }
/// <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; }
internal Dumper(XmlRpcManagerServer outer) { _outer = outer; }
/** <summary>This stops all services such as Xml and DhtRpc. Call this instead of SuspendServices if the node is shutting down or services are no longer required and you would like to release the ports</summary> */ public virtual void StopServices() { if(_xrm != null) { _xrm.Stop(); _xrm = null; } }
/// <summary>Starts services such as shutdown, rpcdht, and xmlrpc. If you wish /// to have your own shutdown path, edit OnExit instead of this. This can be /// called multiple times without negative effect.</summary> public virtual void StartServices() { _shutdown.OnExit += OnExit; if(_node_config.XmlRpcManager.Enabled) { if(_xrm == null) { _xrm = new XmlRpcManagerServer(_node_config.XmlRpcManager.Port); } _xrm.Add(_node); new RpcDht(_dht, _node); } }
/** <summary>Starts services such as shutdown, rpcdht, and xmlrpc. If you wish to have your own shutdown path, edit OnExit instead of this. This can be called multiple times without negative effect.</summary> */ public virtual void StartServices() { string type = "cache"; if(_c_node_config.XmlRpcManager.Enabled) { if(_xrm == null) { _xrm = new XmlRpcManagerServer(_c_node_config.XmlRpcManager.Port); } string uri = string.Format("{0}.rem",type); _xrm.Add(_c_node, uri); type = "query"; uri = string.Format("{0}.rem",type); _xrm.Add(_q_node, uri); new RpcDht(_c_dht, _c_node); new RpcDht(_q_dht, _q_node); } }