Commit Graph

145 Commits

Author SHA1 Message Date
tomFlowee eace700859 Add EndPoint::isOutgoing() -> bool & isIncomimg() 2024-01-24 21:06:25 +01:00
tomFlowee 4fe9d69e7b Use more specific define-guards 2024-01-24 21:03:58 +01:00
tomFlowee ef95af0177 Define the lifetime better.
A connection that is 'shutdown' now ensures one more time we'll call
onDisconnected() (is it was..) allowing the application level logic to
get notified and avoid memory leaks.
2024-01-24 21:03:58 +01:00
tomFlowee 40e5eaa78d Add EndPoint::toString() 2024-01-21 23:16:56 +01:00
tomFlowee ccd53255f8 Avoid doing unneeded work.
When the user-layer triggers a re-connect instead of waiting for the
layer to re-connect then we should avoid doing work twice.
This also avoids a reconnect in some cases.
2024-01-08 16:57:50 +01:00
tomFlowee 64bfb76e06 Linter found issues, we fix 2024-01-08 14:01:21 +01:00
tomFlowee bc47a700a4 Refactor; wrap BufferPool in shared_ptr
As we moved most of the creation of a BufferPool to be via the
Streaming::pool() method, which uses a thread-local, it makes sense
to start cleaning up the design and make it more modern C++.
The above mentioned method would return a reference and you'd see
loads of places use `auto &pool =` which is less than ideal.

As the number of places where we actually instantiate a BufferPool
goes down, the usage of some sort of smart pointer makes more sense.

This now makes all APIs use BufferPool be wrapped in a shared_ptr.
2023-12-21 15:23:23 +01:00
tomFlowee 220965ceae Add operator== to EndPoint 2023-08-13 13:59:24 +02:00
tomFlowee f1f148496f Add API docs. 2023-08-02 11:54:05 +02:00
tomFlowee 9f16d67460 Make API more robust
this avoids the endPoint() method sometimes throwing an exception from
std::map::at confusing the caller.
2023-07-20 20:59:26 +02:00
tomFlowee 9685d484cc Init member var 2023-07-17 21:01:59 +02:00
tomFlowee c8fe78f28e whitespace cleanup 2023-07-15 22:01:30 +02:00
tomFlowee 166f646cc3 Fixes in API / docs 2023-07-15 20:01:26 +02:00
tomFlowee 6951a9f13a Add missing reserve() call 2023-01-31 20:29:51 +01:00
tomFlowee a711c38a77 Don't connect when the reconnect is underway
Avoid massive connect storm.
Using the network manager based logger we got into a fun situation where
logging to a remote host caused us to connect and fail, which caused us
to log this failed which made us try to connect and .. etc.
2022-12-20 15:32:58 +01:00
tomFlowee 7163605b00 Make sure login messages are sent first
When the client sent a message in the onConnected callback, it managed
to get in front of the login message. This fixes that.
2022-12-03 23:30:01 +01:00
tomFlowee bfda224542 Use static_cast instead. 2022-11-08 12:23:00 +01:00
tomFlowee f4ed75f316 Avoid auto-cast, clang didn't like it.
This avoids the code behaving differently under clang.
2022-11-04 11:49:43 +01:00
tomFlowee 126de2a231 Add new NetworkConnection::setLoginMessageCreator() 2022-11-03 23:40:31 +01:00
tomFlowee 6f4ef3bbdb Detect when outgoing connection died
The server always sends pongs in response to our pings, but we assumed
that the underlying OS would close a connection when the other side
isn't replying (ACKs).

Now we take this responsibility in the code and when no pongs are
registered we also close and re-establish the connection.

This additionally shortens the ping time to 30 seconds and the timeout
to 90 seconds.
2022-04-20 11:41:15 +02:00
tomFlowee df002c4973 Count the 'endofheader' byte too.
A header is actually never empty, but lets not make that assumption in
code.
2022-04-20 11:37:33 +02:00
tomFlowee 9a332d9b7b Fix endless loop bug 2022-03-23 22:48:44 +01:00
tomFlowee c7a3478be2 Fix constructor from sometimes throwing 2022-01-26 15:27:30 +01:00
tomFlowee 1d25e45a1c Reconcile more places to use pools API
This removes 2 more custom solutions to converge on one
  Streaming::pool()
namespaced method.
2022-01-25 23:20:12 +01:00
tomFlowee c8ed2ec382 Make compile 2022-01-22 23:27:29 +01:00
tomFlowee a8131f88d7 Fix docs 2022-01-21 19:12:31 +01:00
tomFlowee 4cf26ee529 Fix a very niche bug. 2021-08-05 22:42:58 +02:00
tomFlowee d355c5f0ab Make the reconnect timeout more agressive.
The first bunch of times we want to reconnect much faster so we have less
downtime and faster response.

After a while it goes up to a slower timeout in order to not overload
logs and other such.
2021-08-05 22:42:58 +02:00
tomFlowee 56f083e3b6 Ensure sane queue size
This is based on the fact that a ringbuffer is not very happy if its only
got one element.
2021-08-05 22:02:45 +02:00
tomFlowee 773eafc892 make compile 2021-07-15 13:10:05 +02:00
tomFlowee 9ec0bf9aec Don't re-connect when user calls connect()
User code may not check if it was already connected before calling
connect(), so we do it for them.
2021-07-15 12:47:27 +02:00
tomFlowee e0a41be5a3 Add API docs for this method 2021-07-15 12:47:15 +02:00
tomFlowee 3447230371 [NVM] Make ipv6 based error messages better.
Avoid just appending the portnumber with a colon as that does not help
readability on ipv6 type addresses.
This now neatly adds the square brackets as needed.
2021-07-15 00:08:50 +02:00
tomFlowee e6b02da76b Add secure way to do login on incoming connections.
This adds a baseclass for clients to inherit to make it even easier to
do login. Check ConnectionAuthorizer
2021-06-27 12:37:46 +02:00
tomFlowee 0196bc8bca Remove unused variable. 2021-06-27 11:42:47 +02:00
tomFlowee 2b6b3a3d5a Fix api docs. 2021-06-26 22:17:46 +02:00
tomFlowee ae78dd0bb8 Update email address 2021-06-20 22:44:44 +02:00
tomFlowee ea38ab6de5 Make ping more agressive.
For native connections we ping in order to disconnect stale connections.
This ensures that pings are sent more agressive, via the priority queue,
and we delay the disconnect to 150s.

So, pings more agressive, disconnects less agressive.
2021-04-19 11:31:53 +02:00
tomFlowee 9025a2e2ea Add DoubleSpendService to listen to all double spend notifications 2021-03-16 19:53:14 +01:00
tomFlowee 4d5e7bfb09 Protect node with user-limits for the API.
This introduces several options for public node operators to limit their
nodes usage by 3rd parties, this is aimed at usage of resource-hungry
areas.

We allow limiting the amount of connections any single IP can keep open
with us.
We limit the amount of reconnects we allow in a short number of seconds.
We allow limiting the number of addresses (or scriptHashes) a peer can
register for the node to scan.
The last one is for both the addressMonitorService as well as for the
getBlock filters.

For node operators these items become available using command line
options or config-file options. By default these limits are unlimited as
we assume default usage to be private.
2021-02-26 15:14:14 +01:00
TomZ 3dbb2672b9 Api Docs 2021-02-22 15:53:32 +01:00
TomZ 046c956230 Avoid sideeffects after a move. 2021-02-22 15:52:34 +01:00
tomFlowee b83fd08789 Add chainReorged msg to BlockNotificationService
When blocks are reverted clients likely want to know. This gives them
the information the moment it becomes clear.
2021-02-19 13:43:56 +01:00
tomFlowee abfc90d99a assert -> if 2021-02-17 22:59:35 +01:00
tomFlowee 0824cabbee Sanitize log
Seems some systems are not happy if we print a string that has zeros in it.
This sanitizes the message to replace zeros with spaces.
2021-02-03 13:13:21 +01:00
tomFlowee 3fe98afce9 Minor cleanup
This removes some unused includes from common headers and dead code
from some C++ files.
2021-01-05 22:05:25 +01:00
tomFlowee 9748d3988f Cleanups and improvements. 2020-12-25 23:51:06 +01:00
tomFlowee e89e3fe8ac Add license text
All sources should have a license text at the top of each file
2020-12-25 23:45:03 +01:00
TomZ 4054b9a7d4 Avoid (re)connecting to incoming peer. 2020-10-26 18:21:52 +01:00
TomZ ff58ae6a36 Implement the first ASync API command
This implements the sendTransaction command using the async framework,
allowing clients to benefit from multi-core systems to process
transactions in parallel when being submitted to the Hub.
2020-10-26 18:21:52 +01:00