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
3c95a274
Commit
3c95a274
authored
May 16, 2017
by
Jeromy Johnson
Committed by
GitHub
May 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #58 from libp2p/feat/no-broadcast-opt
update to use no-broadcast option
parents
f02c72d5
04ee593e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
7 deletions
+46
-7
dht_test.go
dht_test.go
+38
-3
package.json
package.json
+2
-2
routing.go
routing.go
+6
-2
No files found.
dht_test.go
View file @
3c95a274
...
...
@@ -216,7 +216,7 @@ func TestProvides(t *testing.T) {
for
_
,
k
:=
range
testCaseCids
{
log
.
Debugf
(
"announcing provider for %s"
,
k
)
if
err
:=
dhts
[
3
]
.
Provide
(
ctx
,
k
);
err
!=
nil
{
if
err
:=
dhts
[
3
]
.
Provide
(
ctx
,
k
,
true
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
...
...
@@ -247,6 +247,41 @@ func TestProvides(t *testing.T) {
}
}
func
TestLocalProvides
(
t
*
testing
.
T
)
{
// t.Skip("skipping test to debug another")
ctx
:=
context
.
Background
()
_
,
_
,
dhts
:=
setupDHTS
(
ctx
,
4
,
t
)
defer
func
()
{
for
i
:=
0
;
i
<
4
;
i
++
{
dhts
[
i
]
.
Close
()
defer
dhts
[
i
]
.
host
.
Close
()
}
}()
connect
(
t
,
ctx
,
dhts
[
0
],
dhts
[
1
])
connect
(
t
,
ctx
,
dhts
[
1
],
dhts
[
2
])
connect
(
t
,
ctx
,
dhts
[
1
],
dhts
[
3
])
for
_
,
k
:=
range
testCaseCids
{
log
.
Debugf
(
"announcing provider for %s"
,
k
)
if
err
:=
dhts
[
3
]
.
Provide
(
ctx
,
k
,
false
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
time
.
Sleep
(
time
.
Millisecond
*
10
)
for
_
,
c
:=
range
testCaseCids
{
for
i
:=
0
;
i
<
3
;
i
++
{
provs
:=
dhts
[
i
]
.
providers
.
GetProviders
(
ctx
,
c
)
if
len
(
provs
)
>
0
{
t
.
Fatal
(
"shouldnt know this"
)
}
}
}
}
// if minPeers or avgPeers is 0, dont test for it.
func
waitForWellFormedTables
(
t
*
testing
.
T
,
dhts
[]
*
IpfsDHT
,
minPeers
,
avgPeers
int
,
timeout
time
.
Duration
)
bool
{
// test "well-formed-ness" (>= minPeers peers in every routing table)
...
...
@@ -471,7 +506,7 @@ func TestProvidesMany(t *testing.T) {
providers
[
c
.
KeyString
()]
=
dht
.
self
t
.
Logf
(
"announcing provider for %s"
,
c
)
if
err
:=
dht
.
Provide
(
ctx
,
c
);
err
!=
nil
{
if
err
:=
dht
.
Provide
(
ctx
,
c
,
true
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
...
...
@@ -545,7 +580,7 @@ func TestProvidesAsync(t *testing.T) {
connect
(
t
,
ctx
,
dhts
[
1
],
dhts
[
2
])
connect
(
t
,
ctx
,
dhts
[
1
],
dhts
[
3
])
err
:=
dhts
[
3
]
.
Provide
(
ctx
,
testCaseCids
[
0
])
err
:=
dhts
[
3
]
.
Provide
(
ctx
,
testCaseCids
[
0
]
,
true
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
package.json
View file @
3c95a274
...
...
@@ -102,9 +102,9 @@
},
{
"author"
:
"whyrusleeping"
,
"hash"
:
"Qm
afuecpeZp3k3sHJ5mUARHd4795revuadECQMkmHB8LfW
"
,
"hash"
:
"Qm
XiH3yLocPhjkAmL8R29fKRcEKoVXKCaVDbAS9tdTrVEd
"
,
"name"
:
"go-libp2p-routing"
,
"version"
:
"2.2.1
2
"
"version"
:
"2.2.1
3
"
},
{
"author"
:
"whyrusleeping"
,
...
...
routing.go
View file @
3c95a274
...
...
@@ -9,6 +9,7 @@ import (
"time"
cid
"github.com/ipfs/go-cid"
logging
"github.com/ipfs/go-log"
pb
"github.com/libp2p/go-libp2p-kad-dht/pb"
kb
"github.com/libp2p/go-libp2p-kbucket"
inet
"github.com/libp2p/go-libp2p-net"
...
...
@@ -240,11 +241,14 @@ func (dht *IpfsDHT) GetValues(ctx context.Context, key string, nvals int) ([]rou
// This is what DSHTs (Coral and MainlineDHT) do to store large values in a DHT.
// Provide makes this node announce that it can provide a value for the given key
func
(
dht
*
IpfsDHT
)
Provide
(
ctx
context
.
Context
,
key
*
cid
.
Cid
)
error
{
defer
log
.
EventBegin
(
ctx
,
"provide"
,
key
)
.
Done
()
func
(
dht
*
IpfsDHT
)
Provide
(
ctx
context
.
Context
,
key
*
cid
.
Cid
,
brdcst
bool
)
error
{
defer
log
.
EventBegin
(
ctx
,
"provide"
,
key
,
logging
.
LoggableMap
{
"broadcast"
:
brdcst
}
)
.
Done
()
// add self locally
dht
.
providers
.
AddProvider
(
ctx
,
key
,
dht
.
self
)
if
!
brdcst
{
return
nil
}
peers
,
err
:=
dht
.
GetClosestPeers
(
ctx
,
key
.
KeyString
())
if
err
!=
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