Skip to content

Commit 65f173d

Browse files
committed
Flushing and Closing connections - see #3
1 parent 8fdae4a commit 65f173d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

d4-tlsf.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ var outCerts = flag.String("w", "", "Folder to write certificates into")
4747
var outJSON = flag.String("j", "", "Folder to write certificates into, stdin if not set")
4848
var jobQ chan d4tls.TLSSession
4949

50-
const closeTimeout time.Duration = time.Hour * 24 // Closing inactive: TODO: from CLI
51-
const timeout time.Duration = time.Minute * 5 // Pending bytes: TODO: from CLI
50+
// flushing
51+
var flushEvery = flag.Int("flush", 5000, "Flush every N packets")
52+
var dtf, _ = time.ParseDuration("5m")
53+
var dtc, _ = time.ParseDuration("48h")
54+
var flushTf = flag.Duration("flushtf", dtf, "Flush older than t")
55+
var flushTc = flag.Duration("flushtc", dtc, "Close older that t")
5256

5357
var assemblerOptions = reassembly.AssemblerOptions{
5458
MaxBufferedPagesPerConnection: 16,
@@ -227,11 +231,9 @@ func (t *tcpStream) ReassembledSG(sg reassembly.ScatterGather, ac reassembly.Ass
227231
}
228232
}
229233

230-
// If the handshake is considered finished and we have not yet outputted it we ship it to output.
231234
if t.tlsSession.HandshakeComplete() && !t.queued {
232235
t.queueSession()
233236
}
234-
235237
}
236238
}
237239
}
@@ -373,9 +375,11 @@ func main() {
373375
}
374376
assembler.AssembleWithContext(packet.NetworkLayer().NetworkFlow(), tcp, &c)
375377
}
376-
//ref := packet.Metadata().CaptureInfo.Timestamp
377-
//flushed, closed := assembler.FlushWithOptions(reassembly.FlushOptions{T: ref.Add(time.Minute * 30), TC: ref.Add(time.Minute * 5)})
378-
//Debug("Forced flush: %d flushed, %d closed (%s)", flushed, closed, ref)
378+
if count%*flushEvery == 0{
379+
ref := packet.Metadata().CaptureInfo.Timestamp
380+
flushed, closed := assembler.FlushWithOptions(reassembly.FlushOptions{T: ref.Add(-*flushTf), TC: ref.Add(-*flushTc)})
381+
Debug("Forced flush: %d flushed, %d closed (%s)", flushed, closed, ref)
382+
}
379383
}
380384
}
381385

0 commit comments

Comments
 (0)