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
f7a86f2f
Commit
f7a86f2f
authored
Feb 21, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add put and get dht commands to cli
parent
2af3b166
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
2 deletions
+18
-2
dht/dht.go
dht/dht.go
+1
-1
dht/handlers.go
dht/handlers.go
+1
-1
dht/routing.go
dht/routing.go
+16
-0
No files found.
dht/dht.go
View file @
f7a86f2f
...
...
@@ -322,7 +322,7 @@ func (dht *IpfsDHT) betterPeersToQuery(pmes *pb.Message, p peer.ID, count int) [
// == to self? thats bad
for
_
,
p
:=
range
closer
{
if
p
==
dht
.
self
{
log
.
Debug
(
"Attempted to return self! this shouldnt happen..."
)
log
.
Error
(
"Attempted to return self! this shouldnt happen..."
)
return
nil
}
}
...
...
dht/handlers.go
View file @
f7a86f2f
...
...
@@ -83,7 +83,7 @@ func (dht *IpfsDHT) handleGetValue(ctx context.Context, p peer.ID, pmes *pb.Mess
// Find closest peer on given cluster to desired key and reply with that info
closer
:=
dht
.
betterPeersToQuery
(
pmes
,
p
,
CloserPeerCount
)
if
closer
!=
nil
{
if
len
(
closer
)
>
0
{
closerinfos
:=
peer
.
PeerInfos
(
dht
.
peerstore
,
closer
)
for
_
,
pi
:=
range
closerinfos
{
log
.
Debugf
(
"handleGetValue returning closer peer: '%s'"
,
pi
.
ID
)
...
...
dht/routing.go
View file @
f7a86f2f
...
...
@@ -59,6 +59,11 @@ func (dht *IpfsDHT) PutValue(ctx context.Context, key u.Key, value []byte) error
wg
.
Add
(
1
)
go
func
(
p
peer
.
ID
)
{
defer
wg
.
Done
()
notif
.
PublishQueryEvent
(
ctx
,
&
notif
.
QueryEvent
{
Type
:
notif
.
Value
,
ID
:
p
,
})
err
:=
dht
.
putValueToPeer
(
ctx
,
p
,
key
,
rec
)
if
err
!=
nil
{
log
.
Debugf
(
"failed putting value to peer: %s"
,
err
)
...
...
@@ -92,6 +97,11 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
// setup the Query
query
:=
dht
.
newQuery
(
key
,
func
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
*
dhtQueryResult
,
error
)
{
notif
.
PublishQueryEvent
(
ctx
,
&
notif
.
QueryEvent
{
Type
:
notif
.
SendingQuery
,
ID
:
p
,
})
val
,
peers
,
err
:=
dht
.
getValueOrPeers
(
ctx
,
p
,
key
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -102,6 +112,12 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
res
.
success
=
true
}
notif
.
PublishQueryEvent
(
ctx
,
&
notif
.
QueryEvent
{
Type
:
notif
.
PeerResponse
,
ID
:
p
,
Responses
:
pointerizePeerInfos
(
peers
),
})
return
res
,
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