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-provider
Commits
4f00ef1b
Commit
4f00ef1b
authored
Mar 15, 2019
by
Erik Ingenito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gofmt
License: MIT Signed-off-by:
Erik Ingenito
<
erik@carbonfive.com
>
parent
e5715368
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
29 deletions
+26
-29
provider.go
provider.go
+1
-1
provider_test.go
provider_test.go
+10
-10
queue.go
queue.go
+14
-17
queue_test.go
queue_test.go
+1
-1
No files found.
provider.go
View file @
4f00ef1b
...
...
@@ -11,7 +11,7 @@ import (
routing
"github.com/libp2p/go-libp2p-routing"
)
var
log
=
logging
.
Logger
(
"provider"
)
var
log
=
logging
.
Logger
(
"provider"
)
const
provideOutgoingWorkerLimit
=
8
...
...
provider_test.go
View file @
4f00ef1b
...
...
@@ -6,11 +6,11 @@ import (
"testing"
"time"
blocksutil
"github.com/ipfs/go-ipfs-blocksutil"
cid
"github.com/ipfs/go-cid"
datastore
"github.com/ipfs/go-datastore"
pstore
"github.com/libp2p/go-libp2p-peerstore"
sync
"github.com/ipfs/go-datastore/sync"
blocksutil
"github.com/ipfs/go-ipfs-blocksutil"
pstore
"github.com/libp2p/go-libp2p-peerstore"
)
var
blockGenerator
=
blocksutil
.
NewBlockGenerator
()
...
...
@@ -58,13 +58,13 @@ func TestAnnouncement(t *testing.T) {
for
cids
.
Len
()
>
0
{
select
{
case
cp
:=
<-
r
.
provided
:
if
!
cids
.
Has
(
cp
)
{
t
.
Fatal
(
"Wrong CID provided"
)
}
cids
.
Remove
(
cp
)
case
<-
time
.
After
(
time
.
Second
*
5
)
:
t
.
Fatal
(
"Timeout waiting for cids to be provided."
)
case
cp
:=
<-
r
.
provided
:
if
!
cids
.
Has
(
cp
)
{
t
.
Fatal
(
"Wrong CID provided"
)
}
cids
.
Remove
(
cp
)
case
<-
time
.
After
(
time
.
Second
*
5
)
:
t
.
Fatal
(
"Timeout waiting for cids to be provided."
)
}
}
}
...
...
@@ -77,4 +77,4 @@ func (r *mockRouting) Provide(ctx context.Context, cid cid.Cid, recursive bool)
// Search for peers who are able to provide a given key
func
(
r
*
mockRouting
)
FindProvidersAsync
(
ctx
context
.
Context
,
cid
cid
.
Cid
,
timeout
int
)
<-
chan
pstore
.
PeerInfo
{
return
nil
}
\ No newline at end of file
}
queue.go
View file @
4f00ef1b
...
...
@@ -19,14 +19,11 @@ import (
type
Queue
struct
{
// used to differentiate queues in datastore
// e.g. provider vs reprovider
name
string
ctx
context
.
Context
tail
uint64
head
uint64
ds
datastore
.
Datastore
// Must be threadsafe
name
string
ctx
context
.
Context
tail
uint64
head
uint64
ds
datastore
.
Datastore
// Must be threadsafe
dequeue
chan
cid
.
Cid
enqueue
chan
cid
.
Cid
}
...
...
@@ -39,13 +36,13 @@ func NewQueue(ctx context.Context, name string, ds datastore.Datastore) (*Queue,
return
nil
,
err
}
q
:=
&
Queue
{
name
:
name
,
ctx
:
ctx
,
head
:
head
,
tail
:
tail
,
ds
:
namespaced
,
dequeue
:
make
(
chan
cid
.
Cid
),
enqueue
:
make
(
chan
cid
.
Cid
),
name
:
name
,
ctx
:
ctx
,
head
:
head
,
tail
:
tail
,
ds
:
namespaced
,
dequeue
:
make
(
chan
cid
.
Cid
),
enqueue
:
make
(
chan
cid
.
Cid
),
}
q
.
work
()
return
q
,
nil
...
...
@@ -54,8 +51,8 @@ func NewQueue(ctx context.Context, name string, ds datastore.Datastore) (*Queue,
// Enqueue puts a cid in the queue
func
(
q
*
Queue
)
Enqueue
(
cid
cid
.
Cid
)
{
select
{
case
q
.
enqueue
<-
cid
:
case
<-
q
.
ctx
.
Done
()
:
case
q
.
enqueue
<-
cid
:
case
<-
q
.
ctx
.
Done
()
:
}
}
...
...
queue_test.go
View file @
4f00ef1b
...
...
@@ -22,7 +22,7 @@ func makeCids(n int) []cid.Cid {
func
assertOrdered
(
cids
[]
cid
.
Cid
,
q
*
Queue
,
t
*
testing
.
T
)
{
for
_
,
c
:=
range
cids
{
select
{
case
dequeued
:=
<-
q
.
dequeue
:
case
dequeued
:=
<-
q
.
dequeue
:
if
c
!=
dequeued
{
t
.
Fatalf
(
"Error in ordering of CIDs retrieved from queue. Expected: %s, got: %s"
,
c
,
dequeued
)
}
...
...
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