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
p2p
go-p2p-kad-dht
Commits
e223f19a
Commit
e223f19a
authored
Sep 22, 2014
by
Jeromy
Committed by
Juan Batiz-Benet
Oct 01, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
catch ipns branch up to master and make all things compile
parent
e38b2d89
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
10 deletions
+7
-10
dht.go
dht.go
+1
-0
routing.go
routing.go
+6
-10
No files found.
dht.go
View file @
e223f19a
...
...
@@ -345,6 +345,7 @@ func (dht *IpfsDHT) putLocal(key u.Key, value []byte) error {
// Update signals to all routingTables to Update their last-seen status
// on the given peer.
func
(
dht
*
IpfsDHT
)
Update
(
p
*
peer
.
Peer
)
{
u
.
DOut
(
"updating peer: [%s] latency = %f
\n
"
,
p
.
ID
.
Pretty
(),
p
.
GetLatency
()
.
Seconds
())
removedCount
:=
0
for
_
,
route
:=
range
dht
.
routingTables
{
removed
:=
route
.
Update
(
p
)
...
...
routing.go
View file @
e223f19a
...
...
@@ -17,7 +17,7 @@ import (
// PutValue adds value corresponding to given Key.
// This is the top level "Store" operation of the DHT
func
(
dht
*
IpfsDHT
)
PutValue
(
key
u
.
Key
,
value
[]
byte
)
error
{
func
(
dht
*
IpfsDHT
)
PutValue
(
ctx
context
.
Context
,
key
u
.
Key
,
value
[]
byte
)
error
{
err
:=
dht
.
putLocal
(
key
,
value
)
if
err
!=
nil
{
return
err
...
...
@@ -38,7 +38,7 @@ func (dht *IpfsDHT) PutValue(key u.Key, value []byte) error {
return
&
dhtQueryResult
{
success
:
true
},
nil
})
_
,
err
:
=
query
.
Run
(
ctx
,
peers
)
_
,
err
=
query
.
Run
(
ctx
,
peers
)
u
.
DOut
(
"[%s] PutValue %v %v
\n
"
,
dht
.
self
.
ID
.
Pretty
(),
key
,
value
)
return
err
}
...
...
@@ -104,8 +104,7 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key u.Key) error {
dht
.
providers
.
AddProvider
(
key
,
dht
.
self
)
peers
:=
dht
.
routingTables
[
0
]
.
NearestPeers
(
kb
.
ConvertKey
(
key
),
PoolSize
)
if
len
(
peers
)
==
0
{
// Early out for no targets
return
nil
return
kb
.
ErrLookupFailure
}
//TODO FIX: this doesn't work! it needs to be sent to the actual nearest peers.
...
...
@@ -156,12 +155,12 @@ func (dht *IpfsDHT) FindProvidersAsync2(ctx context.Context, key u.Key, count in
peers
:=
dht
.
routingTables
[
0
]
.
NearestPeers
(
kb
.
ConvertKey
(
key
),
AlphaValue
)
for
_
,
pp
:=
range
peers
{
go
func
(
p
*
peer
.
Peer
)
{
pmes
,
err
:=
dht
.
findProvidersSingle
(
p
,
key
,
0
,
timeout
)
pmes
,
err
:=
dht
.
findProvidersSingle
(
ctx
,
p
,
key
,
0
)
if
err
!=
nil
{
u
.
PErr
(
"%v
\n
"
,
err
)
return
}
dht
.
addPeerListAsync
(
key
,
pmes
.
GetPeers
(),
ps
,
count
,
peerOut
)
dht
.
addPeerListAsync
(
key
,
pmes
.
GetP
roviderP
eers
(),
ps
,
count
,
peerOut
)
}(
pp
)
}
...
...
@@ -190,11 +189,8 @@ func (dht *IpfsDHT) addPeerListAsync(k u.Key, peers []*Message_Peer, ps *peerSet
// FindProviders searches for peers who can provide the value for given key.
func
(
dht
*
IpfsDHT
)
FindProviders
(
ctx
context
.
Context
,
key
u
.
Key
)
([]
*
peer
.
Peer
,
error
)
{
ll
:=
startNewRPC
(
"FindProviders"
)
ll
.
EndAndPrint
()
// get closest peer
u
.
DOut
(
"Find providers for: '%s'
\n
"
,
key
)
u
.
DOut
(
"Find providers for: '%s'
\n
"
,
key
.
Pretty
()
)
p
:=
dht
.
routingTables
[
0
]
.
NearestPeer
(
kb
.
ConvertKey
(
key
))
if
p
==
nil
{
return
nil
,
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