mirror of
https://github.com/bettercap/bettercap
synced 2025-07-07 13:32:07 -07:00
refact: encapsulating synt.Mutex in packets.Queue struct
This commit is contained in:
parent
7d115f6b70
commit
6e6eb688d7
1 changed files with 6 additions and 15 deletions
|
@ -25,10 +25,11 @@ type Traffic struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Queue struct {
|
type Queue struct {
|
||||||
|
sync.Mutex
|
||||||
|
|
||||||
iface *bnet.Endpoint
|
iface *bnet.Endpoint
|
||||||
handle *pcap.Handle
|
handle *pcap.Handle
|
||||||
source *gopacket.PacketSource
|
source *gopacket.PacketSource
|
||||||
lock *sync.Mutex
|
|
||||||
active bool
|
active bool
|
||||||
|
|
||||||
Activities chan Activity `json:"-"`
|
Activities chan Activity `json:"-"`
|
||||||
|
@ -46,7 +47,6 @@ func NewQueue(iface *bnet.Endpoint) (*Queue, error) {
|
||||||
q := &Queue{
|
q := &Queue{
|
||||||
iface: iface,
|
iface: iface,
|
||||||
handle: nil,
|
handle: nil,
|
||||||
lock: &sync.Mutex{},
|
|
||||||
active: true,
|
active: true,
|
||||||
source: nil,
|
source: nil,
|
||||||
Sent: 0,
|
Sent: 0,
|
||||||
|
@ -139,8 +139,8 @@ func (q *Queue) worker() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queue) Send(raw []byte) error {
|
func (q *Queue) Send(raw []byte) error {
|
||||||
q.lock.Lock()
|
q.Lock()
|
||||||
defer q.lock.Unlock()
|
defer q.Unlock()
|
||||||
|
|
||||||
if q.active {
|
if q.active {
|
||||||
err := q.handle.WritePacketData(raw)
|
err := q.handle.WritePacketData(raw)
|
||||||
|
@ -155,18 +155,9 @@ func (q *Queue) Send(raw []byte) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queue) Lock() {
|
|
||||||
q.lock.Lock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queue) Unlock() {
|
|
||||||
q.lock.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (q *Queue) Stop() {
|
func (q *Queue) Stop() {
|
||||||
q.lock.Lock()
|
q.Lock()
|
||||||
defer q.lock.Unlock()
|
defer q.Unlock()
|
||||||
|
|
||||||
q.handle.Close()
|
q.handle.Close()
|
||||||
q.active = false
|
q.active = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue