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
dbfc1c39
Commit
dbfc1c39
authored
Apr 05, 2019
by
Michael Avila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Close provider on ipfs shutdown
License: MIT Signed-off-by:
Michael Avila
<
davidmichaelavila@gmail.com
>
parent
00f05cb1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletion
+29
-1
offline.go
offline.go
+4
-0
provider.go
provider.go
+8
-0
queue.go
queue.go
+17
-1
No files found.
offline.go
View file @
dbfc1c39
...
...
@@ -14,3 +14,7 @@ func (op *offlineProvider) Run() {}
func
(
op
*
offlineProvider
)
Provide
(
cid
cid
.
Cid
)
error
{
return
nil
}
func
(
op
*
offlineProvider
)
Close
()
error
{
return
nil
}
provider.go
View file @
dbfc1c39
...
...
@@ -20,6 +20,8 @@ type Provider interface {
Run
()
// Provide takes a cid and makes an attempt to announce it to the network
Provide
(
cid
.
Cid
)
error
// Close stops the provider
Close
()
error
}
type
provider
struct
{
...
...
@@ -39,6 +41,12 @@ func NewProvider(ctx context.Context, queue *Queue, contentRouting routing.Conte
}
}
// Close stops the provider
func
(
p
*
provider
)
Close
()
error
{
p
.
queue
.
Close
()
return
nil
}
// Start workers to handle provide requests.
func
(
p
*
provider
)
Run
()
{
p
.
handleAnnouncements
()
...
...
queue.go
View file @
dbfc1c39
...
...
@@ -27,6 +27,8 @@ type Queue struct {
ds
datastore
.
Datastore
// Must be threadsafe
dequeue
chan
cid
.
Cid
enqueue
chan
cid
.
Cid
close
context
.
CancelFunc
closed
chan
struct
{}
}
// NewQueue creates a queue for cids
...
...
@@ -36,19 +38,29 @@ func NewQueue(ctx context.Context, name string, ds datastore.Datastore) (*Queue,
if
err
!=
nil
{
return
nil
,
err
}
cancelCtx
,
cancel
:=
context
.
WithCancel
(
ctx
)
q
:=
&
Queue
{
name
:
name
,
ctx
:
ctx
,
ctx
:
c
ancelC
tx
,
head
:
head
,
tail
:
tail
,
ds
:
namespaced
,
dequeue
:
make
(
chan
cid
.
Cid
),
enqueue
:
make
(
chan
cid
.
Cid
),
close
:
cancel
,
closed
:
make
(
chan
struct
{},
1
),
}
q
.
work
()
return
q
,
nil
}
// Close stops the queue
func
(
q
*
Queue
)
Close
()
error
{
q
.
close
()
<-
q
.
closed
return
nil
}
// Enqueue puts a cid in the queue
func
(
q
*
Queue
)
Enqueue
(
cid
cid
.
Cid
)
{
select
{
...
...
@@ -103,6 +115,10 @@ func (q *Queue) work() {
var
k
datastore
.
Key
=
datastore
.
Key
{}
var
c
cid
.
Cid
=
cid
.
Undef
defer
func
()
{
close
(
q
.
closed
)
}()
for
{
if
c
==
cid
.
Undef
{
k
,
c
=
q
.
nextEntry
()
...
...
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