Commit graph

1228 commits

Author SHA1 Message Date
fanquake
b9416c3847
Merge bitcoin/bitcoin#25096: [net] Minor improvements to addr caching
292828cd77 [test] Test addr cache for multiple onion binds (dergoegge)
3382905bef [net] Seed addr cache randomizer with port from binding address (dergoegge)
f10e80b6e4 [net] Use ConnectedThroughNetwork() instead of GetNetwork() to seed addr cache randomizer (dergoegge)

Pull request description:

  The addr cache id randomizer is currently supposed to be seeded with the network of the inbound connection and the local socket (only the address is used not the port):  a8098f2cef/src/net.cpp (L2800-L2804)

  For inbound onion connections `CNode::addr.GetNetwork()` returns `NET_UNROUTABLE` and `CNode::addrBind` is set to `127.0.0.1:<onion bind port>`. This results in the same addr cache for all inbound connections on 127.0.0.1 binds.

  To avoid the same addr cache across all onion and other 127.0.0.1 binds, we should seed the addr cache randomizer with the correct network for inbound onion connections (using `CNode::ConnectedThroughNetwork()`) as well as the port of `CNode::addrBind`.

ACKs for top commit:
  sipa:
    utACK 292828cd77
  mzumsande:
    Code Review ACK 292828cd77
  naumenkogs:
    utACK 292828cd77

Tree-SHA512: d0be13bab6bc121c2926d4b168687f6c2ed4ce0c9dd19be71eb4886adeba8afc3daacdc4e232a0ba3b03a89d69b618abc5595b69abd1ad0c476d825bc6ea1f9f
2022-06-08 11:21:38 +01:00
Jon Atack
d40550d725 scripted-diff: remove duplicate categories from LogPrint output
-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" src | xargs sed -i "s/$1/$2/g"; }
s 'BCLog::TOR, "tor: '       'BCLog::TOR, "'
s 'BCLog::I2P, "I2P: '       'BCLog::I2P, "'
s 'BCLog::NET, "net: '       'BCLog::NET, "'
s 'BCLog::ZMQ, "zmq: '       'BCLog::ZMQ, "'
s 'BCLog::PRUNE, "Prune: '   'BCLog::PRUNE, "'
-END VERIFY SCRIPT-
2022-06-06 12:12:03 +02:00
dergoegge
3382905bef [net] Seed addr cache randomizer with port from binding address 2022-06-02 19:03:54 +02:00
MarcoFalke
fa72e0ba15
Use designated initializers 2022-06-01 20:06:01 +02:00
laanwj
c4e7717727 refactor: Change LogPrintLevel order to category, severity
This is more consistent with the other functions, as well as with the
logging output itself. If we want to make this change, we should do it
before it's all over the place.
2022-05-25 11:31:58 +02:00
laanwj
90e49c1ece
Merge bitcoin/bitcoin#24464: logging: Add severity level to logs
e11cdc9303  logging: Add log severity level to net.cpp (klementtan)
a8290649a6 logging: Add severity level to logs. (klementtan)

Pull request description:

  **Overview**: This PR introduces a new macro, `LogPrintLevel`, that allows developers to add logs with the severity level. Additionally, it will also print the log category if it is specified.

  Sample log:
  ```
  2022-03-04T16:41:15Z [opencon] [net:debug] trying connection XX.XX.XXX.XXX:YYYYY lastseen=2.7hrs
  ```

  **Motivation**: This feature was suggested in #20576 and I believe that it will bring the following benefits:
  * Allow for easier filtering of logs in `debug.log`
  * Can be extended to allow users to select the minimum level of logs they would like to view (not in the scope of this PR)

  **Details**:
  * New log format. `... [category:level]...`. ie:
    * Do not print category if `category == NONE`
    * Do not print level if `level == NONE`
    * If `category == NONE` and `level == NONE`, do not print any fields (current behaviour)
  * Previous logging functions:
    * `LogPrintf`:  no changes in log as it calls `LogPrintf_` with `category = NONE` and `level = NONE`
    * `LogPrint`: prints additional `[category]` field as it calls `LogPrintf_` with `category = category` and `level = NONE`
  * `net.cpp`: As a proof of concept, updated logs with obvious severity (ie prefixed with `Warning/Error:..`) to use the new logging with severity.

  **Testing**:
  * Compiling and running `bitcoind` with this PR should instantly display logs with the category name (ie `net/tor/...`)
  * Grepping for `net:debug` in `debug.log` should display the updated logs with severity level:
    <details>
    <summary>Code</summary>

    ```
    $ grep "net:debug" debug.log

    2022-03-04T16:41:15Z [opencon] [net:debug] trying connection XXX:YYY lastseen=2.7hrs
    2022-03-04T16:41:16Z [opencon] [net:debug] trying connection XXX:YYY lastseen=16.9hrs
    2022-03-04T16:41:17Z [opencon] [net:debug] trying connection XXX:YYY lastseen=93.2hrs
    2022-03-04T16:41:18Z [opencon] [net:debug] trying connection XXX:YYY lastseen=2.7hrs
    ```
    </details>

ACKs for top commit:
  laanwj:
    Code review and lightly tested ACK e11cdc9303

Tree-SHA512: 89a8c86667ccc0688e5acfdbd399aac1f5bec9f978a160e40b0210b0d9b8fdc338479583fc5bd2e2bc785821363f174f578d52136d228e8f638a20abbf0a568f
2022-05-24 19:32:45 +02:00
klementtan
e11cdc9303
logging: Add log severity level to net.cpp 2022-05-19 21:05:43 +08:00
fanquake
7aa40f5563
refactor: use C++11 default initializers 2022-05-17 17:18:58 +01:00
Jon Atack
51ec96b904 refactor: move StartExtraBlockRelayPeers from header to implementation
where all the other logging actions in src/net.{h,cpp} are located.

StartExtraBlockRelayPeers() does not appear to be a hotspot that needs to be
inlined for performance, as it is called from CheckForStaleTipAndEvictPeers(),
called in turn from StartScheduledTasks() with a scheduleEvery delta of 45
seconds, called at the end of AppInitMain() on bitcoind startup.

This allows dropping `#include <logging.h>` from net.h, which can improve
compile time/speed. Currently, none of the other includes in net.h use
logging.h, except src/sync.h if DEBUG_LOCKCONTENTION is defined.
2022-05-12 17:41:32 +02:00
MacroFake
a2a8e919ee
Merge bitcoin/bitcoin#24925: refactor: make GetRand a template, remove GetRandInt
ab1ea29ba1 refactor: make GetRand a template, remove GetRandInt (pasta)

Pull request description:

  makes GetRand a template for which any integral type can be used, where the default behavior is to return a random integral up to the max of the integral unless a max is provided.
  This simplifies a lot of code from GetRand(std::numeric_limits<uint64_t>::max() -> GetRand<uint64_t>()

ACKs for top commit:
  laanwj:
    Code review ACK ab1ea29ba1

Tree-SHA512: db5082a0e21783389f1be898ae73e097b31ab48cab1a2c0e29348a4adeb545d4098193aa72a547c6baa6e8205699aafec38d6a27b3d65522fb3246f91b4daae9
2022-05-12 08:57:22 +02:00
dergoegge
f10e80b6e4 [net] Use ConnectedThroughNetwork() instead of GetNetwork() to seed addr cache randomizer 2022-05-09 16:18:22 +02:00
MacroFake
0d080a183b
Merge bitcoin/bitcoin#24141: Rename message_command variables in src/net* and src/rpc/net.cpp
e71c51b27d refactor: rename command -> message type in comments in the src/net* files (Shashwat)
2b09593bdd scripted-diff: Rename message command to message type (Shashwat)

Pull request description:

  This PR is a follow-up to #24078.

  > a message is not a command, but simply a message of some type

  The first commit covers the message_command variable name and comments not addressed in the original PR in `src/net*` files.
  The second commit goes beyond the original `src/net*` limit of #24078 and does similar changes in the `src/rpc/net.cpp` file.

ACKs for top commit:
  MarcoFalke:
    review ACK e71c51b27d 💥

Tree-SHA512: 24015d132c00f15239e5d3dc7aedae904ae3103a90920bb09e984ff57723402763f697d886322f78e42a0cb46808cb6bc9d4905561dc6ddee9961168f8324b05
2022-05-05 08:37:35 +02:00
MacroFake
12455acca2
Merge bitcoin/bitcoin#24470: Disallow more unsafe string->path conversions allowed by path append operators
f64aa9c411 Disallow more unsafe string->path conversions allowed by path append operators (Ryan Ofsky)

Pull request description:

  Add more `fs::path` `operator/` and `operator+` overloads to prevent unsafe string->path conversions on Windows that would cause strings to be decoded according to the current Windows locale & code page instead of the correct string encoding.

  Update application code to deal with loss of implicit string->path conversions by calling `fs::u8path` or `fs::PathFromString` explicitly, or by just changing variable types from `std::string` to `fs::path` to avoid conversions altogether, or make them happen earlier.

  In all cases, there's no change in behavior either (1) because strings only contained ASCII characters and would be decoded the same regardless of what encoding was used, or (2) because of the 1:1 mapping between paths and strings using the `PathToString` and `PathFromString` functions.

  Motivation for this PR was just that I was experimenting with #24469 and noticed that operations like `fs::path / std::string` were allowed, and I thought it would be better not to allow them.

ACKs for top commit:
  hebasto:
    ACK f64aa9c411

Tree-SHA512: 944cce49ed51537ee7a35ea4ea7f5feaf0c8fff2fa67ee81ec5adebfd3dcbaf41b73eb35e49973d5f852620367f13506fd12a7a9b5ae3a7a0007414d5c9df50f
2022-05-03 10:39:42 +02:00
laanwj
a19f641a80
Merge bitcoin/bitcoin#24157: p2p: Replace RecursiveMutex cs_totalBytesSent with Mutex and rename it
709af67add p2p: replace RecursiveMutex `m_total_bytes_sent_mutex` with Mutex (w0xlt)
8be75fd0f0 p2p: add assertions and negative TS annotations for `m_total_bytes_sent_mutex` (w0xlt)
a237a065cc scripted-diff: rename cs_totalBytesSent -> m_total_bytes_sent_mutex (w0xlt)

Pull request description:

  Related to #19303, this PR gets rid of the RecursiveMutex `cs_totalBytesSent` and also adds `AssertLockNotHeld` macros combined with `LOCKS_EXCLUDED` thread safety annotations to avoid recursive locking.

ACKs for top commit:
  jonatack:
    ACK 709af67add per `git range-diff 7a4ac71 eff7918 709af67`, rebase to master, clang 15 debug build, and build with -Wthread-safety-negative
  vasild:
    ACK 709af67add
  hebasto:
    ACK 709af67add, tested on Ubuntu 22.04.

Tree-SHA512: 560b4e6c92b1511911d69185207df6ee809db09b96d97f96430d8d2595dc05c98cc691aaec8a58ef87cf2ab0a98675c210b8ce0be3dedb81e31114bbbfdfd8be
2022-04-26 10:21:52 +02:00
pasta
ab1ea29ba1 refactor: make GetRand a template, remove GetRandInt 2022-04-22 09:04:39 -05:00
fanquake
505ba39665
Merge bitcoin/bitcoin#22910: net: Encapsulate asmap in NetGroupManager
36f814c0e8 [netgroupman] Remove NetGroupManager::GetAsmap() (John Newbery)
4709fc2019 [netgroupman] Move asmap checksum calculation to NetGroupManager (John Newbery)
1b978a7e8c [netgroupman] Move GetMappedAS() and GetGroup() logic to NetGroupManager (John Newbery)
ddb4101e63 [net] Only use public CNetAddr functions and data in GetMappedAS() and GetGroup() (John Newbery)
6b2268162e [netgroupman] Add GetMappedAS() and GetGroup() (John Newbery)
19431560e3 [net] Move asmap into NetGroupManager (John Newbery)
17c24d4580 [init] Add netgroupman to node.context (John Newbery)
9b3836710b [build] Add netgroup.cpp|h (John Newbery)

Pull request description:

  The asmap data is currently owned by addrman, but is used by both addrman and connman. #22791 made the data const and private (so that it can't be updated by other components), but it is still passed out of addrman as a reference to const, and used by `CNetAddress` to calculate the group and AS of the net address.

  This RFC PR proposes to move all asmap data and logic into a new `NetGroupManager` component. This is initialized at startup, and the client components addrman and connman simply call `NetGroupManager::GetGroup(const CAddress&)` and `NetGroupManager::GetMappedAS(const CAddress&)` to get the net group and AS of an address.

ACKs for top commit:
  mzumsande:
    Code Review ACK 36f814c0e8
  jnewbery:
    CI failure seems spurious. I rebased onto latest master to trigger a new CI run, but whilst I was doing that, mzumsande ACKed 36f814c0e8, so I've reverted to that.
  dergoegge:
    Code review ACK 36f814c0e8

Tree-SHA512: 244a89cdfd720d8cce679eae5b7951e1b46b37835fccb6bdfa362856761bb110e79e263a6eeee8246140890f3bee2850e9baa7bc14a388a588e0e29b9d275175
2022-04-22 14:43:14 +01:00
w0xlt
8be75fd0f0 p2p: add assertions and negative TS annotations for m_total_bytes_sent_mutex
Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2022-04-22 05:40:24 -03:00
Ryan Ofsky
f64aa9c411 Disallow more unsafe string->path conversions allowed by path append operators
Add more fs::path operator/ and operator+ overloads to prevent unsafe
string->path conversions on Windows that would cause strings to be
decoded according to the current Windows locale & code page instead of
the correct string encoding.

Update application code to deal with loss of implicit string->path
conversions by calling fs::u8path or fs::PathFromString explicitly, or
by just changing variable types from std::string to fs::path to avoid
conversions altoghther, or make them happen earlier.

In all cases, there's no change in behavior either (1) because strings
only contained ASCII characters and would be decoded the same regardless
of what encoding was used, or (2) because of the 1:1 mapping between
paths and strings using the PathToString and PathFromString functions.

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2022-04-21 12:01:00 -05:00
John Newbery
6b2268162e [netgroupman] Add GetMappedAS() and GetGroup()
These currently call through to the CNetAddr methods. The logic will be moved in a future commit.
2022-04-20 14:35:52 +01:00
John Newbery
19431560e3 [net] Move asmap into NetGroupManager 2022-04-20 14:29:29 +01:00
w0xlt
a237a065cc scripted-diff: rename cs_totalBytesSent -> m_total_bytes_sent_mutex
-BEGIN VERIFY SCRIPT-
sed -i 's/cs_totalBytesSent/m_total_bytes_sent_mutex/g' -- $(git grep --files-with-matches 'cs_totalBytesSent')
-END VERIFY SCRIPT-
2022-04-18 13:23:26 -03:00
Shashwat
e71c51b27d refactor: rename command -> message type in comments in the src/net* files
Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
2022-04-16 16:57:26 +05:30
Vasil Dimov
a2c4a7acd1
net: use Sock::SetSockOpt() instead of standalone SetSocketNoDelay()
Since the former is mockable, this makes it easier to test higher level
code that sets the TCP_NODELAY flag.
2022-04-15 09:39:25 +02:00
Vasil Dimov
d65b6c3fb9
net: use Sock::SetSockOpt() instead of setsockopt() 2022-04-15 09:19:05 +02:00
Shashwat
2b09593bdd scripted-diff: Rename message command to message type
-BEGIN VERIFY SCRIPT-

 s1() { sed -i "s/$1/$2/g" $(git grep -l "$1" ./); }

 s1 'NET_MESSAGE_COMMAND_OTHER' 'NET_MESSAGE_TYPE_OTHER'
 s1 'mapMsgCmdSize' 'mapMsgTypeSize'
 s1 'mapRecvBytesPerMsgCmd' 'mapRecvBytesPerMsgType'
 s1 'mapSendBytesPerMsgCmd' 'mapSendBytesPerMsgType'
 s1 'recvPerMsgCmd' 'recvPerMsgType'
 s1 'sendPerMsgCmd' 'sendPerMsgType'

-END VERIFY SCRIPT-
2022-04-07 17:22:36 +05:30
fanquake
37a16ffd70
refactor: fix clang-tidy named args usage 2022-04-04 09:01:19 +01:00
John Newbery
1066d10f71 scripted-diff: rename TxRelay members
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); }

ren cs_filter             m_bloom_filter_mutex
ren fRelayTxes            m_relay_txs
ren pfilter               m_bloom_filter
ren cs_tx_inventory       m_tx_inventory_mutex
ren filterInventoryKnown  m_tx_inventory_known_filter
ren setInventoryTxToSend  m_tx_inventory_to_send
ren fSendMempool          m_send_mempool
ren nNextInvSend          m_next_inv_send_time
ren minFeeFilter          m_fee_filter_received
ren lastSentFeeFilter     m_fee_filter_sent
-END VERIFY SCRIPT-
2022-03-18 11:35:58 +00:00
John Newbery
575bbd0dea [net processing] Move tx relay data to Peer 2022-03-18 11:35:56 +00:00
John Newbery
36346703f8 [net] Add CNode.m_relays_txs and CNode.m_bloom_filter_loaded
We'll move the transaction relay data into Peer in subsequent commits,
but the inbound eviction logic needs to know if the peer is relaying
txs and if the peer has loaded a bloom filter.

This is currently redundant information with m_tx_relay->fRelayTxes,
but when m_tx_relay is moved into net_processing, then we'll need these
separate fields in CNode.
2022-03-18 11:21:48 +00:00
Vasil Dimov
0cfc0cd322
net: fix GetListenPort() to derive the proper port
`GetListenPort()` uses a simple logic: "if `-port=P` is given, then we
must be listening on `P`, otherwise we must be listening on `8333`".
This is however not true if `-bind=` has been provided with `:port` part
or if `-whitebind=` has been provided. Thus, extend `GetListenPort()` to
return the port from `-bind=` or `-whitebind=`, if any.

