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


C# Brunet.MemBlock类代码示例

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


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


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