Note: The components
TCPServer,UDPServer,TCPClient, andUDPClientinside src/assignment-files are provided as part of the assignment specification. TheProxyand the inter-Proxy communication protocol are the author's implementation.
- Language: Java 8 (JDK 1.8)
| Component | Command Format | Description |
|---|---|---|
| Server | java [TCPServer | UDPServer] -port <num> -key <name> -value <val> |
Starts a Key-Value store on the specified port. |
Parameters:
| Parameter | Type | Description |
|---|---|---|
<num> |
Integer | The TCP/UDP port number for listening. |
<name> |
String | The key string (no whitespaces). |
<val> |
Integer | The integer value associated with the key. |
| Component | Command Format | Description |
|---|---|---|
| Client | java [TCPClient | UDPClient] -address <addr> -port <num> -command <cmd> |
Sends a request to the specified target. |
Parameters:
| Parameter | Type | Description |
|---|---|---|
<addr> |
String | The IP address/hostname of the target Server or Proxy. |
<num> |
Integer | The port number on which the target is listening. |
<cmd> |
String | The command string to be executed (e.g., "GET NAMES"). |
| Component | Command Format | Description |
|---|---|---|
| Proxy | java Proxy -port <port> -server <addr> <port> ... |
Starts the intermediary Proxy application. |
Launches the intermediary Proxy. It accepts connections from Clients (TCP/UDP) and forwards requests to the configured backend Servers or other Proxies.
Parameters:
| Parameter | Description |
|---|---|
-port <port> |
The port number on which this Proxy will listen for incoming Client requests (supports both TCP and UDP). |
-server <addr> <port> |
Specifies a neighbor Server or another Proxy to connect to. Note: <addr> <port> pair can be repeated multiple times to connect to many Servers/Proxies. |
- Format: All communication is strictly via text strings.
- Message Length: Commands and responses are each one line terminated by a newline character.
- UDP Limit: The entire UDP message must fit within a single datagram (1460 bytes).
- Hybrid Protocol Support:
TCPClientandUDPClientcan talk both toTCPServerandUDPServerviaProxy. - Server Behavior: Servers do not maintain connections—they disconnect and handle subsequent requests sequentially.
- Mesh Topology Support:
Proxysupports mesh topology managing requests and preventing loop requests. - Auto-Discovery:
Proxyimplements auto discovery on start detecting wether server passed in arguments isTCPServer,UDPServeror anotherProxy. - Data Aggregation (
GET NAMES): Collects all names (keys) from network using agregating inter-proxy protocol. - Smart Routing (
GET VALUE/SET): Propagate values across whole network so everthing is up to date. - Concurrency: by using ExecutorService implementation of interface Executor
Proxyhandles requests optimized. - Graceful Shutdown: by propagating command QUIT and checking it current state if it's still running or already received a QUIT request whole network can be shutted down without loop requests.
This custom protocol enables routing and logic between Proxy nodes.
Upon startup, the Proxy connects to its neighbors to identify their type.
- Request:
PROXY SYN <port> - Response (Proxy):
PROXY ACK - Response (Server):
NA(or error)
To support cyclic graphs, all routing commands include a trace of visited nodes.
- Logic: When a Proxy receives a request, it checks if its own address is in the
[visited_nodes]list.- If YES: Returns
NA(loop detected). - If NO: Appends its address to the list and forwards the request to neighbors.
- If YES: Returns
| Internal Command | Parameters | Description |
|---|---|---|
PROXY SYN |
<port> |
Handshake initialization. |
PROXY ACK |
- | Handshake confirmation. |
GET NAMES LIST |
- | Requests only the immediate list of keys from a neighbor (no recursion). |
PROXY GET NAMES |
<sender> [visited...] |
Full Aggregation. Recursively gathers keys from the network, avoiding visited nodes. |
PROXY GET VALUE |
<key> <sender> [visited...] |
Recursive Search. Hunts for a key deep in the network. |
PROXY SET |
<key> <val> <sender> [visited...] |
Recursive Write. Propagates a write request until the target server is found. |
The project includes a test scenario (start.bat) that verifies:
- Gathering All Keys: Merging lists from TCP and UDP sources.
- Searching the Whole Network: Finding keys located multiple hops away.
- Loop Protection: Querying non-existent keys in a cyclic graph (must return
NA, not hang). - Remote Editing: Modifying data on a remote server via Proxy.
- Connecting TCP & UDP: TCP Client accessing data from a UDP Server via Proxy.