Communication Server Internals
Overview
The Communication Server (droneengage_server) is a Node.js application that exchanges communication messages between different units and web clients via WebSocket connections. It maintains a persistent WebSocket connection to the authentication server for coordination.
Key Components
Communication Server Manager (server/js_comm_server_manager_client.js)
Acts as a WebSocket client to the authentication server:
Connection: Connects to
wss://s2s_ws_target_ip:s2s_ws_target_portAuto-reconnect: Automatically reconnects with retry interval (2000ms) on connection loss
Message Handling: Delegates incoming messages to registered handlers
Message Sending: Provides
fn_sendMessage()to send messages to the authentication server
Key Functions
fn_startServer()- Starts the WebSocket connection to authentication serverfn_onOpen_Handler()- Called when connection is establishedfn_onClose_Handler()- Handles connection close and triggers reconnectionfn_onMessage_Handler()- Delegates incoming messages tofn_onMessageReceivedcallbackfn_sendMessage()- Sends a message to the authentication server
Communication Server (server/js_andruav_comm_server.js)
Manages the communication server logic and coordination with the authentication server.
Waiting Accounts
m_waitingAccounts- Map of temporary login keys to pending login requestsKeys expire after
CONST_WAIT_PARTY_TO_CONNECT_TIMEOUT(10000ms)
Key Functions
isLoginExist(p_key)- Checks if a temporary login key exists in waiting listgetLogin(p_key)- Retrieves login request by temporary keydeleteLogin(p_key)- Removes login request from waiting listfn_addWaitingAccount(p_tempLoginKey, p_LoginRequest)- Adds a login request to waiting list with timeoutfn_decryptAuthMessage(p_msg)- Parses JSON message from authentication serverfn_generateLoginRequestReply(p_cmd)- Generates reply to login request from authentication serverfn_AuthServerConnectionHandler()- Called when authentication server connection is establishedfn_handleLoginResponses(p_cmd)- Processes login request from authentication serverfn_AuthServerMessagesHandler(p_msg)- Routes messages from authentication serverfn_updateServerWatchdog()- Sends server info to authentication serverfn_startServer()- Initializes and starts the communication server
fn_handleLoginResponses()
Processes a login request from the authentication server:
Generates a temporary login key (UUID without dashes)
Stores the login request in
m_waitingAccounts[tempKey]Generates a reply with the temporary key and server connection details
Sends the reply to the authentication server via WebSocket
fn_generateLoginRequestReply()
Builds the JSON reply sent to the authentication server:
{
"c": "b",
"d": {
"r": "request-id",
"e": 0,
"g": "communication-server-host",
"h": "communication-server-port",
"f": "temporary-login-key"
}
}
fn_updateServerWatchdog()
Sends server info to the authentication server:
{
"c": "a",
"d": {
"isOnline": true,
"version": "server-version",
"serverId": "server-id",
"public_host": "public-host",
"serverPort": "server-port",
"accounts": ["account-key-1", "account-key-2"]
}
}
This is sent periodically to keep the authentication server updated on the communication server status and served accounts.
Chat Server (server/chat_server/js_andruav_chat_server.js)
Handles WebSocket connections from authenticated clients.
fn_onConnect_Handler(p_ws, p_req)
Main WebSocket connection handler:
Extracts parameters from the request URL
Validates the temporary login key
If valid, accepts the connection and adds the client to the appropriate account room
fn_validateKey(p_params)
Validates the temporary login key:
Checks if the key exists in the URL parameters
Validates the key format (alphanumeric, max length 200)
Checks if the key exists in
m_waitingAccountsCloses the connection if validation fails
acceptConnection(v_loginTempKey, c_params, p_ws)
Accepts a validated connection:
Retrieves the login request using the temporary key
Builds an onboard object with account ID, group ID, request ID, actor type, permissions
Deletes the temporary key from
m_waitingAccounts(single-use)Calls
_acceptConnection()to add the client to the account roomNotifies the authentication server via
fn_onMessageOpened()
acceptLocalConnection(c_params, p_ws)
Accepts a local connection (when local_server_enabled=true):
Used for local server mode without authentication server
Generates local account and group IDs
Bypasses temporary key validation
Constants (js_constants.js)
Key constants used in communication:
CONST_CS_CMD_INFO- Server info command (a)CONST_CS_CMD_LOGIN_REQUEST- Login request command (b)CONST_CS_CMD_LOGOUT_REQUEST- Logout request command (c)CONST_CS_ACCOUNT_ID- Account ID field (a)CONST_CS_GROUP_ID- Group ID field (b)CONST_CS_SENDER_ID- Sender ID field (s)CONST_CS_LOGIN_TEMP_KEY- Temporary login key field (f)CONST_CS_ERROR- Error field (e)CONST_CS_SERVER_PUBLIC_HOST- Server host field (g)CONST_CS_SERVER_PORT- Server port field (h)CONST_CS_REQUEST_ID- Request ID field (r)
Configuration (server.config)
Key configuration fields:
server_id- Server identifierserver_ip- Listening IP (default:::)public_host- Public host/IP as seen by clientsserver_sid- Unique server ID for multi-server deploymentsserver_port- Listening port (default: 9966)enable_SSL- Enable SSL for client connectionss2s_ws_target_ip- Authentication server IP for S2S connections2s_ws_target_port- Authentication server port for S2S connectionssl_key_file- SSL private key file pathssl_cert_file- SSL certificate file pathallow_fake_SSL- Allow fake SSL (for testing only)ca_cert_path- Custom CA certificate pathignore_auth_server- Ignore authentication server (for local mode)local_server_enabled- Enable local server mode
Connection Flow
Server Startup
Communication server starts
Connects to authentication server via WebSocket
Sends server info (watchdog) to authentication server
Authentication server marks the communication server as online
Client Connection
Client authenticates with authentication server
Authentication server requests login reservation from communication server
Communication server generates temporary login key and stores in waiting list
Authentication server returns temporary key and connection details to client
Client connects to communication server WebSocket with temporary key
Communication server validates temporary key
Communication server accepts connection and adds client to account room
Temporary key is deleted (single-use)
Security Considerations
Temporary login keys are single-use and expire after timeout
SSL/TLS for client connections (configurable)
SSL/TLS for S2S connection to authentication server
Key validation before accepting WebSocket connections
Account room isolation prevents cross-account communication
Active sender tracking prevents duplicate connections