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 ...@@ -4,6 +4,7 @@ package dht
import ( import (
"context" "context"
"fmt"
"net" "net"
"sync/atomic" "sync/atomic"
...@@ -38,11 +39,17 @@ type Announce struct { ...@@ -38,11 +39,17 @@ type Announce struct {
// being NATed. // being NATed.
announcePortImplied bool 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 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 { type pendingAnnouncePeer struct {
Addr Addr
token string token string
...@@ -270,6 +277,7 @@ func (a *Announce) beginQuery(addr Addr, reason string, f func() numWrites) stm. ...@@ -270,6 +277,7 @@ func (a *Announce) beginQuery(addr Addr, reason string, f func() numWrites) stm.
return func(tx *stm.Tx) interface{} { return func(tx *stm.Tx) interface{} {
tx.Set(a.pending, tx.Get(a.pending).(int)+1) tx.Set(a.pending, tx.Get(a.pending).(int)+1)
return a.server.beginQuery(addr, reason, func() numWrites { 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) })) defer stm.Atomically(stm.VoidOperation(func(tx *stm.Tx) { tx.Set(a.pending, tx.Get(a.pending).(int)-1) }))
return f() return f()
})(tx) })(tx)
......
...@@ -61,6 +61,7 @@ func mainErr() int { ...@@ -61,6 +61,7 @@ func mainErr() int {
} }
} }
} }
log.Printf("%v contacted %v nodes", a, a.NumContacted())
}(ih) }(ih)
} }
wg.Wait() wg.Wait()
......
package dht package dht
import ( import (
"encoding/hex"
"math" "math"
"math/big" "math/big"
) )
...@@ -9,6 +10,10 @@ type int160 struct { ...@@ -9,6 +10,10 @@ type int160 struct {
bits [20]uint8 bits [20]uint8
} }
func (me int160) String() string {
return hex.EncodeToString(me.bits[:])
}
func (me *int160) AsByteArray() [20]byte { func (me *int160) AsByteArray() [20]byte {
return me.bits return me.bits
} }
......
...@@ -702,7 +702,9 @@ func (s *Server) makeQueryBytes(q string, a *krpc.MsgArgs, t string) []byte { ...@@ -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) { 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) { 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()) }(time.Now())
replyChan := make(chan krpc.Msg, 1) replyChan := make(chan krpc.Msg, 1)
t := &Transaction{ 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