Compare commits

..

6 Commits

Author SHA1 Message Date
1c54099c96 Merge pull request 'master' (#1) from master into dev
Reviewed-on: open-autonomous-connection/protocol#1
2025-12-08 09:40:06 +00:00
Finn
ca3bc2e2c5 Removed ProtocolBridge#getInstance 2025-12-08 10:33:46 +01:00
Finn
2ea23885fd Renamed DNS to INS 2025-12-08 09:59:58 +01:00
Finn
f5afd9c3e7 Starting with remove Instance-Getter of ProtocolBridge 2025-11-03 18:31:29 +01:00
Finn
c9b6d50be6 Fixing error with validation files 2025-10-04 01:33:57 +02:00
Open Autonomous Connection
bae9f56907 Merge pull request 'Adding proxy option' (#2) from dev into master
Reviewed-on: #2
2025-10-04 00:14:18 +02:00
42 changed files with 941 additions and 745 deletions

View File

@@ -85,7 +85,7 @@ public class Server extends ProtocolServer {
import me.openautonomousconnection.protocol.ProtocolBridge; import me.openautonomousconnection.protocol.ProtocolBridge;
import me.openautonomousconnection.protocol.ProtocolSettings; import me.openautonomousconnection.protocol.ProtocolSettings;
import me.openautonomousconnection.protocol.ProtocolVersion; import me.openautonomousconnection.protocol.ProtocolVersion;
import me.openautonomousconnection.protocol.domain.Domain; import me.openautonomousconnection.protocol.infoName.Domain;
import me.openautonomousconnection.protocol.side.ProtocolClient; import me.openautonomousconnection.protocol.side.ProtocolClient;
import me.openautonomousconnection.protocol.utils.SiteType; import me.openautonomousconnection.protocol.utils.SiteType;
@@ -103,7 +103,7 @@ public class Client extends ProtocolClient {
} }
@Override @Override
public void handleHTMLContent(SiteType siteType, Domain domain, String htmlContent) { public void handleHTMLContent(SiteType siteType, Domain infoName, String htmlContent) {
System.out.println("Website html content received. This site is " + siteType.name); System.out.println("Website html content received. This site is " + siteType.name);
System.out.println(htmlContent); // Render content in a webview for example System.out.println(htmlContent); // Render content in a webview for example
} }

View File

@@ -6,7 +6,7 @@
<groupId>org.openautonomousconnection</groupId> <groupId>org.openautonomousconnection</groupId>
<artifactId>protocol</artifactId> <artifactId>protocol</artifactId>
<version>1.0.0-BETA.6</version> <version>1.0.0-BETA.7</version>
<organization> <organization>
<name>Open Autonomous Connection</name> <name>Open Autonomous Connection</name>
<url>https://open-autonomous-connection.org/</url> <url>https://open-autonomous-connection.org/</url>
@@ -87,7 +87,7 @@
<dependency> <dependency>
<groupId>dev.unlegitdqrk</groupId> <groupId>dev.unlegitdqrk</groupId>
<artifactId>unlegitlibrary</artifactId> <artifactId>unlegitlibrary</artifactId>
<version>1.6.5</version> <version>1.6.6</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>

View File

@@ -5,20 +5,22 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.listeners.ClientListener; import org.openautonomousconnection.protocol.listeners.ClientListener;
import org.openautonomousconnection.protocol.listeners.DNSServerListener; import org.openautonomousconnection.protocol.listeners.INSServerListener;
import org.openautonomousconnection.protocol.listeners.WebServerListener; import org.openautonomousconnection.protocol.listeners.WebServerListener;
import org.openautonomousconnection.protocol.packets.OACPacket; import org.openautonomousconnection.protocol.packets.OACPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.AuthPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.AuthPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.GetDestinationPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.GetDestinationPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.ValidateDomainPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.ValidateInfoNamePacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_DomainPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_DomainPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket;
import org.openautonomousconnection.protocol.side.client.ProtocolClient; import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.side.dns.ProtocolDNSServer; import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer; import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerDNSServer; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerINSServer;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ClientListener; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ClientListener;
@@ -31,13 +33,6 @@ import java.net.Proxy;
* It manages the protocol settings, version, and side instances. * It manages the protocol settings, version, and side instances.
*/ */
public final class ProtocolBridge { public final class ProtocolBridge {
/**
* The singleton instance of the ProtocolBridge class
*/
@Getter
private static ProtocolBridge instance;
/** /**
* The protocol settings for the current connection * The protocol settings for the current connection
*/ */
@@ -60,7 +55,7 @@ public final class ProtocolBridge {
* The protocol side instances * The protocol side instances
*/ */
@Getter @Getter
private ProtocolDNSServer protocolDNSServer; private ProtocolINSServer protocolINSServer;
/** /**
* The protocol side instances * The protocol side instances
@@ -75,11 +70,11 @@ public final class ProtocolBridge {
private ProtocolWebServer protocolWebServer; private ProtocolWebServer protocolWebServer;
/** /**
* The classic protocol handlers for dns server side * The classic protocol handlers for INS server side
*/ */
@Getter @Getter
@Setter @Setter
private ClassicHandlerDNSServer classicHandlerDNSServer; private ClassicHandlerINSServer classicHandlerINSServer;
/** /**
* The classic protocol handlers for web server side * The classic protocol handlers for web server side
@@ -103,18 +98,19 @@ public final class ProtocolBridge {
private Proxy proxy; private Proxy proxy;
/** /**
* Initialize the ProtocolBridge instance for the DNS server side * Initialize the ProtocolBridge instance for the INS server side
* *
* @param protocolDNSServer The ProtocolDNSServer instance * @param protocolINSServer The ProtocolINSServer instance
* @param protocolSettings The ProtocolSettings instance * @param protocolSettings The ProtocolSettings instance
* @param protocolVersion The ProtocolVersion instance * @param protocolVersion The ProtocolVersion instance
* @param logFolder The folder to store the log files * @param logFolder The folder to store the log files
* @throws Exception if an error occurs while initializing the ProtocolBridge * @throws Exception if an error occurs while initializing the ProtocolBridge
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public ProtocolBridge(ProtocolDNSServer protocolDNSServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception { public ProtocolBridge(ProtocolINSServer protocolINSServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
// Assign the parameters to the class fields // Assign the parameters to the class fields
this.protocolDNSServer = protocolDNSServer; this.protocolINSServer = protocolINSServer;
this.protocolINSServer.setProtocolBridge(this);
this.protocolSettings = protocolSettings; this.protocolSettings = protocolSettings;
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
@@ -125,9 +121,6 @@ public final class ProtocolBridge {
// Register the appropriate listeners and packets // Register the appropriate listeners and packets
registerListeners(); registerListeners();
registerPackets(); registerPackets();
// Set the static instance to this instance
instance = this;
} }
/** /**
@@ -143,6 +136,7 @@ public final class ProtocolBridge {
public ProtocolBridge(ProtocolWebServer protocolWebServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception { public ProtocolBridge(ProtocolWebServer protocolWebServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
// Assign the parameters to the class fields // Assign the parameters to the class fields
this.protocolWebServer = protocolWebServer; this.protocolWebServer = protocolWebServer;
this.protocolWebServer.setProtocolBridge(this);
this.protocolSettings = protocolSettings; this.protocolSettings = protocolSettings;
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
@@ -153,9 +147,6 @@ public final class ProtocolBridge {
// Register the appropriate listeners and packets // Register the appropriate listeners and packets
registerListeners(); registerListeners();
registerPackets(); registerPackets();
// Set the static instance to this instance
instance = this;
} }
/** /**
@@ -171,6 +162,7 @@ public final class ProtocolBridge {
public ProtocolBridge(ProtocolClient protocolClient, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception { public ProtocolBridge(ProtocolClient protocolClient, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
// Assign the parameters to the class fields // Assign the parameters to the class fields
this.protocolClient = protocolClient; this.protocolClient = protocolClient;
this.protocolClient.setProtocolBridge(this);
this.protocolSettings = protocolSettings; this.protocolSettings = protocolSettings;
this.protocolVersion = protocolVersion; this.protocolVersion = protocolVersion;
@@ -181,9 +173,6 @@ public final class ProtocolBridge {
// Register the appropriate listeners and packets // Register the appropriate listeners and packets
registerListeners(); registerListeners();
registerPackets(); registerPackets();
// Set the static instance to this instance
instance = this;
} }
/** /**
@@ -192,8 +181,8 @@ public final class ProtocolBridge {
private void registerPackets() { private void registerPackets() {
// Classic packets // Classic packets
Classic_DomainPacket cDomainPacket = new Classic_DomainPacket(); Classic_DomainPacket cDomainPacket = new Classic_DomainPacket();
Classic_DomainPacket cMessagePacket = new Classic_DomainPacket(); Classic_MessagePacket cMessagePacket = new Classic_MessagePacket();
Classic_DomainPacket cPingPacket = new Classic_DomainPacket(); Classic_PingPacket cPingPacket = new Classic_PingPacket();
if (isPacketSupported(cDomainPacket)) protocolSettings.packetHandler.registerPacket(cDomainPacket); if (isPacketSupported(cDomainPacket)) protocolSettings.packetHandler.registerPacket(cDomainPacket);
if (isPacketSupported(cMessagePacket)) protocolSettings.packetHandler.registerPacket(cMessagePacket); if (isPacketSupported(cMessagePacket)) protocolSettings.packetHandler.registerPacket(cMessagePacket);
@@ -202,14 +191,14 @@ public final class ProtocolBridge {
// 1.0.0-BETA packets // 1.0.0-BETA packets
AuthPacket v100bAuthPath = new AuthPacket(); AuthPacket v100bAuthPath = new AuthPacket();
UnsupportedClassicPacket v100bUnsupportedClassicPacket = new UnsupportedClassicPacket(); UnsupportedClassicPacket v100bUnsupportedClassicPacket = new UnsupportedClassicPacket();
ValidateDomainPacket v100bValidateDomainPacket = new ValidateDomainPacket(); ValidateInfoNamePacket v100BValidateInfoNamePacket = new ValidateInfoNamePacket();
GetDestinationPacket v100bGetDestinationPacket = new GetDestinationPacket(); GetDestinationPacket v100bGetDestinationPacket = new GetDestinationPacket();
if (isPacketSupported(v100bAuthPath)) protocolSettings.packetHandler.registerPacket(v100bAuthPath); if (isPacketSupported(v100bAuthPath)) protocolSettings.packetHandler.registerPacket(v100bAuthPath);
if (isPacketSupported(v100bUnsupportedClassicPacket)) if (isPacketSupported(v100bUnsupportedClassicPacket))
protocolSettings.packetHandler.registerPacket(v100bUnsupportedClassicPacket); protocolSettings.packetHandler.registerPacket(v100bUnsupportedClassicPacket);
if (isPacketSupported(v100bValidateDomainPacket)) if (isPacketSupported(v100BValidateInfoNamePacket))
protocolSettings.packetHandler.registerPacket(v100bValidateDomainPacket); protocolSettings.packetHandler.registerPacket(v100BValidateInfoNamePacket);
if (isPacketSupported(v100bGetDestinationPacket)) if (isPacketSupported(v100bGetDestinationPacket))
protocolSettings.packetHandler.registerPacket(v100bGetDestinationPacket); protocolSettings.packetHandler.registerPacket(v100bGetDestinationPacket);
} }
@@ -221,27 +210,37 @@ public final class ProtocolBridge {
*/ */
private void registerListeners() throws Exception { private void registerListeners() throws Exception {
// Classic listeners // Classic listeners
if (isClassicSupported()) protocolSettings.eventManager.registerListener(Classic_ClientListener.class); if (isClassicSupported()) {
Classic_ClientListener classicListener = new Classic_ClientListener();
classicListener.setProtocolBridge(this);
protocolSettings.eventManager.registerListener(classicListener.getClass());
}
else protocolSettings.eventManager.unregisterListener(Classic_ClientListener.class); else protocolSettings.eventManager.unregisterListener(Classic_ClientListener.class);
// DNS Listeners // INS Listeners
if (isRunningAsDNSServer()) { if (isRunningAsINSServer()) {
protocolSettings.eventManager.registerListener(DNSServerListener.class); INSServerListener serverListener = new INSServerListener();
serverListener.setINSServer(protocolINSServer);
protocolSettings.eventManager.registerListener(serverListener.getClass());
protocolSettings.eventManager.unregisterListener(WebServerListener.class); protocolSettings.eventManager.unregisterListener(WebServerListener.class);
protocolSettings.eventManager.unregisterListener(ClientListener.class); protocolSettings.eventManager.unregisterListener(ClientListener.class);
} }
// Web Listeners // Web Listeners
if (isRunningAsWebServer()) { if (isRunningAsWebServer()) {
protocolSettings.eventManager.registerListener(WebServerListener.class); WebServerListener serverListener = new WebServerListener();
protocolSettings.eventManager.unregisterListener(DNSServerListener.class); serverListener.setWebServer(protocolWebServer);
protocolSettings.eventManager.registerListener(serverListener.getClass());
protocolSettings.eventManager.unregisterListener(INSServerListener.class);
protocolSettings.eventManager.unregisterListener(ClientListener.class); protocolSettings.eventManager.unregisterListener(ClientListener.class);
} }
// Client Listeners // Client Listeners
if (isRunningAsClient()) { if (isRunningAsClient()) {
protocolSettings.eventManager.registerListener(ClientListener.class); ClientListener clientListener = new ClientListener();
protocolSettings.eventManager.unregisterListener(DNSServerListener.class); clientListener.setClient(protocolClient);
protocolSettings.eventManager.registerListener(clientListener.getClass());
protocolSettings.eventManager.unregisterListener(INSServerListener.class);
protocolSettings.eventManager.unregisterListener(WebServerListener.class); protocolSettings.eventManager.unregisterListener(WebServerListener.class);
} }
} }
@@ -346,27 +345,27 @@ public final class ProtocolBridge {
return return
(isRunningAsClient() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT) || (isRunningAsClient() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT) ||
(isRunningAsClient() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT_WEB) || (isRunningAsClient() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT_WEB) ||
(isRunningAsClient() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT_DNS) || (isRunningAsClient() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT_INS) ||
(isRunningAsClient() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.ALL) || (isRunningAsClient() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.ALL) ||
(isRunningAsWebServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.WEB) || (isRunningAsWebServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.WEB) ||
(isRunningAsWebServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT_WEB) || (isRunningAsWebServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT_WEB) ||
(isRunningAsWebServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.WEB_DNS) || (isRunningAsWebServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.WEB_INS) ||
(isRunningAsWebServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.ALL) || (isRunningAsWebServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.ALL) ||
(isRunningAsDNSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.DNS) || (isRunningAsINSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.INS) ||
(isRunningAsDNSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.WEB_DNS) || (isRunningAsINSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.WEB_INS) ||
(isRunningAsDNSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT_DNS) || (isRunningAsINSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT_INS) ||
(isRunningAsDNSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.ALL); (isRunningAsINSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.ALL);
} }
/** /**
* Check if the current instance is running as a DNS server * Check if the current instance is running as a INS server
* *
* @return true if the current instance is running as a DNS server, false otherwise * @return true if the current instance is running as a INS server, false otherwise
*/ */
public boolean isRunningAsDNSServer() { public boolean isRunningAsINSServer() {
return protocolDNSServer != null; return protocolINSServer != null;
} }
/** /**

View File

@@ -4,9 +4,11 @@ import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
import dev.unlegitdqrk.unlegitlibrary.event.Listener; import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import dev.unlegitdqrk.unlegitlibrary.network.system.client.events.ClientConnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.client.events.ClientConnectedEvent;
import dev.unlegitdqrk.unlegitlibrary.network.system.client.events.ClientDisconnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.client.events.ClientDisconnectedEvent;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.AuthPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.AuthPacket;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import java.io.IOException; import java.io.IOException;
@@ -17,6 +19,21 @@ import java.io.IOException;
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
public final class ClientListener extends EventListener { public final class ClientListener extends EventListener {
/**
* The reference to the ProtocolClient object
*/
@Getter
private ProtocolClient client;
/**
* Sets the client variable
* @param client The Instance of the ProtocolClient
*/
public void setClient(ProtocolClient client) {
if (this.client != null) return;
this.client = client;
}
/** /**
* Handles the event when a client connects. * Handles the event when a client connects.
* Sends an authentication packet to the server. * Sends an authentication packet to the server.
@@ -26,9 +43,9 @@ public final class ClientListener extends EventListener {
@Listener @Listener
public void onConnect(ClientConnectedEvent event) { public void onConnect(ClientConnectedEvent event) {
try { try {
event.getClient().sendPacket(new AuthPacket()); event.getClient().sendPacket(new AuthPacket(client.getProtocolBridge()));
} catch (IOException | ClassNotFoundException exception) { } catch (IOException | ClassNotFoundException exception) {
ProtocolBridge.getInstance().getLogger().exception("Failed to send auth packet", exception); event.getClient().getLogger().exception("Failed to send auth packet", exception);
event.getClient().disconnect(); event.getClient().disconnect();
} }
} }
@@ -41,7 +58,7 @@ public final class ClientListener extends EventListener {
*/ */
@Listener @Listener
public void onDisconnect(ClientDisconnectedEvent event) { public void onDisconnect(ClientDisconnectedEvent event) {
ProtocolBridge.getInstance().getProtocolClient().onDNSDisconnect(event); client.onINSDisconnect(event);
} }
} }

View File

@@ -4,38 +4,55 @@ import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
import dev.unlegitdqrk.unlegitlibrary.event.Listener; import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerConnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerConnectedEvent;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerDisconnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerDisconnectedEvent;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient; import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
/** /**
* Listener for DNS server connection events. * Listener for INS server connection events.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public final class DNSServerListener extends EventListener { public final class INSServerListener extends EventListener {
/** /**
* Handles the event when a connection handler connects to the DNS server. * The reference to the INSServer object
* Adds the connected client to the ProtocolBridge's DNS server client list. */
@Getter
private ProtocolINSServer insServer;
/**
* Sets the insServer variable
* @param insServer The Instance of the INSServer
*/
public void setINSServer(ProtocolINSServer insServer) {
if (this.insServer != null) return;
this.insServer = insServer;
}
/**
* Handles the event when a connection handler connects to the INS server.
* Adds the connected client to the ProtocolBridge's INS server client list.
* *
* @param event The connection handler connected event. * @param event The connection handler connected event.
*/ */
@Listener @Listener
public void onConnect(ConnectionHandlerConnectedEvent event) { public void onConnect(ConnectionHandlerConnectedEvent event) {
ProtocolBridge.getInstance().getProtocolDNSServer().getClients().add(new ConnectedProtocolClient(event.getConnectionHandler())); insServer.getClients().add(new ConnectedProtocolClient(event.getConnectionHandler(), insServer));
} }
/** /**
* Handles the event when a connection handler disconnects from the DNS server. * Handles the event when a connection handler disconnects from the INS server.
* Removes the disconnected client from the ProtocolBridge's DNS server client list. * Removes the disconnected client from the ProtocolBridge's INS server client list.
* *
* @param event The connection handler disconnected event. * @param event The connection handler disconnected event.
*/ */
@Listener @Listener
public void onDisconnect(ConnectionHandlerDisconnectedEvent event) { public void onDisconnect(ConnectionHandlerDisconnectedEvent event) {
ProtocolBridge.getInstance().getProtocolDNSServer().getClients().removeIf(client -> insServer.getClients().removeIf(client -> client.getConnectionHandler().getClientID() == -1);
client.getConnectionHandler().getClientID() == -1);
} }
} }

