Siacoin/Sia — pull request #81 by lukechampine (2014-04-20 19:09:34+00:00)
Title: Add support for messages of arbitrary length

Messages are now encoded using a prefix-length scheme. The first four bytes of the message contain the length, encoded using `binary.PutUvarint()`. The next byte is an `Identifier`. The remainder is the payload. The receiving end simply `Read()`s until it has read `payloadLength` bytes.

Limitations:
- We assume that the sender is honest about how many bytes they are sending.
- In a similar vein, we assume that all the data will eventually be sent.

These can both be fixed by using a timeout.

I also added a `Close()` method to `TCPServer`, and client connections are now closed after they have been handled. Finally, I replaced the calls to `time.Sleep()` in `node_test.go` with a channel block, which is a lot more robust.