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
Commits
8fb94daa
Commit
8fb94daa
authored
Feb 13, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #779 from jbenet/fix/dht
this might solve all our problems
parents
dee43a39
066ebda6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
19 deletions
+7
-19
routing/dht/handlers.go
routing/dht/handlers.go
+2
-19
routing/dht/providers.go
routing/dht/providers.go
+5
-0
No files found.
routing/dht/handlers.go
View file @
8fb94daa
...
...
@@ -3,7 +3,6 @@ package dht
import
(
"errors"
"fmt"
"time"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
...
...
@@ -63,9 +62,6 @@ func (dht *IpfsDHT) handleGetValue(ctx context.Context, p peer.ID, pmes *pb.Mess
return
nil
,
err
}
// Note: changed the behavior here to return _as much_ info as possible
// (potentially all of {value, closer peers, provider})
// if we have the value, send it back
if
err
==
nil
{
log
.
Debugf
(
"%s handleGetValue success!"
,
dht
.
self
)
...
...
@@ -85,18 +81,10 @@ func (dht *IpfsDHT) handleGetValue(ctx context.Context, p peer.ID, pmes *pb.Mess
resp
.
Record
=
rec
}
// if we know any providers for the requested value, return those.
provs
:=
dht
.
providers
.
GetProviders
(
ctx
,
u
.
Key
(
pmes
.
GetKey
()))
provinfos
:=
peer
.
PeerInfos
(
dht
.
peerstore
,
provs
)
if
len
(
provs
)
>
0
{
log
.
Debugf
(
"handleGetValue returning %d provider[s]"
,
len
(
provs
))
resp
.
ProviderPeers
=
pb
.
PeerInfosToPBPeers
(
dht
.
host
.
Network
(),
provinfos
)
}
// Find closest peer on given cluster to desired key and reply with that info
closer
:=
dht
.
betterPeersToQuery
(
pmes
,
p
,
CloserPeerCount
)
closerinfos
:=
peer
.
PeerInfos
(
dht
.
peerstore
,
closer
)
if
closer
!=
nil
{
closerinfos
:=
peer
.
PeerInfos
(
dht
.
peerstore
,
closer
)
for
_
,
pi
:=
range
closerinfos
{
log
.
Debugf
(
"handleGetValue returning closer peer: '%s'"
,
pi
.
ID
)
if
len
(
pi
.
Addrs
)
<
1
{
...
...
@@ -201,7 +189,7 @@ func (dht *IpfsDHT) handleGetProviders(ctx context.Context, p peer.ID, pmes *pb.
// Also send closer peers.
closer
:=
dht
.
betterPeersToQuery
(
pmes
,
p
,
CloserPeerCount
)
if
closer
!=
nil
{
infos
:=
peer
.
PeerInfos
(
dht
.
peerstore
,
provid
er
s
)
infos
:=
peer
.
PeerInfos
(
dht
.
peerstore
,
clos
er
)
resp
.
CloserPeers
=
pb
.
PeerInfosToPBPeers
(
dht
.
host
.
Network
(),
infos
)
log
.
Debugf
(
"%s have %d closer peers: %s"
,
reqDesc
,
len
(
closer
),
infos
)
}
...
...
@@ -209,11 +197,6 @@ func (dht *IpfsDHT) handleGetProviders(ctx context.Context, p peer.ID, pmes *pb.
return
resp
,
nil
}
type
providerInfo
struct
{
Creation
time
.
Time
Value
peer
.
ID
}
func
(
dht
*
IpfsDHT
)
handleAddProvider
(
ctx
context
.
Context
,
p
peer
.
ID
,
pmes
*
pb
.
Message
)
(
*
pb
.
Message
,
error
)
{
defer
log
.
EventBegin
(
ctx
,
"handleAddProvider"
,
p
)
.
Done
()
key
:=
u
.
Key
(
pmes
.
GetKey
())
...
...
routing/dht/providers.go
View file @
8fb94daa
...
...
@@ -10,6 +10,11 @@ import (
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
)
type
providerInfo
struct
{
Creation
time
.
Time
Value
peer
.
ID
}
type
ProviderManager
struct
{
providers
map
[
u
.
Key
][]
*
providerInfo
local
map
[
u
.
Key
]
struct
{}
...
...
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