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
|
return c
|
||||||
elif c == '\0':
|
elif c == '\0':
|
||||||
return '␀'
|
return '␀'
|
||||||
|
elif c == '\r':
|
||||||
|
return '␍'
|
||||||
|
elif c == '\n':
|
||||||
|
return ''
|
||||||
else:
|
else:
|
||||||
return '·'
|
return '·'
|
||||||
|
|
||||||
|
|
19
ip.py
19
ip.py
|
@ -160,7 +160,8 @@ class Chunk:
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def __add__(self, next):
|
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():
|
for frame in self.collection.itervalues():
|
||||||
new.add(frame)
|
new.add(frame)
|
||||||
for frame in next.collection.itervalues():
|
for frame in next.collection.itervalues():
|
||||||
|
@ -229,24 +230,30 @@ class TCP_Session:
|
||||||
self.seq = [pkt.seq, pkt.ack]
|
self.seq = [pkt.seq, pkt.ack]
|
||||||
self.handle = self.handle_packet
|
self.handle = self.handle_packet
|
||||||
else:
|
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):
|
def handle_packet(self, pkt):
|
||||||
ret = None
|
ret = None
|
||||||
self.frames += 1
|
self.frames += 1
|
||||||
|
|
||||||
# Which way is this going?
|
# Which way is this going? 0 == from client
|
||||||
idx = int(pkt.src == self.srv)
|
idx = int(pkt.src == self.srv)
|
||||||
xdi = 1 - idx
|
xdi = 1 - idx
|
||||||
|
|
||||||
# Does this ACK after the last output sequence number?
|
# Does this ACK after the last output sequence number?
|
||||||
if pkt.ack > self.seq[xdi]:
|
seq = self.seq[xdi]
|
||||||
ret = Chunk(self.seq[xdi])
|
if pkt.ack > seq:
|
||||||
|
ret = Chunk(seq)
|
||||||
pending = self.pending[xdi]
|
pending = self.pending[xdi]
|
||||||
for key in pending.keys():
|
for key in pending.keys():
|
||||||
if key >= pkt.ack:
|
if key >= pkt.ack:
|
||||||
continue
|
continue
|
||||||
ret.add(pending[key])
|
if key >= seq:
|
||||||
|
ret.add(pending[key])
|
||||||
del pending[key]
|
del pending[key]
|
||||||
self.seq[xdi] = pkt.ack
|
self.seq[xdi] = pkt.ack
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue