public virtual int Parse(string[] args)
        {
            try {
                _options.Parse(args);
            } catch (Exception e) {
                _error_message = e.Message;
                return(-1);
            }

            if (_node_config_path == string.Empty || !System.IO.File.Exists(_node_config_path))
            {
                _error_message = "Missing NodeConfig";
                return(-1);
            }

            try {
                Validator.Validate(_node_config_path, NODE_XSD);
                _node_config      = Utils.ReadConfig <NodeConfig>(_node_config_path);
                _node_config.Path = _node_config_path;
            } catch (Exception e) {
                _error_message = "Invalid NodeConfig file: " + e.Message;
                Console.WriteLine(e);
                return(-1);
            }

            return(0);
        }
Exemple #2
0
    public virtual int Parse(string[] args)
    {
      try {
        _options.Parse(args);
      } catch(Exception e) {
        _error_message = e.Message;
        return -1;
      }

      if(_node_config_path == string.Empty || !System.IO.File.Exists(_node_config_path)) {
        _error_message = "Missing NodeConfig";
        return -1;
      }

      try {
        Validator.Validate(_node_config_path, NODE_XSD);
        _node_config = Utils.ReadConfig<NodeConfig>(_node_config_path);
        _node_config.Path = _node_config_path;
      } catch (Exception e) {
        _error_message = "Invalid NodeConfig file: " + e.Message;
        Console.WriteLine(e);
        return -1;
      }

      return 0;
    }
Exemple #3
0
 /// <summary>
 /// The constructor takes two config files
 /// </summary>
 /// <param name="NodeConfigPath">Node config object</param>
 /// <param name="IpopConfigPath">Ipop config object</param>
 public ManagedIpopNode(NodeConfig node_config, IpopConfig ipop_config)
     : base(node_config, ipop_config, null)
 {
     _dhcp_server = ManagedDHCPServer.GetManagedDHCPServer(_ipop_config.VirtualNetworkDevice);
       _dhcp_config = _dhcp_server.Config;
       _marad = new ManagedAddressResolverAndDNS(Brunet, _dhcp_server, ((ManagedDHCPServer) _dhcp_server).LocalIP);
       _dns = _marad;
       _address_resolver = _marad;
       _translator = _marad;
 }
Exemple #4
0
        ///<summary>Creates a DhtIpopNode.</summary>
        /// <param name="NodeConfig">NodeConfig object</param>
        /// <param name="IpopConfig">IpopConfig object</param>
        public DhtIpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config)
            : base(node_config, ipop_config, dhcp_config)
        {
            _address_resolver = new DhtAddressResolver(Dht, _ipop_config.IpopNamespace);

              _connected = false;
              Brunet.StateChangeEvent += StateChangeHandler;
              StateChangeHandler(Brunet, Brunet.ConState);
        }
Exemple #5
0
 public SocialNode(NodeConfig brunetConfig, IpopConfig ipopConfig,
   RSACryptoServiceProvider rsa) 
   : base(brunetConfig, ipopConfig) {
   _friends = ImmutableDictionary<string, SocialUser>.Empty;
   _rsa = rsa;
   _address = AppNode.Node.Address.ToString();
   _user = new WriteOnce<SocialUser>();
   _mco = new ManagedConnectionOverlord(AppNode.Node);
   AppNode.Node.AddConnectionOverlord(_mco);
 }
Exemple #6
0
    /// <summary>Prepares a BasicNode.</summary>
    /// <param name="node_config">A node config object.</param>
    public BasicNode(NodeConfig node_config)
    {
      _node_config = node_config;
      _running = true;
      _shutdown = Shutdown.GetShutdown();
      _shutdown.OnExit += OnExit;

      _type_to_pem = new Dictionary<string, PathELManager>();
      _rand = new Random();
    }
Exemple #7
0
        /// <summary>Prepares a BasicNode.</summary>
        /// <param name="node_config">A node config object.</param>
        public BasicNode(NodeConfig node_config)
        {
            _node_config      = node_config;
            _running          = true;
            _shutdown         = Shutdown.GetShutdown();
            _shutdown.OnExit += OnExit;

            _type_to_pem = new Dictionary <string, PathELManager>();
            _rand        = new Random();
        }
