Add announce --event flag

This commit is contained in:
Matt Joiner 2022-12-05 12:50:40 +11:00
parent 17058f76f7
commit bf5a22f345
No known key found for this signature in database
GPG Key ID: 6B990B8185E7F782
4 changed files with 19 additions and 1 deletions

View File

@ -7,9 +7,11 @@ import (
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/tracker"
"github.com/anacrolix/torrent/tracker/udp"
)
type AnnounceCmd struct {
Event udp.AnnounceEvent
Tracker string `arg:"positional"`
InfoHash torrent.InfoHash `arg:"positional"`
}
@ -21,6 +23,7 @@ func announceErr(flags AnnounceCmd) error {
InfoHash: flags.InfoHash,
Port: uint16(torrent.NewDefaultClientConfig().ListenPort),
NumWant: -1,
Event: flags.Event,
},
}.Do()
if err != nil {

View File

@ -0,0 +1 @@
package udp

View File

@ -2,6 +2,7 @@ package udp
import (
"encoding"
"fmt"
"github.com/anacrolix/dht/v2/krpc"
)
@ -24,9 +25,21 @@ type AnnounceRequest struct {
type AnnounceEvent int32
func (me *AnnounceEvent) UnmarshalText(text []byte) error {
for key, str := range announceEventStrings {
if string(text) == str {
*me = AnnounceEvent(key)
return nil
}
}
return fmt.Errorf("unknown event")
}
var announceEventStrings = []string{"", "completed", "started", "stopped"}
func (e AnnounceEvent) String() string {
// See BEP 3, "event", and https://github.com/anacrolix/torrent/issues/416#issuecomment-751427001.
return []string{"", "completed", "started", "stopped"}[e]
return announceEventStrings[e]
}
type AnnounceResponsePeers interface {

View File

@ -0,0 +1 @@
package server