From c5346a23f86bcc9fd1f8c0925618f137c454d86e Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sat, 6 Feb 2016 14:03:02 +0300 Subject: [PATCH] Let all counters will be unsigned, as sign does not mean anything Signed-off-by: Sergey Matveev --- .../govpn/cmd/govpn-client/tcp.go | 2 +- .../govpn/cmd/govpn-client/udp.go | 2 +- src/cypherpunks.ru/govpn/peer.go | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cypherpunks.ru/govpn/cmd/govpn-client/tcp.go b/src/cypherpunks.ru/govpn/cmd/govpn-client/tcp.go index 7e2b1a3..dd35364 100644 --- a/src/cypherpunks.ru/govpn/cmd/govpn-client/tcp.go +++ b/src/cypherpunks.ru/govpn/cmd/govpn-client/tcp.go @@ -151,7 +151,7 @@ TransportCycle: timeouted <- struct{}{} break TransportCycle } - if atomic.LoadInt64(&peer.BytesIn)+atomic.LoadInt64(&peer.BytesOut) > govpn.MaxBytesPerKey { + if atomic.LoadUint64(&peer.BytesIn)+atomic.LoadUint64(&peer.BytesOut) > govpn.MaxBytesPerKey { log.Println("Need rehandshake") rehandshaking <- struct{}{} break TransportCycle diff --git a/src/cypherpunks.ru/govpn/cmd/govpn-client/udp.go b/src/cypherpunks.ru/govpn/cmd/govpn-client/udp.go index 3d0c421..c70cf46 100644 --- a/src/cypherpunks.ru/govpn/cmd/govpn-client/udp.go +++ b/src/cypherpunks.ru/govpn/cmd/govpn-client/udp.go @@ -70,7 +70,7 @@ MainCycle: log.Println("Unauthenticated packet") timeouts++ } - if atomic.LoadInt64(&peer.BytesIn)+atomic.LoadInt64(&peer.BytesOut) > govpn.MaxBytesPerKey { + if atomic.LoadUint64(&peer.BytesIn)+atomic.LoadUint64(&peer.BytesOut) > govpn.MaxBytesPerKey { log.Println("Need rehandshake") rehandshaking <- struct{}{} break MainCycle diff --git a/src/cypherpunks.ru/govpn/peer.go b/src/cypherpunks.ru/govpn/peer.go index 69490c9..4b48cec 100644 --- a/src/cypherpunks.ru/govpn/peer.go +++ b/src/cypherpunks.ru/govpn/peer.go @@ -39,7 +39,7 @@ const ( // S20BS is Salsa20's internal blocksize in bytes S20BS = 64 // Maximal amount of bytes transfered with single key (4 GiB) - MaxBytesPerKey int64 = 1 << 32 + MaxBytesPerKey uint64 = 1 << 32 // Heartbeat rate, relative to Timeout TimeoutHeartbeat = 4 // Minimal valid packet length @@ -96,10 +96,10 @@ type Peer struct { willSentCycle time.Time // Statistics - BytesIn int64 - BytesOut int64 - BytesPayloadIn int64 - BytesPayloadOut int64 + BytesIn uint64 + BytesOut uint64 + BytesPayloadIn uint64 + BytesPayloadOut uint64 FramesIn uint64 FramesOut uint64 FramesUnauth uint64 @@ -241,7 +241,7 @@ func (p *Peer) EthProcess(data []byte) { // accept the next one copy(p.bufT[S20BS:], data) p.bufT[S20BS+len(data)] = PadByte - p.BytesPayloadOut += int64(len(data)) + p.BytesPayloadOut += uint64(len(data)) } if p.NoiseEnable && !p.Encless { @@ -278,7 +278,7 @@ func (p *Peer) EthProcess(data []byte) { ) copy(p.keyAuthT[:], p.bufT[:SSize]) poly1305.Sum(p.tagT, p.frameT, p.keyAuthT) - atomic.AddInt64(&p.BytesOut, int64(len(p.frameT)+TagSize)) + atomic.AddUint64(&p.BytesOut, uint64(len(p.frameT)+TagSize)) out = append(p.tagT[:], p.frameT...) } p.FramesOut++ @@ -376,7 +376,7 @@ func (p *Peer) PktProcess(data []byte, tap io.Writer, reorderable bool) bool { } p.FramesIn++ - atomic.AddInt64(&p.BytesIn, int64(len(data))) + atomic.AddUint64(&p.BytesIn, uint64(len(data))) p.LastPing = time.Now() p.pktSizeR = bytes.LastIndexByte(out, PadByte) if p.pktSizeR == -1 { @@ -396,7 +396,7 @@ func (p *Peer) PktProcess(data []byte, tap io.Writer, reorderable bool) bool { p.BusyR.Unlock() return true } - p.BytesPayloadIn += int64(p.pktSizeR) + p.BytesPayloadIn += uint64(p.pktSizeR) tap.Write(out[:p.pktSizeR]) p.BusyR.Unlock() return true -- 2.44.0