Skip to content

Commit

Permalink
Update Main.java
Browse files Browse the repository at this point in the history
  • Loading branch information
youfanx committed Nov 28, 2024
1 parent 984e580 commit b8ad77d
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions rxlib/src/main/java/org/rx/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.rx.net.TransportFlags;
import org.rx.net.dns.DnsClient;
import org.rx.net.dns.DnsServer;
import org.rx.net.http.*;
import org.rx.net.rpc.Remoting;
import org.rx.net.rpc.RpcClientConfig;
import org.rx.net.rpc.RpcServerConfig;
Expand All @@ -31,6 +32,7 @@
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -88,8 +90,8 @@ public static class RSSConf {
public String udp2rawEndpoint;
}

static RSSConf conf;
static boolean udp2raw = false;
static RSSConf conf;

@SneakyThrows
static void launchClient(Map<String, String> options, Integer port, Integer connectTimeout) {
Expand Down Expand Up @@ -302,11 +304,36 @@ public void addWhiteList(InetAddress endpoint) {
});
}

app.ddns();
clientInit();
log.info("Server started..");
app.await();
}

static void clientInit() {
Tasks.schedulePeriod(() -> {
if (conf == null) {
log.warn("conf is null");
}

InetAddress wanIp = InetAddress.getByName(IPSearcher.DEFAULT.currentIp());
for (String ddns : conf.ddnsDomains) {
List<InetAddress> currentIps = DnsClient.inlandClient().resolveAll(ddns);
if (currentIps.contains(wanIp)) {
continue;
}
int i = ddns.indexOf(".");
String domain = ddns.substring(i + 1), name = ddns.substring(0, i);
log.info("ddns-{}.{}: {}->{}", name, domain, currentIps, wanIp);
AuthenticProxy p = conf.godaddyProxy != null
? new AuthenticProxy(Proxy.Type.SOCKS, Sockets.parseEndpoint(conf.godaddyProxy))
: null;
IPSearcher.godaddyDns(conf.getGodaddyKey(), domain, name, wanIp.getHostAddress(), p);
}
}, conf.ddnsSeconds * 1000L);
}

static HttpServer httpServer;

static void launchServer(Map<String, String> options, Integer port, Integer connectTimeout) {
AuthenticEndpoint shadowUser = Reflects.convertQuietly(options.get("shadowUser"), AuthenticEndpoint.class);
if (shadowUser == null) {
Expand All @@ -330,34 +357,19 @@ static void launchServer(Map<String, String> options, Integer port, Integer conn
rpcConf.getTcpConfig().setTransportFlags(TransportFlags.FRONTEND_AES_COMBO.flags());
Main app = new Main(backSvr);
Remoting.register(app, rpcConf);
serverInit();
app.await();
}

final SocksProxyServer proxyServer;

void ddns() {
// Tasks.schedulePeriod(() -> {
// if (conf == null) {
// log.warn("conf is null");
// }
//
// InetAddress wanIp = InetAddress.getByName(IPSearcher.DEFAULT.currentIp());
// for (String ddns : conf.ddnsDomains) {
// List<InetAddress> currentIps = DnsClient.inlandClient().resolveAll(ddns);
// if (currentIps.contains(wanIp)) {
// continue;
// }
// int i = ddns.indexOf(".");
// String domain = ddns.substring(i + 1), name = ddns.substring(0, i);
// log.info("ddns-{}.{}: {}->{}", name, domain, currentIps, wanIp);
// AuthenticProxy p = conf.godaddyProxy != null
// ? new AuthenticProxy(Proxy.Type.SOCKS, Sockets.parseEndpoint(conf.godaddyProxy))
// : null;
// IPSearcher.godaddyDns(conf.getGodaddyKey(), domain, name, wanIp.getHostAddress(), p);
// }
// }, conf.ddnsSeconds * 1000L);
static void serverInit() {
httpServer = new HttpServer(8082, true).requestMapping("/hf", (request, response) -> {
String url = request.getQueryString().getFirst("forwardUrl");
response.jsonBody(new HttpClient().get(url).toJson());
});
}

final SocksProxyServer proxyServer;

@Override
public void fakeEndpoint(BigInteger hash, String endpoint) {
SocksSupport.fakeDict().putIfAbsent(hash, UnresolvedEndpoint.valueOf(endpoint));
Expand Down

0 comments on commit b8ad77d

Please sign in to comment.