Constructor fixes
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>org.openautonomousconnection</groupId>
|
<groupId>org.openautonomousconnection</groupId>
|
||||||
<artifactId>protocol</artifactId>
|
<artifactId>protocol</artifactId>
|
||||||
<version>1.0.0-BETA.13</version>
|
<version>1.0.0-BETA.14</version>
|
||||||
<organization>
|
<organization>
|
||||||
<name>Open Autonomous Connection</name>
|
<name>Open Autonomous Connection</name>
|
||||||
<url>https://open-autonomous-connection.org/</url>
|
<url>https://open-autonomous-connection.org/</url>
|
||||||
|
|||||||
@@ -108,6 +108,8 @@ public final class ProtocolBridge {
|
|||||||
*/
|
*/
|
||||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
|
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
|
||||||
public ProtocolBridge(ProtocolINSServer protocolINSServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
public ProtocolBridge(ProtocolINSServer protocolINSServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||||
|
protocolINSServer.attachBridge(this);
|
||||||
|
|
||||||
// Assign the parameters to the class fields
|
// Assign the parameters to the class fields
|
||||||
this.protocolINSServer = protocolINSServer;
|
this.protocolINSServer = protocolINSServer;
|
||||||
this.protocolSettings = protocolSettings;
|
this.protocolSettings = protocolSettings;
|
||||||
@@ -133,6 +135,8 @@ public final class ProtocolBridge {
|
|||||||
*/
|
*/
|
||||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
|
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
|
||||||
public ProtocolBridge(ProtocolWebServer protocolWebServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
public ProtocolBridge(ProtocolWebServer protocolWebServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||||
|
protocolWebServer.attachBridge(this);
|
||||||
|
|
||||||
// Assign the parameters to the class fields
|
// Assign the parameters to the class fields
|
||||||
this.protocolWebServer = protocolWebServer;
|
this.protocolWebServer = protocolWebServer;
|
||||||
this.protocolSettings = protocolSettings;
|
this.protocolSettings = protocolSettings;
|
||||||
@@ -158,6 +162,8 @@ public final class ProtocolBridge {
|
|||||||
*/
|
*/
|
||||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
|
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
|
||||||
public ProtocolBridge(ProtocolClient protocolClient, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
public ProtocolBridge(ProtocolClient protocolClient, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||||
|
protocolClient.attachBridge(this);
|
||||||
|
|
||||||
// Assign the parameters to the class fields
|
// Assign the parameters to the class fields
|
||||||
this.protocolClient = protocolClient;
|
this.protocolClient = protocolClient;
|
||||||
this.protocolSettings = protocolSettings;
|
this.protocolSettings = protocolSettings;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
|||||||
/**
|
/**
|
||||||
* Handles everything with INS-Connection.
|
* Handles everything with INS-Connection.
|
||||||
*/
|
*/
|
||||||
private final NetworkClient clientToINS;
|
private NetworkClient clientToINS;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the folder structure for client certificates.
|
* Manages the folder structure for client certificates.
|
||||||
@@ -39,7 +39,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
|||||||
* The reference to the ProtocolBridge Object
|
* The reference to the ProtocolBridge Object
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private final ProtocolBridge protocolBridge;
|
private ProtocolBridge protocolBridge;
|
||||||
/**
|
/**
|
||||||
* Stores the protocol version of the connected server.
|
* Stores the protocol version of the connected server.
|
||||||
*/
|
*/
|
||||||
@@ -47,17 +47,16 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the ProtocolClient, setting up certificate folders and the INS client connection.
|
* Initializes the ProtocolClient, setting up certificate folders and the INS client connection.
|
||||||
*
|
|
||||||
* @throws CertificateException if there are issues with the certificates.
|
|
||||||
* @throws IOException if there are I/O issues during initialization.
|
|
||||||
*/
|
*/
|
||||||
public ProtocolClient(ProtocolBridge protocolBridge) throws CertificateException, IOException {
|
public ProtocolClient() {
|
||||||
this.protocolBridge = protocolBridge;
|
|
||||||
|
|
||||||
// Initialize and verify certificate folders and files
|
// Initialize and verify certificate folders and files
|
||||||
folderStructure = new ClientCertificateFolderStructure();
|
folderStructure = new ClientCertificateFolderStructure();
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize connection to INS server
|
/**
|
||||||
|
* Initialize connection to INS server
|
||||||
|
*/
|
||||||
|
private void createNetworkClient() {
|
||||||
clientToINS = new NetworkClient.ClientBuilder().setLogger(protocolBridge.getLogger()).setProxy(protocolBridge.getProxy()).
|
clientToINS = new NetworkClient.ClientBuilder().setLogger(protocolBridge.getLogger()).setProxy(protocolBridge.getProxy()).
|
||||||
setHost(protocolBridge.getProtocolSettings().host).setPort(protocolBridge.getProtocolSettings().port).
|
setHost(protocolBridge.getProtocolSettings().host).setPort(protocolBridge.getProtocolSettings().port).
|
||||||
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
||||||
@@ -65,6 +64,19 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
|||||||
build();
|
build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injects the ProtocolBridge.
|
||||||
|
* @param bridge the Bridge instance.
|
||||||
|
* @throws IOException when NetworkServer failed to create.
|
||||||
|
*/
|
||||||
|
public final void attachBridge(ProtocolBridge bridge) throws IOException {
|
||||||
|
if (this.protocolBridge != null)
|
||||||
|
throw new IllegalStateException("ProtocolBridge already attached!");
|
||||||
|
|
||||||
|
this.protocolBridge = bridge;
|
||||||
|
createNetworkClient();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the INS connection client.
|
* Gets the INS connection client.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
|||||||
* The network server instance.
|
* The network server instance.
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private final NetworkServer networkServer;
|
private NetworkServer networkServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The configuration manager for handling server configurations.
|
* The configuration manager for handling server configurations.
|
||||||
@@ -37,7 +37,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
|||||||
* The reference to the ProtocolBridge Object
|
* The reference to the ProtocolBridge Object
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private final ProtocolBridge protocolBridge;
|
private ProtocolBridge protocolBridge;
|
||||||
/**
|
/**
|
||||||
* List of connected protocol clients.
|
* List of connected protocol clients.
|
||||||
*/
|
*/
|
||||||
@@ -56,8 +56,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
|||||||
* @throws IOException If an I/O error occurs.
|
* @throws IOException If an I/O error occurs.
|
||||||
* @throws CertificateException If a certificate error occurs.
|
* @throws CertificateException If a certificate error occurs.
|
||||||
*/
|
*/
|
||||||
public ProtocolINSServer(File configFile, ProtocolBridge protocolBridge) throws IOException, CertificateException {
|
public ProtocolINSServer(File configFile) throws IOException, CertificateException {
|
||||||
this.protocolBridge = protocolBridge;
|
|
||||||
// Ensure the configuration file exists
|
// Ensure the configuration file exists
|
||||||
if (!configFile.exists()) configFile.createNewFile();
|
if (!configFile.exists()) configFile.createNewFile();
|
||||||
|
|
||||||
@@ -87,14 +86,35 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
|||||||
checkFileExists(folderStructure.publicServerFolder, folderStructure.certPrefix, ".crt");
|
checkFileExists(folderStructure.publicServerFolder, folderStructure.certPrefix, ".crt");
|
||||||
checkFileExists(folderStructure.privateServerFolder, folderStructure.certPrefix, ".key");
|
checkFileExists(folderStructure.privateServerFolder, folderStructure.certPrefix, ".key");
|
||||||
|
|
||||||
// Define the certificate and key files based on the public IP address
|
|
||||||
File certFile = new File(folderStructure.publicServerFolder, folderStructure.certPrefix + NetworkUtils.getPublicIPAddress() + ".crt");
|
|
||||||
File keyFile = new File(folderStructure.privateServerFolder, folderStructure.certPrefix + NetworkUtils.getPublicIPAddress() + ".key");
|
|
||||||
|
|
||||||
// Initialize the protocol bridge and clients list
|
// Initialize the protocol bridge and clients list
|
||||||
this.clients = new ArrayList<>();
|
this.clients = new ArrayList<>();
|
||||||
|
|
||||||
// Build the network server with the specified settings
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injects the ProtocolBridge.
|
||||||
|
* @param bridge the Bridge instance.
|
||||||
|
* @throws IOException when NetworkServer failed to create.
|
||||||
|
*/
|
||||||
|
public final void attachBridge(ProtocolBridge bridge) throws IOException {
|
||||||
|
if (this.protocolBridge != null)
|
||||||
|
throw new IllegalStateException("ProtocolBridge already attached!");
|
||||||
|
|
||||||
|
this.protocolBridge = bridge;
|
||||||
|
createNetworkServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build the network server with the specified settings
|
||||||
|
*/
|
||||||
|
private void createNetworkServer() throws IOException {
|
||||||
|
// Define the certificate and key files based on the public IP address
|
||||||
|
File certFile = new File(folderStructure.publicServerFolder, folderStructure.certPrefix + NetworkUtils.getPublicIPAddress() + ".crt");
|
||||||
|
File keyFile = new File(folderStructure.privateServerFolder, folderStructure.certPrefix + NetworkUtils.getPublicIPAddress() + ".key");
|
||||||
|
|
||||||
this.networkServer = new NetworkServer.ServerBuilder().
|
this.networkServer = new NetworkServer.ServerBuilder().
|
||||||
setLogger(protocolBridge.getLogger()).
|
setLogger(protocolBridge.getLogger()).
|
||||||
setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public final class ProtocolWebServer {
|
|||||||
* The reference to the ProtocolBridge Object
|
* The reference to the ProtocolBridge Object
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
private final ProtocolBridge protocolBridge;
|
private ProtocolBridge protocolBridge;
|
||||||
/**
|
/**
|
||||||
* The network server handling pipeline connections.
|
* The network server handling pipeline connections.
|
||||||
*/
|
*/
|
||||||
@@ -96,9 +96,7 @@ public final class ProtocolWebServer {
|
|||||||
* @param rulesFile The rules file.
|
* @param rulesFile The rules file.
|
||||||
* @throws Exception If an error occurs during initialization.
|
* @throws Exception If an error occurs during initialization.
|
||||||
*/
|
*/
|
||||||
public ProtocolWebServer(File configFile, File authFile, File rulesFile, ProtocolBridge protocolBridge) throws Exception {
|
public ProtocolWebServer(File configFile, File authFile, File rulesFile) throws Exception {
|
||||||
this.protocolBridge = protocolBridge;
|
|
||||||
|
|
||||||
// Initialize the list of connected clients
|
// Initialize the list of connected clients
|
||||||
this.clients = new ArrayList<>();
|
this.clients = new ArrayList<>();
|
||||||
|
|
||||||
@@ -162,8 +160,25 @@ public final class ProtocolWebServer {
|
|||||||
|
|
||||||
AuthManager.loadAuthFile(authFile);
|
AuthManager.loadAuthFile(authFile);
|
||||||
RuleManager.loadRules(rulesFile);
|
RuleManager.loadRules(rulesFile);
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the pipeline server
|
/**
|
||||||
|
* Injects the ProtocolBridge.
|
||||||
|
* @param bridge the Bridge instance.
|
||||||
|
* @throws IOException when NetworkServer failed to create.
|
||||||
|
*/
|
||||||
|
public final void attachBridge(ProtocolBridge bridge) throws IOException {
|
||||||
|
if (this.protocolBridge != null)
|
||||||
|
throw new IllegalStateException("ProtocolBridge already attached!");
|
||||||
|
|
||||||
|
this.protocolBridge = bridge;
|
||||||
|
createNetworkServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the pipeline server
|
||||||
|
*/
|
||||||
|
private void createNetworkServer() {
|
||||||
pipelineServer = new NetworkServer.ServerBuilder().
|
pipelineServer = new NetworkServer.ServerBuilder().
|
||||||
setPort(configurationManager.getInt("port.pipeline")).setTimeout(0).
|
setPort(configurationManager.getInt("port.pipeline")).setTimeout(0).
|
||||||
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
||||||
|
|||||||
Reference in New Issue
Block a user