diff --git a/src/main/java/org/openautonomousconnection/ins/DatabaseINSServer.java b/src/main/java/org/openautonomousconnection/ins/DatabaseINSServer.java index 652bd75..3b79587 100644 --- a/src/main/java/org/openautonomousconnection/ins/DatabaseINSServer.java +++ b/src/main/java/org/openautonomousconnection/ins/DatabaseINSServer.java @@ -1,7 +1,7 @@ package org.openautonomousconnection.ins; import dev.unlegitdqrk.unlegitlibrary.file.ConfigurationManager; -import org.openautonomousconnection.protocol.ProtocolBridge; +import org.openautonomousconnection.ins.utils.TargetName; import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecord; import org.openautonomousconnection.protocol.versions.v1_0_0.beta.INSRecordType; @@ -13,31 +13,6 @@ import java.sql.*; import java.util.ArrayList; import java.util.List; -/** - * Concrete INS server implementation backed by a SQL database. - *
- * This implementation expects a table schema similar to: - *
- * CREATE TABLE ins_records (
- * id BIGINT PRIMARY KEY AUTO_INCREMENT,
- * tln VARCHAR(64) NOT NULL,
- * name VARCHAR(255) NOT NULL,
- * sub VARCHAR(255) NULL,
- * type VARCHAR(16) NOT NULL, -- matches {@link INSRecordType#name()}
- * value VARCHAR(1024) NOT NULL,
- * priority INT NOT NULL,
- * weight INT NOT NULL,
- * port INT NOT NULL,
- * ttl INT NOT NULL
- * );
- *
- * CREATE TABLE ins_tln_info (
- * tln VARCHAR(64) PRIMARY KEY,
- * host VARCHAR(255) NOT NULL,
- * port INT NOT NULL
- * );
- *
- */
public final class DatabaseINSServer extends ProtocolINSServer {
private final String jdbcUrl;
@@ -59,7 +34,10 @@ public final class DatabaseINSServer extends ProtocolINSServer {
configurationManager.loadProperties();
if (!configurationManager.isSet("db.url")) {
- configurationManager.set("db.url", "jdbc:mysql://localhost:3306/DB_NAME?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC\n");
+ configurationManager.set(
+ "db.url",
+ "jdbc:mysql://localhost:3306/ins?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"
+ );
configurationManager.saveProperties();
}
@@ -83,70 +61,36 @@ public final class DatabaseINSServer extends ProtocolINSServer {
}
/**
- * Resolves records for the given INS name from the database.
+ * Resolves a request for an INS record based on TLN, name, subname and record type.
* - * This method does a single lookup and returns exactly the records that - * match the given query (no CNAME recursion here – that is handled on a - * higher level, e.g. via {@code INSRecordTools.resolveWithCNAME(...)}). - * - * @param tln Top-level-name. - * @param name InfoName. - * @param sub Optional sub-name. May be {@code null}. - * @param type Desired record type. - * - * @return List of matching {@link INSRecord}s, or an empty list if none exist. + * This implementation: + *
- * The result must be returned as {@code "host:port"}.
- *
- * @param tln The TLN the client is asking about.
- *
- * @return A {@code "host:port"} string or {@code null} if no TLN info site is configured.
+ * The value is read from {@code tln.info} and must be of the form
+ * {@code "host:port"}.
*/
@Override
public String resolveTLNInfoSite(String tln) {
- String sql = "SELECT host, port FROM ins_tln_info WHERE tln = ?";
+ String sql = "SELECT info FROM tln WHERE name = ?";
try (Connection conn = openConnection();
PreparedStatement ps = conn.prepareStatement(sql)) {
@@ -154,11 +98,7 @@ public final class DatabaseINSServer extends ProtocolINSServer {
ps.setString(1, tln);
try (ResultSet rs = ps.executeQuery()) {
- if (rs.next()) {
- String host = rs.getString("host");
- int port = rs.getInt("port");
- return host + ":" + port;
- }
+ if (rs.next()) return rs.getString("info"); // expected "host:port"
}
} catch (SQLException ex) {
getProtocolBridge().getLogger().exception("Failed to resolve TLN info site for tln=" + tln, ex);
@@ -166,4 +106,177 @@ public final class DatabaseINSServer extends ProtocolINSServer {
return null;
}
-}
+
+ private String formatName(String tln, String name, String sub) {
+ if (sub == null || sub.isEmpty()) return name + "." + tln;
+ return sub + "." + name + "." + tln;
+ }
+
+ /**
+ * Recursive resolver with CNAME handling and depth limit.
+ */
+ private List
+ *
+ * @param value Raw CNAME value from the {@code records} table.
+ * @return Parsed {@link TargetName} or {@code null} if the value is invalid.
+ */
+ private TargetName parseCnameTarget(String value) {
+ if (value == null) return null;
+ String trimmed = value.trim();
+ if (trimmed.isEmpty()) return null;
+
+ String[] parts = trimmed.split("\\.");
+ if (parts.length < 2) return null; // at least "