/// <inheritdoc/> public UdpActions DetectRequestType(ReadOnlySpan <byte> bytes) { if (bytes.Length < 8) { return(UdpActions.Unknown); } var protoOrConnectionId = _util.GetLong(bytes.Slice(0, 8)); if (protoOrConnectionId == UdpConstants.ProtocolId) { return(ValidateConnectRequest(bytes) ? UdpActions.Connect : UdpActions.Unknown); } if (bytes.Length < 12) { return(UdpActions.Unknown); } var action = _util.GetInt(bytes.Slice(8, 4)); switch (action) { case (int)UdpActions.Announce: return(ValidateAnnounceRequest(bytes) ? UdpActions.Announce : UdpActions.Unknown); case (int)UdpActions.Scrape: return(ValidateScrapeRequest(bytes) ? UdpActions.Scrape : UdpActions.Unknown); default: return(UdpActions.Unknown); } }
/// <inheritdoc/> public ConnectRequest DeserializeConnectRequest(ReadOnlySpan <byte> bytes) { if (_validator != null && !_validator.ValidateConnectRequest(bytes)) { throw new ArgumentException(MalformedFormat); } var tranId = _util.GetInt(bytes.Slice(12, 4)); return(new ConnectRequest(tranId)); }