change bandwidth type from int to int64 to prevent overflow

This commit is contained in:
luciole 2022-11-17 14:30:16 +01:00 committed by Cecylia Bocovich
parent 115ba6a745
commit 2c599f8827
No known key found for this signature in database
GPG key ID: 009DE379FD9B7B90
7 changed files with 36 additions and 34 deletions

View file

@ -10,35 +10,36 @@ const (
)
type bytesLogger interface {
addOutbound(int)
addInbound(int)
addOutbound(int64)
addInbound(int64)
}
// Default bytesLogger does nothing.
type bytesNullLogger struct{}
func (b bytesNullLogger) addOutbound(amount int) {}
func (b bytesNullLogger) addInbound(amount int) {}
func (b bytesNullLogger) addOutbound(amount int64) {}
func (b bytesNullLogger) addInbound(amount int64) {}
// bytesSyncLogger uses channels to safely log from multiple sources with output
// occuring at reasonable intervals.
type bytesSyncLogger struct {
outboundChan chan int
inboundChan chan int
outboundChan chan int64
inboundChan chan int64
}
// newBytesSyncLogger returns a new bytesSyncLogger and starts it loggin.
func newBytesSyncLogger() *bytesSyncLogger {
b := &bytesSyncLogger{
outboundChan: make(chan int, 5),
inboundChan: make(chan int, 5),
outboundChan: make(chan int64, 5),
inboundChan: make(chan int64, 5),
}
go b.log()
return b
}
func (b *bytesSyncLogger) log() {
var outbound, inbound, outEvents, inEvents int
var outbound, inbound int64
var outEvents, inEvents int
ticker := time.NewTicker(LogTimeInterval)
for {
select {
@ -61,10 +62,10 @@ func (b *bytesSyncLogger) log() {
}
}
func (b *bytesSyncLogger) addOutbound(amount int) {
func (b *bytesSyncLogger) addOutbound(amount int64) {
b.outboundChan <- amount
}
func (b *bytesSyncLogger) addInbound(amount int) {
func (b *bytesSyncLogger) addInbound(amount int64) {
b.inboundChan <- amount
}