- Added comments
This commit is contained in:
@@ -7,21 +7,59 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Enum representing different protocol versions, their types, sides, and compatibility.
|
||||
*/
|
||||
public enum ProtocolVersion implements Serializable {
|
||||
/**
|
||||
* 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)),
|
||||
|
||||
/**
|
||||
* First Beta Version of OAC-Protocol
|
||||
*/
|
||||
PV_1_0_0_BETA("1.0.0", ProtocolType.BETA, ProtocolSide.ALL, List.of(Protocol.OAC), PV_1_0_0_CLASSIC);
|
||||
|
||||
/**
|
||||
* The version string of the protocol version.
|
||||
*/
|
||||
@Getter
|
||||
private final String version;
|
||||
|
||||
/**
|
||||
* The type of the protocol version.
|
||||
*/
|
||||
@Getter
|
||||
private final ProtocolType protocolType;
|
||||
|
||||
/**
|
||||
* The side(s) the protocol version is intended for.
|
||||
*/
|
||||
@Getter
|
||||
private final ProtocolSide protocolSide;
|
||||
|
||||
/**
|
||||
* List of protocol versions that are compatible with this version.
|
||||
*/
|
||||
@Getter
|
||||
private final List<ProtocolVersion> compatibleVersions;
|
||||
|
||||
/**
|
||||
* List of supported protocols.
|
||||
*/
|
||||
@Getter
|
||||
private final List<Protocol> supportedProtocols;
|
||||
|
||||
/**
|
||||
* Constructor for ProtocolVersion enum.
|
||||
*
|
||||
* @param version The version string.
|
||||
* @param protocolType The type of the protocol.
|
||||
* @param protocolSide The side(s) the protocol is intended for.
|
||||
* @param supportedProtocols List of supported protocols.
|
||||
* @param compatibleVersions Varargs of compatible protocol versions.
|
||||
*/
|
||||
ProtocolVersion(String version, ProtocolType protocolType, ProtocolSide protocolSide, List<Protocol> supportedProtocols, ProtocolVersion... compatibleVersions) {
|
||||
this.version = version;
|
||||
this.protocolType = protocolType;
|
||||
@@ -31,57 +69,123 @@ public enum ProtocolVersion implements Serializable {
|
||||
this.supportedProtocols = supportedProtocols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the protocol version, including its version, type, side, supported protocols, and compatible versions.
|
||||
* @return a string representation of the protocol version.
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
StringBuilder compatible = new StringBuilder("[");
|
||||
StringBuilder supported = new StringBuilder("[");
|
||||
|
||||
for (ProtocolVersion compatibleVersion : compatibleVersions) compatible.append(compatibleVersion.buildName());
|
||||
for (Protocol supportedProtocol : supportedProtocols) supported.append(supportedProtocol.toString());
|
||||
|
||||
compatible.append("]");
|
||||
supported.append("]");
|
||||
|
||||
return "{version=" + version + ";type=" + protocolType.toString() + ";side=" + protocolSide.toString() + ";supportedProtocols=" + supported + ";compatibleVersions=" + compatible + "}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a name for the protocol version combining its version and type.
|
||||
* @return a string representing the name of the protocol version.
|
||||
*/
|
||||
public final String buildName() {
|
||||
return version + "-" + protocolType.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum representing different protocols.
|
||||
*/
|
||||
public enum Protocol implements Serializable {
|
||||
HTTP,
|
||||
HTTPS,
|
||||
OAC;
|
||||
|
||||
/**
|
||||
* Returns the name of the protocol in uppercase.
|
||||
* @return the name of the protocol in uppercase.
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
return name().toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum representing different types of protocol versions.
|
||||
*/
|
||||
public enum ProtocolType implements Serializable {
|
||||
CLASSIC, // -> See "_old" Projects https://repo.open-autonomous-connection.org/Open-Autonomous-Connection/
|
||||
/**
|
||||
* Classic Protocol Type, see old OAC-Project: <a href="https://repo.open-autonomous-connection.org/Open-Autonomous-Connection/">*_old</a>
|
||||
*/
|
||||
CLASSIC,
|
||||
|
||||
/**
|
||||
* Beta Protocol Type, may be unstable and subject to change.
|
||||
*/
|
||||
BETA,
|
||||
|
||||
/**
|
||||
* Stable Protocol Type, recommended for production use.
|
||||
*/
|
||||
STABLE;
|
||||
|
||||
/**
|
||||
* Returns the name of the protocol in uppercase.
|
||||
* @return the name of the protocol in uppercase.
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
return name().toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum representing different sides where the protocol version can be used.
|
||||
*/
|
||||
public enum ProtocolSide implements Serializable {
|
||||
/**
|
||||
* Client Side only
|
||||
*/
|
||||
CLIENT, // Protocol version can only used on Client
|
||||
DNS, // Protocol version can only used on DNS Server
|
||||
WEB, // Protocol version can only used on Web Server
|
||||
|
||||
WEB_DNS, // Protocol version can only used on DNS and WebSerber
|
||||
/**
|
||||
* DNS Server Side only
|
||||
*/
|
||||
DNS,
|
||||
|
||||
CLIENT_DNS, // Protocol version can only used on DNS and Client
|
||||
CLIENT_WEB, // Protocol version can only used on WebServer and Client
|
||||
/**
|
||||
* Web Server Side only
|
||||
*/
|
||||
WEB,
|
||||
|
||||
ALL // Protocol version can used on all Sides
|
||||
/**
|
||||
* Both DNS and Web Server Side
|
||||
*/
|
||||
WEB_DNS,
|
||||
|
||||
/**
|
||||
* Both Client and DNS Server Side
|
||||
*/
|
||||
CLIENT_DNS,
|
||||
|
||||
/**
|
||||
* Both Client and Web Server Side
|
||||
*/
|
||||
CLIENT_WEB,
|
||||
|
||||
/**
|
||||
* All Sides
|
||||
*/
|
||||
ALL
|
||||
;
|
||||
|
||||
/**
|
||||
* Returns the name of the protocol in uppercase.
|
||||
* @return the name of the protocol in uppercase.
|
||||
*/
|
||||
@Override
|
||||
public final String toString() {
|
||||
return name().toUpperCase();
|
||||
|
||||
@@ -4,42 +4,79 @@ 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 + "}";
|
||||
|
||||
@@ -9,22 +9,58 @@ 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 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;
|
||||
@@ -34,17 +70,21 @@ public class Domain implements Serializable {
|
||||
|
||||
// Cut path
|
||||
String[] domainPartsAndPath = domainWithPath.split("/", 2);
|
||||
String host = domainPartsAndPath[0]; // z.B. hello.world.com
|
||||
|
||||
// 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());
|
||||
@@ -60,6 +100,7 @@ public class Domain implements Serializable {
|
||||
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);
|
||||
|
||||
@@ -67,23 +108,41 @@ public class Domain implements Serializable {
|
||||
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 final 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 final 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 final 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))
|
||||
@@ -91,9 +150,14 @@ public class Domain implements Serializable {
|
||||
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.
|
||||
* @return a string representation of the domain.
|
||||
*/
|
||||
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/");
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
enum Classic_SiteType implements Serializable {
|
||||
CLIENT("oac-client"), SERVER("oac-server"),
|
||||
PUBLIC("oac"), PROTOCOL("oac-protocol"), LOCAL("oac-local");
|
||||
|
||||
public final String name;
|
||||
|
||||
Classic_SiteType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,19 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.events;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
|
||||
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.utils.Classic_ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||
|
||||
/**
|
||||
* This event is fired when a classic domain packet is received.
|
||||
* 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 org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient
|
||||
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public class Classic_DomainPacketReceivedEvent extends Event {
|
||||
|
||||
public final Classic_ProtocolVersion protocolVersion;
|
||||
@@ -1,9 +1,19 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.events;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.impl.Event;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||
|
||||
/**
|
||||
* This event is fired when a classic ping packet is received.
|
||||
* 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 org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient
|
||||
* @see org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerWebServer
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public class Classic_PingPacketReceivedEvent extends Event {
|
||||
|
||||
public final Classic_ProtocolVersion protocolVersion;
|
||||
public final Classic_Domain domain;
|
||||
public final Classic_RequestDomain requestDomain;
|
||||
@@ -1,13 +1,18 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
|
||||
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket;
|
||||
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.site.Classic_SiteType;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract class defining the client-side handler for Classic protocol operations.
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
|
||||
public abstract class ClassicHandlerClient {
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
|
||||
|
||||
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
|
||||
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient;
|
||||
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.utils.Classic_ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_RequestDomain;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Abstract class defining the DNS server-side handler for Classic protocol operations.
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.DNS)
|
||||
public abstract class ClassicHandlerDNSServer {
|
||||
public abstract void handleMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion);
|
||||
@@ -1,11 +1,13 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers;
|
||||
|
||||
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
|
||||
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Abstract class defining the web server-side handler for Classic protocol operations.
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
|
||||
public abstract class ClassicHandlerWebServer {
|
||||
public abstract void handleMessage(ConnectedProtocolClient client, String message, Classic_ProtocolVersion protocolVersion);
|
||||
@@ -1,15 +1,46 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Classic_Domain is an old representation of a domain, maintained for backward compatibility.
|
||||
* It encapsulates the domain's name, top-level domain, path, and destination.
|
||||
* This class is deprecated and users are encouraged to use the Domain class instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public class Classic_Domain implements Serializable {
|
||||
|
||||
/**
|
||||
* 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")
|
||||
public final String name;
|
||||
|
||||
/**
|
||||
* 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")
|
||||
public final String topLevelDomain;
|
||||
|
||||
|
||||
/**
|
||||
* 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")
|
||||
public final String path;
|
||||
|
||||
/**
|
||||
* 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")
|
||||
private final String destination;
|
||||
|
||||
/**
|
||||
* The encapsulated Domain object for modern usage.
|
||||
*/
|
||||
@Getter
|
||||
private final Domain domain;
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
|
||||
|
||||
/**
|
||||
* Class representing a local domain in the Classic protocol.
|
||||
* This class extends Classic_Domain and is used for local domain representation.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public class Classic_LocalDomain extends Classic_Domain {
|
||||
public Classic_LocalDomain(String name, String endName, String path) {
|
||||
super(name, endName, null, path);
|
||||
@@ -1,7 +1,12 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Class representing a request for a domain in the Classic protocol.
|
||||
* This class extends Classic_Domain and is used for requesting domain information.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public class Classic_RequestDomain extends Classic_Domain implements Serializable {
|
||||
|
||||
public Classic_RequestDomain(String name, String topLevelDomain, String path) {
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.site;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Enum representing different types of sites in the Classic protocol.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public enum Classic_SiteType implements Serializable {
|
||||
/**
|
||||
* Client site type.
|
||||
*/
|
||||
CLIENT("oac-client"),
|
||||
|
||||
/**
|
||||
* Web server site type.
|
||||
*/
|
||||
SERVER("oac-server"),
|
||||
|
||||
/**
|
||||
* DNS server site type.
|
||||
*/
|
||||
PUBLIC("oac"),
|
||||
|
||||
/**
|
||||
* Protocol site type.
|
||||
*/
|
||||
PROTOCOL("oac-protocol"),
|
||||
|
||||
/**
|
||||
* Local site type.
|
||||
*/
|
||||
LOCAL("oac-local");
|
||||
|
||||
/**
|
||||
* The name of the site type.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3 | Will be replaced with a getter")
|
||||
public final String name;
|
||||
|
||||
Classic_SiteType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.site;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||
|
||||
/**
|
||||
* This class contains predefined HTML content for various website responses in the Classic protocol.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public class Classic_WebsitesContent extends DefaultMethodsOverrider {
|
||||
|
||||
public static final String DOMAIN_NOT_FOUND = """
|
||||
@@ -1,23 +1,51 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
|
||||
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
|
||||
/**
|
||||
* Utility class for converting between Classic protocol objects and new protocol objects.
|
||||
*/
|
||||
public class ClassicConverter {
|
||||
|
||||
/**
|
||||
* Converts a Classic_Domain object to a Domain object.
|
||||
* @param classicDomain the Classic_Domain object to convert
|
||||
* @return the converted Domain object
|
||||
*/
|
||||
@SuppressWarnings(value = "deprecation")
|
||||
public static Domain classicDomainToNewDomain(Classic_Domain classicDomain) {
|
||||
return new Domain(classicDomain.name + "." + classicDomain.topLevelDomain + (classicDomain.path.startsWith("/") ? classicDomain.path : "/" + classicDomain.path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Domain object to a Classic_Domain object.
|
||||
* @param newDomain the Domain object to convert
|
||||
* @return the converted Classic_Domain object
|
||||
*/
|
||||
@SuppressWarnings(value = "deprecation")
|
||||
public static Classic_Domain newDomainToClassicDomain(Domain newDomain) {
|
||||
return new Classic_Domain(newDomain.getName(), newDomain.getTopLevelName(), newDomain.getDestination(), newDomain.getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Classic_ProtocolVersion to a ProtocolVersion.
|
||||
* @param classicProtocolVersion the Classic_ProtocolVersion to convert
|
||||
* @return the converted ProtocolVersion
|
||||
*/
|
||||
@SuppressWarnings(value = "deprecation")
|
||||
public static ProtocolVersion classicProtocolVersionToNewProtocolVersion(Classic_ProtocolVersion classicProtocolVersion) {
|
||||
if (classicProtocolVersion == Classic_ProtocolVersion.PV_1_0_0) return ProtocolVersion.PV_1_0_0_CLASSIC;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a ProtocolVersion to a Classic_ProtocolVersion.
|
||||
* @param newProtocolVersion the ProtocolVersion to convert
|
||||
* @return the converted Classic_ProtocolVersion
|
||||
*/
|
||||
@SuppressWarnings(value = "deprecation")
|
||||
public static Classic_ProtocolVersion newProtocolVersionToClassicProtocolVersion(ProtocolVersion newProtocolVersion) {
|
||||
return Classic_ProtocolVersion.PV_1_0_0;
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.EventListener;
|
||||
import dev.unlegitdqrk.unlegitlibrary.event.Listener;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
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_PingPacketReceivedEvent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_LocalDomain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_SiteType;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_WebsitesContent;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
@@ -11,48 +16,77 @@ import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* and web content retrieval.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public class Classic_ClientListener extends EventListener {
|
||||
|
||||
/**
|
||||
* Handles the event when a domain packet is received.
|
||||
* It checks if the domain exists and sends a ping request to the DNS server.
|
||||
* If the domain does not exist, it handles the error accordingly.
|
||||
* @param event The event containing domain information.
|
||||
*/
|
||||
@Listener
|
||||
public void onDomain(Classic_DomainPacketReceivedEvent event) {
|
||||
// Check if the domain exists
|
||||
boolean exists = event.domain != null;
|
||||
|
||||
if (exists) {
|
||||
try {
|
||||
// Send a ping request to the DNS server
|
||||
if (!ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().sendPacket(new Classic_PingPacket(event.requestDomain, event.domain, false))) {
|
||||
// If sending the packet fails, handle the error
|
||||
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""),
|
||||
Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path));
|
||||
}
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
// Handle any exceptions that occur during the process
|
||||
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""),
|
||||
Classic_WebsitesContent.ERROR_OCCURRED(event.domain + "/" + event.domain.path + ":\n" + e.getMessage()));
|
||||
}
|
||||
} else
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the event when a ping packet is received.
|
||||
* If the domain is reachable, it fetches the HTML content from the domain.
|
||||
* If not reachable, it handles the error accordingly.
|
||||
* @param event The event containing ping response information.
|
||||
*/
|
||||
@Listener
|
||||
public void onPing(Classic_PingPacketReceivedEvent event) {
|
||||
// If the domain is reachable, fetch the HTML content
|
||||
if (event.reachable) {
|
||||
String destination = event.domain.getDomain().getDestination();
|
||||
|
||||
try {
|
||||
// Create a URL object
|
||||
URL url = new URL(destination);
|
||||
HttpURLConnection connection2 = (HttpURLConnection) url.openConnection();
|
||||
connection2.setRequestMethod("GET");
|
||||
|
||||
// Read the response
|
||||
StringBuilder content = new StringBuilder();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection2.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) content.append(line);
|
||||
}
|
||||
|
||||
// Handle the HTML content
|
||||
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PUBLIC, event.domain, content.toString());
|
||||
} catch (IOException exception) {
|
||||
// Handle any exceptions that occur during the process
|
||||
ProtocolBridge.getInstance().getClassicHandlerClient().handleHTMLContent(Classic_SiteType.PROTOCOL, new Classic_LocalDomain("error-occurred", "html", ""),
|
||||
Classic_WebsitesContent.ERROR_OCCURRED(exception.getMessage().replace(event.domain.getDomain().getDestination(), event.domain + "/" + event.domain.path)));
|
||||
}
|
||||
} else
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,25 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
|
||||
|
||||
import dev.unlegitdqrk.unlegitlibrary.utils.DefaultMethodsOverrider;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.site.Classic_SiteType;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Utility class for domain-related operations in the Classic protocol.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
class Classic_DomainUtils extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Extracts the top-level domain (TLD) from a given URL.
|
||||
* @param url The URL from which to extract the TLD.
|
||||
* @return The top-level domain as a string.
|
||||
* @throws MalformedURLException If the URL is malformed.
|
||||
*/
|
||||
public static String getTopLevelDomain(String url) throws MalformedURLException {
|
||||
URL uri = null;
|
||||
String tldString = null;
|
||||
@@ -33,6 +44,13 @@ class Classic_DomainUtils extends DefaultMethodsOverrider {
|
||||
return tldString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the domain name (excluding the TLD) from a given URL.
|
||||
* @param url The URL from which to extract the domain name.
|
||||
* @return The domain name as a string.
|
||||
* @throws URISyntaxException If the URL syntax is incorrect.
|
||||
* @throws MalformedURLException If the URL is malformed.
|
||||
*/
|
||||
public static String getDomainName(String url) throws URISyntaxException, MalformedURLException {
|
||||
if (url.startsWith(Classic_SiteType.PUBLIC.name + "://"))
|
||||
url = url.substring((Classic_SiteType.PUBLIC.name + "://").length());
|
||||
@@ -48,11 +66,14 @@ class Classic_DomainUtils extends DefaultMethodsOverrider {
|
||||
if (!url.startsWith("https://") && !url.startsWith("http://")) url = "https://" + url;
|
||||
|
||||
URI uri = new URI(url);
|
||||
String domain = uri.getHost().replace("." + getTopLevelDomain(url), "");
|
||||
return domain;
|
||||
return uri.getHost().replace("." + getTopLevelDomain(url), "");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extracts the path component from a given URL.
|
||||
* @param url The URL from which to extract the path.
|
||||
* @return The path as a string.
|
||||
*/
|
||||
public static String getPath(String url) {
|
||||
if (!url.startsWith(Classic_SiteType.PUBLIC.name + "://") && !url.startsWith(Classic_SiteType.CLIENT.name + "://") &&
|
||||
!url.startsWith(Classic_SiteType.SERVER.name + "://") && !url.startsWith(Classic_SiteType.PROTOCOL.name + "://") &&
|
||||
@@ -1,7 +1,11 @@
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic;
|
||||
package org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Enum representing the protocol versions for the Classic protocol.
|
||||
*/
|
||||
@Deprecated(forRemoval = false, since = "1.0.0-BETA.3")
|
||||
public enum Classic_ProtocolVersion implements Serializable {
|
||||
PV_1_0_0("1.0.0");
|
||||
public final String version;
|
||||
Reference in New Issue
Block a user