Inspiration

Wanted to learn about the challenges faced by TCP

What it does

Python implementation of TCP built on top of UDP. Uses TCP headers.

  • Robust against corruption, arbitrary delays, and dropped packets on the sending channel.
  • Implements RFC 6298 to calculate RTT and use that information to change the resend timeout.

How I built it

Wrote a naive implementation that assumed in-order, non-corrupt delivery. Then expanded it to handle dropped packets, reordered packets, and repeated packets.

Challenges I ran into

TCP is fairly stateful, so there were a lot of edge cases to consider. Also had to ensure malicious clients/servers couldn't cause their peers to transition into a incorrect state by sending invalid packets.

What I learned

I cut a lot of corners with performance --- first by using Python, and later by preferring straightforward, easy-to-verify code over performant code. Creating a production-ready TCP stack in C would be at least 50x harder.

What's next

Handling an ACK channel that can arbitrarily delay and lose packets. This will involve three-way handshaking for connection setup and teardown, as well as a lot more state management.

Built With

Share this project:

Updates