Esempio n. 1
0
 /**
  * When a node is out of the range, this method is called.
  * This method tries to find the nearest node to the middle of range using greedty algorithm.
  * return list of MapReduceInfo
  */
 private List<MapReduceInfo> GenerateTreeOutRange(AHAddress start, AHAddress end, MapReduceArgs mr_args) {
   List<MapReduceInfo> retval = new List<MapReduceInfo>();
   BigInteger up = start.ToBigInteger();
   BigInteger down = end.ToBigInteger();
   BigInteger mid_range = (up + down) /2;
   if (mid_range % 2 == 1) {mid_range = mid_range -1; }
   AHAddress mid_addr = new AHAddress(mid_range);
   //if (!mid_addr.IsBetweenFromLeft(start, end) ) {
   if (!InRange(mid_addr, start, end) ) {
     mid_range += Address.Half;
     mid_addr = new AHAddress(mid_range);
   }
   ArrayList gen_arg = new ArrayList();
   if (NextGreedyClosest(mid_addr) != null ) {
     AHGreedySender ags = new AHGreedySender(_node, mid_addr);
     string start_range = start.ToString();
     string end_range = end.ToString();
     gen_arg.Add(start_range);
     gen_arg.Add(end_range);
     MapReduceInfo mr_info = new MapReduceInfo( (ISender) ags,
     			                new MapReduceArgs(this.TaskName,
     						          mr_args.MapArg,
     							  gen_arg,
                                                               mr_args.ReduceArg));
     Log("{0}: {1}, out of range, moving to the closest node to mid_range: {2} to target node, range start: {3}, range end: {4}",
     		  this.TaskName, _node.Address, mid_addr, start, end);
     retval.Add(mr_info);
   }
   else  {
     // cannot find a node in the range. 
   }
   return retval;
 }
Esempio n. 2
0
  /**
   * This is a recursive function over the network
   * It helps to build an IList of IDictionary types that give the address
   * of each node in the path, and the connection to the next closest node if
   * there is one, otherwise no next.
   */
  protected void DoTraceRouteTo(AHAddress a, object req_state) {
    /*
     * First find the Connection pointing to the node closest to dest, if
     * there is one closer than us
     */

    ConnectionTable tab = _node.ConnectionTable;
    ConnectionList structs = tab.GetConnections(ConnectionType.Structured);
    Connection next_closest = structs.GetNearestTo((AHAddress) _node.Address, a);
    //Okay, we have the next closest:
    ListDictionary my_entry = new ListDictionary();
    my_entry["node"] = _node.Address.ToString();
    if( next_closest != null ) {
      my_entry["next_con"] = next_closest.ToString();
      Channel result = new Channel();
      //We only want one result, so close the queue after we get the first
      result.CloseAfterEnqueue();
      result.CloseEvent += delegate(object o, EventArgs args) {
        Channel q = (Channel)o;
        if( q.Count > 0 ) {
          try {
            RpcResult rres = (RpcResult)q.Dequeue();
            IList l = (IList) rres.Result;
            ArrayList results = new ArrayList( l.Count + 1);
            results.Add(my_entry);
            results.AddRange(l);
            _rpc.SendResult(req_state, results);
          }
          catch(Exception x) {
            string m = String.Format("<node>{0}</node> trying <connection>{1}</connection> got <exception>{2}</exception>", _node.Address, next_closest, x);
            Exception nx = new Exception(m);
            _rpc.SendResult(req_state, nx);
          }
        }
        else {
          //We got no results.
          IList l = new ArrayList(1);
          l.Add( my_entry );
          _rpc.SendResult(req_state, l);
        }
      };
      _rpc.Invoke(next_closest.State.Edge, result, "trace.GetRouteTo", a.ToString());
    }
    else {
      //We are the end of the line, send the result:
      ArrayList l = new ArrayList();
      l.Add(my_entry);
      _rpc.SendResult(req_state, l);  
    }
  }
