Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Sep 6, 2019
1 parent 1504aa7 commit 6671c38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions backoffcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ type backoffCache struct {
peers map[peer.ID]peer.AddrInfo
sendingChs map[chan peer.AddrInfo]int

ongoing bool
strat BackoffStrategy
mux sync.Mutex
ongoing bool
strat BackoffStrategy
mux sync.Mutex
}

func (d *BackoffDiscovery) Advertise(ctx context.Context, ns string, opts ...discovery.Option) (time.Duration, error) {
Expand Down Expand Up @@ -105,7 +105,7 @@ func (d *BackoffDiscovery) FindPeers(ctx context.Context, ns string, opts ...dis
defer func() {
c.mux.Lock()

for ch := range c.sendingChs{
for ch := range c.sendingChs {
close(ch)
}

Expand Down Expand Up @@ -149,7 +149,7 @@ func (d *BackoffDiscovery) FindPeers(ctx context.Context, ns string, opts ...dis
ch <- sendAi
if rem == 1 {
close(ch)
delete(c.sendingChs,ch)
delete(c.sendingChs, ch)
break
} else if rem > 0 {
rem--
Expand Down
12 changes: 6 additions & 6 deletions backoffcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ func (d *mockDiscoveryClient) FindPeers(ctx context.Context, ns string, opts ...
}

type delayedDiscovery struct {
disc discovery.Discovery
disc discovery.Discovery
delay time.Duration
}

func (d *delayedDiscovery) Advertise(ctx context.Context, ns string, opts ...discovery.Option) (time.Duration, error) {
return d.disc.Advertise(ctx,ns, opts...)
return d.disc.Advertise(ctx, ns, opts...)
}

func (d *delayedDiscovery) FindPeers(ctx context.Context, ns string, opts ...discovery.Option) (<-chan peer.AddrInfo, error) {
Expand All @@ -130,9 +130,9 @@ func (d *delayedDiscovery) FindPeers(ctx context.Context, ns string, opts ...dis
}

ch := make(chan peer.AddrInfo, 32)
go func(){
go func() {
defer close(ch)
for ai := range dch{
for ai := range dch {
ch <- ai
time.Sleep(d.delay)
}
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestBackoffDiscoverySimultaneousQuery(t *testing.T) {
n := 40
advertisers := make([]discovery.Discovery, n)

for i := 0; i<n; i++{
for i := 0; i < n; i++ {
h := bhost.NewBlankHost(swarmt.GenSwarm(t, ctx))
advertisers[i] = &mockDiscoveryClient{h, discServer}
}
Expand Down Expand Up @@ -294,4 +294,4 @@ func TestBackoffDiscoverySimultaneousQuery(t *testing.T) {
if szCh1 != n && szCh2 != n {
t.Fatalf("Channels returned %d, %d elements instead of %d", szCh1, szCh2, n)
}
}
}

0 comments on commit 6671c38

Please sign in to comment.