Commit graph

407 commits

Author SHA1 Message Date
Wladimir J. van der Laan 6050ab6855 netbase: Make SOCKS5 negotiation interruptible
Avoids that SOCKS5 negotiation will hold up the shutdown process.

- Sockets can stay in non-blocking mode, no need to switch it on/off
  anymore
- Adds a timeout (20 seconds) on SOCK5 negotiation. This should be
  enough for even Tor to get a connection to a hidden service, and
  avoids blocking the opencon thread indefinitely on a hanging proxy.

Fixes #2954.
2014-09-10 11:33:13 +02:00
Philip Kaufmann 2c2cc5dac1
Remove some unnecessary c_strs() in logging and the GUI
Includes `core: remove unneeded c_str() / Qt: replace c_str() with Qt code`
by P. Kaufmann.
2014-09-09 11:31:17 +02:00
Wladimir J. van der Laan d4168c82be Limit CNode::mapAskFor
Tighten resource constraints on CNode.
2014-09-09 09:19:15 +02:00
Wladimir J. van der Laan 65b529ba93
Merge pull request #4833
bbda402 net: Remove MilliSleep from StopNode (Wladimir J. van der Laan)
2014-09-04 13:31:15 +02:00
Wladimir J. van der Laan bbda40226b
net: Remove MilliSleep from StopNode
I don't understand why it would be there in the first place. This looks
like voodoo, not programming.
2014-09-03 12:23:34 +02:00
phantomcircuit 9189f5fe4d remove useless millisleep
reduces time to service requests improving performance
2014-09-02 21:25:53 -07:00
Wladimir J. van der Laan 70352e11c0
Revert "Add a getutxos command to the p2p protocol. It allows querying of the UTXO set"
This reverts commit da2ec100f3.
2014-08-27 18:04:29 +02:00
Wladimir J. van der Laan ad49c256c3 Split up util.cpp/h
Split up util.cpp/h into:

- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)

The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).

Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-26 13:25:22 +02:00
Wladimir J. van der Laan 651480c8e4 move functions in main and net to implementation files 2014-08-26 13:25:21 +02:00
Wladimir J. van der Laan 11270ebde4
Merge pull request #4351
da2ec10 Add a getutxos command to the p2p protocol. It allows querying of the UTXO set given a set of outpoints. (Mike Hearn)
2014-08-25 10:37:40 +02:00
Wladimir J. van der Laan 04d6c7d10c
Merge pull request #4605
aa82795 Add detailed network info to getnetworkinfo RPC (Wladimir J. van der Laan)
075cf49 Add GetNetworkName function (Wladimir J. van der Laan)
c91a947 Add IsReachable(net) function (Wladimir J. van der Laan)
60dc8e4 Allow -onlynet=onion to be used (Wladimir J. van der Laan)
2014-08-18 13:37:54 +02:00
Wladimir J. van der Laan c33b983903
Don't poll showmyip.com, it doesn't exist anymore
Fixes #4679.

This leaves us with only one candidate, checkip.dyndns.org.
GetMyExternalIP should be phased out as soon as possible.
2014-08-13 12:00:30 +02:00
Mike Hearn da2ec100f3 Add a getutxos command to the p2p protocol. It allows querying of the UTXO set
given a set of outpoints.
2014-08-11 13:59:47 +02:00
Wladimir J. van der Laan c91a9471be Add IsReachable(net) function
Allows other parts of the program to query for reachable
status of a network. Similar to IsLimited(net).
2014-07-30 15:41:17 +02:00
Jeff Garzik 2e7009d67b Avoid querying DNS seeds, if we have open connections.
The goal is to increase independence and privacy.
2014-07-29 11:04:46 -04:00
Wladimir J. van der Laan c5eabde9ea
Merge pull request #4491
eaedb59 net: add SetSocketNonBlocking() as OS independent wrapper (Philip Kaufmann)
2014-07-28 14:05:54 +02:00
Wladimir J. van der Laan 3955c3940e
Merge pull request #4584
0430c30 Add missing FindNode prototype to net.h (Wladimir J. van der Laan)
2014-07-25 11:06:11 +02:00
Wladimir J. van der Laan 0430c30af1 Add missing FindNode prototype to net.h
Also make the argument a const std::string & instead of pass-by-value.
2014-07-24 17:28:47 +02:00
Philip Kaufmann f469f79ff8 remove an unneded .c_str() in OpenNetworkConnection() 2014-07-21 15:00:42 +02:00
Philip Kaufmann c994d2e769 prevent SOCKET leak in BindListenPort()
- the call to CloseSocket() is placed after the WSAGetLastError(), because
  a CloseSocket() can trigger an error also, which we don't want for the
  logging in this two cases
2014-07-17 22:49:23 +02:00
Philip Kaufmann eaedb59e05 net: add SetSocketNonBlocking() as OS independent wrapper 2014-07-17 22:12:44 +02:00
Wladimir J. van der Laan 43f510d37d Convert closesocket 'compat wrapper' to function in netbase
Simpler alternative to #4348.

The current setup with closesocket() is strange. It poses
as a compatibility wrapper but adds functionality.

Rename it and make it a documented utility function in netbase.

Code movement only, zero effect on the functionality.
2014-07-17 15:46:25 +02:00
Wladimir J. van der Laan 6513a9f703
Merge pull request #4400
4eedf4f make RandAddSeed() use OPENSSL_cleanse() (Philip Kaufmann)
6354935 move rand functions from util to new random.h/.cpp (Philip Kaufmann)
001a53d add GetRandBytes() as wrapper for RAND_bytes() (Philip Kaufmann)
2014-07-14 11:35:30 +02:00
Pieter Wuille dc942e6f27 Introduce whitelisted peers.
This adds a -whitelist option to specify subnet ranges from which peers
that connect are whitelisted. In addition, there is a -whitebind option
which works like -bind, except peers connecting to it are also
whitelisted (allowing a separate listen port for trusted connections).

Being whitelisted has two effects (for now):
* They are immune to DoS disconnection/banning.
* Transactions they broadcast (which are valid) are always relayed,
  even if they were already in the mempool. This means that a node
  can function as a gateway for a local network, and that rebroadcasts
  from the local network will work as expected.

Whitelisting replaces the magic exemption localhost had for DoS
disconnection (local addresses are still never banned, though), which
implied hidden service connects (from a localhost Tor node) were
incorrectly immune to DoS disconnection as well. This old
behaviour is removed for that reason, but can be restored using
-whitelist=127.0.0.1 or -whitelist=::1 can be specified. -whitebind
is safer to use in case non-trusted localhost connections are expected
(like hidden services).
2014-07-09 20:40:14 +02:00
Philip Kaufmann 001a53d742 add GetRandBytes() as wrapper for RAND_bytes()
- add a small wrapper in util around RAND_bytes() and replace with
  GetRandBytes() in the code to log errors from calling RAND_bytes()
- remove OpenSSL header rand.h where no longer needed
2014-07-09 09:42:18 +02:00
Wladimir J. van der Laan e1f7c7d173
Merge pull request #4472
9f4da19 Use pong receive time rather than processing time (Pieter Wuille)
2014-07-07 06:28:43 +02:00
Pieter Wuille 9f4da19bab Use pong receive time rather than processing time 2014-07-06 16:08:18 +02:00
R E Broadley 2e36866fec Show nodeid instead of addresses (for anonymity) unless otherwise requested. 2014-07-04 09:38:44 +07:00
Philip Kaufmann 5d59921237 add missing BOOST_FOREACH indentation in ThreadSocketHandler() 2014-06-26 11:01:24 +02:00
Philip Kaufmann 9e9ca2b671 small cleanup of #ifdefs in BindListenPort()
- SO_NOSIGPIPE isn't available on WIN32 so merge the 2 non-WIN32 blocks
- use predefined names from header for IPV6_PROTECTION_LEVEL and
  PROTECTION_LEVEL_UNRESTRICTED
2014-06-26 11:01:23 +02:00
Cory Fields f3967bcc50 build: fix build weirdness after 54372482.
bitcoin-config.h moved, but the old file is likely to still exist when
reconfiguring or switching branches. This would've caused files to not rebuild
correctly, and other strange problems.

Make the path explicit so that the old one cannot be found.

Core libs use config/bitcoin-config.h.

Libs (like crypto) which don't want access to bitcoin's headers continue
to use -Iconfig and #include bitcoin-config.h.
2014-06-23 14:04:38 -04:00
Wladimir J. van der Laan 52d4abfdef
Merge pull request #4388
3dc1464 add missing vhListenSocket.clear(); to CNetCleanup() (Philip Kaufmann)
2831a03 remove unused CNode::Cleanup() (Philip Kaufmann)
2014-06-23 10:21:38 +02:00
Pieter Wuille d4e4e05435
Merge pull request #4309
d38da59 Code simplifications after CTransaction::GetHash() caching (Pieter Wuille)
4949004 Add CMutableTransaction and make CTransaction immutable. (Pieter Wuille)
2014-06-22 20:45:30 +02:00
Philip Kaufmann 3dc1464f0a add missing vhListenSocket.clear(); to CNetCleanup() 2014-06-22 14:52:38 +02:00
Philip Kaufmann 2831a03b79 remove unused CNode::Cleanup() 2014-06-22 14:51:38 +02:00
Pieter Wuille d38da59bf6 Code simplifications after CTransaction::GetHash() caching 2014-06-22 00:06:17 +02:00
Pieter Wuille 806fd19ecb Allocate receive buffers in on the fly 2014-06-21 17:00:38 +02:00
Wladimir J. van der Laan 3f39b9d455
Merge pull request #2784
f1920e8 Ping automatically every 2 minutes (unconditionally) (Pieter Wuille)
2014-06-12 12:40:09 +02:00
Philip Kaufmann 634bd61b76 convert an if into an else if in OpenNetworkConnection() 2014-06-11 12:40:13 +02:00
Philip Kaufmann 5bd6c31bd6 small cleanup of net
- remove an unneded else in ConnectNode()
- make 0 a double and change to 0.0 in ConnectNode()
- rename strDest to pszDest in OpenNetworkConnection()
- remove an unneded call to our REF() macro in BindListenPort()
- small style cleanups and removal of unneeded new-lines
2014-06-11 12:38:31 +02:00
Pieter Wuille f1920e8606 Ping automatically every 2 minutes (unconditionally)
... instead of after 30 minutes of no sending, for latency measurement
and keep-alive. Also, disconnect if no reply arrives within 20 minutes,
instead of 90 of inactivity (for peers supporting the 'pong' message).
2014-06-09 23:06:56 +02:00
Jeff Garzik c79897af31 Merge pull request #4247 from Diapolo/listen
rename fNoListen to fListen and move to net
2014-06-04 15:00:38 -04:00
Huang Le 09a54a65c0 Use pnode->nLastRecv as sync score directly
NodeSyncScore() should find the node which we recv data most recently, so put a negative sign to pnode->nLastRecv is indeed wrong.

Also change the return value type to int64_t.

Signed-off-by: Huang Le <4tarhl@gmail.com>
2014-05-30 23:44:44 +08:00
Philip Kaufmann 53a088154c rename fNoListen to fListen and move to net
- better code readability and it belongs to net
- this is a prerequisite for a pull to add -listen to the GUI
2014-05-29 14:01:39 +02:00
Wladimir J. van der Laan 67f43a99ae
Merge pull request #4132
d4e1c61 add DEFAULT_UPNP constant in net (Philip Kaufmann)
2014-05-29 11:46:28 +02:00
Wladimir J. van der Laan 97b53b581b
Merge pull request #4152
3e8ac6a Replace non-threadsafe gmtime and setlocale (Wladimir J. van der Laan)
a60838d Replace non-threadsafe strerror (Wladimir J. van der Laan)
2014-05-23 15:52:45 +02:00
Wladimir J. van der Laan a60838d09a Replace non-threadsafe strerror
Log the name of the error as well as the error code if a network problem
happens. This makes network troubleshooting more convenient.

Use thread-safe strerror_r and the WIN32 equivalent FormatMessage.
2014-05-23 09:45:04 +02:00
Philip Kaufmann d4e1c61212 add DEFAULT_UPNP constant in net
- as this is a shared Core/GUI setting, this makes it easier to keep them
  in sync (also no new includes are needed)
2014-05-20 15:34:19 +02:00
Cozz Lovan b641c9cd21 Fix addnode "onetry": Connect with OpenNetworkConnection 2014-05-10 00:39:49 +02:00
Wladimir J. van der Laan d387b8ec15 rpc: add getblockchaininfo and getnetworkinfo
Adds two new info query commands that take over information from
hodge-podge `getinfo`.

Also some new information is added:
- `getblockchaininfo`
  - `chain`: (string) current chain (main, testnet3, regtest)
  - `verificationprogress: (numeric) estimated verification progress
  - `chainwork`
- `getnetworkinfo`
  - `localaddresses`: (array) local addresses, from mapLocalHost (fixes #1734)
2014-05-06 09:34:54 +02:00
Philip Kaufmann 2fdd4c7933 better std::exception logging for CAddrDb
- also small logging text changes
2014-05-02 14:35:30 +02:00
Wladimir J. van der Laan e27c4110d9 Remove build-time no-IPv6 setting
The year is 2014. All supported operating systems have IPv6 support,
most certainly at build time (this doesn't mean that IPv6 is configured,
of course).

If noone is exercising the functionality to disable it, that means it
doesn't get tested, and IMO it's better to get rid of it.

(it's also not used consistently in RPC/boost and Net code...)
2014-05-01 12:15:36 +02:00
Gregory Maxwell d20791b0e5 Prevent socket leak in ThreadSocketHandler.
When we are over our outbound limit ThreadSocketHandler would try to
 keep the connection if the peer was addnoded.

This didn't actually work for two reasons: It didn't actually run
 the accept code due to mistaken code flow, and because we have a
 limited number of outbound semaphores it couldn't actually use the
 connection.

Instead it leaked the socket, which might have caused issue #4034.

This patch just takes out the non-functioning white-listing for now.
2014-04-09 09:30:36 -07:00
Wladimir J. van der Laan ebb783a9f2
Merge pull request #3603
a486abd replace custom GetFilesize() with boost::filesystem::file_size() (Philip Kaufmann)
2014-03-27 11:38:34 +01:00
Michagogo d30d379beb Slightly tweak error when unable to bind port
A slight improvement over 2d2d8fae3d -- we don't know that it's the daemon, it could be the GUI.
2014-03-05 18:25:35 +02:00
paveljanik 2d2d8fae3d Clarify the error message when unable to bind to port 2014-03-05 10:42:52 +01:00
paveljanik 094eeff0ba Bitcoin is running fine...
When bitcoind can't bind, bitcoin server (or Bitcoin Core Daemon) is probably already running. Add the missing word "server". Bitcoin itself is definitely running ;-)

Add _(...) so the string can be localized.

I apologize for such trivial changes, learning github interface.
2014-03-05 00:02:18 +01:00
Philip Kaufmann a486abd419 replace custom GetFilesize() with boost::filesystem::file_size() 2014-03-03 22:33:09 +01:00
Wladimir J. van der Laan f48742c2bf Get rid of C99 PRI?64 usage in source files
Amend to d5f1e72. It turns out that BerkelyDB was including inttypes.h
indirectly, so we cannot fix this with just macros.

Trivial commit: apply the following script to all .cpp and .h files:

    # Middle
    sed -i 's/"PRIx64"/x/g' "$1"
    sed -i 's/"PRIu64"/u/g' "$1"
    sed -i 's/"PRId64"/d/g' "$1"
    # Initial
    sed -i 's/PRIx64"/"x/g' "$1"
    sed -i 's/PRIu64"/"u/g' "$1"
    sed -i 's/PRId64"/"d/g' "$1"
    # Trailing
    sed -i 's/"PRIx64/x"/g' "$1"
    sed -i 's/"PRIu64/u"/g' "$1"
    sed -i 's/"PRId64/d"/g' "$1"

After this commit, `git grep` for PRI.64 should turn up nothing except
the defines in util.h.
2014-02-24 09:08:56 +01:00
gubatron 57702541a2 Copyright header updates s/2013/2014 on files whose last git commit was done in 2014.
contrib/devtools/fix-copyright-headers.py script to be able to perform this maintenance task with ease during the rest of the year, every year. Modifications to contrib/devtools/README.md to document what fix-copyright-headers.py does.
2014-02-09 21:06:06 -05:00
Wladimir J. van der Laan 7d9d134bf9 Remove redundant .c_str()s
After the tinyformat switch sprintf() family functions support passing
actual std::string objects.

Remove unnecessary c_str calls (236 of them) in logging and formatting.
2014-01-23 16:05:01 +01:00
Thomas Holenstein df840de5da
Make bitcoin compile without wallet if "db_cxx.h" is not present
Moved includes of "db.h" into #ifdef ENABLE_WALLET blocks or remove
them.
2013-12-19 10:46:41 +01:00
Wladimir J. van der Laan 7266bb1bdc
Merge pull request #3373
80ecf67 Add ThreadGetMyExternalIP to net thread group (Gavin Andresen)
2013-12-09 12:27:59 +01:00
Gavin Andresen 80ecf6702a Add ThreadGetMyExternalIP to net thread group
Fixes #3372 -- crash at shutdown.
2013-12-09 14:10:10 +10:00
Pieter Wuille b2864d2fb3 Add main-specific node state 2013-12-08 14:51:37 +01:00
Wladimir J. van der Laan d004d7279f Move CAddrDB frrom db to net
This was a leftover from the times in which
peers.dat depended in BDB.

Other functions in db.cpp still depend on BerkelyDB,
to be able to compile without BDB this (small)
functionality needs to be moved to another file.
2013-12-04 12:46:13 +01:00
Mike Hearn a946aa8d3e Store and use a sanitized subVer 2013-11-26 13:26:00 +01:00
Wladimir J. van der Laan d980f9b7d6
Merge pull request #3257
379778b core: remove includes in .cpp, if header is already in .h (Philip Kaufmann)
2013-11-20 16:18:33 +01:00
Philip Kaufmann fabba0e6cc orphan spaces cleanup ;-) 2013-11-15 12:24:34 +01:00
Philip Kaufmann 379778bde6 core: remove includes in .cpp, if header is already in .h
- example: if util.h includes stdint.h, remove it from util.cpp, as
  util.h is the first header included in util.cpp
2013-11-15 12:20:16 +01:00
Brandon Dahler 51ed9ec971 Cleanup code using forward declarations.
Use misc methods of avoiding unnecesary header includes.
Replace int typedefs with int##_t from stdint.h.
Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h.
Normalize QT_VERSION ifs where possible.
Resolve some indirect dependencies as direct ones.
Remove extern declarations from .cpp files.
2013-11-10 09:36:28 -06:00
Patrick Strateman 75ef87dd93 process received messages one at a time without sleeping between messages 2013-11-03 20:25:50 -08:00
Gavin Andresen 9038b18f46 -fuzzmessagestest=N : randomly corrupt 1-of-N sent messages
I needed this to test the new "reject" p2p message, but it should be generally
useful for fuzz-testing network message handling code.
2013-10-29 11:20:14 +10:00
Josh Lehan 547c61f8d8 Adding new "addrlocal" field to RPC getpeerinfo.
The existing CNode::addrLocal member is revealed to the user,
as an address string, similar to the existing "addr" field.
Instead of showing garbage or empty string,
it simply will not appear in the output if local address not known yet.
2013-10-21 02:23:05 -07:00
Gavin Andresen 749230d05c Merge pull request #2840 from sipa/nosendlock
Allow SendMessages to run partially without cs_main
2013-10-20 19:06:53 -07:00
Pieter Wuille 9b1200c23b
Merge pull request #3119
db0e8cc Bump Year Number to 2013 (super3)
2013-10-20 22:25:44 +02:00
super3 db0e8ccd90 Bump Year Number to 2013 2013-10-20 15:25:06 -04:00
Pieter Wuille 49d754d915 Run node deletions outside of cs_vNodes 2013-10-15 22:34:25 +02:00
Wladimir J. van der Laan f0c25cf6ec Merge pull request #2924 from sje397/TrafficGraph
[QT] Add network traffic graph to debug window
2013-10-15 03:48:22 -07:00
Gavin Andresen b9beea6e9d Merge pull request #3077 from sipa/chain
Refactor/encapsulate chain globals into a CChain class
2013-10-14 20:39:00 -07:00
Scott Ellis ce14345a89 Add network traffic graph 2013-10-14 19:02:03 +11:00
Pieter Wuille 4c6d41b8b6 Refactor/encapsulate chain globals into a CChain class 2013-10-11 23:25:50 +02:00
Josh Lehan 971bb3e901 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.
2013-10-04 01:30:12 -07:00
Gavin Andresen 881a85a22d Replace printf with LogPrintf / LogPrint 2013-09-18 20:39:25 +10:00
Cory Fields 35b8af9226 autotools: switch to autotools buildsystem 2013-09-05 21:31:03 -04:00
Jeff Garzik 3d86e7cd48 Merge pull request #2618 from fcicq/solaris-support
Partial solaris support
2013-08-24 20:19:24 -07:00
Gavin Andresen 050d2e953f Remove #define loop from util.h
Replace the loop macro with while (true). The #define caused
problems for Qt.
2013-07-31 14:06:44 +10:00
fcicq 98148a713e Fix fcntl include in net.cpp & netbase.cpp 2013-07-17 16:51:40 +08:00
Philip Kaufmann b3e0aaf36e fix invalid conversion error with MinGW 4.8.1 in net.cpp
- fixes src\net.cpp:1601: Error:invalid conversion from 'void*' to
  'const char*' [-fpermissive] in a setsockopt() call on Win32 that was
  found by using MinGW 4.8.1 compiler suite
2013-07-13 13:05:04 +02:00
Pieter Wuille c43da3f183 Dump addresses every 15 minutes instead of 10 seconds 2013-06-24 11:48:14 +02:00
Mike Hearn 0e4b317555 Introduce a CChainParameters singleton class and regtest mode.
The new class is accessed via the Params() method and holds
most things that vary between main, test and regtest networks.
The regtest mode has two purposes, one is to run the
bitcoind/bitcoinj comparison tool which compares two separate
implementations of the Bitcoin protocol looking for divergence.

The other is that when run, you get a local node which can mine
a single block instantly, which is highly convenient for testing
apps during development as there's no need to wait 10 minutes for
a block on the testnet.
2013-06-19 16:28:52 +02:00
bitsofproof c87f462b74 send tx relay flag with version 2013-06-11 23:29:41 +02:00
Philip Kaufmann 53e71135de 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
2013-06-10 19:49:54 +02:00
Eric Lombrozo 6e68524e95 Removed the main.h include from net.cpp. 2013-06-06 00:04:33 -07:00
Eric Lombrozo 501da2503a Using boost::signals2 to message main from net.cpp. 2013-06-05 23:15:20 -07:00
Eric Lombrozo 663224c232 Removed net.cpp's dependency on init.h.
Added explicit include of main.h in init.cpp, changed include of init.h to include of main.h in net.cpp.

Added function registration for net.cpp in init.cpp's network initialization.

Removed protocol.cpp's dependency on main.h.

TODO: Remove main.h include in net.cpp.
2013-06-05 20:36:10 -07:00
Eric Lombrozo 4751d07efd Moved unrelated-to-network calls in StartNode and StopNode into init.cpp 2013-06-05 20:36:10 -07:00
Eric Lombrozo 8926263dde Moved PushGetBlocks to main.cpp to eliminate dependence of net.cpp on CBlockLocator. 2013-06-05 20:36:10 -07:00
Pieter Wuille a9d9f0f5f7 Do not kill connections on recv buffer overflow
Instead of killing a connection when the receive buffer overflows,
just temporarily halt receiving before that happens. Also, no
matter what, always allow at least one full message in the receive
buffer (otherwise blocks larger than the configured buffer size
would pause indefinitely).
2013-05-01 20:56:50 +02:00
Pieter Wuille ba29a5590b Try to increase file descriptor rlimit if necessary
As the default can be too low, especially on OSX.
2013-04-29 01:46:24 +02:00
Wladimir J. van der Laan d23fa49c52 move WSAStartup to init
WSAStartup should be called before using any other socket
functions. BindListenPort is not called if not listening.

Closes #2585.
2013-04-28 08:54:27 +02:00
Gavin Andresen 1fd3ed25be Merge pull request #2461 from sipa/syncnode
Make sure we always have a node to do IBD from
2013-04-09 10:51:06 -07:00
Jeff Garzik 1483aac5f9 net.cpp: Do not change primary process name from (default) to "bitcoin-start"
Discussed a bit on IRC.
2013-04-08 22:02:57 -04:00
Pieter Wuille b7b774d82f Merge pull request #2419 from sipa/noreltime
Drop release times for CNode
2013-04-08 08:21:06 -07:00
Pieter Wuille 86648a8d16 Add bytessent, bytesrecv and syncnode to getpeerinfo 2013-04-07 19:31:13 +02:00
Pieter Wuille 6ed71b5e4f Make sure we always have a node to do IBD from
This introduces the concept of the 'sync node', which is the one we
asked for missing blocks. In case the sync node goes away, a new one
will be selected.

For now, the heuristic is very simple, but it can easily be extended
later to add better policies.
2013-04-07 19:19:13 +02:00
Philip Kaufmann b001c87126 small indentation, space, formatting fixes (no code changes) 2013-04-06 02:29:33 +02:00
Pieter Wuille cedaa71446 Drop release times for CNode
It seems there were two mechanisms for assessing whether a CNode
was still in use: a refcount and a release timestamp. The latter
seems to have been there for a long time, as a safety mechanism.

However, this timer also keeps CNode objects alive for far longer
than necessary after disconnects, potentially opening up a DoS
window.

This commit removes the timestamp-based mechanism, and replaces
it with an assert(nRefCount >= 0), to verify that the refcounting
is indeed correctly working.
2013-04-04 14:45:45 +02:00
Gavin Andresen aaf47eac3a Merge pull request #2423 from TheBlueMatt/limitedmapalreadyaskedfor
Limited mapAlreadyAskedFor
2013-04-03 18:31:35 -07:00
Gavin Andresen b31499ec72 Clean up shutdown process 2013-04-03 19:57:53 -04:00
Gavin Andresen 21eb5adadb Port Thread* methods to boost::thread_group 2013-04-03 19:57:13 -04:00
Gavin Andresen 1b43bf0d3a Rename util.h Sleep --> MilliSleep
Two reasons for this change:
1. Need to always use boost::thread's sleep, even on Windows, so the
sleeps can be interrupted (prior code used Windows' built-in Sleep).

2. I always forgot what units the old Sleep took.
2013-04-03 14:04:21 -04:00
Gavin Andresen c8c2fbe07f 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.
2013-04-03 14:04:21 -04:00
Gavin Andresen d8aae1ce1d Merge pull request #2420 from sipa/globclean
Global cleanups
2013-04-02 10:00:31 -07:00
Matt Corallo b5afda67f2 Move mapAlreadyAskedFor to limitedmap
This will result in re-requesting invs if we are under heavy inv
load, however as long as we get no more than 16,000 invs in two
minutes, this should have no effect on runtime behavior.
2013-04-01 11:56:23 -04:00
Jeff Garzik a0cafb7945 Move GenerateBitcoins() call out of net.cpp's StartNode()
The internal miner is closely bound to the wallet engine,
not the blockchain engine.
2013-03-31 01:54:27 -04:00
Pieter Wuille 41b052ad87 Use per-message send buffer, rather than per connection 2013-03-29 23:56:26 +01:00
Pieter Wuille 967f24590b Some fixes to CNetMessage processing
* Change CNode::vRecvMsg to be a deque instead of a vector (less copying)
* Make sure to acquire cs_vRecvMsg in CNode::CloseSocketDisconnect (as it
  may be called without that lock).
2013-03-29 23:56:26 +01:00
Jeff Garzik b9ff2970b9 P2P: improve RX/TX flow control
1) "optimistic write": Push each message to kernel socket buffer immediately.

2) If there is write data at select time, that implies send() blocked
   during optimistic write.  Drain write queue, before receiving
   any more messages.

This avoids needlessly queueing received data, if the remote peer
is not themselves receiving data.

Result: write buffer (and thus memory usage) is kept small, DoS
potential is slightly lower, and TCP flow control signalling is
properly utilized.

The kernel will queue data into the socket buffer, then signal the
remote peer to stop sending data, until we resume reading again.
2013-03-29 23:56:25 +01:00
Jeff Garzik bc2f5aa72c P2P, cosmetic: break out buffer send(2) code into separate function 2013-03-29 23:56:25 +01:00
Jeff Garzik 607dbfdeaf P2P: parse network datastream into header/data components in socket thread
Replaces CNode::vRecv buffer with a vector of CNetMessage's.  This simplifies
ProcessMessages() and eliminates several redundant data copies.

Overview:

* socket thread now parses incoming message datastream into
  header/data components, as encapsulated by CNetMessage
* socket thread adds each CNetMessage to a vector inside CNode
* message thread (ProcessMessages) iterates through CNode's CNetMessage vector

Message parsing is made more strict:

* Socket is disconnected, if message larger than MAX_SIZE
  or if CMessageHeader deserialization fails (latter is impossible?).
  Previously, code would simply eat garbage data all day long.
* Socket is disconnected, if we fail to find pchMessageStart.
  We do not search through garbage, to find pchMessageStart.  Each
  message must begin precisely after the last message ends.

ProcessMessages() always processes a complete message, and is more efficient:

* buffer is always precisely sized, using CDataStream::resize(),
  rather than progressively sized in 64k chunks.  More efficient
  for large messages like "block".
* whole-buffer memory copy eliminated (vRecv -> vMsg)
* other buffer-shifting memory copies eliminated (vRecv.insert, vRecv.erase)
2013-03-29 23:56:25 +01:00
Pieter Wuille 3427517d50 Clean up global datastructures at shutdown.
This should make detecting leaks much easier.
2013-03-29 02:24:18 +01:00
Matt Corallo 6a1d6e03da Add a new testnet dnsseed (currently only static list, will update) 2013-03-24 20:02:18 -04:00
Matt Corallo c2efd981aa (finally) Remove IRC Seed support now that lfnet is down. 2013-03-24 19:38:19 -04:00
Peter Todd af8998824c Add DNS seed support for testnet 2013-01-29 23:13:17 -05:00
Gavin Andresen 74fbb151de New seed nodes, from http://bitcoin.sipa.be/seeds.txt 2013-01-29 17:53:02 -05:00
Matt Corallo f2bd6c28e6 Try more than the first address for a DNS -addnode. 2013-01-27 03:03:04 -05:00
Matt Corallo f339e9e339 Make ThreadOpenAddedConnections2 exit quicker if(GetNameProxy()). 2013-01-27 03:03:04 -05:00
Matt Corallo 74088e862e 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.
2013-01-27 03:03:04 -05:00
Matt Corallo 4c8fc1a588 Let a node opt out of tx invs before we get a their bloom filter
Note that the default value for fRelayTxes is false, meaning we
now no longer relay tx inv messages before receiving the remote
peer's version message.
2013-01-16 12:48:02 -05:00
Matt Corallo d3b26f7077 Automatically add any matching outputs to a filter during matching. 2013-01-16 12:48:02 -05:00
Matt Corallo 269d9c6492 Replace RelayMessage with RelayTransaction. 2013-01-16 12:48:02 -05:00
Pieter Wuille c2b72ba27f Remove fClient
Client (SPV) mode never got implemented entirely, and whatever part was already
working, is likely not been tested (or even executed at all) for the past two
years. This removes it entirely.

If we want an SPV implementation, I think we should first get the block chain
data structures to be encapsulated in a class implementing a standard interface,
and then writing an alternate implementation with SPV semantics.
2013-01-09 22:28:46 +01:00
Wladimir J. van der Laan 578fc80003 Merge pull request #1932 from Diapolo/thread_printf
fix some thread related log messages
2012-10-30 23:19:35 -07:00
Pieter Wuille 344620e953 Merge pull request #1904 from laanwj/2012_10_remove_getorder
remove "checkorder" P2P command
2012-10-25 11:41:22 -07:00
Philip Kaufmann 847593228d fix some thread related log messages
- "ThreadIRCSeed started" was not displayed, even if the thread ran
  (although only for a short time as the "do we want this thread?"-checks
  happen IN ThreadIRCSeed2())
- the patch ensures we always get that message
- add a "ThreadIRCSeed trying to connect..." message
- add missing "ThreadDumpAddress started" message
2012-10-25 16:12:40 +02:00
Wladimir J. van der Laan ac0ad5dc63 Merge pull request #1901 from laanwj/2012_10_remove_strlcpy
get rid of strlcpy.h
2012-10-11 00:39:51 -07:00
Wladimir J. van der Laan 6032e4f4e7 get rid of strlcpy.h
Don't use hand-rolled string manipulation routine with a fixed
buffer in the bitcoin core, instead make use of c++ strings and boost.
2012-10-07 14:38:37 +02:00
Philip Kaufmann 81bbef2609 add LOCK() for proxy related data-structures
- fix #1560 by properly locking proxy related data-structures
- update GetProxy() and introduce GetNameProxy() to be able to use a
  thread-safe local copy from proxyInfo and nameproxyInfo
- update usage of GetProxy() all over the source to match the new
  behaviour, as it now fills a full proxyType object
- rename GetNameProxy() into HaveNameProxy() to be more clear
2012-10-04 09:35:24 +02:00
Wladimir J. van der Laan 529a4d4824 remove "checkorder" and "reply" P2P commands
These command are a leftover from send-to-IP transactions, which have been
removed a long time ago.
Also removes CNode::mapRequests and CNode::PushRequests, as these were
only used for the mentioned commands.
2012-10-03 20:09:33 +02:00
Philip Kaufmann d210f4f5b8 fix -Wformat warnings all over the source 2012-10-01 19:45:42 +02:00
Pieter Wuille 2e3ffb2d82 Remove stack randomization 2012-09-28 21:53:28 +02:00
Philip Kaufmann 463a1cab43 fix signed/unsigned in strprintf and CNetAddr::GetByte()
- I checked every occurance of strprintf() in the code and used %u, where
  unsigned vars are used
- the change to GetByte() was made, as ip is an unsigned char
2012-09-12 21:30:47 +02:00
Wladimir J. van der Laan f106491fa2 Merge pull request #1786 from jgarzik/select-fix
select()'s first argument should be zero, if no file descriptors are selected
2012-09-06 23:30:22 -07:00
Philip Kaufmann 4bd34b4966 replace 2x WSAGetLastError() with 1x WSAGetLastError() call 2012-09-05 22:20:26 +02:00
Jeff Garzik 2387944782 select(): Use precise fd presence check, rather than imprecise hSocketMax test 2012-09-05 16:01:28 -04:00
Jeff Garzik 2fd6f067db Merge pull request #1777 from laanwj/2012_09_eliminate_sprintf
Remove last occurrence of potentially insecure function sprintf
2012-09-04 09:00:02 -07:00
Wladimir J. van der Laan 9c80909452 Remove last occurrence of potentially insecure function sprintf.
%d can return up to 11 characters. Move away from fixed buffer completely and
use our own safe function strprintf.
2012-09-03 16:18:16 +02:00
Wladimir J. van der Laan 4d1d94c56c Rename CreateThread to NewThread
Prevent clash with win32 API symbol
2012-08-29 20:25:37 +02:00
Pieter Wuille af4da4be3d Bugfix: increase score, not port 2012-08-29 02:33:25 +02:00