View File

@@ -4,9 +4,12 @@ import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
import dev.unlegitdqrk.unlegitlibrary.event.Listener; import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerConnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerConnectedEvent;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerDisconnectedEvent; import dev.unlegitdqrk.unlegitlibrary.network.system.server.events.ConnectionHandlerDisconnectedEvent;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.side.web.ConnectedWebClient; import org.openautonomousconnection.protocol.side.web.ConnectedWebClient;
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
/** /**
@@ -15,6 +18,21 @@ import org.openautonomousconnection.protocol.versions.ProtocolVersion;
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
public final class WebServerListener extends EventListener { public final class WebServerListener extends EventListener {
/**
* The reference to the ProtocolWebServer object
*/
@Getter
private ProtocolWebServer webServer;
/**
* Sets the webServer variable
* @param webServer The Instance of the ProtocolWebServer
*/
public void setWebServer(ProtocolWebServer webServer) {
if (this.webServer != null) return;
this.webServer = webServer;
}
/** /**
* Handles the event when a connection is established. * Handles the event when a connection is established.
* Adds the connected client to the protocol web server's client list. * Adds the connected client to the protocol web server's client list.
@@ -23,7 +41,7 @@ public final class WebServerListener extends EventListener {
*/ */
@Listener @Listener
public void onConnect(ConnectionHandlerConnectedEvent event) { public void onConnect(ConnectionHandlerConnectedEvent event) {
ProtocolBridge.getInstance().getProtocolWebServer().getClients().add(new ConnectedWebClient(event.getConnectionHandler())); webServer.getClients().add(new ConnectedWebClient(event.getConnectionHandler()));
} }
/** /**
@@ -34,7 +52,7 @@ public final class WebServerListener extends EventListener {
*/ */
@Listener @Listener
public void onDisconnect(ConnectionHandlerDisconnectedEvent event) { public void onDisconnect(ConnectionHandlerDisconnectedEvent event) {
ProtocolBridge.getInstance().getProtocolWebServer().getClients().removeIf(client -> client.getPipelineConnection().getClientID() == -1); webServer.getClients().removeIf(client -> client.getPipelineConnection().getClientID() == -1);
} }
} }

View File

@@ -4,7 +4,7 @@ import dev.unlegitdqrk.unlegitlibrary.network.system.packets.Packet;
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler; import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
import lombok.Getter; import lombok.Getter;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseCode;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
@@ -25,7 +25,7 @@ public abstract class OACPacket extends Packet {
/** /**
* The response code for the packet, defaulting to RESPONSE_NOT_REQUIRED. * The response code for the packet, defaulting to RESPONSE_NOT_REQUIRED.
*/ */
private DNSResponseCode responseCode = DNSResponseCode.RESPONSE_NOT_REQUIRED; private INSResponseCode responseCode = INSResponseCode.RESPONSE_NOT_REQUIRED;
/** /**
* Constructor for OACPacket. * Constructor for OACPacket.
@@ -41,18 +41,18 @@ public abstract class OACPacket extends Packet {
/** /**
* Gets the response code for the packet. * Gets the response code for the packet.
* *
* @return The DNSResponseCode associated with the packet. * @return The INSResponseCode associated with the packet.
*/ */
protected final DNSResponseCode getResponseCode() { protected final INSResponseCode getResponseCode() {
return responseCode; return responseCode;
} }
/** /**
* Sets the response code for the packet. * Sets the response code for the packet.
* *
* @param responseCode The DNSResponseCode to set for the packet. * @param responseCode The INSResponseCode to set for the packet.
*/ */
protected final void setResponseCode(DNSResponseCode responseCode) { protected final void setResponseCode(INSResponseCode responseCode) {
this.responseCode = responseCode; this.responseCode = responseCode;
} }
@@ -80,8 +80,8 @@ public abstract class OACPacket extends Packet {
// Read the response code if the protocol version is not classic // Read the response code if the protocol version is not classic
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC) if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC)
responseCode = (DNSResponseCode) objectInputStream.readObject(); responseCode = (INSResponseCode) objectInputStream.readObject();
else responseCode = DNSResponseCode.RESPONSE_NOT_REQUIRED; else responseCode = INSResponseCode.RESPONSE_NOT_REQUIRED;
// Call the response code read handler // Call the response code read handler
onResponseCodeRead(packetHandler, objectInputStream); onResponseCodeRead(packetHandler, objectInputStream);

View File

@@ -6,12 +6,12 @@ import dev.unlegitdqrk.unlegitlibrary.network.system.server.ConnectionHandler;
import dev.unlegitdqrk.unlegitlibrary.network.utils.NetworkUtils; import dev.unlegitdqrk.unlegitlibrary.network.utils.NetworkUtils;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.packets.OACPacket; import org.openautonomousconnection.protocol.packets.OACPacket;
import org.openautonomousconnection.protocol.side.client.events.ConnectedToProtocolDNSServerEvent; import org.openautonomousconnection.protocol.side.client.events.ConnectedToProtocolINSServerEvent;
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient; import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
import org.openautonomousconnection.protocol.side.dns.events.ConnectedProtocolClientEvent; import org.openautonomousconnection.protocol.side.ins.events.ConnectedProtocolClientEvent;
import org.openautonomousconnection.protocol.side.web.ConnectedWebClient; import org.openautonomousconnection.protocol.side.web.ConnectedWebClient;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseCode;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -20,13 +20,12 @@ import java.io.ObjectOutputStream;
public final class AuthPacket extends OACPacket { public final class AuthPacket extends OACPacket {
File certificatesFolder = new File("certificates"); private ProtocolBridge protocolBridge;
File publicFolder = new File(certificatesFolder, "public");
File publicCAFolder = new File(publicFolder, "ca"); public AuthPacket(ProtocolBridge protocolBridge) {
File publicServerFolder = new File(publicFolder, "server"); this();
File privateFolder = new File(certificatesFolder, "private"); this.protocolBridge = protocolBridge;
File privateCAFolder = new File(privateFolder, "ca"); }
File privateServerFolder = new File(privateFolder, "server");
public AuthPacket() { public AuthPacket() {
super(4, ProtocolVersion.PV_1_0_0_BETA); super(4, ProtocolVersion.PV_1_0_0_BETA);
@@ -34,72 +33,72 @@ public final class AuthPacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) { if (protocolBridge.isRunningAsINSServer()) {
objectOutputStream.writeObject(ProtocolBridge.getInstance().getProtocolVersion()); objectOutputStream.writeObject(protocolBridge.getProtocolVersion());
// Read ca files // Read ca files
String caKey = "N/A"; String caKey = "N/A";
String caPem = "N/A"; String caPem = "N/A";
String caSrl = "N/A"; String caSrl = "N/A";
try { try {
objectOutputStream.writeUTF(ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress()); objectOutputStream.writeUTF(protocolBridge.getProtocolINSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress());
caKey = FileUtils.readFileFull(new File( caKey = FileUtils.readFileFull(new File(
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().privateCAFolder, protocolBridge.getProtocolINSServer().getFolderStructure().privateCAFolder,
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".key")); protocolBridge.getProtocolINSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".key"));
caPem = FileUtils.readFileFull(new File( caPem = FileUtils.readFileFull(new File(
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().publicCAFolder, protocolBridge.getProtocolINSServer().getFolderStructure().publicCAFolder,
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".pem")); protocolBridge.getProtocolINSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".pem"));
caSrl = FileUtils.readFileFull(new File( caSrl = FileUtils.readFileFull(new File(
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().publicCAFolder, protocolBridge.getProtocolINSServer().getFolderStructure().publicCAFolder,
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".srl")); protocolBridge.getProtocolINSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".srl"));
} catch (Exception exception) { } catch (Exception exception) {
ProtocolBridge.getInstance().getLogger().exception("Failed to read ca-files", exception); protocolBridge.getLogger().exception("Failed to read ca-files", exception);
setResponseCode(DNSResponseCode.RESPONSE_AUTH_FAILED); setResponseCode(INSResponseCode.RESPONSE_AUTH_FAILED);
} }
// Send ca data // Send ca data
objectOutputStream.writeUTF(caKey); objectOutputStream.writeUTF(caKey);
objectOutputStream.writeUTF(caPem); objectOutputStream.writeUTF(caPem);
objectOutputStream.writeUTF(caSrl); objectOutputStream.writeUTF(caSrl);
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (protocolBridge.isRunningAsClient()) {
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID()); objectOutputStream.writeInt(protocolBridge.getProtocolClient().getClientINSConnection().getClientID());
objectOutputStream.writeObject(ProtocolBridge.getInstance().getProtocolVersion()); objectOutputStream.writeObject(protocolBridge.getProtocolVersion());
} }
} }
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsDNSServer() || ProtocolBridge.getInstance().isRunningAsWebServer()) { if (protocolBridge.isRunningAsINSServer() || protocolBridge.isRunningAsWebServer()) {
int clientID = objectInputStream.readInt(); int clientID = objectInputStream.readInt();
ProtocolVersion clientVersion = (ProtocolVersion) objectInputStream.readObject(); ProtocolVersion clientVersion = (ProtocolVersion) objectInputStream.readObject();
ConnectionHandler connectionHandler = ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getConnectionHandlerByID(clientID); ConnectionHandler connectionHandler = protocolBridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID);
if (!ProtocolBridge.getInstance().isVersionSupported(clientVersion)) { if (!protocolBridge.isVersionSupported(clientVersion)) {
setResponseCode(DNSResponseCode.RESPONSE_AUTH_FAILED); setResponseCode(INSResponseCode.RESPONSE_AUTH_FAILED);
connectionHandler.disconnect(); connectionHandler.disconnect();
return; return;
} else setResponseCode(DNSResponseCode.RESPONSE_AUTH_SUCCESS); } else setResponseCode(INSResponseCode.RESPONSE_AUTH_SUCCESS);
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) { if (protocolBridge.isRunningAsINSServer()) {
ConnectedProtocolClient client = ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID); ConnectedProtocolClient client = protocolBridge.getProtocolINSServer().getClientByID(clientID);
client.setClientVersion(clientVersion); client.setClientVersion(clientVersion);
ProtocolBridge.getInstance().getProtocolSettings().eventManager.executeEvent(new ConnectedProtocolClientEvent(client)); protocolBridge.getProtocolSettings().eventManager.executeEvent(new ConnectedProtocolClientEvent(client));
} else { } else {
ConnectedWebClient client = ProtocolBridge.getInstance().getProtocolWebServer().getClientByID(clientID); ConnectedWebClient client = protocolBridge.getProtocolWebServer().getClientByID(clientID);
client.setClientVersion(clientVersion); client.setClientVersion(clientVersion);
} }
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (protocolBridge.isRunningAsClient()) {
ProtocolVersion serverVersion = (ProtocolVersion) objectInputStream.readObject(); ProtocolVersion serverVersion = (ProtocolVersion) objectInputStream.readObject();
if (!ProtocolBridge.getInstance().isVersionSupported(serverVersion)) { if (!protocolBridge.isVersionSupported(serverVersion)) {
setResponseCode(DNSResponseCode.RESPONSE_AUTH_FAILED); setResponseCode(INSResponseCode.RESPONSE_AUTH_FAILED);
ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().disconnect(); protocolBridge.getProtocolClient().getClientINSConnection().disconnect();
return; return;
} else setResponseCode(DNSResponseCode.RESPONSE_AUTH_SUCCESS); } else setResponseCode(INSResponseCode.RESPONSE_AUTH_SUCCESS);
String caPrefix = objectInputStream.readUTF(); String caPrefix = objectInputStream.readUTF();
@@ -108,12 +107,12 @@ public final class AuthPacket extends OACPacket {
String caSrl = objectInputStream.readUTF(); String caSrl = objectInputStream.readUTF();
if (caKey.equalsIgnoreCase("N/A") || caPem.equalsIgnoreCase("N/A") || caSrl.equalsIgnoreCase("N/A")) if (caKey.equalsIgnoreCase("N/A") || caPem.equalsIgnoreCase("N/A") || caSrl.equalsIgnoreCase("N/A"))
setResponseCode(DNSResponseCode.RESPONSE_AUTH_FAILED); setResponseCode(INSResponseCode.RESPONSE_AUTH_FAILED);
else { else {
File caPemFile = new File(ProtocolBridge.getInstance().getProtocolClient().getFolderStructure().publicCAFolder, caPrefix + ".pem"); File caPemFile = new File(protocolBridge.getProtocolClient().getFolderStructure().publicCAFolder, caPrefix + ".pem");
File caSrlFile = new File(ProtocolBridge.getInstance().getProtocolClient().getFolderStructure().publicCAFolder, caPrefix + ".srl"); File caSrlFile = new File(protocolBridge.getProtocolClient().getFolderStructure().publicCAFolder, caPrefix + ".srl");
File caKeyFile = new File(ProtocolBridge.getInstance().getProtocolClient().getFolderStructure().privateCAFolder, caPrefix + ".key"); File caKeyFile = new File(protocolBridge.getProtocolClient().getFolderStructure().privateCAFolder, caPrefix + ".key");
try { try {
if (!caPemFile.exists()) caPemFile.createNewFile(); if (!caPemFile.exists()) caPemFile.createNewFile();
@@ -124,13 +123,13 @@ public final class AuthPacket extends OACPacket {
FileUtils.writeFile(caSrlFile, caKey); FileUtils.writeFile(caSrlFile, caKey);
FileUtils.writeFile(caKeyFile, caSrl); FileUtils.writeFile(caKeyFile, caSrl);
} catch (Exception exception) { } catch (Exception exception) {
ProtocolBridge.getInstance().getLogger().exception("Failed to create/save ca-files", exception); protocolBridge.getLogger().exception("Failed to create/save ca-files", exception);
setResponseCode(DNSResponseCode.RESPONSE_AUTH_FAILED); setResponseCode(INSResponseCode.RESPONSE_AUTH_FAILED);
} }
} }
ProtocolBridge.getInstance().getProtocolClient().setServerVersion(serverVersion); protocolBridge.getProtocolClient().setServerVersion(serverVersion);
ProtocolBridge.getInstance().getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolDNSServerEvent()); protocolBridge.getProtocolSettings().eventManager.executeEvent(new ConnectedToProtocolINSServerEvent(protocolBridge.getProtocolClient()));
} }
} }
} }