Exemple #8
0
        /// <summary>Create a new node config given a public node config and a
        /// private node config, used to generate the private node.</summary>
        public static NodeConfig GetPrivateNodeConfig(NodeConfig nc)
        {
            NodeConfig private_config = Utils.Copy <NodeConfig>(nc);

            private_config.PrivateNodeConfig = null;
            private_config.BrunetNamespace   = nc.PrivateNodeConfig.BrunetNamespace;
            private_config.Security          = nc.PrivateNodeConfig.Security;
            private_config.RemoteTAs         = new String[0];
            return(private_config);
        }
Exemple #9
0
 public ApplicationNode(StructuredNode node, IDht dht, RpcDhtProxy dht_proxy,
                        NCService ncservice, SecurityOverlord security_overlord, NodeConfig nc)
 {
     Config                   = nc;
     Node                     = node;
     Dht                      = dht;
     DhtProxy                 = dht_proxy;
     NCService                = ncservice;
     SecurityOverlord         = security_overlord;
     SymphonySecurityOverlord = security_overlord as SymphonySecurityOverlord;
 }
Exemple #10
0
    ///<summary>Creates a DhtIpopNode.</summary>
    /// <param name="NodeConfig">NodeConfig object</param>
    /// <param name="IpopConfig">IpopConfig object</param>
    public DhtIpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config) : base(node_config, ipop_config, dhcp_config)
    {
      DhtAddressResolver dar = new DhtAddressResolver(AppNode.Dht, _ipop_config.IpopNamespace);
      Shutdown.OnExit += dar.Stop;
      _address_resolver = dar;

      _connected = false;
      AppNode.Node.StateChangeEvent += StateChangeHandler;
      StateChangeHandler(AppNode.Node, AppNode.Node.ConState);
    }
Exemple #11
0
 public ApplicationNode(StructuredNode node, IDht dht, RpcDhtProxy dht_proxy,
     NCService ncservice, SecurityOverlord security_overlord, NodeConfig nc)
 {
   Config = nc;
   Node = node;
   Dht = dht;
   DhtProxy = dht_proxy;
   NCService = ncservice;
   SecurityOverlord = security_overlord;
   SymphonySecurityOverlord = security_overlord as SymphonySecurityOverlord;
 }
Exemple #12
0
 /// <summary>
 /// The constructor takes two config files
 /// </summary>
 /// <param name="NodeConfigPath">Node config object</param>
 /// <param name="IpopConfigPath">Ipop config object</param>
 public ManagedIpopNode(NodeConfig node_config, IpopConfig ipop_config) :
   base(node_config, ipop_config, null)
 {
   _dhcp_server = ManagedDhcpServer.GetManagedDhcpServer(_ipop_config.VirtualNetworkDevice);  
   _dhcp_config = _dhcp_server.Config;
   _marad = new ManagedAddressResolverAndDns(AppNode.Node, _dhcp_server,
       ((ManagedDhcpServer) _dhcp_server).LocalIP, _ipop_config.Dns.NameServer,
       _ipop_config.Dns.ForwardQueries);
   _dns = _marad;
   _address_resolver = _marad;
   _translator = _marad;
 }
    public MultiNode(NodeConfig node_config, int count) : base(node_config) 
    {
      _node_config_single = Utils.Copy<NodeConfig>(node_config);

      foreach(NodeConfig.EdgeListener item in _node_config.EdgeListeners) {
        item.port = 0;
      }

      _count = count;
      _nodes = new ArrayList(_count - 1);
      _threads = new ArrayList(_count - 1);
    }
Exemple #14
0
 public SocialNode(NodeConfig brunetConfig, IpopConfig ipopConfig,
                   string certificate) : base(brunetConfig, ipopConfig) {
   _friends = new Dictionary<string, SocialUser>();
   _bfriends = new List<string>();
   _sync = new object();
   _status = StatusTypes.Offline.ToString();
   _global_block = new WriteOnce<bool>();
   _local_user = new SocialUser();
   _local_user.Certificate = certificate;
   _local_user.IP = _marad.LocalIP;
   _marad.AddDnsMapping(_local_user.Alias, _local_user.IP, true);
   _bso = AppNode.SecurityOverlord;
   _bso.CertificateHandler.AddCACertificate(_local_user.GetCert().X509);
   _bso.CertificateHandler.AddSignedCertificate(_local_user.GetCert().X509);
 }
