@@ -161,6 +161,9 @@ public static NationalFinanceID greet(final Connection CONN)
161161
162162 private static void financePrompt (final Connection CONN , final NationalFinanceID NFID )
163163 {
164+ // Ensure proxy table exists
165+ N21Store .createUserProxySelectionsTable ();
166+
164167 write (CONN , "National ID Finance" );
165168 write (CONN , "" );
166169
@@ -175,6 +178,23 @@ private static void financePrompt(final Connection CONN, final NationalFinanceID
175178 cryptoPrompt (CONN , NFID );
176179 write (CONN , line + " < Returned from crypto management." );
177180 }
181+ else if (input .trim ().toLowerCase ().startsWith ("set proxy" ))
182+ {
183+ write (CONN , line + " < " + handleSetProxy (CONN , input , NFID ));
184+ }
185+ else if (input .trim ().toLowerCase ().startsWith ("clear proxy" ))
186+ {
187+ N21Store .clearProxySelection (NFID .nationalId );
188+ write (CONN , line + " < Proxy cleared. Using default (localhost)." );
189+ }
190+ else if (input .trim ().toLowerCase ().startsWith ("show proxy" ))
191+ {
192+ String [] sel = N21Store .loadProxySelection (NFID .nationalId );
193+ if (sel != null )
194+ write (CONN , line + " < Proxy: " + sel [0 ] + ":" + sel [1 ]);
195+ else
196+ write (CONN , line + " < No proxy set (using default localhost)." );
197+ }
178198 else
179199 {
180200 write (CONN , line + " < " + trade (input , NFID ));
@@ -183,6 +203,47 @@ private static void financePrompt(final Connection CONN, final NationalFinanceID
183203 }
184204 }
185205
206+ /**
207+ * Handles "set proxy <host> <port>" — validates host resolves and port is connectable,
208+ * stores in MySQL if OK, otherwise falls back to default.
209+ */
210+ private static String handleSetProxy (final Connection CONN , final String INPUT , final NationalFinanceID NFID )
211+ {
212+ // Parse: "set proxy host port"
213+ String [] parts = INPUT .trim ().split ("\\ s+" );
214+ if (parts .length < 4 )
215+ return "Usage: set proxy <host> <port>" ;
216+
217+ String host = parts [2 ];
218+ int port ;
219+ try { port = Integer .parseInt (parts [3 ]); }
220+ catch (NumberFormatException e ) { return "Invalid port number: " + parts [3 ]; }
221+
222+ if (port < 1 || port > 65535 )
223+ return "Port must be 1–65535." ;
224+
225+ // Validate host resolves
226+ try { java .net .InetAddress .getByName (host ); }
227+ catch (java .net .UnknownHostException e )
228+ {
229+ return "✗ Host '" + host + "' does not resolve. Keeping default." ;
230+ }
231+
232+ // Validate port is connectable (2s timeout)
233+ try (java .net .Socket test = new java .net .Socket ())
234+ {
235+ test .connect (new java .net .InetSocketAddress (host , port ), 2000 );
236+ }
237+ catch (Exception e )
238+ {
239+ return "✗ Cannot connect to " + host + ":" + port + " — " + e .getMessage () + ". Keeping default." ;
240+ }
241+
242+ // Store selection
243+ N21Store .storeProxySelection (NFID .nationalId , host , port );
244+ return "✔ Proxy set to " + host + ":" + port + " (verified reachable). Stored." ;
245+ }
246+
186247 /**
187248 * Produce a trading-context reply for the given input.
188249 * Recognises basic directives; anything else echoes a market acknowledgement.
@@ -205,14 +266,17 @@ private static String trade(final String INPUT, final NationalFinanceID NFID)
205266 "\r \n " +
206267 " Commands\r \n " +
207268 " ────────────────────────────────────────────────────\r \n " +
208- " buy <amount> Place a BUY order on the market\r \n " +
209- " sell <amount> Place a SELL order on the market\r \n " +
210- " balance Show your promissory note balance (USD)\r \n " +
211- " id Show your National ID and profile summary\r \n " +
212- " status Show full account status and trust level\r \n " +
213- " crypto Manage cryptographic keys (RSA/DSA/AES)\r \n " +
214- " help Show this command list\r \n " +
215- " quit / exit End this session\r \n " +
269+ " buy <amount> Place a BUY order on the market\r \n " +
270+ " sell <amount> Place a SELL order on the market\r \n " +
271+ " balance Show your promissory note balance (USD)\r \n " +
272+ " id Show your National ID and profile summary\r \n " +
273+ " status Show full account status and trust level\r \n " +
274+ " crypto Manage cryptographic keys (RSA/DSA/AES)\r \n " +
275+ " set proxy <host> <port> Set remote proxy (validated before storing)\r \n " +
276+ " show proxy Show current proxy selection\r \n " +
277+ " clear proxy Reset proxy to default (localhost)\r \n " +
278+ " help Show this command list\r \n " +
279+ " quit / exit End this session\r \n " +
216280 " ────────────────────────────────────────────────────" ;
217281
218282 // ─────────────────────────────────────────────────────────────────────────
0 commit comments