An individual TCP "message". Note that TCP is *stream-based* and not *message-based*. For practical purposes the stream is chunked into messages here, but you should not rely on message boundaries.
| 6 | |
| 7 | |
| 8 | class TCPMessage(serializable.Serializable): |
| 9 | """ |
| 10 | An individual TCP "message". |
| 11 | Note that TCP is *stream-based* and not *message-based*. |
| 12 | For practical purposes the stream is chunked into messages here, |
| 13 | but you should not rely on message boundaries. |
| 14 | """ |
| 15 | |
| 16 | def __init__(self, from_client, content, timestamp=None): |
| 17 | self.from_client = from_client |
| 18 | self.content = content |
| 19 | self.timestamp = timestamp or time.time() |
| 20 | |
| 21 | @classmethod |
| 22 | def from_state(cls, state): |
| 23 | return cls(*state) |
| 24 | |
| 25 | def get_state(self): |
| 26 | return self.from_client, self.content, self.timestamp |
| 27 | |
| 28 | def set_state(self, state): |
| 29 | self.from_client, self.content, self.timestamp = state |
| 30 | |
| 31 | def __repr__(self): |
| 32 | return "{direction} {content}".format( |
| 33 | direction="->" if self.from_client else "<-", content=repr(self.content) |
| 34 | ) |
| 35 | |
| 36 | |
| 37 | class TCPFlow(flow.Flow): |
no outgoing calls
searching dependent graphs…