mirror of https://github.com/dirtbags/netarch.git
Pick up TCP mid-stream
This commit is contained in:
parent
60d47e5350
commit
f210967a1d
|
@ -19,6 +19,10 @@ def to_printable(c):
|
|||
return c
|
||||
elif c == '\0':
|
||||
return '␀'
|
||||
elif c == '\r':
|
||||
return '␍'
|
||||
elif c == '\n':
|
||||
return ''
|
||||
else:
|
||||
return '·'
|
||||
|
||||
|
|
17
ip.py
17
ip.py
|
@ -160,7 +160,8 @@ class Chunk:
|
|||
return s
|
||||
|
||||
def __add__(self, next):
|
||||
new = Chunk(self.seq, self.drop)
|
||||
seq = min(self.seq, next.seq)
|
||||
new = Chunk(seq, self.drop)
|
||||
for frame in self.collection.itervalues():
|
||||
new.add(frame)
|
||||
for frame in next.collection.itervalues():
|
||||
|
@ -229,23 +230,29 @@ class TCP_Session:
|
|||
self.seq = [pkt.seq, pkt.ack]
|
||||
self.handle = self.handle_packet
|
||||
else:
|
||||
raise ValueError('Weird flags in handshake: %d' % pkt.flags)
|
||||
# In the middle of a session, do the best we can
|
||||
self.cli, self.srv = pkt.src, pkt.dst
|
||||
self.seq = [pkt.seq, pkt.ack]
|
||||
self.handle = self.handle_packet
|
||||
self.handle(pkt)
|
||||
|
||||
def handle_packet(self, pkt):
|
||||
ret = None
|
||||
self.frames += 1
|
||||
|
||||
# Which way is this going?
|
||||
# Which way is this going? 0 == from client
|
||||
idx = int(pkt.src == self.srv)
|
||||
xdi = 1 - idx
|
||||
|
||||
# Does this ACK after the last output sequence number?
|
||||
if pkt.ack > self.seq[xdi]:
|
||||
ret = Chunk(self.seq[xdi])
|
||||
seq = self.seq[xdi]
|
||||
if pkt.ack > seq:
|
||||
ret = Chunk(seq)
|
||||
pending = self.pending[xdi]
|
||||
for key in pending.keys():
|
||||
if key >= pkt.ack:
|
||||
continue
|
||||
if key >= seq:
|
||||
ret.add(pending[key])
|
||||
del pending[key]
|
||||
self.seq[xdi] = pkt.ack
|
||||
|
|
Loading…
Reference in New Issue