bitcoinjs/node-bitcoin-p2p — Issue #54: Better handling for network parsing errors
Author: justmoon
Created: 2011-12-28 04:44:44+00:00
State: open

Sometimes, BitcoinJS will run into parsing errors. Usually, this is caused the by the node on the other side sending bogus messages. (The original client doesn't do a very good job at reporting parsing errors, so many alternative implementations don't notice bugs in their implementation.)

```
28 Dec 05:40:59 - error: Error while parsing message inv from [removed]:8333:
Error: oob
at Buffer.slice (buffer.js:516:32)
at Parser.buffer (/atlas/www/node-bitcoin-p2p/lib/parser.js:11:26)
at Parser. (/atlas/www/node-bitcoin-p2p/lib/parser.js:96:20)
at Function.parseMessage (/atlas/www/node-bitcoin-p2p/lib/connection.js:414:22)
at Connection.processData (/atlas/www/node-bitcoin-p2p/lib/connection.js:371:26)
at Connection.handleData (/atlas/www/node-bitcoin-p2p/lib/connection.js:307:8)
at Socket. (native)
at Socket.emit (events.js:88:20)
at TCP.onread (net.js:327:14)
```

We want to:

* Recover in those cases where we are able to. (Better fault isolation.)
* Otherwise disconnect the offending node and remove it from the known peers.
* Record a debug dump, containing the offending package, the remote node's sub-version - if available, the remote node's IP and the local node's version. (Disabled by default for security.)
* Print a shorter debug message with more useful information. (no stack trace, sub-version if available)