当前位置: 首页>>代码示例>>C#>>正文


C# Node.AddEdgeListener方法代码示例

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


在下文中一共展示了Node.AddEdgeListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemotingTester

    public RemotingTester(int p, NetworkConfiguration nc, StreamWriter fs)
    { 
      int desired_port = p;
      _port = (short)p;
      _sw = fs;
      Console.WriteLine("Z {0}",_port);
      int local_host_index = nc.GetLocalHostIndex(desired_port); 
      NodeConfiguration this_node_configuration = (NodeConfiguration)nc.Nodes[local_host_index];
      Console.WriteLine("A");
      TransportAddressConfiguration local_ta_configuration = 
        (TransportAddressConfiguration)this_node_configuration.TransportAddresses[0];
      Console.WriteLine("B");
      short this_port = local_ta_configuration.Port;

      SHA1 sha = new SHA1CryptoServiceProvider();
      String local_ta = local_ta_configuration.GetTransportAddressURI();
      //We take the local transport address plus the port number to be hashed to obtain a random AHAddress
      byte[] hashedbytes = sha.ComputeHash(Encoding.UTF8.GetBytes(local_ta + desired_port));
      //inforce type 0
      hashedbytes[Address.MemSize - 1] &= 0xFE;
      AHAddress _local_ahaddress = new AHAddress(hashedbytes);
      Node this_node = new HybridNode( _local_ahaddress );
      //Node this_node = new StructuredNode( _local_ahaddress );

      node = this_node;
      if ( local_ta_configuration.Protocol == "tcp" ) {
        node.AddEdgeListener( new TcpEdgeListener(this_port) );
      } 
      else if( local_ta_configuration.Protocol == "udp" ) {
        node.AddEdgeListener( new UdpEdgeListener(this_port) );        
      }
      Console.WriteLine("C");
      int remote_node_index = local_host_index-1;
      int num_remote_ta = 150; //20 nodes on the list to try to bootstrap to

      if (local_host_index!=0) {
              Console.WriteLine("C--");
        NodeConfiguration remote_node_configuration = (NodeConfiguration)nc.Nodes[0];
      Console.WriteLine("C++");
        TransportAddressConfiguration remote_ta_configuration = 
          (TransportAddressConfiguration)remote_node_configuration.TransportAddresses[0];
      Console.WriteLine("D");

        String remote_ta = remote_ta_configuration.GetTransportAddressURI(); 
        node.RemoteTAs.Add( new TransportAddress( remote_ta  ) );
      }

      while ( (remote_node_index>=0) && (num_remote_ta>=0) ) { 
        NodeConfiguration remote_node_configuration = (NodeConfiguration)nc.Nodes[remote_node_index];
      Console.WriteLine("E");
        TransportAddressConfiguration remote_ta_configuration = 
          (TransportAddressConfiguration)remote_node_configuration.TransportAddresses[0];

        String remote_ta = remote_ta_configuration.GetTransportAddressURI(); 
        node.RemoteTAs.Add( new TransportAddress( remote_ta  ) );

        //System.Console.WriteLine("Adding {0}", remote_ta);

        remote_node_index--;
        num_remote_ta--;
      }

      bool net_stream = false;
      String server_ipadd = "cantor.ee.ucla.edu";
      int server_port = 8002;
      int time_diff = 0;
      String td_file_string = "~/joe/time_diff.txt";
      if(File.Exists(td_file_string)){
        StreamReader sr = new StreamReader(td_file_string);
        time_diff = Convert.ToInt32( sr.ReadLine() );     
        sr.Close();
      }  
      //String file_string = "./data/brunetadd" + Convert.ToString(desired_port) + ".log";
      fs.WriteLine( "local_address " + node.Address.ToBigInteger().ToString() 
          + " " + Dns.GetHostName() + ":" + desired_port);
      fs.Write( DateTime.Now.ToUniversalTime().ToString("MM'/'dd'/'yyyy' 'HH':'mm':'ss") + 
          ":" + DateTime.Now.ToUniversalTime().Millisecond +
          "  Start  Start  " + node.Address.ToBigInteger().ToString() + '\n'); 
      fs.Flush(); 

#if PLAB_LOG
      BrunetLogger bl = new BrunetLogger(desired_port, (AHAddress)node.Address, 
          net_stream, server_ipadd, server_port, time_diff, fs); 
      node.Logger = bl;
#endif
      //bool log_rdp = false;	  

#if PACKET_LOG
      String file_packet = "./data/packet" + Convert.ToString(desired_port) + ".log";
      StreamWriter packet_sw = new StreamWriter(file_packet, false);
      packet_sw.WriteLine("Local_node: {0}:{1} start_time_GMT: {2}:{3} local_address {4}", Dns.GetHostName(), 
          desired_port, DateTime.Now.ToUniversalTime().ToString("MM'/'dd'/'yyyy' 'HH':'mm':'ss"), 
          DateTime.Now.ToUniversalTime().Millisecond, node.Address.ToBigInteger().ToString() ); 
      packet_sw.Close(); 
#endif

    }
