diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-10-19 15:25:39 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-10-19 20:26:05 +1300 |
commit | 24cf8da27eb56a65bf3e4ceb78bbeacdb1864597 (patch) | |
tree | fee98428fbf36897aa874fd91fe5c9738bf2626f /mitmproxy/tcp.py | |
parent | 5a68d21e8c87e05f2ad0c18e6c7c505f5e9fc93d (diff) | |
download | mitmproxy-24cf8da27eb56a65bf3e4ceb78bbeacdb1864597.tar.gz mitmproxy-24cf8da27eb56a65bf3e4ceb78bbeacdb1864597.tar.bz2 mitmproxy-24cf8da27eb56a65bf3e4ceb78bbeacdb1864597.zip |
Move all tools into mitmproxy.tools, move models/* to top level
The primary motivation here (and for all the other moving around) is to present
a clean "front of house" to library users, and to migrate primary objects to
the top of the module hierarchy.
Diffstat (limited to 'mitmproxy/tcp.py')
-rw-r--r-- | mitmproxy/tcp.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/mitmproxy/tcp.py b/mitmproxy/tcp.py new file mode 100644 index 00000000..af54c9d4 --- /dev/null +++ b/mitmproxy/tcp.py @@ -0,0 +1,53 @@ +import time + +from typing import List + +import netlib.basetypes +from mitmproxy import flow + + +class TCPMessage(netlib.basetypes.Serializable): + + def __init__(self, from_client, content, timestamp=None): + self.content = content + self.from_client = from_client + if timestamp is None: + timestamp = time.time() + self.timestamp = timestamp + + @classmethod + def from_state(cls, state): + return cls(*state) + + def get_state(self): + return self.from_client, self.content, self.timestamp + + def set_state(self, state): + self.from_client = state.pop("from_client") + self.content = state.pop("content") + self.timestamp = state.pop("timestamp") + + def __repr__(self): + return "{direction} {content}".format( + direction="->" if self.from_client else "<-", + content=repr(self.content) + ) + + +class TCPFlow(flow.Flow): + + """ + A TCPFlow is a simplified representation of a TCP session. + """ + + def __init__(self, client_conn, server_conn, live=None): + super().__init__("tcp", client_conn, server_conn, live) + self.messages = [] # type: List[TCPMessage] + + _stateobject_attributes = flow.Flow._stateobject_attributes.copy() + _stateobject_attributes.update( + messages=List[TCPMessage] + ) + + def __repr__(self): + return "<TCPFlow ({} messages)>".format(len(self.messages)) |