View File

@@ -4,33 +4,36 @@ import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.packets.OACPacket; import org.openautonomousconnection.protocol.packets.OACPacket;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseCode;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
public final class GetDestinationPacket extends OACPacket { public final class GetDestinationPacket extends OACPacket {
private Domain domain; private InfoName infoName;
private int clientID; private int clientID;
private DNSResponseCode validationResponse; private INSResponseCode validationResponse;
private String destination; private String destination;
private ProtocolBridge protocolBridge;
// DNS-Server Constructor // INS-Server Constructor
public GetDestinationPacket(Domain domain, DNSResponseCode validationResponse, String destination) { public GetDestinationPacket(InfoName infoName, INSResponseCode validationResponse, String destination, ProtocolBridge protocolBridge) {
this(); this();
this.domain = domain; this.infoName = infoName;
this.validationResponse = validationResponse; this.validationResponse = validationResponse;
this.destination = destination; this.destination = destination;
this.protocolBridge = protocolBridge;
} }
// Client Constructor // Client Constructor
public GetDestinationPacket(Domain domain, DNSResponseCode validationResponse) { public GetDestinationPacket(InfoName infoName, INSResponseCode validationResponse, ProtocolBridge protocolBridge) {
this(); this();
this.domain = domain; this.infoName = infoName;
this.validationResponse = validationResponse; this.validationResponse = validationResponse;
this.destination = destination; this.destination = destination;
this.protocolBridge = protocolBridge;
} }
// Registration Constructor // Registration Constructor
@@ -40,14 +43,14 @@ public final class GetDestinationPacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsClient()) { if (protocolBridge.isRunningAsClient()) {
if (validationResponse != DNSResponseCode.RESPONSE_DOMAIN_FULLY_EXIST) return; if (validationResponse != INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST) return;
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID()); objectOutputStream.writeInt(protocolBridge.getProtocolClient().getClientINSConnection().getClientID());
objectOutputStream.writeObject(domain); objectOutputStream.writeObject(infoName);
objectOutputStream.writeObject(validationResponse); objectOutputStream.writeObject(validationResponse);
} else if (ProtocolBridge.getInstance().isRunningAsDNSServer()) { } else if (protocolBridge.isRunningAsINSServer()) {
objectOutputStream.writeObject(domain); objectOutputStream.writeObject(infoName);
objectOutputStream.writeObject(validationResponse); objectOutputStream.writeObject(validationResponse);
objectOutputStream.writeUTF(destination); objectOutputStream.writeUTF(destination);
} }
@@ -55,16 +58,16 @@ public final class GetDestinationPacket extends OACPacket {
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) { if (protocolBridge.isRunningAsINSServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
domain = (Domain) objectInputStream.readObject(); infoName = (InfoName) objectInputStream.readObject();
validationResponse = (DNSResponseCode) objectInputStream.readObject(); validationResponse = (INSResponseCode) objectInputStream.readObject();
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (protocolBridge.isRunningAsClient()) {
domain = (Domain) objectInputStream.readObject(); infoName = (InfoName) objectInputStream.readObject();
validationResponse = (DNSResponseCode) objectInputStream.readObject(); validationResponse = (INSResponseCode) objectInputStream.readObject();
destination = objectInputStream.readUTF(); destination = objectInputStream.readUTF();
ProtocolBridge.getInstance().getProtocolClient().getDestinationCompleted(domain, destination, validationResponse); protocolBridge.getProtocolClient().getDestinationCompleted(infoName, destination, validationResponse);
} }
} }
@@ -72,14 +75,14 @@ public final class GetDestinationPacket extends OACPacket {
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) { protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {
super.onResponseCodeRead(packetHandler, objectInputStream); super.onResponseCodeRead(packetHandler, objectInputStream);
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) { if (protocolBridge.isRunningAsINSServer()) {
if (validationResponse != DNSResponseCode.RESPONSE_DOMAIN_FULLY_EXIST) return; if (validationResponse != INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST) return;
destination = domain.getDestination(); destination = infoName.getDestination(protocolBridge);
try { try {
ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID).getConnectionHandler().sendPacket(new GetDestinationPacket(domain, validationResponse, destination)); protocolBridge.getProtocolINSServer().getClientByID(clientID).getConnectionHandler().sendPacket(new GetDestinationPacket(infoName, validationResponse, destination, protocolBridge));
} catch (IOException | ClassNotFoundException exception) { } catch (IOException | ClassNotFoundException exception) {
ProtocolBridge.getInstance().getProtocolDNSServer().domainDestinationPacketFailedSend(ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID), domain, validationResponse, exception); protocolBridge.getProtocolINSServer().infoNameDestinationPacketFailedSend(protocolBridge.getProtocolINSServer().getClientByID(clientID), infoName, validationResponse, exception);
} }
} }
} }

View File

@@ -4,7 +4,7 @@ import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.packets.OACPacket; import org.openautonomousconnection.protocol.packets.OACPacket;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseCode;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
@@ -13,12 +13,14 @@ import java.io.ObjectOutputStream;
public final class UnsupportedClassicPacket extends OACPacket { public final class UnsupportedClassicPacket extends OACPacket {
private Class<? extends OACPacket> unsupportedClassicPacket; private Class<? extends OACPacket> unsupportedClassicPacket;
private Object[] content; private Object[] content;
private ProtocolBridge protocolBridge;
// Constructor with more information // Constructor with more information
public UnsupportedClassicPacket(Class<? extends OACPacket> unsupportedClassicPacket, Object[] content) { public UnsupportedClassicPacket(Class<? extends OACPacket> unsupportedClassicPacket, Object[] content, ProtocolBridge protocolBridge) {
this(); this();
this.unsupportedClassicPacket = unsupportedClassicPacket; this.unsupportedClassicPacket = unsupportedClassicPacket;
this.content = content; this.content = content;
this.protocolBridge = protocolBridge;
} }
// Registration Constructor // Registration Constructor
@@ -28,19 +30,19 @@ public final class UnsupportedClassicPacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsClient()) if (protocolBridge.isRunningAsClient())
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID()); objectOutputStream.writeInt(protocolBridge.getProtocolClient().getClientINSConnection().getClientID());
objectOutputStream.writeUTF(unsupportedClassicPacket.getName()); objectOutputStream.writeUTF(unsupportedClassicPacket.getName());
objectOutputStream.writeInt(content.length); objectOutputStream.writeInt(content.length);
for (Object o : content) objectOutputStream.writeObject(o); for (Object o : content) objectOutputStream.writeObject(o);
setResponseCode(DNSResponseCode.RESPONSE_NOT_REQUIRED); setResponseCode(INSResponseCode.RESPONSE_NOT_REQUIRED);
} }
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
int clientID = 0; int clientID = 0;
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) clientID = objectInputStream.readInt(); if (protocolBridge.isRunningAsINSServer()) clientID = objectInputStream.readInt();
String className = objectInputStream.readUTF(); String className = objectInputStream.readUTF();
int size = objectInputStream.readInt(); int size = objectInputStream.readInt();
content = new Object[size]; content = new Object[size];
@@ -49,12 +51,12 @@ public final class UnsupportedClassicPacket extends OACPacket {
content[i] = objectInputStream.readObject(); content[i] = objectInputStream.readObject();
} }
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) if (protocolBridge.isRunningAsINSServer())
ProtocolBridge.getInstance().getClassicHandlerDNSServer().unsupportedClassicPacket(className, content, ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID)); protocolBridge.getClassicHandlerINSServer().unsupportedClassicPacket(className, content, protocolBridge.getProtocolINSServer().getClientByID(clientID));
else if (ProtocolBridge.getInstance().isRunningAsClient()) else if (protocolBridge.isRunningAsClient())
ProtocolBridge.getInstance().getClassicHandlerClient().unsupportedClassicPacket(className, content); protocolBridge.getClassicHandlerClient().unsupportedClassicPacket(className, content);
else if (ProtocolBridge.getInstance().isRunningAsWebServer()) else if (protocolBridge.isRunningAsWebServer())
ProtocolBridge.getInstance().getClassicHandlerWebServer().unsupportedClassicPacket(className, content, ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID)); protocolBridge.getClassicHandlerWebServer().unsupportedClassicPacket(className, content, protocolBridge.getProtocolINSServer().getClientByID(clientID));
} }
} }

View File

@@ -1,56 +0,0 @@
package org.openautonomousconnection.protocol.packets.v1_0_0.beta;
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.packets.OACPacket;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public final class ValidateDomainPacket extends OACPacket {
private Domain domain;
private int clientID;
public ValidateDomainPacket(Domain domain) {
this();
this.domain = domain;
}
public ValidateDomainPacket() {
super(6, ProtocolVersion.PV_1_0_0_BETA);
}
@Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsClient())
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID());
else if (ProtocolBridge.getInstance().isRunningAsDNSServer())
setResponseCode(ProtocolBridge.getInstance().getProtocolDNSServer().validateDomain(domain));
objectOutputStream.writeObject(domain);
}
@Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) clientID = objectInputStream.readInt();
domain = (Domain) objectInputStream.readObject();
}
@Override
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {
super.onResponseCodeRead(packetHandler, objectInputStream);
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
try {
ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID).getConnectionHandler().sendPacket(new ValidateDomainPacket(domain));
} catch (IOException | ClassNotFoundException e) {
ProtocolBridge.getInstance().getProtocolDNSServer().validationPacketSendFailed(domain, ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID), e);
}
} else if (ProtocolBridge.getInstance().isRunningAsClient())
ProtocolBridge.getInstance().getProtocolClient().validationCompleted(domain, getResponseCode());
}
}

View File

@@ -0,0 +1,58 @@
package org.openautonomousconnection.protocol.packets.v1_0_0.beta;
import dev.unlegitdqrk.unlegitlibrary.network.system.packets.PacketHandler;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.packets.OACPacket;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public final class ValidateInfoNamePacket extends OACPacket {
private InfoName infoName;
private int clientID;
private ProtocolBridge protocolBridge;
public ValidateInfoNamePacket(InfoName infoName, ProtocolBridge protocolBridge) {
this();
this.infoName = infoName;
this.protocolBridge = protocolBridge;
}
public ValidateInfoNamePacket() {
super(6, ProtocolVersion.PV_1_0_0_BETA);
}
@Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (protocolBridge.isRunningAsClient())
objectOutputStream.writeInt(protocolBridge.getProtocolClient().getClientINSConnection().getClientID());
else if (protocolBridge.isRunningAsINSServer())
setResponseCode(protocolBridge.getProtocolINSServer().validateInfoName(infoName));
objectOutputStream.writeObject(infoName);
}
@Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (protocolBridge.isRunningAsINSServer()) clientID = objectInputStream.readInt();
infoName = (InfoName) objectInputStream.readObject();
}
@Override
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {
super.onResponseCodeRead(packetHandler, objectInputStream);
if (protocolBridge.isRunningAsINSServer()) {
try {
protocolBridge.getProtocolINSServer().getClientByID(clientID).getConnectionHandler().sendPacket(new ValidateInfoNamePacket(infoName, protocolBridge));
} catch (IOException | ClassNotFoundException e) {
protocolBridge.getProtocolINSServer().validationPacketSendFailed(infoName, protocolBridge.getProtocolINSServer().getClientByID(clientID), e);
}
} else if (protocolBridge.isRunningAsClient())
protocolBridge.getProtocolClient().validationCompleted(infoName, getResponseCode());
}
}

View File

@@ -19,10 +19,12 @@ public final class Classic_DomainPacket extends OACPacket {
private Classic_RequestDomain requestDomain; private Classic_RequestDomain requestDomain;
private Classic_Domain domain; private Classic_Domain domain;
private int clientID; private int clientID;
private ProtocolBridge bridge;
public Classic_DomainPacket(int toClient, Classic_RequestDomain requestDomain, Classic_Domain domain) { public Classic_DomainPacket(int toClient, Classic_RequestDomain requestDomain, Classic_Domain domain, ProtocolBridge protocolBridge) {
this(); this();
this.clientID = toClient; this.clientID = toClient;
this.bridge = protocolBridge;
this.requestDomain = requestDomain; this.requestDomain = requestDomain;
this.domain = domain; this.domain = domain;
@@ -35,12 +37,12 @@ public final class Classic_DomainPacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) { if (bridge.isRunningAsINSServer()) {
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
objectOutputStream.writeObject(requestDomain); objectOutputStream.writeObject(requestDomain);
objectOutputStream.writeObject(domain); objectOutputStream.writeObject(domain);
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (bridge.isRunningAsClient()) {
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID(); clientID = bridge.getProtocolClient().getClientINSConnection().getClientID();
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
objectOutputStream.writeObject(requestDomain); objectOutputStream.writeObject(requestDomain);
} }
@@ -50,36 +52,36 @@ public final class Classic_DomainPacket extends OACPacket {
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) { if (bridge.isRunningAsINSServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
try { try {
domain = ProtocolBridge.getInstance().getClassicHandlerDNSServer().getDomain(requestDomain); domain = bridge.getClassicHandlerINSServer().getDomain(requestDomain);
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID)); bridge.getProtocolINSServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
if (ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID).supportClientClassic()) if (bridge.getProtocolINSServer().getClientByID(clientID).supportClientClassic())
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain)); bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain, bridge));
else else
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain})); bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain}, bridge));
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (bridge.isRunningAsClient()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
domain = (Classic_Domain) objectInputStream.readObject(); domain = (Classic_Domain) objectInputStream.readObject();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID)); bridge.getProtocolClient().getClientINSConnection().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
} else if (ProtocolBridge.getInstance().isRunningAsWebServer()) { } else if (bridge.isRunningAsWebServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getProtocolWebServer().getPipelineServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain})); bridge.getProtocolWebServer().getPipelineServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain}, bridge));
} }
} }
} }

View File

@@ -13,12 +13,14 @@ import java.io.ObjectOutputStream;
public final class Classic_MessagePacket extends OACPacket { public final class Classic_MessagePacket extends OACPacket {
private String message; private String message;
private int clientID; private int clientID;
private ProtocolBridge bridge;
// Constructor with message and client id // Constructor with message and client id
public Classic_MessagePacket(String message, int toClient) { public Classic_MessagePacket(String message, int toClient, ProtocolBridge bridge) {
this(); this();
this.message = message; this.message = message;
this.clientID = toClient; this.clientID = toClient;
this.bridge = bridge;
} }
public Classic_MessagePacket() { public Classic_MessagePacket() {
@@ -27,10 +29,10 @@ public final class Classic_MessagePacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsDNSServer() || ProtocolBridge.getInstance().isRunningAsWebServer()) if (bridge.isRunningAsINSServer() || bridge.isRunningAsWebServer())
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
else if (ProtocolBridge.getInstance().isRunningAsClient()) { else if (bridge.isRunningAsClient()) {
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID(); clientID = bridge.getProtocolClient().getClientINSConnection().getClientID();
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
} }
@@ -40,24 +42,24 @@ public final class Classic_MessagePacket extends OACPacket {
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) { if (bridge.isRunningAsINSServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
String message = objectInputStream.readUTF(); String message = objectInputStream.readUTF();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getClassicHandlerDNSServer().handleMessage(ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID), message, protocolVersion); bridge.getClassicHandlerINSServer().handleMessage(bridge.getProtocolINSServer().getClientByID(clientID), message, protocolVersion);
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (bridge.isRunningAsClient()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
String message = objectInputStream.readUTF(); String message = objectInputStream.readUTF();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getClassicHandlerClient().handleMessage(message, protocolVersion); bridge.getClassicHandlerClient().handleMessage(message, protocolVersion);
} else if (ProtocolBridge.getInstance().isRunningAsWebServer()) { } else if (bridge.isRunningAsWebServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
String message = objectInputStream.readUTF(); String message = objectInputStream.readUTF();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getClassicHandlerWebServer().handleMessage(ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID), message, protocolVersion); bridge.getClassicHandlerWebServer().handleMessage(bridge.getProtocolINSServer().getClientByID(clientID), message, protocolVersion);
} }
} }
} }