Fixes https://github.com/bitcoin/bitcoin/issues/20184 (cases 1. 2. 3. 5.)
2022-03-02 15:42:37 +01:00
Vasil Dimov
f98cdcb357
net: pass Span by value to CaptureMessage()
Span is lightweight and need not be passed by const reference.
2022-03-02 15:40:36 +01:00
Vasil Dimov
3cb9d9c861
net: make CaptureMessage() mockable
Rename `CaptureMessage()` to `CaptureMessageToFile()` and introduce a
`std::function` variable called `CaptureMessage` whose value can be
changed by unit tests, should they need to inspect message contents.
2022-03-02 15:40:36 +01:00
laanwj
8b6cd42c62
Merge bitcoin/bitcoin#24165: p2p: extend inbound eviction protection by network to CJDNS peers
b7be28cac5 test: add combined CJDNS/I2P/localhost/onion eviction protection tests (Jon Atack)
0a1bb84770 test: add tests for inbound eviction protection of CJDNS peers (Jon Atack)
0c00c0c981 test: fix off-by-one logic in an eviction protection test (Jon Atack)
f7b8094d61 p2p: extend inbound eviction protection by network to CJDNS peers (Jon Atack)

Pull request description:

  Extend inbound eviction protection for peers connected over CJDNS, as is the case for peers connected via onion, localhost, and I2P since #21261 and #20197.  CJDNS peers seem to have better min ping latency than onion and I2P peers but still higher than that of unencrypted IPv4/6 peers and can be disadvantaged under our eviction criteria. They are also very few in number, which is a further reason to protect them, as the goal of this logic is to favorise the diversity of our peer connections.  CJDNS support was added in #23077 for the upcoming v23 release.

ACKs for top commit:
  laanwj:
    Concept and code review ACK b7be28cac5
  w0xlt:
    tACK b7be28c

Tree-SHA512: 89ebdd217602e16ae14b9bd0d5a25fc09f9b2384c951f820bc0f5a6d8452bbc9042065db817d5d5296c0ad22988491a83fc5b9a611e660c40ebd4f03448c4061
2022-03-02 12:00:58 +01:00
laanwj
ba11eb354b
Merge bitcoin/bitcoin#23542: net: open p2p connections to nodes that listen on non-default ports
36ee76d1af net: remove unused CNetAddr::GetHash() (Vasil Dimov)
d0abce9a50 net: include the port when deciding a relay destination (Vasil Dimov)
2e38a0e686 net: add CServiceHash constructor so the caller can provide the salts (Vasil Dimov)
97208634b9 net: open p2p connections to nodes that listen on non-default ports (Vasil Dimov)

