Rework beacon address

This commit is contained in:
crschnick 2024-08-01 19:41:43 +00:00
parent 64cc467628
commit aceef43f6f
3 changed files with 8 additions and 8 deletions

View file

@ -1,5 +1,7 @@
package io.xpipe.app.beacon; package io.xpipe.app.beacon;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
import io.xpipe.app.core.AppResources; import io.xpipe.app.core.AppResources;
import io.xpipe.app.issue.ErrorEvent; import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.issue.TrackEvent; import io.xpipe.app.issue.TrackEvent;
@ -8,13 +10,10 @@ import io.xpipe.beacon.BeaconConfig;
import io.xpipe.beacon.BeaconInterface; import io.xpipe.beacon.BeaconInterface;
import io.xpipe.core.process.OsType; import io.xpipe.core.process.OsType;
import io.xpipe.core.util.XPipeInstallation; import io.xpipe.core.util.XPipeInstallation;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
import lombok.Getter; import lombok.Getter;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.Inet4Address;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
@ -127,7 +126,7 @@ public class AppBeaconServer {
} }
private void start() throws IOException { private void start() throws IOException {
server = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), port), 10); server = HttpServer.create(new InetSocketAddress(Inet4Address.getByAddress(new byte[]{ 0x7f,0x00,0x00,0x01 }), port), 10);
BeaconInterface.getAll().forEach(beaconInterface -> { BeaconInterface.getAll().forEach(beaconInterface -> {
server.createContext(beaconInterface.getPath(), new BeaconRequestHandler<>(beaconInterface)); server.createContext(beaconInterface.getPath(), new BeaconRequestHandler<>(beaconInterface));
}); });

View file

@ -64,7 +64,8 @@ public class BeaconClient {
var client = HttpClient.newHttpClient(); var client = HttpClient.newHttpClient();
HttpResponse<String> response; HttpResponse<String> response;
try { try {
var uri = URI.create("http://localhost:" + port + prov.getPath()); // Use direct IP to prevent DNS lookups and potential blocks (e.g. portmaster)
var uri = URI.create("http://127.0.0.1:" + port + prov.getPath());
var builder = HttpRequest.newBuilder(); var builder = HttpRequest.newBuilder();
if (token != null) { if (token != null) {
builder.header("Authorization", "Bearer " + token); builder.header("Authorization", "Bearer " + token);

View file

@ -8,7 +8,7 @@ import io.xpipe.core.util.XPipeInstallation;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.InetAddress; import java.net.Inet4Address;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
import java.util.List; import java.util.List;
@ -20,7 +20,7 @@ public class BeaconServer {
public static boolean isReachable(int port) { public static boolean isReachable(int port) {
try (var socket = new Socket()) { try (var socket = new Socket()) {
socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), port), 5000); socket.connect(new InetSocketAddress(Inet4Address.getByAddress(new byte[]{ 0x7f,0x00,0x00,0x01 }), port), 5000);
return true; return true;
} catch (Exception e) { } catch (Exception e) {
return false; return false;