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
5617e89d
Commit
5617e89d
authored
Mar 30, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce dht bandwidth consumption
Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
809b09ef
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
7 deletions
+12
-7
dht/handlers.go
dht/handlers.go
+1
-1
dht/records.go
dht/records.go
+7
-2
dht/routing.go
dht/routing.go
+4
-4
No files found.
dht/handlers.go
View file @
5617e89d
...
...
@@ -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
}
dht/records.go
View file @
5617e89d
...
...
@@ -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
)
{
...
...
dht/routing.go
View file @
5617e89d
...
...
@@ -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