Sink and duplex streams

We need these for replication over RPC, so I decided to take a stab at it. Let me know if there are any issues to fix.