Merge pull request #2 from buger/tcp-sessions

Add support for tcp sessions
This commit is contained in:
Leonid Bugaev
2016-07-31 20:28:42 +03:00
committed by GitHub
7 changed files with 265 additions and 32 deletions
+16 -5
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"io"
"time"
"hash/fnv"
)
// Start initialize loop for sending data from inputs to outputs
@@ -81,13 +82,23 @@ func CopyMulty(src io.Reader, writers ...io.Writer) (err error) {
}
if Settings.splitOutput {
// Simple round robin
writers[wIndex].Write(payload)
if Settings.recognizeTCPSessions {
hasher := fnv.New32a()
// First 20 bytes contain tcp session
id := payloadID(payload)
hasher.Write(id[:20])
wIndex++
wIndex = int(hasher.Sum32()) % len(writers)
writers[wIndex].Write(payload)
} else {
// Simple round robin
writers[wIndex].Write(payload)
if wIndex >= len(writers) {
wIndex = 0
wIndex++
if wIndex >= len(writers) {
wIndex = 0
}
}
} else {
for _, dst := range writers {