Task <SocketError> SendDatagramAsync(Datagram datagram) { datagram.ConnectionKey = this.EndPoint.ConnectionKey; Statistics.PacketOut(); Statistics.BytesOut(datagram.GetTotalSize()); return(peer.SendDatagramAsync(this, datagram)); }
void OnMtuExpand(Datagram datagram) { if (!CheckStatus(datagram, UdpConnectionStatus.Connected)) { return; } int size = datagram.GetTotalSize(); byte fix = 0; if (size > peer.Configuration.LimitMtu) { size = peer.Configuration.LimitMtu; fix = 1; } logger.Debug($"MTU Successfully expanded to {size} by request from other side"); var mtuDatagram = CreateSpecialDatagram(MessageType.ExpandMTUSuccess, 5); using (WardenStreamWriter writer = new WardenStreamWriter(mtuDatagram.BaseStream, true)) { writer.WriteVarInt(size); writer.Write(fix); } if (size > this.Mtu) { this.Mtu = size; } _ = SendDatagramAsync(mtuDatagram); datagram.Dispose(); }
internal void OnDatagram(Datagram datagram) { if (datagram.ConnectionKey != this.EndPoint.ConnectionKey) { logger.Warn($"Got wrong {datagram}: connection id mismatch"); datagram.Dispose(); return; } Statistics.PacketIn(); Statistics.BytesIn(datagram.GetTotalSize()); switch (datagram.Type) { case MessageType.ConnectReq: OnConnectReq(datagram); break; case MessageType.ConnectResp: OnConnectResp(datagram); break; case MessageType.DisconnectReq: OnDisconnectReq(datagram); break; case MessageType.DisconnectResp: OnDisconnectResp(datagram); break; case MessageType.Ping: OnPing(datagram); break; case MessageType.Pong: OnPong(datagram); break; case MessageType.ExpandMTURequest: OnMtuExpand(datagram); break; case MessageType.ExpandMTUSuccess: OnMtuSuccess(datagram); break; case MessageType.DeliveryAck: OnAckReceived(datagram); break; default: OnDataReceived(datagram); break; } }