Commit graph

453 commits

Author SHA1 Message Date
Gregory Maxwell a4e28b3d1e Set TCP_NODELAY on P2P sockets.
Nagle appears to be a significant contributor to latency now that the static
 sleeps are gone.  Most of our messages are relatively large compared to
 IP + TCP so I do not expect this to create enormous overhead.

This may also reduce traffic burstyness somewhat.
2015-10-22 17:57:48 +00:00
Philip Kaufmann e8600c924d banlist (bugfix): allow CNode::SweepBanned() to run on interval
- allows CNode::SweepBanned() to run, even if !CNode::BannedSetIsDirty(),
  because if nBanUntil is over we want the ban to be disabled for these
  nodes
2015-10-02 11:38:16 +02:00
Philip Kaufmann 2977c243ef banlist: add more banlist infos to log / add GUI signal
- to match the peers.dat handling also supply a debug.log entry for how
  many entries were loaded from banlist.dat and how long it took
- add a GUI init message for loading the banlist (same as with peers.dat)

- move the same message for peers.dat upwards in the code, to be able to
  reuse the timing variable nStart and also just log, if our read from
  peers.dat didn't fail
2015-10-02 11:38:16 +02:00
Philip Kaufmann ce479aaada banlist: better handling of banlist in StartNode()
- only start working on/with banlist data, if reading in the banlist from
  disk didn't fail
- as CNode::setBannedIsDirty is false (default) when reading fails, we
  don't need to explicitly set it to false to prevent writing
  banlist.dat in that case either
2015-10-02 11:38:15 +02:00
Philip Kaufmann 57c77fe4d3 banlist: update set dirty to be more fine grained
- move the SetBannedSetDirty(false) call from DumpData() into DumpBanlist()
- ensure we only set false, if the write succeeded
2015-10-02 11:38:14 +02:00
Wladimir J. van der Laan 93ff1b9041 net: correctly initialize nMinPingUsecTime
`nMinPingUsecTime` was left uninitialized in CNode.
The correct initialization for a minimum-until-now is int64_t's max value, so initialize it to that.
Thanks @MarcoFalke for noticing.
2015-09-04 16:27:38 +02:00
Matt Corallo a6eb4ba38b Report minimum ping time in getpeerinfo 2015-09-03 13:06:13 -07:00
Wladimir J. van der Laan 69dc5b51a0
Merge pull request #6374
027de94 Use network group instead of CNetAddr in final pass to select node to disconnect (Patrick Strateman)
000c18a Fix comment (Patrick Strateman)
fed3094 Acquire cs_vNodes before changing refrence counts (Patrick Strateman)
69ee1aa CNodeRef copy constructor and assignment operator (Patrick Strateman)
dc81dd0 Return false early if vEvictionCandidates is empty (Patrick Strateman)
17f3533 Better support for nodes with non-standard nMaxConnections (Patrick Strateman)
1317cd1 RAII wrapper for CNode* (Patrick Strateman)
df23937 Add comments to AttemptToEvictConnection (Patrick Strateman)
a8f6e45 Remove redundant whiteconnections option (Patrick Strateman)
b105ba3 Prefer to disconnect peers in favor of whitelisted peers (Patrick Strateman)
2c70153 AttemptToEvictConnection (Patrick Strateman)
4bac601 Record nMinPingUsecTime (Patrick Strateman)
ae037b7 Refactor: Move failure conditions to the top of AcceptConnection (Patrick Strateman)
1ef4817 Refactor: Bail early in AcceptConnection (Patrick Strateman)
541a1dd Refactor: AcceptConnection (Patrick Strateman)
2015-09-03 18:27:24 +02:00
Wladimir J. van der Laan af9305a7e8
Merge pull request #6583
9f3e48e add support for miniupnpc api version 14 (Pavel Vasin)
2015-08-31 17:38:07 +02:00
Patrick Strateman 027de94e1f
Use network group instead of CNetAddr in final pass to select node to disconnect 2015-08-30 22:09:14 -07:00
J Ross Nicoll 9bebf60698
Make sure LogPrint strings are line-terminated 2015-08-29 17:40:13 +01:00
Patrick Strateman 000c18aace Fix comment 2015-08-25 16:31:13 -07:00
Patrick Strateman fed30940ef Acquire cs_vNodes before changing refrence counts 2015-08-25 16:30:02 -07:00
Patrick Strateman 69ee1aab00 CNodeRef copy constructor and assignment operator 2015-08-25 15:33:29 -07:00
Cory Fields a19338723d net: Set SO_REUSEADDR for Windows too
When running the rpc tests in Wine, nodes often fail to listen on localhost
due to a stale socket from a previous run. This aligns the behavior with other
platforms.
2015-08-25 11:31:06 -04:00
Pavel Vasin 9f3e48e521 add support for miniupnpc api version 14
The value of new arg ttl is set to 2 as it's recommended default.
2015-08-23 23:53:49 +03:00
Patrick Strateman dc81dd02a1 Return false early if vEvictionCandidates is empty 2015-08-22 15:38:24 -07:00
Patrick Strateman 17f3533c84 Better support for nodes with non-standard nMaxConnections 2015-08-22 15:38:24 -07:00
Patrick Strateman 1317cd1928 RAII wrapper for CNode* 2015-08-22 15:38:24 -07:00
Patrick Strateman df23937422 Add comments to AttemptToEvictConnection 2015-08-22 15:38:24 -07:00
Patrick Strateman a8f6e45249 Remove redundant whiteconnections option 2015-08-22 15:38:24 -07:00
Patrick Strateman b105ba398b Prefer to disconnect peers in favor of whitelisted peers 2015-08-22 15:38:24 -07:00
Patrick Strateman 2c701537c8 AttemptToEvictConnection 2015-08-22 15:38:24 -07:00
Patrick Strateman ae037b707c Refactor: Move failure conditions to the top of AcceptConnection 2015-08-22 15:38:23 -07:00
Patrick Strateman 1ef4817614 Refactor: Bail early in AcceptConnection 2015-08-22 15:38:23 -07:00
Patrick Strateman 541a1dd9e6 Refactor: AcceptConnection 2015-08-22 15:38:23 -07:00
Veres Lajos 9f68ed6b6d typofixes (found by misspell_fixer) 2015-08-10 22:06:27 +01:00
Wladimir J. van der Laan c384800027
Merge pull request #6462
7b79cbd limit total length of user agent comments (Pavol Rusnak)
557f8ea implement uacomment config parameter which can add comments to user agent as per BIP-0014 (Pavol Rusnak)
2015-08-05 15:43:10 +02:00
Pavol Rusnak 7b79cbd722 limit total length of user agent comments
Reworked-By: Wladimir J. van der Laan <laanwj@gmail.com>
2015-08-05 09:38:20 +02:00
Matt Quinn 19dd40a25f Consolidate individual references to the current maximum peer connection
value of 125 into a single constant declaration.
2015-08-03 14:37:00 -07:00
Pavol Rusnak 557f8eac7a implement uacomment config parameter
which can add comments to user agent as per BIP-0014
2015-07-31 16:19:23 +02:00
Peter Todd d2d7ee0e86 Make CRollingBloomFilter set nTweak for you
While CBloomFilter is usually used with an explicitly set nTweak,
CRollingBloomFilter is only used internally. Requiring every caller to
set nTweak is error-prone and redundant; better to have the class handle
that for you with a high-quality randomness source.

