mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-31 11:33:06 -07:00
*: add structured logging
This commit is contained in:
@@ -6,6 +6,8 @@ package bittorrent
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
// PeerID represents a peer ID.
|
||||
@@ -24,6 +26,10 @@ func PeerIDFromBytes(b []byte) PeerID {
|
||||
return PeerID(buf)
|
||||
}
|
||||
|
||||
func (p PeerID) String() string {
|
||||
return string(p[:])
|
||||
}
|
||||
|
||||
// PeerIDFromString creates a PeerID from a string.
|
||||
//
|
||||
// It panics if s is not 20 bytes long.
|
||||
@@ -66,6 +72,10 @@ func InfoHashFromString(s string) InfoHash {
|
||||
return InfoHash(buf)
|
||||
}
|
||||
|
||||
func (i InfoHash) String() string {
|
||||
return string(i[:])
|
||||
}
|
||||
|
||||
// AnnounceRequest represents the parsed parameters from an announce request.
|
||||
type AnnounceRequest struct {
|
||||
Event Event
|
||||
@@ -92,6 +102,18 @@ type AnnounceResponse struct {
|
||||
IPv6Peers []Peer
|
||||
}
|
||||
|
||||
// LogFields renders the current response as a set of Logrus fields.
|
||||
func (ar 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,
|
||||
}
|
||||
}
|
||||
|
||||
// ScrapeRequest represents the parsed parameters from a scrape request.
|
||||
type ScrapeRequest struct {
|
||||
AddressFamily AddressFamily
|
||||
@@ -107,6 +129,13 @@ type ScrapeResponse struct {
|
||||
Files []Scrape
|
||||
}
|
||||
|
||||
// LogFields renders the current response as a set of Logrus fields.
|
||||
func (sr ScrapeResponse) LogFields() log.Fields {
|
||||
return log.Fields{
|
||||
"files": sr.Files,
|
||||
}
|
||||
}
|
||||
|
||||
// Scrape represents the state of a swarm that is returned in a scrape response.
|
||||
type Scrape struct {
|
||||
InfoHash InfoHash
|
||||
|
||||
Reference in New Issue
Block a user