void OnDisconnectReq(Datagram datagram) { if (!CheckStatus(datagram, UdpConnectionStatus.Connected)) { return; } SendDatagramAsync(CreateSpecialDatagram(MessageType.DisconnectResp)); CloseInternal(DisconnectReason.ClosedByOtherPeer, datagram.ConvertToMessage()); datagram.Dispose(); }
void IChannelConnection.ReleaseDatagram(Datagram datagram) { if (datagram.IsFragmented) { ManageFragment(datagram); } else { ReleaseMessage(datagram.ConvertToMessage(), datagram.DeliveryType, datagram.Channel); datagram.Dispose(); } }
void OnConnectReq(Datagram datagram) { switch (Status) { case UdpConnectionStatus.Connected: logger.Debug($"Got late {datagram.Type} resend connect resp"); SendDatagramAsync(CreateSpecialDatagram(MessageType.ConnectResp)); break; case UdpConnectionStatus.Waiting: var connectionAccepted = peer.OnAcceptConnection(new OnAcceptConnectionEventArgs(this.EndPoint.EndPoint, datagram.ConvertToMessage())); if (connectionAccepted) { logger.Debug($"Accepting connection {this}"); SendDatagramAsync(CreateSpecialDatagram(MessageType.ConnectResp)); ChangeStatus(UdpConnectionStatus.Connected); } else { logger.Debug($"Rejecting connection {this}"); SendDatagramAsync(CreateSpecialDatagram(MessageType.DisconnectResp)); ChangeStatus(UdpConnectionStatus.Disconnected); } break; case UdpConnectionStatus.Disconnected: logger.Debug($"Got late {datagram.Type}, but connection is closed. Resend disconnect resp"); SendDatagramAsync(CreateSpecialDatagram(MessageType.DisconnectResp)); break; default: logger.Debug($"Got {datagram.Type} in wrong connection status: {Status}. Dropping..."); break; } datagram.Dispose(); }