Exemple #15
0
    /**
    <summary>Loads a configuration file and creates a Node.Address if
    necessary.</summary>
    <param name="path">The path to a NodeConfig</param>
    <returns>Exits if NodeConfig is invalid.</returns>
    */
    public BasicNode(String path) {
      try {
        _node_config = Utils.ReadConfig<NodeConfig>(path);
      }
      catch {
        Console.WriteLine("Invalid or missing configuration file.");
        Environment.Exit(1);
      }

      _node_config_path = path;
      if(_node_config.NodeAddress == null) {
        _node_config.NodeAddress = (Utils.GenerateAHAddress()).ToString();
        Utils.WriteConfig(path, _node_config);
      }
      _running = true;
    }
Exemple #16
0
        /// <summary>Prepares a BasicNode.</summary>
        /// <param name="node_config">A node config object.</param>
        public BasicNode(NodeConfig node_config)
        {
            _node_config      = node_config;
            _running          = true;
            _shutdown         = Shutdown.GetShutdown();
            _shutdown.OnExit += OnExit;

            _type_to_pem = new Dictionary <string, PathELManager>();
            _rand        = new Random();

            if (_node_config.XmppServices.Enabled)
            {
                XmppService = new XmppService(_node_config.XmppServices.Username,
                                              _node_config.XmppServices.Password,// _node_config.XmppServices.Server,
                                              _node_config.XmppServices.Port);
                XmppService.Connect();
            }
        }
Exemple #17
0
        public virtual int Parse(string[] args)
        {
            try {
                _options.Parse(args);
            } catch (Exception e) {
                _error_message = e.Message;
                return(-1);
            }

            try {
                _node_config = NodeConfig.ReadConfig(_node_config_path);
            } catch (Exception e) {
                _error_message = "Invalid NodeConfig file: " + e.Message;
                return(-1);
            }

            return(0);
        }
Exemple #18
0
        /// <summary>Read a NodeConfig, if it fails, then let's find the problem.</summary>
        public static NodeConfig ReadConfig(string path)
        {
            if (!File.Exists(path))
            {
                throw new Exception("Missing NodeConfig.");
            }

            NodeConfig node_config = null;

            try {
                node_config      = Utils.ReadConfig <NodeConfig>(path);
                node_config.Path = path;
            } catch {
                ConfigurationValidator cv = new ConfigurationValidator();
                cv.Validate(path, "Node.xsd");
            }
            return(node_config);
        }
Exemple #19
0
    public virtual int Parse(string[] args)
    {
      try {
        _options.Parse(args);
      } catch(Exception e) {
        _error_message = e.Message;
        return -1;
      }

      try {
        _node_config = NodeConfig.ReadConfig(_node_config_path);
      } catch (Exception e) {
        _error_message = "Invalid NodeConfig file: " + e.Message;
        return -1;
      }

      return 0;
    }
Exemple #20
0
        /// <summary>Create a PrivateNode given a shared node and a node_config.</summary>
        protected void CreatePrivateNode(ApplicationNode shared,
                                         NodeConfig node_config)
        {
            // Not necessary, but its nice to map the public and private overlay nodes
            node_config.NodeAddress = shared.Node.Address.ToString();
            ApplicationNode app_node = CreateNode(node_config);

            EdgeListener el = new SubringEdgeListener(shared.Node, app_node.Node);

            if (node_config.Security.SecureEdgesEnabled)
            {
                el = new SecureEdgeListener(el, app_node.SecurityOverlord);
            }
            app_node.Node.AddEdgeListener(el);
            Discovery d = new DhtDiscovery(app_node.Node as StructuredNode,
                                           shared.Dht, shared.Node.Realm, shared.DhtProxy);

            app_node.Node.AddTADiscovery(d);
            shared.PrivateNode = app_node;
        }
