void RecvUnconnectedPacket(UdpBitStream buff, UdpEndPoint ep) { buff.Ptr = UdpHeader.GetSize(this); if (buff.ReadByte(8) == (byte)UdpCommandType.Connect) { if (Config.AllowIncommingConnections && ((connLookup.Count + pendingConnections.Count) < Config.ConnectionLimit || Config.ConnectionLimit == -1)) { if (Config.AutoAcceptIncommingConnections) { AcceptConnection(ep); } else { if (pendingConnections.Add(ep)) { Raise(UdpEvent.PUBLIC_CONNECT_REQUEST, ep); } } } else { SendRefusedCommand(ep); } } else { UdpLog.Debug("received invalid header byte in unconnected packet from {0}", ep.ToString()); } }
internal void ProcessConnectedTimeouts(uint now) { if ((recvTime + socket.Config.ConnectionTimeout) < now) { UdpLog.Debug("disconnecting due to timeout from {0}, last packet received: {1}, current time: {2}", endpoint.ToString(), recvTime.ToString(), now.ToString()); ChangeState(UdpConnectionState.Disconnected); } if (CheckState(UdpConnectionState.Connected)) { if (sendTime + socket.Config.PingTimeout < now || recvSinceLastSend >= socket.Config.RecvWithoutAckLimit) { SendCommand(UdpCommandType.Ping); } } }
void ConnectionError(UdpConnectionError error) { UdpLog.Debug("error '{0}' on connection to {1}", error.ToString(), endpoint.ToString()); switch (error) { case UdpConnectionError.SequenceOutOfBounds: ChangeState(UdpConnectionState.Disconnected); break; case UdpConnectionError.IncorrectCommand: ChangeState(UdpConnectionState.Disconnected); break; case UdpConnectionError.SendWindowFull: ChangeState(UdpConnectionState.Disconnected); break; } }
void OnEventSleep(UdpEvent ev) { UdpLog.Debug("sleeping network thread for {0} ms", ev.OptionIntValue); Thread.Sleep(ev.OptionIntValue); }