Advertisement
smokex

sharelin onPacketPI

Sep 27th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. void PacketHandler::onPacketPI(const g2::Packet& pk, ip::Endpoint ep, ip::protocol::Type proto)
  2. {
  3.     verb2::g2 << "Got ping from " << ep << std::endl;
  4.     g2::Reader r(pk);
  5.    
  6.     bool bUdp = false;
  7.     bool bRelay = false;
  8.     ip::Endpoint to;
  9.    
  10.     while (r.next())
  11.     {
  12.         if(r.type() == g2::UDP)
  13.         {
  14.             g2::Reader rudp(r.child(), g2::Reader::payload);
  15.             to.address = rudp.pod<uint32>();
  16.             to.port = rudp.pod<uint16>();
  17.             if( !to.empty() )
  18.             {
  19.                 bUdp = true;
  20.             }
  21.         }
  22.         else if (r.type() == g2::RELAY)
  23.         {
  24.             bRelay = true;
  25.         }
  26.     }
  27.    
  28.     if(!bUdp && !bRelay)
  29.     {
  30.         // Direct Ping
  31.         g2::Packet po;
  32.         g2::Writer w(po);
  33.        
  34.         w.Begin( g2::PO );
  35.         w.Close( g2::PO );
  36.        
  37.         manager_.transceiver()->send(ep, po);
  38.     }
  39.    
  40.     if(bUdp && !bRelay)
  41.     {
  42.         // /PI/UDP
  43.         // TODO: Relay UDP pings if neighbour is G2 HUB
  44.     }
  45.    
  46.     if(bUdp && bRelay)
  47.     {
  48.         g2::Packet po;
  49.         g2::Writer w(po);
  50.        
  51.         w.Begin( g2::PO );
  52.             w.Begin( g2::RELAY );
  53.             w.Close( g2::RELAY );
  54.         w.Close( g2::PO );
  55.        
  56.         manager_.transceiver()->send(to, po);
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement