mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
Rework beacon address
This commit is contained in:
parent
64cc467628
commit
aceef43f6f
3 changed files with 8 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
|||
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.issue.ErrorEvent;
|
||||
import io.xpipe.app.issue.TrackEvent;
|
||||
|
@ -8,13 +10,10 @@ import io.xpipe.beacon.BeaconConfig;
|
|||
import io.xpipe.beacon.BeaconInterface;
|
||||
import io.xpipe.core.process.OsType;
|
||||
import io.xpipe.core.util.XPipeInstallation;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
@ -127,7 +126,7 @@ public class AppBeaconServer {
|
|||
}
|
||||
|
||||
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 -> {
|
||||
server.createContext(beaconInterface.getPath(), new BeaconRequestHandler<>(beaconInterface));
|
||||
});
|
||||
|
|
|
@ -64,7 +64,8 @@ public class BeaconClient {
|
|||
var client = HttpClient.newHttpClient();
|
||||
HttpResponse<String> response;
|
||||
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();
|
||||
if (token != null) {
|
||||
builder.header("Authorization", "Bearer " + token);
|
||||
|
|
|
@ -8,7 +8,7 @@ import io.xpipe.core.util.XPipeInstallation;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.List;
|
||||
|
@ -20,7 +20,7 @@ public class BeaconServer {
|
|||
|
||||
public static boolean isReachable(int port) {
|
||||
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;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue