mirror of
https://github.com/apernet/OpenGFW.git
synced 2024-12-22 17:09:21 +08:00
rebase and remove replayDelay
This commit is contained in:
parent
94387450cf
commit
f01b79e625
@ -137,7 +137,6 @@ func initConfig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
viper.SetDefault("replay.realtime", true)
|
viper.SetDefault("replay.realtime", true)
|
||||||
viper.SetDefault("replay.replayDelay", 10 * time.Millisecond)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func initLogger() {
|
func initLogger() {
|
||||||
@ -185,7 +184,6 @@ type cliConfigIO struct {
|
|||||||
|
|
||||||
type cliConfigReplay struct {
|
type cliConfigReplay struct {
|
||||||
Realtime bool `mapstructure:"realtime"`
|
Realtime bool `mapstructure:"realtime"`
|
||||||
ReplayDelay time.Duration `mapstructure:"replayDelay"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type cliConfigWorkers struct {
|
type cliConfigWorkers struct {
|
||||||
@ -216,7 +214,6 @@ func (c *cliConfig) fillIO(config *engine.Config) error {
|
|||||||
ioImpl, err = io.NewPcapPacketIO(io.PcapPacketIOConfig{
|
ioImpl, err = io.NewPcapPacketIO(io.PcapPacketIOConfig{
|
||||||
PcapFile: pcapFile,
|
PcapFile: pcapFile,
|
||||||
Realtime: c.Replay.Realtime,
|
Realtime: c.Replay.Realtime,
|
||||||
ReplayDelay: c.Replay.ReplayDelay,
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// Setup IO for nfqueue
|
// Setup IO for nfqueue
|
||||||
|
20
io/pcap.go
20
io/pcap.go
@ -24,7 +24,6 @@ type pcapPacketIO struct {
|
|||||||
type PcapPacketIOConfig struct {
|
type PcapPacketIOConfig struct {
|
||||||
PcapFile string
|
PcapFile string
|
||||||
Realtime bool
|
Realtime bool
|
||||||
ReplayDelay time.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPcapPacketIO(config PcapPacketIOConfig) (PacketIO, error) {
|
func NewPcapPacketIO(config PcapPacketIOConfig) (PacketIO, error) {
|
||||||
@ -34,8 +33,6 @@ func NewPcapPacketIO(config PcapPacketIOConfig) (PacketIO, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
print(config.ReplayDelay)
|
|
||||||
|
|
||||||
return &pcapPacketIO{
|
return &pcapPacketIO{
|
||||||
pcap: handle,
|
pcap: handle,
|
||||||
lastTime: nil,
|
lastTime: nil,
|
||||||
@ -58,8 +55,9 @@ func (p *pcapPacketIO) Register(ctx context.Context, cb PacketCallback) error {
|
|||||||
id := crc32.Checksum([]byte(strings.Join(endpoints, ",")), crc32.IEEETable)
|
id := crc32.Checksum([]byte(strings.Join(endpoints, ",")), crc32.IEEETable)
|
||||||
|
|
||||||
cb(&pcapPacket{
|
cb(&pcapPacket{
|
||||||
streamID: id,
|
streamID: id,
|
||||||
data: packet.LinkLayer().LayerPayload(),
|
timestamp: packet.Metadata().Timestamp,
|
||||||
|
data: packet.LinkLayer().LayerPayload(),
|
||||||
}, nil)
|
}, nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,10 +89,8 @@ func (p *pcapPacketIO) Close() error {
|
|||||||
|
|
||||||
// Intentionally slow down the replay
|
// Intentionally slow down the replay
|
||||||
// In realtime mode, this is to match the timestamps in the capture
|
// 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 {
|
func (p *pcapPacketIO) wait(packet gopacket.Packet) error {
|
||||||
if !p.config.Realtime {
|
if !p.config.Realtime {
|
||||||
time.Sleep(p.config.ReplayDelay)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,15 +108,19 @@ func (p *pcapPacketIO) wait(packet gopacket.Packet) error {
|
|||||||
var _ Packet = (*pcapPacket)(nil)
|
var _ Packet = (*pcapPacket)(nil)
|
||||||
|
|
||||||
type pcapPacket struct {
|
type pcapPacket struct {
|
||||||
streamID uint32
|
streamID uint32
|
||||||
data []byte
|
timestamp time.Time
|
||||||
|
data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *pcapPacket) StreamID() uint32 {
|
func (p *pcapPacket) StreamID() uint32 {
|
||||||
return p.streamID
|
return p.streamID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *pcapPacket) Timestamp() time.Time {
|
||||||
|
return p.timestamp
|
||||||
|
}
|
||||||
|
|
||||||
func (p *pcapPacket) Data() []byte {
|
func (p *pcapPacket) Data() []byte {
|
||||||
return p.data
|
return p.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user