Commit d40f9ecc authored by Matt Joiner's avatar Matt Joiner
Browse files

Improve some logging and comments

parent 8cfd0386
......@@ -4,6 +4,7 @@ package dht
import (
"context"
"fmt"
"net"
"sync/atomic"
......@@ -38,11 +39,17 @@ type Announce struct {
// being NATed.
announcePortImplied bool
pendingAnnouncePeers *stm.Var // List of pendingAnnouncePeer
// List of pendingAnnouncePeer. TODO: Perhaps this should be sorted by distance to the target,
// so we can do that sloppy hash stuff ;).
pendingAnnouncePeers *stm.Var
traversal traversal
}
func (a *Announce) String() string {
return fmt.Sprintf("%[1]T %[1]p of %v on %v", a, a.infoHash, a.server)
}
type pendingAnnouncePeer struct {
Addr
token string
......@@ -270,6 +277,7 @@ func (a *Announce) beginQuery(addr Addr, reason string, f func() numWrites) stm.
return func(tx *stm.Tx) interface{} {
tx.Set(a.pending, tx.Get(a.pending).(int)+1)
return a.server.beginQuery(addr, reason, func() numWrites {
a.server.logger().Printf("doing %s to %v", reason, addr)
defer stm.Atomically(stm.VoidOperation(func(tx *stm.Tx) { tx.Set(a.pending, tx.Get(a.pending).(int)-1) }))
return f()
})(tx)
......
......@@ -61,6 +61,7 @@ func mainErr() int {
}
}
}
log.Printf("%v contacted %v nodes", a, a.NumContacted())
}(ih)
}
wg.Wait()
......
package dht
import (
"encoding/hex"
"math"
"math/big"
)
......@@ -9,6 +10,10 @@ type int160 struct {
bits [20]uint8
}
func (me int160) String() string {
return hex.EncodeToString(me.bits[:])
}
func (me *int160) AsByteArray() [20]byte {
return me.bits
}
......
......@@ -702,7 +702,9 @@ func (s *Server) makeQueryBytes(q string, a *krpc.MsgArgs, t string) []byte {
func (s *Server) queryContext(ctx context.Context, addr Addr, q string, a *krpc.MsgArgs) (reply krpc.Msg, writes numWrites, err error) {
defer func(started time.Time) {
s.logger().WithValues(log.Debug).Printf("queryContext returned after %v (err=%v, reply.Y=%v, reply.E=%v)", time.Since(started), err, reply.Y, reply.E)
s.logger().WithValues(log.Debug, q).Printf(
"queryContext(%v) returned after %v (err=%v, reply.Y=%v, reply.E=%v, writes=%v)",
q, time.Since(started), err, reply.Y, reply.E, writes)
}(time.Now())
replyChan := make(chan krpc.Msg, 1)
t := &Transaction{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment