Commit Graph

72 Commits

Author SHA1 Message Date
tomFlowee f2b59b7737 Make logging code compile with more defines
This allows compile with BCH_NO_INFO_OUTPUT define, which removes
from the compiled binary all info level logging.
2026-01-14 18:23:19 +01:00
tomFlowee fc2e2cc395 Minor cleanups 2026-01-13 21:15:00 +01:00
tomFlowee 56561b4d98 Add new signal to broadcastTxData
This now also registers when a peer sends the INV.
2025-05-21 22:52:31 +02:00
tomFlowee 5f6db1de18 Add feature: p2pnet power save mode.
Setting the "LowPower" mode on the main DownloadManager class will
cause it to halt all network activity and jobs will die.
You can revive it by changing it to NormalPower and optionally calling
the start() method to restart all jobs.
2025-03-07 14:31:02 +01:00
tomFlowee 5cae07500c Port away from deprecated ASIO methods
This makes thehub compile with BOOST_ASIO_NO_DEPRECATED defined.
2025-02-11 16:46:21 +01:00
tomFlowee bb7275466b Stop using deprecated asio io_service
This ports the io-service to the source compatible io-context
class, with the most work going to the WorkerThreads which owns
that one.
2025-02-08 19:05:26 +01:00
tomFlowee b6fc84696a Wrap PrivacySegment in a shared pointer.
This is an abstract class that the application using this library needs
to subclass. Ownership and lifetime don't change, it still lies with the
app using the library and they still need to add and remove it from the
connectionManager, but this makes it much more stable for multi-
threading environments and avoids issues on misuse.
2024-11-29 15:12:13 +01:00
tomFlowee 88f3e65fa5 Add a callback indicating the certainty of the height
As the systems gets more peers to confirm the same current blockheight,
our certainty increases. This is now made available via a listener
callback.
2024-11-29 14:02:36 +01:00
tomFlowee e9915cbcad When removing a segment, disconnect its peers
The removal of a privacySegment now makes sure that all the Peers
that reported to it are disconnected and then deleted.
2024-10-11 19:44:54 +02:00
tomFlowee 4b6ca81490 Remove dead code. 2024-10-11 19:40:26 +02:00
tomFlowee 2612db6fb4 Add IP to log message 2024-01-30 20:48:36 +01:00
tomFlowee 2e50054d69 Tweaks to the punishment values. 2024-01-28 19:53:59 +01:00
tomFlowee 9d980fdcad Minor tweaks to IP selection.
When we didn't personally verify the services, don't judge the IP based
on them and connect anyway.

In addition to not trusting the services we receive from the net, be
more careful with the usage of the 'lastConnected' field.
Notice that we don't actually use the result of that variable in the end
if the everConnected is likewise incorrect.
2024-01-28 17:01:01 +01:00
tomFlowee 249ea8c2c8 Add new callback for peers before the handshake. 2024-01-26 12:08:03 +01:00
tomFlowee ffca9b3418 Refactor the BroadcastTxData slightly and pass in the peer. 2024-01-18 21:46:08 +01:00
tomFlowee 0adb3b5307 Relay of transactions is an essential requirement for us
In practice this won't change anything, but this closes a DOS-like attack
on p2plib using apps where we give slots to peers and then skip using them.
2024-01-18 21:45:11 +01:00
tomFlowee 678eccfa70 Be smarter at asking for 'headers' from peers 2024-01-04 21:53:16 +01:00
tomFlowee fb927b9436 Continue shared_ptr convertion of Peer
Last year we started wrapping the Peer object in a shared pointer,
which is used now in the managers.
This continues the idea by making the PrivacySegment use smart
pointers too and the P2PNetInterface is changed to do the same
for downstream applications.
2024-01-04 17:06:32 +01:00
tomFlowee 8cf80a8634 Cleanup GetHeaders p2p call
Move the builder into the place its used (leftover from earlier ownership change)
Make the message we build be more compatible.
2023-11-03 22:07:57 +01:00
tomFlowee 003cdd6b23 Fix logic; missing braces. 2023-08-17 21:32:09 +02:00
tomFlowee 991eadb311 Add some more debugging output 2023-08-17 21:32:09 +02:00
tomFlowee f50ad44529 Tweaks in the punishment score
The PeerAddressDB keeps a score for each IP/port we have about how
useful that peer is.
This change re-visits the way we use the DB where we now are more fluid
in our approach to scores. We no longer simply forever-ban a peer after
it made a mistake once.

This rewrites the select-a-peer algo to take timing into account,
preferring a peer that we connected to recently while putting a higher
score on a peer that failed a long time ago so if we start running out
of good peers we start on the not-so-great-but-maybe-improved first.

Good behavior is likewise rewarded so a peer can become higher prio
again, but generally a new IP still gets preferred. Again, the balance
is to keep not-so-great options in the running.
2023-04-24 13:48:55 +02:00
tomFlowee 791bd302bc Mobile networks move 2023-04-21 22:06:46 +02:00
tomFlowee 2c0e0bad75 Update SyncChainAction to present day concepts
When the SyncChainAction was written, various interactions we do
today in the ConnectionManager did not happen yet. Features in
Peer didn't exist yet.

This updates the SyncChainAction to take those items into account
and be more responsive and conclue we are 'up to date' faster,
while also leaving behind a better state.
2023-03-27 15:20:50 +02:00
tomFlowee 2322456465 Add thread-safety for the deque too.
A list of weak-pointers itself is not directly thread-safe, the list
itself needs to be synched too.
2023-03-27 15:17:56 +02:00
tomFlowee 038e7bc0a5 Add new CMake option 'build_apps'.
To enable this means the buildsystem will build all the applications
as well as the libraries.
Applications are 'hub' / 'txVulcano' / 'indexer' etc.
Default this one is turned off.
2023-03-20 19:50:32 +01:00
tomFlowee 6002803fa4 Add more bannable messages.
Alert:
This has been sunset so long ago, no complient BCH client will (/can) use it.