Additionally when clearing the filter it makes sense to change nTweak as
well to recover from a bad setting, e.g. due to insufficient randomness
at initialization, so the clear() method is replaced by a reset() method
that sets a new, random, nTweak value.
2015-07-27 18:38:49 +02:00
Wladimir J. van der Laan ca37e0f339
Merge pull request #5697
60c8bac Includes: Cleanup around net main and wallet (Jorge Timón)
9dd793f TRIVIAL: Missing includes (Jorge Timón)
2015-07-27 14:40:29 +02:00
Jorge Timón 60c8bac77c Includes: Cleanup around net main and wallet
-Move from .h to .cpp: in main, net and wallet
-Remove unnecessary #include "main.h"
-Cleanup some wallet files includes
2015-07-23 21:10:26 +02:00
Wladimir J. van der Laan d2464dfee9
Merge pull request #6287
a794284 locking: add a quick example of GUARDED_BY (Cory Fields)
2b890dd locking: fix a few small issues uncovered by -Wthread-safety (Cory Fields)
cd27bba locking: teach Clang's -Wthread-safety to cope with our scoped lock macros (Cory Fields)
2015-07-23 18:45:26 +02:00
Pieter Wuille d422f9b1fd Test whether created sockets are select()able 2015-07-10 12:05:09 -04:00
Wladimir J. van der Laan 445220544e
Merge pull request #5288
e3cae52 Added -whiteconnections=<n> option (Josh Lehan)
2015-07-10 15:07:15 +02:00
Jonas Schnelli 177a0e4914 Adding CSubNet constructor over a single CNetAddr 2015-07-02 20:44:27 +02:00
Jonas Schnelli 409bccfbf5 use CBanEntry as object container for banned nodes
- added a reason enum for a ban
- added creation time for a ban

