Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3-routing
Commits
da75b0f0
Commit
da75b0f0
authored
Feb 18, 2016
by
Richard Littauer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Capitalized DHT
License: MIT Signed-off-by:
Richard Littauer
<
richard.littauer@gmail.com
>
parent
52fd0b26
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
9 deletions
+9
-9
dht/dht_net.go
dht/dht_net.go
+2
-2
dht/dht_test.go
dht/dht_test.go
+2
-2
dht/handlers.go
dht/handlers.go
+1
-1
dht/records.go
dht/records.go
+4
-4
No files found.
dht/dht_net.go
View file @
da75b0f0
...
...
@@ -70,7 +70,7 @@ func (dht *IpfsDHT) handleNewMessage(s inet.Stream) {
// measure the RTT for latency measurements.
func
(
dht
*
IpfsDHT
)
sendRequest
(
ctx
context
.
Context
,
p
peer
.
ID
,
pmes
*
pb
.
Message
)
(
*
pb
.
Message
,
error
)
{
log
.
Debugf
(
"%s
dht
starting stream"
,
dht
.
self
)
log
.
Debugf
(
"%s
DHT
starting stream"
,
dht
.
self
)
s
,
err
:=
dht
.
host
.
NewStream
(
ctx
,
ProtocolDHT
,
p
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -108,7 +108,7 @@ func (dht *IpfsDHT) sendRequest(ctx context.Context, p peer.ID, pmes *pb.Message
// sendMessage sends out a message
func
(
dht
*
IpfsDHT
)
sendMessage
(
ctx
context
.
Context
,
p
peer
.
ID
,
pmes
*
pb
.
Message
)
error
{
log
.
Debugf
(
"%s
dht
starting stream"
,
dht
.
self
)
log
.
Debugf
(
"%s
DHT
starting stream"
,
dht
.
self
)
s
,
err
:=
dht
.
host
.
NewStream
(
ctx
,
ProtocolDHT
,
p
)
if
err
!=
nil
{
return
err
...
...
dht/dht_test.go
View file @
da75b0f0
...
...
@@ -93,7 +93,7 @@ func connect(t *testing.T, ctx context.Context, a, b *IpfsDHT) {
func
bootstrap
(
t
*
testing
.
T
,
ctx
context
.
Context
,
dhts
[]
*
IpfsDHT
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
log
.
Debugf
(
"
b
ootstrapping
dht
s..."
)
log
.
Debugf
(
"
B
ootstrapping
DHT
s..."
)
// tried async. sequential fares much better. compare:
// 100 async https://gist.github.com/jbenet/56d12f0578d5f34810b2
...
...
@@ -391,7 +391,7 @@ func TestPeriodicBootstrap(t *testing.T) {
connect
(
t
,
ctx
,
dhts
[
i
],
dhts
[(
i
+
1
)
%
len
(
dhts
)])
}
t
.
Logf
(
"
dht
s are now connected to 1-2 others."
,
nDHTs
)
t
.
Logf
(
"
DHT
s are now connected to 1-2 others."
,
nDHTs
)
for
_
,
dht
:=
range
dhts
{
rtlen
:=
dht
.
routingTable
.
Size
()
if
rtlen
>
2
{
...
...
dht/handlers.go
View file @
da75b0f0
...
...
@@ -106,7 +106,7 @@ func (dht *IpfsDHT) checkLocalDatastore(k key.Key) (*pb.Record, error) {
rec
:=
new
(
pb
.
Record
)
err
=
proto
.
Unmarshal
(
byts
,
rec
)
if
err
!=
nil
{
log
.
Debug
(
"Failed to unmarshal
dht
record from datastore"
)
log
.
Debug
(
"Failed to unmarshal
DHT
record from datastore
.
"
)
return
nil
,
err
}
...
...
dht/records.go
View file @
da75b0f0
...
...
@@ -42,7 +42,7 @@ func (dht *IpfsDHT) GetPublicKey(ctx context.Context, p peer.ID) (ci.PubKey, err
}
// last ditch effort: let's try the dht.
log
.
Debugf
(
"pk for %s not in peerstore, and peer failed.
t
rying
dht
."
,
p
)
log
.
Debugf
(
"pk for %s not in peerstore, and peer failed.
T
rying
DHT
."
,
p
)
pkkey
:=
routing
.
KeyForPublicKey
(
p
)
val
,
err
:=
dht
.
GetValue
(
ctxT
,
pkkey
)
...
...
@@ -77,14 +77,14 @@ func (dht *IpfsDHT) getPublicKeyFromNode(ctx context.Context, p peer.ID) (ci.Pub
// node doesn't have key :(
record
:=
pmes
.
GetRecord
()
if
record
==
nil
{
return
nil
,
fmt
.
Errorf
(
"
n
ode not responding with its public key: %s"
,
p
)
return
nil
,
fmt
.
Errorf
(
"
N
ode not responding with its public key: %s"
,
p
)
}
// Success! We were given the value. we don't need to check
// validity because a) we can't. b) we know the hash of the
// key we're looking for.
val
:=
record
.
GetValue
()
log
.
Debug
(
"
dht
got a value from other peer."
)
log
.
Debug
(
"
DHT
got a value from other peer."
)
pk
,
err
=
ci
.
UnmarshalPublicKey
(
val
)
if
err
!=
nil
{
...
...
@@ -100,7 +100,7 @@ func (dht *IpfsDHT) getPublicKeyFromNode(ctx context.Context, p peer.ID) (ci.Pub
}
// ok! it's valid. we got it!
log
.
Debugf
(
"
dht
got public key from node itself."
)
log
.
Debugf
(
"
DHT
got public key from node itself."
)
return
pk
,
nil
}
...
...
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