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
9f37aaa2
Commit
9f37aaa2
authored
Jun 11, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
a few small changes to make the dht more efficient
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
63b6db05
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
29 deletions
+23
-29
dht.go
dht.go
+0
-28
routing.go
routing.go
+23
-1
No files found.
dht.go
View file @
9f37aaa2
...
...
@@ -117,34 +117,6 @@ func (dht *IpfsDHT) putValueToPeer(ctx context.Context, p peer.ID,
return
nil
}
// putProvider sends a message to peer 'p' saying that the local node
// can provide the value of 'key'
func
(
dht
*
IpfsDHT
)
putProvider
(
ctx
context
.
Context
,
p
peer
.
ID
,
skey
string
)
error
{
// add self as the provider
pi
:=
pstore
.
PeerInfo
{
ID
:
dht
.
self
,
Addrs
:
dht
.
host
.
Addrs
(),
}
// // only share WAN-friendly addresses ??
// pi.Addrs = addrutil.WANShareableAddrs(pi.Addrs)
if
len
(
pi
.
Addrs
)
<
1
{
// log.Infof("%s putProvider: %s for %s error: no wan-friendly addresses", dht.self, p, key.Key(key), pi.Addrs)
return
fmt
.
Errorf
(
"no known addresses for self. cannot put provider."
)
}
pmes
:=
pb
.
NewMessage
(
pb
.
Message_ADD_PROVIDER
,
skey
,
0
)
pmes
.
ProviderPeers
=
pb
.
RawPeerInfosToPBPeers
([]
pstore
.
PeerInfo
{
pi
})
err
:=
dht
.
sendMessage
(
ctx
,
p
,
pmes
)
if
err
!=
nil
{
return
err
}
log
.
Debugf
(
"%s putProvider: %s for %s (%s)"
,
dht
.
self
,
p
,
key
.
Key
(
skey
),
pi
.
Addrs
)
return
nil
}
var
errInvalidRecord
=
errors
.
New
(
"received invalid record"
)
// getValueOrPeers queries a particular peer p for the value for
...
...
routing.go
View file @
9f37aaa2
...
...
@@ -2,6 +2,7 @@ package dht
import
(
"bytes"
"fmt"
"sync"
"time"
...
...
@@ -243,13 +244,18 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key key.Key) error {
return
err
}
mes
,
err
:=
dht
.
makeProvRecord
(
key
)
if
err
!=
nil
{
return
err
}
wg
:=
sync
.
WaitGroup
{}
for
p
:=
range
peers
{
wg
.
Add
(
1
)
go
func
(
p
peer
.
ID
)
{
defer
wg
.
Done
()
log
.
Debugf
(
"putProvider(%s, %s)"
,
key
,
p
)
err
:=
dht
.
putProvider
(
ctx
,
p
,
string
(
key
)
)
err
:=
dht
.
sendMessage
(
ctx
,
p
,
mes
)
if
err
!=
nil
{
log
.
Debug
(
err
)
}
...
...
@@ -258,6 +264,22 @@ func (dht *IpfsDHT) Provide(ctx context.Context, key key.Key) error {
wg
.
Wait
()
return
nil
}
func
(
dht
*
IpfsDHT
)
makeProvRecord
(
skey
key
.
Key
)
(
*
pb
.
Message
,
error
)
{
pi
:=
pstore
.
PeerInfo
{
ID
:
dht
.
self
,
Addrs
:
dht
.
host
.
Addrs
(),
}
// // only share WAN-friendly addresses ??
// pi.Addrs = addrutil.WANShareableAddrs(pi.Addrs)
if
len
(
pi
.
Addrs
)
<
1
{
return
nil
,
fmt
.
Errorf
(
"no known addresses for self. cannot put provider."
)
}
pmes
:=
pb
.
NewMessage
(
pb
.
Message_ADD_PROVIDER
,
string
(
skey
),
0
)
pmes
.
ProviderPeers
=
pb
.
RawPeerInfosToPBPeers
([]
pstore
.
PeerInfo
{
pi
})
return
pmes
,
nil
}
// FindProviders searches until the context expires.
func
(
dht
*
IpfsDHT
)
FindProviders
(
ctx
context
.
Context
,
key
key
.
Key
)
([]
pstore
.
PeerInfo
,
error
)
{
...
...
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