Esempio n. 3
0
    /**
     * Generates tree for bounded broadcast. Algorithm works as follows:
     * The goal is to broadcast to all nodes in range (start, end).
     * Given a range (a, b), determine all connections that belong to this range.
     * Let the left connections be l_1, l_2, ..... l_n.
     * Let the right connections be r_1, r_2, ... , r_n.
     * To left connection l_i assign the range [b_{i-1}, b_i).
     * To right connection r_i assign the range [r_i, r_{i-1}]
     * To the connection ln assign range [l_{n-1}, end)
     * To the connection rn assign range (start, r_{n-1}]
     */
    public override void GenerateTree(Channel q, MapReduceArgs mr_args)  
    {
      ArrayList gen_list = mr_args.GenArg as ArrayList;
      string start_range = gen_list[0] as string;
      AHAddress start_addr = (AHAddress) AddressParser.Parse(start_range);
      AHAddress end_addr;
      string end_range;
      /// If users do not specify an end range, this method understands 
      /// that users intend to broadcasting the whole range.
      /// Thus, the address of end range is set to (start_address - 2), 
      /// the farthest address from the start_addr.
      if (gen_list.Count < 2)  {
        BigInteger start_int = start_addr.ToBigInteger();
        BigInteger end_int = start_int -2;
        end_addr = new AHAddress(end_int);
        end_range = end_addr.ToString();
      }
      else {
        end_range = gen_list[1] as string;
        end_addr = (AHAddress) AddressParser.Parse(end_range);
      }
      Log("generating child tree, range start: {0}, range end: {1}.", start_range, end_range);
      //we are at the start node, here we go:
      ConnectionTable tab = _node.ConnectionTable;
      ConnectionList structs = tab.GetConnections(ConnectionType.Structured);
      List<MapReduceInfo> retval = new List<MapReduceInfo>();

      if (InRange(_this_addr, start_addr, end_addr)) {
        if (structs.Count > 0) {
          //make connection list in the range.
          //left connection list is a list of neighbors which are in the range (this node, end of range)
          //right connection list is a list of neighbors which are in the range (start of range, this node)
          Brunet.Collections.Pair<List<Connection>,List<Connection>> cons = GetConnectionInfo(_this_addr, start_addr, end_addr, structs);
          List<Connection> left_cons =  cons.First as List<Connection>;
          List<Connection> right_cons = cons.Second as List<Connection>;
          //PrintConnectionList(left_cons);
          //PrintConnectionList(right_cons);
          retval = GenerateTreeInRange(start_addr, end_addr, left_cons, true, mr_args);
          List<MapReduceInfo> ret_right = GenerateTreeInRange(start_addr, end_addr, right_cons, false, mr_args);
          retval.AddRange(ret_right);
        }
        else {  //this node is a leaf node.
          //MapReduceInfo mr_info = null;
          //retval.Add(mr_info);
          //Console.WriteLine("no connection in the range: return null info");
        }
      }
      else { // _node is out of range. Just pass it to the closest to the middle of range.
        retval = GenerateTreeOutRange(start_addr, end_addr, mr_args);
      }
      q.Enqueue( retval.ToArray());
    }
Esempio n. 4
0
 /**
  * Generate tree within the range.
  * return list of MapReduceInfo
  */
 private List<MapReduceInfo> GenerateTreeInRange(AHAddress start, AHAddress end, List<Connection> cons, bool left, MapReduceArgs mr_args) {
   //Divide the range and trigger bounded broadcasting again in divided range starting with neighbor.
   //Deivided ranges are (start, n_1), (n_1, n_2), ... , (n_m, end)
   AHAddress this_minus2 = new AHAddress(_this_addr.ToBigInteger()-2);
   AHAddress this_plus2 = new AHAddress(_this_addr.ToBigInteger()+2);
   List<MapReduceInfo> retval = new List<MapReduceInfo>();
   if (cons.Count != 0) //make sure if connection list is not empty!
   {
     //con_list is sorted.
     AHAddress last;
     if (left) {
       last = end;
     }
     else {
       last = start;
     }
     string rg_start, rg_end;
     //the first element of cons is the nearest.
     //Let's start with the farthest neighbor first.
     for (int i = (cons.Count-1); i >= 0; i--) {
       ArrayList gen_arg = new ArrayList();
       Connection next_c = cons[i];
       AHAddress next_addr = (AHAddress)next_c.Address;
       ISender sender = next_c.State.Edge;
       if (i==0) {  // The last bit
         if (left) {
           // the left nearest neighbor 
           rg_start = this_plus2.ToString();
           rg_end = last.ToString();
         }
         else {
           // the right nearest neighbor
           rg_start = last.ToString();
           rg_end = this_minus2.ToString();
         }
       }
       else {
         if (left) { //left connections
           rg_start = next_addr.ToString();
           rg_end = last.ToString();
         }
         else {  //right connections
           rg_start = last.ToString();
           rg_end = next_addr.ToString();
         }
       }
       gen_arg.Add(rg_start);
       gen_arg.Add(rg_end);
       MapReduceInfo mr_info = new MapReduceInfo( sender,
        		                              new MapReduceArgs(this.TaskName,
       				               	             mr_args.MapArg,
       							     gen_arg,
       							     mr_args.ReduceArg));
       Log("{0}: {1}, adding address: {2} to sender list, range start: {3}, range end: {4}",
       			    this.TaskName, _node.Address, next_c.Address,
       			    gen_arg[0], gen_arg[1]);
       if (left) {
         last = new AHAddress(next_addr.ToBigInteger()-2);
       }
       else {
         last = new AHAddress(next_addr.ToBigInteger()+2);
       }
       retval.Add(mr_info);
     }
   }
   return retval;
 }    
