2017-08-29

So, I got into the AI course. I was rejected the first time, and applied again but didn't really think I'd get in. This might throw off the Rust learning (or maybe I'll just start to implement some of the code).

As I was reviewing the first of my project ideas from last night, I started thinking about some of the challenges in doing them. I started writing a TCP proxy (still need to write the spec) in Go, but there were a few things that I ran into. My test setup helped me to flush out these issues and to test solutions.

The test setup was fairly basic: I proxied traffic over the loopback interface from port 8080 to the dev server for this site, listening on port 8000. The proxy test script, written in Python, would send the string "GET / HTTP/1.1\r\n\r\n" to the proxied address (127.0.0.1:8080), at which point the proxy should relay traffic to the dev server and return a page to the client. To test a few assumptions, I delay one second between each character. This script is invoked as

./proxy-tester GET / HTTP/1.1\\r\\n\\r\\n

The problem I ran into was that the receive in the proxy tester would timeout. Changing the script to parse \r and \n in a string into 0x0D and 0x0A, respectively, fixed this issue.

However, I first thought the problem was elsewhere, and built an over-complicated relay function that set read and write deadlines and copied data in chunks. It was interesting to read up on this, but I didn't need to worry about it in end, and I reverted back to a simple io.Copy.

I've started writing these programs in Go because it's still the language I'm most proficient in and it's faster than writing them in C; still, I hope to write C and Rust versions for these programs as well.


Tags: