This is a code cleanup to help me better understand the network.py code.
Add typehints where the IDE cannot guees the type.
Use an Enum for interface modes for better type-safety and more helpful IDE assistance.
Remove an unused TCPConnection.protocol attribute.
Use the more modern NamedTuple class definition.