Skip to content

Commit

Permalink
fix returned discoveryPort which will be needed for port forwarding
Browse files Browse the repository at this point in the history
Signed-off-by: Daan Poron <[email protected]>
  • Loading branch information
daanporon committed Feb 21, 2024
1 parent c2c87cc commit e6c3eee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,27 @@ public CompletableFuture<Integer> start(final int tcpPort) {
.thenApply(
(InetSocketAddress localAddress) -> {
// Once listener is set up, finish initializing
final int discoveryPort =
final int localDiscoveryPort = localAddress.getPort();
final int externalDiscoveryPort =
natService
.getPortMapping(NatServiceType.DISCOVERY, NetworkProtocol.UDP)
.map(NatPortMapping::getExternalPort)
.orElseGet(localAddress::getPort);
.orElse(localDiscoveryPort);

final DiscoveryPeer ourNode =
DiscoveryPeer.fromEnode(
EnodeURLImpl.builder()
.nodeId(id)
.ipAddress(advertisedAddress)
.listeningPort(tcpPort)
.discoveryPort(discoveryPort)
.discoveryPort(externalDiscoveryPort)
.build());
this.localNode = Optional.of(ourNode);
isActive = true;
LOG.info("P2P peer discovery agent started and listening on {}", localAddress);
updateNodeRecord();
startController(ourNode);
return discoveryPort;
return localDiscoveryPort;
});
} else {
this.isActive = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.hyperledger.besu.nat.NatMethod;
import org.hyperledger.besu.nat.NatService;
import org.hyperledger.besu.nat.core.NatManager;
import org.hyperledger.besu.nat.core.domain.NatPortMapping;
import org.hyperledger.besu.nat.core.domain.NatServiceType;
import org.hyperledger.besu.nat.core.domain.NetworkProtocol;
import org.hyperledger.besu.nat.upnp.UpnpNatManager;
Expand Down Expand Up @@ -469,13 +470,17 @@ private void setLocalNode(

// override advertised host if we detect an external IP address via NAT manager
final String advertisedAddress = natService.queryExternalIPAddress(address);
final int advertisedDiscoveryPort = natService
.getPortMapping(NatServiceType.DISCOVERY, NetworkProtocol.UDP)
.map(NatPortMapping::getExternalPort)
.orElse(discoveryPort);

final EnodeURL localEnode =
EnodeURLImpl.builder()
.nodeId(nodeId)
.ipAddress(advertisedAddress)
.listeningPort(listeningPort)
.discoveryPort(discoveryPort)
.discoveryPort(advertisedDiscoveryPort)
.build();

LOG.info("Enode URL {}", localEnode.toString());
Expand Down

0 comments on commit e6c3eee

Please sign in to comment.