Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
x0x
dht
Commits
d40f9ecc
Commit
d40f9ecc
authored
Nov 06, 2019
by
Matt Joiner
Browse files
Improve some logging and comments
parent
8cfd0386
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
2 deletions
+18
-2
announce.go
announce.go
+9
-1
cmd/dht-announce/main.go
cmd/dht-announce/main.go
+1
-0
int160.go
int160.go
+5
-0
server.go
server.go
+3
-1
No files found.
announce.go
View file @
d40f9ecc
...
...
@@ -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
)
...
...
cmd/dht-announce/main.go
View file @
d40f9ecc
...
...
@@ -61,6 +61,7 @@ func mainErr() int {
}
}
}
log
.
Printf
(
"%v contacted %v nodes"
,
a
,
a
.
NumContacted
())
}(
ih
)
}
wg
.
Wait
()
...
...
int160.go
View file @
d40f9ecc
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
}
...
...
server.go
View file @
d40f9ecc
...
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment