• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Symphony.AHAddress类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Brunet.Symphony.AHAddress的典型用法代码示例。如果您正苦于以下问题:C# AHAddress类的具体用法?C# AHAddress怎么用?C# AHAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AHAddress类属于Brunet.Symphony命名空间,在下文中一共展示了AHAddress类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: SubringTransportAddress

 public SubringTransportAddress(AHAddress target, string node_ns) :
   base(string.Format("brunet.{0}://{1}.{2}", TATypeToString(TAType.Subring),
         target.ToMemBlock().ToBase32String(), node_ns))
 {
   Target = target;
   Namespace = node_ns;
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:7,代码来源:SubringTransportAddress.cs


示例2: StructuredNode

    public StructuredNode(AHAddress add, string realm):base(add,realm)
    {
      /**
       * Here are the ConnectionOverlords
       */ 
      _leafco = new LeafConnectionOverlord(this);
      AddConnectionOverlord(_leafco);
      _snco = new StructuredNearConnectionOverlord(this);
      AddConnectionOverlord(_snco);
      _ssco = new StructuredShortcutConnectionOverlord(this);
      AddConnectionOverlord(_ssco);
#if !BRUNET_SIMULATOR
      _iphandler = new IPHandler();
      _iphandler.Subscribe(this, null);
      AddTADiscovery(new LocalDiscovery(this, Realm, _rpc, _iphandler));
#endif

      /**
       * Turn on some protocol support : 
       */
      /// Turn on Packet Forwarding Support :
      GetTypeSource(PType.Protocol.Forwarding).Subscribe(new PacketForwarder(this), null);
      AHHandler = new AHHandler(this);
      GetTypeSource(PType.Protocol.AH).Subscribe(AHHandler, this);
      GetTypeSource(PType.Protocol.Echo).Subscribe(new EchoHandler(), this);
      
      //Add the standard RPC handlers:
      _rpc.AddHandler("sys:ctm", new CtmRequestHandler(this));
      sys_link = new ConnectionPacketHandler(this);
      _rpc.AddHandler("sys:link", sys_link);
      _rpc.AddHandler("trace", new TraceRpcHandler(this));
      //Serve some public information about our ConnectionTable
      _rpc.AddHandler("ConnectionTable", new ConnectionTableRpc(ConnectionTable, _rpc));
      //Add a map-reduce handlers:
      _mr_handler = new MapReduceHandler(this);
      //Subscribe it with the RPC handler:
      _rpc.AddHandler("mapreduce", _mr_handler);

      //Subscribe map-reduce tasks
      _mr_handler.SubscribeTask(new MapReduceTrace(this));
      _mr_handler.SubscribeTask(new MapReduceRangeCounter(this));

      
      /*
       * Handle Node state changes.
       */
      StateChangeEvent += delegate(Node n, Node.ConnectionState s) {
        if( s == Node.ConnectionState.Leaving ) {
          //Start our StructuredNode specific leaving:
          Leave();
        }
      };

      _connection_table.ConnectionEvent += new EventHandler(this.EstimateSize);
      _connection_table.ConnectionEvent += new EventHandler(this.UpdateNeighborStatus);
      _connection_table.DisconnectionEvent += new EventHandler(this.EstimateSize);
      _connection_table.DisconnectionEvent += new EventHandler(this.UpdateNeighborStatus);
    }
开发者ID:acisp2p,项目名称:brunet,代码行数:58,代码来源:StructuredNode.cs


示例3: AddDisconnectedPair

    // adds a disconnected pair to the pool
    public void AddDisconnectedPair(out Address address1, out Address address2, bool nctunnel)
    {
      address1 = new AHAddress(new RNGCryptoServiceProvider());
      byte[] addrbuff = Address.ConvertToAddressBuffer(address1.ToBigInteger() + (Address.Full / 2));
      Address.SetClass(addrbuff, AHAddress._class);
      address2 = new AHAddress(addrbuff);

      AddDisconnectedPair(address1, address2, nctunnel);
    }
开发者ID:hseom,项目名称:brunet,代码行数:10,代码来源:RelayOverlapSimulator.cs


示例4: GraphNode

    public GraphNode(AHAddress addr)
    {
      Shortcuts = 0;
      Address = addr;
      ConnectionTable = new ConnectionTable(addr);
      UpdateSystem();

      do {
        UniqueID = _rand.Next();
      } while(_unique_allocations.ContainsKey(UniqueID));
      _unique_allocations[UniqueID] = UniqueID;
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:12,代码来源:GraphNode.cs


示例5: DoTraceRouteTo

  /**
   * 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);  
    }
  }
开发者ID:pstjuste,项目名称:brunet,代码行数:56,代码来源:TraceRpcHandler.cs


示例6: info

 /**
 <summary>Reassign range info(Start and End) based on recalculated range.</summary>
 <param name = "rg_size">Current range size(round distance between start address and end address of this Entry).</param>
 <remarks>new_start = mid - rg_size/2, new_end = mid + rg_size/2 </remarks>
  */
 public Entry ReAssignRange(BigInteger rg_size) {
   // calculate middle address of range
   BigInteger start_int = Start.ToBigInteger();
   BigInteger end_int = End.ToBigInteger();
   BigInteger mid_int =  (start_int + end_int) / 2;  
   if (mid_int % 2 == 1) { mid_int = mid_int -1; }
   AHAddress mid_addr = new AHAddress(mid_int);
   /*
    * If we have a case where start -> end includes zero,
    * this is the wrap around.  So, we can imagine that
    * we have end' = end + Address.Full.  So,
    * mid' = (start + end')/2 = (start + end)/2 + Address.Full/2
           = (start + end)/ 2 + Address.Half
    */
   if (!mid_addr.IsBetweenFromLeft(Start, End)) {
     mid_int += Address.Half;
   }
   //addresses for new range
   BigInteger rg_half = rg_size / 2;
   if (rg_half % 2 == 1) { rg_half -= 1; }
   AHAddress n_a = new AHAddress(mid_int - rg_half);
   AHAddress n_b = new AHAddress(mid_int + rg_half);
   return new Entry(Content, Alpha, n_a, n_b);
 }
开发者ID:hseom,项目名称:brunet,代码行数:29,代码来源:Entry.cs


示例7: Test

    public void Test()
    {
      Address addr_x = new AHAddress(new RNGCryptoServiceProvider());
      byte[] addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (Address.Full / 2));
      Address.SetClass(addrbuff, AHAddress._class);
      Address addr_y = new AHAddress(addrbuff);

      List<Connection> connections = new List<Connection>();
      ConnectionTable ct_x = new ConnectionTable();
      ConnectionTable ct_y = new ConnectionTable();
      ConnectionTable ct_empty = new ConnectionTable();
      NCService ncservice = new NCService();

      Connection fast_con = null;
      for(int i = 1; i <= 11; i++) {
        addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (i * Address.Full / 16));
        Address.SetClass(addrbuff, AHAddress._class);
        Address addr = new AHAddress(addrbuff);
        Connection con = null;

        TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://158.7.0.1:5000");
        Edge fe = new FakeEdge(ta, ta, TransportAddress.TAType.Tcp);
        if(i <= 10) {
          con = new Connection(fe, addr, "structured", null, null);
          ct_x.Add(con);
          if(i % 2 == 0) {
            ncservice.ProcessSample(DateTime.UtcNow, String.Empty, addr,
                new Point(new double[] {0, 0}, 0), 0, i*10);
          }
        } else {
          fast_con = new Connection(fe, addr, "structured", null, null);
          ncservice.ProcessSample(DateTime.UtcNow, String.Empty, addr,
              new Point(new double[] {0, 0}, 0), 0, 5);
        }

        if(i == 10) {
          ct_y.Add(con);
        }
        connections.Add(con);
      }

      ITunnelOverlap sto = new SimpleTunnelOverlap();
      ITunnelOverlap nto = new NCTunnelOverlap(ncservice);

      ConnectionType con_type = ConnectionType.Structured;
      List<Connection> pre_cons = new List<Connection>();
      pre_cons.Add(connections[9]);
      IDictionary id = nto.GetSyncMessage(pre_cons, addr_x, ct_x.GetConnections(con_type));

      // We do have some pre-existing overlap
      Assert.AreEqual(nto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], connections[9], "NC: Have an overlap!");
      Assert.AreEqual(sto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], connections[9], "Simple: Have an overlap!");

      // We have no overlap with an empty connection table
      Assert.AreEqual(nto.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!");
      Assert.AreEqual(sto.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!");

      // latency[0] == -1
      Assert.AreEqual(connections[1].Address.Equals(nto.EvaluatePotentialOverlap(id)), true,
          "NC: EvaluatePotentialOverlap returns expected!");
      Assert.AreEqual(ct_x.Contains(con_type, sto.EvaluatePotentialOverlap(id)), true,
          "Simple: EvaluatePotentialOverlap returns valid!");

      ct_y.Add(fast_con);
      ct_x.Add(fast_con);
      id = nto.GetSyncMessage(pre_cons, addr_x, ct_x.GetConnections(con_type));
      Assert.AreEqual(fast_con.Address.Equals(nto.EvaluatePotentialOverlap(id)), true,
          "NC: EvaluatePotentialOverlap returns expected!");
      Assert.AreEqual(nto.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0], fast_con, "NC: Have better overlap!");
    }
开发者ID:johnynek,项目名称:brunet,代码行数:70,代码来源:NCTunnelOverlap.cs


示例8: GetConnectionInfo

 /**
  * Find neighbor connections within the range
  * return ArrayList of List<Connection> for left and right neighbors.
  */
 private Brunet.Collections.Pair<List<Connection>,List<Connection>> GetConnectionInfo(AHAddress t_addr, AHAddress start, AHAddress end, ConnectionList cl) {
    
   //this node is within the given range (start_addr, end_addr)
   List<Connection> left_con_list = new List<Connection>();
   List<Connection> right_con_list = new List<Connection>();
   foreach(Connection c in cl) {
     AHAddress adr = (AHAddress)c.Address;
     //if(adr.IsBetweenFromLeft(t_addr, end) ) {
     if (InRange(adr, start, t_addr) ) {
       left_con_list.Add(c);
     }
     //else if (adr.IsBetweenFromLeft(start, t_addr) ) {
     else if (InRange(adr, start, t_addr) ) {
       right_con_list.Add(c);
     }
     else {
       //Out of Range. Do nothing!
     }
   }
   //Make a compare and add it to ConnectionTable to sort by Address
   ConnectionLeftComparer left_cmp = new ConnectionLeftComparer(t_addr);
   left_con_list.Sort(left_cmp);
   ConnectionRightComparer right_cmp = new ConnectionRightComparer(t_addr);
   right_con_list.Sort(right_cmp);
   Brunet.Collections.Pair<List<Connection>,List<Connection>> ret = new Brunet.Collections.Pair<List<Connection>,List<Connection>>(left_con_list, right_con_list);
   return ret;
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:31,代码来源:MapReduceBaseTasks.cs


示例9: GenerateTreeOutRange

 /**
  * 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;
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:38,代码来源:MapReduceBaseTasks.cs


示例10: GenerateTree

    /**
     * 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());
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:63,代码来源:MapReduceBaseTasks.cs


示例11: PrepareNode

    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, "[email protected]", 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;
    }
开发者ID:hseom,项目名称:brunet,代码行数:97,代码来源:Simulator.cs


示例12: GenerateAddress

 /// <summary>Generate a new unique address, there is potential for
 /// collissions when we make the address space small.</summary>
 protected AHAddress GenerateAddress()
 {
   byte[] addr = new byte[Address.MemSize];
   _rand.NextBytes(addr);
   Address.SetClass(addr, AHAddress._class);
   AHAddress ah_addr = new AHAddress(MemBlock.Reference(addr));
   if(Nodes.ContainsKey(ah_addr)) {
     ah_addr = GenerateAddress();
   }
   return ah_addr;
 }
开发者ID:hseom,项目名称:brunet,代码行数:13,代码来源:Simulator.cs


示例13: AHState

 public AHState(AHAddress local, ConnectionList structs, ConnectionList leafs) {
   Leafs = leafs;
   Structs = structs;
   Local = local;
   
   _directional = new DirectionalRouting(local, structs);
   _greedy = new GreedyRouting(local, structs);
   _annealing = new AnnealingRouting(local, structs);
 }
开发者ID:johnynek,项目名称:brunet,代码行数:9,代码来源:AHSender.cs


示例14: Test

    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());
    }
开发者ID:johnynek,项目名称:brunet,代码行数:37,代码来源:AHSender.cs


示例15: AddNode

 ///<summary>Add a new specific node to the simulation.</summary>
 public virtual Node AddNode(int id, AHAddress address)
 {
   StructuredNode node = PrepareNode(id, address);
   if(!_start) {
     node.Connect();
   }
   CurrentNetworkSize++;
   return node;
 }
开发者ID:hseom,项目名称:brunet,代码行数:10,代码来源:Simulator.cs


示例16: MapReduceBoundedBroadcast

 public MapReduceBoundedBroadcast(Node n):base(n) {
   _this_addr = _node.Address as AHAddress;
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:3,代码来源:MapReduceBaseTasks.cs


示例17: Test

    public void Test()
    {
      IRelayOverlap _ito = new SimpleRelayOverlap();
      Address addr_x = new AHAddress(new RNGCryptoServiceProvider());
      byte[] addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (Address.Full / 2));
      Address.SetClass(addrbuff, AHAddress._class);
      Address addr_y = new AHAddress(addrbuff);

      ArrayList addresses = new ArrayList();
      ConnectionTable ct_x = new ConnectionTable();
      ConnectionTable ct_y = new ConnectionTable();
      ConnectionTable ct_empty = new ConnectionTable();
      for(int i = 1; i <= 10; i++) {
        addrbuff = Address.ConvertToAddressBuffer(addr_x.ToBigInteger() + (i * Address.Full / 16));
        Address.SetClass(addrbuff, AHAddress._class);
        addresses.Add(new AHAddress(addrbuff));

        TransportAddress ta = TransportAddressFactory.CreateInstance("brunet.tcp://158.7.0.1:5000");
        Edge fe = new FakeEdge(ta, ta, TransportAddress.TAType.Tcp);
        ct_x.Add(new Connection(fe, addresses[i - 1] as AHAddress, "structured", null, null));
        if(i == 10) {
          ct_y.Add(new Connection(fe, addresses[i - 1] as AHAddress, "structured", null, null));
        }
      }


      ConnectionType con_type = ConnectionType.Structured;
      IDictionary id = _ito.GetSyncMessage(null, addr_x, ct_x.GetConnections(con_type));
      Assert.AreEqual(_ito.EvaluateOverlap(ct_y.GetConnections(con_type), id)[0].Address, addresses[9], "Have an overlap!");
      Assert.AreEqual(_ito.EvaluateOverlap(ct_empty.GetConnections(con_type), id).Count, 0, "No overlap!");
      Assert.AreEqual(addresses.Contains(_ito.EvaluatePotentialOverlap(id)), true, "EvaluatePotentialOverlap returns valid!");
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:32,代码来源:RelayOverlap.cs


示例18: GenerateTreeInRange

 /**
  * 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;
 }    
开发者ID:pstjuste,项目名称:brunet,代码行数:71,代码来源:MapReduceBaseTasks.cs


示例19: EvaluatePotentialOverlap

    /// <summary>Always returns the oldest non-tunnel address.</summary>
    public virtual Address EvaluatePotentialOverlap(IDictionary msg)
    {
      Address oldest_addr = null;
      int oldest_age = -1;
      foreach(DictionaryEntry de in msg) {
        MemBlock key = de.Key as MemBlock;
        if(key == null) {
          key = MemBlock.Reference((byte[]) de.Key);
        }
        Address addr = new AHAddress(key);

        Hashtable values = de.Value as Hashtable;
        TransportAddress.TAType tatype =
          TransportAddressFactory.StringToType(values["ta"] as string);

        if(tatype.Equals(TransportAddress.TAType.Relay)) {
          continue;
        }

        int age = (int) values["ct"];
        if(age > oldest_age) {
          oldest_addr = addr;
        }
      }

      return oldest_addr;
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:28,代码来源:RelayOverlap.cs


示例20: NextGreedyClosest

 protected Connection NextGreedyClosest(AHAddress dest) {
 /*
  * First find the Connection pointing to the node closest 
  * from local to dest, 
  * if there is one closer than us
  */
   ConnectionTable tab = _node.ConnectionTable;
   ConnectionList structs = tab.GetConnections(ConnectionType.Structured);
   AHAddress local = (AHAddress)_node.Address;
   Connection next_closest = structs.GetNearestTo(local, dest);
   return next_closest;
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:12,代码来源:MapReduceBaseTasks.cs



注:本文中的Brunet.Symphony.AHAddress类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Transport.TransportAddress类代码示例发布时间:2022-05-24
下一篇:
C# Brunet.Node类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap