Пример #1
0
        void Pong(IncomingMessage msg)
        {
            OutgoingMessage pongMessage = new OutgoingMessage(PacketType.Pong);

            pongMessage.Write(msg.ReadInt64());
            CommitAndEnqueueForSending(pongMessage, DeliveryType.Sequenced, msg.Channel);
        }
Пример #2
0
        public OutgoingMessage Clone()
        {
            OutgoingMessage result = new OutgoingMessage(this.Type);

            result.channel = channel;
            result.Write(this.GetBody());
            return(result);
        }
Пример #3
0
        internal void SendError(string text)
        {
            OutgoingMessage connectionError = new OutgoingMessage(PacketType.ConnectionError);

            connectionError.RemoteEP = ClientEndPoint;
            connectionError.Write(text);
            peer.SendMessageInternal(connectionError, DeliveryType.Unreliable);
        }
Пример #4
0
        void ReceivedMtuExpand(IncomingMessage msg)
        {
            OutgoingMessage mtuMessage = new OutgoingMessage(PacketType.MTUSuccess);

            mtuMessage.RemoteEP = ClientEndPoint;
            mtuMessage.Write((int)msg.BodyLength);
            peer.SendMessageInternal(mtuMessage, DeliveryType.Unreliable);
        }
Пример #5
0
        internal void ConnectAck(byte[] handShakeData)
        {
            OutgoingMessage connAckMessage = new OutgoingMessage(PacketType.ConnectAck);

            if (handShakeData != null)
            {
                connAckMessage.Write(handShakeData);
            }
            CommitAndEnqueueForSending(connAckMessage, DeliveryType.Reliable);
        }
Пример #6
0
        void TryMTUExpand()
        {
            if (mtuFinalized || !MTUExpandEnabled || State != SessionState.Connected)
            {
                return;
            }

            if ((DateTime.UtcNow - mtuSentTime).TotalMilliseconds < MtuExpandInterval)
            {
                return;
            }

            if (mtuTries <= 3)
            {
                int nextMtu = 0;
                if (smallestFailedMtu < 0)
                {
                    nextMtu = (int)(PayloadMTU * 1.2);
                }
                else
                {
                    nextMtu = (int)((PayloadMTU + smallestFailedMtu) / 2.0);
                    if (nextMtu == PayloadMTU)
                    {
                        System.Diagnostics.Debug.WriteLine("MTU finalized at " + PayloadMTU.ToString());
                        mtuFinalized = true;
                        return;
                    }
                }

                OutgoingMessage mtuMessage = new OutgoingMessage(PacketType.MTUExpandRequest);
                mtuMessage.DontFragment = true;
                mtuMessage.RemoteEP     = ClientEndPoint;
                mtuMessage.Write(new byte[nextMtu]);
                //System.Diagnostics.Debug.WriteLine("Expanding MTU up to " + nextMtu.ToString());
                if (!peer.SendMessageInternal(mtuMessage, DeliveryType.Unreliable))
                {
                    MtuFail(nextMtu);
                }
                else
                {
                    mtuSentTime = DateTime.UtcNow;
                    mtuTries++;
                    lastSentMtu = nextMtu;
                }
            }
            else
            {
                MtuFail(lastSentMtu);
            }
        }
Пример #7
0
        internal void Ping()
        {
            if (peer is AgNetServer && !(peer as AgNetServer).PingUsers)
            {
                return;
            }

            if ((DateTime.UtcNow - lastPingSent).TotalMilliseconds < pingInterval)
            {
                return;
            }

            OutgoingMessage pingMessage = new OutgoingMessage(PacketType.Ping);

            pingMessage.Channel = byte.MaxValue;
            pingMessage.Write(DateTime.UtcNow.Ticks);
            CommitAndEnqueueForSending(pingMessage, DeliveryType.Sequenced, byte.MaxValue);
            lastPingSent = DateTime.UtcNow;
        }