Fix several bugs in peer.js and enable it to successfully connect to a peer (tested with bitcoind).