Updated listener to Getters
This commit is contained in:
@@ -13,7 +13,6 @@ import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient;
|
|||||||
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
|
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
|
||||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord;
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecordType;
|
|
||||||
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus;
|
import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -84,44 +83,44 @@ public final class INSServerListener extends EventListener {
|
|||||||
public void onPacket(S_PacketReceivedEvent event) {
|
public void onPacket(S_PacketReceivedEvent event) {
|
||||||
if (!(event.getPacket() instanceof INSQueryPacket q)) return;
|
if (!(event.getPacket() instanceof INSQueryPacket q)) return;
|
||||||
|
|
||||||
insServer.onQueryReceived(q.tln, q.name, q.sub, q.type);
|
insServer.onQueryReceived(q.getTLN(), q.getName(), q.getSub(), q.getType());
|
||||||
List<INSRecord> resolved = new ArrayList<>();
|
List<INSRecord> resolved = new ArrayList<>();
|
||||||
INSResponseStatus status = null;
|
INSResponseStatus status = null;
|
||||||
|
|
||||||
if (q.sub == null && q.tln.equalsIgnoreCase("oac")) {
|
if (q.getSub() == null && q.getTLN().equalsIgnoreCase("oac")) {
|
||||||
if (q.name.equalsIgnoreCase("info")) {
|
if (q.getName().equalsIgnoreCase("info")) {
|
||||||
// Return INS server info site
|
// Return INS server info site
|
||||||
String[] hostPort = insServer.getINSInfoSite().split(":");
|
String[] hostPort = insServer.getINSInfoSite().split(":");
|
||||||
resolved = List.of(new INSRecord(q.type, hostPort[0], -1, -1, Integer.parseInt(hostPort[1]), 0));
|
resolved = List.of(new INSRecord(q.getType(), hostPort[0], -1, -1, Integer.parseInt(hostPort[1]), 0));
|
||||||
} else if (q.name.equalsIgnoreCase("register")) {
|
} else if (q.getName().equalsIgnoreCase("register")) {
|
||||||
// Return INS frontend site
|
// Return INS frontend site
|
||||||
String[] hostPort = insServer.getINSFrontendSite().split(":");
|
String[] hostPort = insServer.getINSFrontendSite().split(":");
|
||||||
resolved = List.of(new INSRecord(q.type, hostPort[0], -1, -1, Integer.parseInt(hostPort[1]), 0));
|
resolved = List.of(new INSRecord(q.getType(), hostPort[0], -1, -1, Integer.parseInt(hostPort[1]), 0));
|
||||||
} else {
|
} else {
|
||||||
// Not a special name → use normal resolving
|
// Not a special name → use normal resolving
|
||||||
resolved = insServer.resolve(q.tln, q.name, q.sub, q.type);
|
resolved = insServer.resolve(q.getTLN(), q.getName(), q.getName(), q.getType());
|
||||||
}
|
}
|
||||||
} else if (q.sub == null && q.name.equalsIgnoreCase("info")) {
|
} else if (q.getSub() == null && q.getName().equalsIgnoreCase("info")) {
|
||||||
// Return TLN server info site
|
// Return TLN server info site
|
||||||
String resolve = insServer.resolveTLNInfoSite(q.tln);
|
String resolve = insServer.resolveTLNInfoSite(q.getTLN());
|
||||||
if (resolve == null) status = INSResponseStatus.INVALID_REQUEST;
|
if (resolve == null) status = INSResponseStatus.INVALID_REQUEST;
|
||||||
else {
|
else {
|
||||||
String[] hostPort = resolve.split(":");
|
String[] hostPort = resolve.split(":");
|
||||||
resolved = List.of(new INSRecord(q.type, hostPort[0], -1, -1, Integer.parseInt(hostPort[1]), 0));
|
resolved = List.of(new INSRecord(q.getType(), hostPort[0], -1, -1, Integer.parseInt(hostPort[1]), 0));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Normal resolving
|
// Normal resolving
|
||||||
resolved = insServer.resolve(q.tln, q.name, q.sub, q.type);
|
resolved = insServer.resolve(q.getTLN(), q.getName(), q.getSub(), q.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
status = status == null && resolved.isEmpty() ? INSResponseStatus.NOT_FOUND : INSResponseStatus.OK;
|
status = status == null && resolved.isEmpty() ? INSResponseStatus.NOT_FOUND : INSResponseStatus.OK;
|
||||||
INSResponsePacket response = new INSResponsePacket(status, resolved, q.clientId, insServer.getProtocolBridge());
|
INSResponsePacket response = new INSResponsePacket(status, resolved, q.getClientId(), insServer.getProtocolBridge());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
event.getConnectionHandler().sendPacket(response);
|
event.getConnectionHandler().sendPacket(response);
|
||||||
insServer.onResponseSent(q.tln, q.name, q.sub, q.type, resolved);
|
insServer.onResponseSent(q.getTLN(), q.getName(), q.getSub(), q.getType(), resolved);
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException | ClassNotFoundException e) {
|
||||||
insServer.onResponseSentFailed(q.tln, q.name, q.sub, q.type, resolved, e);
|
insServer.onResponseSentFailed(q.getTLN(), q.getName(), q.getSub(), q.getType(), resolved, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import java.io.ObjectOutputStream;
|
|||||||
public final class INSQueryPacket extends OACPacket {
|
public final class INSQueryPacket extends OACPacket {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private String tln;
|
private String TLN;
|
||||||
@Getter
|
@Getter
|
||||||
private String name;
|
private String name;
|
||||||
@Getter
|
@Getter
|
||||||
@@ -46,7 +46,7 @@ public final class INSQueryPacket extends OACPacket {
|
|||||||
*/
|
*/
|
||||||
public INSQueryPacket(String tln, String name, String sub, INSRecordType type, int clientId) {
|
public INSQueryPacket(String tln, String name, String sub, INSRecordType type, int clientId) {
|
||||||
super(5, ProtocolVersion.PV_1_0_0_BETA);
|
super(5, ProtocolVersion.PV_1_0_0_BETA);
|
||||||
this.tln = tln;
|
this.TLN = tln;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.sub = sub;
|
this.sub = sub;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -65,7 +65,7 @@ public final class INSQueryPacket extends OACPacket {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
public void onWrite(PacketHandler handler, ObjectOutputStream out) throws IOException {
|
||||||
out.writeUTF(tln);
|
out.writeUTF(TLN);
|
||||||
out.writeUTF(name);
|
out.writeUTF(name);
|
||||||
|
|
||||||
out.writeBoolean(sub != null);
|
out.writeBoolean(sub != null);
|
||||||
@@ -80,7 +80,7 @@ public final class INSQueryPacket extends OACPacket {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException, ClassNotFoundException {
|
public void onRead(PacketHandler handler, ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||||
tln = in.readUTF();
|
TLN = in.readUTF();
|
||||||
name = in.readUTF();
|
name = in.readUTF();
|
||||||
|
|
||||||
boolean hasSub = in.readBoolean();
|
boolean hasSub = in.readBoolean();
|
||||||
|
|||||||
Reference in New Issue
Block a user