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

C# Brunet.MemBlock类代码示例

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

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



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

示例1: LinuxTap

        public LinuxTap(string dev)
        {
            int TUNSETIFF = GetIOCtlWrite('T', 202, 4); /* size of int 4, from if_tun.h */

              ifreq1 ifr1 = new ifreq1();
              int fd;

              if ((fd = Syscall.open("/dev/net/tun", OpenFlags.O_RDWR)) < 0) {
            throw new Exception("Failed to open /dev/net/tun");
              }

              ifr1.ifru_flags = IFF_TAP | IFF_NO_PI;
              ifr1.ifrn_name = dev;
              if (ioctl(fd, TUNSETIFF, ref ifr1) < 0) {
            Syscall.close(fd);
            throw new Exception("TUNSETIFF failed");
              }
              _fd = fd;

              int ctrl_fd = socket(AF_INET, SOCK_DGRAM, 0);
              if(ctrl_fd == -1) {
            Syscall.close(fd);
            throw new Exception("Unable to open CTL_FD");
              }

              ifreq2 ifr2 = new ifreq2();
              ifr2.ifrn_name = dev; // ioctl changed the name?
              if(ioctl(ctrl_fd, SIOCGIFHWADDR, ref ifr2) <0) {
            Console.WriteLine("Failed to get hw addr.");
            Syscall.close(ctrl_fd);
            throw new Exception("Failed to get hw addr.");
              }
              _addr =  MemBlock.Reference(ASCIIEncoding.UTF8.GetBytes(ifr2.ifr_hwaddr.sa_data));
        }
开发者ID:xujyan,项目名称:ipop,代码行数:34,代码来源:LinuxTap.cs


示例2: HandleData

 public void HandleData(MemBlock payload, ISender return_path, object state) {
   if(_sub != null) {
     MemBlock rest = null;
     PType.Parse(payload, out rest);
     _sub.Handle(rest, return_path);
   }
 }
开发者ID:johnynek,项目名称:brunet,代码行数:7,代码来源:RoutingDataHandler.cs


示例3: HandleData

    public void HandleData(MemBlock packet, ISender from, object node)
    {
      _message_count++;

      long stop_time, rt_ticks = -10000;

      if ( !from.Equals(node)) {
        if (packet[0] == 0) {
        //log.Debug("Echo Response:");
	  stop_time = System.DateTime.Now.Ticks;
	  int received_uid = NumberSerializer.ReadInt(packet, 1);
          if(uid_starttime.ContainsKey(received_uid)){
		rt_ticks = stop_time - (long)EchoTester.uid_starttime[received_uid];
	  }
	  double rt_ms = (double) rt_ticks/10000.0;
	  uid_brunetpingtime.Add(received_uid, rt_ms);
	  Console.WriteLine("Packet ID = {0}, Round-trip = {1}", received_uid, rt_ms); 	  
        }
        else {
        //log.Debug("Echo Request:");
        }

        //log.Debug(packet.ToString());

        //System.Console.WriteLine("{0}", packet.ToString());

        if (packet[0] > 0) {
          //Send a reply back, this is a request  
	  byte[] new_payload = new byte[ packet.Length ];
	  packet.CopyTo(new_payload, 0);
          new_payload[0] = (byte) 0;
          from.Send(new CopyList(PType.Protocol.Echo, MemBlock.Reference(new_payload)));
        }
      }
    }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:35,代码来源:EchoTester.cs


示例4: GetNetwork

        /// <summary> 
        /// Finds an available IP range on the system 
        /// </summary>
        /// <param name="networkdevice">Device to be ignored</param> 
        /// <param name="startip">Device to be ignored</param> 
        /// <returns>Return IP to use</returns> 
        public static MemBlock GetNetwork(string networkdevice, MemBlock startip)
        {
            IPAddresses ipaddrs = IPAddresses.GetIPAddresses();
              ArrayList used_networks = new ArrayList();
              MemBlock netip = startip;

              foreach (Hashtable ht in ipaddrs.AllInterfaces) {
            if (ht["inet addr"] != null && ht["Mask"] != null
            && (string)ht["interface"] != networkdevice) {
              MemBlock addr = MemBlock.Reference(Utils.StringToBytes((string) ht["inet addr"], '.'));
              MemBlock mask = MemBlock.Reference(Utils.StringToBytes((string) ht["Mask"], '.'));

              byte[] tmp = new byte[addr.Length];
              for(int i = 0; i < addr.Length; i++) {
            tmp[i] = (byte)(addr[i] & mask[i]);
              }
              used_networks.Add(MemBlock.Reference(tmp));
            }
              }

              while(used_networks.Contains(netip)) {
            byte[] tmp = new byte[netip.Length];
            netip.CopyTo(tmp, 0);
            if (tmp[1] == 0) {
              throw new Exception("Out of Addresses!");
            }
            tmp[1] -= 1;
            netip = MemBlock.Reference(tmp);
              }
              return netip;
        }
开发者ID:kyungyonglee,项目名称:ipop,代码行数:37,代码来源:RpcNodeHelper.cs


示例5: EthernetPacket

 static EthernetPacket()
 {
     Random _rand = new Random();
       byte[] unicast = new byte[6];
       _rand.NextBytes(unicast);
       unicast[0] = 0xFE;
       UnicastAddress = MemBlock.Reference(unicast);
 }
开发者ID:arjunprakash84,项目名称:ipop,代码行数:8,代码来源:Ethernet.cs


示例6: SecurityControlMessage

 static SecurityControlMessage()
 {
   byte[] empty_cookie = new byte[CookieLength];
   for(int i = 0; i < CookieLength; i++) {
     empty_cookie[i] = 0;
   }
   EmptyCookie = MemBlock.Reference(empty_cookie);
 }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:8,代码来源:SecurityControlMessage.cs


示例7: HandleData

 public void HandleData(MemBlock payload, ISender return_path, object state) {
   _last_received = payload;
   _ht[payload] = return_path;
   _order.Add(payload);
   if(HandleDataCallback != null) {
     HandleDataCallback(payload, null);
   }
 }
开发者ID:xujyan,项目名称:brunet,代码行数:8,代码来源:MockDataHandler.cs


示例8: AHAddress

 public AHAddress(MemBlock mb) : base(mb)
 {
   if (ClassOf(_buffer) != this.Class) {
     throw new System.
     ArgumentException("Class of address is not my class:  ",
                       this.ToString());
   }
 }
开发者ID:xujyan,项目名称:brunet,代码行数:8,代码来源:AHAddress.cs


示例9: ReadInt

 //Too bad we can't use a template here, .Net generics *may* do the job
 public static int ReadInt(MemBlock mb, int offset)
 {
   int val = 0;
   for(int i = 0; i < 4; i++) {
     val = (val << 8) | mb[i + offset];
   }
   return val;
 }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:9,代码来源:NumberSerializer.cs


示例10: Address

 /**
  * Create an address from a MemBlock
  */
 protected Address(MemBlock mb)
 {
   _buffer = mb;
   if (ClassOf(_buffer) != this.Class) {
     throw new System.
     ArgumentException("Class of address is not my class:  ",
                       this.ToString());
   }
 }
开发者ID:kyungyonglee,项目名称:BrunetTutorial,代码行数:12,代码来源:Address.cs


示例11: AHAddress

 public AHAddress(MemBlock mb) : base(mb)
 {
   if (ClassOf(_buffer) != this.Class) {
     throw new System.
     ArgumentException("Class of address is not my class:  ",
                       this.ToString());
   }
   _prefix = (uint)NumberSerializer.ReadInt(_buffer, 0);
 }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:9,代码来源:AHAddress.cs


示例12: DataPacket

    public DataPacket(ICopyable packet) {
      _update_icpacket = false;
      _update_packet = false;

      _icpacket = packet;
      _packet = packet as MemBlock;
      if(_packet == null) {
        _update_packet = true;
      }
    }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:10,代码来源:DataPacket.cs


示例13: HandleData

 /**
  * This handles the packet forwarding protocol
  */
 public void HandleData(MemBlock b, ISender ret_path, object state)
 {
   /*
    * Check it
    */
   AHSender ahs = ret_path as AHSender;
   if( ahs != null ) {
     //This was an AHSender:
     /*
      * This goes A -> B -> C
      */
     if( b[0] == 0 ) {
       int offset = 1;
       //This is the first leg, going from A->B
       Address add_c = AddressParser.Parse(b.Slice(offset, Address.MemSize));
       offset += Address.MemSize;
       //Since ahs a sender to return, we would be the source:
       Address add_a = ahs.Destination;
       short ttl = NumberSerializer.ReadShort(b, offset);//2 bytes
       offset += 2;
       ushort options = (ushort) NumberSerializer.ReadShort(b, offset);//2 bytes
       offset += 2;
       MemBlock payload = b.Slice(offset);
       MemBlock f_header = MemBlock.Reference( new byte[]{1} );
       /*
        * switch the packet from [A B f0 C] to [B C f 1 A]
        */
       ICopyable new_payload = new CopyList(PType.Protocol.Forwarding,
                                        f_header, add_a, payload);
       /*
        * ttl and options are present in the forwarding header.
        */
       AHSender next = new AHSender(_n, ahs.ReceivedFrom, add_c,
                                    ttl,
                                    options); 
       next.Send(new_payload);
     }
     else if ( b[0] == 1 ) {
       /*
        * This is the second leg: B->C
        * Make a Forwarding Sender, and unwrap the inside packet
        */
       Address add_a = AddressParser.Parse(b.Slice(1, Address.MemSize));
       Address add_b = ahs.Destination;
       MemBlock rest_of_payload = b.Slice(1 + Address.MemSize);
       //Here's the return path:
       ISender new_ret_path = new ForwardingSender(_n, add_b, add_a);
       _n.HandleData(rest_of_payload, new_ret_path, this);
     }
   }
   else {
     //This is not (currently) supported.
     Console.Error.WriteLine("Got a forwarding request from: {0}", ret_path);
   }
 }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:58,代码来源:PacketForwarder.cs


示例14: Verify

    public static void Verify(MemBlock p, ISender from, object state) {
      lock(_class_lock) {
	//
	// Make sure that the packet equals my state.
	//
	if (!p.Equals(state)) {
	  _wrongly_routed++;
	}
	_received++;
      }
    }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:11,代码来源:RoutingTester-1.cs


示例15: HandleData

 public void HandleData(MemBlock p, ISender edge, object state)
 {
   try {
     int num = NumberSerializer.ReadInt(p, 0);
     Console.WriteLine("Got packet number: {0}", num);
     edge.Send( p );
   }
   catch(Exception x) {
     Console.WriteLine("Server got exception on send: {0}", x);
   }
 }
开发者ID:twchoi,项目名称:tmp-brunet-deetoo,代码行数:11,代码来源:EdgeTester.cs


示例16: TextTranslate

 /// <summary>
 /// This method replaces IP addresses based on some identifier
 /// </summary>
 /// <param name="payload">Payload to be translated</param>
 /// <param name="old_ss_ip">Old source IP address</param>
 /// <param name="old_sd_ip">Old destination IP</param>
 /// <param name="new_ss_ip">New source IP address</param>
 /// <param name="new_sd_ip">New destination IP address</param>
 /// <param name="packet_id">A packet identifier</param>
 /// <returns>A MemBlock of the translated payload</returns>
 public static MemBlock TextTranslate(MemBlock payload, string old_ss_ip,
                                  string old_sd_ip, string new_ss_ip,
                                  string new_sd_ip, string packet_id)
 {
     string sdata = payload.GetString(System.Text.Encoding.UTF8);
       if(sdata.Contains(packet_id)) {
     sdata = sdata.Replace(old_ss_ip, new_ss_ip);
     sdata = sdata.Replace(old_sd_ip, new_sd_ip);
     payload = MemBlock.Reference(System.Text.Encoding.UTF8.GetBytes(sdata));
       }
       return payload;
 }
开发者ID:arjunprakash84,项目名称:ipop,代码行数:22,代码来源:ManagedNodeHelper.cs


示例17: DNS

 /// <summary>Default constructor</summary>
 /// <param name="ip_address">An IP Address in the range.</param>
 /// <param name="netmask">The netmask for the range.</param>
 public DNS(MemBlock ip_address, MemBlock netmask)
 {
     _sync = new object();
       byte[] ba = new byte[ip_address.Length];
       for(int i = 0; i < ip_address.Length; i++) {
     ba[i] = (byte) (ip_address[i] & netmask[i]);
       }
       lock(_sync) {
     _base_address = MemBlock.Reference(ba);
     _netmask = netmask;
       }
       _active = true;
 }
开发者ID:kyungyonglee,项目名称:ipop,代码行数:16,代码来源:DNS.cs


