Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Primary goal
As of now, setting the
SAMOptions
of anI2pListener
is not very convenient, and not supported by the primary constructing functions ofI2pListener
. This PR introduces anI2pListenerBuilder
, which tries to fix this.Binding to addresses
Also, currently there are three functions (
bind
,bind_via
andbind_addr
) which bind the listener to some address, but the distinction is not quite clear. The builder addresses this by only exposing the functionswith_addr
(exactly one already parsedSocketAddr
) andwith_addrs
(everything that may or may not resolve to one or moreSocketAddr
s - hence theResult
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 twoSocketAddr
s by just callingwith_addr
twice.Changes to existing code
Changing some existing function signatures was necessary, since the
SAMOptions
were previously set todefault()
"deep in the code". This parameter is now passed down fromI2pListener
andI2pDatagramSocket
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 defaultSAMOptions
.Future work
I2pDatagramSocket
bind
functions ofI2pListener
could also be removed as they are redundant and (from my very personal perspective) less easy-to-use and harder to understand.