diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-06-11 18:13:52 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-06-11 18:13:52 +0200 |
commit | 3371f8dac6fe6bbd7522a8316b50f6473012e302 (patch) | |
tree | 85900fb0a804af625c1e1f62264e69ee632cb2a8 /device/peer.go | |
parent | 41fdbf09710b7987b442e8fd8310568f2790c15b (diff) |
device: update transfer counters correctly
The rule is to always update them to the full packet size minus UDP/IP
encapsulation for all authenticated packet types.
Diffstat (limited to 'device/peer.go')
-rw-r--r-- | device/peer.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/device/peer.go b/device/peer.go index 815dff4..4e7f2da 100644 --- a/device/peer.go +++ b/device/peer.go @@ -10,6 +10,7 @@ import ( "errors" "fmt" "sync" + "sync/atomic" "time" ) @@ -140,7 +141,11 @@ func (peer *Peer) SendBuffer(buffer []byte) error { return errors.New("no known endpoint for peer") } - return peer.device.net.bind.Send(buffer, peer.endpoint) + err := peer.device.net.bind.Send(buffer, peer.endpoint) + if err == nil { + atomic.AddUint64(&peer.stats.txBytes, uint64(len(buffer))) + } + return err } func (peer *Peer) String() string { |