Exemple #1
0
        public UDPHub(UDP UDP, UDPHubSettings Settings)
        {
            this._Settings = Settings;
            this._Peers = new Dictionary<IPEndPoint, UDPPeer>();
            this._ConnectionRequests = new Dictionary<IPEndPoint, _ConnectionRequest>();
            this._UDP = UDP;

            UDP.Received += new UDP.ReceiveRawPacketHandler(this._Receive);
        }
Exemple #2
0
        /// <summary>
        /// Called when an (unvalidated) packet is received for this peer.
        /// </summary>
        internal void _Receive(UDPHubSettings Settings, UDPHub Hub, Packet Packet, out bool Remove)
        {
            Remove = false;

            // Validate
            if (!this._Valid(Packet.SequenceNumber))
                return;

            // Disconnect?
            if (Packet.Disconnect)
            {
                Remove = true;
                return;
            }

            // Reset expire delay
            this._ExpireDelay = Settings.ExpireDelay;

            // Read additional information
            int ack;
            if (Packet.AcknowledgementNumber.TryGetValue(out ack))
            {
                this._OutTerminal.AcknowledgementNumber = ack;
            }
            double rtt;
            if (Packet.RoundTripTime.TryGetValue(out rtt))
            {
                this._RoundTripTime = rtt;
            }

            // Chunk?
            if (Packet.ChunkData != null)
            {
                this._Process(Packet.SequenceNumber, Packet.ChunkData, Packet.ChunkInitial, Packet.ChunkFinal);
            }

            // Ping?
            if (Packet.PingRequest)
            {
                this._SendPingResponse(Hub);
            }
        }
Exemple #3
0
 /// <summary>
 /// Initializes a peer with the local machine being the server of the connection.
 /// </summary>
 internal static UDPPeer _InitializeServer(
     UDPHubSettings Settings, IPEndPoint EndPoint, 
     int SequenceNumber, int AcknowledgementNumber)
 {
     return new UDPPeer(Settings, EndPoint, SequenceNumber, AcknowledgementNumber)
     {
         _RoundTripTime = Settings.InitialRoundTripTime,
         _KeepAliveDelay = Settings.KeepAliveDelay,
         _ExpireDelay = Settings.InitialExpireDelay,
         _WaveDelay = 0.0,
         _WaveSize = Settings.InitialWaveSize
     };
 }
Exemple #4
0
 /// <summary>
 /// Initializes a peer with the local machine being the client (initiator) of the connection.
 /// </summary>
 /// <param name="Time">The time it took to respond to the connection request.</param>
 internal static UDPPeer _InitializeClient(
     UDPHubSettings Settings, IPEndPoint EndPoint, 
     int SequenceNumber, int AcknowledgementNumber,
     double Time)
 {
     return new UDPPeer(Settings, EndPoint, SequenceNumber, AcknowledgementNumber)
     {
         _RoundTripTime = Time,
         _KeepAliveDelay = 0.0,
         _ExpireDelay = Settings.ExpireDelay,
         _WaveDelay = 0.0,
         _WaveSize = Settings.InitialWaveSize,
         _ShouldSendRoundTripTime = true
     };
 }
Exemple #5
0
 internal UDPPeer(UDPHubSettings Settings, IPEndPoint EndPoint, int SequenceNumber, int AcknowledgementNumber)
 {
     this._Settings = Settings;
     this._EndPoint = EndPoint;
     this._InTerminal = new InTerminal(AcknowledgementNumber);
     this._OutTerminal = new OutTerminal(SequenceNumber);
 }