/**
     * 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 ArrayList GenerateTreeOutRange(AHAddress start, AHAddress end, MapReduceArgs mr_args, int timeout) {
      ArrayList retval = new ArrayList();
      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) ) {
          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,
								  timeout));
	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;
    }
    /**
     * Generate tree within the range.
     * return list of MapReduceInfo
     */
    private ArrayList GenerateTreeInRange(AHAddress this_addr, AHAddress start, AHAddress end, List<Connection> cons, bool left, MapReduceArgs mr_args, int timeout) {
      //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)
      ArrayList retval = new ArrayList();
      if (cons.Count != 0) //make sure if connection list is not empth!
      {
        //con_list is sorted.
	AHAddress last = this_addr;
	//the first element of cons is the nearest.
        for (int i = 0; i < cons.Count; i++) {
	  Connection next_c = (Connection)cons[i];
	  AHAddress next_addr = (AHAddress)next_c.Address;
	  ISender sender = (ISender) next_c.Edge;
	  string front = last.ToString();
	  string back = next_addr.ToString();
	  string rg_start = start.ToString();
	  string rg_end = end.ToString();
          ArrayList gen_arg = new ArrayList();
	  if (i==cons.Count -1) {  // The last bit
            if (left) {
	      // the left farthest neighbor 
	      gen_arg.Add(front);
	      gen_arg.Add(rg_end);
	    }
	    else {
	      // the right farthest neighbor
              gen_arg.Add(rg_start);
	      gen_arg.Add(front);
	    }
	  }
	  else {
	    if (left) { //left connections
              gen_arg.Add(front);
	      gen_arg.Add(back);
	    }
	    else {  //right connections
	      gen_arg.Add(back);
              gen_arg.Add(front);
	    }

	  }
	  MapReduceInfo mr_info = new MapReduceInfo( (ISender) sender,
	 		                              new MapReduceArgs(this.TaskName,
					               	             mr_args.MapArg,
								     gen_arg,
								     mr_args.ReduceArg,
								     timeout // timeout
								     ));
          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]);
	  last = next_addr;
	  retval.Add(mr_info);
	}
      }
      return retval;
    }    
Esempio n. 3
0
 /**
  * Recursive function to compute the latency of an Rpc call
  * by accumulating measured latencies of individual hops.
  * @param target address of the target
  */
 public void ComputePathLatencyTo(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_latency"] = GetMeasuredLatency(next_closest.Address);
     my_entry["next_contype"] = next_closest.ConType;
     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.Edge, result, "ncserver.ComputePathLatencyTo", 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. 4
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. 5
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. 6
0
    // adds a node to the pool
    protected static void add_node(bool output) {
      AHAddress address = new AHAddress(new RNGCryptoServiceProvider());
      Node node = new StructuredNode(address, brunet_namespace);
      NodeMapping nm = new NodeMapping();
      nm.Node = node;
      nodes.Add((Address) address, nm);

      nm.Port = TakenPorts.Count;
      while(TakenPorts.Contains(nm.Port)) {
        nm.Port = rand.Next(0, 65535);
      }

      TAAuthorizer auth = null;
      if(broken != 0) {
        auth = new BrokenTAAuth(broken);
      }

      EdgeListener el = new SimulationEdgeListener(nm.Port, 0, auth, true);

      if(secure_edges || secure_senders) {
        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);

        BrunetSecurityOverlord so = new BrunetSecurityOverlord(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) {
        el = new SecureEdgeListener(el, nm.BSO);
      }

      node.AddEdgeListener(el);

      if(broken != 0) {
        el = new TunnelEdgeListener(node);
        node.AddEdgeListener(el);
      }

      ArrayList RemoteTAs = new ArrayList();
      for(int i = 0; i < 5 && i < TakenPorts.Count; i++) {
        int rport = (int) TakenPorts.GetByIndex(rand.Next(0, TakenPorts.Count));
        RemoteTAs.Add(TransportAddressFactory.CreateInstance("brunet.function://127.0.0.1:" + rport));
      }
      node.RemoteTAs = RemoteTAs;

      TakenPorts[nm.Port] = nm.Port;

      if(output) {
        Console.WriteLine("Adding: " + nm.Node.Address);
      }
      node.Connect();
      network_size++;
    }