开发者ID:xujyan,项目名称:brunet,代码行数:97,代码来源:RemotingTester.cs

示例2: BrunetTester

    public BrunetTester(int p, NetworkConfiguration nc, StreamWriter fs)
    { 
      int desired_port = p;
      _port = (short)p;
      _sw = fs;
      int local_host_index = nc.GetLocalHostIndex(desired_port); 
      NodeConfiguration this_node_configuration = (NodeConfiguration)nc.Nodes[local_host_index];

      TransportAddressConfiguration local_ta_configuration = 
        (TransportAddressConfiguration)this_node_configuration.TransportAddresses[0];
      short this_port = local_ta_configuration.Port;

      SHA1 sha = new SHA1CryptoServiceProvider();
      String local_ta = local_ta_configuration.GetTransportAddressURI();
      //We take the local transport address plus the port number to be hashed to obtain a random AHAddress
      byte[] hashedbytes = sha.ComputeHash(Encoding.UTF8.GetBytes(local_ta + desired_port));
      //inforce type 0
      hashedbytes[Address.MemSize - 1] &= 0xFE;
      AHAddress _local_ahaddress = new AHAddress(hashedbytes);
      //Node this_node = new HybridNode( _local_ahaddress );
      Node this_node = new StructuredNode( _local_ahaddress );

      node = this_node;
      if ( local_ta_configuration.Protocol == "tcp" ) {
        node.AddEdgeListener( new TcpEdgeListener(this_port) );
      } 
      else if( local_ta_configuration.Protocol == "udp" ) {
        node.AddEdgeListener( new UdpEdgeListener(this_port) );        
      }

      int remote_node_index = local_host_index-1;
      int num_remote_ta = 150; //20 nodes on the list to try to bootstrap to

      if (local_host_index!=0) {
        NodeConfiguration remote_node_configuration = (NodeConfiguration)nc.Nodes[0];
        TransportAddressConfiguration remote_ta_configuration = 
          (TransportAddressConfiguration)remote_node_configuration.TransportAddresses[0];

        String remote_ta = remote_ta_configuration.GetTransportAddressURI(); 
        node.RemoteTAs.Add( TransportAddressFactory.CreateInstance( remote_ta  ) );
      }

      while ( (remote_node_index>=0) && (num_remote_ta>=0) ) { 
        NodeConfiguration remote_node_configuration = (NodeConfiguration)nc.Nodes[remote_node_index];
        TransportAddressConfiguration remote_ta_configuration = 
          (TransportAddressConfiguration)remote_node_configuration.TransportAddresses[0];

        String remote_ta = remote_ta_configuration.GetTransportAddressURI(); 
        node.RemoteTAs.Add(
	             TransportAddressFactory.CreateInstance( remote_ta  ) );

        //System.Console.WriteLine("Adding {0}", remote_ta);

        remote_node_index--;
        num_remote_ta--;
      }

      //String file_string = "./data/brunetadd" + Convert.ToString(desired_port) + ".log";
      fs.WriteLine( "local_address " + node.Address.ToBigInteger().ToString() 
          + " " + Dns.GetHostName() + ":" + desired_port);
      fs.Write( DateTime.Now.ToUniversalTime().ToString("MM'/'dd'/'yyyy' 'HH':'mm':'ss") + 
          ":" + DateTime.Now.ToUniversalTime().Millisecond +
          "  Start  Start  " + node.Address.ToBigInteger().ToString() + '\n'); 
      fs.Flush(); 
      //bool log_rdp = false;	  

#if PACKET_LOG
      String file_packet = "./data/packet" + Convert.ToString(desired_port) + ".log";
      StreamWriter packet_sw = new StreamWriter(file_packet, false);
      packet_sw.WriteLine("Local_node: {0}:{1} start_time_GMT: {2}:{3} local_address {4}", Dns.GetHostName(), 
          desired_port, DateTime.Now.ToUniversalTime().ToString("MM'/'dd'/'yyyy' 'HH':'mm':'ss"), 
          DateTime.Now.ToUniversalTime().Millisecond, node.Address.ToBigInteger().ToString() ); 
      packet_sw.Close(); 
#endif

    }
开发者ID:hseom,项目名称:hseom_brunet,代码行数:76,代码来源:BrunetTester.cs


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