Commit graph

416 commits

Author SHA1 Message Date
Wladimir J. van der Laan 9bbe71b641 net: Add and document network messages in protocol.h
- Avoids string typos (by making the compiler check)
- Makes it easier to grep for handling/generation of a certain message type
- Refer directly to documentation by following the symbol in IDE
- Move list of valid message types to protocol.cpp:
    protocol.cpp is a more appropriate place for this, and having
    the array there makes it easier to keep things consistent.
2015-12-10 12:14:06 +01:00
Wladimir J. van der Laan e3bc5e0e92 net: Account for sendheaders verack messages
Looks like these were forgotten in #6589.
2015-12-07 15:17:53 +01:00
Jonas Schnelli ca188c629e
log bytes recv/sent per command 2015-12-07 13:32:59 +01:00
Wladimir J. van der Laan 8843676621
Merge pull request #7133
aa4b0c2 When not filtering blocks, getdata sends more in one test (Pieter Wuille)
d41e44c Actually only use filterInventoryKnown with MSG_TX inventory messages. (Gregory Maxwell)
b6a0da4 Only use filterInventoryKnown with MSG_TX inventory messages. (Patick Strateman)
6b84935 Rename setInventoryKnown filterInventoryKnown (Patick Strateman)
e206724 Remove mruset as it is no longer used. (Gregory Maxwell)
ec73ef3 Replace setInventoryKnown with a rolling bloom filter. (Gregory Maxwell)
2015-12-03 13:16:46 +01:00
Wladimir J. van der Laan 1b5118bfa0
Merge pull request #7079
ebb25f4 Limit setAskFor and retire requested entries only when a getdata returns. (Gregory Maxwell)
5029698 prevent peer flooding request queue for an inv (kazcw)
2015-12-01 09:02:33 +01:00
Patick Strateman 6b849350ab Rename setInventoryKnown filterInventoryKnown 2015-11-30 12:53:48 +01:00
Gregory Maxwell ec73ef37ec Replace setInventoryKnown with a rolling bloom filter.
Mruset setInventoryKnown was reduced to a remarkably small 1000
 entries as a side effect of sendbuffer size reductions in 2012.

This removes setInventoryKnown filtering from merkleBlock responses
 because false positives there are especially unattractive and
 also because I'm not sure if there aren't race conditions around
 the relay pool that would cause some transactions there to
 be suppressed. (Also, ProcessGetData was accessing
 setInventoryKnown without taking the required lock.)
2015-11-30 12:53:48 +01:00
Luke Dashjr b966aa836a Constrain constant values to a single location in code 2015-11-28 18:47:29 +01:00
Gregory Maxwell ebb25f4c23 Limit setAskFor and retire requested entries only when a getdata returns.
The setAskFor duplicate elimination was too eager and removed entries
 when we still had no getdata response, allowing the peer to keep
 INVing and not responding.
2015-11-23 01:54:23 +00:00
kazcw 5029698186 prevent peer flooding request queue for an inv
mapAlreadyAskedFor does not keep track of which peer has a request queued for a
particular tx. As a result, a peer can blind a node to a tx indefinitely by
sending many invs for the same tx, and then never replying to getdatas for it.
Each inv received will be placed 2 minutes farther back in mapAlreadyAskedFor,
so a short message containing 10 invs would render that tx unavailable for 20
minutes.

This is fixed by disallowing a peer from having more than one entry for a
particular inv in mapAlreadyAskedFor at a time.
2015-11-23 01:18:54 +00:00
Peter Todd 08843ed998 Add relaytxes status to getpeerinfo 2015-11-20 16:07:12 -08:00
Patick Strateman 71a2683f4b Use DEFAULT_BLOCKSONLY and DEFAULT_WHITELISTALWAYSRELAY constants 2015-11-14 05:10:59 -08:00
Patick Strateman 4044f07d1c Add blocksonly mode 2015-11-14 04:52:21 -08:00
MarcoFalke b27e81f115 [net] Cleanup maxuploadtarget
* log: nMaxOutboundLimit is in bytes
* log: Hide misleading -maxuploadtarget=0 warning
* qa : Minor cleanup to maxuploadtarget rpc tests
* net: Use DEFAULT_MAX_UPLOAD_TARGET = 0
2015-11-12 20:45:57 +01:00
Wladimir J. van der Laan 09c1ae1c01 torcontrol improvements and fixes
- Force AUTHCOOKIE size to be 32 bytes: This provides protection against
  an attack where a process pretends to be Tor and uses the cookie
  authentication method to nab arbitrary files such as the
  wallet
- torcontrol logging
- fix cookie auth
- add HASHEDPASSWORD auth, fix fd leak when fwrite() fails
- better error reporting when cookie file is not ok
- better init/shutdown flow
- stop advertizing service when disconnected from tor control port
- COOKIE->SAFECOOKIE auth
2015-11-12 17:58:15 +01:00
Wladimir J. van der Laan 8f4e67f152 net: Automatically create hidden service, listen on Tor
Starting with Tor version 0.2.7.1 it is possible, through Tor's control socket
API, to create and destroy 'ephemeral' hidden services programmatically.
https://stem.torproject.org/api/control.html#stem.control.Controller.create_ephemeral_hidden_service

This means that if Tor is running (and proper authorization is available),
bitcoin automatically creates a hidden service to listen on, without user
manual configuration. This will positively affect the number of available
.onion nodes.

- When the node is started, connect to Tor through control socket
- Send `ADD_ONION` command
- First time:
    - Make it create a hidden service key
    - Save the key in the data directory for later usage
- Make it redirect port 8333 to the local port 8333 (or whatever port we're listening on).
- Keep control socket connection open for as long node is running. The hidden service will
  (by default) automatically go away when the connection is closed.
2015-11-10 17:29:56 +01:00
Jonas Schnelli 872fee3fcc
Introduce -maxuploadtarget
* -maxuploadtarget can be set in MiB
* if <limit> - ( time-left-in-24h-cycle / 600 * MAX_BLOCK_SIZE ) has reach, stop serve blocks older than one week and filtered blocks
* no action if limit has reached, no guarantee that the target will not be  surpassed
* add outbound limit informations to rpc getnettotals
2015-10-26 15:37:30 +01:00
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
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