Skip to content

Commit fa96541

Browse files
committed
System Touch
1 parent 73cb973 commit fa96541

4 files changed

Lines changed: 111 additions & 3 deletions

File tree

configuration/nwe-config.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,21 @@
252252
<description>Production Bitcoin remote target.</description>
253253
</remote-server>
254254

255+
<!-- ═══════════════════════════════════════════════════════════════════
256+
OBJECT HASHCODE OVERRIDES
257+
Admins may set fixed Object IDs for well-known classes.
258+
These appear in the [Object ID: XXXXXXXXXX] field of system output.
259+
Format: <entry class="SimpleClassName">integer_value</entry>
260+
════════════════════════════════════════════════════════════════════ -->
261+
<hashcodes>
262+
<entry class="NitroWebExpress">0195600860</entry>
263+
<entry class="MessageQueueSorter">1343441044</entry>
264+
<entry class="MessageQueue">0762660330</entry>
265+
<entry class="HeuristicClassifier">0481230099</entry>
266+
<entry class="ConnectionPoller">0553219871</entry>
267+
<entry class="Communicator">0617340022</entry>
268+
<entry class="BinaryHttpServer">0889912345</entry>
269+
<entry class="WeatherServer">0721100456</entry>
270+
</hashcodes>
271+
255272
</nwe-config>

source/commons/printing/ComponentPrinter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public static void print(Object owner, int hash, String line) {
1818
String simple = owner.getClass().getSimpleName();
1919
String padded = padClassname(simple);
2020

21-
String hashStr = String.format("%010d", hash);
21+
int resolvedHash = configuration.HashCodeRegistry.resolve(owner);
22+
String hashStr = String.format("%010d", resolvedHash);
2223
String coloredHash = ColorResolver.resolveCategoryColor(simple) + hashStr + ColorPalette.OID_DEFAULT;
2324

2425
String date = timestamp();
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package configuration;
2+
3+
import org.w3c.dom.Document;
4+
import org.w3c.dom.Element;
5+
import org.w3c.dom.NodeList;
6+
7+
import javax.xml.parsers.DocumentBuilderFactory;
8+
import java.io.File;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
/**
13+
* HashCodeRegistry — loads admin-defined hashcodes from nwe-config.xml.
14+
*
15+
* Config format:
16+
* <hashcodes>
17+
* <entry class="NitroWebExpress">1234567890</entry>
18+
* <entry class="MessageQueueSorter">9876543210</entry>
19+
* </hashcodes>
20+
*
21+
* Call HashCodeRegistry.resolve(object) instead of object.hashCode()
22+
* to get the admin-overridden value (or default if not configured).
23+
*/
24+
public final class HashCodeRegistry
25+
{
26+
private static final String CONFIG_FILE = "configuration/nwe-config.xml";
27+
private static Map<String, Integer> OVERRIDES;
28+
29+
private HashCodeRegistry() {}
30+
31+
public static int resolve(Object owner)
32+
{
33+
if (OVERRIDES == null) load();
34+
String name = owner.getClass().getSimpleName();
35+
Integer override = OVERRIDES.get(name);
36+
return override != null ? override : owner.hashCode();
37+
}
38+
39+
private static synchronized void load()
40+
{
41+
OVERRIDES = new HashMap<>();
42+
try
43+
{
44+
File file = new File(CONFIG_FILE);
45+
if (!file.exists()) return;
46+
47+
Document doc = DocumentBuilderFactory.newInstance()
48+
.newDocumentBuilder().parse(file);
49+
doc.getDocumentElement().normalize();
50+
51+
NodeList hcNodes = doc.getElementsByTagName("hashcodes");
52+
if (hcNodes.getLength() == 0) return;
53+
54+
Element hcEl = (Element) hcNodes.item(0);
55+
NodeList entries = hcEl.getElementsByTagName("entry");
56+
for (int i = 0; i < entries.getLength(); i++)
57+
{
58+
Element entry = (Element) entries.item(i);
59+
String className = entry.getAttribute("class");
60+
String value = entry.getTextContent().trim();
61+
if (!className.isEmpty() && !value.isEmpty())
62+
{
63+
try { OVERRIDES.put(className, Integer.parseUnsignedInt(value)); }
64+
catch (NumberFormatException ignored) {}
65+
}
66+
}
67+
}
68+
catch (Exception ignored) {}
69+
}
70+
71+
/** Force reload (e.g. after config change). */
72+
public static void reload() { OVERRIDES = null; }
73+
}

source/national/NationalFinanceIDFeeder.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ private static void financePrompt(final Connection CONN, final NationalFinanceID
191191
write(CONN, " ║ Your effort today builds a better tomorrow. ║");
192192
write(CONN, " ╚══════════════════════════════════════════════════════════╝");
193193
write(CONN, "");
194+
// Close the telnet session
195+
try { if (CONN.SOCKET != null && !CONN.SOCKET.isClosed()) CONN.SOCKET.close(); }
196+
catch (Exception ignored) {}
194197
break;
195198
}
196199

@@ -277,8 +280,10 @@ private static String enterProxyMode(final Connection CONN, final NationalFinanc
277280
break;
278281
}
279282

280-
// Send to proxy
281-
proxyOut.write((userInput + "\r\n").getBytes());
283+
// Send to proxy — wrap in protocol framing if well-known port
284+
String toSend = configuration.ProtocolHandlerRegistry.wrapMessage(
285+
port, userInput, java.util.Map.of("host", host, "path", "/"));
286+
proxyOut.write(toSend.getBytes());
282287
proxyOut.flush();
283288

284289
// Read response (up to 4096 bytes, with timeout)
@@ -375,6 +380,18 @@ private static String handleSetProxy(final Connection CONN, final String INPUT,
375380
return "✗ Cannot connect to " + host + ":" + port + " — " + e.getMessage() + ". Keeping default.";
376381
}
377382

383+
// Verify the remote is running the expected protocol for well-known ports
384+
configuration.ProtocolHandlerRegistry.ProtocolHandler ph =
385+
configuration.ProtocolHandlerRegistry.get(port);
386+
if (ph != null)
387+
{
388+
boolean protocolOk = configuration.ProtocolHandlerRegistry.verify(host, port);
389+
if (protocolOk)
390+
write(CONN, " ✔ Protocol verified: " + ph.protocol + " on port " + port);
391+
else
392+
write(CONN, " ⚠ Port " + port + " connected but did not confirm " + ph.protocol + " protocol.");
393+
}
394+
378395
// Store selection
379396
N21Store.storeProxySelection(NFID.nationalId, host, port);
380397

0 commit comments

Comments
 (0)