From e554aa19a691615f349bf6dae0601706ea47dc03 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 16 Dec 2022 15:38:30 +1100 Subject: [PATCH] Add --port flag to announce --- cmd/torrent/announce.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/torrent/announce.go b/cmd/torrent/announce.go index 94500d96..f48dfd2a 100644 --- a/cmd/torrent/announce.go +++ b/cmd/torrent/announce.go @@ -12,19 +12,24 @@ import ( type AnnounceCmd struct { Event udp.AnnounceEvent + Port *uint16 Tracker string `arg:"positional"` InfoHash torrent.InfoHash `arg:"positional"` } func announceErr(flags AnnounceCmd) error { + req := tracker.AnnounceRequest{ + InfoHash: flags.InfoHash, + Port: uint16(torrent.NewDefaultClientConfig().ListenPort), + NumWant: -1, + Event: flags.Event, + } + if flags.Port != nil { + req.Port = *flags.Port + } response, err := tracker.Announce{ TrackerUrl: flags.Tracker, - Request: tracker.AnnounceRequest{ - InfoHash: flags.InfoHash, - Port: uint16(torrent.NewDefaultClientConfig().ListenPort), - NumWant: -1, - Event: flags.Event, - }, + Request: req, }.Do() if err != nil { return fmt.Errorf("doing announce: %w", err) -- 2.44.0