From b5dd173c017b71ea9975c52c98d05f6692fa5f46 Mon Sep 17 00:00:00 2001 From: hebo Date: Fri, 27 Sep 2019 12:53:54 +0800 Subject: [PATCH] change default capture rate --- capture/network.go | 40 ++++++++++++++++++++-------------------- communicator/model.go | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/capture/network.go b/capture/network.go index a981347..0308730 100644 --- a/capture/network.go +++ b/capture/network.go @@ -113,33 +113,33 @@ func (nc *networkCard) listenNormal() { var ci gopacket.CaptureInfo var err error - // capture packets according to a certain probability - capturePacketRate := communicator.GetTCPCapturePacketRate() - if capturePacketRate <= 0 { - time.Sleep(time.Second*1) - aliveCounter += 1 - if aliveCounter >= checkCount { - aliveCounter = 0 - nc.receiver <- model.NewBaseQueryPiece(localIPAddr, nc.listenPort, capturePacketRate) - } - continue - - } else if 0 < capturePacketRate && capturePacketRate < 1.0 { - // fall into throw range - rn := rand.Float64() - if rn > capturePacketRate { - continue - } - } - - aliveCounter = 0 data, ci, err = handler.ZeroCopyReadPacketData() if err != nil { log.Error(err.Error()) time.Sleep(time.Second*3) continue } + + // capture packets according to a certain probability + tcpCapturePacketRate := communicator.GetTCPCapturePacketRate() + if tcpCapturePacketRate <= 0 { + time.Sleep(time.Second*1) + aliveCounter += 1 + if aliveCounter >= checkCount { + aliveCounter = 0 + nc.receiver <- model.NewBaseQueryPiece(localIPAddr, nc.listenPort, tcpCapturePacketRate) + } + continue + } else if 0 < tcpCapturePacketRate && tcpCapturePacketRate < 1.0 { + // fall into throw range + rn := rand.Float64() + if rn > tcpCapturePacketRate { + continue + } + } + + aliveCounter = 0 packet := gopacket.NewPacket(data, layers.LayerTypeEthernet, gopacket.NoCopy) m := packet.Metadata() m.CaptureInfo = ci diff --git a/communicator/model.go b/communicator/model.go index c1c6a3d..ec420f3 100644 --- a/communicator/model.go +++ b/communicator/model.go @@ -32,7 +32,7 @@ func (cprc *capturePacketRateConfig) setVal (val interface{}) (err error){ return } - fmt.Printf("set config %s: %v", CAPTURE_PACKET_RATE, realVal) + fmt.Printf("set config %s: %v\n", CAPTURE_PACKET_RATE, realVal) cprc.mysqlTPR = realVal cprc.tcpTPR = math.Sqrt(realVal) return