Ejemplo n.º 1
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
            {
                throw new Exception("Unrecognized transport: " + el_info.type);
            }
            return(el);
        }
Ejemplo n.º 2
0
    //Methods:

    protected PathELManager(EdgeListener el, bool thread) {
      _el = el;
      _sync = new object();
      _edges = new List<Edge>();
      _unannounced = new Dictionary<Edge, PathEdge>();
      _pel_map = new Dictionary<string, PathEdgeListener>();
      //Use the reqrep protocol with a special prefix:
      _rrm = new ReqrepManager("PathELManager:" + el.ToString(), PType.Protocol.Pathing);
      _rrm.Subscribe(this, null);
      Rpc = new RpcManager(_rrm);
      Rpc.AddHandler("sys:pathing", this);
      _el.EdgeEvent += HandleEdge;
      _running = true;
      _next_check = DateTime.UtcNow.Ticks;

      if(thread) {
        _timer_thread = new Thread(
          delegate() {
            while(_running) {
              Thread.Sleep(1000);
              TimeoutCheck();
            }
          }
        );

        _timer_thread.IsBackground = true;
        _timer_thread.Start();
      }
    }
Ejemplo n.º 3
0
 public PathEdgeListener(PathELManager pem, string path, EdgeListener el)
 {
     _path       = path;
     _el         = el;
     _pem        = pem;
     _is_started = 0;
 }
Ejemplo n.º 4
0
 public SecureEdgeListener(EdgeListener el, SecurityOverlord so) : base(el)
 {
     _so              = so;
     _so.AnnounceSA  += AnnounceSA;
     _edge_to_sa      = new Dictionary <Edge, SecurityAssociation>();
     _edge_to_inbound = new Dictionary <Edge, bool>();
 }
Ejemplo n.º 5
0
        //Methods:

        protected PathELManager(EdgeListener el, bool thread)
        {
            _el          = el;
            _sync        = new object();
            _edges       = new List <Edge>();
            _unannounced = new Dictionary <Edge, PathEdge>();
            _pel_map     = new Dictionary <string, PathEdgeListener>();
            //Use the reqrep protocol with a special prefix:
            _rrm = new ReqrepManager("PathELManager:" + el.ToString(), PType.Protocol.Pathing);
            _rrm.Subscribe(this, null);
            Rpc = new RpcManager(_rrm);
            Rpc.AddHandler("sys:pathing", this);
            _el.EdgeEvent += HandleEdge;
            _running       = true;
            _next_check    = DateTime.UtcNow.Ticks;

            if (thread)
            {
                _timer_thread = new Thread(
                    delegate() {
                    while (_running)
                    {
                        Thread.Sleep(1000);
                        TimeoutCheck();
                    }
                }
                    );

                _timer_thread.IsBackground = true;
                _timer_thread.Start();
            }
        }
Ejemplo n.º 6
0
 public NodeConfig() {
   EdgeListeners = new EdgeListener[0];
   RemoteTAs = new String[0];
   DevicesToBind = new String[0];
   XmlRpcManager = new Service();
   NCService = new NCServiceConfig();
   Security = new SecurityPolicy();
 }
Ejemplo n.º 7
0
 public NodeConfig()
 {
     EdgeListeners = new EdgeListener[0];
     RemoteTAs     = new String[0];
     DevicesToBind = new String[0];
     XmlRpcManager = new Service();
     NCService     = new NCServiceConfig();
     Security      = new SecurityPolicy();
 }
Ejemplo n.º 8
0
        /** Multiplex an EdgeListener using Pathing with the IActionQueue managing the
         * Rrm.
         * @param el the EdgeListener to multiplex
         */
        public PathELManager(EdgeListener el, IActionQueue queue) : this(el, false)
        {
            PathELManagerAction pema = new PathELManagerAction(this);

            Action <DateTime> torun = delegate(DateTime now) {
                queue.EnqueueAction(pema);
            };

            _fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(torun, _period, _period / 2 + 1);
        }
Ejemplo n.º 9
0
 public WrapperEdgeListener(EdgeListener el) {
   _sync = new object();
   lock(_sync) {
     _el = el;
     _el.EdgeEvent += HandleEdgeEvent;
     _el.EdgeCloseRequestEvent += HandleEdgeCloseRequestEvent;
     _edge_to_wrapper_edge = new Dictionary<Edge, WrapperEdge>(); 
     _edge_to_ecw = new  Dictionary<Edge, EdgeCreationWrapper>();
   }
 }
Ejemplo n.º 10
0
 public NodeConfig() {
   EdgeListeners = new EdgeListener[0];
   RemoteTAs = new String[0];
   DevicesToBind = new String[0];
   XmlRpcManager = new Service();
   NCService = new NCServiceConfig();
   Security = new SecurityPolicy();
   PrivateNodeConfig = new PrivateNodeConfig();
   BrunetNamespace = String.Empty;
   XmppServices = new XmppConfig();
 }
Ejemplo n.º 11
0
 public WrapperEdgeListener(EdgeListener el)
 {
     _sync = new object();
     lock (_sync) {
         _el                        = el;
         _el.EdgeEvent             += HandleEdgeEvent;
         _el.EdgeCloseRequestEvent += HandleEdgeCloseRequestEvent;
         _edge_to_wrapper_edge      = new Dictionary <Edge, WrapperEdge>();
         _edge_to_ecw               = new  Dictionary <Edge, EdgeCreationWrapper>();
     }
 }
Ejemplo n.º 12
0
 public NodeConfig()
 {
     EdgeListeners     = new EdgeListener[0];
     RemoteTAs         = new String[0];
     DevicesToBind     = new String[0];
     XmlRpcManager     = new Service();
     NCService         = new NCServiceConfig();
     Security          = new SecurityPolicy();
     PrivateNodeConfig = new PrivateNodeConfig();
     BrunetNamespace   = String.Empty;
     XmppServices      = new XmppConfig();
 }
Ejemplo n.º 13
0
        public virtual void AddEdgeListener(EdgeListener el)
        {
            /* The EdgeFactory needs to be made aware of all EdgeListeners */
            _edge_factory.AddListener(el);
            _edgelistener_list.Add(el);

            /**
             * It is ESSENTIAL that the EdgeEvent of EdgeListener objects
             * be connected to the EdgeHandler method of ConnectionPacketHandler
             */
            el.EdgeEvent             += this.EdgeHandler;
            el.EdgeCloseRequestEvent += delegate(object elsender, EventArgs args) {
                EdgeCloseRequestArgs ecra = (EdgeCloseRequestArgs)args;
                Close(ecra.Edge);
            };
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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();
            PType        path_p = PType.Protocol.Pathing;

            node.Node.DemuxHandler.GetTypeSource(path_p).Subscribe(pem, path_p);
            return(el);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
0
    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);
    }
Ejemplo n.º 18
0
 /** Multiplex an EdgeListener using Pathing with a thread managing the Rrm
  * @param el the EdgeListener to multiplex
  */
 public PathELManager(EdgeListener el) : this(el, true)
 {
 }
Ejemplo n.º 19
0
    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);
      }
    }
Ejemplo n.º 20
0
        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);
            }
        }
Ejemplo n.º 21
0
 public EdgeCreationWrapper(TransportAddress ta, EdgeListener.EdgeCreationCallback ecb,
     Edge edge, WrapperEdgeListener parent)
 {
   ExternalECB = ecb;
   TA = ta;
   Parent = parent;
   _edge = edge;
   _called = 0;
 }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
 public CreateState(PathEdgeListener pel, string rem, string loc,
                    EdgeListener.EdgeCreationCallback ecb) {
   _pel = pel;
   RemotePath = rem;
   LocalPath = loc;
   ECB = ecb;
 }
Ejemplo n.º 24
0
    /** Multiplex an EdgeListener using Pathing with the IActionQueue managing the
     * Rrm.
     * @param el the EdgeListener to multiplex
     */
    public PathELManager(EdgeListener el, IActionQueue queue) : this(el, false) {
      PathELManagerAction pema = new PathELManagerAction(this);

      Action<DateTime> torun = delegate(DateTime now) {
        queue.EnqueueAction(pema);
      };

      _fe = Brunet.Util.FuzzyTimer.Instance.DoEvery(torun, _period, _period / 2 + 1);
    }
Ejemplo n.º 25
0
 /** Multiplex an EdgeListener using Pathing with a thread managing the Rrm
  * @param el the EdgeListener to multiplex
  */
 public PathELManager(EdgeListener el) : this(el, true) {
 }
