Skip to content

Commit c059937

Browse files
committed
System Touch
1 parent a62a374 commit c059937

14 files changed

Lines changed: 1658 additions & 2 deletions
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
Middle Director Module Configuration
4+
=====================================
5+
Defines the synchronization modules for finance and target goals
6+
consumed on port 8888.
7+
-->
8+
<middle-director port="8888">
9+
<module name="ShortHops" class="middle.director.ShortHopsModule"
10+
description="Short-range finance synchronization hops between middle nodes"/>
11+
<module name="MediumHops" class="middle.director.MediumHopsModule"
12+
description="Medium-range goal synchronization across regional nodes"/>
13+
<module name="ThoughtsAsGoals" class="middle.director.ThoughtsAsGoalsModule"
14+
description="Converts thought patterns into actionable finance goals"/>
15+
<module name="FinalMediumHops" class="middle.director.FinalMediumHopsModule"
16+
description="Final medium-range hops before national module delivery"/>
17+
<module name="GamesAsGoals" class="middle.director.GamesAsGoalsModule"
18+
description="Gamified goal tracking and achievement synchronization"/>
19+
<module name="AuditorContent" class="middle.director.AuditorContentModule"
20+
description="Auditor content verification and goal compliance"/>
21+
22+
<targets>
23+
<target type="middle" description="Forward to other middle nodes on port 8888"/>
24+
<target type="national" description="Forward to final NWE installations on port 49152"/>
25+
</targets>
26+
</middle-director>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
Short Hops Module — Trade Definitions
4+
======================================
5+
Trades that lead to quick observable results.
6+
Each trade type is a loadable sub-module within ShortHopsModule.
7+
-->
8+
<short-hops>
9+
<trade name="Contract" type="document"
10+
description="Legally binding contract documents for immediate execution"/>
11+
<trade name="Legal" type="document"
12+
description="Legal filings, affidavits, and court-ready documents"/>
13+
<trade name="Monies" type="financial"
14+
description="Direct monetary transfers and payment settlements"/>
15+
<trade name="Resumes" type="document"
16+
description="Employment resumes and professional credentials"/>
17+
<trade name="Willingness" type="intent"
18+
description="Declarations of intent or readiness to transact"/>
19+
<trade name="Trades" type="financial"
20+
description="Active trade executions with immediate observable outcome"/>
21+
<trade name="Quits" type="termination"
22+
description="Termination of active positions, contracts, or engagements"/>
23+
</short-hops>

logging/clamav.log

Lines changed: 1115 additions & 0 deletions
Large diffs are not rendered by default.

source/connections/Connection.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class Connection implements AutoCloseable
5151
/** Active session protocol (HTTP, HTTPS, FTP, etc.) — null means RAW/no wrapping. */
5252
public String protocol;
5353

54+
/** Active HTTP method (GET, POST) — null means raw binary passthrough. */
55+
public String httpMethod;
56+
5457
public telnet.TelnetLineEditor lineEditor;
5558

