Inheritance: StandardWaveTunnelPacket
Beispiel #1
0
 public PeerInfo Wave(IPEndPoint facilitatorIp, int timeout, UdpClient udpClient)
 {
     long waitTime = timeout * 10000;
     _udpClient = udpClient;
     Logger.Debug("Waving at " + facilitatorIp + " from local port " + ((IPEndPoint)udpClient.Client.LocalEndPoint).Port + " for " + timeout + "ms");
     var packet = new StandardWaveTunnelRqPacket { internalEndPoint = new IPEndPoint(IPAddress.Any, ((IPEndPoint)udpClient.Client.LocalEndPoint).Port) };
     long startTime = DateTime.Now.Ticks;
     _waveEvent.Reset();
     // Setup a listener for a wave response
     InitReceiverWaveRs();
     do
     {
         byte[] sendBytes = packet.getBytes();
         udpClient.Send(sendBytes, sendBytes.Length, facilitatorIp);
         if (DateTime.Now.Ticks - startTime > waitTime)
         {
             Logger.Error("Wave timeout : " + (DateTime.Now.Ticks - startTime));
             //throw new TimeoutException("Timeout occured while waving");
             break;
         }
         Logger.Debug("Waiting for wave response from " + facilitatorIp + " to local port " + ((IPEndPoint)udpClient.Client.LocalEndPoint).Port);
     } while (!_waveEvent.WaitOne(2000));
     if(_waveResult == null)
     {
         _waveResult = new PeerInfo();
     }
     _waveResult.InternalEndPoints = GetLocalEndPoints(_udpClient);
     return _waveResult;
 }
 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;
 }