Protoconf:
This looks like its a BSV message.
2023-02-25 19:38:06 +01:00
tomFlowee 18fed67872 Use known not-bch p2p messages to disconnect
When we receive a known message (currently just avahello) we now
intantly ban and disconnect the peer, no need to
test compliance when they openly greet us saying they are not following
the same chain.
2023-02-25 12:02:19 +01:00
tomFlowee 004f957540 Revisit listener interfaces.
Now we have 3 more logically divided interfaces for the listener
pattern (callbacks).

A P2PNetInterface for peers maintainance.
A DataListenerInterface for the sections getting new data.
And last the new  HeaderSyncInterface about the state of the
header-chain (application wide).
2023-01-31 20:29:51 +01:00
tomFlowee 64d382b7c4 Add saveData() function to p2p net 2022-11-11 19:25:19 +01:00
tomFlowee 5f629a161e Let the actions do the assignments of segments.
This removes some code from the connectionmanager / blockchain classes
which assigned a random segment on a new peer.
2022-07-13 13:50:23 +02:00
tomFlowee 1ab4d88993 Split version.h
Version.h held mostly stuff for protocol.h, which is a hub-specific file.
The only thing that we actually use is the PROTOCOL_VERSION in our code
and as such that one moved to the interfaces dir.
2022-07-06 22:50:53 +02:00
tomFlowee 7376c28a3c Move pool thread-local getter to utils.
This nicely cleans up the calling usage a static on the connection
manager instance.
2022-01-24 12:06:37 +01:00
tomFlowee d79ab0a301 Special case peers that are behind
A peer that is behind is marked as "on a different chain", which is
ultimately correct, but the response to punish or ban them is too much.
We could very well reconnect later when the situation is resolved.

So, detect when a peer is simply behind and respond by disconnecting
without punishment.
2021-11-01 17:19:00 +01:00
tomFlowee c5e845b11b Be more generous with asking for headers.
On connect, we should ask for a HEADERS overview from the remote peer,
even if we aren't fully at the tip yet.

Also remove some old lookup no longer used.
2021-10-27 19:14:09 +02:00
tomFlowee 1af7fea053 Fix too-fast-banning bug
Sometimes a node would not be online for a while and we'd incorrectly
ban them for a long time when we just need to mark them as not-
reachable-right-now.
2021-10-27 19:14:09 +02:00
tomFlowee 6692a0a11a Follow API change in NWM.
Setting the ringbuffers to not-so-tiny values
2021-08-05 23:03:19 +02:00
tomFlowee 77bd1ac74f Improve the SPV sync action.
This re-thinks the way we assign new peers and massively speeds up the
finding of enough peer for our wallets.
2021-07-30 16:56:25 +02:00
tomFlowee d3f1d7f454 Whitepace and minor fixes. 2021-02-05 17:32:36 +01:00
tomFlowee 70f363cabb Also allow downloading of dsproofs. 2021-02-04 18:09:38 +01:00
tomFlowee 44e8717d1e Send a MEMPOOL message on SPV/merkleblock sync. 2021-02-04 17:39:44 +01:00
tomFlowee 5d6d09e4d6 Assign segments only to good peers
Instead of assigning a privacy segment at connect, wait until we have
determined if this peer is on the same chain as us before we allocate a
peer slot.

This also helps us limit the amount of peers we send our bloom filter to.
2021-02-03 14:41:51 +01:00
tomFlowee adfe4081cb Update copyright notice and email address 2021-02-02 13:08:07 +01:00
TomZ 301a4ca3ee Fix properly following the chain-tip
This is done in several steps:

1. Separate my height from the remote peer heights.
Instead of assuming we have one height, recognize that a peer may
not be at the tip at the same time we are. We monitor headers/invs
to update the 'peerHeight' variable.

2. Ask for merkle blocks from a peer to the maximum height of that
peer (but not later than what we validated to be true).
This avoids us asking past the remotes tip which they didn't like.

3. Redo the SyncSPVAction to use all this and make it much more
reliable in finding peers to download from and getting all the
changes as fast as possible.
2020-11-13 21:03:56 +01:00
TomZ 5fa1b50fa1 Remove duplicate 2020-11-13 20:09:29 +01:00
TomZ 5e48d0dae7 Be smarter about when to ask for headers.
This avoids us asking a bunch of peers the headers while we are not yet
at the tip.
2020-11-05 21:54:33 +01:00
TomZ 062f62af67 Bugfixes 2020-11-05 21:49:32 +01:00
TomZ 781805d6a9 Less waiting while finding proper peers 2020-11-05 21:47:54 +01:00
TomZ 3f5fe41534 P2PNet: Support multiple chains.
This adds support for the testnet4 chain.
2020-10-29 21:47:53 +01:00
TomZ 652fc1e161 Introduce structure to broadcast transactions.
To send out transactions in the p2p net is quite a lot of work,
you need to find multiple peers to send the transaction to. First
you send an INV, then you respond to a getData to actually send
the transaction and last you wait for 'reject' messages that may
indicate that there is something wrong with the transaction.

This introduces the BroadcastTxData class that wraps a transaction
and gets callbacks for sending and for rejects, abstracting away
all the complexity for the user.
2020-06-08 21:35:10 +02:00