Using CBanEntry as container will keep banlist.dat extenable.
2015-07-02 20:29:36 +02:00
Jonas Schnelli dfa174c295 CAddrDB/CBanDB: change filesize variables from int to uint64_t 2015-07-02 20:29:36 +02:00
Jonas Schnelli f581d3d656 banlist.dat: store banlist on disk 2015-07-02 20:29:36 +02:00
Jonas Schnelli 62909f68a0 fix missing lock in CNode::ClearBanned() 2015-06-19 13:31:33 +02:00
Jonas Schnelli 4e36e9bcc7 setban: rewrite to UniValue, allow absolute bantime 2015-06-17 21:40:55 +02:00
Jonas Schnelli 433fb1a95d [RPC] extend setban to allow subnets 2015-06-17 21:40:55 +02:00
Jonas Schnelli e8b93473f1 [net] remove unused return type bool from CNode::Ban() 2015-06-17 21:40:55 +02:00
Jonas Schnelli 2252fb91cd [net] extend core functionallity for ban/unban/listban 2015-06-17 21:40:55 +02:00
Cory Fields 2b890dd424 locking: fix a few small issues uncovered by -Wthread-safety
- rpcwallet: No need to lock twice here
- openssl: Clang doesn't understand selective lock/unlock here. Ignore it.
- CNode: Fix a legitimate (though very unlikely) locking bug.
2015-06-16 04:04:02 -04:00
Josh Lehan e3cae52538 Added -whiteconnections=<n> option
This sets aside a number of connection slots for whitelisted peers,
useful for ensuring your local users and miners can always get in,
even if your limit on inbound connections has already been reached.
2015-06-14 02:07:15 -07:00
Philip Kaufmann a9ac95c1bc use const references where appropriate 2015-06-04 19:34:18 +02:00
Philip Kaufmann 49b22928ee [net, trivial] explicitly use std::string for FindNode
- in OpenNetworkConnection we have a FindNode call, which gets a const
  char*, wheras we only have defined a FindNode for std::string
2015-05-31 15:44:22 +02:00
Gavin Andresen 9a1dcea2df
Use CScheduler for net's DumpAddresses
Instead of starting Yet Another Thread to dump addresses,
use CScheduler to do it.
2015-05-14 12:50:42 -04:00
Pieter Wuille d4d5022cfc Use ring buffer of set iterators instead of deque of copies in mruset 2015-04-30 08:16:30 -07:00
Gavin Andresen d81cff32e5 Replace mruset setAddrKnown with CRollingBloomFilter addrKnown
Use a probabilistic bloom filter to keep track of which addresses
we think we have given our peers, instead of a list.

This uses much less memory, at the cost of sometimes failing to
relay an address to a peer-- worst case if the bloom filter happens
to be as full as it gets, 1-in-1,000.

Measured memory usage of a full mruset setAddrKnown: 650Kbytes
Constant memory usage of CRollingBloomFilter addrKnown: 37Kbytes.

This will also help heap fragmentation, because the 37K of storage
is allocated when a CNode is created (when a connection to a peer
is established) and then there is no per-item-remembered memory
allocation.

