示例#1
0
  /**
   * Here we handle routing AHPackets
   */
  public void HandleData(MemBlock data, ISender ret_path, object state) {
    /*
     * Unfortunately, the old code needs the full header intact, and
     * we have already eaten a byte of it, put it back:
     */
    MemBlock full_packet = data.ExtendHead(1);
    AHPacket p = new AHPacket(full_packet);
    //Route avoiding the edge we got the packet from:
    IRouter router = null;
    if( p.Destination.Class == 0 ) {
      router = _ah_router;
    }
    else {
      router = _d_router;
    }
    Edge edge_rec_from = ret_path as Edge;
    bool deliver_locally;
    router.Route(edge_rec_from, p, out deliver_locally);
    if( deliver_locally ) {
      //Send a response exactly back to the node that sent to us
      ISender resp_send = new AHSender(_n, ret_path, p.Source,
                                       _n.DefaultTTLFor(p.Source),
                                       AHPacket.AHOptions.Exact);
      //data:
      _n.HandleData( data.Slice(AHPacket.HeaderLength), resp_send, this); 
    }

  }