View File

@@ -5,7 +5,7 @@ import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.packets.OACPacket; import org.openautonomousconnection.protocol.packets.OACPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseCode;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_PingPacketReceivedEvent; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_PingPacketReceivedEvent;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
@@ -22,9 +22,11 @@ public final class Classic_PingPacket extends OACPacket {
private int clientID; private int clientID;
private boolean reachable; private boolean reachable;
private Classic_ProtocolVersion protocolVersion; private Classic_ProtocolVersion protocolVersion;
private ProtocolBridge bridge;
public Classic_PingPacket(Classic_RequestDomain requestDomain, Classic_Domain domain, boolean reachable) { public Classic_PingPacket(Classic_RequestDomain requestDomain, Classic_Domain domain, boolean reachable, ProtocolBridge bridge) {
this(); this();
this.bridge = bridge;
this.requestDomain = requestDomain; this.requestDomain = requestDomain;
this.domain = domain; this.domain = domain;
@@ -38,13 +40,13 @@ public final class Classic_PingPacket extends OACPacket {
@Override @Override
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException { public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) { if (bridge.isRunningAsINSServer()) {
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
objectOutputStream.writeObject(requestDomain); objectOutputStream.writeObject(requestDomain);
objectOutputStream.writeObject(domain); objectOutputStream.writeObject(domain);
objectOutputStream.writeBoolean(reachable); objectOutputStream.writeBoolean(reachable);
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (bridge.isRunningAsClient()) {
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID(); clientID = bridge.getProtocolClient().getClientINSConnection().getClientID();
objectOutputStream.writeInt(clientID); objectOutputStream.writeInt(clientID);
objectOutputStream.writeObject(requestDomain); objectOutputStream.writeObject(requestDomain);
} }
@@ -54,38 +56,38 @@ public final class Classic_PingPacket extends OACPacket {
@Override @Override
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) { if (bridge.isRunningAsINSServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
try { try {
domain = ProtocolBridge.getInstance().getClassicHandlerDNSServer().ping(requestDomain); domain = bridge.getClassicHandlerINSServer().ping(requestDomain);
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
reachable = domain != null; reachable = domain != null;
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID)); bridge.getProtocolINSServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
if (ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID).supportClientClassic()) if (bridge.getProtocolINSServer().getClientByID(clientID).supportClientClassic())
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable)); bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable, bridge));
else else
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain, domain, reachable})); bridge.getProtocolINSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain, domain, reachable}, bridge));
} else if (ProtocolBridge.getInstance().isRunningAsClient()) { } else if (bridge.isRunningAsClient()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
domain = (Classic_Domain) objectInputStream.readObject(); domain = (Classic_Domain) objectInputStream.readObject();
boolean reachable = objectInputStream.readBoolean(); boolean reachable = objectInputStream.readBoolean();
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getProtocolClient().validationCompleted(domain.getDomain(), reachable ? DNSResponseCode.RESPONSE_DOMAIN_FULLY_EXIST : DNSResponseCode.RESPONSE_DOMAIN_FULLY_NOT_EXIST); bridge.getProtocolClient().validationCompleted(domain.getInfoName(), reachable ? INSResponseCode.RESPONSE_INFONAME_FULLY_EXIST : INSResponseCode.RESPONSE_INFONAME_FULLY_NOT_EXIST);
ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID)); bridge.getProtocolClient().getClientINSConnection().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
} else if (ProtocolBridge.getInstance().isRunningAsWebServer()) { } else if (bridge.isRunningAsWebServer()) {
clientID = objectInputStream.readInt(); clientID = objectInputStream.readInt();
requestDomain = (Classic_RequestDomain) objectInputStream.readObject(); requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject(); protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
ProtocolBridge.getInstance().getProtocolWebServer().getPipelineServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain})); bridge.getProtocolWebServer().getPipelineServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain}, bridge));
} }
} }
} }

View File

