Exemplo n.º 1
0
 public void ProcessSyncRq(StandardSyncRqTunnelPacket packet)
 {
     lock (_syncRqLock)
     {
         Logger.Debug("Got a sync request for " + Id + " from " + packet.ip + ", last sync packet was from " + (_lastSyncRqPacketIp == null ? "nowhere" : _lastSyncRqPacketIp.ToString()));
         if (_lastSyncRqPacketIp == null || _lastSyncRqPacketIp.Equals(packet.ip))
         {
             if (_expectedPeer.EndPoints.Contains(packet.ip))
             {
                 _lastSyncRqPacketIp = packet.ip;
                 _syncRqEvent.Set();
                 StandardSyncRsTunnelPacket syncRs = new StandardSyncRsTunnelPacket();
                 byte[] syncBytes = syncRs.getBytes();
                 _udpClient.Send(syncBytes, syncBytes.Length, packet.ip);
             }
             else
             {
                 Logger.Error("Tunnel " + Id + ", got a sync request from an unexpected peer [" + packet.ip +
                              ", not " + _expectedPeer + "], dropping");
             }
         }
         else
         {
             Logger.Debug("Received a sync request packet for " + Id + " from " + packet.ip +
                          " after we have already received our first one from " + _lastSyncRqPacketIp +
                          ", ignoring");
         }
     }
 }
Exemplo n.º 2
0
 public BasicTunnelPacket getPacket(byte[] bytes, IPEndPoint ip)
 {
     BasicTunnelPacket packet;
     switch (bytes[BasicTunnelPacket.PKT_POS_TYPE])
     {
         case BasicTunnelPacket.PKT_TYPE_PING:
             packet = new StandardPingTunnelPacket();
             break;
         case BasicTunnelPacket.PKT_TYPE_PONG:
             packet = new StandardPongTunnelPacket();
             break;
         case BasicTunnelPacket.PKT_TYPE_SYNC_RS:
             packet = new StandardSyncRsTunnelPacket();
             break;
         case BasicTunnelPacket.PKT_TYPE_SYNC_RQ:
             packet = new StandardSyncRqTunnelPacket();
             break;
         case BasicTunnelPacket.PKT_TYPE_WAVE_RS:
             packet = new StandardWaveTunnelRsPacket();
             break;
         case BasicTunnelPacket.PKT_TYPE_WAVE_RQ:
             packet = new StandardWaveTunnelRqPacket();
             break;
         case BasicTunnelPacket.PKT_TYPE_DATA:
             packet = new StandardTunnelDataPacket();
             break;
         case BasicTunnelPacket.PKT_TYPE_NOP:
             packet = new StandardTunnelNopPacket();
             break;
         case BasicTunnelPacket.PKT_TYPE_CLOSE:
             packet = new StandardCloseTunnelPacket();
             break;
         default:
             throw new UnknownPacketException("Failed to determine packet type [" + bytes[BasicTunnelPacket.PKT_POS_TYPE] + "]");
     }
     packet.processPacket(bytes, ip);
     return packet;
 }
Exemplo n.º 3
0
 public void ProcessSyncRs(StandardSyncRsTunnelPacket packet)
 {
     lock (_syncRsLock)
     {
         Logger.Debug("Got a sync response for " + Id + " from " + packet.ip);
         if (_lastSyncPacketIp == null || _lastSyncPacketIp.Equals(packet.ip))
         {
             _lastSyncPacketIp = packet.ip;
             _syncEvent.Set();
         }
         else
         {
             Logger.Debug("Received a sync response packet for " + Id + " from " + packet.ip +
                          " after we have already received our first one from " + _lastSyncPacketIp +
                          ", ignoring");
         }
     }
 }