Skip to content

Add support for SAM over UNIX domain sockets#2375

Open
Lkzeu wants to merge 1 commit into
PurpleI2P:opensslfrom
Lkzeu:support_unix_sockets_on_sam
Open

Add support for SAM over UNIX domain sockets#2375
Lkzeu wants to merge 1 commit into
PurpleI2P:opensslfrom
Lkzeu:support_unix_sockets_on_sam

Conversation

@Lkzeu

@Lkzeu Lkzeu commented Apr 26, 2026

Copy link
Copy Markdown

closes #1751

Comment thread libi2pd_client/SAM.cpp
{
boost::asio::ip::tcp::endpoint ep;
ep.resize(tmp.size());
std::memcpy(ep.data(), tmp.data(), tmp.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use memcpy instead just ep = tmp?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use memcpy instead just ep = tmp?

The SAMSocket::Socket_t is now a generic::stream_protocol::socket to allow it to receive a tcp::socket or local::stream_protocol::socket at runtime.
So remote_endpoint() now returns a generic endpoint, which could not be copied into tcp::endpoint.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If generic_endpoint is the base class, why not use static_cast instead? Relying on internals is always a bad idea, because it can change later.

Comment thread libi2pd_client/SAM.h
const decltype(m_Sessions)& GetSessions () const { return m_Sessions; };
};

class SAMAcceptor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use template ServiceAcceptor from I2PService.h implementing acceptors for different socket types.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use template ServiceAcceptor from I2PService.h implementing acceptors for different socket types.

Understood. SAMBridge needs to select the type of m_Acceptor at runtime based on the config file like I2PControl.h/cpp does it.

By using the polymorphic SAMAcceptor, SAMBridge uses only one m_Acceptor in the code instead of m_Acceptor and m_LocalAcceptor like I2PControlService does.

I could add UDSAcceptor that derives from ServiceAcceptor and adapt SAMBridge/SAMSocket accordingly. but, as a template, I will need to check if the acceptor is m_Acceptor or m_LocalAcceptor.

Or I could work on a major refactor to make ServiceAcceptor polymorphic, similar to how SAMAcceptor is now.

What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polymophic acceptor makes sense. I would implement it in more generic code (I2PService), because it's need in many other places beside SAM. And SOCKS proxy is the first in the list.

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.

Add support for SAM over UNIX domain sockets

2 participants