]> Sergey Matveev's repositories - btrtrc.git/blob - webtorrent/tracker_protocol.go
Tidy up the webtorrent package, remove buffer
[btrtrc.git] / webtorrent / tracker_protocol.go
1 package webtorrent
2
3 import (
4         "github.com/pion/webrtc/v2"
5 )
6
7 type AnnounceRequest struct {
8         Numwant    int     `json:"numwant"`
9         Uploaded   int     `json:"uploaded"`
10         Downloaded int     `json:"downloaded"`
11         Left       int64   `json:"left"`
12         Event      string  `json:"event"`
13         Action     string  `json:"action"`
14         InfoHash   string  `json:"info_hash"`
15         PeerID     string  `json:"peer_id"`
16         Offers     []Offer `json:"offers"`
17 }
18
19 type Offer struct {
20         OfferID string                    `json:"offer_id"`
21         Offer   webrtc.SessionDescription `json:"offer"`
22 }
23
24 type AnnounceResponse struct {
25         InfoHash   string                     `json:"info_hash"`
26         Action     string                     `json:"action"`
27         Interval   *int                       `json:"interval,omitempty"`
28         Complete   *int                       `json:"complete,omitempty"`
29         Incomplete *int                       `json:"incomplete,omitempty"`
30         PeerID     string                     `json:"peer_id,omitempty"`
31         ToPeerID   string                     `json:"to_peer_id,omitempty"`
32         Answer     *webrtc.SessionDescription `json:"answer,omitempty"`
33         Offer      *webrtc.SessionDescription `json:"offer,omitempty"`
34         OfferID    string                     `json:"offer_id,omitempty"`
35 }
36
37 // I wonder if this is a defacto standard way to decode bytes to JSON for webtorrent. I don't really
38 // care.
39 func binaryToJsonString(b []byte) string {
40         var seq []rune
41         for _, v := range b {
42                 seq = append(seq, rune(v))
43         }
44         return string(seq)
45 }