Add --port flag to announce

This commit is contained in:
Matt Joiner 2022-12-16 15:38:30 +11:00
parent 16c7621d9e
commit e554aa19a6
No known key found for this signature in database
GPG Key ID: 6B990B8185E7F782
1 changed files with 11 additions and 6 deletions

View File

@ -12,19 +12,24 @@ import (
type AnnounceCmd struct { type AnnounceCmd struct {
Event udp.AnnounceEvent Event udp.AnnounceEvent
Port *uint16
Tracker string `arg:"positional"` Tracker string `arg:"positional"`
InfoHash torrent.InfoHash `arg:"positional"` InfoHash torrent.InfoHash `arg:"positional"`
} }
func announceErr(flags AnnounceCmd) error { 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{ response, err := tracker.Announce{
TrackerUrl: flags.Tracker, TrackerUrl: flags.Tracker,
Request: tracker.AnnounceRequest{ Request: req,
InfoHash: flags.InfoHash,
Port: uint16(torrent.NewDefaultClientConfig().ListenPort),
NumWant: -1,
Event: flags.Event,
},
}.Do() }.Do()
if err != nil { if err != nil {
return fmt.Errorf("doing announce: %w", err) return fmt.Errorf("doing announce: %w", err)