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
b17e206c
Commit
b17e206c
authored
Nov 14, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use an iterator for provider key sweeping
parent
044ea16a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
32 deletions
+38
-32
providers/providers.go
providers/providers.go
+29
-28
providers/providers_test.go
providers/providers_test.go
+9
-4
No files found.
providers/providers.go
View file @
b17e206c
...
...
@@ -206,44 +206,40 @@ func (pm *ProviderManager) deleteProvSet(k *cid.Cid) error {
return
nil
}
func
(
pm
*
ProviderManager
)
get
All
ProvKeys
()
(
[]
*
cid
.
Cid
,
error
)
{
func
(
pm
*
ProviderManager
)
getProvKeys
()
(
func
()
(
*
cid
.
Cid
,
bool
),
error
)
{
res
,
err
:=
pm
.
dstore
.
Query
(
dsq
.
Query
{
KeysOnly
:
tru
e
,
KeysOnly
:
fals
e
,
Prefix
:
providersKeyPrefix
,
})
if
err
!=
nil
{
return
nil
,
err
}
entries
,
err
:=
res
.
Rest
()
if
err
!=
nil
{
return
nil
,
err
}
iter
:=
func
()
(
*
cid
.
Cid
,
bool
)
{
for
e
:=
range
res
.
Next
()
{
parts
:=
strings
.
Split
(
e
.
Key
,
"/"
)
if
len
(
parts
)
!=
4
{
log
.
Warning
(
"incorrectly formatted provider entry in datastore"
)
continue
}
decoded
,
err
:=
base32
.
RawStdEncoding
.
DecodeString
(
parts
[
2
])
if
err
!=
nil
{
log
.
Warning
(
"error decoding base32 provider key"
)
continue
}
seen
:=
cid
.
NewSet
()
for
_
,
e
:=
range
entries
{
parts
:=
strings
.
Split
(
e
.
Key
,
"/"
)
if
len
(
parts
)
!=
4
{
log
.
Warning
(
"incorrectly formatted provider entry in datastore"
)
continue
}
decoded
,
err
:=
base32
.
RawStdEncoding
.
DecodeString
(
parts
[
2
])
if
err
!=
nil
{
log
.
Warning
(
"error decoding base32 provider key"
)
continue
}
c
,
err
:=
cid
.
Cast
(
decoded
)
if
err
!=
nil
{
log
.
Warning
(
"error casting key to cid from datastore key"
)
continue
}
c
,
err
:=
cid
.
Cast
(
decoded
)
if
err
!=
nil
{
log
.
Warning
(
"error casting key to cid from datastore key"
)
continue
return
c
,
true
}
seen
.
Add
(
c
)
return
nil
,
false
}
return
seen
.
Keys
()
,
nil
return
iter
,
nil
}
func
(
pm
*
ProviderManager
)
run
()
{
...
...
@@ -263,12 +259,17 @@ func (pm *ProviderManager) run() {
gp
.
resp
<-
provs
case
<-
tick
.
C
:
keys
,
err
:=
pm
.
get
All
ProvKeys
()
keys
,
err
:=
pm
.
getProvKeys
()
if
err
!=
nil
{
log
.
Error
(
"Error loading provider keys: "
,
err
)
continue
}
for
_
,
k
:=
range
keys
{
for
{
k
,
ok
:=
keys
()
if
!
ok
{
break
}
provs
,
err
:=
pm
.
getProvSet
(
k
)
if
err
!=
nil
{
log
.
Error
(
"error loading known provset: "
,
err
)
...
...
providers/providers_test.go
View file @
b17e206c
...
...
@@ -10,7 +10,7 @@ import (
cid
"github.com/ipfs/go-cid"
ds
"github.com/ipfs/go-datastore"
lds
"github.com/ipfs/go-ds-leveldb"
//
lds "github.com/ipfs/go-ds-leveldb"
u
"github.com/ipfs/go-ipfs-util"
peer
"github.com/libp2p/go-libp2p-peer"
)
...
...
@@ -142,17 +142,21 @@ func TestProvidesExpire(t *testing.T) {
t
.
Fatal
(
"providers map not cleaned up"
)
}
all
prov
s
,
err
:=
p
.
get
All
ProvKeys
()
prov
iter
,
err
:=
p
.
getProvKeys
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
allprovs
)
!=
0
{
_
,
ok
:=
proviter
()
if
ok
{
t
.
Fatal
(
"expected everything to be cleaned out of the datastore"
)
}
}
///* This can be used for profiling. Keeping it commented out for now to avoid incurring extra CI time
var
_
=
ioutil
.
NopCloser
var
_
=
os
.
DevNull
/* This can be used for profiling. Keeping it commented out for now to avoid incurring extra CI time
func TestLargeProvidersSet(t *testing.T) {
old := lruCacheSize
lruCacheSize = 10
...
...
@@ -201,3 +205,4 @@ func TestLargeProvidersSet(t *testing.T) {
}
}
//*/
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