Exemple #21
0
        public static int Main(String[] args)
        {
            P2PNodeParameters parameters = new P2PNodeParameters();

            if (parameters.Parse(args) != 0)
            {
                Console.WriteLine(parameters.ErrorMessage);
                parameters.ShowHelp();
                return(-1);
            }
            else if (parameters.Help)
            {
                parameters.ShowHelp();
                return(0);
            }

            NodeConfig node_config = parameters.NodeConfig;

            if (node_config.NodeAddress == null)
            {
                node_config.NodeAddress = Utils.GenerateAHAddress().ToString();
                node_config.WriteConfig();
            }

            BasicNode node = null;

            if (parameters.Count == 1)
            {
                node = new BasicNode(node_config);
            }
            else
            {
                node = new MultiNode(node_config, parameters.Count);
            }
            node.Run();

            return(0);
        }
Exemple #22
0
 /// <summary>Create a new node config given a public node config and a
 /// private node config, used to generate the private node.</summary>
 public static NodeConfig GetPrivateNodeConfig(NodeConfig nc)
 {
   NodeConfig private_config = Utils.Copy<NodeConfig>(nc);
   private_config.PrivateNodeConfig = null;
   private_config.BrunetNamespace = nc.PrivateNodeConfig.BrunetNamespace;
   private_config.Security = nc.PrivateNodeConfig.Security;
   private_config.RemoteTAs = new String[0];
   return private_config;
 }
Exemple #23
0
 /**
  * Constructor.
  * @param brunetConfig configuration file for Brunet P2P library.
  * @param ipopConfig configuration file for IP over P2P app.
  */
 public SocialNode(NodeConfig brunetConfig, IpopConfig ipopConfig, 
               string certDir, string http_port, string jabber_port,
               string global_access)
     : base(brunetConfig, ipopConfig)
 {
     _friends = new Dictionary<string, SocialUser>();
       _aliases = new Dictionary<string, string>();
       _addr_to_key = new Dictionary<string, string>();
       _cert_dir = certDir;
       _http_port = http_port;
       string cert_path = Path.Combine(certDir, CERTFILENAME);
       _local_cert = new Certificate(SocialUtils.ReadFileBytes(cert_path));
       _local_user = new SocialUser(_local_cert);
       _local_cert_b64 = Convert.ToBase64String(_local_cert.X509.RawData);
       _bso.CertificateHandler.AddCACertificate(_local_cert.X509);
       _bso.CertificateHandler.AddSignedCertificate(_local_cert.X509);
       _queue = new BlockingQueue();
       _snp = new SocialNetworkProvider(this.Dht, _local_user,
                                _local_cert.X509.RawData, _queue,
                                jabber_port);
       _sdm = new SocialDnsManager(this, _local_user);
       _srh = new SocialRpcHandler(_node, _local_user, _friends, _queue, _sdm);
       _scm = new SocialConnectionManager(this, _snp, _srh, http_port, _queue,
                                  _sdm);
       _cert_published = false;
       _node.ConnectionTable.ConnectionEvent += ConnectHandler;
       _node.HeartBeatEvent += _scm.HeartBeatHandler;
       Shutdown.OnExit += _scm.Stop;
       _local_user.IP = _marad.LocalIP;
       CreateAlias(_local_user);
       _marad.MapLocalDNS(_local_user.Alias);
       _scm.GlobalAccess = (global_access == "on");
       LoadCertificates();
 }
Exemple #24
0
 /// <summary>Prepares a BasicNode.</summary>
 /// <param name="node_config">A node config object.</param>
 public BasicNode(NodeConfig node_config) {
   _node_config = node_config;
   _running = true;
   _shutdown = Shutdown.GetShutdown();
 }
    /**
    <summary>Loads a configuration file and creates a Node.Address if
    necessary.</summary>
    <param name="path">The path to a NodeConfig</param>
    <returns>Exits if NodeConfig is invalid.</returns>
    */
    public DeetooNode(String c_path, String q_path) {
      try {
        _c_node_config = Utils.ReadConfig<NodeConfig>(c_path);
        _q_node_config = Utils.ReadConfig<NodeConfig>(q_path);
      }
      catch {
        Console.WriteLine("Invalid or missing configuration file.");
        Environment.Exit(1);
      }

      _c_node_config_path = c_path;
      _q_node_config_path = q_path;
      if(_c_node_config.NodeAddress == null) {
	AHAddress c_addr = Utils.GenerateAHAddress();
        _c_node_config.NodeAddress = c_addr.ToString();
	_q_node_config.NodeAddress = AddressTranspose(c_addr).ToString();
        Utils.WriteConfig(c_path, _c_node_config);
	Utils.WriteConfig(q_path, _q_node_config);
      }
      _running = true;
      //_rpc.AddHandler("Deetoo", new DeetooHandler(node,this));
    }
