Skip to content

Commit

Permalink
Remove unnecessary incoming channel
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Michael Avila <davidmichaelavila@gmail.com>
  • Loading branch information
michaelavila committed Jan 17, 2019
1 parent 00be68d commit ad614ed
Showing 1 changed file with 11 additions and 27 deletions.
38 changes: 11 additions & 27 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ type Provider struct {
ctx context.Context
lock sync.Mutex

// CIDs to provide
incoming chan cid.Cid
// CIDs we are working on providing now
outgoing chan cid.Cid
// strategy for deciding which CIDs, given a CID, should be provided
Expand All @@ -47,13 +45,11 @@ func NewProvider(ctx context.Context, strategy Strategy, tracker *Tracker, queue
contentRouting: contentRouting,
lock: sync.Mutex{},
outgoing: make(chan cid.Cid),
incoming: make(chan cid.Cid),
}
}

// Start workers to handle provide requests.
func (p *Provider) Run() {
go p.handleIncoming()
go p.handlePopulateOutgoing()
go p.handleOutgoing()
}
Expand All @@ -63,7 +59,17 @@ func (p *Provider) Provide(root cid.Cid) {
cids := p.strategy(p.ctx, root)
go func() {
for cid := range cids {
p.incoming <- cid
isTracking, err := p.tracker.IsTracking(cid)
if err != nil {
log.Warning("Unable to check provider tracking on incoming: %s", err)
continue
}

if !isTracking {
p.lock.Lock()
p.queue.Enqueue(cid)
p.lock.Unlock()
}
}
}()
}
Expand All @@ -83,28 +89,6 @@ func (p *Provider) announce(cid cid.Cid) error {
return nil
}

// Move CIDs from the incoming channel to the providing queue
func (p *Provider) handleIncoming() {
for {
select {
case key := <-p.incoming:
isTracking, err := p.tracker.IsTracking(key)
if err != nil {
log.Warning("Unable to check provider tracking on incoming: %s", err)
continue
}

if !isTracking {
p.lock.Lock()
p.queue.Enqueue(key)
p.lock.Unlock()
}
case <-p.ctx.Done():
return
}
}
}

// Move CIDs from the providing queue to the outgoing channel
func (p *Provider) handlePopulateOutgoing() {
for {
Expand Down

0 comments on commit ad614ed

Please sign in to comment.