Esempio n. 5
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;
    }
Esempio n. 6
0
    public void LMSerializationTest()
    {
      NodeInfo n1 = NodeInfo.CreateInstance(null, TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:45"));
      RandomNumberGenerator rng = new RNGCryptoServiceProvider();      
      AHAddress tmp_add = new AHAddress(rng);
      LinkMessage l1 = new LinkMessage(ConnectionType.Structured, n1,
				       NodeInfo.CreateInstance(new DirectionalAddress(DirectionalAddress.Direction.Left),
				       TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:837")), tmp_add.ToString() );
      RoundTripHT(l1);
      StringDictionary attrs = new StringDictionary();
      attrs["realm"] = "test_realm";
      attrs["type"] = "structured.near";
      LinkMessage l3 = new LinkMessage(attrs, n1, n1, tmp_add.ToString());
      RoundTripHT(l3);
    }
Esempio n. 7
0
 private string GetRandomNodeAddr() {
   AHAddress addr = new AHAddress(new RNGCryptoServiceProvider());
   return addr.ToString();
 }
Esempio n. 8
0
    public void CTMSerializationTest()
    {
      Address a = new DirectionalAddress(DirectionalAddress.Direction.Left);
      TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:5000"); 
      NodeInfo ni = NodeInfo.CreateInstance(a, ta);

      RandomNumberGenerator rng = new RNGCryptoServiceProvider();      
      AHAddress tmp_add = new AHAddress(rng);
      ConnectToMessage ctm1 = new ConnectToMessage(ConnectionType.Unstructured, ni, tmp_add.ToString());
      
      HTRoundTrip(ctm1);

      //Test multiple tas:
      ArrayList tas = new ArrayList();
      tas.Add(ta);
      for(int i = 5001; i < 5010; i++)
        tas.Add(TransportAddressFactory.CreateInstance("brunet.tcp://127.0.0.1:" + i.ToString()));
      NodeInfo ni2 = NodeInfo.CreateInstance(a, tas);

      ConnectToMessage ctm2 = new ConnectToMessage(ConnectionType.Structured, ni2, tmp_add.ToString());
      HTRoundTrip(ctm2);
      //Here is a ConnectTo message with a neighbor list:
      NodeInfo[] neighs = new NodeInfo[5];
      for(int i = 0; i < 5; i++) {
	string ta_tmp = "brunet.tcp://127.0.0.1:" + (i+80).ToString();
        NodeInfo tmp =
		NodeInfo.CreateInstance(new DirectionalAddress(DirectionalAddress.Direction.Left),
	                     TransportAddressFactory.CreateInstance(ta_tmp)
			    );
	neighs[i] = tmp;
      }
      ConnectToMessage ctm3 = new ConnectToMessage("structured", ni, neighs, tmp_add.ToString());
      HTRoundTrip(ctm3);
#if false
      Console.Error.WriteLine( ctm3.ToString() );
      foreach(NodeInfo tni in ctm3a.Neighbors) {
        Console.Error.WriteLine(tni.ToString());
      }
#endif
    }
Esempio n. 9
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;
    }