7 "github.com/pion/webrtc/v3"
10 type AnnounceRequest struct {
11 Numwant int `json:"numwant"`
12 Uploaded int64 `json:"uploaded"`
13 Downloaded int64 `json:"downloaded"`
14 Left int64 `json:"left"`
15 Event string `json:"event,omitempty"`
16 Action string `json:"action"`
17 InfoHash string `json:"info_hash"`
18 PeerID string `json:"peer_id"`
19 Offers []Offer `json:"offers"`
23 OfferID string `json:"offer_id"`
24 Offer webrtc.SessionDescription `json:"offer"`
27 type AnnounceResponse struct {
28 InfoHash string `json:"info_hash"`
29 Action string `json:"action"`
30 Interval *int `json:"interval,omitempty"`
31 Complete *int `json:"complete,omitempty"`
32 Incomplete *int `json:"incomplete,omitempty"`
33 PeerID string `json:"peer_id,omitempty"`
34 ToPeerID string `json:"to_peer_id,omitempty"`
35 Answer *webrtc.SessionDescription `json:"answer,omitempty"`
36 Offer *webrtc.SessionDescription `json:"offer,omitempty"`
37 OfferID string `json:"offer_id,omitempty"`
40 // I wonder if this is a defacto standard way to decode bytes to JSON for webtorrent. I don't really
42 func binaryToJsonString(b []byte) string {
45 seq = append(seq, rune(v))
50 func jsonStringToInfoHash(s string) (ih [20]byte, err error) {
56 panic(fmt.Sprintf("%q", s))
58 for i, c := range []rune(s) {
59 if c < 0 || c > math.MaxUint8 {
60 err = fmt.Errorf("bad infohash string: %v", s)