Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Solodkov <oleg.solodkov@xored.com>
  • Loading branch information
sol-0 committed Dec 7, 2021
1 parent 2a51462 commit 58ba1da
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/networkservice/common/refresh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package refresh

import (
"context"
"math"
"time"

"github.com/golang/protobuf/ptypes"
Expand Down Expand Up @@ -109,7 +108,7 @@ func (t *refreshClient) Close(ctx context.Context, conn *networkservice.Connecti
func after(ctx context.Context, conn *networkservice.Connection) (time.Duration, error) {
clockTime := clock.FromContext(ctx)

var minTimeout = time.Duration(math.MaxInt64)
var minTimeout *time.Duration
var expireTime time.Time
for _, segment := range conn.GetPath().GetPathSegments() {
expTime, err := ptypes.Timestamp(segment.GetExpires())
Expand All @@ -119,15 +118,19 @@ func after(ctx context.Context, conn *networkservice.Connection) (time.Duration,

timeout := clockTime.Until(expTime)

if timeout < minTimeout {
minTimeout = timeout
if minTimeout == nil || timeout < *minTimeout {
if minTimeout == nil {
minTimeout = new(time.Duration)
}

*minTimeout = timeout
expireTime = expTime
}
}

log.FromContext(ctx).Infof("expiration after %s at %s", minTimeout.String(), expireTime.UTC())

if minTimeout <= 0 {
if minTimeout == nil || *minTimeout <= 0 {
return 1, nil
}

Expand All @@ -140,7 +143,7 @@ func after(ctx context.Context, conn *networkservice.Connection) (time.Duration,
if len(path.PathSegments) > 1 {
scale = 0.2 + 0.2*float64(path.Index)/float64(len(path.PathSegments))
}
duration := time.Duration(float64(minTimeout) * scale)
duration := time.Duration(float64(*minTimeout) * scale)

return duration, nil
}

0 comments on commit 58ba1da

Please sign in to comment.