-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bind udp to all available interfaces (#304)
- Loading branch information
Showing
7 changed files
with
81 additions
and
28 deletions.
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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/mageddo/dnsproxyserver/server/dns/UDPServerPool.java
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.mageddo.dnsproxyserver.server.dns; | ||
|
||
import com.mageddo.dnsproxyserver.net.Networks; | ||
import com.mageddo.dnsproxyserver.utils.Ips; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import java.net.SocketAddress; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
@Singleton | ||
@RequiredArgsConstructor(onConstructor = @__({@Inject})) | ||
public class UDPServerPool { | ||
|
||
private final RequestHandler requestHandler; | ||
private List<UDPServer> servers = new ArrayList<>(); | ||
|
||
public void start(int port) { | ||
this.servers = Networks | ||
.findMachineIps() | ||
.map(it -> new UDPServer(Ips.toSocketAddress(it.raw(), port), this.requestHandler)) | ||
.peek(UDPServer::start) | ||
.toList(); | ||
final var addresses = this.servers | ||
.stream() | ||
.map(UDPServer::getAddress) | ||
.map(SocketAddress::toString) | ||
.collect(Collectors.joining(", ")); | ||
log.info("Starting UDP server, addresses={}", addresses); | ||
} | ||
} |
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