Skip to content

Commit aee7c27

Browse files
committed
Fixed dep ensure, added all dependencies, increasing the timer no activity counter
1 parent 510949f commit aee7c27

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

Gopkg.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@
2121
# version = "2.4.0"
2222

2323

24+
[[constraint]]
25+
branch = "master"
26+
name = "github.com/c2h5oh/datasize"
27+
2428
[[constraint]]
2529
branch = "master"
2630
name = "github.com/google/logger"
31+
32+
[[constraint]]
33+
branch = "master"
34+
name = "github.com/gosuri/uilive"
35+
36+
[[constraint]]
37+
name = "github.com/paulbellamy/ratecounter"
38+
version = "0.2.0"
39+
40+
[[constraint]]
41+
name = "gopkg.in/alecthomas/kingpin.v2"
42+
version = "2.2.5"

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636
func main() {
3737
logger.Init("p2p-port-forward", false, false, os.Stdout)
3838

39+
kingpin.Version("1.0.1")
3940
kingpin.Parse()
4041

4142
zt := libzt.Init(*network, "./zt")

utils/data_rate_counter.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ import (
66
"time"
77
)
88

9+
var rateUpdateInterval = 10 * time.Second
10+
911
type DataRateCounter interface {
1012
GetDataRate() datasize.ByteSize
1113
CaptureEvent(rate int)
1214
}
1315

1416
func NewRateCounter() DataRateCounter {
1517
counter := dataRateCounter{
16-
rateCounter: ratecounter.NewRateCounter(10 * time.Second),
18+
rateCounter: ratecounter.NewRateCounter(rateUpdateInterval),
1719
noActivityTimer: time.NewTimer(time.Second),
1820
}
1921
go counter.updateOnNoActivity()
@@ -22,7 +24,7 @@ func NewRateCounter() DataRateCounter {
2224
}
2325

2426
type dataRateCounter struct {
25-
rateCounter *ratecounter.RateCounter
27+
rateCounter *ratecounter.RateCounter
2628
noActivityTimer *time.Timer
2729
}
2830

@@ -32,12 +34,13 @@ func (c dataRateCounter) GetDataRate() datasize.ByteSize {
3234

3335
func (c dataRateCounter) CaptureEvent(rate int) {
3436
c.rateCounter.Incr(int64(rate))
35-
c.noActivityTimer.Reset(time.Second)
37+
c.noActivityTimer.Reset(rateUpdateInterval)
3638
}
3739

3840
func (c dataRateCounter) updateOnNoActivity() {
3941
for {
4042
<-c.noActivityTimer.C
4143
c.rateCounter.Incr(0)
44+
c.noActivityTimer.Reset(rateUpdateInterval)
4245
}
4346
}

0 commit comments

Comments
 (0)