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

Commit

Permalink
dial delay: address review
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Jun 3, 2018
1 parent 95a234f commit 2dafe20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions dial_delay.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const p_circuit = 290

const numTiers = 2

var tierDelay = 2 * time.Second
var TierDelay = 1 * time.Second

var relay = mafmt.Or(mafmt.And(mafmt.Base(p_circuit), mafmt.Base(ma.P_IPFS)), mafmt.And(mafmt.Base(ma.P_IPFS), mafmt.Base(p_circuit), mafmt.Base(ma.P_IPFS)))

Expand All @@ -21,7 +21,7 @@ var relay = mafmt.Or(mafmt.And(mafmt.Base(p_circuit), mafmt.Base(ma.P_IPFS)), ma
// sending more addresses in case all previous failed
func delayDialAddrs(ctx context.Context, c <-chan ma.Multiaddr) (<-chan ma.Multiaddr, chan<- struct{}) {
out := make(chan ma.Multiaddr)
delay := time.NewTimer(tierDelay)
delay := time.NewTimer(TierDelay)
triggerNext := make(chan struct{}, 1)

go func() {
Expand Down Expand Up @@ -64,7 +64,7 @@ func delayDialAddrs(ctx context.Context, c <-chan ma.Multiaddr) (<-chan ma.Multi
}
}

// waitForMore woits for addresses from the channel
// waitForMore waits for addresses from the channel
waitForMore := func() (bool, error) {
select {
case addr, ok := <-c:
Expand Down Expand Up @@ -93,12 +93,12 @@ func delayDialAddrs(ctx context.Context, c <-chan ma.Multiaddr) (<-chan ma.Multi
put(addr)
return true, false, nil
case <-delay.C:
delay.Reset(tierDelay)
delay.Reset(TierDelay)
case <-triggerNext:
if !delay.Stop() {
<-delay.C
}
delay.Reset(tierDelay)
delay.Reset(TierDelay)
case <-ctx.Done():
return false, false, ctx.Err()
}
Expand All @@ -123,7 +123,7 @@ func delayDialAddrs(ctx context.Context, c <-chan ma.Multiaddr) (<-chan ma.Multi
if !delay.Stop() {
<-delay.C
}
delay.Reset(tierDelay)
delay.Reset(TierDelay)
case <-ctx.Done():
return false, ctx.Err()
}
Expand Down
4 changes: 2 additions & 2 deletions dial_delay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func prepare() {
}
_ = ma.AddProtocol(circuitProto)

tierDelay = 32 * time.Millisecond // 2x windows timer resolution
TierDelay = 32 * time.Millisecond // 2x windows timer resolution
}

// addrChan creates a multiaddr channel with `nsync` size. If nsync is larger
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestDelayMoreT1T0(t *testing.T) {
func TestDelaySingleT0T1WaitT0(t *testing.T) {
ctx := context.Background()
prepare()
tierDelay = 64 * time.Millisecond // 4x windows timer resolution
TierDelay = 64 * time.Millisecond // 4x windows timer resolution

start := time.Now()
ch, _ := delayDialAddrs(ctx, addrChan(t, 2, T0_A, T1_A, "16ms", T0_B))
Expand Down

0 comments on commit 2dafe20

Please sign in to comment.