You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuweni.apache.org by to...@apache.org on 2020/11/26 08:51:59 UTC

[incubator-tuweni] branch master updated: Expose actual network interface

This is an automated email from the ASF dual-hosted git repository.

toulmean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git


The following commit(s) were added to refs/heads/master by this push:
     new 69c50e4  Expose actual network interface
     new 8cabf9b  Merge pull request #176 from atoulme/expose_network_interface
69c50e4 is described below

commit 69c50e43d0d5d007338c08243c41cec07b99b34e
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Wed Nov 25 23:49:28 2020 -0800

    Expose actual network interface
---
 .../apache/tuweni/les/LESSubProtocolHandlerTest.kt | 13 ++++++++++++
 .../java/org/apache/tuweni/rlpx/RLPxService.java   | 23 ++++++++++++++++++++++
 .../apache/tuweni/rlpx/vertx/VertxRLPxService.java | 22 ++++++++++-----------
 3 files changed, 46 insertions(+), 12 deletions(-)

diff --git a/les/src/test/kotlin/org/apache/tuweni/les/LESSubProtocolHandlerTest.kt b/les/src/test/kotlin/org/apache/tuweni/les/LESSubProtocolHandlerTest.kt
index bba84a8..424090b 100644
--- a/les/src/test/kotlin/org/apache/tuweni/les/LESSubProtocolHandlerTest.kt
+++ b/les/src/test/kotlin/org/apache/tuweni/les/LESSubProtocolHandlerTest.kt
@@ -111,6 +111,19 @@ internal class LESSubProtocolHandlerTest {
   )
 
   private class MyRLPxService : RLPxService {
+
+    override fun actualPort(): Int {
+      TODO("not implemented") // To change body of created functions use File | Settings | File Templates.
+    }
+
+    override fun actualSocketAddress(): InetSocketAddress {
+      TODO("not implemented") // To change body of created functions use File | Settings | File Templates.
+    }
+
+    override fun advertisedPort(): Int {
+      TODO("not implemented") // To change body of created functions use File | Settings | File Templates.
+    }
+
     override fun getClient(subProtocolIdentifier: SubProtocolIdentifier): SubProtocolClient {
       TODO("not implemented")
     }
diff --git a/rlpx/src/main/java/org/apache/tuweni/rlpx/RLPxService.java b/rlpx/src/main/java/org/apache/tuweni/rlpx/RLPxService.java
index de2fa1e..0710ca6 100644
--- a/rlpx/src/main/java/org/apache/tuweni/rlpx/RLPxService.java
+++ b/rlpx/src/main/java/org/apache/tuweni/rlpx/RLPxService.java
@@ -37,6 +37,29 @@ public interface RLPxService {
    */
   AsyncResult<WireConnection> connectTo(SECP256K1.PublicKey peerPublicKey, InetSocketAddress peerAddress);
 
+  /**
+   * Provides the actual port in use.
+   *
+   * @return the port used by the server
+   * @throws IllegalStateException if the service is not started
+   */
+  int actualPort();
+
+  /**
+   * Provides the actual socket address (network interface and port) in use.
+   *
+   * @return the socket address used by the server
+   * @throws IllegalStateException if the service is not started
+   */
+  InetSocketAddress actualSocketAddress();
+
+  /**
+   * Provides the advertised port.
+   *
+   * @return the port advertised by the server
+   * @throws IllegalStateException if the service is not started
+   */
+  int advertisedPort();
 
   /**
    * Starts the service.
diff --git a/rlpx/src/main/java/org/apache/tuweni/rlpx/vertx/VertxRLPxService.java b/rlpx/src/main/java/org/apache/tuweni/rlpx/vertx/VertxRLPxService.java
index 4b84467..7864d57 100644
--- a/rlpx/src/main/java/org/apache/tuweni/rlpx/vertx/VertxRLPxService.java
+++ b/rlpx/src/main/java/org/apache/tuweni/rlpx/vertx/VertxRLPxService.java
@@ -249,12 +249,7 @@ public final class VertxRLPxService implements RLPxService {
     }
   }
 
-  /**
-   * Provides the actual port in use.
-   * 
-   * @return the port used by the server
-   * @throws IllegalStateException if the service is not started
-   */
+  @Override
   public int actualPort() {
     if (!started.get()) {
       throw new IllegalStateException("The RLPx service is not active");
@@ -262,12 +257,15 @@ public final class VertxRLPxService implements RLPxService {
     return server.actualPort();
   }
 
-  /**
-   * Provides the advertised port.
-   *
-   * @return the port advertised by the server
-   * @throws IllegalStateException if the service is not started
-   */
+  @Override
+  public InetSocketAddress actualSocketAddress() {
+    if (!started.get()) {
+      throw new IllegalStateException("The RLPx service is not active");
+    }
+    return new InetSocketAddress(networkInterface, server.actualPort());
+  }
+
+  @Override
   public int advertisedPort() {
     if (!started.get()) {
       throw new IllegalStateException("The RLPx service is not active");


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org