5659
public Connection()
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package middle;
2+
3+
import commons.CommonRails;
4+
import middle.director.*;
5+
6+
import java.io.*;
7+
import java.net.InetAddress;
8+
import java.net.ServerSocket;
9+
import java.net.Socket;
10+
import java.util.List;
11+
import java.util.concurrent.CopyOnWriteArrayList;
12+
13+
/**
14+
* MiddleDirectorServer — listens on port 8888, synchronizes finance and target goals
15+
* across middle nodes and forwards finalized content to national NWE installations (49152).
16+
*
17+
* Modules are loaded from configuration/middle-director-modules.xml.
18+
*/
19+
public class MiddleDirectorServer extends Thread
20+
{
21+
public static final int PORT = 8888;
22+
23+
private final String HOST;
24+
private ServerSocket serverSocket;
25+
26+
/** Active director modules. */
27+
private final List<DirectorModule> modules = new CopyOnWriteArrayList<>();
28+
29+
/** Known peer middle nodes (host:port). */
30+
private final List<String> middlePeers = new CopyOnWriteArrayList<>();
31+
32+
/** Known national NWE endpoints (host:49152). */
33+
private final List<String> nationalEndpoints = new CopyOnWriteArrayList<>();
34+
35+
public MiddleDirectorServer(final String HOST)
36+
{
37+
this.HOST = HOST;
38+
this.setName("MiddleDirectorServer-8888");
39+
this.setDaemon(true);
40+
loadModules();
41+
}
42+
43+
private void loadModules()
44+
{
45+
modules.add(new ShortHopsModule());
46+
modules.add(new MediumHopsModule());
47+
modules.add(new ThoughtsAsGoalsModule());
48+
modules.add(new FinalMediumHopsModule());
49+
modules.add(new GamesAsGoalsModule());
50+
modules.add(new AuditorContentModule());
51+
}
52+
53+
@Override
54+
public void run()
55+
{
56+
try
57+
{
58+
serverSocket = new ServerSocket(PORT, 64, InetAddress.getByName(HOST));
59+
CommonRails.printSystemComponent(this, this.hashCode(),
60+
". MiddleDirectorServer listening on " + HOST + ":" + PORT + " .");
61+
62+
while (!Thread.currentThread().isInterrupted())
63+
{
64+
Socket client = serverSocket.accept();
65+
Thread.ofVirtual().start(() -> handle(client));
66+
}
67+
}
68+
catch (IOException e) { exceptions.ExceptionHandler.dispatch(e); }
69+
}
70+
71+
private void handle(final Socket CLIENT)
72+
{
73+
try (
74+
BufferedReader in = new BufferedReader(new InputStreamReader(CLIENT.getInputStream()));
75+
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(CLIENT.getOutputStream()))
76+
)
77+
{
78+
String line;
79+
while ((line = in.readLine()) != null)
80+
{
81+
line = line.trim();
82+
if (line.isEmpty()) continue;
83+
if (line.equalsIgnoreCase("quit")) break;
84+
85+
String result = processGoal(line);
86+
out.write(result + "\r\n");
87+
out.flush();
88+
}
89+
}
90+
catch (Exception e) { exceptions.ExceptionHandler.dispatch(e); }
91+
finally { try { CLIENT.close(); } catch (Exception ignored) {} }
92+
}
93+
94+
/**
95+
* Passes content through each module in sequence, then routes the result.
96+
*/
97+
private String processGoal(final String INPUT)
98+
{
99+
String payload = INPUT;
100+
for (DirectorModule module : modules)
101+
{
102+
payload = module.process(payload);
103+
}
104+
return payload;
105+
}
106+
107+
// ── Forwarding ───────────────────────────────────────────────────────────
108+
109+
/** Send content to another middle node. */
110+
public void sendToMiddle(final String HOST, final int PORT, final String CONTENT)
111+
{
112+
forward(HOST, PORT, CONTENT);
113+
}
114+
115+
/** Send content to a national NWE installation (port 49152). */
116+
public void sendToNational(final String HOST, final String CONTENT)
117+
{
118+
forward(HOST, 49152, CONTENT);
119+
}
120+
121+
private void forward(final String HOST, final int PORT, final String CONTENT)
122+
{
123+
try (Socket s = new Socket(HOST, PORT);
124+
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(s.getOutputStream())))
125+
{
126+
w.write(CONTENT + "\r\n");
127+
w.flush();
128+
CommonRails.printSystemComponent(this, this.hashCode(),
129+
". MiddleDirector forwarded to " + HOST + ":" + PORT + " .");
130+
}
131+
catch (IOException e) { exceptions.ExceptionHandler.dispatch(e); }
132+
}
133+
134+
public void addMiddlePeer(String hostPort) { middlePeers.add(hostPort); }
135+
public void addNationalEndpoint(String host) { nationalEndpoints.add(host); }
136+
public List<String> getMiddlePeers() { return middlePeers; }
137+
public List<String> getNationalEndpoints() { return nationalEndpoints; }
138+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package middle.director;
2+
3+
/** Auditor content verification and goal compliance. */
4+
public class AuditorContentModule implements DirectorModule
5+
{
6+
@Override public String name() { return "AuditorContent"; }
7+
8+
@Override
9+
public String process(String input)
10+
{
11+
return "[Auditor] " + input;
12+
}
13+
14+
public String processAndRecord(String input, long nationalId, String ip,
15+
String publicKey, long signatoryId, String signatoryKey,
16+
boolean employed, boolean democrat)
17+
{
18+
recordTrade("audit", nationalId, ip, publicKey, signatoryId, signatoryKey, employed, democrat);
19+
return "[Auditor] " + input;
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package middle.director;
2+
3+
/**
4+
* Base interface for all Middle Director modules.
5+
* Each module processes finance/goal synchronization content in sequence
6+
* and persists trade records via DirectorPersistence.
7+
*/
8+
public interface DirectorModule
9+
{
10+
String name();
11+
String process(String input);
12+
13+
/** Record a trade with full identity and status fields. */
14+
default void recordTrade(String tradeType, long nationalId, String ip,
15+
String publicKey, long signatoryId, String signatoryKey,
16+
boolean employed, boolean democrat)
17+
{
18+
DirectorPersistence.saveTrade(name(), tradeType, nationalId, ip,
19+
publicKey, signatoryId, signatoryKey, employed, democrat);
20+
}
21+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package middle.director;
2+
3+
import java.io.*;
4+
import java.nio.file.*;
5+
import java.time.LocalDateTime;
6+
import java.time.format.DateTimeFormatter;
7+
import java.util.StringJoiner;
8+
9+
/**
10+
* Persistent storage for director module trade records.
11+
* Saves to relative CSV files under data/middle/director/.
12+
*
13+
* Record fields:
14+
* timestamp, tradeType, nationalId, ipAddress, publicKey, signatoryId,
15+
* signatoryKey, employmentStatus (binary 0/1), democratStatus (binary 0/1)
16+
*/
17+
public class DirectorPersistence
18+
{
19+
private static final String BASE_DIR = "data/middle/director";
20+
private static final DateTimeFormatter FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
21+
22+
static { init(); }
23+
24+
private static void init()
25+
{
26+
try { Files.createDirectories(Path.of(BASE_DIR)); }
27+
catch (IOException e) { exceptions.ExceptionHandler.dispatch(e); }
28+
}
29+
30+
/**
31+
* Persist a trade record to the module's CSV file.
32+
*/
33+
public static synchronized void saveTrade(
34+
String moduleName,
35+
String tradeType,
36+
long nationalId,
37+
String ipAddress,
38+
String publicKey,
39+
long signatoryId,
40+
String signatoryKey,
41+
boolean employed,
42+
boolean democrat
43+
)
44+
{
45+
Path file = Path.of(BASE_DIR, moduleName + "-trades.csv");
46+
boolean newFile = !Files.exists(file);
47+
48+
try (BufferedWriter w = Files.newBufferedWriter(file,
49+
StandardOpenOption.CREATE, StandardOpenOption.APPEND))
50+
{
51+
if (newFile)
52+
w.write("timestamp,tradeType,nationalId,ipAddress,publicKey,signatoryId,signatoryKey,employmentStatus,democratStatus\n");
53+
54+
StringJoiner row = new StringJoiner(",");
55+
row.add(LocalDateTime.now().format(FMT));
56+
row.add(escape(tradeType));
57+
row.add(String.valueOf(nationalId));
58+
row.add(escape(ipAddress));
59+
row.add(escape(publicKey));
60+
row.add(String.valueOf(signatoryId));
61+
row.add(escape(signatoryKey));
62+
row.add(employed ? "1" : "0");
63+
row.add(democrat ? "1" : "0");
64+
w.write(row + "\n");
65+
}
66+
catch (IOException e) { exceptions.ExceptionHandler.dispatch(e); }
67+
}
68+
69+
private static String escape(String val)
70+
{
71+
if (val == null) return "";
72+
if (val.contains(",") || val.contains("\""))
73+
return "\"" + val.replace("\"", "\"\"") + "\"";
74+
return val;
75+
}
76+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package middle.director;
2+
3+
/** Final medium-range hops before national module delivery. */
4+
public class FinalMediumHopsModule implements DirectorModule
5+
{
6+
@Override public String name() { return "FinalMediumHops"; }
7+
8+
@Override
9+
public String process(String input)
10+
{
11+
return "[FinalMediumHop] " + input;
12+
}
13+
14+
public String processAndRecord(String input, long nationalId, String ip,
15+
String publicKey, long signatoryId, String signatoryKey,
16+
boolean employed, boolean democrat)
17+
{
18+
recordTrade("finalmedium", nationalId, ip, publicKey, signatoryId, signatoryKey, employed, democrat);
19+
return "[FinalMediumHop] " + input;
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package middle.director;
2+
3+
/** Gamified goal tracking and achievement synchronization. */
4+
public class GamesAsGoalsModule implements DirectorModule
5+
{
6+
@Override public String name() { return "GamesAsGoals"; }
7+
8+
@Override
9+
public String process(String input)
10+
{
11+
return "[GameGoal] " + input;
12+
}
13+
14+
public String processAndRecord(String input, long nationalId, String ip,
15+
String publicKey, long signatoryId, String signatoryKey,
16+
boolean employed, boolean democrat)
17+
{
18+
recordTrade("game", nationalId, ip, publicKey, signatoryId, signatoryKey, employed, democrat);
19+
return "[GameGoal] " + input;
20+
}
21+
}

0 commit comments

Comments
 (0)