Pull request description:

  By default, for mainnet, the p2p listening port is 8333. Bitcoin Core
  has a strong preference for only connecting to nodes that listen on that
  port.

  Remove that preference because connections over clearnet that involve
  port 8333 make it easy to detect, analyze, block or divert Bitcoin p2p
  traffic before the connection is even established (at TCP SYN time).

  For further justification see the OP of:
  https://github.com/bitcoin/bitcoin/pull/23306

ACKs for top commit:
  laanwj:
    Concept and light code review ACK 36ee76d1af
  prayank23:
    ACK 36ee76d1af
  stickies-v:
    tACK 36ee76d1a
  jonatack:
    ACK 36ee76d1af
  glozow:
    utACK 36ee76d1af

Tree-SHA512: 7f45ab7567c51c19fc50fabbaf84f0cc8883a8eef84272b76435c014c31d89144271d70dd387212cc1114213165d76b4d20a5ddb8dbc958fe7e74e6ddbd56d11
2022-03-02 09:33:03 +01:00
laanwj
848b11615b
Merge bitcoin/bitcoin#22834: net: respect -onlynet= when making outbound connections
0eea83a85e scripted-diff: rename `proxyType` to `Proxy` (Vasil Dimov)
e53a8505db net: respect -onlynet= when making outbound connections (Vasil Dimov)

Pull request description:

  Do not make outbound connections to hosts which belong to a network
  which is restricted by `-onlynet`.

  This applies to hosts that are automatically chosen to connect to and to
  anchors.

  This does not apply to hosts given to `-connect`, `-addnode`,
  `addnode` RPC, dns seeds, `-seednode`.

  Fixes https://github.com/bitcoin/bitcoin/issues/13378
  Fixes https://github.com/bitcoin/bitcoin/issues/22647
  Supersedes https://github.com/bitcoin/bitcoin/pull/22651

ACKs for top commit:
  naumenkogs:
    utACK 0eea83a85e
  prayank23:
    reACK 0eea83a85e
  jonatack:
    ACK 0eea83a85e code review, rebased to master, debug built, and did some manual testing with various config options on signet

Tree-SHA512: 37d68b449dd6d2715843fc84d85f48fa2508be40ea105a7f4a28443b318d0b6bd39e3b2ca2a6186f2913836adf08d91038a8b142928e1282130f39ac81aa741b
2022-03-01 18:32:01 +01:00
Hennadii Stepanov
ff33c5ae63
Add missed word to error message 2022-02-24 02:59:38 +02:00
Jon Atack
48742693ac
Replace "can not" with "cannot" in docs, user messages, and tests 2022-02-21 19:07:29 +01:00
Vasil Dimov
97208634b9
net: open p2p connections to nodes that listen on non-default ports
By default, for mainnet, the p2p listening port is 8333. Bitcoin Core
has a strong preference for only connecting to nodes that listen on that
port.

Remove that preference because connections over clearnet that involve
port 8333 make it easy to detect, analyze, block or divert Bitcoin p2p
traffic before the connection is even established (at TCP SYN time).

For further justification see the OP of:
https://github.com/bitcoin/bitcoin/pull/23306
2022-02-11 15:21:49 +01:00
laanwj
e8a3882e20
Merge bitcoin/bitcoin#23604: Use Sock in CNode
ef5014d256 style: wrap long lines in CNode creation and add some comments (Vasil Dimov)
b683491648 scripted-diff: rename CNode::cs_hSocket to CNode::m_sock_mutex (Vasil Dimov)
c41a1162ac net: use Sock in CNode (Vasil Dimov)
c5dd72e146 fuzz: move FuzzedSock earlier in src/test/fuzz/util.h (Vasil Dimov)

Pull request description:

  _This is a piece of #21878, chopped off to ease review._

  Change `CNode` to use a pointer to `Sock` instead of a bare `SOCKET`.
  This will help mocking / testing / fuzzing more code.

ACKs for top commit:
  jonatack:
    re-ACK ef5014d256 changes since last review are the removal of an unneeded dtor and the addition of a style commit
  w0xlt:
    reACK ef5014d
  PastaPastaPasta:
    utACK ef5014d256, I have reviewed the code, and believe it makes sense to merge
  theStack:
    Cod-review ACK ef5014d256

Tree-SHA512: 7f5414dd339cd2f16f7cbdc5fcec238d68b6d50072934aea10b901f409da28ff1ece6db6e899196616aa8127b8b25ab5b86d000bdcee58b4cadd7a3c1cf560c5
2022-02-04 09:24:17 +01:00
Kiminuo
41d7166c8a
refactor: replace boost::filesystem with std::filesystem
Warning: Replacing fs::system_complete calls with fs::absolute calls
in this commit may cause minor changes in behaviour because fs::absolute
no longer strips trailing slashes; however these changes are believed to
be safe.

Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2022-02-03 18:35:52 +08:00
Vasil Dimov
ef5014d256
style: wrap long lines in CNode creation and add some comments 2022-01-28 06:41:11 +01:00
Vasil Dimov
b683491648
scripted-diff: rename CNode::cs_hSocket to CNode::m_sock_mutex
-BEGIN VERIFY SCRIPT-
sed -i -e 's/cs_hSocket/m_sock_mutex/g' $(git grep -l cs_hSocket)
-END VERIFY SCRIPT-
2022-01-28 06:41:10 +01:00
Vasil Dimov
c41a1162ac
net: use Sock in CNode
Change `CNode` to use a pointer to `Sock` instead of a bare `SOCKET`.
This will help mocking / testing / fuzzing more code.
2022-01-28 06:41:09 +01:00
laanwj
196b459920
Merge bitcoin/bitcoin#23438: refactor: Use spans of std::byte in serialize
fa5d2e678c Remove unused char serialize (MarcoFalke)
fa24493d63 Use spans of std::byte in serialize (MarcoFalke)
fa65bbf217 span: Add BytePtr helper (MarcoFalke)

Pull request description:

  This changes the serialize code (`.read()` and `.write()` functions) to take a `Span` instead of a pointer and size. This is a breaking change for the serialize interface, so at no additional cost we can also switch to `std::byte` (instead of using `char`).

  The benefits of using `Span`:
  * Less verbose and less fragile code when passing an already existing `Span`(-like) object to or from serialization

  The benefits of using `std::byte`:
  * `std::byte` can't accidentally be mistaken for an integer

  The goal here is to only change serialize to use spans of `std::byte`. If needed, `AsBytes`,  `MakeUCharSpan`, ... can be used (temporarily) to pass spans of the right type.

  Other changes that are included here:

  * [#22167](https://github.com/bitcoin/bitcoin/pull/22167) (refactor: Remove char serialize by MarcoFalke)
  * [#21906](https://github.com/bitcoin/bitcoin/pull/21906) (Preserve const in cast on CTransactionSignatureSerializer by promag)

ACKs for top commit:
  laanwj:
    Concept and code review ACK fa5d2e678c
  sipa:
    re-utACK fa5d2e678c

Tree-SHA512: 08ee9eced5fb777cedae593b11e33660bed9a3e1711a7451a87b835089a96c99ce0632918bb4666a4e859c4d020f88fb50f2dd734216b0c3d1a9a704967ece6f
2022-01-27 19:19:12 +01:00
Jon Atack
f7b8094d61
p2p: extend inbound eviction protection by network to CJDNS peers
This commit extends our inbound eviction protection to CJDNS peers to
favorise the diversity of peer connections, as peers connected
through the CJDNS network are otherwise disadvantaged by our eviction
criteria for their higher latency (higher min ping times) relative
to IPv4 and IPv6 peers.

The `networks` array is order-dependent in the case of a tie in
candidate counts between networks; earlier array members receive
priority in the case of a tie.

Therefore, we place CJDNS candidates before I2P, localhost, and onion
ones in terms of opportunity to recover unused remaining protected
slots from the previous iteration, estimating that most nodes allowing
several inbound privacy networks will have more onion, localhost or
I2P peers than CJDNS ones, as CJDNS support is only being added in the
upcoming v23.0 release.
2022-01-26 09:19:23 +01:00
MarcoFalke
b32f0d3af1
Merge bitcoin/bitcoin#24108: Replace RecursiveMutex cs_addrLocal with Mutex, and rename it
dec787d8ac refactor: replace RecursiveMutex `m_addr_local_mutex` with Mutex (w0xlt)
93609c1dfa p2p: add assertions and negative TS annotations for m_addr_local_mutex (w0xlt)
c4a31ca267 scripted-diff: rename cs_addrLocal -> m_addr_local_mutex (w0xlt)

Pull request description:

  This PR is related to #19303 and gets rid of the `RecursiveMutex cs_addrLocal`.

ACKs for top commit:
  hebasto:
    ACK dec787d8ac, I have reviewed the code and it looks OK, I agree it can be merged.
  shaavan:
    reACK dec787d8ac

Tree-SHA512: b7a043bfd4e2ccbe313bff21ad815169db6ad215ca96daf358ce960c496a548b4a9e90be9e4357430ca59652b96df87c097450118996c6d4703cbaabde2072d0
2022-01-24 12:40:15 +01:00
MarcoFalke
973c390298
Merge bitcoin/bitcoin#24078: net, refactor: Rename CNetMessage::m_command with CNetMessage::m_type
224d87855e net, refactor: Drop tautological local variables (Hennadii Stepanov)
3073a9917b scripted-diff: Rename CNetMessage::m_command with CNetMessage::m_type (Hennadii Stepanov)

Pull request description:

  https://github.com/bitcoin/bitcoin/pull/18533#issue-594592488:
  > a message is not a command, but simply a message of some type

  Continuation of bitcoin/bitcoin#18533 and bitcoin/bitcoin#18937.

ACKs for top commit:
  theStack:
    Concept and code-review ACK 224d87855e
  shaavan:
    Code Review ACK 224d87855e
  w0xlt:
    crACK 224d878

Tree-SHA512: 898cafb44708dae1413fcc1533d809d75878891354f1b5edaaec1287f4921c31adc9330f4d42d82544a39689886bc17fee71ea587f9199fd5cc849d376f82176
2022-01-24 08:49:17 +01:00
fanquake
6d859cbd79
Merge bitcoin/bitcoin#24021: Rename and move PoissonNextSend functions
9b8dcb25b5 [net processing] Rename PoissonNextSendInbound to NextInvToInbounds (John Newbery)
ea99f5d01e [net processing] Move PoissonNextSendInbound to PeerManager (John Newbery)
bb060746df scripted-diff: replace PoissonNextSend with GetExponentialRand (John Newbery)
03cfa1b603 [refactor] Use uint64_t and std namespace in PoissonNextSend (John Newbery)
9e64d69bf7 [move] Move PoissonNextSend to src/random and update comment (John Newbery)

Pull request description:

  `PoissonNextSend` and `PoissonNextSendInbound` are used in the p2p code to obfuscate various regularly occurring processes, in order to make it harder for others to get timing-based information deterministically.

  The naming of these functions has been confusing to several people (including myself, see also #23347) because the resulting random timestamps don't follow a Poisson distribution but an exponential distribution (related to events in a Poisson process, hence the name). This PR
  - moves `PoissonNextSend()` out of `net` to `random` and renames it to `GetExponentialRand()`
  - moves `PoissonNextSendInbound()` out of `CConnman` to `PeerManager` and renames it to `NextInvToInbounds()`
  - adds documentation for these functions

  This is work by jnewbery - due to him being less active currently, I opened the PR and will address feedback.

ACKs for top commit:
  jnewbery:
    ACK 9b8dcb25b5
  hebasto:
    ACK 9b8dcb25b5, I have reviewed the code and it looks OK, I agree it can be merged.
  theStack:
    ACK 9b8dcb25b5 📊

Tree-SHA512: 85c366c994e7147f9981fe863fb9838502643fa61ffd32d55a43feef96a38b79a5daa2c4d38ce01074897cc95fa40c76779816edad53f5265b81b05c3a1f4f50
2022-01-23 11:44:02 +08:00
w0xlt
93609c1dfa p2p: add assertions and negative TS annotations for m_addr_local_mutex 2022-01-20 17:34:48 -03:00
w0xlt
c4a31ca267 scripted-diff: rename cs_addrLocal -> m_addr_local_mutex
-BEGIN VERIFY SCRIPT-
sed -i 's/cs_addrLocal/m_addr_local_mutex/g' -- $(git grep --files-with-matches 'cs_addrLocal')
-END VERIFY SCRIPT-
2022-01-20 05:43:10 -03:00