mirror of
https://github.com/bettercap/bettercap
synced 2025-07-10 15:23:30 -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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync/atomic"
|
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/log"
|
"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})
|
wrote, _ := con.Write([]byte{0x00})
|
||||||
|
|
||||||
if wrote > 0 {
|
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"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/core"
|
"github.com/bettercap/bettercap/core"
|
||||||
|
@ -169,13 +168,15 @@ func (d *Discovery) Show(by string) error {
|
||||||
|
|
||||||
d.showTable(colNames, rows)
|
d.showTable(colNames, rows)
|
||||||
|
|
||||||
|
d.Session.Queue.Stats.RLock()
|
||||||
fmt.Printf("\n%s %s / %s %s / %d pkts / %d errs\n\n",
|
fmt.Printf("\n%s %s / %s %s / %d pkts / %d errs\n\n",
|
||||||
core.Red("↑"),
|
core.Red("↑"),
|
||||||
humanize.Bytes(atomic.LoadUint64(&d.Session.Queue.Stats.Sent)),
|
humanize.Bytes(d.Session.Queue.Stats.Sent),
|
||||||
core.Green("↓"),
|
core.Green("↓"),
|
||||||
humanize.Bytes(atomic.LoadUint64(&d.Session.Queue.Stats.Received)),
|
humanize.Bytes(d.Session.Queue.Stats.Received),
|
||||||
atomic.LoadUint64(&d.Session.Queue.Stats.PktReceived),
|
d.Session.Queue.Stats.PktReceived,
|
||||||
atomic.LoadUint64(&d.Session.Queue.Stats.Errors))
|
d.Session.Queue.Stats.Errors)
|
||||||
|
d.Session.Queue.Stats.RUnlock()
|
||||||
|
|
||||||
s := EventsStream{}
|
s := EventsStream{}
|
||||||
events := d.Session.Events.Sorted()
|
events := d.Session.Events.Sorted()
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/network"
|
"github.com/bettercap/bettercap/network"
|
||||||
|
|
||||||
|
@ -26,6 +25,8 @@ type Traffic struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
|
sync.RWMutex
|
||||||
|
|
||||||
Sent uint64
|
Sent uint64
|
||||||
Received uint64
|
Received uint64
|
||||||
PktReceived uint64
|
PktReceived uint64
|
||||||
|
@ -146,8 +147,12 @@ func (q *Queue) worker() {
|
||||||
|
|
||||||
pktSize := uint64(len(pkt.Data()))
|
pktSize := uint64(len(pkt.Data()))
|
||||||
|
|
||||||
atomic.AddUint64(&q.Stats.PktReceived, 1)
|
q.Stats.Lock()
|
||||||
atomic.AddUint64(&q.Stats.Received, pktSize)
|
|
||||||
|
q.Stats.PktReceived++
|
||||||
|
q.Stats.Received += pktSize
|
||||||
|
|
||||||
|
q.Stats.Unlock()
|
||||||
|
|
||||||
q.onPacketCallback(pkt)
|
q.onPacketCallback(pkt)
|
||||||
|
|
||||||
|
@ -179,10 +184,14 @@ func (q *Queue) Send(raw []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := q.handle.WritePacketData(raw); err != nil {
|
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
|
return err
|
||||||
} else {
|
} else {
|
||||||
atomic.AddUint64(&q.Stats.Sent, uint64(len(raw)))
|
q.Stats.Lock()
|
||||||
|
q.Stats.Sent += uint64(len(raw))
|
||||||
|
q.Stats.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue