- Started with Web Protocol
This commit is contained in:
@@ -3,8 +3,10 @@ package org.openautonomousconnection.protocol.packets.v1_0_0.beta;
|
||||
import org.openautonomousconnection.protocol.ProtocolBridge;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.side.client.events.ConnectedToProtocolServer;
|
||||
import org.openautonomousconnection.protocol.side.server.ConnectedProtocolClient;
|
||||
import org.openautonomousconnection.protocol.side.server.events.ProtocolClientConnected;
|
||||
import org.openautonomousconnection.protocol.side.dns.ConnectedProtocolClient;
|
||||
import org.openautonomousconnection.protocol.side.dns.events.ConnectedProtocolClientEvent;
|
||||
import org.openautonomousconnection.protocol.side.web.ConnectedWebClient;
|
||||
import org.openautonomousconnection.protocol.side.web.events.ConnectedWebClientEvent;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.DNSResponseCode;
|
||||
import dev.unlegitdqrk.unlegitlibrary.file.FileUtils;
|
||||
@@ -19,6 +21,7 @@ import java.io.ObjectOutputStream;
|
||||
|
||||
public class AuthPacket extends OACPacket {
|
||||
|
||||
// Registration Constructor
|
||||
public AuthPacket() {
|
||||
super(4, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
@@ -36,7 +39,7 @@ public class AuthPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
objectOutputStream.writeObject(ProtocolBridge.getInstance().getProtocolVersion());
|
||||
|
||||
// Read ca files
|
||||
@@ -44,19 +47,19 @@ public class AuthPacket extends OACPacket {
|
||||
String caPem = "N/A";
|
||||
String caSrl = "N/A";
|
||||
try {
|
||||
objectOutputStream.writeUTF(ProtocolBridge.getInstance().getProtocolServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress());
|
||||
objectOutputStream.writeUTF(ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress());
|
||||
|
||||
caKey = FileUtils.readFileFull(new File(
|
||||
ProtocolBridge.getInstance().getProtocolServer().getFolderStructure().privateCAFolder,
|
||||
ProtocolBridge.getInstance().getProtocolServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".key"));
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().privateCAFolder,
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".key"));
|
||||
|
||||
caPem = FileUtils.readFileFull(new File(
|
||||
ProtocolBridge.getInstance().getProtocolServer().getFolderStructure().publicCAFolder,
|
||||
ProtocolBridge.getInstance().getProtocolServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".pem"));
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().publicCAFolder,
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".pem"));
|
||||
|
||||
caSrl = FileUtils.readFileFull(new File(
|
||||
ProtocolBridge.getInstance().getProtocolServer().getFolderStructure().publicCAFolder,
|
||||
ProtocolBridge.getInstance().getProtocolServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".srl"));
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().publicCAFolder,
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getFolderStructure().caPrefix + NetworkUtils.getPublicIPAddress() + ".srl"));
|
||||
} catch (Exception exception) {
|
||||
ProtocolBridge.getInstance().getLogger().exception("Failed to read ca-files", exception);
|
||||
setResponseCode(DNSResponseCode.RESPONSE_AUTH_FAILED);
|
||||
@@ -66,18 +69,18 @@ public class AuthPacket extends OACPacket {
|
||||
objectOutputStream.writeUTF(caKey);
|
||||
objectOutputStream.writeUTF(caPem);
|
||||
objectOutputStream.writeUTF(caSrl);
|
||||
} else {
|
||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID());
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID());
|
||||
objectOutputStream.writeObject(ProtocolBridge.getInstance().getProtocolVersion());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer() || ProtocolBridge.getInstance().isRunningAsWebServer()) {
|
||||
int clientID = objectInputStream.readInt();
|
||||
ProtocolVersion clientVersion = (ProtocolVersion) objectInputStream.readObject();
|
||||
ConnectionHandler connectionHandler = ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID);
|
||||
ConnectionHandler connectionHandler = ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getConnectionHandlerByID(clientID);
|
||||
|
||||
if (!ProtocolBridge.getInstance().isVersionSupported(clientVersion)) {
|
||||
setResponseCode(DNSResponseCode.RESPONSE_AUTH_FAILED);
|
||||
@@ -86,15 +89,20 @@ public class AuthPacket extends OACPacket {
|
||||
} else setResponseCode(DNSResponseCode.RESPONSE_AUTH_SUCCESS);
|
||||
|
||||
|
||||
ConnectedProtocolClient client = ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID);
|
||||
client.setClientVersion(clientVersion);
|
||||
ProtocolBridge.getInstance().getProtocolSettings().eventManager.executeEvent(new ProtocolClientConnected(client));
|
||||
} else {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
ConnectedProtocolClient client = ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID);
|
||||
client.setClientVersion(clientVersion);
|
||||
ProtocolBridge.getInstance().getProtocolSettings().eventManager.executeEvent(new ConnectedProtocolClientEvent(client));
|
||||
} else {
|
||||
ConnectedWebClient client = ProtocolBridge.getInstance().getProtocolWebServer().getClientByID(clientID);
|
||||
client.setClientVersion(clientVersion);
|
||||
}
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
ProtocolVersion serverVersion = (ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
if (!ProtocolBridge.getInstance().isVersionSupported(serverVersion)) {
|
||||
setResponseCode(DNSResponseCode.RESPONSE_AUTH_FAILED);
|
||||
ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().disconnect();
|
||||
ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().disconnect();
|
||||
return;
|
||||
} else setResponseCode(DNSResponseCode.RESPONSE_AUTH_SUCCESS);
|
||||
|
||||
|
@@ -17,6 +17,7 @@ public class GetDestinationPacket extends OACPacket {
|
||||
private DNSResponseCode validationResponse;
|
||||
private String destination;
|
||||
|
||||
// DNS-Server Constructor
|
||||
public GetDestinationPacket(Domain domain, DNSResponseCode validationResponse, String destination) {
|
||||
this();
|
||||
this.domain = domain;
|
||||
@@ -24,6 +25,15 @@ public class GetDestinationPacket extends OACPacket {
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
// Client Constructor
|
||||
public GetDestinationPacket(Domain domain, DNSResponseCode validationResponse) {
|
||||
this();
|
||||
this.domain = domain;
|
||||
this.validationResponse = validationResponse;
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
// Registration Constructor
|
||||
public GetDestinationPacket() {
|
||||
super(6, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
@@ -33,10 +43,10 @@ public class GetDestinationPacket extends OACPacket {
|
||||
if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
if (validationResponse != DNSResponseCode.RESPONSE_DOMAIN_FULLY_EXIST) return;
|
||||
|
||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID());
|
||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID());
|
||||
objectOutputStream.writeObject(domain);
|
||||
objectOutputStream.writeObject(validationResponse);
|
||||
} else {
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
objectOutputStream.writeObject(domain);
|
||||
objectOutputStream.writeObject(validationResponse);
|
||||
objectOutputStream.writeUTF(destination);
|
||||
@@ -45,11 +55,11 @@ public class GetDestinationPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
domain = (Domain) objectInputStream.readObject();
|
||||
validationResponse = (DNSResponseCode) objectInputStream.readObject();
|
||||
} else {
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
domain = (Domain) objectInputStream.readObject();
|
||||
validationResponse = (DNSResponseCode) objectInputStream.readObject();
|
||||
destination = objectInputStream.readUTF();
|
||||
@@ -62,13 +72,14 @@ public class GetDestinationPacket extends OACPacket {
|
||||
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {
|
||||
super.onResponseCodeRead(packetHandler, objectInputStream);
|
||||
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
if (validationResponse != DNSResponseCode.RESPONSE_DOMAIN_FULLY_EXIST) return;
|
||||
destination = domain.getDestination();
|
||||
|
||||
try {
|
||||
ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID).getConnectionHandler().sendPacket(new GetDestinationPacket(domain, validationResponse, destination));
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID).getConnectionHandler().sendPacket(new GetDestinationPacket(domain, validationResponse, destination));
|
||||
} catch (IOException | ClassNotFoundException exception) {
|
||||
ProtocolBridge.getInstance().getProtocolServer().getDomainDestinationFailed(ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID), domain, validationResponse, exception);
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().domainDestinationPacketFailedSend(ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID), domain, validationResponse, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,12 +14,14 @@ public class UnsupportedClassicPacket extends OACPacket {
|
||||
private Class<? extends OACPacket> unsupportedClassicPacket;
|
||||
private Object[] content;
|
||||
|
||||
// Constructor with more information
|
||||
public UnsupportedClassicPacket(Class<? extends OACPacket> unsupportedClassicPacket, Object[] content) {
|
||||
this();
|
||||
this.unsupportedClassicPacket = unsupportedClassicPacket;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
// Registration Constructor
|
||||
public UnsupportedClassicPacket() {
|
||||
super(5, ProtocolVersion.PV_1_0_0_BETA);
|
||||
}
|
||||
@@ -27,7 +29,8 @@ public class UnsupportedClassicPacket extends OACPacket {
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsClient())
|
||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID());
|
||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID());
|
||||
|
||||
objectOutputStream.writeUTF(unsupportedClassicPacket.getName());
|
||||
objectOutputStream.writeInt(content.length);
|
||||
for (Object o : content) objectOutputStream.writeObject(o);
|
||||
@@ -37,7 +40,7 @@ public class UnsupportedClassicPacket extends OACPacket {
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
int clientID = 0;
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) clientID = objectInputStream.readInt();
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) clientID = objectInputStream.readInt();
|
||||
String className = objectInputStream.readUTF();
|
||||
int size = objectInputStream.readInt();
|
||||
content = new Object[size];
|
||||
@@ -46,8 +49,8 @@ public class UnsupportedClassicPacket extends OACPacket {
|
||||
content[i] = objectInputStream.readObject();
|
||||
}
|
||||
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer())
|
||||
ProtocolBridge.getInstance().getClassicHandlerServer().unsupportedClassicPacket(className, content, ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID));
|
||||
else ProtocolBridge.getInstance().getClassicHandlerClient().unsupportedClassicPacket(className, content);
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer())
|
||||
ProtocolBridge.getInstance().getClassicHandlerServer().unsupportedClassicPacket(className, content, ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID));
|
||||
else if (ProtocolBridge.getInstance().isRunningAsClient()) ProtocolBridge.getInstance().getClassicHandlerClient().unsupportedClassicPacket(className, content);
|
||||
}
|
||||
}
|
||||
|
@@ -26,15 +26,15 @@ public class ValidateDomainPacket extends OACPacket {
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsClient())
|
||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID());
|
||||
else setResponseCode(ProtocolBridge.getInstance().getProtocolServer().validateDomain(domain));
|
||||
objectOutputStream.writeInt(ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID());
|
||||
else if (ProtocolBridge.getInstance().isRunningAsDNSServer()) setResponseCode(ProtocolBridge.getInstance().getProtocolDNSServer().validateDomain(domain));
|
||||
|
||||
objectOutputStream.writeObject(domain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) clientID = objectInputStream.readInt();
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) clientID = objectInputStream.readInt();
|
||||
domain = (Domain) objectInputStream.readObject();
|
||||
}
|
||||
|
||||
@@ -42,16 +42,14 @@ public class ValidateDomainPacket extends OACPacket {
|
||||
protected void onResponseCodeRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) {
|
||||
super.onResponseCodeRead(packetHandler, objectInputStream);
|
||||
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
try {
|
||||
ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID).getConnectionHandler().sendPacket(new ValidateDomainPacket(domain));
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID).getConnectionHandler().sendPacket(new ValidateDomainPacket(domain));
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
ProtocolBridge.getInstance().getProtocolServer().validationFailed(domain, ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID), e);
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().validationPacketSendFailed(domain, ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID), e);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ProtocolBridge.getInstance().getProtocolClient().validationCompleted(domain, getResponseCode());
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) ProtocolBridge.getInstance().getProtocolClient().validationCompleted(domain, getResponseCode());
|
||||
}
|
||||
}
|
||||
|
@@ -28,18 +28,19 @@ public class Classic_DomainPacket extends OACPacket {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
// Registration constructor
|
||||
public Classic_DomainPacket() {
|
||||
super(2, ProtocolVersion.PV_1_0_0_CLASSIC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
objectOutputStream.writeInt(clientID);
|
||||
objectOutputStream.writeObject(requestDomain);
|
||||
objectOutputStream.writeObject(domain);
|
||||
} else {
|
||||
clientID = ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID();
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID();
|
||||
objectOutputStream.writeInt(clientID);
|
||||
objectOutputStream.writeObject(requestDomain);
|
||||
}
|
||||
@@ -49,7 +50,7 @@ public class Classic_DomainPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
@@ -60,19 +61,19 @@ public class Classic_DomainPacket extends OACPacket {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
|
||||
|
||||
if (ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID).clientSupportClassic())
|
||||
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain));
|
||||
if (ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID).supportClientClassic())
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_DomainPacket(clientID, requestDomain, domain));
|
||||
else
|
||||
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain}));
|
||||
} else {
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{clientID, requestDomain, domain}));
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||
domain = (Classic_Domain) objectInputStream.readObject();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
|
||||
ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getEventManager().executeEvent(new Classic_DomainPacketReceivedEvent(protocolVersion, domain, requestDomain, clientID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ public class Classic_MessagePacket extends OACPacket {
|
||||
private String message;
|
||||
private int clientID;
|
||||
|
||||
// Constructor with message and client id
|
||||
public Classic_MessagePacket(String message, int toClient) {
|
||||
this();
|
||||
this.message = message;
|
||||
@@ -26,9 +27,9 @@ public class Classic_MessagePacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) objectOutputStream.writeInt(clientID);
|
||||
else {
|
||||
clientID = ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID();
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) objectOutputStream.writeInt(clientID);
|
||||
else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID();
|
||||
objectOutputStream.writeInt(clientID);
|
||||
}
|
||||
|
||||
@@ -38,13 +39,13 @@ public class Classic_MessagePacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
String message = objectInputStream.readUTF();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
ProtocolBridge.getInstance().getClassicHandlerServer().handleMessage(ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID), message, protocolVersion);
|
||||
} else {
|
||||
ProtocolBridge.getInstance().getClassicHandlerServer().handleMessage(ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID), message, protocolVersion);
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
String message = objectInputStream.readUTF();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
@@ -4,6 +4,7 @@ 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.beta.DNSResponseCode;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_Domain;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_PingPacketReceivedEvent;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.Classic_ProtocolVersion;
|
||||
@@ -37,13 +38,13 @@ public class Classic_PingPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onWrite(PacketHandler packetHandler, ObjectOutputStream objectOutputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
objectOutputStream.writeInt(clientID);
|
||||
objectOutputStream.writeObject(requestDomain);
|
||||
objectOutputStream.writeObject(domain);
|
||||
objectOutputStream.writeBoolean(reachable);
|
||||
} else {
|
||||
clientID = ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getClientID();
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
clientID = ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getClientID();
|
||||
objectOutputStream.writeInt(clientID);
|
||||
objectOutputStream.writeObject(requestDomain);
|
||||
}
|
||||
@@ -53,7 +54,7 @@ public class Classic_PingPacket extends OACPacket {
|
||||
|
||||
@Override
|
||||
public void onRead(PacketHandler packetHandler, ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
||||
if (ProtocolBridge.getInstance().isRunningAsServer()) {
|
||||
if (ProtocolBridge.getInstance().isRunningAsDNSServer()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||
protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
@@ -65,19 +66,20 @@ public class Classic_PingPacket extends OACPacket {
|
||||
}
|
||||
|
||||
reachable = domain != null;
|
||||
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||
if (ProtocolBridge.getInstance().getProtocolServer().getClientByID(clientID).clientSupportClassic())
|
||||
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable));
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||
if (ProtocolBridge.getInstance().getProtocolDNSServer().getClientByID(clientID).supportClientClassic())
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new Classic_PingPacket(requestDomain, domain, reachable));
|
||||
else
|
||||
ProtocolBridge.getInstance().getProtocolServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain, domain, reachable}));
|
||||
} else {
|
||||
ProtocolBridge.getInstance().getProtocolDNSServer().getNetworkServer().getConnectionHandlerByID(clientID).sendPacket(new UnsupportedClassicPacket(Classic_PingPacket.class, new Object[]{requestDomain, domain, reachable}));
|
||||
} else if (ProtocolBridge.getInstance().isRunningAsClient()) {
|
||||
clientID = objectInputStream.readInt();
|
||||
requestDomain = (Classic_RequestDomain) objectInputStream.readObject();
|
||||
domain = (Classic_Domain) objectInputStream.readObject();
|
||||
boolean reachable = objectInputStream.readBoolean();
|
||||
Classic_ProtocolVersion protocolVersion = (Classic_ProtocolVersion) objectInputStream.readObject();
|
||||
|
||||
ProtocolBridge.getInstance().getProtocolClient().getNetworkClient().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||
ProtocolBridge.getInstance().getProtocolClient().validationCompleted(domain.getDomain(), reachable ? DNSResponseCode.RESPONSE_DOMAIN_FULLY_EXIST : DNSResponseCode.RESPONSE_DOMAIN_FULLY_NOT_EXIST);
|
||||
ProtocolBridge.getInstance().getProtocolClient().getClientDNSConnection().getEventManager().executeEvent(new Classic_PingPacketReceivedEvent(protocolVersion, domain, requestDomain, reachable, clientID));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user