Shutdown cleanup prep-work

Create a boost::thread_group object at the qt/bitcoind main-loop level
that will hold pointers to all the main-loop threads.

This will replace the vnThreadsRunning[] array.

For testing, ported the BitcoinMiner threads to use its
own boost::thread_group.

Conflicts:
	src/main.cpp
LoopForever and ThreadTrace helpers
Use a copy in place of mapMultiArgs["-addnode"].

Also moves the DNS lookup of -addnode nodes into the repeated
loop, allowing -addnode to follow DNS changes.

Conflicts:
	src/net.cpp
Make ThreadOpenAddedConnections2 exit quicker if(GetNameProxy()).

Conflicts:
	src/net.cpp
Try more than the first address for a DNS -addnode.

Conflicts:
	src/net.cpp
Add addnode RPC command.

Conflicts:
	src/bitcoinrpc.cpp
	src/bitcoinrpc.h
	src/rpcnet.cpp
Add a getaddednodeinfo RPC.

Conflicts:
	src/bitcoinrpc.cpp
	src/bitcoinrpc.h
	src/rpcnet.cpp
RPC, cosmetic: push down ReadHTTPStatus() calls into ReadHTTP() callers

ReadHTTPStatus() is currently overloaded:  In client mode, it properly parses
and receives an HTTP status line.  In server mode, it incorrectly parses the
HTTP request line as an HTTP status line.

This server mode bug has never mattered, because the RPC server never
cared about the URI (path) provided in the HTTP request.  That will change in
the future, so go ahead and begin fixing the problem.

This patch is cosmetic, and should result in NO behavior changes.

Further renames:
ReadHTTPHeader -> ReadHTTPHeaders
ReadHTTP -> ReadHTTPMessage
RPC: HTTP server uses its own ReadHTTPRequestLine()
rather than reusing ReadHTTPStatus() from the client mode.

The following additional HTTP request validations are added, both in line with
existing HTTP client practice:

1) HTTP method must be GET or POST.  Most clients use POST, some
   use GET.  Either way, this continues to work.
2) HTTP URI must start with "/" character.
   Normal URI is "/" (a 1-char string), so this is fine.
Port Thread* methods to boost::thread_group

Conflicts:
	src/bitcoinrpc.cpp
	src/checkqueue.h
	src/init.cpp
	src/main.cpp
	src/main.h
	src/net.cpp
	src/net.h
	src/test/test_bitcoin.cpp
port stake miner to boost::thread_group
Clean up shutdown process

Conflicts:
	src/init.cpp
	src/init.h
	src/main.cpp
	src/net.cpp
	src/net.h
	src/txdb.cpp
	src/util.cpp
	src/util.h
	src/walletdb.cpp
Have Qt poll for shutdown requested, the QT way.

Conflicts:
	src/qt/bitcoin.cpp
	src/qt/bitcoingui.cpp
	src/qt/bitcoingui.h
Reimplement click-to-pay links. Add OSX support.

Switch to using Qt's QLocalServer/QLocalSocket to handle bitcoin
payment links (bitcoin:... URIs)

Reason for switch: the boost::interprocess mechanism seemed flaky,
and doesn't mesh as well with "The Qt Way"

qtipcserver.cpp/h is replaced by paymentserver.cpp/h

Click-to-pay now also works on OSX, with a custom Info.plist
that registers Bitcoin-Qt as a handler for bitcoin: URLs and
an event listener on the main QApplication that handles
QFileOpenEvents (Qt translates 'url clicked' AppleEvents into
QFileOpenEvents automagically).

Conflicts:
	src/qt/bitcoin.cpp
	src/qt/qtipcserver.cpp
	src/qt/qtipcserver.h
build: prepare to move DetectShutdownThread
Use boost::asio::deadline_timer for walletpassphrase timeout

New method in bitcoinrpc:  RunLater, that uses a map of deadline
timers to run a function later.

Behavior of walletpassphrase is changed; before, calling
walletpassphrase again before the lock timeout passed
would result in: Error: Wallet is already unlocked.

You would have to call lockwallet before walletpassphrase.

Now: the last walletpassphrase with correct password
wins, and overrides any previous timeout.

Fixes issue# 1961 which was caused by spawning too many threads.

Test plan:

Start with encrypted wallet, password 'foo'
NOTE:
 python -c 'import time; print("%d"%time.time())'
... will tell you current unix timestamp.

Try:

walletpassphrase foo 600
getinfo
EXPECT: unlocked_until is about 10 minutes in the future

walletpassphrase foo 1
sleep 2
sendtoaddress mun74Bvba3B1PF2YkrF4NsgcJwHXXh12LF 11
EXPECT: Error: Please enter the wallet passphrase with walletpassphrase first.

walletpassphrase foo 600
walletpassphrase foo 0
getinfo
EXPECT: wallet is locked (unlocked_until is 0)

walletpassphrase foo 10
walletpassphrase foo 600
getinfo
EXPECT: wallet is unlocked until 10 minutes in future

walletpassphrase foo 60
walletpassphrase bar 600
EXPECT: Error, incorrect passphrase
getinfo
EXPECT: wallet still scheduled to lock 60 seconds from first (successful) walletpassphrase

Conflicts:
	src/bitcoinrpc.cpp
	src/rpcwallet.cpp
changes to thread code (directly use boost::thread)

- removes our NewThread() function an replaces remaining calls with
  boost::thread with our TraceThread template
- remove ExitThread() function
- fix THREAD_PRIORITY_ABOVE_NORMAL for non Windows OSes

Conflicts:
	src/net.cpp
Dump addresses every 15 minutes instead of 10 seconds

Conflicts:
	src/net.cpp
Add ThreadGetMyExternalIP to net thread group

Fixes #3372 -- crash at shutdown.
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