Exemple #26
0
 /**
 <summary>A constructor to be used only by sub-classes.  The goal here being
 that inheritors may want to implement their own subclass of config but
 BasicNode still needs to be configured and possibly write to the config
 file.  This gets around that problem!</summary>
 <param name="path">The Path of the NodeConfig in the second parameter
 </param>
 <param name="config">A NodeConfig inherited object.</param>
 */
 protected BasicNode(String path, NodeConfig config) {
   _node_config = config;
   if(_node_config.NodeAddress == null) {
     _node_config.NodeAddress = (Utils.GenerateAHAddress()).ToString();
     Utils.WriteConfig(path, _node_config);
   }
   _running = true;
 }
 /// <summary>The only parameter to the constructor is a valid NodeConfig.
 public HelloWorldRpcHandler(NodeConfig node_config)
     : base(node_config)
 {
 }
Exemple #28
0
        /// <summary>Creates an IpopNode given a NodeConfig and an IpopConfig.
        /// Also sets up the Information, Ethernet device, and subscribes
        /// to Brunet for IP Packets</summary>
        /// <param name="node_config">The path to a NodeConfig xml file</param>
        /// <param name="ipop_config">The path to a IpopConfig xml file</param>
        public IpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config)
            : base(node_config)
        {
            AppNode = CreateNode(node_config);
              AppNode.Node.DisconnectOnOverload = false;
              _chota = AppNode.Node.Cco;
              _ipop_config = ipop_config;

              Ethernet = new Ethernet(_ipop_config.VirtualNetworkDevice);
              Ethernet.Subscribe(this, null);

              Info = new Information(AppNode.Node, "IpopNode");
              Info.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;

              if(_ipop_config.EndToEndSecurity && AppNode.SecurityOverlord != null) {
            _secure_senders = true;
              } else {
            _secure_senders = false;
              }
              AppNode.Node.GetTypeSource(PType.Protocol.IP).Subscribe(this, null);

              _sync = new object();
              _lock = 0;

              _ether_to_ip = new Dictionary<MemBlock, MemBlock>();
              _ip_to_ether = new Dictionary<MemBlock, MemBlock>();

              _dhcp_server_port = _ipop_config.DHCPPort != 0 ? _ipop_config.DHCPPort : 67;
              _dhcp_client_port = _dhcp_server_port + 1;
              ProtocolLog.WriteIf(IpopLog.DhcpLog, String.Format(
              "Setting Dhcp Ports to: {0},{1}", _dhcp_server_port, _dhcp_client_port));
              _ether_to_dhcp_server = new Dictionary<MemBlock, DhcpServer>();
              _static_mapping = new Dictionary<MemBlock, SimpleTimer>();
              _dhcp_config = dhcp_config;
              if(_dhcp_config != null) {
            SetDns();
            _dhcp_server = GetDhcpServer();
              }
              _checked_out = new Hashtable();

              AppNode.Node.HeartBeatEvent += CheckNode;
              _last_check_node = DateTime.UtcNow;

              AppNode.Node.Rpc.AddHandler("Ipop", this);
        }
Exemple #29
0
 /// <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;
 }
