mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-27 15:31:32 +00:00
Set IP on the request object
This commit is contained in:
parent
75b4a20e56
commit
b1f186b665
5 changed files with 23 additions and 14 deletions
|
@ -19,7 +19,8 @@ type AnnounceRequest struct {
|
||||||
Event event.Event
|
Event event.Event
|
||||||
InfoHash InfoHash
|
InfoHash InfoHash
|
||||||
PeerID PeerID
|
PeerID PeerID
|
||||||
IP string
|
|
||||||
|
IPv4, IPv6 net.IP
|
||||||
Port uint16
|
Port uint16
|
||||||
|
|
||||||
Compact bool
|
Compact bool
|
||||||
|
|
|
@ -44,6 +44,8 @@ func init() {
|
||||||
eventToString[Stopped] = "stopped"
|
eventToString[Stopped] = "stopped"
|
||||||
eventToString[Completed] = "completed"
|
eventToString[Completed] = "completed"
|
||||||
|
|
||||||
|
stringToEvent[""] = None
|
||||||
|
|
||||||
for k, v := range eventToString {
|
for k, v := range eventToString {
|
||||||
stringToEvent[v] = k
|
stringToEvent[v] = k
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ func TestNew(t *testing.T) {
|
||||||
expected Event
|
expected Event
|
||||||
expectedErr error
|
expectedErr error
|
||||||
}{
|
}{
|
||||||
{"", None, ErrUnknownEvent},
|
{"", None, nil},
|
||||||
{"NONE", None, nil},
|
{"NONE", None, nil},
|
||||||
{"none", None, nil},
|
{"none", None, nil},
|
||||||
{"started", Started, nil},
|
{"started", Started, nil},
|
||||||
|
|
|
@ -31,10 +31,7 @@ func announceRequest(r *http.Request, cfg *httpConfig) (*chihaya.AnnounceRequest
|
||||||
return nil, errors.NewBadRequest("failed to provide valid client event")
|
return nil, errors.NewBadRequest("failed to provide valid client event")
|
||||||
}
|
}
|
||||||
|
|
||||||
compactStr, err := q.String("compact")
|
compactStr, _ := q.String("compact")
|
||||||
if err != nil {
|
|
||||||
return nil, errors.NewBadRequest("failed to parse parameter: compact")
|
|
||||||
}
|
|
||||||
request.Compact = compactStr != "0"
|
request.Compact = compactStr != "0"
|
||||||
|
|
||||||
infoHashes := q.InfoHashes()
|
infoHashes := q.InfoHashes()
|
||||||
|
@ -67,10 +64,7 @@ func announceRequest(r *http.Request, cfg *httpConfig) (*chihaya.AnnounceRequest
|
||||||
return nil, errors.NewBadRequest("failed to parse parameter: uploaded")
|
return nil, errors.NewBadRequest("failed to parse parameter: uploaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
request.NumWant, err = q.Uint64("numwant")
|
request.NumWant, _ = q.Uint64("numwant")
|
||||||
if err != nil {
|
|
||||||
return nil, errors.NewBadRequest("failed to parse parameter: numwant")
|
|
||||||
}
|
|
||||||
|
|
||||||
port, err := q.Uint64("port")
|
port, err := q.Uint64("port")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -78,6 +72,13 @@ func announceRequest(r *http.Request, cfg *httpConfig) (*chihaya.AnnounceRequest
|
||||||
}
|
}
|
||||||
request.Port = uint16(port)
|
request.Port = uint16(port)
|
||||||
|
|
||||||
|
v4, v6, err := requestedIP(q, r, cfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.NewBadRequest("failed to parse remote IP")
|
||||||
|
}
|
||||||
|
request.IPv4 = v4
|
||||||
|
request.IPv6 = v6
|
||||||
|
|
||||||
return request, nil
|
return request, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,8 +88,13 @@ func scrapeRequest(r *http.Request, cfg *httpConfig) (*chihaya.ScrapeRequest, er
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
infoHashes := q.InfoHashes()
|
||||||
|
if len(infoHashes) < 1 {
|
||||||
|
return nil, errors.NewBadRequest("no info_hash parameter supplied")
|
||||||
|
}
|
||||||
|
|
||||||
request := &chihaya.ScrapeRequest{
|
request := &chihaya.ScrapeRequest{
|
||||||
InfoHashes: q.InfoHashes(),
|
InfoHashes: infoHashes,
|
||||||
Params: q,
|
Params: q,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@ var peerStoreDrivers = make(map[string]PeerStoreDriver)
|
||||||
// PeerStore represents an interface for manipulating peers.
|
// PeerStore represents an interface for manipulating peers.
|
||||||
type PeerStore interface {
|
type PeerStore interface {
|
||||||
PutSeeder(infoHash chihaya.InfoHash, p chihaya.Peer) error
|
PutSeeder(infoHash chihaya.InfoHash, p chihaya.Peer) error
|
||||||
DeleteSeeder(infoHash chihaya.InfoHash, peerID chihaya.Peer) error
|
DeleteSeeder(infoHash chihaya.InfoHash, p chihaya.Peer) error
|
||||||
|
|
||||||
PutLeecher(infoHash chihaya.InfoHash, p chihaya.Peer) error
|
PutLeecher(infoHash chihaya.InfoHash, p chihaya.Peer) error
|
||||||
DeleteLeecher(infoHash chihaya.InfoHash, peerID chihaya.Peer) error
|
DeleteLeecher(infoHash chihaya.InfoHash, p chihaya.Peer) error
|
||||||
|
|
||||||
GraduateLeecher(infoHash chihaya.InfoHash, p chihaya.Peer) error
|
GraduateLeecher(infoHash chihaya.InfoHash, p chihaya.Peer) error
|
||||||
AnnouncePeers(infoHash chihaya.InfoHash, seeder bool, numWant int) (peers, peers6 []chihaya.Peer, err error)
|
AnnouncePeers(infoHash chihaya.InfoHash, seeder bool, numWant int) (peers, peers6 []chihaya.Peer, err error)
|
||||||
|
|
Loading…
Add table
Reference in a new issue