Added Built-In infonames
This commit is contained in:
@@ -13,9 +13,11 @@ 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;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,9 +85,36 @@ public final class INSServerListener extends EventListener {
|
|||||||
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.tln, q.name, q.sub, q.type);
|
||||||
List<INSRecord> resolved = insServer.resolve(q.tln, q.name, q.sub, q.type);
|
List<INSRecord> resolved = new ArrayList<>();
|
||||||
|
INSResponseStatus status = null;
|
||||||
|
|
||||||
INSResponseStatus status = resolved.isEmpty() ? INSResponseStatus.NOT_FOUND : INSResponseStatus.OK;
|
if (q.sub == null && q.tln.equalsIgnoreCase("oac")) {
|
||||||
|
if (q.name.equalsIgnoreCase("info")) {
|
||||||
|
// Return INS server info site
|
||||||
|
String[] hostPort = insServer.getINSInfoSite().split(":");
|
||||||
|
resolved = List.of(new INSRecord(q.type, hostPort[0], -1, -1, Integer.parseInt(hostPort[1]), 0));
|
||||||
|
} else if (q.name.equalsIgnoreCase("register")) {
|
||||||
|
// Return INS frontend site
|
||||||
|
String[] hostPort = insServer.getINSFrontendSite().split(":");
|
||||||
|
resolved = List.of(new INSRecord(q.type, hostPort[0], -1, -1, Integer.parseInt(hostPort[1]), 0));
|
||||||
|
} else {
|
||||||
|
// Not a special name → use normal resolving
|
||||||
|
resolved = insServer.resolve(q.tln, q.name, q.sub, q.type);
|
||||||
|
}
|
||||||
|
} else if (q.sub == null && q.name.equalsIgnoreCase("info")) {
|
||||||
|
// Return TLN server info site
|
||||||
|
String resolve = insServer.resolveTLNInfoSite(q.tln);
|
||||||
|
if (resolve == null) status = INSResponseStatus.INVALID_REQUEST;
|
||||||
|
else {
|
||||||
|
String[] hostPort = resolve.split(":");
|
||||||
|
resolved = List.of(new INSRecord(q.type, hostPort[0], -1, -1, Integer.parseInt(hostPort[1]), 0));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Normal resolving
|
||||||
|
resolved = insServer.resolve(q.tln, q.name, q.sub, q.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
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.clientId, insServer.getProtocolBridge());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -67,12 +67,12 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
|||||||
|
|
||||||
// Set default values for configuration properties if not already set
|
// Set default values for configuration properties if not already set
|
||||||
if (!configurationManager.isSet("server.site.info")) {
|
if (!configurationManager.isSet("server.site.info")) {
|
||||||
configurationManager.set("server.site.info", "INS-SERVER INFO SITE IP");
|
configurationManager.set("server.site.info", "INS-SERVER INFO SITE IP:PORT");
|
||||||
configurationManager.saveProperties();
|
configurationManager.saveProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!configurationManager.isSet("server.site.register")) {
|
if (!configurationManager.isSet("server.site.frontend")) {
|
||||||
configurationManager.set("server.site.register", "SERVER IP TO INS-FRONTEND WEBSITE");
|
configurationManager.set("server.site.frontend", "SERVER IP TO INS-FRONTEND:PORT");
|
||||||
configurationManager.saveProperties();
|
configurationManager.saveProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,8 +188,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
|||||||
* @param sub An optional subname, or {@code null}.
|
* @param sub An optional subname, or {@code null}.
|
||||||
* @param type The record type requested.
|
* @param type The record type requested.
|
||||||
*/
|
*/
|
||||||
public void onQueryReceived(String tln, String name, String sub, INSRecordType type) {
|
public void onQueryReceived(String tln, String name, String sub, INSRecordType type) {}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback fired after an INS response was successfully sent to the client.
|
* Callback fired after an INS response was successfully sent to the client.
|
||||||
@@ -200,8 +199,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
|||||||
* @param type The requested record type.
|
* @param type The requested record type.
|
||||||
* @param results The records returned to the client.
|
* @param results The records returned to the client.
|
||||||
*/
|
*/
|
||||||
public void onResponseSent(String tln, String name, String sub, INSRecordType type, List<INSRecord> results) {
|
public void onResponseSent(String tln, String name, String sub, INSRecordType type, List<INSRecord> results) {}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback fired when an INS response could not be delivered to the client.
|
* Callback fired when an INS response could not be delivered to the client.
|
||||||
@@ -213,16 +211,47 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider {
|
|||||||
* @param results The records that would have been sent.
|
* @param results The records that would have been sent.
|
||||||
* @param exception The exception describing the failure.
|
* @param exception The exception describing the failure.
|
||||||
*/
|
*/
|
||||||
public void onResponseSentFailed(String tln, String name, String sub, INSRecordType type, List<INSRecord> results, Exception exception) {
|
public void onResponseSentFailed(String tln, String name, String sub, INSRecordType type, List<INSRecord> results, Exception exception) {}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Resolves the information endpoint for a given Top-Level Name (TLN).
|
||||||
|
*
|
||||||
|
* <p>This method is part of the INS server's internal resolution logic.
|
||||||
|
* Each TLN
|
||||||
|
* need to define a special "info site" which provides metadata, documentation,
|
||||||
|
* or administrative information for that TLN.
|
||||||
|
*
|
||||||
|
* <p>The returned string must always be in the format:
|
||||||
|
* <pre>
|
||||||
|
* host:port
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* <p>This method is used automatically by the INS protocol handler when a client
|
||||||
|
* queries an InfoName of the form:
|
||||||
|
* <pre>
|
||||||
|
* info.<tln>
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* <p>If no TLN-specific info endpoint exists or the TLN does not exist, the implementation can:
|
||||||
|
* <ul>
|
||||||
|
* <li>return <code>null</code> to signal that no info site is registered</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param tln the top-level name for which the info site should be resolved.
|
||||||
|
* Must not be null. Case-insensitive.
|
||||||
|
*
|
||||||
|
* @return a string in <code>"host:port"</code> format representing the TLN's info endpoint,
|
||||||
|
* or <code>null</code> if the TLN has no registered info site.
|
||||||
|
*/
|
||||||
|
public abstract String resolveTLNInfoSite(String tln);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the INS registration site URL from the configuration.
|
* Gets the INS registration site URL from the configuration.
|
||||||
*
|
*
|
||||||
* @return The INS registration site URL.
|
* @return The INS registration site URL.
|
||||||
*/
|
*/
|
||||||
public final String getINSRegisterSite() {
|
public final String getINSFrontendSite() {
|
||||||
return configurationManager.getString("server.site.register");
|
return configurationManager.getString("server.site.frontend");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import java.io.Serializable;
|
|||||||
* This is the transport format used in responses and packets.
|
* This is the transport format used in responses and packets.
|
||||||
* Each record contains:
|
* Each record contains:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>The record type (A, AAAA, CNAME, TXT, ...)</li>
|
* <li>The record type</li>
|
||||||
* <li>A value (IPv4, IPv6, hostname, text, ...)</li>
|
* <li>A value</li>
|
||||||
* <li>Optional priority and weight fields (MX, SRV)</li>
|
* <li>Optional priority and weight fields</li>
|
||||||
* <li>Optional port field (SRV)</li>
|
* <li>Optional port field (SRV)</li>
|
||||||
* <li>A TTL defining how long the record may be cached</li>
|
* <li>A TTL defining how long the record may be cached</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
|
|||||||
@@ -22,4 +22,5 @@ public enum INSRecordType {
|
|||||||
MX,
|
MX,
|
||||||
SRV,
|
SRV,
|
||||||
NS,
|
NS,
|
||||||
|
INFO,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user