示例18: GetFragsInBulk

        /// <summary>
        /// Does bulk Brunet DHT gets by calling the bulk DHT operation API of its 
        /// XML-RPC interface.
        /// </summary>
        /// <returns>Null if not all the pieces are successfully retrieved and parsed.</returns>
        /// <exception cref="Exception">Parsing errors.</exception>
        private MemBlock GetFragsInBulk(byte[] base_key, int piece_num,
            out int largest_age, out int smallest_ttl)
        {
            largest_age = 0;
              smallest_ttl = Int32.MaxValue;
              MemBlock fragments = new MemBlock();

              byte[][] keys = new byte[piece_num][];
              for (int i = 0; i < piece_num; i++) {
            byte[] piece_key = BuildFragmentKey(base_key, i);
            keys[i] = piece_key;
              }

              DhtGetResult[] dgrs = _dht.BulkGet(keys);
              for (int i = 0; i < dgrs.Length; i++) {
            DhtGetResult dgr = dgrs[i];
            if (dgr == null) {
              Logger.WriteLineIf(LogLevel.Error, _log_props,
            string.Format("Piece #{0} is null. Retrying...", i));
              dgr = GetWithRetries(keys[i], 2);
              if (dgr == null) {
            Logger.WriteLineIf(LogLevel.Error, _log_props,
              string.Format("Piece #{0} is null after retries. Skipping " +
              "further parsing and returning...", i));
            return null;
              }
            }
            FingerprintedData fpd;
            try {
              fpd =
            (FingerprintedData)DictionaryData.CreateDictionaryData(dgr.value);
            } catch (Exception ex) {
              Logger.WriteLineIf(LogLevel.Error, _log_props,
              ex);
              throw ex;
            }
            Logger.WriteLineIf(LogLevel.Verbose, _log_props,
            string.Format("Piece #{0} retrieved and successfully parsed", i));
            RegularData rd = fpd.InnerData as RegularData;
            fragments = MemBlock.Concat(fragments, MemBlock.Reference(rd.PayLoad));
            if (smallest_ttl > dgr.ttl)
              smallest_ttl = dgr.ttl;
            if (largest_age < dgr.age)
              largest_age = dgr.age;
            //Now it's safe to say, this attempt succeeded.
              }

              return fragments;
        }
开发者ID:xujyan,项目名称:hurricane,代码行数:55,代码来源:BrunetDht.Bulk.cs


示例19: HandleData

 public void HandleData(MemBlock b, ISender from, object state) {
   MemBlock payload = null;
   PType t = null;
   try {
     t = PType.Parse(b, out payload);
     if(t.Equals(PType.Protocol.ReqRep)) {
       _rrm.HandleData(payload, from, state);
     }
     else if(t.Equals(PType.Protocol.Rpc)) {
       Rpc.HandleData(payload, from, state);
     }
   }
   catch(Exception x) {
     Console.Error.WriteLine("Packet Handling Exception: {3}\n\tType: {0}\n\t\n\tFrom: {1}\n\tData: {2}",
       t, from, payload.GetString(System.Text.Encoding.ASCII), x);
   }
 }
开发者ID:xujyan,项目名称:brunet,代码行数:17,代码来源:BrunetRpc.cs


示例20: ARPPacket

 public ARPPacket(MemBlock Packet)
 {
     _icpacket = _packet = Packet;
       HardwareType = NumberSerializer.ReadShort(Packet, 0);
       ProtocolType = NumberSerializer.ReadShort(Packet, 2);
       int hw_len = Packet[4];
       int proto_len = Packet[5];
       Operation = (Operations) NumberSerializer.ReadShort(Packet, 6);
       int pos = 8;
       SenderHWAddress = MemBlock.Reference(Packet, pos, hw_len);
       pos += hw_len;
       SenderProtoAddress = MemBlock.Reference(Packet, pos, proto_len);
       pos += proto_len;
       TargetHWAddress = MemBlock.Reference(Packet, pos, hw_len);
       pos += hw_len;
       TargetProtoAddress = MemBlock.Reference(Packet, pos, proto_len);
 }
开发者ID:kyungyonglee,项目名称:ipop,代码行数:17,代码来源:ARP.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Brunet.Node类代码示例发布时间:2022-05-24
下一篇:
C# Brunet.Address类代码示例发布时间: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