Skip to content

Commit

Permalink
rebase and remove replayDelay
Browse files Browse the repository at this point in the history
  • Loading branch information
eddc005 committed May 6, 2024
1 parent 9438745 commit f01b79e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
3 changes: 0 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func initConfig() {
}

viper.SetDefault("replay.realtime", true)
viper.SetDefault("replay.replayDelay", 10 * time.Millisecond)
}

func initLogger() {
Expand Down Expand Up @@ -185,7 +184,6 @@ type cliConfigIO struct {

type cliConfigReplay struct {
Realtime bool `mapstructure:"realtime"`
ReplayDelay time.Duration `mapstructure:"replayDelay"`
}

type cliConfigWorkers struct {
Expand Down Expand Up @@ -216,7 +214,6 @@ func (c *cliConfig) fillIO(config *engine.Config) error {
ioImpl, err = io.NewPcapPacketIO(io.PcapPacketIOConfig{
PcapFile: pcapFile,
Realtime: c.Replay.Realtime,
ReplayDelay: c.Replay.ReplayDelay,
})
} else {
// Setup IO for nfqueue
Expand Down
20 changes: 10 additions & 10 deletions io/pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type pcapPacketIO struct {
type PcapPacketIOConfig struct {
PcapFile string
Realtime bool
ReplayDelay time.Duration
}

func NewPcapPacketIO(config PcapPacketIOConfig) (PacketIO, error) {
Expand All @@ -34,8 +33,6 @@ func NewPcapPacketIO(config PcapPacketIOConfig) (PacketIO, error) {
return nil, err
}

print(config.ReplayDelay)

return &pcapPacketIO{
pcap: handle,
lastTime: nil,
Expand All @@ -58,8 +55,9 @@ func (p *pcapPacketIO) Register(ctx context.Context, cb PacketCallback) error {
id := crc32.Checksum([]byte(strings.Join(endpoints, ",")), crc32.IEEETable)

cb(&pcapPacket{
streamID: id,
data: packet.LinkLayer().LayerPayload(),
streamID: id,
timestamp: packet.Metadata().Timestamp,
data: packet.LinkLayer().LayerPayload(),
}, nil)
}
}
Expand Down Expand Up @@ -91,10 +89,8 @@ func (p *pcapPacketIO) Close() error {

// Intentionally slow down the replay
// In realtime mode, this is to match the timestamps in the capture
// In non realtime mode, this helps to avoid flooding the workers
func (p *pcapPacketIO) wait(packet gopacket.Packet) error {
if !p.config.Realtime {
time.Sleep(p.config.ReplayDelay)
return nil
}

Expand All @@ -112,15 +108,19 @@ func (p *pcapPacketIO) wait(packet gopacket.Packet) error {
var _ Packet = (*pcapPacket)(nil)

type pcapPacket struct {
streamID uint32
data []byte
streamID uint32
timestamp time.Time
data []byte
}

func (p *pcapPacket) StreamID() uint32 {
return p.streamID
}

func (p *pcapPacket) Timestamp() time.Time {
return p.timestamp
}

func (p *pcapPacket) Data() []byte {
return p.data
}

0 comments on commit f01b79e

Please sign in to comment.