@@ -10,12 +10,12 @@ import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.exceptions.UnsupportedProtocolException; import org.openautonomousconnection.protocol.exceptions.UnsupportedProtocolException;
import org.openautonomousconnection.protocol.packets.OACPacket; import org.openautonomousconnection.protocol.packets.OACPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.GetDestinationPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.GetDestinationPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.ValidateDomainPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.beta.ValidateInfoNamePacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_DomainPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_DomainPacket;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseCode;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
import java.io.File; import java.io.File;
@@ -24,14 +24,14 @@ import java.io.IOException;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
/** /**
* Abstract class defining the client-side protocol operations and interactions with DNS and web servers. * Abstract class defining the client-side protocol operations and interactions with INS and web servers.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public abstract class ProtocolClient extends DefaultMethodsOverrider { public abstract class ProtocolClient extends DefaultMethodsOverrider {
/** /**
* Handles everything with DNS-Connection. * Handles everything with INS-Connection.
*/ */
private final NetworkClient clientToDNS; private final NetworkClient clientToINS;
/** /**
* Manages the folder structure for client certificates. * Manages the folder structure for client certificates.
@@ -51,7 +51,13 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
private ProtocolVersion serverVersion = null; private ProtocolVersion serverVersion = null;
/** /**
* Initializes the ProtocolClient, setting up certificate folders and the DNS client connection. * The reference to the ProtocolBridge Object
*/
@Getter
private ProtocolBridge protocolBridge;
/**
* Initializes the ProtocolClient, setting up certificate folders and the INS client connection.
* *
* @throws CertificateException if there are issues with the certificates. * @throws CertificateException if there are issues with the certificates.
* @throws IOException if there are I/O issues during initialization. * @throws IOException if there are I/O issues during initialization.
@@ -60,34 +66,34 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
// Initialize and verify certificate folders and files // Initialize and verify certificate folders and files
folderStructure = new ClientCertificateFolderStructure(); folderStructure = new ClientCertificateFolderStructure();
// Initialize connection to DNS server // Initialize connection to INS server
clientToDNS = new NetworkClient.ClientBuilder().setLogger(ProtocolBridge.getInstance().getLogger()).setProxy(ProtocolBridge.getInstance().getProxy()). clientToINS = new NetworkClient.ClientBuilder().setLogger(protocolBridge.getLogger()).setProxy(protocolBridge.getProxy()).
setHost(ProtocolBridge.getInstance().getProtocolSettings().host).setPort(ProtocolBridge.getInstance().getProtocolSettings().port). setHost(protocolBridge.getProtocolSettings().host).setPort(protocolBridge.getProtocolSettings().port).
setPacketHandler(ProtocolBridge.getInstance().getProtocolSettings().packetHandler).setEventManager(ProtocolBridge.getInstance().getProtocolSettings().eventManager). setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
setRootCAFolder(folderStructure.publicCAFolder).setClientCertificatesFolder(folderStructure.publicClientFolder, folderStructure.privateClientFolder). setRootCAFolder(folderStructure.publicCAFolder).setClientCertificatesFolder(folderStructure.publicClientFolder, folderStructure.privateClientFolder).
build(); build();
} }
/** /**
* Gets the DNS connection client. * Gets the INS connection client.
* *
* @return the NetworkClient handling the DNS connection. * @return the NetworkClient handling the INS connection.
*/ */
public final NetworkClient getClientDNSConnection() { public final NetworkClient getClientINSConnection() {
return clientToDNS; return clientToINS;
} }
/** /**
* Creates a web connection to the specified domain and ports. * Creates a web connection to the specified InfoName and ports.
* *
* @param domain the target domain for the web connection. * @param infoName the target InfoName for the web connection.
* @param pipelinePort the port used for the pipeline connection. * @param pipelinePort the port used for the pipeline connection.
* @param webPort the port used for the web connection. * @param webPort the port used for the web connection.
* @throws Exception if there are issues creating the web connection or if the protocol is unsupported. * @throws Exception if there are issues creating the web connection or if the protocol is unsupported.
*/ */
public final void createWebConnection(Domain domain, int pipelinePort, int webPort) throws Exception { public final void createWebConnection(InfoName infoName, int pipelinePort, int webPort) throws Exception {
// Ensure the protocol supports web connections // Ensure the protocol supports web connections
if (!ProtocolBridge.getInstance().isProtocolSupported(ProtocolVersion.Protocol.OAC)) if (!protocolBridge.isProtocolSupported(ProtocolVersion.Protocol.OAC))
throw new UnsupportedProtocolException(); throw new UnsupportedProtocolException();
// Check if web client is already connected and close it // Check if web client is already connected and close it
@@ -95,13 +101,13 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
try { try {
webClient.closeConnection(); webClient.closeConnection();
} catch (IOException e) { } catch (IOException e) {
ProtocolBridge.getInstance().getLogger().exception("Failed to close connection to web server", e); protocolBridge.getLogger().exception("Failed to close connection to web server", e);
return; return;
} }
} }
// Verify necessary certificate files exist // Verify necessary certificate files exist
webClient = new WebClient(domain, pipelinePort, webPort); webClient = new WebClient(infoName, pipelinePort, webPort, this);
} }
/** /**
@@ -127,8 +133,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
// Validate each file in the folder // Validate each file in the folder
for (File file : files) { for (File file : files) {
if (!file.getName().startsWith(prefix) || !file.getName().endsWith(extension)) if (!file.getName().startsWith(prefix)) throw new CertificateException(file.getAbsolutePath() + " is not valid");
throw new CertificateException(file.getAbsolutePath() + " is not valid");
// Check for specific files // Check for specific files
if (!found) found = file.getName().equalsIgnoreCase(prefix + NetworkUtils.getPublicIPAddress() + extension); if (!found) found = file.getName().equalsIgnoreCase(prefix + NetworkUtils.getPublicIPAddress() + extension);
@@ -157,12 +162,12 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
} }
/** /**
* Handles DNS disconnection events, resetting the server version and closing the web client connection if necessary. * Handles INS disconnection events, resetting the server version and closing the web client connection if necessary.
* *
* @param event the ClientDisconnectedEvent triggered on DNS disconnection. * @param event the ClientDisconnectedEvent triggered on INS disconnection.
*/ */
public final void onDNSDisconnect(ClientDisconnectedEvent event) { public final void onINSDisconnect(ClientDisconnectedEvent event) {
// Reset server version on DNS disconnect // Reset server version on INS disconnect
serverVersion = null; serverVersion = null;
// Close web client connection if it exists // Close web client connection if it exists
@@ -170,7 +175,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
try { try {
webClient.closeConnection(); webClient.closeConnection();
} catch (IOException e) { } catch (IOException e) {
ProtocolBridge.getInstance().getLogger().exception("Failed to close connection to web server", e); protocolBridge.getLogger().exception("Failed to close connection to web server", e);
} }
} }
} }
@@ -297,54 +302,62 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
} }
/** /**
* Validates the specified domain by sending a validation request to the DNS server. * Validates the specified InfoName by sending a validation request to the INS server.
* *
* @param domain the Domain to validate. * @param infoName the InfoName to validate.
* @throws IOException if there are I/O issues during the validation process. * @throws IOException if there are I/O issues during the validation process.
* @throws ClassNotFoundException if there are issues with class loading during packet handling. * @throws ClassNotFoundException if there are issues with class loading during packet handling.
*/ */
public final void validateDomain(Domain domain) throws IOException, ClassNotFoundException { public final void validateInfoName(InfoName infoName) throws IOException, ClassNotFoundException {
// Send Classic_PingPacket if classic protocol is supported // Send Classic_PingPacket if classic protocol is supported
Classic_PingPacket cPingPacket = new Classic_PingPacket(new Classic_RequestDomain(domain.getName(), domain.getTopLevelName(), domain.getPath()), null, false); Classic_PingPacket cPingPacket = new Classic_PingPacket(new Classic_RequestDomain(infoName.getName(), infoName.getTopLevelName(), infoName.getPath(), protocolBridge), null, false, protocolBridge);
if (ProtocolBridge.getInstance().isClassicSupported()) clientToDNS.sendPacket(cPingPacket); if (protocolBridge.isClassicSupported()) clientToINS.sendPacket(cPingPacket);
// Send ValidateDomainPacket // Send ValidateInfoNamePacket
clientToDNS.sendPacket(new ValidateDomainPacket(domain)); clientToINS.sendPacket(new ValidateInfoNamePacket(infoName, protocolBridge));
} }
/** /**
* Requests the destination for the specified domain from the DNS server. * Requests the destination for the specified InfoName from the INS server.
* *
* @param domain the Domain for which to request the destination. * @param infoName the InfoName for which to request the destination.
* @param responseCode the expected DNSResponseCode for the request. * @param responseCode the expected INSResponseCode for the request.
* @throws IOException if there are I/O issues during the request process. * @throws IOException if there are I/O issues during the request process.
* @throws ClassNotFoundException if there are issues with class loading during packet handling. * @throws ClassNotFoundException if there are issues with class loading during packet handling.
*/ */
public final void requestDestination(Domain domain, DNSResponseCode responseCode) throws IOException, ClassNotFoundException { public final void requestInfoName(InfoName infoName, INSResponseCode responseCode) throws IOException, ClassNotFoundException {
// Send Classic_DomainPacket if classic protocol is supported // Send Classic_DomainPacket if classic protocol is supported
Classic_DomainPacket cDomainPacket = new Classic_DomainPacket(0, new Classic_RequestDomain(domain.getName(), domain.getTopLevelName(), domain.getPath()), null); Classic_DomainPacket cDomainPacket = new Classic_DomainPacket(0, new Classic_RequestDomain(infoName.getName(), infoName.getTopLevelName(), infoName.getPath(), protocolBridge), null, protocolBridge);
if (ProtocolBridge.getInstance().isClassicSupported()) clientToDNS.sendPacket(cDomainPacket); if (protocolBridge.isClassicSupported()) clientToINS.sendPacket(cDomainPacket);
// Send GetDestinationPacket // Send GetDestinationPacket
clientToDNS.sendPacket(new GetDestinationPacket(domain, responseCode)); clientToINS.sendPacket(new GetDestinationPacket(infoName, responseCode, protocolBridge));
} }
/** /**
* Callback method invoked when domain validation is completed. * Set protocol bridge.
* * @param protocolBridge The ProtocolBridge object.
* @param domain the Domain that was validated.
* @param responseCode the DNSResponseCode resulting from the validation.
*/ */
public abstract void validationCompleted(Domain domain, DNSResponseCode responseCode); public void setProtocolBridge(ProtocolBridge protocolBridge) {
if (this.protocolBridge == null) this.protocolBridge = protocolBridge;
}
/**
* Callback method invoked when InfoName validation is completed.
*
* @param infoName the InfoName that was validated.
* @param responseCode the INSResponseCode resulting from the validation.
*/
public abstract void validationCompleted(InfoName infoName, INSResponseCode responseCode);
/** /**
* Callback method invoked when the destination retrieval is completed. * Callback method invoked when the destination retrieval is completed.
* *
* @param domain the Domain for which the destination was requested. * @param infoName the InfoName for which the destination was requested.
* @param destination the retrieved destination as a string. * @param destination the retrieved destination as a string.
* @param validationResponse the DNSResponseCode resulting from the destination retrieval. * @param validationResponse the INSResponseCode resulting from the destination retrieval.
*/ */
public abstract void getDestinationCompleted(Domain domain, String destination, DNSResponseCode validationResponse); public abstract void getDestinationCompleted(InfoName infoName, String destination, INSResponseCode validationResponse);
/** /**
* Manages the folder structure for client certificates. * Manages the folder structure for client certificates.

View File

@@ -1,10 +1,11 @@
package org.openautonomousconnection.protocol.side.client; package org.openautonomousconnection.protocol.side.client;
import dev.unlegitdqrk.unlegitlibrary.network.system.client.NetworkClient; import dev.unlegitdqrk.unlegitlibrary.network.system.client.NetworkClient;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
@@ -21,7 +22,7 @@ import java.net.Socket;
* WebClient handles secure connections to web servers through a pipeline connection. * WebClient handles secure connections to web servers through a pipeline connection.
* It manages SSL/TLS handshakes and data transmission over the established connection. * It manages SSL/TLS handshakes and data transmission over the established connection.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public final class WebClient { public final class WebClient {
/** /**
* NetworkClient instance for managing the pipeline connection to the web server. * NetworkClient instance for managing the pipeline connection to the web server.
@@ -42,34 +43,43 @@ public final class WebClient {
*/ */
private ObjectInputStream inputStream; private ObjectInputStream inputStream;
/**
* The Protocol Client associated with this protocol client.
*/
@Getter
private final ProtocolClient protocolClient;
/** /**
* Constructs a WebClient instance and establishes a secure connection to the web server. * Constructs a WebClient instance and establishes a secure connection to the web server.
* *
* @param domain The domain information for the web server. * @param infoName The InfoName information for the web server.
* @param pipelinePort The port for the pipeline connection. * @param pipelinePort The port for the pipeline connection.
* @param webPort The port for the web server connection. * @param webPort The port for the web server connection.
* @param protocolClient The Protocol Client associated with this protocol client.
* @throws Exception If an error occurs during connection setup. * @throws Exception If an error occurs during connection setup.
*/ */
public WebClient(Domain domain, int pipelinePort, int webPort) throws Exception { public WebClient(InfoName infoName, int pipelinePort, int webPort, ProtocolClient protocolClient) throws Exception {
this.protocolClient = protocolClient;
// Initialize and connect the pipeline client // Initialize and connect the pipeline client
clientToWebPipeline = new NetworkClient.ClientBuilder(). clientToWebPipeline = new NetworkClient.ClientBuilder().
// Set logger from ProtocolBridge // Set logger from ProtocolBridge
setLogger(ProtocolBridge.getInstance().getLogger()). setLogger(protocolClient.getProtocolBridge().getLogger()).
// Set the destination and port for the pipeline connection // Set the destination and port for the pipeline connection
setHost(domain.getDestination()).setPort(pipelinePort). setHost(infoName.getDestination(protocolClient.getProtocolBridge())).setPort(pipelinePort).
// Configure packet handler and event manager // Configure packet handler and event manager
setPacketHandler(ProtocolBridge.getInstance().getProtocolSettings().packetHandler). setPacketHandler(protocolClient.getProtocolBridge().getProtocolSettings().packetHandler).
setEventManager(ProtocolBridge.getInstance().getProtocolSettings().eventManager). setEventManager(protocolClient.getProtocolBridge().getProtocolSettings().eventManager).
// Set proxy and ssl parameters from DNS connection settings // Set proxy and ssl parameters from INS connection settings
setProxy(ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getProxy()). setProxy(protocolClient.getProtocolBridge().getProtocolClient().getClientINSConnection().getProxy()).
setSSLParameters(ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getSocket().getSSLParameters()). setSSLParameters(protocolClient.getProtocolBridge().getProtocolClient().getClientINSConnection().getSocket().getSSLParameters()).
// Set certificates and folders for SSL // Set certificates and folders for SSL
setRootCAFolder(ProtocolBridge.getInstance().getProtocolClient().getFolderStructure().publicCAFolder). setRootCAFolder(protocolClient.getProtocolBridge().getProtocolClient().getFolderStructure().publicCAFolder).
setClientCertificatesFolder(ProtocolBridge.getInstance().getProtocolClient().getFolderStructure().publicClientFolder, setClientCertificatesFolder(protocolClient.getProtocolBridge().getProtocolClient().getFolderStructure().publicClientFolder,
ProtocolBridge.getInstance().getProtocolClient().getFolderStructure().privateClientFolder). protocolClient.getProtocolBridge().getProtocolClient().getFolderStructure().privateClientFolder).
// Finalize the client setup // Finalize the client setup
@@ -83,9 +93,9 @@ public final class WebClient {
// Create SSL socket factory using client certificates // Create SSL socket factory using client certificates
SSLSocketFactory sslSocketFactory = NetworkClient.ClientBuilder. SSLSocketFactory sslSocketFactory = NetworkClient.ClientBuilder.
createSSLSocketFactory(ProtocolBridge.getInstance().getProtocolClient().getFolderStructure().publicCAFolder, createSSLSocketFactory(protocolClient.getProtocolBridge().getProtocolClient().getFolderStructure().publicCAFolder,
ProtocolBridge.getInstance().getProtocolClient().getFolderStructure().publicClientFolder, protocolClient.getProtocolBridge().getProtocolClient().getFolderStructure().publicClientFolder,
ProtocolBridge.getInstance().getProtocolClient().getFolderStructure().privateClientFolder); protocolClient.getProtocolBridge().getProtocolClient().getFolderStructure().privateClientFolder);
// Get proxy settings from the pipeline client // Get proxy settings from the pipeline client
Proxy proxy = clientToWebPipeline.getProxy(); Proxy proxy = clientToWebPipeline.getProxy();
@@ -98,10 +108,10 @@ public final class WebClient {
// Create raw socket and wrap it in SSL socket // Create raw socket and wrap it in SSL socket
if (proxy != null) { if (proxy != null) {
Socket rawSocket = new Socket(proxy); Socket rawSocket = new Socket(proxy);
rawSocket.connect(new InetSocketAddress(domain.getDestination(), webPort), 0); rawSocket.connect(new InetSocketAddress(infoName.getDestination(protocolClient.getProtocolBridge()), webPort), 0);
tempSocket = (SSLSocket) sslSocketFactory.createSocket(rawSocket, domain.getDestination(), webPort, true); tempSocket = (SSLSocket) sslSocketFactory.createSocket(rawSocket, infoName.getDestination(protocolClient.getProtocolBridge()), webPort, true);
} else { } else {
tempSocket = (SSLSocket) sslSocketFactory.createSocket(domain.getDestination(), webPort); tempSocket = (SSLSocket) sslSocketFactory.createSocket(infoName.getDestination(protocolClient.getProtocolBridge()), webPort);
} }
clientToWebServer = tempSocket; clientToWebServer = tempSocket;
@@ -166,7 +176,7 @@ public final class WebClient {
public boolean isConnected() { public boolean isConnected() {
return this.clientToWebServer != null && this.clientToWebServer.isConnected() && !this.clientToWebServer.isClosed() return this.clientToWebServer != null && this.clientToWebServer.isConnected() && !this.clientToWebServer.isClosed()
&& this.receiveThread.isAlive() && !this.receiveThread.isInterrupted() && && this.receiveThread.isAlive() && !this.receiveThread.isInterrupted() &&
ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().isConnected() && clientToWebPipeline.isConnected(); protocolClient.getProtocolBridge().getProtocolClient().getClientINSConnection().isConnected() && clientToWebPipeline.isConnected();
} }
/** /**
@@ -183,7 +193,7 @@ public final class WebClient {
try { try {
this.closeConnection(); this.closeConnection();
} catch (IOException exception) { } catch (IOException exception) {
ProtocolBridge.getInstance().getLogger().exception("Failed to close connection to web server", var2); protocolClient.getProtocolBridge().getLogger().exception("Failed to close connection to web server", var2);
} }
} }
} }

View File

@@ -1,12 +0,0 @@
package org.openautonomousconnection.protocol.side.client.events;
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
/**
* Event triggered when a client successfully connects to a DNS protocol server.
*/
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS)
public final class ConnectedToProtocolDNSServerEvent extends Event {
}

View File

@@ -0,0 +1,25 @@
package org.openautonomousconnection.protocol.side.client.events;
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
import lombok.Getter;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
/**
* Event triggered when a client successfully connects to a INS protocol server.
*/
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public final class ConnectedToProtocolINSServerEvent extends Event {
/**
* Reference to the ProtocolClient object.
*/
@Getter
private final ProtocolClient client;
public ConnectedToProtocolINSServerEvent(ProtocolClient client) {
this.client = client;
}
}

View File

@@ -1,4 +1,4 @@
package org.openautonomousconnection.protocol.side.dns; package org.openautonomousconnection.protocol.side.ins;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.ConnectionHandler; import dev.unlegitdqrk.unlegitlibrary.network.system.server.ConnectionHandler;
import lombok.Getter; import lombok.Getter;
@@ -7,9 +7,9 @@ import org.openautonomousconnection.protocol.packets.OACPacket;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
/** /**
* Represents a connected protocol client on the DNS server side. * Represents a connected protocol client on the INS server side.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public final class ConnectedProtocolClient { public final class ConnectedProtocolClient {
/** /**
@@ -18,13 +18,20 @@ public final class ConnectedProtocolClient {
@Getter @Getter
private final ConnectionHandler connectionHandler; private final ConnectionHandler connectionHandler;
/**
* The Protocol Server associated with this protocol client.
*/
@Getter
private final ProtocolINSServer protocolINSServer;
/** /**
* The protocol version of the connected client. * The protocol version of the connected client.
*/ */
private ProtocolVersion clientVersion = null; private ProtocolVersion clientVersion = null;
public ConnectedProtocolClient(ConnectionHandler connectionHandler) { public ConnectedProtocolClient(ConnectionHandler connectionHandler, ProtocolINSServer protocolINSServer) {
this.connectionHandler = connectionHandler; this.connectionHandler = connectionHandler;
this.protocolINSServer = protocolINSServer;
} }
/** /**

View File

@@ -1,4 +1,4 @@
package org.openautonomousconnection.protocol.side.dns; package org.openautonomousconnection.protocol.side.ins;
import dev.unlegitdqrk.unlegitlibrary.file.ConfigurationManager; import dev.unlegitdqrk.unlegitlibrary.file.ConfigurationManager;
import dev.unlegitdqrk.unlegitlibrary.network.system.server.NetworkServer; import dev.unlegitdqrk.unlegitlibrary.network.system.server.NetworkServer;
@@ -8,8 +8,8 @@ import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseCode;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@@ -19,10 +19,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* Abstract class representing a DNS server in the protocol. * Abstract class representing a INS server in the protocol.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public abstract class ProtocolDNSServer extends DefaultMethodsOverrider { public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
/** /**
* The network server instance. * The network server instance.
*/ */
@@ -47,13 +47,19 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
private ServerCertificateFolderStructure folderStructure; private ServerCertificateFolderStructure folderStructure;
/** /**
* Constructs a ProtocolDNSServer with the specified configuration file. * The reference to the ProtocolBridge Object
*/
@Getter
private ProtocolBridge protocolBridge;
/**
* Constructs a ProtocolINSServer with the specified configuration file.
* *
* @param configFile The configuration file for the DNS server. * @param configFile The configuration file for the INS server.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
* @throws CertificateException If a certificate error occurs. * @throws CertificateException If a certificate error occurs.
*/ */
public ProtocolDNSServer(File configFile) throws IOException, CertificateException { public ProtocolINSServer(File configFile) throws IOException, CertificateException {
// Ensure the configuration file exists // Ensure the configuration file exists
if (!configFile.exists()) configFile.createNewFile(); if (!configFile.exists()) configFile.createNewFile();
@@ -63,12 +69,12 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
// Set default values for configuration properties if not already set // Set default values for configuration properties if not already set
if (!configurationManager.isSet("server.site.info")) { if (!configurationManager.isSet("server.site.info")) {
configurationManager.set("server.site.info", "DNS-SERVER INFO SITE IP"); configurationManager.set("server.site.info", "INS-SERVER INFO SITE IP");
configurationManager.saveProperties(); configurationManager.saveProperties();
} }
if (!configurationManager.isSet("server.site.register")) { if (!configurationManager.isSet("server.site.register")) {
configurationManager.set("server.site.register", "SERVER IP TO DNS-FRONTENT WEBSITE"); configurationManager.set("server.site.register", "SERVER IP TO INS-FRONTEND WEBSITE");
configurationManager.saveProperties(); configurationManager.saveProperties();
} }
@@ -88,7 +94,6 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
File keyFile = new File(folderStructure.privateServerFolder, folderStructure.certPrefix + NetworkUtils.getPublicIPAddress() + ".key"); File keyFile = new File(folderStructure.privateServerFolder, folderStructure.certPrefix + NetworkUtils.getPublicIPAddress() + ".key");
// Initialize the protocol bridge and clients list // Initialize the protocol bridge and clients list
ProtocolBridge protocolBridge = ProtocolBridge.getInstance();
this.clients = new ArrayList<>(); this.clients = new ArrayList<>();
// Build the network server with the specified settings // Build the network server with the specified settings
@@ -126,8 +131,7 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
// Validate each file in the folder // Validate each file in the folder
for (File file : files) { for (File file : files) {
if (!file.getName().startsWith(prefix) || !file.getName().endsWith(extension)) if (!file.getName().startsWith(prefix)) throw new CertificateException(file.getAbsolutePath() + " is not valid");
throw new CertificateException(file.getAbsolutePath() + " is not valid");
// Check if the file matches the expected naming convention // Check if the file matches the expected naming convention
if (!found) found = file.getName().equalsIgnoreCase(prefix + NetworkUtils.getPublicIPAddress() + extension); if (!found) found = file.getName().equalsIgnoreCase(prefix + NetworkUtils.getPublicIPAddress() + extension);
@@ -150,81 +154,87 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
} }
/** /**
* Gets the DNS information site URL from the configuration. * Set protocol bridge
* * @param protocolBridge The ProtocolBridge object
* @return The DNS information site URL.
*/ */
public final String getDNSInfoSite() { public void setProtocolBridge(ProtocolBridge protocolBridge) {
if (this.protocolBridge == null) this.protocolBridge = protocolBridge;
}
/**
* Gets the INS information site URL from the configuration.
*
* @return The INS information site URL.
*/
public final String getINSInfoSite() {
return configurationManager.getString("server.site.info"); return configurationManager.getString("server.site.info");
} }
/** /**
* Gets the DNS registration site URL from the configuration. * Gets the INS registration site URL from the configuration.
* *
* @return The DNS registration site URL. * @return The INS registration site URL.
*/ */
public final String getDNSRegisterSite() { public final String getINSRegisterSite() {
return configurationManager.getString("server.site.register"); return configurationManager.getString("server.site.register");
} }
/** /**
* Abstract method to retrieve the list of domains managed by the DNS server. * Abstract method to retrieve the list of InfoNames managed by the INS server.
* *
* @return A list of Domain objects. * @return A list of InfoName objects.
*/ */
public abstract List<Domain> getDomains(); public abstract List<InfoName> getInfoNames();
/** /**
* @param domain The domain to look up. * @param infoName The InfoName to look up.
* @return The destination associated with the domain. * @return The destination associated with the InfoName.
* @see Domain#getDestination() * @see InfoName#getDestination(ProtocolBridge)
* Abstract method to get the destination for a given domain. * Abstract method to get the destination for a given InfoName.
*/ */
public abstract String getDomainDestination(Domain domain); public abstract String getInfoNameDestination(InfoName infoName);
/** /**
* @param domain The parent domain. * @param infoName The parent InfoName.
* @param subname The subname to look up. * @param subname The subname to look up.
* @return The destination associated with the subname. * @return The destination associated with the subname.
* @see Domain#getDestination() * @see InfoName#getDestination(ProtocolBridge)
* Abstract method to get the destination for a given subname under a specific domain. * Abstract method to get the destination for a given subname under a specific InfoName.
*/ */
public abstract String getSubnameDestination(Domain domain, String subname); public abstract String getSubnameDestination(InfoName infoName, String subname);
/** /**
* @param topLevelName The top-level domain name. * @param topLevelName The top-level name.
* @return The information site URL for the specified top-level domain. * @return The information site URL for the specified top-level name.
* @see Domain#getDestination() * @see InfoName#getDestination(ProtocolBridge)
* Abstract method to get the top-level domain information site URL. * Abstract method to get the top-level name information site URL.
*/ */
public abstract String getTLNInfoSite(String topLevelName); public abstract String getTLNInfoSite(String topLevelName);
/** /**
* Abstract method to validate a requested domain. * Abstract method to validate a requested InfoName.
* *
* @param requestedDomain The domain to validate. * @param requestedInfoName The InfoName to validate.
* @return A DNSResponseCode indicating the result of the validation. * @return A INSResponseCode indicating the result of the validation.
*/ */
public abstract DNSResponseCode validateDomain(Domain requestedDomain); public abstract INSResponseCode validateInfoName(InfoName requestedInfoName);
/** /**
* Abstract method called when a validation packet fails to send. * Abstract method called when a validation packet fails to send.
* * @param infoName The InfoName associated with the validation.
* @param domain The domain associated with the validation.
* @param client The connected protocol client. * @param client The connected protocol client.
* @param exception The exception that occurred during sending. * @param exception The exception that occurred during sending.
*/ */
public abstract void validationPacketSendFailed(Domain domain, ConnectedProtocolClient client, Exception exception); public abstract void validationPacketSendFailed(InfoName infoName, ConnectedProtocolClient client, Exception exception);
/** /**
* Abstract method called when a domain destination packet fails to send. * Abstract method called when a InfoName destination packet fails to send.
*
* @param client The connected protocol client. * @param client The connected protocol client.
* @param domain The domain associated with the packet. * @param infoName The InfoName associated with the packet.
* @param validationResponse The DNS response code from validation. * @param validationResponse The INS response code from validation.
* @param exception The exception that occurred during sending. * @param exception The exception that occurred during sending.
*/ */
public abstract void domainDestinationPacketFailedSend(ConnectedProtocolClient client, Domain domain, DNSResponseCode validationResponse, Exception exception); public abstract void infoNameDestinationPacketFailedSend(ConnectedProtocolClient client, InfoName infoName, INSResponseCode validationResponse, Exception exception);
/** /**
* Class representing the folder structure for server certificates. * Class representing the folder structure for server certificates.
@@ -240,8 +250,8 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
public final File publicCAFolder; public final File publicCAFolder;
public final File publicServerFolder; public final File publicServerFolder;
public final String caPrefix = "ca_dns_"; public final String caPrefix = "ca_ins_";
public final String certPrefix = "cert_dns_"; public final String certPrefix = "cert_ins_";
public ServerCertificateFolderStructure() { public ServerCertificateFolderStructure() {
certificatesFolder = new File("certificates"); certificatesFolder = new File("certificates");

View File

@@ -1,15 +1,15 @@
package org.openautonomousconnection.protocol.side.dns.events; package org.openautonomousconnection.protocol.side.ins.events;
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event; import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
import lombok.Getter; import lombok.Getter;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient; import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
/** /**
* Event triggered when a protocol client connects to the DNS server. * Event triggered when a protocol client connects to the INS server.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public final class ConnectedProtocolClientEvent extends Event { public final class ConnectedProtocolClientEvent extends Event {
@Getter @Getter

View File

@@ -68,6 +68,12 @@ public final class ConnectedWebClient {
*/ */
private final Thread receiveThread = new Thread(this::receive); private final Thread receiveThread = new Thread(this::receive);
/**
* The reference to the ProtocolWebServer Object
*/
@Getter
private ProtocolWebServer protocolWebServer;
/** /**
* Sends an HTTP redirect response to the client. * Sends an HTTP redirect response to the client.
* *
@@ -629,7 +635,7 @@ public final class ConnectedWebClient {
path = URLDecoder.decode(path, StandardCharsets.UTF_8); path = URLDecoder.decode(path, StandardCharsets.UTF_8);
path = normalizePath(path); path = normalizePath(path);
File file = new File(ProtocolBridge.getInstance().getProtocolWebServer().getContentFolder(), path); File file = new File(protocolWebServer.getProtocolBridge().getProtocolWebServer().getContentFolder(), path);
String sessionId = null; String sessionId = null;
if (headers.containsKey("cookie")) { if (headers.containsKey("cookie")) {
@@ -642,14 +648,14 @@ public final class ConnectedWebClient {
} }
if (!file.exists() || !file.isFile()) { if (!file.exists() || !file.isFile()) {
sendResponse(out, 404, new File(ProtocolBridge.getInstance().getProtocolWebServer().getErrorsFolder(), "404.html")); sendResponse(out, 404, new File(protocolWebServer.getProtocolBridge().getProtocolWebServer().getErrorsFolder(), "404.html"));
return; return;
} }
String clientIp = webSocket.getInetAddress().getHostAddress(); String clientIp = webSocket.getInetAddress().getHostAddress();
String userAgent = headers.getOrDefault("user-agent", null); String userAgent = headers.getOrDefault("user-agent", null);
boolean loggedIn = sessionId != null && SessionManager.isValid(sessionId, clientIp, userAgent); boolean loggedIn = sessionId != null && SessionManager.isValid(sessionId, clientIp, userAgent, protocolWebServer);
if (path.equals("/403-login") && headers.getOrDefault("content-type", "").startsWith("application/x-www-form-urlencoded")) { if (path.equals("/403-login") && headers.getOrDefault("content-type", "").startsWith("application/x-www-form-urlencoded")) {
Map<String, String> postParams = parsePostParams(in); Map<String, String> postParams = parsePostParams(in);
@@ -657,7 +663,7 @@ public final class ConnectedWebClient {
String password = postParams.get("password"); String password = postParams.get("password");
if (AuthManager.checkAuth(login, password)) { if (AuthManager.checkAuth(login, password)) {
String newSessionId = SessionManager.create(login, clientIp, userAgent); String newSessionId = SessionManager.create(login, clientIp, userAgent, protocolWebServer);
Map<String, String> cookies = Map.of("Set-Cookie", "SESSIONID=" + newSessionId + "; HttpOnly; Path=/"); Map<String, String> cookies = Map.of("Set-Cookie", "SESSIONID=" + newSessionId + "; HttpOnly; Path=/");
sendRedirect(out, "/main.html", cookies); sendRedirect(out, "/main.html", cookies);
return; return;
@@ -668,18 +674,18 @@ public final class ConnectedWebClient {
} }
if (isMultipart(headers)) { if (isMultipart(headers)) {
handleMultipart(in, headers, new File(ProtocolBridge.getInstance().getProtocolWebServer().getContentFolder(), "uploads")); handleMultipart(in, headers, new File(protocolWebServer.getProtocolBridge().getProtocolWebServer().getContentFolder(), "uploads"));
} }
if (RuleManager.requiresAuth(path) && !loggedIn) { if (RuleManager.requiresAuth(path) && !loggedIn) {
PHPResponse phpResp = renderPHPWithCookies(new File(ProtocolBridge.getInstance().getProtocolWebServer().getContentFolder(), "403.php")); PHPResponse phpResp = renderPHPWithCookies(new File(protocolWebServer.getProtocolBridge().getProtocolWebServer().getContentFolder(), "403.php"));
sendResponse(out, 200, phpResp.body.getBytes(StandardCharsets.UTF_8), "text/html", phpResp.cookies); sendResponse(out, 200, phpResp.body.getBytes(StandardCharsets.UTF_8), "text/html", phpResp.cookies);
return; return;
} }
if (RuleManager.isDenied(path) && !RuleManager.isAllowed(path)) { if (RuleManager.isDenied(path) && !RuleManager.isAllowed(path)) {
sendResponse(out, 403, new File(ProtocolBridge.getInstance().getProtocolWebServer().getErrorsFolder(), "403.php")); sendResponse(out, 403, new File(protocolWebServer.getProtocolBridge().getProtocolWebServer().getErrorsFolder(), "403.php"));
return; return;
} }
@@ -701,6 +707,14 @@ public final class ConnectedWebClient {
} }
} }
/**
* Set protocol bridge
* @param protocolWebServer The ProtocolWebServer object
*/
public void setProtocolWebServer(ProtocolWebServer protocolWebServer) {
if (this.protocolWebServer == null) this.protocolWebServer = protocolWebServer;
}
/** /**
* Represents the response from a PHP script, including body and cookies. * Represents the response from a PHP script, including body and cookies.
*/ */

View File

@@ -83,6 +83,12 @@ public final class ProtocolWebServer {
@Getter @Getter
private String uniqueSessionString; private String uniqueSessionString;
/**
* The reference to the ProtocolBridge Object
*/
@Getter
private ProtocolBridge protocolBridge;
/** /**
* Initializes the web server with the given configuration, authentication, and rules files. * Initializes the web server with the given configuration, authentication, and rules files.
* *
@@ -159,8 +165,8 @@ public final class ProtocolWebServer {
// Initialize the pipeline server // Initialize the pipeline server
pipelineServer = new NetworkServer.ServerBuilder(). pipelineServer = new NetworkServer.ServerBuilder().
setPort(configurationManager.getInt("port.pipeline")).setTimeout(0). setPort(configurationManager.getInt("port.pipeline")).setTimeout(0).
setPacketHandler(ProtocolBridge.getInstance().getProtocolSettings().packetHandler).setEventManager(ProtocolBridge.getInstance().getProtocolSettings().eventManager). setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
setLogger(ProtocolBridge.getInstance().getLogger()). setLogger(protocolBridge.getLogger()).
setServerCertificate(certFile, keyFile).setRootCAFolder(folderStructure.publicCAFolder). setServerCertificate(certFile, keyFile).setRootCAFolder(folderStructure.publicCAFolder).
build(); build();
} }
@@ -177,6 +183,14 @@ public final class ProtocolWebServer {
return null; return null;
} }
/**
* Set protocol bridge
* @param protocolBridge The ProtocolBridge object
*/
public void setProtocolBridge(ProtocolBridge protocolBridge) {
if (this.protocolBridge == null) this.protocolBridge = protocolBridge;
}
/** /**
* Starts the web server to accept and handle client connections. * Starts the web server to accept and handle client connections.
* *
@@ -228,6 +242,7 @@ public final class ProtocolWebServer {
if (connectedWebClient.getPipelineConnection().getClientID() != -1 && connectedWebClient.isClientVersionLoaded()) { if (connectedWebClient.getPipelineConnection().getClientID() != -1 && connectedWebClient.isClientVersionLoaded()) {
// Assign socket to an existing connected client // Assign socket to an existing connected client
connectedWebClient.setWebSocket(client); connectedWebClient.setWebSocket(client);
connectedWebClient.setProtocolWebServer(this);
} }
} }
} catch (IOException e) { } catch (IOException e) {
@@ -255,7 +270,7 @@ public final class ProtocolWebServer {
* @throws CertificateException If a required certificate file is missing or invalid. * @throws CertificateException If a required certificate file is missing or invalid.
* @throws IOException If an I/O error occurs while checking the files. * @throws IOException If an I/O error occurs while checking the files.
*/ */
private void checkFileExists(File folder, String prefix, String extension) throws CertificateException, IOException { private final void checkFileExists(File folder, String prefix, String extension) throws CertificateException, IOException {
boolean found = false; boolean found = false;
// Ensure the folder exists // Ensure the folder exists
@@ -268,8 +283,7 @@ public final class ProtocolWebServer {
// Check for the required certificate file // Check for the required certificate file
for (File file : files) { for (File file : files) {
if (!file.getName().startsWith(prefix) || !file.getName().endsWith(extension)) if (!file.getName().startsWith(prefix)) throw new CertificateException(file.getAbsolutePath() + " is not valid");
throw new CertificateException(file.getAbsolutePath() + " is not valid");
// Check for file matching the public IP address // Check for file matching the public IP address
if (!found) found = file.getName().equalsIgnoreCase(prefix + NetworkUtils.getPublicIPAddress() + extension); if (!found) found = file.getName().equalsIgnoreCase(prefix + NetworkUtils.getPublicIPAddress() + extension);

View File

@@ -3,6 +3,7 @@ package org.openautonomousconnection.protocol.side.web.managers;
import lombok.Getter; import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import java.io.IOException; import java.io.IOException;
@@ -34,19 +35,20 @@ public final class SessionManager {
* @param login The username associated with the session. * @param login The username associated with the session.
* @param ip The IP address of the client. * @param ip The IP address of the client.
* @param userAgent The User-Agent string of the client. * @param userAgent The User-Agent string of the client.
* @param protocolWebServer The Protocol WebServer for the unique Session
* @return The generated session ID. * @return The generated session ID.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public static String create(String login, String ip, String userAgent) throws IOException { public static String create(String login, String ip, String userAgent, ProtocolWebServer protocolWebServer) throws IOException {
// Generate a secure random session ID // Generate a secure random session ID
byte[] bytes = new byte[32]; byte[] bytes = new byte[32];
secureRandom.nextBytes(bytes); secureRandom.nextBytes(bytes);
// Encode the bytes to a URL-safe Base64 string // Encode the bytes to a URL-safe Base64 string
String sessionId = Base64.getUrlEncoder().withoutPadding().encodeToString(bytes) + ProtocolBridge.getInstance().getProtocolWebServer().getUniqueSessionString(); String sessionId = Base64.getUrlEncoder().withoutPadding().encodeToString(bytes) + protocolWebServer.getUniqueSessionString();
// Create and store the new session // Create and store the new session
sessions.put(sessionId, new Session(login, ip, userAgent)); sessions.put(sessionId, new Session(login, ip, userAgent, protocolWebServer));
return sessionId; return sessionId;
} }
@@ -56,10 +58,11 @@ public final class SessionManager {
* @param sessionId The session ID to validate. * @param sessionId The session ID to validate.
* @param ip The IP address of the client. * @param ip The IP address of the client.
* @param userAgent The User-Agent string of the client. * @param userAgent The User-Agent string of the client.
* @param protocolWebServer The Protocol WebServer to get the config for refreshing
* @return True if the session is valid, false otherwise. * @return True if the session is valid, false otherwise.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public static boolean isValid(String sessionId, String ip, String userAgent) throws IOException { public static boolean isValid(String sessionId, String ip, String userAgent, ProtocolWebServer protocolWebServer) throws IOException {
// Retrieve the session associated with the session ID // Retrieve the session associated with the session ID
Session session = sessions.get(sessionId); Session session = sessions.get(sessionId);
@@ -70,7 +73,7 @@ public final class SessionManager {
} }
// Refresh the session expiration time // Refresh the session expiration time
session.refresh(); session.refresh(protocolWebServer);
return true; return true;
} }
@@ -122,11 +125,11 @@ public final class SessionManager {
String userAgent; String userAgent;
long expiresAt; long expiresAt;
Session(String login, String ip, String userAgent) throws IOException { Session(String login, String ip, String userAgent, ProtocolWebServer protocolWebServer) throws IOException {
this.login = login; this.login = login;
this.ip = ip; this.ip = ip;
this.userAgent = userAgent; this.userAgent = userAgent;
this.expiresAt = System.currentTimeMillis() + (long) ProtocolBridge.getInstance().getProtocolWebServer().getConfigurationManager().getInt("sessionexpireminutes") * 60 * 1000; this.expiresAt = System.currentTimeMillis() + (long) protocolWebServer.getConfigurationManager().getInt("sessionexpireminutes") * 60 * 1000;
} }
/** /**
@@ -151,11 +154,11 @@ public final class SessionManager {
/** /**
* Refreshes the session's expiration time. * Refreshes the session's expiration time.
* * @param protocolWebServer The Protocol WebServer to get the Config setting
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
void refresh() throws IOException { void refresh(ProtocolWebServer protocolWebServer) throws IOException {
this.expiresAt = System.currentTimeMillis() + (long) ProtocolBridge.getInstance().getProtocolWebServer().getConfigurationManager().getInt("sessionexpireminutes") * 60 * 1000; this.expiresAt = System.currentTimeMillis() + (long) protocolWebServer.getConfigurationManager().getInt("sessionexpireminutes") * 60 * 1000;
} }
} }
} }

View File

@@ -14,7 +14,7 @@ public enum ProtocolVersion implements Serializable {
/** /**
* Support for old OAC-Project => <a href="https://repo.open-autonomous-connection.org/Open-Autonomous-Connection/">*_old</a> * Support for old OAC-Project => <a href="https://repo.open-autonomous-connection.org/Open-Autonomous-Connection/">*_old</a>
*/ */
PV_1_0_0_CLASSIC("1.0.0", ProtocolType.CLASSIC, ProtocolSide.WEB_DNS, List.of(Protocol.HTTP)), PV_1_0_0_CLASSIC("1.0.0", ProtocolType.CLASSIC, ProtocolSide.WEB_INS, List.of(Protocol.HTTP)),
/** /**
* First Beta Version of OAC-Protocol * First Beta Version of OAC-Protocol
@@ -153,12 +153,12 @@ public enum ProtocolVersion implements Serializable {
/** /**
* Client Side only * Client Side only
*/ */
CLIENT, // Protocol version can only used on Client CLIENT,
/** /**
* DNS Server Side only * INS Server Side only
*/ */
DNS, INS,
/** /**
* Web Server Side only * Web Server Side only
@@ -166,14 +166,14 @@ public enum ProtocolVersion implements Serializable {
WEB, WEB,
/** /**
* Both DNS and Web Server Side * Both INS and Web Server Side
*/ */
WEB_DNS, WEB_INS,
/** /**
* Both Client and DNS Server Side * Both Client and INS Server Side
*/ */
CLIENT_DNS, CLIENT_INS,
/** /**
* Both Client and Web Server Side * Both Client and Web Server Side

View File

@@ -1,85 +0,0 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.beta;
import lombok.Getter;
import java.io.Serializable;
/**
* Enum representing various DNS response codes and their descriptions.
*/
public enum DNSResponseCode implements Serializable {
/**
* General Responses
*/
RESPONSE_NOT_REQUIRED(0, "Response code not required"),
RESPONSE_INVALID_REQUEST(1, "Invalid request"),
/**
* Authentication Responses
*/
RESPONSE_AUTH_SUCCESS(4, "Auth success"),
RESPONSE_AUTH_FAILED(5, "Auth failed"),
/**
* Domain Responses
*/
RESPONSE_DOMAIN_NAME_EXIST(100, "Domainname exist"),
RESPONSE_DOMAIN_NAME_NOT_EXIST(101, "Domainname does not exist"),
RESPONSE_DOMAIN_NAME_CREATED(105, "Domainname created"),
RESPONSE_DOMAIN_NAME_DELETED(106, "Domainname deleted"),
/**
* Top Level Name Responses
*/
RESPONSE_DOMAIN_TLN_EXIST(110, "TopLevelName exist"),
RESPONSE_DOMAIN_TLN_NOT_EXIST(111, "TopLevelName does not exist"),
RESPONSE_DOMAIN_TLN_CREATED(115, "TopLevelName created"),
RESPONSE_DOMAIN_TLN_DELETED(116, "TopLevelName deleted"),
/**
* Subname Responses
*/
RESPONSE_DOMAIN_SUBNAME_EXIST(120, "Subname exist"),
RESPONSE_DOMAIN_SUBNAME_NOT_EXIST(121, "Subname does not exist"),
RESPONSE_DOMAIN_SUBNAME_CREATED(125, "Subname created"),
RESPONSE_DOMAIN_SUBNAME_DELETED(126, "Subname deleted"),
/**
* Full Domain Responses
*/
RESPONSE_DOMAIN_FULLY_EXIST(130, "Full domain exist"),
RESPONSE_DOMAIN_FULLY_NOT_EXIST(131, "Full domain does not exist");
/**
* The numeric code representing the DNS response.
*/
@Getter
private final int code;
/**
* A brief description of the DNS response code.
*/
@Getter
private final String description;
/**
* Constructor for DNSResponseCode enum.
*
* @param code The numeric code of the response.
* @param description A brief description of the response.
*/
DNSResponseCode(int code, String description) {
this.code = code;
this.description = description;
}
/**
* Returns a string representation of the DNS response code, including its code and description.
*
* @return a string representation of the DNS response code.
*/
@Override
public String toString() {
return "{code=" + code + ";description=" + description + "}";
}
}

View File

@@ -1,172 +0,0 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.beta;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
/**
* Class representing a domain with its components such as subname, name, top-level name, path, query, fragment, and protocol.
*/
public final class Domain implements Serializable {
/**
* The subname of the domain (e.g., "sub" in "sub.example.com").
*/
@Getter
private final String subname;
/**
* The main name of the domain (e.g., "example" in "sub.example.com").
*/
@Getter
private final String name;
/**
* The top-level name of the domain (e.g., "com" in "sub.example.com").
*/
@Getter
private final String topLevelName;
/**
* The path component of the domain (e.g., "path/to/resource" in "example.com/path/to/resource").
*/
@Getter
private String path;
/**
* The query component of the domain (e.g., "key=value" in "example.com/path?key=value").
*/
@Getter
private String query;
/**
* The fragment component of the domain (e.g., "section1" in "example.com/path#section1").
*/
@Getter
private String fragment;
/**
* The protocol of the domain (e.g., "oac" in "oac://example.com").
*/
@Getter
private String protocol;
/**
* Constructs a Domain object by parsing the provided full domain string.
*
* @param fullDomain The full domain string to parse.
* @throws IllegalArgumentException if the domain is invalid.
*/
public Domain(String fullDomain) {
// Remove protocol
String domainWithPath = fullDomain.contains("://") ? fullDomain.split("://", 2)[1] : fullDomain;
this.protocol = fullDomain.contains("://") ? fullDomain.split("://", 2)[0] : "";
if (this.protocol.endsWith("://"))
this.protocol = this.protocol.substring(0, this.protocol.length() - "://".length());
// Cut path
String[] domainPartsAndPath = domainWithPath.split("/", 2);
// Get host and full path
String host = domainPartsAndPath[0];
String fullPath = domainPartsAndPath.length > 1 ? "/" + domainPartsAndPath[1] : "";
// Split domain in labels
List<String> labels = Arrays.asList(host.split("\\."));
if (labels.size() < 2) throw new IllegalArgumentException("Invalid domain: " + host);
// Get subname, name and top-level name
this.topLevelName = labels.getLast();
this.name = labels.get(labels.size() - 2);
this.subname = labels.size() > 2 ? String.join(".", labels.subList(0, labels.size() - 2)) : null;
// Split fragment
if (fullPath.contains("#")) {
this.fragment = "#" + Arrays.stream(fullPath.split("#")).toList().getLast();
fullPath = fullPath.substring(0, fullPath.length() - ("#" + fragment).length());
} else this.fragment = "";
// Split path and query
if (fullPath.contains("?")) {
String[] parts = fullPath.split("\\?", 2);
this.path = parts[0];
this.query = parts[1];
} else {
this.path = fullPath;
this.query = "";
}
// Clean up path, query and fragment
if (this.path.startsWith("/")) this.path = this.path.substring(1);
if (this.path.endsWith("/")) this.path = this.path.substring(0, this.path.length() - 1);
if (this.query.startsWith("?")) this.query = this.query.substring(1);
if (this.fragment.startsWith("#")) this.fragment = this.fragment.substring(1);
}
/**
* Checks if the domain has a subname.
*
* @return true if the domain has a subname, false otherwise.
*/
public boolean hasSubname() {
return subname != null;
}
/**
* Checks if this domain is equal to another object.
* Two domains are considered equal if their subname, name, top-level name, and protocol are equal (case-insensitive).
*
* @return true if the domains are equal, false otherwise.
*/
@Override
public boolean equals(Object obj) {
// Check if the object is an instance of Domain
if (!(obj instanceof Domain domain)) return false;
// Compare subname, name, top-level name, and protocol (case-insensitive)
return domain.getSubname().equalsIgnoreCase(this.subname) && domain.getName().equalsIgnoreCase(this.name) &&
domain.getTopLevelName().equalsIgnoreCase(this.topLevelName) && domain.getProtocol().equalsIgnoreCase(this.protocol);
}
/**
* Returns the destination associated with this domain.
* The destination is determined based on the domain's components and the current protocol context.
*
* @return the destination as a string.
*/
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS)
public String getDestination() {
// If running as client or web server, return invalid request
if (ProtocolBridge.getInstance().isRunningAsClient() || ProtocolBridge.getInstance().isRunningAsWebServer())
return DNSResponseCode.RESPONSE_INVALID_REQUEST.toString();
// Handle special default domains
if (this.equals(DefaultDomains.DNS_INFO_SITE))
return ProtocolBridge.getInstance().getProtocolDNSServer().getDNSInfoSite();
if (this.equals(DefaultDomains.DNS_REGISTER_SITE))
return ProtocolBridge.getInstance().getProtocolDNSServer().getDNSRegisterSite();
if (this.name.equalsIgnoreCase("about") && this.protocol.equalsIgnoreCase("oac"))
return ProtocolBridge.getInstance().getProtocolDNSServer().getTLNInfoSite(topLevelName);
// Return destination based on whether subname exists
return !hasSubname() ? ProtocolBridge.getInstance().getProtocolDNSServer().getDomainDestination(this) : ProtocolBridge.getInstance().getProtocolDNSServer().getSubnameDestination(this, subname);
}
/**
* Returns a string representation of the domain, including its protocol, subname, name, top-level name, path, query, and fragment.
*/
public static class DefaultDomains {
public static final Domain DNS_INFO_SITE = new Domain("oac://about.oac/");
public static final Domain DNS_REGISTER_SITE = new Domain("oac://register.oac/");
public static Domain TLN_INFO_SITE(String topLevelName) {
return new Domain("oac://about." + topLevelName + "/");
}
}
}

View File

@@ -0,0 +1,85 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.beta;
import lombok.Getter;
import java.io.Serializable;
/**
* Enum representing various INS response codes and their descriptions.
*/
public enum INSResponseCode implements Serializable {
/**
* General Responses
*/
RESPONSE_NOT_REQUIRED(0, "Response code not required"),
RESPONSE_INVALID_REQUEST(1, "Invalid request"),
/**
* Authentication Responses
*/
RESPONSE_AUTH_SUCCESS(4, "Auth success"),
RESPONSE_AUTH_FAILED(5, "Auth failed"),
/**
* InfoName Responses
*/
RESPONSE_INFONAME_NAME_EXIST(100, "Infoname exist"),
RESPONSE_INFONAME_NAME_NOT_EXIST(101, "Infoname does not exist"),
RESPONSE_INFONAME_NAME_CREATED(105, "Infoname created"),
RESPONSE_INFONAME_NAME_DELETED(106, "Infoname deleted"),
/**
* Top Level Name Responses
*/
RESPONSE_INFONAME_TLN_EXIST(110, "TopLevelName exist"),
RESPONSE_INFONAME_TLN_NOT_EXIST(111, "TopLevelName does not exist"),
RESPONSE_INFONAME_TLN_CREATED(115, "TopLevelName created"),
RESPONSE_INFONAME_TLN_DELETED(116, "TopLevelName deleted"),
/**
* Subname Responses
*/
RESPONSE_INFONAME_SUBNAME_EXIST(120, "Subname exist"),
RESPONSE_INFONAME_SUBNAME_NOT_EXIST(121, "Subname does not exist"),
RESPONSE_INFONAME_SUBNAME_CREATED(125, "Subname created"),
RESPONSE_INFONAME_SUBNAME_DELETED(126, "Subname deleted"),
/**
* Full InfoName Responses
*/
RESPONSE_INFONAME_FULLY_EXIST(130, "Full Infoname exist"),
RESPONSE_INFONAME_FULLY_NOT_EXIST(131, "Full Infoname does not exist");
/**
* The numeric code representing the INS response.
*/
@Getter
private final int code;
/**
* A brief description of the INS response code.
*/
@Getter
private final String description;
/**
* Constructor for INSResponseCode enum.
*
* @param code The numeric code of the response.
* @param description A brief description of the response.
*/
INSResponseCode(int code, String description) {
this.code = code;
this.description = description;
}
/**
* Returns a string representation of the INS response code, including its code and description.
*
* @return a string representation of the INS response code.
*/
@Override
public String toString() {
return "{code=" + code + ";description=" + description + "}";
}
}

View File

@@ -0,0 +1,172 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.beta;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
/**
* Class representing a InfoName with its components such as subname, name, top-level name, path, query, fragment, and protocol.
*/
public final class InfoName implements Serializable {
/**
* The subname of the InfoName (e.g., "sub" in "sub.example.com").
*/
@Getter
private final String subname;
/**
* The main name of the InfoName (e.g., "example" in "sub.example.com").
*/
@Getter
private final String name;
/**
* The top-level name of the InfoName (e.g., "com" in "sub.example.com").
*/
@Getter
private final String topLevelName;
/**
* The path component of the InfoName (e.g., "path/to/resource" in "example.com/path/to/resource").
*/
@Getter
private String path;
/**
* The query component of the InfoName (e.g., "key=value" in "example.com/path?key=value").
*/
@Getter
private String query;
/**
* The fragment component of the InfoName (e.g., "section1" in "example.com/path#section1").
*/
@Getter
private String fragment;
/**
* The protocol of the InfoName (e.g., "oac" in "oac://example.com").
*/
@Getter
private String protocol;
/**
* Constructs a InfoName object by parsing the provided full InfoName string.
*
* @param fullInfoName The full InfoName string to parse.
* @throws IllegalArgumentException if the InfoName is invalid.
*/
public InfoName(String fullInfoName) {
// Remove protocol
String infoNameWithPath = fullInfoName.contains("://") ? fullInfoName.split("://", 2)[1] : fullInfoName;
this.protocol = fullInfoName.contains("://") ? fullInfoName.split("://", 2)[0] : "";
if (this.protocol.endsWith("://"))
this.protocol = this.protocol.substring(0, this.protocol.length() - "://".length());
// Cut path
String[] infoNamePartsAndPath = infoNameWithPath.split("/", 2);
// Get host and full path
String host = infoNamePartsAndPath[0];
String fullPath = infoNamePartsAndPath.length > 1 ? "/" + infoNamePartsAndPath[1] : "";
// Split InfoName in labels
List<String> labels = Arrays.asList(host.split("\\."));
if (labels.size() < 2) throw new IllegalArgumentException("Invalid InfoName: " + host);
// Get subname, name and top-level name
this.topLevelName = labels.getLast();
this.name = labels.get(labels.size() - 2);
this.subname = labels.size() > 2 ? String.join(".", labels.subList(0, labels.size() - 2)) : null;
// Split fragment
if (fullPath.contains("#")) {
this.fragment = "#" + Arrays.stream(fullPath.split("#")).toList().getLast();
fullPath = fullPath.substring(0, fullPath.length() - ("#" + fragment).length());
} else this.fragment = "";
// Split path and query
if (fullPath.contains("?")) {
String[] parts = fullPath.split("\\?", 2);
this.path = parts[0];
this.query = parts[1];
} else {
this.path = fullPath;
this.query = "";
}
// Clean up path, query and fragment
if (this.path.startsWith("/")) this.path = this.path.substring(1);
if (this.path.endsWith("/")) this.path = this.path.substring(0, this.path.length() - 1);
if (this.query.startsWith("?")) this.query = this.query.substring(1);
if (this.fragment.startsWith("#")) this.fragment = this.fragment.substring(1);
}
/**
* Checks if the InfoName has a subname.
*
* @return true if the InfoName has a subname, false otherwise.
*/
public boolean hasSubname() {
return subname != null;
}
/**
* Checks if this InfoName is equal to another object.
* Two InfoNames are considered equal if their subname, name, top-level name, and protocol are equal (case-insensitive).
*
* @return true if the InfoNames are equal, false otherwise.
*/
@Override
public boolean equals(Object obj) {
// Check if the object is an instance of InfoName
if (!(obj instanceof InfoName infoName)) return false;
// Compare subname, name, top-level name, and protocol (case-insensitive)
return infoName.getSubname().equalsIgnoreCase(this.subname) && infoName.getName().equalsIgnoreCase(this.name) &&
infoName.getTopLevelName().equalsIgnoreCase(this.topLevelName) && infoName.getProtocol().equalsIgnoreCase(this.protocol);
}
/**
* Returns the destination associated with this InfoName.
* The destination is determined based on the InfoName's components and the current protocol context.
*
* @return the destination as a string.
*/
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public String getDestination(ProtocolBridge protocolBridge) {
// If running as client or web server, return invalid request
if (protocolBridge.isRunningAsClient() || protocolBridge.isRunningAsWebServer())
return INSResponseCode.RESPONSE_INVALID_REQUEST.toString();
// Handle special default InfoNames
if (this.equals(DefaultInfoNames.INS_INFO_SITE))
return protocolBridge.getProtocolINSServer().getINSInfoSite();
if (this.equals(DefaultInfoNames.INS_REGISTER_SITE))
return protocolBridge.getProtocolINSServer().getINSRegisterSite();
if (this.equals(DefaultInfoNames.TLN_INFO_SITE(topLevelName)))
return protocolBridge.getProtocolINSServer().getTLNInfoSite(topLevelName);
// Return destination based on whether subname exists
return !hasSubname() ? protocolBridge.getProtocolINSServer().getInfoNameDestination(this) : protocolBridge.getProtocolINSServer().getSubnameDestination(this, subname);
}
/**
* Returns a string representation of the InfoName, including its protocol, subname, name, top-level name, path, query, and fragment.
*/
public static class DefaultInfoNames {
public static final InfoName INS_INFO_SITE = new InfoName("oac://info.oac/");
public static final InfoName INS_REGISTER_SITE = new InfoName("oac://register.oac/");
public static InfoName TLN_INFO_SITE(String topLevelName) {
return new InfoName("oac://about." + topLevelName + "/");
}
}
}

View File

@@ -1,6 +1,7 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.events; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.events;
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event; import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerINSServer;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
@@ -9,7 +10,7 @@ import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Class
* This event is fired when a classic domain packet is received. * This event is fired when a classic domain packet is received.
* This event is deprecated and will be marked for removal in future versions. * This event is deprecated and will be marked for removal in future versions.
* *
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerDNSServer * @see ClassicHandlerINSServer
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient * @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer * @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer
*/ */

View File

@@ -1,6 +1,7 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.events; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.events;
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event; import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerINSServer;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
@@ -9,7 +10,7 @@ import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Class
* This event is fired when a classic ping packet is received. * This event is fired when a classic ping packet is received.
* This event is deprecated and will be marked for removal in future versions. * This event is deprecated and will be marked for removal in future versions.
* *
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerDNSServer * @see ClassicHandlerINSServer
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient * @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer * @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer
*/ */

View File

@@ -1,8 +1,10 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket; import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket;
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_SiteType; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_SiteType;
@@ -16,6 +18,21 @@ import java.io.IOException;
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
public abstract class ClassicHandlerClient { public abstract class ClassicHandlerClient {
/**
* Reference to the ProtocolClient
*/
@Getter
private final ProtocolClient client;
/**
* Sets the client variable
*
* @param client The ProtocolClient Object
*/
public ClassicHandlerClient(ProtocolClient client) {
this.client = client;
}
public abstract void unsupportedClassicPacket(String classicPacketClassName, Object[] content); public abstract void unsupportedClassicPacket(String classicPacketClassName, Object[] content);
public abstract void handleHTMLContent(Classic_SiteType siteType, Classic_Domain domain, String html); public abstract void handleHTMLContent(Classic_SiteType siteType, Classic_Domain domain, String html);
@@ -23,6 +40,6 @@ public abstract class ClassicHandlerClient {
public abstract void handleMessage(String message, Classic_ProtocolVersion protocolVersion); public abstract void handleMessage(String message, Classic_ProtocolVersion protocolVersion);
public final void sendMessage(String message) throws IOException, ClassNotFoundException { public final void sendMessage(String message) throws IOException, ClassNotFoundException {
ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().sendPacket(new Classic_MessagePacket(message, 0)); client.getClientINSConnection().sendPacket(new Classic_MessagePacket(message, 0, client.getProtocolBridge()));
} }
} }

View File

@@ -1,7 +1,7 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient; import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
@@ -10,10 +10,10 @@ import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Class
import java.sql.SQLException; import java.sql.SQLException;
/** /**
* Abstract class defining the DNS server-side handler for Classic protocol operations. * Abstract class defining the INS server-side handler for Classic protocol operations.
*/ */
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS) @ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
public abstract class ClassicHandlerDNSServer { public abstract class ClassicHandlerINSServer {
public abstract void handleMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion); public abstract void handleMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion);
public abstract Classic_Domain getDomain(Classic_RequestDomain requestDomain) throws SQLException; public abstract Classic_Domain getDomain(Classic_RequestDomain requestDomain) throws SQLException;

View File

@@ -1,7 +1,7 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
import org.openautonomousconnection.protocol.annotations.ProtocolInfo; import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient; import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;

View File

@@ -1,14 +1,15 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
import lombok.Getter; import lombok.Getter;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
import java.io.Serializable; import java.io.Serializable;
/** /**
* Classic_Domain is an old representation of a domain, maintained for backward compatibility. * Classic_Domain is an old representation of a InfoName, maintained for backward compatibility.
* It encapsulates the domain's name, top-level domain, path, and destination. * It encapsulates the InfoName's name, top-level name, path, and destination.
* This class is deprecated and users are encouraged to use the Domain class instead. * This class is deprecated and users are encouraged to use the InfoName class instead.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public class Classic_Domain implements Serializable { public class Classic_Domain implements Serializable {
@@ -16,45 +17,52 @@ public class Classic_Domain implements Serializable {
/** /**
* The name of the domain (e.g., "example" in "example.com"). * The name of the domain (e.g., "example" in "example.com").
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3 | Will be replaced with a getter") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public final String name; public final String name;
/** /**
* The top-level domain (e.g., "com" in "example.com"). * The top-level domain (e.g., "com" in "example.com").
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3 | Will be replaced with a getter") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public final String topLevelDomain; public final String topLevelDomain;
/** /**
* The path component of the domain (e.g., "/path/to/resource" in "example.com/path/to/resource"). * The path component of the domain (e.g., "/path/to/resource" in "example.com/path/to/resource").
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3 | Will be replaced with a getter") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public final String path; public final String path;
/** /**
* The destination of the domain, typically the full URL or address. * The destination of the domain, typically the full URL or address.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3 | Will be replaced with a getter") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
private final String destination; private final String destination;
/**
* The ProtocolBridge reference.
*/
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
private final ProtocolBridge protocolBridge;
/** /**
* The encapsulated Domain object for modern usage. * The encapsulated Domain object for modern usage.
*/ */
@Getter @Getter
private final Domain domain; private final InfoName infoName;
public Classic_Domain(String name, String topLevelDomain, String destination, String path) { public Classic_Domain(String name, String topLevelDomain, String destination, String path, ProtocolBridge bridge) {
this.domain = new Domain(name + "." + topLevelDomain + "/" + (path.startsWith("/") ? path : "/" + path)); this.protocolBridge = bridge;
this.name = domain.getName(); this.infoName = new InfoName(name + "." + topLevelDomain + "/" + (path.startsWith("/") ? path : "/" + path));
this.topLevelDomain = domain.getTopLevelName(); this.name = infoName.getName();
this.destination = domain.getDestination(); this.topLevelDomain = infoName.getTopLevelName();
this.path = domain.getPath(); this.destination = infoName.getDestination(bridge);
this.path = infoName.getPath();
} }
@Override @Override
protected final Object clone() throws CloneNotSupportedException { protected final Object clone() throws CloneNotSupportedException {
return new Classic_Domain(name, topLevelDomain, destination, path); return new Classic_Domain(name, topLevelDomain, destination, path, protocolBridge);
} }
@Override @Override

View File

@@ -1,12 +1,14 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
import org.openautonomousconnection.protocol.ProtocolBridge;
/** /**
* Class representing a local domain in the Classic protocol. * Class representing a local domain in the Classic protocol.
* This class extends Classic_Domain and is used for local domain representation. * This class extends Classic_Domain and is used for local domain representation.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public final class Classic_LocalDomain extends Classic_Domain { public final class Classic_LocalDomain extends Classic_Domain {
public Classic_LocalDomain(String name, String endName, String path) { public Classic_LocalDomain(String name, String endName, String path, ProtocolBridge protocolBridge) {
super(name, endName, null, path); super(name, endName, null, path, protocolBridge);
} }
} }

View File

@@ -1,5 +1,7 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
import org.openautonomousconnection.protocol.ProtocolBridge;
import java.io.Serializable; import java.io.Serializable;
/** /**
@@ -9,7 +11,7 @@ import java.io.Serializable;
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public final class Classic_RequestDomain extends Classic_Domain implements Serializable { public final class Classic_RequestDomain extends Classic_Domain implements Serializable {
public Classic_RequestDomain(String name, String topLevelDomain, String path) { public Classic_RequestDomain(String name, String topLevelDomain, String path, ProtocolBridge protocolBridge) {
super(name, topLevelDomain, null, path); super(name, topLevelDomain, null, path, protocolBridge);
} }
} }

View File

@@ -18,7 +18,7 @@ public enum Classic_SiteType implements Serializable {
SERVER("oac-server"), SERVER("oac-server"),
/** /**
* DNS server site type. * INS server site type.
*/ */
PUBLIC("oac"), PUBLIC("oac"),
@@ -35,7 +35,7 @@ public enum Classic_SiteType implements Serializable {
/** /**
* The name of the site type. * The name of the site type.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3 | Will be replaced with a getter") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public final String name; public final String name;
Classic_SiteType(String name) { Classic_SiteType(String name) {

View File

@@ -17,7 +17,7 @@ public final class Classic_WebsitesContent extends DefaultMethodsOverrider {
<meta content="Domain not found" name="description"/> <meta content="Domain not found" name="description"/>
</head> </head>
<body> <body>
<h1>404 - This domain was not found</h1> <h1>404 - This infoName was not found</h1>
</body> </body>
</html> </html>
"""; """;
@@ -61,7 +61,7 @@ public final class Classic_WebsitesContent extends DefaultMethodsOverrider {
<meta content="Site not reached" name="description"/> <meta content="Site not reached" name="description"/>
</head> </head>
<body> <body>
<h1>500 - Error occured while resolving domain!</h1> <h1>500 - Error occured while resolving infoName!</h1>
<h4>Details:</h2> <h4>Details:</h2>
<h5>""" + errorDetails + "</h5>" + """ <h5>""" + errorDetails + "</h5>" + """
</body> </body>

View File

@@ -1,7 +1,8 @@
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils; package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.versions.ProtocolVersion; import org.openautonomousconnection.protocol.versions.ProtocolVersion;
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.InfoName;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
/** /**
@@ -10,25 +11,26 @@ import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Cla
public final class ClassicConverter { public final class ClassicConverter {
/** /**
* Converts a Classic_Domain object to a Domain object. * Converts a Classic_Domain object to a InfoName object.
* *
* @param classicDomain the Classic_Domain object to convert * @param classicDomain the Classic_Domain object to convert
* @return the converted Domain object * @return the converted InfoName object
*/ */
@SuppressWarnings(value = "deprecation") @SuppressWarnings(value = "deprecation")
public static Domain classicDomainToNewDomain(Classic_Domain classicDomain) { public static InfoName classicDomainToInfoName(Classic_Domain classicDomain) {
return new Domain(classicDomain.name + "." + classicDomain.topLevelDomain + (classicDomain.path.startsWith("/") ? classicDomain.path : "/" + classicDomain.path)); return new InfoName(classicDomain.name + "." + classicDomain.topLevelDomain + (classicDomain.path.startsWith("/") ? classicDomain.path : "/" + classicDomain.path));
} }
/** /**
* Converts a Domain object to a Classic_Domain object. * Converts a InfoName object to a Classic_Domain object.
* *
* @param newDomain the Domain object to convert * @param newInfoName the InfoName object to convert
* @param protocolBridge The reference to the ProtocolBridge object.
* @return the converted Classic_Domain object * @return the converted Classic_Domain object
*/ */
@SuppressWarnings(value = "deprecation") @SuppressWarnings(value = "deprecation")
public static Classic_Domain newDomainToClassicDomain(Domain newDomain) { public static Classic_Domain infoNameToClassicDomain(InfoName newInfoName, ProtocolBridge protocolBridge) {
return new Classic_Domain(newDomain.getName(), newDomain.getTopLevelName(), newDomain.getDestination(), newDomain.getPath()); return new Classic_Domain(newInfoName.getName(), newInfoName.getTopLevelName(), newInfoName.getDestination(protocolBridge), newInfoName.getPath(), protocolBridge);
} }
/** /**

View File

@@ -2,6 +2,7 @@ package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
import dev.unlegitdqrk.unlegitlibrary.event.EventListener; import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
import dev.unlegitdqrk.unlegitlibrary.event.Listener; import dev.unlegitdqrk.unlegitlibrary.event.Listener;
import lombok.Getter;
import org.openautonomousconnection.protocol.ProtocolBridge; import org.openautonomousconnection.protocol.ProtocolBridge;
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket; import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket;
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_DomainPacketReceivedEvent; import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_DomainPacketReceivedEvent;
@@ -18,15 +19,30 @@ import java.net.URL;
/** /**
* This class listens for events related to Classic protocol operations on the client side. * This class listens for events related to Classic protocol operations on the client side.
* It handles domain resolution and ping responses, facilitating communication with the DNS server * It handles domain resolution and ping responses, facilitating communication with the INS server
* and web content retrieval. * and web content retrieval.
*/ */
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3") @Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
public final class Classic_ClientListener extends EventListener { public final class Classic_ClientListener extends EventListener {
/**
* Reference to the ProtocolBridge
*/
@Getter
private ProtocolBridge protocolBridge;
/**
* Set protocol bridge
* @param protocolBridge The ProtocolBridge object
*/
public void setProtocolBridge(ProtocolBridge protocolBridge) {
if (this.protocolBridge != null) return;
this.protocolBridge = protocolBridge;
}
/** /**
* Handles the event when a domain packet is received. * Handles the event when a domain packet is received.
* It checks if the domain exists and sends a ping request to the DNS server. * It checks if the domain exists and sends a ping request to the INS server.
* If the domain does not exist, it handles the error accordingly. * If the domain does not exist, it handles the error accordingly.
* *
* @param event The event containing domain information. * @param event The event containing domain information.
@@ -38,20 +54,20 @@ public final class Classic_ClientListener extends EventListener {
if (exists) { if (exists) {
try { try {
// Send a ping request to the DNS server // Send a ping request to the INS server
if (!ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().sendPacket(new Classic_PingPacket(event.requestDomain, event.domain, false))) { if (!protocolBridge.getProtocolClient().getClientINSConnection().sendPacket(new Classic_PingPacket(event.requestDomain, event.domain, false, protocolBridge))) {
// If sending the packet fails, handle the error // If sending the packet fails, handle the error
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""), protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", "", protocolBridge),
Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path)); Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path));
} }
} catch (IOException | ClassNotFoundException e) { } catch (IOException | ClassNotFoundException e) {
// Handle any exceptions that occur during the process // Handle any exceptions that occur during the process
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""), protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", "", protocolBridge),
Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path + ":\n" + e.getMessage())); Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path + ":\n" + e.getMessage()));
} }
} else } else
// If the domain does not exist, handle the error // If the domain does not exist, handle the error
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("domain-not-found", "html", ""), Classic_WebsitesContent.DOMAIN_NOT_FOUND); protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("domain-not-found", "html", "", protocolBridge), Classic_WebsitesContent.DOMAIN_NOT_FOUND);
} }
/** /**
@@ -65,7 +81,7 @@ public final class Classic_ClientListener extends EventListener {
public void onPing(Classic_PingPacketReceivedEvent event) { public void onPing(Classic_PingPacketReceivedEvent event) {
// If the domain is reachable, fetch the HTML content // If the domain is reachable, fetch the HTML content
if (event.reachable) { if (event.reachable) {
String destination = event.domain.getDomain().getDestination(); String destination = event.domain.getInfoName().getDestination(protocolBridge);
try { try {
// Create a URL object // Create a URL object
@@ -81,15 +97,15 @@ public final class Classic_ClientListener extends EventListener {
} }
// Handle the HTML content // Handle the HTML content
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PUBLIC, event.domain, content.toString()); protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PUBLIC, event.domain, content.toString());
} catch (IOException exception) { } catch (IOException exception) {
// Handle any exceptions that occur during the process // Handle any exceptions that occur during the process
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""), protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", "", protocolBridge),
Classic_WebsitesContent.ERROR_OCCURRED(exception.getMessage().replace(event.domain.getDomain().getDestination(), event.domain + "/" + event.domain.path))); Classic_WebsitesContent.ERROR_OCCURRED(exception.getMessage().replace(event.domain.getInfoName().getDestination(protocolBridge), event.domain + "/" + event.domain.path)));
} }
} else } else
// If the domain is not reachable, handle the error // If the domain is not reachable, handle the error
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-not-reached", "html", ""), Classic_WebsitesContent.DOMAIN_NOT_REACHABLE); protocolBridge.getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-not-reached", "html", "", protocolBridge), Classic_WebsitesContent.DOMAIN_NOT_REACHABLE);
} }
@Override @Override