Ejemplo n.º 26
0
        protected virtual StructuredNode PrepareNode(int id, AHAddress address)
        {
            if (TakenIDs.Contains(id))
            {
                throw new Exception("ID already taken");
            }

            StructuredNode node = new StructuredNode(address, BrunetNamespace);

            NodeMapping nm = new NodeMapping();

            TakenIDs[id] = nm.ID = id;
            nm.Node      = node;
            Nodes.Add((Address)address, nm);

            EdgeListener el = CreateEdgeListener(nm.ID);

            if (_secure_edges || _secure_senders)
            {
                byte[] blob = _se_key.ExportCspBlob(true);
                RSACryptoServiceProvider rsa_copy = new RSACryptoServiceProvider();
                rsa_copy.ImportCspBlob(blob);

                CertificateMaker cm = new CertificateMaker("United States", "UFL",
                                                           "ACIS", "David Wolinsky", "*****@*****.**", rsa_copy,
                                                           address.ToString());
                Certificate cert = cm.Sign(_ca_cert, _se_key);

                CertificateHandler ch = new CertificateHandler();
                ch.AddCACertificate(_ca_cert.X509);
                ch.AddSignedCertificate(cert.X509);

                ProtocolSecurityOverlord so = new ProtocolSecurityOverlord(node, rsa_copy, node.Rrm, ch);
                so.Subscribe(node, null);
                node.GetTypeSource(SecurityOverlord.Security).Subscribe(so, null);
                nm.BSO = so;
                node.HeartBeatEvent += so.Heartbeat;
            }

            if (_secure_edges)
            {
                node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
                el = new SecureEdgeListener(el, nm.BSO);
            }

            node.AddEdgeListener(el);

            node.RemoteTAs = GetRemoteTAs();

            ITunnelOverlap ito = null;

            if (NCEnable)
            {
                nm.NCService = new NCService(node, new Point());
// My evaluations show that when this is enabled the system sucks
//        (node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
                ito = new NCTunnelOverlap(nm.NCService);
            }
            else
            {
                ito = new SimpleTunnelOverlap();
            }

            if (_broken != 0)
            {
                el = new Tunnel.TunnelEdgeListener(node, ito);
                node.AddEdgeListener(el);
            }
            // Enables Dht data store
            new TableServer(node);
            return(node);
        }
Ejemplo n.º 27
0
 public PathEdgeListener(PathELManager pem, string path, EdgeListener el) {
   _path = path;
   _el = el;
   _pem = pem;
   _is_started = 0;
 }
Ejemplo n.º 28
0
Archivo: Node.cs Proyecto: hseom/brunet
 // ///////////////////
 // Methods
 // ///////////////////
   
    public virtual void AddEdgeListener(EdgeListener el)
    {
      /* The EdgeFactory needs to be made aware of all EdgeListeners */
      _edge_factory.AddListener(el);
      _edgelistener_list.Add(el);
      /**
       * It is ESSENTIAL that the EdgeEvent of EdgeListener objects
       * be connected to the EdgeHandler method of ConnectionPacketHandler
       */
      el.EdgeEvent += this.EdgeHandler;
      el.EdgeCloseRequestEvent += delegate(object elsender, EventArgs args) {
        EdgeCloseRequestArgs ecra = (EdgeCloseRequestArgs)args;
        Close(ecra.Edge);
      };
    }
Ejemplo n.º 29
0
 /** creates a new outgoing Edge using the pathing protocol
  */
 public override void CreateEdgeTo(TransportAddress ta,
                                   EdgeListener.EdgeCreationCallback ecb) {
   if( !IsStarted ) {
     throw new EdgeException("PathEdgeListener is not started");
   }
   string rempath;
   TransportAddress base_ta = PathELManager.SplitPath(ta, out rempath);
   if( _path == PathELManager.Root && rempath == PathELManager.Root ) {
     /*
      * This is "normal" case, and we can skip all this stuff
      */
     _el.CreateEdgeTo(ta, ecb);
   }
   else {
     CreateState cs = new CreateState(this, rempath, _path, ecb);
     /*
      * Make the underlying Edge:
      */
     _el.CreateEdgeTo(base_ta, cs.HandleEC);
   }
 }
Ejemplo n.º 30
0
 public SecureEdgeListener(EdgeListener el, SecurityOverlord so): base(el) {
   _so = so;
   _so.AnnounceSA += AnnounceSA;
   _edge_to_sa = new Dictionary<Edge, SecurityAssociation>();
   _edge_to_inbound = new Dictionary<Edge, bool>();
 }
Ejemplo n.º 31
0
        protected virtual StructuredNode PrepareNode(int id, AHAddress address)
        {
            if (TakenIDs.ContainsKey(id))
            {
                throw new Exception("ID already taken");
            }

            StructuredNode node = new StructuredNode(address, BrunetNamespace);

            NodeMapping nm = new NodeMapping();

            nm.ID        = id;
            TakenIDs[id] = nm;
            nm.Node      = node;
            Nodes.Add((Address)address, nm);

            EdgeListener el = CreateEdgeListener(nm.ID);

            if (_secure_edges || _secure_senders)
            {
                byte[] blob = _se_key.ExportCspBlob(true);
                RSACryptoServiceProvider rsa_copy = new RSACryptoServiceProvider();
                rsa_copy.ImportCspBlob(blob);

                string           username = address.ToString().Replace('=', '0');
                CertificateMaker cm       = new CertificateMaker("United States", "UFL",
                                                                 "ACIS", username, "*****@*****.**", rsa_copy,
                                                                 address.ToString());
                Certificate cert = cm.Sign(_ca_cert, _se_key);

                CertificateHandler ch = null;
                if (_dtls)
                {
                    ch = new OpenSslCertificateHandler();
                }
                else
                {
                    ch = new CertificateHandler();
                }
                ch.AddCACertificate(_ca_cert.X509);
                ch.AddSignedCertificate(cert.X509);

                if (_dtls)
                {
                    nm.SO = new DtlsOverlord(rsa_copy, ch, PeerSecOverlord.Security);
                }
                else
                {
                    nm.Sso = new SymphonySecurityOverlord(node, rsa_copy, ch, node.Rrm);
                    nm.SO  = nm.Sso;
                }

                var brh = new BroadcastRevocationHandler(_ca_cert, nm.SO);
                node.GetTypeSource(BroadcastRevocationHandler.PType).Subscribe(brh, null);
                ch.AddCertificateVerification(brh);
                nm.SO.Subscribe(node, null);
                node.GetTypeSource(PeerSecOverlord.Security).Subscribe(nm.SO, null);
            }

            if (_pathing)
            {
                nm.PathEM = new PathELManager(el, nm.Node);
                nm.PathEM.Start();
                el = nm.PathEM.CreatePath();
                PType path_p = PType.Protocol.Pathing;
                nm.Node.DemuxHandler.GetTypeSource(path_p).Subscribe(nm.PathEM, path_p);
            }

            if (_secure_edges)
            {
                node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
                el = new SecureEdgeListener(el, nm.SO);
            }

            node.AddEdgeListener(el);

            if (!_start)
            {
                node.RemoteTAs = GetRemoteTAs();
            }

            IRelayOverlap ito = null;

            if (NCEnable)
            {
                nm.NCService = new NCService(node, new Point());
// My evaluations show that when this is enabled the system sucks
//        (node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
                ito = new NCRelayOverlap(nm.NCService);
            }
            else
            {
                ito = new SimpleRelayOverlap();
            }

            if (_broken != 0)
            {
                el = new Relay.RelayEdgeListener(node, ito);
                if (_secure_edges)
                {
                    el = new SecureEdgeListener(el, nm.SO);
                }
                node.AddEdgeListener(el);
            }

            BroadcastHandler bhandler = new BroadcastHandler(node as StructuredNode);

            node.DemuxHandler.GetTypeSource(BroadcastSender.PType).Subscribe(bhandler, null);
            node.DemuxHandler.GetTypeSource(SimBroadcastPType).Subscribe(SimBroadcastHandler, null);

            // Enables Dht data store
            new TableServer(node);
            nm.Dht      = new Dht(node, 3, 20);
            nm.DhtProxy = new RpcDhtProxy(nm.Dht, node);
            return(node);
        }
Ejemplo n.º 32
0
 public SecureEdgeListener(EdgeListener el, SecurityOverlord so) : base(el)
 {
     _so             = so;
     _so.AnnounceSA += AnnounceSA;
 }