Constructor fixes
This commit is contained in:
@@ -108,6 +108,8 @@ public final class ProtocolBridge {
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
|
||||
public ProtocolBridge(ProtocolINSServer protocolINSServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||
protocolINSServer.attachBridge(this);
|
||||
|
||||
// Assign the parameters to the class fields
|
||||
this.protocolINSServer = protocolINSServer;
|
||||
this.protocolSettings = protocolSettings;
|
||||
@@ -133,6 +135,8 @@ public final class ProtocolBridge {
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
|
||||
public ProtocolBridge(ProtocolWebServer protocolWebServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||
protocolWebServer.attachBridge(this);
|
||||
|
||||
// Assign the parameters to the class fields
|
||||
this.protocolWebServer = protocolWebServer;
|
||||
this.protocolSettings = protocolSettings;
|
||||
@@ -158,6 +162,8 @@ public final class ProtocolBridge {
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
|
||||
public ProtocolBridge(ProtocolClient protocolClient, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||
protocolClient.attachBridge(this);
|
||||
|
||||
// Assign the parameters to the class fields
|
||||
this.protocolClient = protocolClient;
|
||||
this.protocolSettings = protocolSettings;
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
/**
|
||||
* Handles everything with INS-Connection.
|
||||
*/
|
||||
private final NetworkClient clientToINS;
|
||||
private NetworkClient clientToINS;
|
||||
|
||||
/**
|
||||
* Manages the folder structure for client certificates.
|
||||
@@ -39,7 +39,7 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
* The reference to the ProtocolBridge Object
|
||||
*/
|
||||
@Getter
|
||||
private final ProtocolBridge protocolBridge;
|
||||
private ProtocolBridge protocolBridge;
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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 {
|
||||
this.protocolBridge = protocolBridge;
|
||||
|
||||
public ProtocolClient() {
|
||||
// Initialize and verify certificate folders and files
|
||||
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()).
|
||||
setHost(protocolBridge.getProtocolSettings().host).setPort(protocolBridge.getProtocolSettings().port).
|
||||
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
||||
@@ -65,6 +64,19 @@ public abstract class ProtocolClient extends DefaultMethodsOverrider {
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -27,7 +27,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
||||
* The network server instance.
|
||||
*/
|
||||
@Getter
|
||||
private final NetworkServer networkServer;
|
||||
private NetworkServer networkServer;
|
||||
|
||||
/**
|
||||
* The configuration manager for handling server configurations.
|
||||
@@ -37,7 +37,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
||||
* The reference to the ProtocolBridge Object
|
||||
*/
|
||||
@Getter
|
||||
private final ProtocolBridge protocolBridge;
|
||||
private ProtocolBridge protocolBridge;
|
||||
/**
|
||||
* List of connected protocol clients.
|
||||
*/
|
||||
@@ -56,8 +56,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
||||
* @throws IOException If an I/O error occurs.
|
||||
* @throws CertificateException If a certificate error occurs.
|
||||
*/
|
||||
public ProtocolINSServer(File configFile, ProtocolBridge protocolBridge) throws IOException, CertificateException {
|
||||
this.protocolBridge = protocolBridge;
|
||||
public ProtocolINSServer(File configFile) throws IOException, CertificateException {
|
||||
// Ensure the configuration file exists
|
||||
if (!configFile.exists()) configFile.createNewFile();
|
||||
|
||||
@@ -87,14 +86,35 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
||||
checkFileExists(folderStructure.publicServerFolder, folderStructure.certPrefix, ".crt");
|
||||
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
|
||||
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().
|
||||
setLogger(protocolBridge.getLogger()).
|
||||
setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
||||
|
||||
@@ -66,7 +66,7 @@ public final class ProtocolWebServer {
|
||||
* The reference to the ProtocolBridge Object
|
||||
*/
|
||||
@Getter
|
||||
private final ProtocolBridge protocolBridge;
|
||||
private ProtocolBridge protocolBridge;
|
||||
/**
|
||||
* The network server handling pipeline connections.
|
||||
*/
|
||||
@@ -96,9 +96,7 @@ public final class ProtocolWebServer {
|
||||
* @param rulesFile The rules file.
|
||||
* @throws Exception If an error occurs during initialization.
|
||||
*/
|
||||
public ProtocolWebServer(File configFile, File authFile, File rulesFile, ProtocolBridge protocolBridge) throws Exception {
|
||||
this.protocolBridge = protocolBridge;
|
||||
|
||||
public ProtocolWebServer(File configFile, File authFile, File rulesFile) throws Exception {
|
||||
// Initialize the list of connected clients
|
||||
this.clients = new ArrayList<>();
|
||||
|
||||
@@ -162,8 +160,25 @@ public final class ProtocolWebServer {
|
||||
|
||||
AuthManager.loadAuthFile(authFile);
|
||||
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().
|
||||
setPort(configurationManager.getInt("port.pipeline")).setTimeout(0).
|
||||
setPacketHandler(protocolBridge.getProtocolSettings().packetHandler).setEventManager(protocolBridge.getProtocolSettings().eventManager).
|
||||
|
||||
Reference in New Issue
Block a user