Exemplo n.º 1
0
        /// <summary>Continues a broadcast to the overlay.</summary>
        public BroadcastSender(StructuredNode node, AHAddress source,
                               AHAddress from, AHAddress to, int forwarders, int hops)
        {
            Node             = node;
            Source           = source;
            From             = from;
            To               = to;
            _distance_sorter = new AbsoluteDistanceComparer(node.Address as AHAddress);
            _address_sorter  = new LeftDistanceComparer(node.Address as AHAddress);
            Forwarders       = forwarders;
            Hops             = hops;

            byte[] hops_data = new byte[4];
            NumberSerializer.WriteInt(hops, hops_data, 0);
            _hops = MemBlock.Reference(hops_data);

            if (forwarders == DEFAULT_FORWARDERS)
            {
                _forwarders = DEFAULT_FORWARDERS_MB;
            }
            else
            {
                byte[] def = new byte[4];
                NumberSerializer.WriteInt(forwarders, def, 0);
                _forwarders = MemBlock.Reference(def);
            }
        }
Exemplo n.º 2
0
 public UpdateNeighborAction(StructuredNode n,
                             string contype,
                             Connection neigh)
 {
     Node     = n;
     ConType  = contype;
     Neighbor = neigh;
 }
Exemplo n.º 3
0
 public ApplicationNode(StructuredNode node, IDht dht, RpcDhtProxy dht_proxy,
     NCService ncservice ,ProtocolSecurityOverlord security_overlord)
 {
   Node = node;
   Dht = dht;
   DhtProxy = dht_proxy;
   NCService = ncservice;
   SecurityOverlord = security_overlord;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 /// <summary>Stores data about this hop in a broadcast and provides a path
 /// back to the originating broadcaster.</summary>
 public BroadcastReceiver(BroadcastSender bs)
 {
   Node = bs.Node;
   From = bs.From;
   To = bs.To;
   Source = bs.Source;
   Hops = bs.Hops;
   _bs = bs;
   _sender = new AHSender(Node, Source,
       AHSender.DefaultTTLFor(Node.NetworkSize),
       AHHeader.Options.Exact);
 }
Exemplo n.º 6
0
 public NetworkTest(StructuredNode node)
 {
   _node = node;
   _fe = FuzzyTimer.Instance.DoEvery(Run, 30 * 60 * 1000, 500);
   _running = 0;
   _sync = new object();
   _db_con = String.Format("URI=file:{0}.{1}.db,version=3",
       _node.Realm, GetAddress(_node.Address));
   _current_iter = InitializeDatabase();
   Thread.MemoryBarrier();
   _node.StateChangeEvent += Stop;
 }
Exemplo n.º 7
0
 /// <summary>Stores data about this hop in a broadcast and provides a path
 /// back to the originating broadcaster.</summary>
 public BroadcastReceiver(BroadcastSender bs)
 {
     Node    = bs.Node;
     From    = bs.From;
     To      = bs.To;
     Source  = bs.Source;
     Hops    = bs.Hops;
     _bs     = bs;
     _sender = new AHSender(Node, Source,
                            AHSender.DefaultTTLFor(Node.NetworkSize),
                            AHHeader.Options.Exact);
 }
Exemplo n.º 8
0
    public ConnectionHandler(PType ptype, StructuredNode node)
    {
      _node = node;
      _ondemand = new OnDemandConnectionOverlord(node);
      _node.AddConnectionOverlord(_ondemand);
      _ptype = ptype;
      _ptype_mb = ptype.ToMemBlock();
      _address_to_sender = new Dictionary<Address, ISender>();
      _sender_to_address = new Dictionary<ISender, Address>();

      node.GetTypeSource(_ptype).Subscribe(this, null);
      node.ConnectionTable.ConnectionEvent += HandleConnection;
      node.ConnectionTable.DisconnectionEvent += HandleDisconnection;
    }
Exemplo n.º 9
0
 public AHSender(Node n, ISender from, Address destination, short ttl, ushort options, short hops_taken)
 {
     Node = n as StructuredNode;
     if (Node == null)
     {
         throw new Exception("Node must be a structured node");
     }
     ReceivedFrom = from;
     //Here are the fields in the order they appear:
     Ttl         = ttl;
     Source      = n.Address;
     Destination = destination;
     Options     = options;
     HopsTaken   = hops_taken;
     Header      = new AHHeader(Hops, Ttl, Source, Destination, Options);
 }
Exemplo n.º 10
0
    /// <summary>Uses the Dht for the bootstrap problem.</summary>
    /// <param name="node">The node needing remote tas.</param>
    /// <param name="dht">The dht for the shared overlay.</param>
    /// <param name="dht_proxy">A dht proxy for the shared overlay.</param>
    public DhtDiscovery(StructuredNode node, IDht dht, string shared_namespace,
        RpcDhtProxy dht_proxy) :
      base(node)
    {
      _dht = dht;
      _dht_proxy = dht_proxy;
      _node = node;
      _shared_namespace = shared_namespace;
      string skey = "PrivateOverlay:" + node.Realm;
      byte[] bkey = Encoding.UTF8.GetBytes(skey);
      _p2p_address = node.Address.ToMemBlock();
      _private_dht_key = MemBlock.Reference(bkey);

      _ongoing = 0;
      _steady_state = 0;
      _dht_proxy.Register(_private_dht_key, _p2p_address, PUT_DELAY_S);
    }
Exemplo n.º 11
0
        public void Test()
        {
            RandomNumberGenerator rng     = new RNGCryptoServiceProvider();
            AHAddress             tmp_add = new AHAddress(rng);
            Node             n            = new StructuredNode(tmp_add, "unittest");
            AHSender         ah           = new AHSender(n, AddressParser.Parse("brunet:node:JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4"));
            ForwardingSender fs           = new ForwardingSender(n,
                                                                 AddressParser.Parse("brunet:node:JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4"),
                                                                 AddressParser.Parse("brunet:node:5FMQW3KKJWOOGVDO6QAQP65AWVZQ4VUQ"));

            string  uri = "sender:ah?dest=JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4&mode=exact";
            ISender s   = SenderFactory.CreateInstance(n, uri);

            Assert.IsTrue(s is AHSender);
            Assert.AreEqual(uri, s.ToUri());
            uri = "sender:ah?dest=JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4&mode=greedy";

            //Create the above programatically
            IDictionary <string, string> param_args = new Dictionary <string, string>();

            param_args["dest"] = "JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4";
            param_args["mode"] = "greedy";
            string uri0 = SenderFactory.EncodeUri("ah", param_args);

            Assert.AreEqual(uri, uri0, "EncodeUri works");
            //Check decode:
            string scheme;

            param_args = SenderFactory.DecodeUri(uri, out scheme);
            Assert.AreEqual(scheme, "ah", "Scheme decoded");
            Assert.AreEqual(param_args.Count, 2, "2 parameters in uri");
            Assert.AreEqual(param_args["dest"], "JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4", "Extracted address");
            Assert.AreEqual(param_args["mode"], "greedy", "got mode");

            s = SenderFactory.CreateInstance(n, uri);
            Assert.IsTrue(s is AHSender);
            Assert.AreEqual(uri, s.ToUri());
            string furi = "sender:fw?relay=JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4&init_mode=greedy&dest=5FMQW3KKJWOOGVDO6QAQP65AWVZQ4VUQ&ttl=3&mode=path";

            s = SenderFactory.CreateInstance(n, furi);
            Assert.IsTrue(s is ForwardingSender);
            Assert.AreEqual(furi, s.ToUri());
        }
Exemplo n.º 12
0
        /// <summary>Creates a new BroadcastSender based upon a packet sent from
        /// one.  This makes the recursion step easier.</summary>
        public static BroadcastSender Parse(StructuredNode node, MemBlock packet,
                                            out MemBlock data)
        {
            int       pos    = 0;
            AHAddress source = new AHAddress(packet.Slice(pos, Address.MemSize));

            pos += Address.MemSize;
            AHAddress from = new AHAddress(packet.Slice(pos, Address.MemSize));

            pos += Address.MemSize;
            AHAddress to = new AHAddress(packet.Slice(pos, Address.MemSize));

            pos += Address.MemSize;
            int forwarders = NumberSerializer.ReadInt(packet, pos);

            pos += 4;
            int hops = NumberSerializer.ReadInt(packet, pos) + 1;

            pos += 4;
            data = packet.Slice(pos);
            return(new BroadcastSender(node, source, from, to, forwarders, hops));
        }
Exemplo n.º 13
0
 public AHSender(Node n, ISender from, Address destination, short ttl, ushort options, short hops_taken) {
   Node = n as StructuredNode;
   if(Node == null) {
     throw new Exception("Node must be a structured node");
   }
   ReceivedFrom = from;
   //Here are the fields in the order they appear:
   Ttl = ttl;
   Source = n.Address;
   Destination = destination;
   Options = options;
   HopsTaken = hops_taken;
   Header = new AHHeader(Hops, Ttl, Source, Destination, Options);
 }
Exemplo n.º 14
0
 public UpdateNeighborAction(StructuredNode n,
                             string contype,
                             Connection neigh) {
   Node = n;
   ConType = contype;
   Neighbor = neigh;
 }
Exemplo n.º 15
0
 protected BroadcastSender(StructuredNode node, AHAddress source, int forwarders) :
     this(node, source, GetRightNearTarget(source), GetLeftNearTarget(source),
          forwarders, 0)
 {
 }
Exemplo n.º 16
0
 public SecureConnectionHandler(PType ptype, StructuredNode node,
     SymphonySecurityOverlord so) : base(ptype, node)
 {
   _so = so;
   _registered = new Dictionary<SecurityAssociation, bool>();
 }
Exemplo n.º 17
0
 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));
 }
