Some work on the p2p system

Fixes several bugs in peer.js and enables it to successfully connect to a peer (tested standalone with bitcoind).