Repository: mageddo/dns-proxy-server
Pull request #368 (2023-03-17 02:25:10)

Minor Fixes
## 3.12.1
* Binding UDP server to anylocalhost just as TCP this way DPS can be used on any interface.
* Disabling mac as the binary isn't working macos-latest, see #341
* Fixing DPS network features startup


Patch:
diff --git a/.github/workflows/actions-deploy.yml b/.github/workflows/actions-deploy.yml
index a75d6590..78553b81 100644
--- a/.github/workflows/actions-deploy.yml
+++ b/.github/workflows/actions-deploy.yml
@@ -114,7 +114,8 @@ jobs:
     runs-on: ${{ matrix.os }}
     strategy:
       matrix:
-        os: [macos-latest, windows-latest]
+        os: [windows-latest]
+        # disabling mac as the binary isn't working macos-latest, see #341
     env:
       APP_VERSION: ${{ needs.primary_release.outputs.APP_VERSION }}
     steps:
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 6c27a111..74f6e978 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -1,3 +1,8 @@
+## 3.12.1
+* Binding UDP server to anylocalhost just as TCP this way DPS can be used on any interface.
+* Disabling mac as the binary isn't working macos-latest, see #341
+* Fixing DPS network features startup
+
 ## 3.12
 * Also configuring resolv.conf on Mac when in standalone mode
 * Fixing random failure on dns configs restore on MacOSX
