2
0
mirror of synced 2025-02-24 06:38:14 +00:00
torrent/webtorrent/tracker_protocol.go

46 lines
1.4 KiB
Go
Raw Normal View History

package webtorrent
import (
"github.com/pion/webrtc/v2"
)
type AnnounceRequest struct {
Numwant int `json:"numwant"`
Uploaded int `json:"uploaded"`
Downloaded int `json:"downloaded"`
Left int64 `json:"left"`
Event string `json:"event"`
Action string `json:"action"`
InfoHash string `json:"info_hash"`
PeerID string `json:"peer_id"`
Offers []Offer `json:"offers"`
}
type Offer struct {
OfferID string `json:"offer_id"`
Offer webrtc.SessionDescription `json:"offer"`
}
type AnnounceResponse struct {
InfoHash string `json:"info_hash"`
Action string `json:"action"`
Interval *int `json:"interval,omitempty"`
Complete *int `json:"complete,omitempty"`
Incomplete *int `json:"incomplete,omitempty"`
PeerID string `json:"peer_id,omitempty"`
ToPeerID string `json:"to_peer_id,omitempty"`
Answer *webrtc.SessionDescription `json:"answer,omitempty"`
Offer *webrtc.SessionDescription `json:"offer,omitempty"`
OfferID string `json:"offer_id,omitempty"`
}
// I wonder if this is a defacto standard way to decode bytes to JSON for webtorrent. I don't really
// care.
func binaryToJsonString(b []byte) string {
var seq []rune
for _, v := range b {
seq = append(seq, rune(v))
}
return string(seq)
}