Network optimalizations

This pull request contains:
* The commits from #2016 and #2017
* Fixes and memory improvements for those
* A change from per-connection to per-message send buffers
* A change to break processing of getdata into several stages, when the send buffer fills up

This should improve network latency and memory usage.