Exemplo n.º 1
0
 internal void CommitAndEnqueueForSending(OutgoingMessage msg, DeliveryType deliveryType)
 {
     CommitAndEnqueueForSending(msg, deliveryType, 0);
 }
Exemplo n.º 2
0
        bool ProcessMessage(IAgNetChannel channel, IncomingMessage msg)
        {
            if (msg.Type == PacketType.ConfirmDelivery)
            {
                int confirmed = msg.ReadInt32();
                for (int i = 0; i < confirmed; i++)
                {
                    int             sequence    = msg.ReadInt32();
                    OutgoingMessage deliveryFor = reliableChannel.PopFromAwaitConfirmation(sequence);

                    if (deliveryFor == null)
                    {
                        continue;
                    }

                    deliveryFor.Status = AgNetSendStatus.Confirmed;

                    if (State == SessionState.Connecting && deliveryFor.Type == PacketType.ConnectAck)
                    {
                        SetState(SessionState.Connected);
                    }

                    if (State == SessionState.Closing && deliveryFor.Type == PacketType.FinResp)
                    {
                        Close("Shutdown method called");
                    }

                    deliveryFor.Dispose();
                }

                return(false);
            }

            if (msg.Type == PacketType.Ping)
            {
                Pong(msg);
                return(false);
            }

            if (msg.Type == PacketType.MTUExpandRequest)
            {
                ReceivedMtuExpand(msg);
                return(false);
            }

            if (msg.Type == PacketType.MTUSuccess)
            {
                ReceivedMtuResponse(msg);
                return(false);
            }

            if (msg.Type == PacketType.Pong)
            {
                lastPongReceived = DateTime.UtcNow;
                DateTime sent = new DateTime(msg.ReadInt64());
                TimeSpan ts   = DateTime.UtcNow - sent;
                PingRoundtrip = (int)ts.TotalMilliseconds;
                return(false);
            }

            if (msg.Type == PacketType.ConnectionError)
            {
                Close(msg.ReadString());
                return(false);
            }

            if (msg.Type == PacketType.FinAck)
            {
                SetState(SessionState.Closing);
                FinResp();
                return(false);
            }

            if (msg.Type == PacketType.FinResp)
            {
                Close("Connection closed by remote peer");
                return(false);
            }

            if (msg.Type == PacketType.ConnectAck && State == SessionState.Closed)
            {
                var server = peer as AgNetServer;
                if (server != null)
                {
                    if (server.MaximumSessions > 0 && server.SessionsCount >= server.MaximumSessions)
                    {
                        SendError("Server rejected connection");
                    }
                    else
                    {
                        SetState(SessionState.Connected);
                    }
                }
                return(false);
            }


            if (msg.Type == PacketType.Ping)
            {
                return(false);
            }

            if (msg.Type == PacketType.PartialMessage)
            {
                return(false);
            }

            if (State == SessionState.Connected && msg.Type == PacketType.UserData)
            {
                return(true);
            }

            Close("Unknown service packet");
            return(false);
        }
Exemplo n.º 3
0
 public void SendMessage(AgNetSession session, OutgoingMessage msg, DeliveryType deliveryType)
 {
     SendMessage(session, msg, deliveryType, 0);
 }
Exemplo n.º 4
0
        internal void FinResp()
        {
            OutgoingMessage finRespMessage = new OutgoingMessage(PacketType.FinResp);

            CommitAndEnqueueForSending(finRespMessage, DeliveryType.Reliable);
        }
Exemplo n.º 5
0
 public void SendMessage(OutgoingMessage msg, DeliveryType deliveryType)
 {
     SendMessage(msg, deliveryType, 0);
 }