Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved creation of I2pListeners #20

Merged
merged 2 commits into from
Nov 23, 2023
Merged

Improved creation of I2pListeners #20

merged 2 commits into from
Nov 23, 2023

Conversation

a-0-dev
Copy link

@a-0-dev a-0-dev commented Nov 21, 2023

Primary goal

As of now, setting the SAMOptions of an I2pListener is not very convenient, and not supported by the primary constructing functions of I2pListener. This PR introduces an I2pListenerBuilder, which tries to fix this.

Binding to addresses

Also, currently there are three functions (bind, bind_via and bind_addr) which bind the listener to some address, but the distinction is not quite clear. The builder addresses this by only exposing the functions with_addr (exactly one already parsed SocketAddr) and with_addrs (everything that may or may not resolve to one or more SocketAddrs - hence the Result return type). From my point of view, this is easier to understand for the users and as a side effect also allows binding to exactly two SocketAddrs by just calling with_addr twice.

Changes to existing code

Changing some existing function signatures was necessary, since the SAMOptions were previously set to default() "deep in the code". This parameter is now passed down from I2pListener and I2pDatagramSocket functions. To leave the "simplest way" of instanciating a listener or datagram socket as simple as is, those function signatures weren't changed. They use the default SAMOptions.

Future work

  • A builder could also be implemented for the I2pDatagramSocket
  • Depending on the opinion of the maintainer and users of this library, the currently used bind functions of I2pListener could also be removed as they are redundant and (from my very personal perspective) less easy-to-use and harder to understand.

Philip (a-0) added 2 commits November 21, 2023 15:44
- Added `I2pListenerBuilder`, which covers the functionality of `I2pListener::bind()`, `I2pListener::bind_with_session(...)`, `I2pListener::bind_via(...)` and `I2pListener::bind_addr(...)`.
- Added parameter `options: &SAMOptions` to functions creating/instanciating streams or listeners, except the "light versions" `I2pStream::connect()` and `I2pDatagramSocket::bind(addr)`
…call by reference, introduced in last commit)
@eyedeekay
Copy link
Contributor

What's the status on testing this? Have you used it in anything yet?

@a-0-dev
Copy link
Author

a-0-dev commented Nov 22, 2023

I have tested the I2pListenerBuilder in my use case of this library (which already does "end-to-end testing" by transmitting data over I2P), both with with_addr, with_addrs and without any of them. I have not tested the with_session yet, because my code doesn't use it, but as it uses exactly the same code as before, I don't expect any problem.

@eyedeekay
Copy link
Contributor

All right then you have an ACK from me, merging.

@eyedeekay eyedeekay merged commit fbde12b into i2p:master Nov 23, 2023
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.

None yet

2 participants