Exemple #30
0
    /// <summary>Create a PrivateNode given a shared node and a node_config.</summary>
    protected void CreatePrivateNode(ApplicationNode shared,
        NodeConfig node_config)
    {
      // Not necessary, but its nice to map the public and private overlay nodes
      node_config.NodeAddress = shared.Node.Address.ToString();
      ApplicationNode app_node = CreateNode(node_config);

      EdgeListener el = new SubringEdgeListener(shared.Node, app_node.Node);
      if(node_config.Security.SecureEdgesEnabled) {
        el = new SecureEdgeListener(el, app_node.SecurityOverlord);
      }
      app_node.Node.AddEdgeListener(el);
      Discovery d = new DhtDiscovery(app_node.Node as StructuredNode,
          shared.Dht, shared.Node.Realm, shared.DhtProxy);
      app_node.Node.AddTADiscovery(d);
      shared.PrivateNode = app_node;
    }
 /// <summary>The only parameter to the constructor is a valid NodeConfig.
 /// We also register the PType here.</summary>
 public HelloWorldNodeDataHandler(NodeConfig node_config) : base(node_config) {
   HW = new PType("HelloWorld");
 }
Exemple #32
0
        /// <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);
        }
 /// <summary>The only parameter to the constructor is a valid NodeConfig.
 /// We also create address as an array list.</summary>
 public HelloWorldRpcHandler(NodeConfig node_config)
     : base(node_config)
 {
     _addr = new ArrayList();
 }
Exemple #34
0
 public MultiNode(NodeConfig node_config, int count) : base(node_config)
 {
     _count   = count;
     _nodes   = new List <ApplicationNode>(count);
     _threads = new List <Thread>();
 }
Exemple #35
0
 public DhtIpopNode(NodeConfig node_config, IpopConfig ipop_config)
     : this(node_config, ipop_config, null)
 {
 }
Exemple #36
0
    /// <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;
    }
Exemple #37
0
    /// <summary>Creates an IpopNode given a NodeConfig and an IpopConfig.
    /// Also sets up the Information, Ethernet device, and subscribes
    /// to Brunet for IP Packets</summary>
    /// <param name="node_config">The path to a NodeConfig xml file</param>
    /// <param name="ipop_config">The path to a IpopConfig xml file</param>
    public IpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config) : base(node_config)
    {
      PublicNode = CreateNode(node_config);
      PublicNode.Node.DisconnectOnOverload = false;
      if(PublicNode.PrivateNode == null) {
        AppNode = PublicNode;
      } else {
        AppNode = PublicNode.PrivateNode;
        AppNode.Node.DisconnectOnOverload = false;
      }

      _ipop_config = ipop_config;

      Ethernet = new Ethernet(_ipop_config.VirtualNetworkDevice);
      Ethernet.Subscribe(this, null);

      Info = new Information(AppNode.Node, "IpopNode", AppNode.SecurityOverlord);
      Info.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;
      if(PublicNode == AppNode) {
        PublicInfo = Info;
      } else {
        PublicInfo = new Information(PublicNode.Node, "PrivateIpopNode",
            PublicNode.SecurityOverlord);
        PublicInfo.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;
      }

      if(_ipop_config.EndToEndSecurity && !AppNode.Config.Security.SecureEdges &&
          AppNode.Config.Security.Enabled)
      {
        _conn_handler = new Brunet.Security.PeerSec.Symphony.SecureConnectionHandler(
            PType.Protocol.IP, AppNode.Node, AppNode.SymphonySecurityOverlord);
      } else {
        _conn_handler = new ConnectionHandler(PType.Protocol.IP, AppNode.Node);
      }
      _conn_handler.Subscribe(this, null);

      _sync = new object();
      _lock = 0;

      _ether_to_ip = new Dictionary<MemBlock, MemBlock>();
      _ip_to_ether = new Dictionary<MemBlock, MemBlock>();

      _dhcp_server_port = _ipop_config.DHCPPort != 0 ? _ipop_config.DHCPPort : 67;
      _dhcp_client_port = _dhcp_server_port + 1;
      ProtocolLog.WriteIf(IpopLog.DhcpLog, String.Format(
          "Setting Dhcp Ports to: {0},{1}", _dhcp_server_port, _dhcp_client_port));
      _ether_to_dhcp_server = new Dictionary<MemBlock, DhcpServer>();
      _static_mapping = new Dictionary<MemBlock, SimpleTimer>();
      _dhcp_config = dhcp_config;
      if(_dhcp_config != null) {
        SetDns();
        SetTAAuth();
        _dhcp_server = GetDhcpServer();
      }
      _checked_out = new Hashtable();

      AppNode.Node.HeartBeatEvent += CheckNode;
      _last_check_node = DateTime.UtcNow;

      AppNode.Node.Rpc.AddHandler("Ipop", this);
    }
