Reformatted code using IntelliJ
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.openautonomousconnection</groupId>
|
||||
<artifactId>protocol</artifactId>
|
||||
<version>1.0.0-BETA.4</version>
|
||||
<version>1.0.0-BETA.5</version>
|
||||
<organization>
|
||||
<name>Open Autonomous Connection</name>
|
||||
<url>https://open-autonomous-connection.org/</url>
|
||||
|
@@ -24,7 +24,6 @@ import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Class
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/**
|
||||
* The main bridge class for the protocol connection.
|
||||
@@ -97,6 +96,7 @@ public final class ProtocolBridge {
|
||||
|
||||
/**
|
||||
* Initialize the ProtocolBridge instance for the DNS server side
|
||||
*
|
||||
* @param protocolDNSServer The ProtocolDNSServer instance
|
||||
* @param protocolSettings The ProtocolSettings instance
|
||||
* @param protocolVersion The ProtocolVersion instance
|
||||
@@ -124,6 +124,7 @@ public final class ProtocolBridge {
|
||||
|
||||
/**
|
||||
* Initialize the ProtocolBridge instance for the web server side
|
||||
*
|
||||
* @param protocolWebServer The ProtocolWebServer instance
|
||||
* @param protocolSettings The ProtocolSettings instance
|
||||
* @param protocolVersion The ProtocolVersion instance
|
||||
@@ -151,6 +152,7 @@ public final class ProtocolBridge {
|
||||
|
||||
/**
|
||||
* Initialize the ProtocolBridge instance for the client side
|
||||
*
|
||||
* @param protocolClient The ProtocolClient instance
|
||||
* @param protocolSettings The ProtocolSettings instance
|
||||
* @param protocolVersion The ProtocolVersion instance
|
||||
@@ -196,13 +198,17 @@ public final class ProtocolBridge {
|
||||
GetDestinationPacket v100bGetDestinationPacket = new GetDestinationPacket();
|
||||
|
||||
if (isPacketSupported(v100bAuthPath)) protocolSettings.packetHandler.registerPacket(v100bAuthPath);
|
||||
if (isPacketSupported(v100bUnsupportedClassicPacket)) protocolSettings.packetHandler.registerPacket(v100bUnsupportedClassicPacket);
|
||||
if (isPacketSupported(v100bValidateDomainPacket)) protocolSettings.packetHandler.registerPacket(v100bValidateDomainPacket);
|
||||
if (isPacketSupported(v100bGetDestinationPacket)) protocolSettings.packetHandler.registerPacket(v100bGetDestinationPacket);
|
||||
if (isPacketSupported(v100bUnsupportedClassicPacket))
|
||||
protocolSettings.packetHandler.registerPacket(v100bUnsupportedClassicPacket);
|
||||
if (isPacketSupported(v100bValidateDomainPacket))
|
||||
protocolSettings.packetHandler.registerPacket(v100bValidateDomainPacket);
|
||||
if (isPacketSupported(v100bGetDestinationPacket))
|
||||
protocolSettings.packetHandler.registerPacket(v100bGetDestinationPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the appropriate listeners based on the current side
|
||||
*
|
||||
* @throws Exception if an error occurs while registering the listeners
|
||||
*/
|
||||
private void registerListeners() throws Exception {
|
||||
@@ -234,6 +240,7 @@ public final class ProtocolBridge {
|
||||
|
||||
/**
|
||||
* Initialize the logger instance
|
||||
*
|
||||
* @param logFolder The folder to store the log files
|
||||
*/
|
||||
private void initializeLogger(File logFolder) {
|
||||
@@ -268,9 +275,10 @@ public final class ProtocolBridge {
|
||||
|
||||
/**
|
||||
* Check if the classic protocol is supported by the current protocol version
|
||||
*
|
||||
* @return true if the classic protocol is supported, false otherwise
|
||||
*/
|
||||
public final boolean isClassicSupported() {
|
||||
public boolean isClassicSupported() {
|
||||
boolean yes = false;
|
||||
for (ProtocolVersion compatibleVersion : protocolVersion.getCompatibleVersions()) {
|
||||
// Check if the compatible version is classic
|
||||
@@ -284,10 +292,11 @@ public final class ProtocolBridge {
|
||||
|
||||
/**
|
||||
* Check if the target protocol is supported by the current protocol version
|
||||
*
|
||||
* @param protocol The target protocol to check
|
||||
* @return true If the target protocol is supported, false otherwise
|
||||
*/
|
||||
public final boolean isProtocolSupported(ProtocolVersion.Protocol protocol) {
|
||||
public boolean isProtocolSupported(ProtocolVersion.Protocol protocol) {
|
||||
boolean yes = false;
|
||||
for (ProtocolVersion compatibleVersion : protocolVersion.getCompatibleVersions()) {
|
||||
// Check if the compatible version supports the target protocol
|
||||
@@ -301,25 +310,28 @@ public final class ProtocolBridge {
|
||||
|
||||
/**
|
||||
* Check if the target packet is supported by the current protocol version
|
||||
*
|
||||
* @param packet The target packet to check
|
||||
* @return true if the target packet is supported, false otherwise
|
||||
*/
|
||||
public final boolean isPacketSupported(OACPacket packet) {
|
||||
public boolean isPacketSupported(OACPacket packet) {
|
||||
return isVersionSupported(packet.getProtocolVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the target protocol version is supported by the current protocol version
|
||||
*
|
||||
* @param targetVersion The target protocol version to check
|
||||
* @return true if the target protocol version is supported, false otherwise
|
||||
*/
|
||||
public final boolean isVersionSupported(ProtocolVersion targetVersion) {
|
||||
public boolean isVersionSupported(ProtocolVersion targetVersion) {
|
||||
// Check if the target protocol version is the same as the current protocol version or if it is in the list of compatible versions
|
||||
return protocolVersion == targetVersion || protocolVersion.getCompatibleVersions().contains(targetVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if the protocol version is valid for the current side
|
||||
*
|
||||
* @return true if the protocol version is valid for the current side, false otherwise
|
||||
*/
|
||||
private boolean validateProtocolSide() {
|
||||
@@ -342,25 +354,28 @@ public final class ProtocolBridge {
|
||||
|
||||
/**
|
||||
* Check if the current instance is running as a DNS server
|
||||
*
|
||||
* @return true if the current instance is running as a DNS server, false otherwise
|
||||
*/
|
||||
public final boolean isRunningAsDNSServer() {
|
||||
public boolean isRunningAsDNSServer() {
|
||||
return protocolDNSServer != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current instance is running as a client
|
||||
*
|
||||
* @return true if the current instance is running as a client, false otherwise
|
||||
*/
|
||||
public final boolean isRunningAsClient() {
|
||||
public boolean isRunningAsClient() {
|
||||
return protocolClient != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current instance is running as a web server
|
||||
*
|
||||
* @return true if the current instance is running as a web server, false otherwise
|
||||
*/
|
||||
public final boolean isRunningAsWebServer() {
|
||||
public boolean isRunningAsWebServer() {
|
||||
return protocolWebServer != null;
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ public @interface ProtocolInfo {
|
||||
/**
|
||||
* Specifies the side of the protocol that the annotated class or method is associated with.
|
||||
* Default is ALL, indicating that it can be used on any side.
|
||||
*
|
||||
* @return The protocol side.
|
||||
*/
|
||||
ProtocolVersion.ProtocolSide protocolSide() default ProtocolVersion.ProtocolSide.ALL;
|
||||
|
@@ -36,21 +36,16 @@ public class CallTracker<A extends Annotation> extends GenericReflectClass<A> {
|
||||
}
|
||||
|
||||
public abstract static class CallInterceptor {
|
||||
private static Set<CallInterceptor> interceptors = new HashSet<>();
|
||||
private static final Set<CallInterceptor> interceptors = new HashSet<>();
|
||||
|
||||
public CallInterceptor() {
|
||||
interceptors.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Code executed on any method call
|
||||
*/
|
||||
public abstract void onCall(Method method, @Nullable StackTraceElement callerMethod);
|
||||
|
||||
@Advice.OnMethodEnter
|
||||
static void intercept(@Advice.Origin Method method) {
|
||||
|
||||
for(CallInterceptor interceptor : interceptors) {
|
||||
for (CallInterceptor interceptor : interceptors) {
|
||||
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
|
||||
|
||||
if (stack.length <= 3)
|
||||
@@ -79,5 +74,10 @@ public class CallTracker<A extends Annotation> extends GenericReflectClass<A> {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Code executed on any method call
|
||||
*/
|
||||
public abstract void onCall(Method method, @Nullable StackTraceElement callerMethod);
|
||||
}
|
||||
}
|
||||
|
@@ -41,42 +41,41 @@ public class ProtocolInfoProcessing extends AnnotationProcessor<ProtocolInfo> {
|
||||
|
||||
Object o;
|
||||
|
||||
if((o = methodGetByName(callerMethod.getMethodName())) != null)
|
||||
if ((o = methodGetByName(callerMethod.getMethodName())) != null)
|
||||
callerSide = ((Method) o).getAnnotation(ProtocolInfo.class).protocolSide();
|
||||
else if((o = typeHasAnnotation(callerMethod.getClassName())) != null)
|
||||
else if ((o = typeHasAnnotation(callerMethod.getClassName())) != null)
|
||||
callerSide = ((Class<?>) o).getAnnotation(ProtocolInfo.class).protocolSide();
|
||||
else
|
||||
return;
|
||||
|
||||
|
||||
if(methodReferences.get().contains(method))
|
||||
if (methodReferences.get().contains(method))
|
||||
side = method.getAnnotation(ProtocolInfo.class).protocolSide();
|
||||
|
||||
else if(typeReferences.get().contains(method.getDeclaringClass()))
|
||||
else if (typeReferences.get().contains(method.getDeclaringClass()))
|
||||
side = method.getDeclaringClass().getAnnotation(ProtocolInfo.class).protocolSide();
|
||||
else
|
||||
return;
|
||||
|
||||
if(callerSide.equals(ProtocolVersion.ProtocolSide.CLIENT) &&
|
||||
if (callerSide.equals(ProtocolVersion.ProtocolSide.CLIENT) &&
|
||||
!side.equals(callerSide))
|
||||
throw new IncompatibleProtocolSideException(callerSide, side);
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Method methodGetByName(String methodName) {
|
||||
for(Method method : this.annotatedMethods)
|
||||
if(method.getName().equals(methodName))
|
||||
for (Method method : this.annotatedMethods)
|
||||
if (method.getName().equals(methodName))
|
||||
return method;
|
||||
return null;
|
||||
}
|
||||
|
||||
private Class<?> typeHasAnnotation(String typeName) {
|
||||
for(Class<?> type : this.annotatedTypes)
|
||||
if(type.getName().equals(typeName))
|
||||
for (Class<?> type : this.annotatedTypes)
|
||||
if (type.getName().equals(typeName))
|
||||
return type;
|
||||
return null;
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@ public final class ClientListener extends EventListener {
|
||||
/**
|
||||
* Handles the event when a client connects.
|
||||
* Sends an authentication packet to the server.
|
||||
*
|
||||
* @param event The client connected event.
|
||||
*/
|
||||
@Listener
|
||||
@@ -35,6 +36,7 @@ public final class ClientListener extends EventListener {
|
||||
/**
|
||||
* Handles the event when a client disconnects.
|
||||
* Notifies the protocol client of the disconnection.
|
||||
*
|
||||
* @param event The client disconnected event.
|
||||
*/
|
||||
@Listener
|
||||
|
@@ -18,6 +18,7 @@ public final class DNSServerListener extends EventListener {
|
||||
/**
|
||||
* Handles the event when a connection handler connects to the DNS server.
|
||||
* Adds the connected client to the ProtocolBridge's DNS server client list.
|
||||
*
|
||||
* @param event The connection handler connected event.
|
||||
*/
|
||||
@Listener
|
||||
@@ -28,6 +29,7 @@ public final class DNSServerListener extends EventListener {
|
||||
/**
|
||||
* Handles the event when a connection handler disconnects from the DNS server.
|
||||
* Removes the disconnected client from the ProtocolBridge's DNS server client list.
|
||||
*
|
||||
* @param event The connection handler disconnected event.
|
||||
*/
|
||||
@Listener
|
||||
|
@@ -18,6 +18,7 @@ public final class WebServerListener extends EventListener {
|
||||
/**
|
||||
* Handles the event when a connection is established.
|
||||
* Adds the connected client to the protocol web server's client list.
|
||||
*
|
||||
* @param event The connection handler connected event.
|
||||
*/
|
||||
@Listener
|
||||
@@ -28,6 +29,7 @@ public final class WebServerListener extends EventListener {
|
||||
/**
|
||||
* Handles the event when a connection is disconnected.
|
||||
* Removes the disconnected client from the protocol web server's client list.
|
||||
*
|
||||
* @param event The connection handler disconnected event.
|
||||
*/
|
||||
@Listener
|
||||
|
@@ -29,6 +29,7 @@ public abstract class OACPacket extends Packet {
|
||||
|
||||
/**
|
||||
* Constructor for OACPacket.
|
||||
*
|
||||
* @param id The unique identifier for the packet.
|
||||
* @param protocolVersion The protocol version associated with this packet.
|
||||
*/
|
||||
@@ -39,6 +40,7 @@ public abstract class OACPacket extends Packet {
|
||||
|
||||
/**
|
||||
* Gets the response code for the packet.
|
||||
*
|
||||
* @return The DNSResponseCode associated with the packet.
|
||||
*/
|
||||
protected final DNSResponseCode getResponseCode() {
|
||||
@@ -47,6 +49,7 @@ public abstract class OACPacket extends Packet {
|
||||
|
||||
/**
|
||||
* Sets the response code for the packet.
|
||||
*
|
||||
* @param responseCode The DNSResponseCode to set for the packet.
|
||||
*/
|
||||
protected final void setResponseCode(DNSResponseCode responseCode) {
|
||||
@@ -55,6 +58,7 @@ public abstract class OACPacket extends Packet {
|
||||
|
||||
/**
|
||||
* Writes the packet data to the output stream.
|
||||
*
|
||||
* @param packetHandler The packet handler managing the packet.
|
||||
* @param objectOutputStream The output stream to write the packet data to.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
@@ -75,7 +79,8 @@ public abstract class OACPacket extends Packet {
|
||||
onRead(packetHandler, objectInputStream);
|
||||
|
||||
// Read the response code if the protocol version is not classic
|
||||
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC) responseCode = (DNSResponseCode) objectInputStream.readObject();
|
||||
if (protocolVersion != ProtocolVersion.PV_1_0_0_CLASSIC)
|
||||
responseCode = (DNSResponseCode) objectInputStream.readObject();
|
||||
else responseCode = DNSResponseCode.RESPONSE_NOT_REQUIRED;
|
||||
|
||||
// Call the response code read handler
|
||||
@@ -84,6 +89,7 @@ public abstract class OACPacket extends Packet {
|
||||
|
||||
/**
|
||||
* Abstract method to be implemented by subclasses for writing specific packet data.
|
||||
*
|
||||
* @param packetHandler The packet handler managing the packet.
|
||||
* @param objectOutputStream The output stream to write the packet data to.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
@@ -93,6 +99,7 @@ public abstract class OACPacket extends Packet {
|
||||
|
||||
/**
|
||||
* Abstract method to be implemented by subclasses for reading specific packet data.
|
||||
*
|
||||
* @param packetHandler The packet handler managing the packet.
|
||||
* @param objectInputStream The input stream to read the packet data from.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
@@ -103,8 +110,10 @@ public abstract class OACPacket extends Packet {
|
||||
/**
|
||||
* Method called after the response code has been read from the input stream.
|
||||
* Subclasses can override this method to handle any additional logic based on the response code.
|
||||
*
|
||||
* @param packetHandler The packet handler managing the packet.
|
||||
* @param objectInputStream The input stream from which the response code was read.
|
||||
*/
|
||||
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {}
|
||||
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {
|
||||
}
|
||||
}
|
||||
|
@@ -5,10 +5,10 @@ import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket;
|
||||
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.events.Classic_DomainPacketReceivedEvent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
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.utils.Classic_ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
@@ -27,7 +27,8 @@ public final class Classic_MessagePacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer() || ProtocolBridge.getInstance().isRunningAsWebServer()) objectOutputStream.writeInt(clientID);
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer() || ProtocolBridge.getInstance().isRunningAsWebServer())
|
||||
objectOutputStream.writeInt(clientID);
|
||||
else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID();
|
||||
objectOutputStream.writeInt(clientID);
|
||||
|
@@ -6,10 +6,10 @@ import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.objects.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.events.Classic_PingPacketReceivedEvent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
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.utils.Classic_ProtocolVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
|
@@ -52,6 +52,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Initializes the ProtocolClient, setting up certificate folders and the DNS client connection.
|
||||
*
|
||||
* @throws CertificateException if there are issues with the certificates.
|
||||
* @throws IOException if there are I/O issues during initialization.
|
||||
*/
|
||||
@@ -69,6 +70,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Gets the DNS connection client.
|
||||
*
|
||||
* @return the NetworkClient handling the DNS connection.
|
||||
*/
|
||||
public final NetworkClient getClientDNSConnection() {
|
||||
@@ -77,6 +79,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Creates a web connection to the specified domain and ports.
|
||||
*
|
||||
* @param domain the target domain for the web connection.
|
||||
* @param pipelinePort the port used for the pipeline connection.
|
||||
* @param webPort the port used for the web connection.
|
||||
@@ -103,6 +106,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the required certificate files exist in the specified folder.
|
||||
*
|
||||
* @param folder the folder to check for certificate files.
|
||||
* @param prefix the prefix of the certificate files.
|
||||
* @param extension the extension of the certificate files.
|
||||
@@ -136,6 +140,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Gets the protocol version of the connected server.
|
||||
*
|
||||
* @return the ProtocolVersion of the server, or PV_1_0_0_CLASSIC if not set.
|
||||
*/
|
||||
public final ProtocolVersion getServerVersion() {
|
||||
@@ -144,6 +149,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Sets the protocol version of the connected server.
|
||||
*
|
||||
* @param serverVersion the ProtocolVersion to set for the server.
|
||||
*/
|
||||
public final void setServerVersion(ProtocolVersion serverVersion) {
|
||||
@@ -152,6 +158,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Handles DNS disconnection events, resetting the server version and closing the web client connection if necessary.
|
||||
*
|
||||
* @param event the ClientDisconnectedEvent triggered on DNS disconnection.
|
||||
*/
|
||||
public final void onDNSDisconnect(ClientDisconnectedEvent event) {
|
||||
@@ -170,6 +177,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the connected server is a stable server.
|
||||
*
|
||||
* @return true if the server is stable, false otherwise.
|
||||
*/
|
||||
public final boolean isStableServer() {
|
||||
@@ -179,6 +187,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the connected server or its compatible versions support stable protocol.
|
||||
*
|
||||
* @return true if stable protocol is supported, false otherwise.
|
||||
*/
|
||||
public final boolean supportServerStable() {
|
||||
@@ -195,6 +204,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the connected server is a beta server.
|
||||
*
|
||||
* @return true if the server is beta, false otherwise.
|
||||
*/
|
||||
public final boolean isBetaServer() {
|
||||
@@ -204,6 +214,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the connected server or its compatible versions support beta protocol.
|
||||
*
|
||||
* @return true if beta protocol is supported, false otherwise.
|
||||
*/
|
||||
public final boolean supportServerBeta() {
|
||||
@@ -220,6 +231,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the connected server is a classic server.
|
||||
*
|
||||
* @return true if the server is classic, false otherwise.
|
||||
*/
|
||||
public final boolean isClassicServer() {
|
||||
@@ -229,6 +241,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the connected server or its compatible versions support classic protocol.
|
||||
*
|
||||
* @return true if classic protocol is supported, false otherwise.
|
||||
*/
|
||||
public final boolean supportServerClassic() {
|
||||
@@ -245,6 +258,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the connected server supports the protocol version of the given packet.
|
||||
*
|
||||
* @param packet the OACPacket to check against the server's supported protocol version.
|
||||
* @return true if the server supports the packet's protocol version, false otherwise.
|
||||
*/
|
||||
@@ -255,6 +269,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the connected server or its compatible versions support the specified protocol version.
|
||||
*
|
||||
* @param targetVersion the ProtocolVersion to check for support.
|
||||
* @return true if the server or its compatible versions support the target version, false otherwise.
|
||||
*/
|
||||
@@ -265,6 +280,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the connected server or its compatible versions support the specified protocol.
|
||||
*
|
||||
* @param protocol the Protocol to check for support.
|
||||
* @return true if the server or its compatible versions support the protocol, false otherwise.
|
||||
*/
|
||||
@@ -282,6 +298,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Validates the specified domain by sending a validation request to the DNS server.
|
||||
*
|
||||
* @param domain the Domain to validate.
|
||||
* @throws IOException if there are I/O issues during the validation process.
|
||||
* @throws ClassNotFoundException if there are issues with class loading during packet handling.
|
||||
@@ -297,6 +314,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Requests the destination for the specified domain from the DNS server.
|
||||
*
|
||||
* @param domain the Domain for which to request the destination.
|
||||
* @param responseCode the expected DNSResponseCode for the request.
|
||||
* @throws IOException if there are I/O issues during the request process.
|
||||
@@ -313,6 +331,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Callback method invoked when domain validation is completed.
|
||||
*
|
||||
* @param domain the Domain that was validated.
|
||||
* @param responseCode the DNSResponseCode resulting from the validation.
|
||||
*/
|
||||
@@ -320,6 +339,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Callback method invoked when the destination retrieval is completed.
|
||||
*
|
||||
* @param domain the Domain for which the destination was requested.
|
||||
* @param destination the retrieved destination as a string.
|
||||
* @param validationResponse the DNSResponseCode resulting from the destination retrieval.
|
||||
|
@@ -42,13 +42,9 @@ public final class WebClient {
|
||||
*/
|
||||
private ObjectInputStream inputStream;
|
||||
|
||||
/**
|
||||
* Thread for receiving data from the web server.
|
||||
*/
|
||||
private final Thread receiveThread = new Thread(this::receive);
|
||||
|
||||
/**
|
||||
* Constructs a WebClient instance and establishes a secure connection to the web server.
|
||||
*
|
||||
* @param domain The domain information for the web server.
|
||||
* @param pipelinePort The port for the pipeline connection.
|
||||
* @param webPort The port for the web server connection.
|
||||
@@ -139,10 +135,14 @@ public final class WebClient {
|
||||
// Start the receive thread
|
||||
this.receiveThread.start();
|
||||
}
|
||||
}
|
||||
} /**
|
||||
* Thread for receiving data from the web server.
|
||||
*/
|
||||
private final Thread receiveThread = new Thread(this::receive);
|
||||
|
||||
/**
|
||||
* Gets the NetworkClient used for the pipeline connection to the web server.
|
||||
*
|
||||
* @return The NetworkClient connected to the web server pipeline.
|
||||
*/
|
||||
public NetworkClient getClientPipelineConnection() {
|
||||
@@ -151,6 +151,7 @@ public final class WebClient {
|
||||
|
||||
/**
|
||||
* Gets the SSLSocket used for communication with the web server.
|
||||
*
|
||||
* @return The SSLSocket connected to the web server.
|
||||
*/
|
||||
public SSLSocket getClientWebConnection() {
|
||||
@@ -159,6 +160,7 @@ public final class WebClient {
|
||||
|
||||
/**
|
||||
* Checks if the WebClient is currently connected to the web server.
|
||||
*
|
||||
* @return true if connected, false otherwise.
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
@@ -188,6 +190,7 @@ public final class WebClient {
|
||||
|
||||
/**
|
||||
* Closes the connection to the web server and releases resources.
|
||||
*
|
||||
* @return true if the connection was successfully closed, false if it was already closed.
|
||||
* @throws IOException If an I/O error occurs during closure.
|
||||
*/
|
||||
@@ -225,4 +228,6 @@ public final class WebClient {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -30,6 +30,7 @@ public final class ConnectedProtocolClient {
|
||||
/**
|
||||
* Gets the protocol version of the connected client.
|
||||
* Defaults to PV_1_0_0_CLASSIC if not set.
|
||||
*
|
||||
* @return The protocol version of the client.
|
||||
*/
|
||||
public ProtocolVersion getClientVersion() {
|
||||
@@ -38,6 +39,7 @@ public final class ConnectedProtocolClient {
|
||||
|
||||
/**
|
||||
* Sets the protocol version of the connected client.
|
||||
*
|
||||
* @param clientVersion The protocol version to set.
|
||||
*/
|
||||
public void setClientVersion(ProtocolVersion clientVersion) {
|
||||
@@ -46,6 +48,7 @@ public final class ConnectedProtocolClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client is a stable client.
|
||||
*
|
||||
* @return True if the client is stable, false otherwise.
|
||||
*/
|
||||
public boolean isStableClient() {
|
||||
@@ -55,6 +58,7 @@ public final class ConnectedProtocolClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports stable protocol versions.
|
||||
*
|
||||
* @return True if the client supports stable versions, false otherwise.
|
||||
*/
|
||||
public boolean supportClientStable() {
|
||||
@@ -71,6 +75,7 @@ public final class ConnectedProtocolClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client is a beta client.
|
||||
*
|
||||
* @return True if the client is beta, false otherwise.
|
||||
*/
|
||||
public boolean isBetaClient() {
|
||||
@@ -80,6 +85,7 @@ public final class ConnectedProtocolClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports beta protocol versions.
|
||||
*
|
||||
* @return True if the client supports beta versions, false otherwise.
|
||||
*/
|
||||
public boolean supportClientBeta() {
|
||||
@@ -96,6 +102,7 @@ public final class ConnectedProtocolClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client is a classic client.
|
||||
*
|
||||
* @return True if the client is classic, false otherwise.
|
||||
*/
|
||||
public boolean isClassicClient() {
|
||||
@@ -106,6 +113,7 @@ public final class ConnectedProtocolClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports classic protocol versions.
|
||||
*
|
||||
* @return True if the client supports classic versions, false otherwise.
|
||||
*/
|
||||
public boolean supportClientClassic() {
|
||||
@@ -122,6 +130,7 @@ public final class ConnectedProtocolClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports the given packet's protocol version.
|
||||
*
|
||||
* @param packet The packet to check.
|
||||
* @return True if the client supports the packet's protocol version, false otherwise.
|
||||
*/
|
||||
@@ -131,6 +140,7 @@ public final class ConnectedProtocolClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports the given protocol version.
|
||||
*
|
||||
* @param targetVersion The protocol version to check.
|
||||
* @return True if the client supports the target version, false otherwise.
|
||||
*/
|
||||
@@ -141,6 +151,7 @@ public final class ConnectedProtocolClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports the given protocol.
|
||||
*
|
||||
* @param protocol The protocol to check.
|
||||
* @return True if the client supports the protocol, false otherwise.
|
||||
*/
|
||||
|
@@ -104,6 +104,7 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Checks if the required certificate files exist in the specified folder.
|
||||
*
|
||||
* @param folder The folder to check for certificate files.
|
||||
* @param prefix The prefix of the certificate files.
|
||||
* @param extension The extension of the certificate files.
|
||||
@@ -138,6 +139,7 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Retrieves a connected protocol client by its client ID.
|
||||
*
|
||||
* @param clientID The ID of the client to retrieve.
|
||||
* @return The ConnectedProtocolClient with the specified ID, or null if not found.
|
||||
*/
|
||||
@@ -149,6 +151,7 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Gets the DNS information site URL from the configuration.
|
||||
*
|
||||
* @return The DNS information site URL.
|
||||
*/
|
||||
public final String getDNSInfoSite() {
|
||||
@@ -157,6 +160,7 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Gets the DNS registration site URL from the configuration.
|
||||
*
|
||||
* @return The DNS registration site URL.
|
||||
*/
|
||||
public final String getDNSRegisterSite() {
|
||||
@@ -165,37 +169,39 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Abstract method to retrieve the list of domains managed by the DNS server.
|
||||
*
|
||||
* @return A list of Domain objects.
|
||||
*/
|
||||
public abstract List<Domain> getDomains();
|
||||
|
||||
/**
|
||||
* @see Domain#getDestination()
|
||||
* Abstract method to get the destination for a given domain.
|
||||
* @param domain The domain to look up.
|
||||
* @return The destination associated with the domain.
|
||||
* @see Domain#getDestination()
|
||||
* Abstract method to get the destination for a given domain.
|
||||
*/
|
||||
public abstract String getDomainDestination(Domain domain);
|
||||
|
||||
/**
|
||||
* @see Domain#getDestination()
|
||||
* Abstract method to get the destination for a given subname under a specific domain.
|
||||
* @param domain The parent domain.
|
||||
* @param subname The subname to look up.
|
||||
* @return The destination associated with the subname.
|
||||
* @see Domain#getDestination()
|
||||
* Abstract method to get the destination for a given subname under a specific domain.
|
||||
*/
|
||||
public abstract String getSubnameDestination(Domain domain, String subname);
|
||||
|
||||
/**
|
||||
* @see Domain#getDestination()
|
||||
* Abstract method to get the top-level domain information site URL.
|
||||
* @param topLevelName The top-level domain name.
|
||||
* @return The information site URL for the specified top-level domain.
|
||||
* @see Domain#getDestination()
|
||||
* Abstract method to get the top-level domain information site URL.
|
||||
*/
|
||||
public abstract String getTLNInfoSite(String topLevelName);
|
||||
|
||||
/**
|
||||
* Abstract method to validate a requested domain.
|
||||
*
|
||||
* @param requestedDomain The domain to validate.
|
||||
* @return A DNSResponseCode indicating the result of the validation.
|
||||
*/
|
||||
@@ -203,6 +209,7 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Abstract method called when a validation packet fails to send.
|
||||
*
|
||||
* @param domain The domain associated with the validation.
|
||||
* @param client The connected protocol client.
|
||||
* @param exception The exception that occurred during sending.
|
||||
@@ -211,6 +218,7 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Abstract method called when a domain destination packet fails to send.
|
||||
*
|
||||
* @param client The connected protocol client.
|
||||
* @param domain The domain associated with the packet.
|
||||
* @param validationResponse The DNS response code from validation.
|
||||
@@ -234,6 +242,7 @@ public abstract class ProtocolDNSServer extends DefaultMethodsOverrider {
|
||||
public final File publicServerFolder;
|
||||
public final String caPrefix = "ca_dns_";
|
||||
public final String certPrefix = "cert_dns_";
|
||||
|
||||
public ServerCertificateFolderStructure() {
|
||||
certificatesFolder = new File("certificates");
|
||||
|
||||
|
@@ -51,20 +51,18 @@ public final class ConnectedWebClient {
|
||||
* The protocol version of the connected client.
|
||||
*/
|
||||
private ProtocolVersion clientVersion = null;
|
||||
|
||||
/**
|
||||
* Indicates if the client version has been loaded.
|
||||
*/
|
||||
@Getter
|
||||
private boolean clientVersionLoaded = false; /**
|
||||
* Thread for receiving data from the client.
|
||||
*/
|
||||
private final Thread receiveThread = new Thread(this::receive);
|
||||
|
||||
/**
|
||||
* Indicates if the client version has been loaded.
|
||||
*/
|
||||
@Getter
|
||||
private boolean clientVersionLoaded = false;
|
||||
|
||||
/**
|
||||
* Constructs a ConnectedWebClient with the given connection handler.
|
||||
*
|
||||
* @param pipelineConnection The connection handler for the web client.
|
||||
*/
|
||||
public ConnectedWebClient(ConnectionHandler pipelineConnection) {
|
||||
@@ -73,6 +71,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Sends an HTTP redirect response to the client.
|
||||
*
|
||||
* @param out The output stream to send the response to.
|
||||
* @param location The URL to redirect to.
|
||||
* @param cookies Optional cookies to set in the response.
|
||||
@@ -97,6 +96,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Parses POST parameters from the input stream.
|
||||
*
|
||||
* @param in The input stream to read from.
|
||||
* @return A map of POST parameter names to values.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
@@ -124,6 +124,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Normalizes a file path to prevent directory traversal attacks.
|
||||
*
|
||||
* @param path The raw file path.
|
||||
* @return The normalized file path.
|
||||
*/
|
||||
@@ -141,6 +142,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Parses query parameters from a raw URL path.
|
||||
*
|
||||
* @param rawPath The raw URL path containing query parameters.
|
||||
* @return A map of query parameter names to values.
|
||||
*/
|
||||
@@ -161,6 +163,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the request is a multipart/form-data request.
|
||||
*
|
||||
* @param headers The HTTP headers of the request.
|
||||
* @return True if the request is multipart/form-data, false otherwise.
|
||||
*/
|
||||
@@ -171,6 +174,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Handles a multipart/form-data request, saving uploaded files to the specified directory.
|
||||
*
|
||||
* @param in The input stream to read the request body from.
|
||||
* @param headers The HTTP headers of the request.
|
||||
* @param uploadDir The directory to save uploaded files to.
|
||||
@@ -232,6 +236,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Sends an response to the client.
|
||||
*
|
||||
* @param out
|
||||
* @param code
|
||||
* @param file
|
||||
@@ -245,6 +250,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Sends an response to the client.
|
||||
*
|
||||
* @param out The output stream to send the response to.
|
||||
* @param code The HTTP status code.
|
||||
* @param file The file to read the response body from.
|
||||
@@ -256,6 +262,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Sends an response to the client.
|
||||
*
|
||||
* @param out The output stream to send the response to.
|
||||
* @param code The HTTP status code.
|
||||
* @param body The response body as a string.
|
||||
@@ -268,6 +275,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Sends an response to the client.
|
||||
*
|
||||
* @param out The output stream to send the response to.
|
||||
* @param code The HTTP status code.
|
||||
* @param file The file to read the response body from.
|
||||
@@ -281,6 +289,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Sends an response to the client.
|
||||
*
|
||||
* @param out The output stream to send the response to.
|
||||
* @param code The HTTP status code.
|
||||
* @param body The response body as a byte array.
|
||||
@@ -310,6 +319,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Returns the standard status text for a given status code.
|
||||
*
|
||||
* @param code The status code.
|
||||
* @return The corresponding status text.
|
||||
*/
|
||||
@@ -329,6 +339,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Returns the content type based on the file extension.
|
||||
*
|
||||
* @param name The file name.
|
||||
* @return The corresponding content type.
|
||||
*/
|
||||
@@ -350,6 +361,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Renders a PHP file by executing it with the PHP interpreter and captures cookies.
|
||||
*
|
||||
* @param file The PHP file to render.
|
||||
* @return A PHPResponse containing the output and cookies.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
@@ -402,6 +414,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Sets the SSL socket for the web client and starts the receive thread.
|
||||
*
|
||||
* @param webSocket The SSL socket to set.
|
||||
*/
|
||||
public void setWebSocket(SSLSocket webSocket) {
|
||||
@@ -411,6 +424,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the web client is currently connected.
|
||||
*
|
||||
* @return True if connected, false otherwise.
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
@@ -419,6 +433,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Disconnects the web client, closing streams and the socket.
|
||||
*
|
||||
* @return True if disconnection was successful, false if already disconnected.
|
||||
*/
|
||||
public synchronized boolean disconnect() {
|
||||
@@ -452,6 +467,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Gets the protocol version of the connected client.
|
||||
*
|
||||
* @return The protocol version of the client, defaults to PV_1_0_0_CLASSIC if not set.
|
||||
*/
|
||||
public ProtocolVersion getClientVersion() {
|
||||
@@ -460,6 +476,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Sets the protocol version of the connected client.
|
||||
*
|
||||
* @param clientVersion The protocol version to set.
|
||||
*/
|
||||
public void setClientVersion(ProtocolVersion clientVersion) {
|
||||
@@ -469,6 +486,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client is a stable client.
|
||||
*
|
||||
* @return True if the client is stable, false otherwise.
|
||||
*/
|
||||
public boolean isStableClient() {
|
||||
@@ -478,6 +496,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports stable protocol versions.
|
||||
*
|
||||
* @return True if the client supports stable versions, false otherwise.
|
||||
*/
|
||||
public boolean supportClientStable() {
|
||||
@@ -494,6 +513,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client is a beta client.
|
||||
*
|
||||
* @return True if the client is beta, false otherwise.
|
||||
*/
|
||||
public boolean isBetaClient() {
|
||||
@@ -503,6 +523,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports beta protocol versions.
|
||||
*
|
||||
* @return True if the client supports beta versions, false otherwise.
|
||||
*/
|
||||
public boolean supportClientBeta() {
|
||||
@@ -519,6 +540,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client is a classic client.
|
||||
*
|
||||
* @return True if the client is classic, false otherwise.
|
||||
*/
|
||||
public boolean isClassicClient() {
|
||||
@@ -527,6 +549,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports classic protocol versions.
|
||||
*
|
||||
* @return True if the client supports classic versions, false otherwise.
|
||||
*/
|
||||
public boolean supportClientClassic() {
|
||||
@@ -543,6 +566,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports the protocol version of the given packet.
|
||||
*
|
||||
* @param packet The packet to check support for.
|
||||
* @return True if the client supports the packet's protocol version, false otherwise.
|
||||
*/
|
||||
@@ -552,6 +576,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports the given protocol version.
|
||||
*
|
||||
* @param targetVersion The protocol version to check support for.
|
||||
* @return True if the client supports the target version, false otherwise.
|
||||
*/
|
||||
@@ -562,6 +587,7 @@ public final class ConnectedWebClient {
|
||||
|
||||
/**
|
||||
* Checks if the connected client supports the given protocol.
|
||||
*
|
||||
* @param protocol The protocol to check support for.
|
||||
* @return True if the client supports the protocol, false otherwise.
|
||||
*/
|
||||
@@ -689,4 +715,6 @@ public final class ConnectedWebClient {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -58,31 +58,25 @@ public final class ProtocolWebServer {
|
||||
* Certificate files for SSL.
|
||||
*/
|
||||
private final File keyFile;
|
||||
|
||||
|
||||
/**
|
||||
* The configuration file for the web server.
|
||||
*/
|
||||
private final File configFile;
|
||||
/**
|
||||
* The network server handling pipeline connections.
|
||||
*/
|
||||
@Getter
|
||||
private NetworkServer pipelineServer;
|
||||
|
||||
/**
|
||||
* The SSL server socket for web connections.
|
||||
*/
|
||||
@Getter
|
||||
private SSLServerSocket webServer;
|
||||
|
||||
/**
|
||||
* List of connected web clients.
|
||||
*/
|
||||
@Getter
|
||||
private List<ConnectedWebClient> clients;
|
||||
|
||||
/**
|
||||
* The configuration file for the web server.
|
||||
*/
|
||||
private final File configFile;
|
||||
|
||||
/**
|
||||
* A unique secret for session management.
|
||||
*/
|
||||
@@ -91,6 +85,7 @@ public final class ProtocolWebServer {
|
||||
|
||||
/**
|
||||
* Initializes the web server with the given configuration, authentication, and rules files.
|
||||
*
|
||||
* @param configFile The configuration file.
|
||||
* @param authFile The authentication file.
|
||||
* @param rulesFile The rules file.
|
||||
@@ -172,10 +167,11 @@ public final class ProtocolWebServer {
|
||||
|
||||
/**
|
||||
* Retrieves a connected web client by its client ID.
|
||||
*
|
||||
* @param clientID The client ID to search for.
|
||||
* @return The connected web client with the specified ID, or null if not found.
|
||||
*/
|
||||
public final ConnectedWebClient getClientByID(int clientID) {
|
||||
public ConnectedWebClient getClientByID(int clientID) {
|
||||
for (ConnectedWebClient client : clients)
|
||||
if (client.getPipelineConnection().getClientID() == clientID) return client;
|
||||
return null;
|
||||
@@ -183,9 +179,10 @@ public final class ProtocolWebServer {
|
||||
|
||||
/**
|
||||
* Starts the web server to accept and handle client connections.
|
||||
*
|
||||
* @throws Exception If an error occurs while starting the server.
|
||||
*/
|
||||
public final void startWebServer() throws Exception {
|
||||
public void startWebServer() throws Exception {
|
||||
// Start the pipeline server
|
||||
pipelineServer.start();
|
||||
|
||||
@@ -215,7 +212,8 @@ public final class ProtocolWebServer {
|
||||
try {
|
||||
// Sleep for a while before checking again
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ignored) {}
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
@@ -241,6 +239,7 @@ public final class ProtocolWebServer {
|
||||
|
||||
/**
|
||||
* Handles the shutdown of the web server when the pipeline server stops.
|
||||
*
|
||||
* @throws IOException If an I/O error occurs while closing the web server.
|
||||
*/
|
||||
private void onPipelineStop() throws IOException {
|
||||
@@ -249,6 +248,7 @@ public final class ProtocolWebServer {
|
||||
|
||||
/**
|
||||
* Checks if the required certificate files exist in the specified folder.
|
||||
*
|
||||
* @param folder The folder to check for certificate files.
|
||||
* @param prefix The prefix of the certificate files.
|
||||
* @param extension The extension of the certificate files.
|
||||
@@ -281,15 +281,17 @@ public final class ProtocolWebServer {
|
||||
|
||||
/**
|
||||
* Retrieves the configuration manager for the web server.
|
||||
*
|
||||
* @return The configuration manager.
|
||||
* @throws IOException If an I/O error occurs while loading or saving the configuration.
|
||||
*/
|
||||
public final ConfigurationManager getConfigurationManager() throws IOException {
|
||||
public ConfigurationManager getConfigurationManager() throws IOException {
|
||||
return getConfigurationManager(configFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and initializes the configuration manager with default settings if necessary.
|
||||
*
|
||||
* @param configFile The configuration file to load.
|
||||
* @return The initialized configuration manager.
|
||||
* @throws IOException If an I/O error occurs while loading or saving the configuration.
|
||||
@@ -339,6 +341,7 @@ public final class ProtocolWebServer {
|
||||
public final File publicServerFolder;
|
||||
public final String caPrefix = "ca_server_";
|
||||
public final String certPrefix = "cert_server_";
|
||||
|
||||
public ServerCertificateFolderStructure() {
|
||||
certificatesFolder = new File("certificates");
|
||||
|
||||
|
@@ -27,6 +27,7 @@ public final class AuthManager {
|
||||
* Loads the authentication file and populates the users map.
|
||||
* The file should contain lines in the format: username:hashed_password
|
||||
* Lines starting with '#' are treated as comments and ignored.
|
||||
*
|
||||
* @param authFile The authentication file to load.
|
||||
* @throws IOException If an I/O error occurs reading from the file.
|
||||
*/
|
||||
@@ -48,6 +49,7 @@ public final class AuthManager {
|
||||
|
||||
/**
|
||||
* Checks if the provided login and password are valid.
|
||||
*
|
||||
* @param login The username to check.
|
||||
* @param password The password to verify.
|
||||
* @return True if the credentials are valid, false otherwise.
|
||||
@@ -64,6 +66,7 @@ public final class AuthManager {
|
||||
|
||||
/**
|
||||
* Computes the SHA-256 hash of the given input string.
|
||||
*
|
||||
* @param input The input string to hash.
|
||||
* @return The hexadecimal representation of the SHA-256 hash.
|
||||
*/
|
||||
|
@@ -39,13 +39,15 @@ public final class RuleManager {
|
||||
* "deny": ["pattern1", "pattern2", ...],
|
||||
* "auth": ["pattern1", "pattern2", ...]
|
||||
* }
|
||||
*
|
||||
* @param rulesFile The JSON file containing the rules.
|
||||
* @throws Exception If an error occurs reading the file or parsing JSON.
|
||||
*/
|
||||
public static void loadRules(File rulesFile) throws Exception {
|
||||
// Load and parse the JSON file
|
||||
String json = new String(Files.readAllBytes(rulesFile.toPath()));
|
||||
Map<String, List<String>> map = new Gson().fromJson(json, new TypeToken<Map<String, List<String>>>() {}.getType());
|
||||
Map<String, List<String>> map = new Gson().fromJson(json, new TypeToken<Map<String, List<String>>>() {
|
||||
}.getType());
|
||||
|
||||
// Default to empty lists if keys are missing
|
||||
allow = map.getOrDefault("allow", List.of());
|
||||
@@ -53,7 +55,9 @@ public final class RuleManager {
|
||||
auth = map.getOrDefault("auth", List.of());
|
||||
}
|
||||
|
||||
/** Checks if the given path is allowed based on the allow rules.
|
||||
/**
|
||||
* Checks if the given path is allowed based on the allow rules.
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @return True if the path is allowed, false otherwise.
|
||||
*/
|
||||
@@ -61,7 +65,9 @@ public final class RuleManager {
|
||||
return allow.stream().anyMatch(p -> pathMatches(path, p));
|
||||
}
|
||||
|
||||
/** Checks if the given path is denied based on the deny rules.
|
||||
/**
|
||||
* Checks if the given path is denied based on the deny rules.
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @return True if the path is denied, false otherwise.
|
||||
*/
|
||||
@@ -69,7 +75,9 @@ public final class RuleManager {
|
||||
return deny.stream().anyMatch(p -> pathMatches(path, p));
|
||||
}
|
||||
|
||||
/** Checks if the given path requires authentication based on the auth rules.
|
||||
/**
|
||||
* Checks if the given path requires authentication based on the auth rules.
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @return True if the path requires authentication, false otherwise.
|
||||
*/
|
||||
@@ -77,8 +85,10 @@ public final class RuleManager {
|
||||
return auth.stream().anyMatch(p -> pathMatches(path, p));
|
||||
}
|
||||
|
||||
/** Helper method to check if a path matches a pattern.
|
||||
/**
|
||||
* Helper method to check if a path matches a pattern.
|
||||
* Patterns can include '*' as a wildcard.
|
||||
*
|
||||
* @param path The path to check.
|
||||
* @param pattern The pattern to match against.
|
||||
* @return True if the path matches the pattern, false otherwise.
|
||||
|
@@ -30,6 +30,7 @@ public final class SessionManager {
|
||||
|
||||
/**
|
||||
* Creates a new session for the given user.
|
||||
*
|
||||
* @param login The username associated with the session.
|
||||
* @param ip The IP address of the client.
|
||||
* @param userAgent The User-Agent string of the client.
|
||||
@@ -51,6 +52,7 @@ public final class SessionManager {
|
||||
|
||||
/**
|
||||
* Validates a session ID against the provided IP and User-Agent.
|
||||
*
|
||||
* @param sessionId The session ID to validate.
|
||||
* @param ip The IP address of the client.
|
||||
* @param userAgent The User-Agent string of the client.
|
||||
@@ -74,6 +76,7 @@ public final class SessionManager {
|
||||
|
||||
/**
|
||||
* Invalidates a session, removing it from the active sessions.
|
||||
*
|
||||
* @param sessionId The session ID to invalidate.
|
||||
*/
|
||||
public static void invalidate(String sessionId) {
|
||||
@@ -82,6 +85,7 @@ public final class SessionManager {
|
||||
|
||||
/**
|
||||
* Retrieves the username associated with a valid session ID.
|
||||
*
|
||||
* @param sessionId The session ID to look up.
|
||||
* @return The username if the session is valid, null otherwise.
|
||||
*/
|
||||
@@ -127,6 +131,7 @@ public final class SessionManager {
|
||||
|
||||
/**
|
||||
* Checks if the session has expired.
|
||||
*
|
||||
* @return True if the session is expired, false otherwise.
|
||||
*/
|
||||
boolean isExpired() {
|
||||
@@ -135,6 +140,7 @@ public final class SessionManager {
|
||||
|
||||
/**
|
||||
* Checks if the session matches the given IP and User-Agent.
|
||||
*
|
||||
* @param ip The IP address to check.
|
||||
* @param userAgent The User-Agent string to check.
|
||||
* @return True if both match, false otherwise.
|
||||
@@ -145,6 +151,7 @@ public final class SessionManager {
|
||||
|
||||
/**
|
||||
* Refreshes the session's expiration time.
|
||||
*
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
void refresh() throws IOException {
|
||||
|
@@ -71,6 +71,7 @@ public enum ProtocolVersion implements Serializable {
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -89,6 +90,7 @@ public enum ProtocolVersion implements Serializable {
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
@@ -105,6 +107,7 @@ public enum ProtocolVersion implements Serializable {
|
||||
|
||||
/**
|
||||
* Returns the name of the protocol in uppercase.
|
||||
*
|
||||
* @return the name of the protocol in uppercase.
|
||||
*/
|
||||
@Override
|
||||
@@ -134,6 +137,7 @@ public enum ProtocolVersion implements Serializable {
|
||||
|
||||
/**
|
||||
* Returns the name of the protocol in uppercase.
|
||||
*
|
||||
* @return the name of the protocol in uppercase.
|
||||
*/
|
||||
@Override
|
||||
@@ -179,11 +183,11 @@ public enum ProtocolVersion implements Serializable {
|
||||
/**
|
||||
* All Sides
|
||||
*/
|
||||
ALL
|
||||
;
|
||||
ALL;
|
||||
|
||||
/**
|
||||
* Returns the name of the protocol in uppercase.
|
||||
*
|
||||
* @return the name of the protocol in uppercase.
|
||||
*/
|
||||
@Override
|
||||
|
@@ -75,6 +75,7 @@ public enum DNSResponseCode implements Serializable {
|
||||
|
||||
/**
|
||||
* Returns a string representation of the DNS response code, including its code and description.
|
||||
*
|
||||
* @return a string representation of the DNS response code.
|
||||
*/
|
||||
@Override
|
||||
|
@@ -110,19 +110,21 @@ public final class Domain implements Serializable {
|
||||
|
||||
/**
|
||||
* Checks if the domain has a subname.
|
||||
*
|
||||
* @return true if the domain has a subname, false otherwise.
|
||||
*/
|
||||
public final boolean hasSubname() {
|
||||
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 final boolean equals(Object obj) {
|
||||
public boolean equals(Object obj) {
|
||||
// Check if the object is an instance of Domain
|
||||
if (!(obj instanceof Domain domain)) return false;
|
||||
|
||||
@@ -134,10 +136,11 @@ public final class Domain implements Serializable {
|
||||
/**
|
||||
* 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() {
|
||||
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();
|
||||
|
@@ -1,14 +1,14 @@
|
||||
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;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -29,22 +29,22 @@ public final class Classic_DomainPacketReceivedEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Object clone() throws CloneNotSupportedException {
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object obj) {
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
@@ -2,12 +2,13 @@ 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;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -29,22 +30,22 @@ public final class Classic_PingPacketReceivedEvent extends Event {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Object clone() throws CloneNotSupportedException {
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object obj) {
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
@@ -4,8 +4,8 @@ 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 org.openautonomousconnection.protocol.versions.v1_0_0.classic.utils.Classic_ProtocolVersion;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
|
@@ -11,6 +11,7 @@ public final class ClassicConverter {
|
||||
|
||||
/**
|
||||
* Converts a Classic_Domain object to a Domain object.
|
||||
*
|
||||
* @param classicDomain the Classic_Domain object to convert
|
||||
* @return the converted Domain object
|
||||
*/
|
||||
@@ -21,6 +22,7 @@ public final class ClassicConverter {
|
||||
|
||||
/**
|
||||
* Converts a Domain object to a Classic_Domain object.
|
||||
*
|
||||
* @param newDomain the Domain object to convert
|
||||
* @return the converted Classic_Domain object
|
||||
*/
|
||||
@@ -31,6 +33,7 @@ public final class ClassicConverter {
|
||||
|
||||
/**
|
||||
* Converts a Classic_ProtocolVersion to a ProtocolVersion.
|
||||
*
|
||||
* @param classicProtocolVersion the Classic_ProtocolVersion to convert
|
||||
* @return the converted ProtocolVersion
|
||||
*/
|
||||
@@ -42,6 +45,7 @@ public final class ClassicConverter {
|
||||
|
||||
/**
|
||||
* Converts a ProtocolVersion to a Classic_ProtocolVersion.
|
||||
*
|
||||
* @param newProtocolVersion the ProtocolVersion to convert
|
||||
* @return the converted Classic_ProtocolVersion
|
||||
*/
|
||||
|
@@ -28,6 +28,7 @@ public final 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
|
||||
@@ -57,6 +58,7 @@ public final class Classic_ClientListener extends EventListener {
|
||||
* 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
|
||||
@@ -91,22 +93,22 @@ public final class Classic_ClientListener extends EventListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final Object clone() throws CloneNotSupportedException {
|
||||
protected Object clone() throws CloneNotSupportedException {
|
||||
return super.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean equals(Object obj) {
|
||||
public boolean equals(Object obj) {
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
}
|
@@ -16,6 +16,7 @@ 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.
|
||||
@@ -46,6 +47,7 @@ class Classic_DomainUtils extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -71,6 +73,7 @@ class Classic_DomainUtils extends DefaultMethodsOverrider {
|
||||
|
||||
/**
|
||||
* Extracts the path component from a given URL.
|
||||
*
|
||||
* @param url The URL from which to extract the path.
|
||||
* @return The path as a string.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user