mirror of
https://github.com/zr-hebo/sniffer-agent.git
synced 2025-08-11 02:22:01 +08:00
add communicator api
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
package capture
|
||||
|
||||
import (
|
||||
sd "github.com/zr-hebo/sniffer-agent/session-dealer"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"sync"
|
||||
sd "github.com/zr-hebo/sniffer-agent/session-dealer"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
localIPAddr *string
|
||||
|
||||
sessionPool = make(map[string]sd.ConnSession)
|
||||
sessionPoolLock sync.Mutex
|
||||
// sessionPoolLock sync.Mutex
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -21,4 +22,6 @@ func init() {
|
||||
|
||||
localIPAddr = &ipAddr
|
||||
log.Infof("parsed local ip address:%s", *localIPAddr)
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
@@ -6,7 +6,9 @@ import (
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
"github.com/google/gopacket/pcap"
|
||||
"github.com/zr-hebo/sniffer-agent/communicator"
|
||||
"golang.org/x/net/bpf"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/google/gopacket/pcapgo"
|
||||
@@ -114,6 +116,20 @@ func (nc *networkCard) listenNormal() {
|
||||
continue
|
||||
}
|
||||
|
||||
// throw packets according to a certain probability
|
||||
throwPacketRate := communicator.GetConfig(communicator.THROW_PACKET_RATE).(float64)
|
||||
if throwPacketRate >= 1.0 {
|
||||
time.Sleep(time.Second*3)
|
||||
continue
|
||||
|
||||
} else if 0 < throwPacketRate && throwPacketRate < 1.0 {
|
||||
// fall into throw range
|
||||
rn := rand.Float64()
|
||||
if rn <= throwPacketRate {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
packet := gopacket.NewPacket(data, layers.LayerTypeEthernet, gopacket.NoCopy)
|
||||
m := packet.Metadata()
|
||||
m.CaptureInfo = ci
|
||||
|
Reference in New Issue
Block a user