From 330d23be222a9b042804fe196ff8f9f2f8d5b347 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 5 Dec 2022 12:51:29 +1100 Subject: [PATCH] Some tidying in tracker/udp --- tracker/udp/client.go | 2 +- tracker/udp/protocol.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tracker/udp/client.go b/tracker/udp/client.go index 0095a912..42f0d14e 100644 --- a/tracker/udp/client.go +++ b/tracker/udp/client.go @@ -125,7 +125,7 @@ func (cl *Client) requestWriter(ctx context.Context, action Action, body []byte, return } buf.Reset() - err = binary.Write(&buf, binary.BigEndian, RequestHeader{ + err = Write(&buf, RequestHeader{ ConnectionId: connId, Action: action, TransactionId: tId, diff --git a/tracker/udp/protocol.go b/tracker/udp/protocol.go index 4a8dc668..f6beb4c6 100644 --- a/tracker/udp/protocol.go +++ b/tracker/udp/protocol.go @@ -13,9 +13,11 @@ const ( ActionAnnounce ActionScrape ActionError +) - ConnectRequestConnectionId = 0x41727101980 +const ConnectRequestConnectionId = 0x41727101980 +const ( // BEP 41 optionTypeEndOfOptions = 0 optionTypeNOP = 1 @@ -57,7 +59,7 @@ type InfoHash = [20]byte func marshal(data interface{}) (b []byte, err error) { var buf bytes.Buffer - err = binary.Write(&buf, binary.BigEndian, data) + err = Write(&buf, data) b = buf.Bytes() return } @@ -70,6 +72,7 @@ func mustMarshal(data interface{}) []byte { return b } +// This is for fixed-size, builtin types only I think. func Write(w io.Writer, data interface{}) error { return binary.Write(w, binary.BigEndian, data) }