Last active
May 4, 2021 04:42
-
-
Save jeanqasaur/dc06126bbfd648d5e3ee7775830056e4 to your computer and use it in GitHub Desktop.
Example of using StreamFactory, StreamPool, and Assembler for TCP packet parsing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (p *NetworkTrafficParser) ParseFromInterface( | |
interfaceName, bpfFilter string, signalClose <-chan struct{}, | |
fs ...akinet.TCPParserFactory) | |
(<-chan akinet.ParsedNetworkTraffic, error) { | |
// Read in packets, pass to assembler | |
packets, err := p.pcap.capturePackets(signalClose, | |
interfaceName, | |
bpfFilter) | |
if err != nil { | |
return nil, errors.Wrapf( | |
err, "failed begin capturing packets from %s", | |
interfaceName) | |
} | |
// Set up assembly | |
out := make(chan akinet.ParsedNetworkTraffic, 100) | |
streamFactory := newTCPStreamFactory( | |
p.clock, out, akinet.TCPParserFactorySelector(fs)) | |
streamPool := reassembly.NewStreamPool(streamFactory) | |
assembler := reassembly.NewAssembler(streamPool) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment