mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-01 14:28:58 -07:00
(minor) unify log keys
This commit is contained in:
+7
-7
@@ -140,7 +140,7 @@ type fetchArgs struct {
|
||||
|
||||
func (h *responseHook) appendPeers(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse) (err error) {
|
||||
seeding := req.Left == 0
|
||||
max := int(req.NumWant)
|
||||
maxPeers := int(req.NumWant)
|
||||
peers := make([]bittorrent.Peer, 0, len(resp.IPv4Peers)+len(resp.IPv6Peers))
|
||||
primaryIP := req.GetFirst()
|
||||
v6First := primaryIP.Is6()
|
||||
@@ -158,24 +158,24 @@ func (h *responseHook) appendPeers(ctx context.Context, req *bittorrent.Announce
|
||||
peers = append(peers, resp.IPv4Peers...)
|
||||
peers = append(peers, resp.IPv6Peers...)
|
||||
}
|
||||
if l := len(peers); l > max {
|
||||
peers, max = peers[:max], 0
|
||||
if l := len(peers); l > maxPeers {
|
||||
peers, maxPeers = peers[:maxPeers], 0
|
||||
} else {
|
||||
max -= l
|
||||
maxPeers -= l
|
||||
}
|
||||
|
||||
for _, a := range args {
|
||||
if max <= 0 {
|
||||
if maxPeers <= 0 {
|
||||
break
|
||||
}
|
||||
var storePeers []bittorrent.Peer
|
||||
storePeers, err = h.store.AnnouncePeers(ctx, a.ih, seeding, max, a.v6)
|
||||
storePeers, err = h.store.AnnouncePeers(ctx, a.ih, seeding, maxPeers, a.v6)
|
||||
if err != nil && !errors.Is(err, storage.ErrResourceDoesNotExist) {
|
||||
return err
|
||||
}
|
||||
err = nil
|
||||
peers = append(peers, storePeers...)
|
||||
max -= len(storePeers)
|
||||
maxPeers -= len(storePeers)
|
||||
}
|
||||
|
||||
// Some clients expect a minimum of their own peer representation returned to
|
||||
|
||||
@@ -82,6 +82,7 @@ func build(config conf.MapConfig, _ storage.PeerStorage) (h middleware.Hook, err
|
||||
cfg.Header = authorizationHeader
|
||||
logger.Warn().
|
||||
Str("name", "Header").
|
||||
Str("provided", "").
|
||||
Str("default", cfg.Header).
|
||||
Msg("falling back to default configuration")
|
||||
}
|
||||
@@ -149,7 +150,7 @@ func (h *hook) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceReque
|
||||
logger.Info().
|
||||
Stringer("claimInfoHash", claimIH).
|
||||
Stringer("requestInfoHash", req.InfoHash).
|
||||
Object("peer", req.RequestPeer).
|
||||
Object("source", req.RequestPeer).
|
||||
Msg("unequal 'infohash' claim when validating JWT")
|
||||
err = ErrInvalidJWT
|
||||
}
|
||||
@@ -220,7 +221,7 @@ func (h *hook) HandleScrape(ctx context.Context, req *bittorrent.ScrapeRequest,
|
||||
} else {
|
||||
logger.Info().
|
||||
Err(jwtErr).
|
||||
Array("source", &req.RequestAddresses).
|
||||
Array("addresses", &req.RequestAddresses).
|
||||
Msg("JWT validation failed")
|
||||
err = ErrInvalidJWT
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func NewHooks(configs []conf.NamedMapConfig, storage storage.PeerStorage) (hooks
|
||||
buildersMU.RLock()
|
||||
defer buildersMU.RUnlock()
|
||||
for _, c := range configs {
|
||||
logger.Debug().Object("hook", c).Msg("starting hook")
|
||||
logger.Debug().Str("name", c.Name).Object("hook", c).Msg("starting hook")
|
||||
newHook, ok := builders[c.Name]
|
||||
if !ok {
|
||||
err = fmt.Errorf("hook with name '%s' does not exists", c.Name)
|
||||
|
||||
Reference in New Issue
Block a user