From 019af7507582cb16074ecbed8fa501a14714643e Mon Sep 17 00:00:00 2001 From: Michael Avila Date: Wed, 20 Mar 2019 14:13:30 -0700 Subject: [PATCH] Add comments; Check ctx.Err(); Move import License: MIT Signed-off-by: Michael Avila --- core/core.go | 2 +- provider/provider.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/core.go b/core/core.go index d139011475a..0d41b737874 100644 --- a/core/core.go +++ b/core/core.go @@ -14,7 +14,6 @@ import ( "context" "errors" "fmt" - "github.com/ipfs/go-ipfs/provider" "io" "io/ioutil" "os" @@ -29,6 +28,7 @@ import ( ipnsrp "github.com/ipfs/go-ipfs/namesys/republisher" p2p "github.com/ipfs/go-ipfs/p2p" pin "github.com/ipfs/go-ipfs/pin" + provider "github.com/ipfs/go-ipfs/provider" repo "github.com/ipfs/go-ipfs/repo" bitswap "github.com/ipfs/go-bitswap" diff --git a/provider/provider.go b/provider/provider.go index a5093d65bdf..f9aa4ed7820 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -5,10 +5,9 @@ package provider import ( "context" - - cid "github.com/ipfs/go-cid" + "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log" - routing "github.com/libp2p/go-libp2p-routing" + "github.com/libp2p/go-libp2p-routing" ) var log = logging.Logger("provider") @@ -17,7 +16,9 @@ const provideOutgoingWorkerLimit = 8 // Provider announces blocks to the network type Provider interface { + // Run is used to begin processing the provider work Run() + // Provide takes a cid and makes an attempt to announce it to the network Provide(cid.Cid) error } @@ -53,7 +54,7 @@ func (p *provider) Provide(root cid.Cid) error { func (p *provider) handleAnnouncements() { for workers := 0; workers < provideOutgoingWorkerLimit; workers++ { go func() { - for { + for p.ctx.Err() == nil { select { case <-p.ctx.Done(): return