Exemplo n.º 18
0
 /// <summary>Broadcasts to the entire overlay.</summary>
 public BroadcastSender(StructuredNode node) : this(node, DEFAULT_FORWARDERS)
 {
 }
Exemplo n.º 19
0
 public BroadcastSender(StructuredNode node, int forwarders) :
     this(node, node.Address as AHAddress, forwarders)
 {
 }
Exemplo n.º 20
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;
    }
Exemplo n.º 21
0
 /// <summary>Creates a BroadcastHandler, don't forget to Subscribe to the
 /// Node.DemuxHandler with the PType -> BroadcastSender.PType.</summary>
 public BroadcastHandler(StructuredNode node)
 {
     Node = node;
 }
Exemplo n.º 22
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(SecureEdges || SecureSenders) {
        byte[] blob = SEKey.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(CACert, SEKey);

        CertificateHandler ch = new CertificateHandler();
        ch.AddCACertificate(CACert.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(SecureEdges) {
        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;
    }
Exemplo n.º 23
0
    public void Test() {
      RandomNumberGenerator rng = new RNGCryptoServiceProvider();      
      AHAddress tmp_add = new AHAddress(rng);
      Node n = new StructuredNode(tmp_add, "unittest");
      AHSender ah = new AHSender(n, AddressParser.Parse("brunet:node:JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4"));
      ForwardingSender fs = new ForwardingSender(n, 
                                                 AddressParser.Parse("brunet:node:JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4"),
                                                 AddressParser.Parse("brunet:node:5FMQW3KKJWOOGVDO6QAQP65AWVZQ4VUQ"));
      
      string uri = "sender:ah?dest=JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4&mode=exact";
      ISender s = SenderFactory.CreateInstance(n, uri);
      Assert.IsTrue(s is AHSender);
      Assert.AreEqual(uri, s.ToUri());
      uri = "sender:ah?dest=JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4&mode=greedy";
      
      //Create the above programatically
      IDictionary<string, string> param_args = new Dictionary<string,string>();
      param_args["dest"] = "JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4";
      param_args["mode"] = "greedy";
      string uri0 = SenderFactory.EncodeUri("ah", param_args); 
      Assert.AreEqual(uri, uri0, "EncodeUri works");
      //Check decode:
      string scheme;
      param_args = SenderFactory.DecodeUri(uri, out scheme);
      Assert.AreEqual(scheme, "ah", "Scheme decoded");
      Assert.AreEqual(param_args.Count, 2, "2 parameters in uri");
      Assert.AreEqual(param_args["dest"], "JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4", "Extracted address");
      Assert.AreEqual(param_args["mode"], "greedy", "got mode");

      s = SenderFactory.CreateInstance(n, uri);
      Assert.IsTrue(s is AHSender);
      Assert.AreEqual(uri, s.ToUri());      
      string furi = "sender:fw?relay=JOJZG7VO6RFOEZJ6CJJ2WOIJWTXRVRP4&init_mode=greedy&dest=5FMQW3KKJWOOGVDO6QAQP65AWVZQ4VUQ&ttl=3&mode=path";
      s = SenderFactory.CreateInstance(n, furi);
      Assert.IsTrue(s is ForwardingSender);
      Assert.AreEqual(furi, s.ToUri());
    }
Exemplo n.º 24
0
 /// <summary>Creates a BroadcastHandler, don't forget to Subscribe to the
 /// Node.DemuxHandler with the PType -> BroadcastSender.PType.</summary>
 public BroadcastHandler(StructuredNode node)
 {
   Node = node;
 }