Send() public method

public Send ( ICopyable data ) : void
data ICopyable
return void
コード例 #1
0
 /*
  * Send a packet by forwarding it first.
  */
 public void Send(ICopyable d)
 {
     _sender.Send(new CopyList(_header, d));
 }
コード例 #2
0
        /**
         * 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);
            }
        }
コード例 #3
0
ファイル: PacketForwarder.cs プロジェクト: johnynek/brunet
 /**
  * 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);
   }
 }