Add announce --event flag
This commit is contained in:
parent
17058f76f7
commit
bf5a22f345
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
package udp
|
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
package server
|
Loading…
Reference in New Issue