private void EnterStateListening() { CloseReason = ConnectionClosedReason.None; State = ConnectionState.Listening; if (BehaviorSet(ConnectionBehavior.GenerateOutgoingHandshakes)) { Connection.Enqueue(HandshakePayload.Generate(State, false)); } Behavior = ConnectionBehavior.HandleIncomingHandshakesOnly; }
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; }
private async Task SendHandshakeAsync() { var handshake = new HandshakePayload() { ProtocolVersion = Config.ProtocolVersion, User = new Protobuf.CommunicationProtocol.UserData() { Username = _userData.Login } }; await SendRequestAsync(handshake, OperationRequestCode.Handshake); }
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 }
private void EnqueueHandshake(bool ackRequired) { HandshakeSentMarker.Mark(); Connection.Enqueue(HandshakePayload.Generate(State, ackRequired)); }