diff --git a/build.gradle b/build.gradle
index 8d7e960c..10f3babb 100644
--- a/build.gradle
+++ b/build.gradle
@@ -33,6 +33,7 @@ dependencies {
   annotationProcessor("com.google.dagger:dagger-compiler:2.45")
   implementation("com.google.dagger:dagger:2.45")
 
+  implementation 'org.graalvm.sdk:graal-sdk:22.3.1'
   implementation('jakarta.enterprise:jakarta.enterprise.cdi-api:2.0.2')
   implementation('jakarta.ws.rs:jakarta.ws.rs-api:2.1.6')
   implementation('com.mageddo.commons:commons-lang:0.1.6')
diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml
index 5520d48b..5f9b37c8 100644
--- a/docker-compose-dev.yml
+++ b/docker-compose-dev.yml
@@ -1,26 +1,30 @@
 version: '3'
 services:
   backend:
-    image: openjdk:17-jdk
+    image: openjdk:19-jdk
     environment:
-      - MG_LOG_LEVEL=DEBUG
-      - MG_REGISTER_CONTAINER_NAMES=1
-#      - MG_RESOLVCONF=/host/etc/systemd/resolved.conf
+      MG_LOG_LEVEL: DEBUG
+      MG_DPS_NETWORK: true
+      MG_DPS_NETWORK_AUTO_CONNECT: true
+    #      - MG_LOG_LEVEL=DEBUG
+    #      - MG_REGISTER_CONTAINER_NAMES=1
+    #      - MG_RESOLVCONF=/host/etc/systemd/resolved.conf
     labels:
       - dps.container=true
     volumes:
-      - ./build:/app
+      - ./build/libs:/app
       - /var/run/docker.sock:/var/run/docker.sock
-      - /etc/systemd/:/host/etc/systemd/
+      - /etc/resolv.conf:/etc/resolv.conf
+    #      - /etc/systemd/:/host/etc/systemd/
     working_dir: /app
-    command: java -jar dns-proxy-server.jar
-#    ports:
-#      - "172.17.0.1:53:53/udp"
-#      - "192.168.0.128:53:53/udp"
-#      - "192.168.0.128:53:53/tcp"
-#      - "127.0.0.1:53:53/udp"
-#      - "127.0.0.1:53:53/tcp"
-    network_mode: host
+    command: java -jar dns-proxy-server-3.12.0-all.jar
+    #    ports:
+    #      - "172.17.0.1:53:53/udp"
+    #      - "192.168.0.128:53:53/udp"
+    #      - "192.168.0.128:53:53/tcp"
+    #      - "127.0.0.1:53:53/udp"
+    #      - "127.0.0.1:53:53/tcp"
+#    network_mode: host
 
   # https://github.com/gohugoio/hugo/releases/tag/v0.55.4
   docs:
diff --git a/gradle.properties b/gradle.properties
index 16565265..72bc992c 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,1 +1,1 @@
-version=3.12.0
+version=3.12.1
diff --git a/src/main/java/com/mageddo/dnsproxyserver/di/StartupEvent.java b/src/main/java/com/mageddo/dnsproxyserver/di/StartupEvent.java
index 4e7f32e3..0cd5fa9c 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/di/StartupEvent.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/di/StartupEvent.java
@@ -1,7 +1,5 @@
 package com.mageddo.dnsproxyserver.di;
 
-import dagger.Module;
-
 public interface StartupEvent {
   void onStart();
 }
diff --git a/src/main/java/com/mageddo/dnsproxyserver/di/module/ModuleStartup.java b/src/main/java/com/mageddo/dnsproxyserver/di/module/ModuleStartup.java
index 8e0cf38b..ffc395d0 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/di/module/ModuleStartup.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/di/module/ModuleStartup.java
@@ -2,15 +2,22 @@ package com.mageddo.dnsproxyserver.di.module;
 
 import com.mageddo.dnsproxyserver.di.StartupEvent;
 import com.mageddo.dnsproxyserver.dnsconfigurator.DnsConfigurators;
-import dagger.Binds;
+import com.mageddo.dnsproxyserver.docker.EventListener;
 import dagger.Module;
-import dagger.multibindings.IntoSet;
+import dagger.Provides;
+import dagger.multibindings.ElementsIntoSet;
+
+import javax.inject.Singleton;
+import java.util.Set;
 
 @Module
 public interface ModuleStartup {
 
-  @Binds
-  @IntoSet
-  StartupEvent startupBeans(DnsConfigurators b1);
+  @Provides
+  @Singleton
+  @ElementsIntoSet
+  static Set<StartupEvent> startupBeans(DnsConfigurators b1, EventListener b2){
+    return Set.of(b1, b2);
+  }
 
 }
diff --git a/src/main/java/com/mageddo/dnsproxyserver/server/dns/UDPServerPool.java b/src/main/java/com/mageddo/dnsproxyserver/server/dns/UDPServerPool.java
index 3902bc57..cb7f220b 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/server/dns/UDPServerPool.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/server/dns/UDPServerPool.java
@@ -1,6 +1,5 @@
 package com.mageddo.dnsproxyserver.server.dns;
 
-import com.mageddo.net.Networks;
 import com.mageddo.dnsproxyserver.utils.Ips;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -9,6 +8,7 @@ import javax.inject.Inject;
 import javax.inject.Singleton;
 import java.net.SocketAddress;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -21,12 +21,8 @@ public class UDPServerPool {
   private List<UDPServer> servers = new ArrayList<>();
 
   public void start(int port) {
-    this.servers = Networks
-      .findMachineIps()
-      .stream()
-      .map(it -> new UDPServer(Ips.toSocketAddress(it.raw(), port), this.requestHandler))
-      .peek(UDPServer::start)
-      .toList();
+    this.servers = Collections.singletonList(new UDPServer(Ips.getAnyLocalAddress(port), this.requestHandler));
+    this.servers.forEach(UDPServer::start);
     final var addresses = this.servers
       .stream()
       .map(UDPServer::getAddress)
@@ -37,8 +33,8 @@ public class UDPServerPool {
 
   public void stop() {
     this.servers
-        .parallelStream()
-        .forEach(UDPServer::stop)
+      .parallelStream()
+      .forEach(UDPServer::stop)
     ;
   }
 }
diff --git a/src/main/java/com/mageddo/dnsproxyserver/utils/Ips.java b/src/main/java/com/mageddo/dnsproxyserver/utils/Ips.java
index 3f3d1312..342fe5c6 100644
--- a/src/main/java/com/mageddo/dnsproxyserver/utils/Ips.java
+++ b/src/main/java/com/mageddo/dnsproxyserver/utils/Ips.java
@@ -51,4 +51,8 @@ public class Ips {
       return null;
     }
   }
+
+  public static InetSocketAddress getAnyLocalAddress(int port) {
+    return new InetSocketAddress(getAnyLocalAddress(), port);
+  }
 }


Test patch:
diff --git a/src/test/java/com/mageddo/dnsproxyserver/docker/EventListenerCompTest.java b/src/test/java/com/mageddo/dnsproxyserver/docker/EventListenerCompTest.java
new file mode 100644
index 00000000..26b06d39
--- /dev/null
+++ b/src/test/java/com/mageddo/dnsproxyserver/docker/EventListenerCompTest.java
@@ -0,0 +1,35 @@
+package com.mageddo.dnsproxyserver.docker;
+
+import com.mageddo.dnsproxyserver.di.Context;
+import com.mageddo.dnsproxyserver.di.StartupEvent;
+import dagger.sheath.junit.DaggerTest;
+import org.junit.jupiter.api.Test;
+
+import javax.inject.Inject;
+import java.util.Objects;
+import java.util.Set;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@DaggerTest(component = Context.class)
+class EventListenerCompTest {
+
+  @Inject
+  Set<StartupEvent> events;
+
+  @Test
+  void mustConfigureNetworkEventListener(){
+
+    // arrange
+
+    // act
+    final var size = this.events
+        .stream()
+        .filter(it -> Objects.equals(EventListener.class, it.getClass()))
+        .count();
+
+    // assert
+    assertEquals(1, size);
+
+  }
+}