コード例 #1
0
 private void EnterStateListening()
 {
     CloseReason = ConnectionClosedReason.None;
     State       = ConnectionState.Listening;
     if (BehaviorSet(ConnectionBehavior.GenerateOutgoingHandshakes))
     {
         Connection.Enqueue(HandshakePayload.Generate(State, false));
     }
     Behavior = ConnectionBehavior.HandleIncomingHandshakesOnly;
 }
コード例 #2
0
 private void EnterStateClosed(ConnectionClosedReason reason)
 {
     CloseReason = reason;
     State       = ConnectionState.Closed;
     if (BehaviorSet(ConnectionBehavior.GenerateOutgoingHandshakes))
     {
         // If we have just come from a state where handshakes are required, then we should notify the endpoint that we are closing.
         Connection.Enqueue(HandshakePayload.Generate(State, false));
     }
     Behavior = ConnectionBehavior.None;
 }
コード例 #3
0
        private async Task SendHandshakeAsync()
        {
            var handshake = new HandshakePayload()
            {
                ProtocolVersion = Config.ProtocolVersion,
                User            = new Protobuf.CommunicationProtocol.UserData()
                {
                    Username = _userData.Login
                }
            };

            await SendRequestAsync(handshake, OperationRequestCode.Handshake);
        }
コード例 #4
0
        public NetworkConnection RecieveConnection()
        {
            if (IncomingConnections >= IncomingConnectionLimit)
            {
                // We cannot allocate any additional incoming connections. Just flush em.
                UnallocatedIncomingData.Clear();
                return(null);
            }

            FlushRecieve();

            UDPFeed feed = null;
            List <AddressedData> remainingIncoming = null;

            foreach (AddressedData incoming in UnallocatedIncomingData)
            {
                if (feed == null)
                {
                    byte[] data = incoming.Data;
                    if (Compression)
                    {
                        data = Compress.Enflate(data);
                    }

                    // Attempt to decode the packet.
                    if (data.Length < (Packet.HeaderSize + Payload.HeaderSize))
                    {
                        continue;
                    }

                    HandshakePayload req = Packet.Peek <HandshakePayload>(data);
                    if (req != null && req.State == NetworkClient.ConnectionState.Opening)
                    {
                        feed = OpenIncomingConnection(incoming.Source);
                        feed.FeedData(incoming.Data); // This data belongs to the new feed.

                        // We will start putting other packets in here for next round.
                        remainingIncoming = new List <AddressedData>();
                        break;
                    }
                }
                else
                {
                    if (!incoming.Source.Equals(feed.Destination))
                    {
                        // The remaining items should be added to the
                        remainingIncoming.Add(incoming);
                    }
                    else
                    {
                        feed.FeedData(incoming.Data);
                    }
                }
            }

            if (remainingIncoming != null)
            {
                UnallocatedIncomingData = remainingIncoming;
            }
            else
            {
                UnallocatedIncomingData.Clear();
            }

            return(feed); // This may be null
        }
コード例 #5
0
 private void EnqueueHandshake(bool ackRequired)
 {
     HandshakeSentMarker.Mark();
     Connection.Enqueue(HandshakePayload.Generate(State, ackRequired));
 }