mirror of
https://github.com/bettercap/bettercap
synced 2025-07-10 07:13:36 -07:00
fix: using normal mutex instead of atomic increments ( fixes #69 )
This commit is contained in:
parent
129f87f8f9
commit
d60648f0db
3 changed files with 23 additions and 12 deletions
|
@ -3,7 +3,6 @@ package modules
|
|||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/bettercap/bettercap/log"
|
||||
)
|
||||
|
@ -20,7 +19,9 @@ func (p *Prober) sendProbeUDP(from net.IP, from_hw net.HardwareAddr, ip net.IP)
|
|||
wrote, _ := con.Write([]byte{0x00})
|
||||
|
||||
if wrote > 0 {
|
||||
atomic.AddUint64(&p.Session.Queue.Stats.Sent, uint64(wrote))
|
||||
p.Session.Queue.Stats.Lock()
|
||||
p.Session.Queue.Stats.Sent += uint64(wrote)
|
||||
p.Session.Queue.Stats.Unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/bettercap/bettercap/core"
|
||||
|
@ -169,13 +168,15 @@ func (d *Discovery) Show(by string) error {
|
|||
|
||||
d.showTable(colNames, rows)
|
||||
|
||||
d.Session.Queue.Stats.RLock()
|
||||
fmt.Printf("\n%s %s / %s %s / %d pkts / %d errs\n\n",
|
||||
core.Red("↑"),
|
||||
humanize.Bytes(atomic.LoadUint64(&d.Session.Queue.Stats.Sent)),
|
||||
humanize.Bytes(d.Session.Queue.Stats.Sent),
|
||||
core.Green("↓"),
|
||||
humanize.Bytes(atomic.LoadUint64(&d.Session.Queue.Stats.Received)),
|
||||
atomic.LoadUint64(&d.Session.Queue.Stats.PktReceived),
|
||||
atomic.LoadUint64(&d.Session.Queue.Stats.Errors))
|
||||
humanize.Bytes(d.Session.Queue.Stats.Received),
|
||||
d.Session.Queue.Stats.PktReceived,
|
||||
d.Session.Queue.Stats.Errors)
|
||||
d.Session.Queue.Stats.RUnlock()
|
||||
|
||||
s := EventsStream{}
|
||||
events := d.Session.Events.Sorted()
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/bettercap/bettercap/network"
|
||||
|
||||
|
@ -26,6 +25,8 @@ type Traffic struct {
|
|||
}
|
||||
|
||||
type Stats struct {
|
||||
sync.RWMutex
|
||||
|
||||
Sent uint64
|
||||
Received uint64
|
||||
PktReceived uint64
|
||||
|
@ -146,8 +147,12 @@ func (q *Queue) worker() {
|
|||
|
||||
pktSize := uint64(len(pkt.Data()))
|
||||
|
||||
atomic.AddUint64(&q.Stats.PktReceived, 1)
|
||||
atomic.AddUint64(&q.Stats.Received, pktSize)
|
||||
q.Stats.Lock()
|
||||
|
||||
q.Stats.PktReceived++
|
||||
q.Stats.Received += pktSize
|
||||
|
||||
q.Stats.Unlock()
|
||||
|
||||
q.onPacketCallback(pkt)
|
||||
|
||||
|
@ -179,10 +184,14 @@ func (q *Queue) Send(raw []byte) error {
|
|||
}
|
||||
|
||||
if err := q.handle.WritePacketData(raw); err != nil {
|
||||
atomic.AddUint64(&q.Stats.Errors, 1)
|
||||
q.Stats.Lock()
|
||||
q.Stats.Errors++
|
||||
q.Stats.Unlock()
|
||||
return err
|
||||
} else {
|
||||
atomic.AddUint64(&q.Stats.Sent, uint64(len(raw)))
|
||||
q.Stats.Lock()
|
||||
q.Stats.Sent += uint64(len(raw))
|
||||
q.Stats.Unlock()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue