Reject non-canonically-encoded sizes

The length of vectors, maps, sets, etc are serialized using
Write/ReadCompactSize -- which, unfortunately, do not use a
unique encoding.

So deserializing and then re-serializing a transaction (for example)
can give you different bits than you started with. That doesn't
cause any problems that we are aware of, but it is exactly the type
of subtle mismatch that can lead to exploits.

With this pull, reading a non-canonical CompactSize throws an
exception, which means nodes will ignore 'tx' or 'block' or
other messages that are not properly encoded.

Please check my logic... but this change is safe with respect to
causing a network split. Old clients that receive
non-canonically-encoded transactions or blocks deserialize
them into CTransaction/CBlock structures in memory, and then
re-serialize them before relaying them to peers.

And please check my logic with respect to causing a blockchain
split: there are no CompactSize fields in the block header, so
the block hash is always canonical. The merkle root in the block
header is computed on a vector<CTransaction>, so
any non-canonical encoding of the transactions in 'tx' or 'block'
messages is erased as they are read into memory by old clients,
and does not affect the block hash. And, as noted above, old
clients re-serialize (with canonical encoding) 'tx' and 'block'
messages before relaying to peers.
Squashed 'src/leveldb/' changes from be1b0ff..936b461

936b461 Merge upstream LevelDB 1.13.
748539c LevelDB 1.13

git-subtree-dir: src/leveldb
git-subtree-split: 936b4613ea4551992e6096b1e05eeefc09a20e3b
Merge src/leveldb changes for LevelDB 1.13
improve wallet load time by removing duplicated calls to EC_KEY_check_key and adding a hash for vchPubKey/vchPrivKey entries in wallet.dat

backwards compatible with previous wallet.dat format
verify vchPubKey matches calculated public key unless fSkipCheck is set
Rename -tor to -onion to better reflect what it does.

I've seen users confused multiple times thinking they
 should be using -tor to set their tor proxy and then
 finding in horror that they were still connecting to
 the IPv4 internet.

Even Jeff guesses wrong about what the knob does, so
 I think we should rename it. This leaves the old
 knob working, we can pull it out completely in a
 later release.
[Fee logic] Don't count txins for priority to encourage sweeping.

This changes the priority calculation to not include the size of per-txin
 data including up to 110 bytes of scriptsig so that transactions which
 sweep up extra UTXO don't lose priority relative to ones that don't.

I'd toyed with some other variations, but it seems like any formulation
 which results in an incentive stronger than making them not count will
 sometimes create incentives to add extra outputs so that you have
 extra inputs to consume later.  The maximum credit is limited so that
 users don't lose the disincentive to stuff random data in their
 transactions, the limit of 110 is based on the size of a P2SH
 redemption with a compressed public key.

This shouldn't need a staged deployment because the priority is not
 used as a relay criteria, only a mining criteria.
Inline signature serializer

Instead of building a full copy of a CTransaction being signed, and
then modifying bits and pieces until its fits the form necessary
for computing the signature hash, use a wrapper serializer that
only serializes the necessary bits on-the-fly.

This makes it easier to see which data is actually being hash,
reduces load on the heap, and also marginally improves performances
(around 3-4us/sigcheck here). The performance improvements are much
larger for large transactions, though.

The old implementation of SignatureHash is moved to a unit tests,
to test whether the old and new algorithm result in the same value
for randomly-constructed transactions.
special case DoS value == 0 in ProcessMessage()

- prevents unneeded log messages, which could make users think something
  bad was happening
Added ping time measurement.
New RPC "ping" command to request ping.
Implemented "pong" message handler.
New "pingtime" field in getpeerinfo, to provide results to user.
New "pingwait" field, to show pings still in flight, to better see newly lagging peers.
Merge pull request #3047 from Diapolo/misbehave

special case DoS value == 0
Remove CENT-output free transaction rule when relaying

Remove the (relay/mempool) rule that all outputs of free transactions
must be greater than 0.01 XBT. Dust spam is now taken care of by making
dusty outputs non-standard.
Lower maximum size for free transaction creation

Changes the maximum size of a free transaction that will be created
from 10,000 bytes to 1,000 bytes.

The idea behind this change is to make the free transaction area
available to a greater number of people; with the default 27K-per-block,
just three very-large very-high-priority transactions could fill the space.
Hurricane Electric uses block 2001:470::, not 2011:470::
Bitcoin-Qt: prevent stuck/unusable debug window on exit

- when closing the client with an open debug window, that window could
  become stuck/unsuable (it was still shown wherea the main window was
  hidden already)
- fix this by hiding the debug window, when quitting the the client
Merge pull request #3053 from dajohi/master

Hurricane Electric uses block 2001:470::, not 2011:470::
Merge pull request #3056 from Diapolo/stuck_debug_window

Bitcoin-Qt: prevent stuck/unusable debug window on exit
add missing Boost Thread join_all() call during shutdown

- fixes #3037 by adding missing join_all() call and brings bitcoind
  shutdown code in line with Bitcoin-Qt shutdown code
- added a comment for the if (!fRet) case
style-police: fixed badly readable code in ProcessMessage()

- I introduced the problem and fixed it with better readable code
Merge pull request #3064 from Diapolo/style

style-police: fixed badly readable code in ProcessMessage()