From 05ec96981c9644dbf7654fefc60aaefaad3f3900 Mon Sep 17 00:00:00 2001 From: Finn Date: Thu, 11 Dec 2025 09:46:59 +0100 Subject: [PATCH] Added Built-In infonames --- .../protocol/listeners/INSServerListener.java | 33 +++++++++++- .../protocol/side/ins/ProtocolINSServer.java | 51 +++++++++++++++---- .../versions/v1_0_0/beta/INSRecord.java | 6 +-- .../versions/v1_0_0/beta/INSRecordType.java | 1 + 4 files changed, 75 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/openautonomousconnection/protocol/listeners/INSServerListener.java b/src/main/java/org/openautonomousconnection/protocol/listeners/INSServerListener.java index d4d4ff6..08180c0 100644 --- a/src/main/java/org/openautonomousconnection/protocol/listeners/INSServerListener.java +++ b/src/main/java/org/openautonomousconnection/protocol/listeners/INSServerListener.java @@ -13,9 +13,11 @@ import org.openautonomousconnection.protocol.side.ins.ConnectedProtocolClient; import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer; 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.INSRecordType; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSResponseStatus; import java.io.IOException; +import java.util.ArrayList; import java.util.List; /** @@ -83,9 +85,36 @@ public final class INSServerListener extends EventListener { if (!(event.getPacket() instanceof INSQueryPacket q)) return; insServer.onQueryReceived(q.tln, q.name, q.sub, q.type); - List resolved = insServer.resolve(q.tln, q.name, q.sub, q.type); + List 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()); try { diff --git a/src/main/java/org/openautonomousconnection/protocol/side/ins/ProtocolINSServer.java b/src/main/java/org/openautonomousconnection/protocol/side/ins/ProtocolINSServer.java index 1663acf..297d33f 100644 --- a/src/main/java/org/openautonomousconnection/protocol/side/ins/ProtocolINSServer.java +++ b/src/main/java/org/openautonomousconnection/protocol/side/ins/ProtocolINSServer.java @@ -67,12 +67,12 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider { // Set default values for configuration properties if not already set 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(); } - if (!configurationManager.isSet("server.site.register")) { - configurationManager.set("server.site.register", "SERVER IP TO INS-FRONTEND WEBSITE"); + if (!configurationManager.isSet("server.site.frontend")) { + configurationManager.set("server.site.frontend", "SERVER IP TO INS-FRONTEND:PORT"); configurationManager.saveProperties(); } @@ -188,8 +188,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider { * @param sub An optional subname, or {@code null}. * @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. @@ -200,8 +199,7 @@ public abstract class ProtocolINSServer extends DefaultMethodsOverrider { * @param type The requested record type. * @param results The records returned to the client. */ - public void onResponseSent(String tln, String name, String sub, INSRecordType type, List results) { - } + public void onResponseSent(String tln, String name, String sub, INSRecordType type, List results) {} /** * 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 exception The exception describing the failure. */ - public void onResponseSentFailed(String tln, String name, String sub, INSRecordType type, List results, Exception exception) { - } + public void onResponseSentFailed(String tln, String name, String sub, INSRecordType type, List results, Exception exception) {} + + /** + * Resolves the information endpoint for a given Top-Level Name (TLN). + * + *

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. + * + *

The returned string must always be in the format: + *

+     *     host:port
+     * 
+ * + *

This method is used automatically by the INS protocol handler when a client + * queries an InfoName of the form: + *

+     *     info.<tln>
+     * 
+ * + *

If no TLN-specific info endpoint exists or the TLN does not exist, the implementation can: + *

    + *
  • return null to signal that no info site is registered
  • + *
+ * + * @param tln the top-level name for which the info site should be resolved. + * Must not be null. Case-insensitive. + * + * @return a string in "host:port" format representing the TLN's info endpoint, + * or null if the TLN has no registered info site. + */ + public abstract String resolveTLNInfoSite(String tln); /** * Gets the INS registration site URL from the configuration. * * @return The INS registration site URL. */ - public final String getINSRegisterSite() { - return configurationManager.getString("server.site.register"); + public final String getINSFrontendSite() { + return configurationManager.getString("server.site.frontend"); } /** diff --git a/src/main/java/org/openautonomousconnection/protocol/versions/v1_0_0/beta/INSRecord.java b/src/main/java/org/openautonomousconnection/protocol/versions/v1_0_0/beta/INSRecord.java index d326093..c61d20f 100644 --- a/src/main/java/org/openautonomousconnection/protocol/versions/v1_0_0/beta/INSRecord.java +++ b/src/main/java/org/openautonomousconnection/protocol/versions/v1_0_0/beta/INSRecord.java @@ -8,9 +8,9 @@ import java.io.Serializable; * This is the transport format used in responses and packets. * Each record contains: *
    - *
  • The record type (A, AAAA, CNAME, TXT, ...)
  • - *
  • A value (IPv4, IPv6, hostname, text, ...)
  • - *
  • Optional priority and weight fields (MX, SRV)
  • + *
  • The record type
  • + *
  • A value
  • + *
  • Optional priority and weight fields
  • *
  • Optional port field (SRV)
  • *
  • A TTL defining how long the record may be cached
  • *
diff --git a/src/main/java/org/openautonomousconnection/protocol/versions/v1_0_0/beta/INSRecordType.java b/src/main/java/org/openautonomousconnection/protocol/versions/v1_0_0/beta/INSRecordType.java index 36f186c..ee73c72 100644 --- a/src/main/java/org/openautonomousconnection/protocol/versions/v1_0_0/beta/INSRecordType.java +++ b/src/main/java/org/openautonomousconnection/protocol/versions/v1_0_0/beta/INSRecordType.java @@ -22,4 +22,5 @@ public enum INSRecordType { MX, SRV, NS, + INFO, }