Skip to content

Conversation

Sjors
Copy link
Owner

@Sjors Sjors commented Jul 19, 2024

Based on:

Followed by #49. Parent PR #68

This PR introduces Sv2Connman, a subclass of SockMan (bitcoin#30988). It uses the Sv2Transport introduced in bitcoin#30315 to enable incoming connections from other Stratum v2 roles.

It's main target user is the Template Provider role introduced in #49.

There may be other Stratum v2 roles we want to support in the future.

Earlier version(s): bitcoin#30332


Note to self, to keep this rebased until bitcoin#30988 lands (1 merge commits and 3 normal commits):

git rebase --rebase-merges HEAD~4 --onto sv2-transport

This won't include changes in the original branches. To achieve that:

git reset --hard sv2-transport
# git fetch vasild
# git merge vasild/sockman
git fetch pinheadmz
git merge pinheadmz/sockman-lite
git cherry-pick sjors/2024/06/sv2_connection~2^..sjors/2024/06/sv2_connection

Note that this code will most likely not be upstreamed to Bitcoin Core, but instead used to create a standalone c++ application that connects to a running node via an IPC interface. See bitcoin#31098.

@Sjors
Copy link
Owner Author

Sjors commented Jul 19, 2024

@pinheadmz wrote in the original PR:

I am working on a libevent-replacing HTTP server using netbase primitives and yeah, I have some functions that look a lot like the sv2connamn in this branch.

I think it would be cool if possible to abstract the mechanisms in ThreadSocketHandler to work on "abstract clients" and I'd be happy to review and collaborate on that.

I plan to take a look at this.

@Sjors
Copy link
Owner Author

Sjors commented Aug 29, 2024

CMake rebase.

@Sjors Sjors force-pushed the 2024/06/sv2_connection branch from 6b5ee20 to 4f957ee Compare August 29, 2024 11:37
@Sjors Sjors force-pushed the 2024/06/sv2_transport branch from 922fd8a to 50b6eb8 Compare August 29, 2024 11:47
@Sjors Sjors force-pushed the 2024/06/sv2_connection branch from 4f957ee to b69544c Compare August 29, 2024 11:49
@Sjors Sjors force-pushed the 2024/06/sv2_transport branch from 50b6eb8 to 6a02367 Compare September 5, 2024 12:48
@Sjors Sjors force-pushed the 2024/06/sv2_connection branch from b69544c to 1ca68d2 Compare September 5, 2024 12:57
@Sjors Sjors force-pushed the 2024/06/sv2_transport branch from 6a02367 to ce4269c Compare September 10, 2024 14:50
@Sjors Sjors force-pushed the 2024/06/sv2_connection branch from 1ca68d2 to b578e0a Compare September 10, 2024 14:54
@Sjors Sjors force-pushed the 2024/06/sv2_transport branch 3 times, most recently from 8220337 to 5fca2c5 Compare September 19, 2024 14:40
@Sjors Sjors force-pushed the 2024/06/sv2_connection branch from b578e0a to 489c9fb Compare September 19, 2024 15:02
@Sjors Sjors force-pushed the 2024/06/sv2_transport branch from 5fca2c5 to dfb9a6d Compare September 20, 2024 09:13
@Sjors Sjors force-pushed the 2024/06/sv2_connection branch from 489c9fb to a55fa83 Compare September 20, 2024 09:17
@Sjors
Copy link
Owner Author

Sjors commented Sep 20, 2024

Rebased to move everything into a bitcoin_sv2 library (use -DWITH_SV2=ON to compile).

@Sjors
Copy link
Owner Author

Sjors commented Jun 16, 2025

I switched to @pinheadmz's lite version of SockMan for now: bitcoin#32747

@Sjors Sjors force-pushed the 2024/06/sv2_connection branch 2 times, most recently from 21324f0 to b62f820 Compare July 9, 2025 08:11
@Sjors
Copy link
Owner Author

Sjors commented Jul 9, 2025

I made m_send_messages GUARDED_BY(cs_send) after a TSan race in the TP: https://cirrus-ci.com/task/4839347817545728?logs=ci#L2904 diff

@Sjors Sjors force-pushed the 2024/06/sv2_connection branch from b62f820 to 5a6d2b3 Compare July 9, 2025 08:47
pinheadmz and others added 10 commits August 7, 2025 11:29
Introduce a new low-level socket managing class `SockMan`.

BindListenPort() is copied from CConnMan in net.cpp and will
be modernized in the next commit.

Unit-test it with a new class `SocketTestingSetup` which mocks
`CreateSock()` and will enable mock client I/O in future commits.

`SockMan` and `SocketTestingSetup` are designed to be generic and
reusbale for higher-level network protocol implementation and testing.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
It was copied verbatim from `CConnman::BindListenPort()` in the previous
commit. Modernize its variables and style and log the error messages
from the caller. Also categorize the informative messages to the "net"
category because they are quite specific to the networking layer.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
AcceptConnection() is mostly copied from CConmann in net.cpp
and will be modernized in the following commit.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Socket handling methods are copied from CConnMan:

`CConnman::GenerateWaitSockets()` goes to
`SockMan::GenerateWaitSockets()`.

`CConnman::ThreadSocketHandler()` and
`CConnman::SocketHandler()` are combined into
`SockMan::ThreadSocketHandler()`.

`CConnman::SocketHandlerListening()` goes to
`SockMan::SocketHandlerListening()`.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
`CConnman::SocketHandlerConnected()` copied to
`SockMan::SocketHandlerConnected()`.

Testing this requires adding a new feature to the SocketTestingSetup,
inserting a "request" payload into the mock client that connects
to us.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Sockets-touching bits from `CConnman::SocketSendData()` copied to
`SockMan::SendBytes()`.

Testing this requires adding a new feature to the SocketTestingSetup,
returning the DynSock I/O pipes from the mock socket so the received
data can be checked.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Copy from some parts of `CConnman::SocketHandlerConnected()` and
`CConnman::ThreadSocketHandler()` to:
`EventIOLoopCompletedForOne(id)` and `EventIOLoopCompletedForAll()`.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
Sjors and others added 3 commits August 25, 2025 14:37
@Sjors Sjors force-pushed the 2024/06/sv2_connection branch from 5a6d2b3 to 32e76bb Compare August 25, 2025 12:42
@Sjors
Copy link
Owner Author

Sjors commented Aug 25, 2025

Last rebase before I'm going to split off the sv2 functionality into a fresh codebase.

@Sjors Sjors force-pushed the 2024/06/sv2_connection branch from 32e76bb to d375647 Compare August 25, 2025 14:29
@Sjors
Copy link
Owner Author

Sjors commented Aug 25, 2025

Added a mutex for m_disconnect_flag and m_setup_connection_confirmed om Sv2Client after TSan failure.

Co-Authored-By: Vasil Dimov <vd@FreeBSD.org>
@Sjors Sjors force-pushed the 2024/06/sv2_connection branch from d375647 to 6b8e3e6 Compare August 25, 2025 14:48
@Sjors
Copy link
Owner Author

Sjors commented Aug 27, 2025

This code is now part of https://github.com/Sjors/sv2-tp; feedback and pull requests are welcome there!

@Sjors Sjors closed this Aug 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants