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


C# Util.MemBlock类代码示例

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


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

示例1: UserRevocationMessage

    /// <summary>Parse a revocation message.</summary>
    public UserRevocationMessage(Certificate cacert, MemBlock data)
    {
      _data = data;

      int pos = 0;
      int length = 0;

      Username = AdrConverter.Deserialize(data, pos, out length) as string;
      pos += length;
      // Random number to reduce likelihood of malicious duplication of messages
      NumberSerializer.ReadInt(data, pos);
      pos += 4;
      // Verify that there is a date contained therein, perhaps we should verify the time
      new DateTime(NumberSerializer.ReadLong(data, pos));
      pos += 8;
      Signature = new byte[data.Length - pos];
      data.Slice(pos).CopyTo(Signature, 0);

      // hash the data
      SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
      Hash = sha1.ComputeHash(data, 0, data.Length - Signature.Length);

      if(!cacert.PublicKey.VerifyHash(Hash,
            CryptoConfig.MapNameToOID("SHA1"), Signature))
      {
        throw new Exception("Invalid UserRevocationMessage signature");
      }
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:29,代码来源:UserRevocationMessage.cs

示例2: 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:johnynek,项目名称:brunet,代码行数:9,代码来源:NumberSerializer.cs

示例3: DhtGet

 public DhtGet(Node node, MemBlock key, EventHandler enqueue,
     EventHandler close) : base(close)
 {
   Node = node;
   Key = key;
   _enqueue = enqueue;
   Results = new Queue<MemBlock>();
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:8,代码来源:DhtGet.cs

示例4: HandleData

 public void HandleData(MemBlock b, ISender return_path, object state) {
   byte b0 = b[0];
   if( b0 == 0 ) {
     //This is a request:
     MemBlock data = b.Slice(1);
     //Make sure node to reply with a zero
     return_path.Send( new CopyList( PType.Protocol.Echo, REPLY_HEADER, data) );
   }
 }
开发者ID:johnynek,项目名称:brunet,代码行数:9,代码来源:EchoHandler.cs

示例5: DhtPut

 public DhtPut(Node node, MemBlock key, MemBlock value, int ttl,
     EventHandler finished) : base(finished)
 {
   Node = node;
   Key = key;
   Value = value;
   Ttl = ttl;
   _result = null;
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:9,代码来源:DhtPut.cs

示例6: HandleData

 override public void HandleData(MemBlock data, ISender return_path, object state)
 {
   SecurityAssociation sa = return_path as SecurityAssociation;
   if(sa == null) {
     ProtocolLog.WriteIf(ProtocolLog.Exceptions, String.Format(
           "Insecure sender {0} sent ptype {1}", return_path, _ptype));
     return;
   }
   base.HandleData(data, return_path, state);
 }
开发者ID:acisp2p,项目名称:brunet,代码行数:10,代码来源:SecureConnectionHandler.cs

示例7: Attribute

 /// <summary>Create a new Attribute.</summary>
 public Attribute(AttributeType type, MemBlock value)
 {
   Type = type;
   Value = value;
   byte[] data = new byte[4 + value.Length];
   NumberSerializer.WriteUShort((ushort) type, data, 0);
   NumberSerializer.WriteUShort((ushort) value.Length, data, 2);
   value.CopyTo(data, 4);
   Data = MemBlock.Reference(data);
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:11,代码来源:Stun.cs

示例8: 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:johnynek,项目名称:brunet,代码行数:58,代码来源:PacketForwarder.cs

示例9: DirectionalAddress

 public DirectionalAddress(MemBlock mb)
 {
   if (ClassOf(mb) != this.Class) {
     throw new System.
     ArgumentException
     ("This is not an AHAddress (Class 124) :  ",
      this.ToString());
   }
   _buffer = mb;
   _dir = (Direction) NumberSerializer.ReadInt(mb, 0);
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:11,代码来源:DirectionalAddress.cs

示例10: HandleData

 public void HandleData(MemBlock data, ISender return_path, object state)
 {
   MemBlock user_data;
   // Parse BroadcastSender
   BroadcastSender bs = BroadcastSender.Parse(Node, data, out user_data);
   // Present the packet to the local handler
   BroadcastReceiver br = new BroadcastReceiver(bs);
   Node.HandleData(user_data, br, null);
   // Broadcast to the next hop
   bs.Send(user_data);
 }
开发者ID:pstjuste,项目名称:brunet,代码行数:11,代码来源:BroadcastHandler.cs

示例11: ConnectionHandler

    public ConnectionHandler(PType ptype, StructuredNode node)
    {
      _node = node;
      _ondemand = new OnDemandConnectionOverlord(node);
      _node.AddConnectionOverlord(_ondemand);
      _ptype = ptype;
      _ptype_mb = ptype.ToMemBlock();
      _address_to_sender = new Dictionary<Address, ISender>();
      _sender_to_address = new Dictionary<ISender, Address>();

      node.GetTypeSource(_ptype).Subscribe(this, null);
      node.ConnectionTable.ConnectionEvent += HandleConnection;
      node.ConnectionTable.DisconnectionEvent += HandleDisconnection;
    }
开发者ID:acisp2p,项目名称:brunet,代码行数:14,代码来源:ConnectionHandler.cs

示例12: DhtDiscovery

    /// <summary>Uses the Dht for the bootstrap problem.</summary>
    /// <param name="node">The node needing remote tas.</param>
    /// <param name="dht">The dht for the shared overlay.</param>
    /// <param name="dht_proxy">A dht proxy for the shared overlay.</param>
    public DhtDiscovery(StructuredNode node, IDht dht, string shared_namespace,
        RpcDhtProxy dht_proxy) :
      base(node)
    {
      _dht = dht;
      _dht_proxy = dht_proxy;
      _node = node;
      _shared_namespace = shared_namespace;
      string skey = "PrivateOverlay:" + node.Realm;
      byte[] bkey = Encoding.UTF8.GetBytes(skey);
      _p2p_address = node.Address.ToMemBlock();
      _private_dht_key = MemBlock.Reference(bkey);

      _ongoing = 0;
      _steady_state = 0;
      _dht_proxy.Register(_private_dht_key, _p2p_address, PUT_DELAY_S);
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:21,代码来源:DhtDiscovery.cs

示例13: 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:johnynek,项目名称:brunet,代码行数:17,代码来源:BrunetRpc.cs

示例14: GroupGraph

    public GroupGraph(int count, int near, int shortcuts, int random_seed,
        List<List<int>> dataset, int group_count) :
      base(count, near, shortcuts, random_seed, dataset)
    {
      if(group_count > count || group_count < 0) {
        throw new Exception("Invalid group count: " + group_count);
      }

      _group_members = new List<GraphNode>();

      for(int i = 0; i < group_count; i++) {
        int index = _rand.Next(0, count);
        AHAddress addr = _addrs[index];
        _group_members.Add(_addr_to_node[addr]);
      }

      _group_identifier = GenerateAddress().ToMemBlock();
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:18,代码来源:Group.cs

示例15: HandleData

    /// <summary>Parses an incoming revocation and updates the revoked users
    /// hashtable if successful.</summary>
    public void HandleData(MemBlock data, ISender ret, object state)
    {
      UserRevocationMessage urm = null;
      try {
        urm = new UserRevocationMessage(_ca_cert, data);
      } catch(Exception e) {
        ProtocolLog.WriteIf(ProtocolLog.SecurityExceptions, e.ToString());
        return;
      }


      lock(_revoked_users) {
        if(_revoked_users.Contains(urm.Username)) {
          return;
        }
        _revoked_users[urm.Username] = true;
      }

      _so.VerifySAs();
    }
开发者ID:pstjuste,项目名称:brunet,代码行数:22,代码来源:BroadcastRevocationHandler.cs


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