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
bdd00c9d
Commit
bdd00c9d
authored
Mar 31, 2015
by
Jeromy Johnson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #986 from ipfs/feat/dht-bw-usage
reduce dht bandwidth consumption
parents
0f9082aa
ad432fe8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
7 deletions
+12
-7
handlers.go
handlers.go
+1
-1
records.go
records.go
+7
-2
routing.go
routing.go
+4
-4
No files found.
handlers.go
View file @
bdd00c9d
...
...
@@ -226,5 +226,5 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.M
dht
.
providers
.
AddProvider
(
ctx
,
key
,
p
)
}
return
pmes
,
nil
// send back same msg as confirmation.
return
nil
,
nil
}
records.go
View file @
bdd00c9d
...
...
@@ -31,6 +31,10 @@ func (dht *IpfsDHT) getPublicKeyOnline(ctx context.Context, p peer.ID) (ci.PubKe
ctxT
,
cancelFunc
:=
ctxutil
.
WithDeadlineFraction
(
ctx
,
0.3
)
defer
cancelFunc
()
if
pk
,
err
:=
dht
.
getPublicKeyFromNode
(
ctx
,
p
);
err
==
nil
{
err
:=
dht
.
peerstore
.
AddPubKey
(
p
,
pk
)
if
err
!=
nil
{
return
pk
,
err
}
return
pk
,
nil
}
...
...
@@ -38,7 +42,7 @@ func (dht *IpfsDHT) getPublicKeyOnline(ctx context.Context, p peer.ID) (ci.PubKe
log
.
Debugf
(
"pk for %s not in peerstore, and peer failed. trying dht."
,
p
)
pkkey
:=
KeyForPublicKey
(
p
)
// ok, try the
node itself. if they're overwhelmed or slow we can move on.
// ok,
now
try the
dht. Anyone who has previously fetched the key should have it
val
,
err
:=
dht
.
GetValue
(
ctxT
,
pkkey
)
if
err
!=
nil
{
log
.
Warning
(
"Failed to find requested public key."
)
...
...
@@ -50,7 +54,8 @@ func (dht *IpfsDHT) getPublicKeyOnline(ctx context.Context, p peer.ID) (ci.PubKe
log
.
Debugf
(
"Failed to unmarshal public key: %s"
,
err
)
return
nil
,
err
}
return
pk
,
nil
return
pk
,
dht
.
peerstore
.
AddPubKey
(
p
,
pk
)
}
func
(
dht
*
IpfsDHT
)
getPublicKeyFromNode
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
ci
.
PubKey
,
error
)
{
...
...
routing.go
View file @
bdd00c9d
...
...
@@ -91,7 +91,7 @@ func (dht *IpfsDHT) GetValue(ctx context.Context, key u.Key) ([]byte, error) {
}
// get closest peers in the routing table
rtp
:=
dht
.
routingTable
.
Li
stPeers
()
rtp
:=
dht
.
routingTable
.
Neare
stPeers
(
kb
.
ConvertKey
(
key
),
AlphaValue
)
log
.
Debugf
(
"peers in rt: %s"
,
len
(
rtp
),
rtp
)
if
len
(
rtp
)
==
0
{
log
.
Warning
(
"No peers from routing table!"
)
...
...
@@ -256,7 +256,7 @@ func (dht *IpfsDHT) findProvidersAsyncRoutine(ctx context.Context, key u.Key, co
return
&
dhtQueryResult
{
closerPeers
:
clpeers
},
nil
})
peers
:=
dht
.
routingTable
.
Li
stPeers
()
peers
:=
dht
.
routingTable
.
Neare
stPeers
(
kb
.
ConvertKey
(
key
),
AlphaValue
)
_
,
err
:=
query
.
Run
(
ctx
,
peers
)
if
err
!=
nil
{
log
.
Debugf
(
"Query error: %s"
,
err
)
...
...
@@ -276,7 +276,7 @@ func (dht *IpfsDHT) FindPeer(ctx context.Context, id peer.ID) (peer.PeerInfo, er
return
pi
,
nil
}
peers
:=
dht
.
routingTable
.
Li
stPeers
()
peers
:=
dht
.
routingTable
.
Neare
stPeers
(
kb
.
ConvertPeerID
(
id
),
AlphaValue
)
if
len
(
peers
)
==
0
{
return
peer
.
PeerInfo
{},
errors
.
Wrap
(
kb
.
ErrLookupFailure
)
}
...
...
@@ -342,7 +342,7 @@ func (dht *IpfsDHT) FindPeersConnectedToPeer(ctx context.Context, id peer.ID) (<
peerchan
:=
make
(
chan
peer
.
PeerInfo
,
asyncQueryBuffer
)
peersSeen
:=
peer
.
Set
{}
peers
:=
dht
.
routingTable
.
Li
stPeers
()
peers
:=
dht
.
routingTable
.
Neare
stPeers
(
kb
.
ConvertPeerID
(
id
),
AlphaValue
)
if
len
(
peers
)
==
0
{
return
nil
,
errors
.
Wrap
(
kb
.
ErrLookupFailure
)
}
...
...
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