-
Notifications
You must be signed in to change notification settings - Fork 22
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
Support listening both IPv4 and IPv6 + NodeRecord extension #178
Merged
StefanBratanov
merged 14 commits into
Consensys:master
from
StefanBratanov:dual_stack_support
Jun 25, 2024
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7f5fa3c
Support listening both IPv4 and IPv6 + NodeRecord extension
StefanBratanov d48bdfe
revert
StefanBratanov 44d9c81
improvements
StefanBratanov b23bd94
adding integration test
StefanBratanov 9c15104
enable ipv6
StefanBratanov 5c700f1
fix CircleCI
StefanBratanov 0abe2cb
try
StefanBratanov cd049cd
few changes
StefanBratanov de8691e
small refactor
StefanBratanov 8ea0208
nit
StefanBratanov 0dbccfc
some nits
StefanBratanov ab23789
fix spotless
StefanBratanov f534cda
Use Flux.from instead of Flux.concat
StefanBratanov 2e38ea0
fix spotless
StefanBratanov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,10 @@ | |
|
||
import io.netty.buffer.Unpooled; | ||
import io.netty.channel.socket.DatagramPacket; | ||
import io.netty.channel.socket.InternetProtocolFamily; | ||
import io.netty.channel.socket.nio.NioDatagramChannel; | ||
import java.net.InetSocketAddress; | ||
import java.util.Map; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.tuweni.bytes.Bytes; | ||
|
@@ -17,17 +19,19 @@ | |
/** Netty discovery UDP client */ | ||
public class NettyDiscoveryClientImpl implements DiscoveryClient { | ||
private static final Logger LOG = LogManager.getLogger(NettyDiscoveryClientImpl.class); | ||
private NioDatagramChannel channel; | ||
|
||
private final Map<InternetProtocolFamily, NioDatagramChannel> channels; | ||
|
||
/** | ||
* Constructs UDP client using | ||
* | ||
* @param outgoingStream Stream of outgoing packets, client will forward them to the channel | ||
* @param channel Nio channel | ||
* @param channels must have either 1 entry (IPv4/IPv6) or 2 entries (IPv4 and IPv6) | ||
*/ | ||
public NettyDiscoveryClientImpl( | ||
Publisher<NetworkParcel> outgoingStream, NioDatagramChannel channel) { | ||
this.channel = channel; | ||
final Publisher<NetworkParcel> outgoingStream, | ||
final Map<InternetProtocolFamily, NioDatagramChannel> channels) { | ||
this.channels = channels; | ||
Flux.from(outgoingStream) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we throw here if both are empty? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the design a bit. You can have a look. |
||
.subscribe( | ||
networkPacket -> | ||
|
@@ -39,8 +43,14 @@ public NettyDiscoveryClientImpl( | |
public void stop() {} | ||
|
||
@Override | ||
public void send(Bytes data, InetSocketAddress destination) { | ||
DatagramPacket packet = new DatagramPacket(Unpooled.copiedBuffer(data.toArray()), destination); | ||
public void send(final Bytes data, final InetSocketAddress destination) { | ||
final DatagramPacket packet = | ||
new DatagramPacket(Unpooled.copiedBuffer(data.toArray()), destination); | ||
final NioDatagramChannel channel = | ||
channels.getOrDefault( | ||
InternetProtocolFamily.of(destination.getAddress()), | ||
// default to any other available channel | ||
channels.values().stream().findFirst().orElseThrow()); | ||
LOG.trace(() -> String.format("Sending packet %s", packet)); | ||
channel.write(packet); | ||
channel.flush(); | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd add throw if channels is empty.