Exemple #38
0
    /// <summary>Given an EdgeListener info, attempts to find a PathEL, if one is not
    /// found, creates a base EL and wraps it with a PathEL.</summary>
    protected EdgeListener CreateEdgeListener(NodeConfig.EdgeListener el_info,
        ApplicationNode node, IEnumerable addresses)
    {
      PathELManager pem = null;
      if(!_type_to_pem.TryGetValue(el_info.type, out pem)) {
        pem = new PathELManager(CreateBaseEdgeListener(el_info, node, addresses), node.Node);
        pem.Start();
        _type_to_pem[el_info.type] = pem;
      }

      EdgeListener el = pem.CreatePath();
      return el;
    }
Exemple #39
0
        /// <summary>Creates an IpopNode given a NodeConfig and an IpopConfig.
        /// Also sets up the Information, Ethernet device, and subscribes
        /// to Brunet for IP Packets</summary>
        /// <param name="node_config">The path to a NodeConfig xml file</param>
        /// <param name="ipop_config">The path to a IpopConfig xml file</param>
        public IpopNode(NodeConfig node_config, IpopConfig ipop_config,
        DHCPConfig dhcp_config)
            : base(node_config)
        {
            CreateNode();
              this.Brunet = _node;
              _ipop_config = ipop_config;

              Ethernet = new Ethernet(_ipop_config.VirtualNetworkDevice);
              Ethernet.Subscribe(this, null);

              _info = new Information(Brunet, "IpopNode");
              _info.UserData["IpopNamespace"] = _ipop_config.IpopNamespace;

              if(_ipop_config.EndToEndSecurity && _bso != null) {
            _secure_senders = true;
              } else {
            _secure_senders = false;
              }
              Brunet.GetTypeSource(PType.Protocol.IP).Subscribe(this, null);

              _sync = new object();
              _lock = 0;

              _ether_to_ip = new Dictionary<MemBlock, MemBlock>();
              _ip_to_ether = new Dictionary<MemBlock, MemBlock>();

              _dhcp_server_port = _ipop_config.DHCPPort != 0 ? _ipop_config.DHCPPort : 67;
              _dhcp_client_port = _dhcp_server_port + 1;
              ProtocolLog.WriteIf(IpopLog.DHCPLog, String.Format(
              "Setting DHCP Ports to: {0},{1}", _dhcp_server_port, _dhcp_client_port));
              _ether_to_dhcp_server = new Dictionary<MemBlock, DHCPServer>();
              _static_mapping = new Dictionary<MemBlock, SimpleTimer>();
              _dhcp_config = dhcp_config;
              if(_dhcp_config != null) {
            SetDNS();
            _dhcp_server = GetDHCPServer();
              }
              _checked_out = new Hashtable();

              Brunet.HeartBeatEvent += CheckNode;
              _last_check_node = DateTime.UtcNow;
        }
Exemple #40
0
    /// <summary>Prepares a BasicNode.</summary>
    /// <param name="node_config">A node config object.</param>
    public BasicNode(NodeConfig node_config)
    {
      _node_config = node_config;
      _running = true;
      _shutdown = Shutdown.GetShutdown();
      _shutdown.OnExit += OnExit;

      _type_to_pem = new Dictionary<string, PathELManager>();
      _rand = new Random();

      if(_node_config.XmppServices.Enabled) {
        XmppService = new XmppService(_node_config.XmppServices.Username,
            _node_config.XmppServices.Password,// _node_config.XmppServices.Server,
            _node_config.XmppServices.Port);
        XmppService.Connect();
      }
    }
Exemple #41
0
 public MultiNode(NodeConfig node_config, int count) : base(node_config) 
 {
   _count = count;
   _nodes = new List<ApplicationNode>(count);
   _threads = new List<Thread>();
 }