bittorrent: add String() and LogFields()
This commit is contained in:
parent
ce43a09956
commit
66e12c6684
1 changed files with 50 additions and 8 deletions
|
@ -93,6 +93,24 @@ type AnnounceRequest struct {
|
|||
Params
|
||||
}
|
||||
|
||||
// LogFields renders the current response as a set of log fields.
|
||||
func (r AnnounceRequest) LogFields() log.Fields {
|
||||
return log.Fields{
|
||||
"event": r.Event,
|
||||
"infoHash": r.InfoHash,
|
||||
"compact": r.Compact,
|
||||
"eventProvided": r.EventProvided,
|
||||
"numWantProvided": r.NumWantProvided,
|
||||
"ipProvided": r.IPProvided,
|
||||
"numWant": r.NumWant,
|
||||
"left": r.Left,
|
||||
"downloaded": r.Downloaded,
|
||||
"uploaded": r.Uploaded,
|
||||
"peer": r.Peer,
|
||||
"params": r.Params,
|
||||
}
|
||||
}
|
||||
|
||||
// AnnounceResponse represents the parameters used to create an announce
|
||||
// response.
|
||||
type AnnounceResponse struct {
|
||||
|
@ -105,15 +123,15 @@ type AnnounceResponse struct {
|
|||
IPv6Peers []Peer
|
||||
}
|
||||
|
||||
// LogFields renders the current response as a set of Logrus fields.
|
||||
func (ar AnnounceResponse) LogFields() log.Fields {
|
||||
// LogFields renders the current response as a set of log fields.
|
||||
func (r AnnounceResponse) LogFields() log.Fields {
|
||||
return log.Fields{
|
||||
"compact": ar.Compact,
|
||||
"complete": ar.Complete,
|
||||
"interval": ar.Interval,
|
||||
"minInterval": ar.MinInterval,
|
||||
"ipv4Peers": ar.IPv4Peers,
|
||||
"ipv6Peers": ar.IPv6Peers,
|
||||
"compact": r.Compact,
|
||||
"complete": r.Complete,
|
||||
"interval": r.Interval,
|
||||
"minInterval": r.MinInterval,
|
||||
"ipv4Peers": r.IPv4Peers,
|
||||
"ipv6Peers": r.IPv6Peers,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,6 +142,15 @@ type ScrapeRequest struct {
|
|||
Params Params
|
||||
}
|
||||
|
||||
// LogFields renders the current response as a set of log fields.
|
||||
func (r ScrapeRequest) LogFields() log.Fields {
|
||||
return log.Fields{
|
||||
"addressFamily": r.AddressFamily,
|
||||
"infoHashes": r.InfoHashes,
|
||||
"params": r.Params,
|
||||
}
|
||||
}
|
||||
|
||||
// ScrapeResponse represents the parameters used to create a scrape response.
|
||||
//
|
||||
// The Scrapes must be in the same order as the InfoHashes in the corresponding
|
||||
|
@ -150,6 +177,17 @@ type Scrape struct {
|
|||
// AddressFamily is the address family of an IP address.
|
||||
type AddressFamily uint8
|
||||
|
||||
func (af AddressFamily) String() string {
|
||||
switch af {
|
||||
case IPv4:
|
||||
return "IPv4"
|
||||
case IPv6:
|
||||
return "IPv6"
|
||||
default:
|
||||
panic("tried to print unknown AddressFamily")
|
||||
}
|
||||
}
|
||||
|
||||
// AddressFamily constants.
|
||||
const (
|
||||
IPv4 AddressFamily = iota
|
||||
|
@ -162,6 +200,10 @@ type IP struct {
|
|||
AddressFamily
|
||||
}
|
||||
|
||||
func (ip IP) String() string {
|
||||
return ip.IP.String()
|
||||
}
|
||||
|
||||
// Peer represents the connection details of a peer that is returned in an
|
||||
// announce response.
|
||||
type Peer struct {
|
||||
|
|
Loading…
Add table
Reference in a new issue