I plan on testing by restarting a full node with an empty peers.dat,
running a while with -debug=addrman and -debug=net, and making sure
that the 'addr' message traffic out is reasonable.
(suggestions for better tests welcome)
2015-04-30 08:16:20 -07:00
Wladimir J. van der Laan f026ab606d
Merge pull request #6059
739d615 chainparams: use SeedSpec6's rather than CAddress's for fixed seeds (Cory Fields)
2015-04-30 14:57:04 +02:00
pstratem 351593b9c8 replace absolute sleep with conditional wait 2015-04-27 11:48:31 -07:00
Cory Fields 739d6155d3 chainparams: use SeedSpec6's rather than CAddress's for fixed seeds
This negates the need for CAddress here at all
2015-04-24 14:32:39 -04:00
Pieter Wuille 1d5b47a903 nLastTry is only used for addrman entries
No need to define it for every CAddress, as it's memory only anyway.
2015-04-19 11:10:23 -07:00
Wladimir J. van der Laan f7dea1cba7
Merge pull request #5941
1d21ba2 Scale up addrman (Pieter Wuille)
c6a63ce Always use a 50% chance to choose between tried and new entries (Pieter Wuille)
f68ba3f Do not bias outgoing connections towards fresh addresses (Pieter Wuille)
a8ff7c6 Simplify hashing code (Pieter Wuille)
e6b343d Make addrman's bucket placement deterministic. (Pieter Wuille)
b23add5 Switch addrman key from vector to uint256 (Pieter Wuille)
2015-04-01 16:17:13 +02:00
Ruben de Vries fc720207e0 don't trickle for whitelisted nodes 2015-03-24 14:53:16 +01:00
Pieter Wuille c6a63ceeb4 Always use a 50% chance to choose between tried and new entries
This change was suggested as Countermeasure 2 in
Eclipse Attacks on Bitcoin’s Peer-to-Peer Network, Ethan Heilman,
Alison Kendler, Aviv Zohar, Sharon Goldberg. ePrint Archive Report
2015/263. March 2015.
2015-03-23 17:24:18 -07:00
Pieter Wuille 2f10aa0fa1
Merge pull request #5151
eec3713 make CMessageHeader a dumb storage class (Cory Fields)
2015-03-07 05:38:34 -08:00
Wladimir J. van der Laan dec84cae2a src/net.cpp: endian compatibility in EndMessage 2015-03-06 17:21:58 +01:00
Pieter Wuille ba04c4a780 Limit message sizes before transfer
This introduces a fixed limit for the size of p2p messages, and enforces it
before download.
2015-03-06 04:03:17 -08:00
Cory Fields eec37136fd make CMessageHeader a dumb storage class
It shouldn't know or care about bitcoind's chain param selection
2015-02-25 18:44:49 -05:00
Gregory Maxwell 28d4cff0ed Sanitize command strings before logging them.
Normally bitcoin core does not display any network originated strings without
 sanitizing or hex encoding.  This wasn't done for strcommand in many places.

This could be used to play havoc with a terminal displaying the logs,
 especially with printtoconsole in use.

Thanks to Evil-Knievel for reporting this issue.
2015-02-08 19:58:59 +00:00
Pavel Janík 5262fde0ec Remove whitespaces before double colon in errors and logs 2015-01-31 17:38:28 -05:00
Wladimir J. van der Laan 66b473457b
Delete RecvLine function
No longer necessary since #5161 / 845c86d128.
2015-01-20 18:03:20 +01:00
Wladimir J. van der Laan 729ba31749
Merge pull request #5513
856e862 namespace: drop most boost namespaces and a few header cleanups (Cory Fields)
9b1ab86 namespace: drop boost::assign altogether here (Cory Fields)
a324199 namespace: remove boost namespace pollution (Cory Fields)
2015-01-06 20:32:45 +01:00
Wladimir J. van der Laan 4f1524966a Replace direct use of 0 with SetNull and IsNull
Replace x=0 with .SetNull(),
x==0 with IsNull(), x!=0 with !IsNull().
Replace uses of uint256(0) with uint256().
2015-01-05 15:45:34 +01:00
Cory Fields a3241998e1 namespace: remove boost namespace pollution 2015-01-02 15:12:03 -05:00
Wladimir J. van der Laan c986972ad7
Merge pull request #5476
73caf47 Display time offset in the debug window's Peers tab (Pavel Janík)
26a6bae Add time offset to getpeerinfo output (Pavel Janík)
2015-01-02 17:54:21 +01:00
sandakersmann f914f1a746
Added "Core" to copyright headers
Github-Pull: #5494
Rebased-From: 15de949bb9277e442302bdd8dee299a8d6deee60
2014-12-19 19:55:32 +01:00
Wladimir J. van der Laan 111a7d45f1
Merge pull request #5470
78253fc Remove references to X11 licence (Michael Ford)
2014-12-19 19:23:23 +01:00
Wladimir J. van der Laan 6e718f9435
Remove outdated comment about NTP
The comment has been around since 0.1, but NTP inside the client
isn't deemed necessary so remove the comment to avoid confusion.
2014-12-19 16:26:27 +01:00
Philip Kaufmann 27df4123c4 make all catch() arguments const
- I saw this on http://en.cppreference.com/w/cpp/language/try_catch and
  thought it would be a good idea
- also unify used format to better be able to search for exception
  uses in our codebase
2014-12-17 09:39:24 +01:00
Michael Ford 78253fcbad Remove references to X11 licence 2014-12-16 15:56:50 +08:00
Pavel Janík 26a6bae753 Add time offset to getpeerinfo output 2014-12-15 11:06:15 +01:00
Wladimir J. van der Laan 800458eddd
Merge pull request #5408
35e408f Regard connection failures as attempt for addrman (Wladimir J. van der Laan)
2014-12-05 11:39:18 +01:00
Luke Dashjr d227011184 MOVEONLY: core/ -> primitives/ 2014-12-03 10:52:58 +00:00
Wladimir J. van der Laan 35e408f8a4 Regard connection failures as attempt for addrman
This avoids connecting to them again too soon in ThreadOpenConnections.

Make an exception for connection failures to the proxy as these
shouldn't affect the status of specific nodes.
2014-12-02 17:54:16 +01:00
Philip Kaufmann cd4d3f1915 Win32: change buffer size for gethotsname in Discover()
- 256 byte is the maximum, as per
  http://msdn.microsoft.com/en-us/library/windows/desktop/ms738527%28v=vs.85%29.aspx
2014-11-13 15:26:09 +01:00
Philip Kaufmann 8fa0494e92 Win32: log addresses found in Discover() calls 2014-11-13 15:25:44 +01:00
Gregory Maxwell 845c86d128 Do not use third party services for IP detection.
This is a simplified re-do of closed pull #3088.

This patch eliminates the privacy and reliability problematic use
of centralized web services for discovering the node's addresses
for advertisement.

The Bitcoin protocol already allows your peers to tell you what
IP they think you have, but this data isn't trustworthy since
they could lie. So the challenge is using it without creating a
DOS vector.

To accomplish this we adopt an approach similar to the one used
by P2Pool: If we're announcing and don't have a better address
discovered (e.g. via UPNP) or configured we just announce to
each peer the address that peer told us. Since peers could
already replace, forge, or drop our address messages this cannot
create a new vulnerability... but if even one of our peers is
giving us a good address we'll eventually make a useful
advertisement.

We also may randomly use the peer-provided address for the
daily rebroadcast even if we otherwise have a seemingly routable
address, just in case we've been misconfigured (e.g. by UPNP).

To avoid privacy problems, we only do these things if discovery
is enabled.
2014-11-07 12:13:46 -08:00
Cory Fields 71697f97d3 Separate protocol versioning from clientversion 2014-10-29 00:24:40 -04:00
jtimon 4a3587d8db MOVEONLY: Separate CTransaction and dependencies from core 2014-10-27 13:54:37 +01:00
Wladimir J. van der Laan a873823864
CAutoFile: Explicit Get() and remove unused methods
Also add documentation to some methods.
2014-10-22 10:18:19 +02:00
Ruben Dario Ponticeli fef24cab1a Add IsNull() to class CAutoFile and remove operator ! 2014-10-20 12:46:56 +02:00
Pieter Wuille 341735eb8f Headers-first synchronization
Many changes:
* Do not use 'getblocks', but 'getheaders', and use it to build a headers tree.
* Blocks are fetched in parallel from all available outbound peers, using a
  limited moving window. When one peer stalls the movement of the window, it is
  disconnected.
* No more orphan blocks. At all. We only ever request a block for which we have
  verified the headers, and store it to disk immediately. This means that a
  disk-fill attack would require PoW.
* Require protocol version 31800 for every peer (released in december 2010).
* No more syncnode (we sync from everyone we can, though limited to 1 during
  initial *headers* sync).
* Introduce some extra named constants, comments and asserts.
2014-10-14 15:42:01 -07:00
Wladimir J. van der Laan 992ab87114
Merge pull request #4942
9406471 Write fee estimate and peers files only when initialized (Wladimir J. van der Laan)
2014-10-14 11:35:17 +02:00
Cory Fields eee030f6bc autofile: don't copy CAutoFile by value 2014-09-25 19:25:19 -04:00
Wladimir J. van der Laan 94064710b9 Write fee estimate and peers files only when initialized
Fixes #4669.

Move the loading of addresses to StartNode() to make it more
self-contained.
2014-09-18 14:20:18 +02:00
Pieter Wuille 7388b74cd2
Merge pull request #4911
611116d header include cleanup (Philip Kaufmann)
2014-09-16 04:12:52 +02:00
Wladimir J. van der Laan 327dcfece7 Merge pull request #4869
6050ab6 netbase: Make SOCKS5 negotiation interruptible (Wladimir J. van der Laan)
2014-09-15 17:25:12 +02:00
ENikS ec91092df8
Fixing compiler warning C4101
Github-Pull: #4856
2014-09-15 14:35:32 +02:00
Philip Kaufmann 611116d4e3 header include cleanup
- ensures alphabetical ordering for includes etc. in source file headers
2014-09-14 12:43:56 +02:00
Wladimir J. van der Laan d6af9856b0
Merge pull request #4878
540ac45 Avoid returning many "inv" orphans (Jeff Garzik)
d4168c8 Limit CNode::mapAskFor (Wladimir J. van der Laan)
2014-09-10 16:52:57 +02:00
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