The client library implements Rust client nodes for web browsing and chatting in a drone-based networked system. It integrates with wg_internal for networking and common for shared utilities, using channels for communication and a routing handler for message routing.
Provides two client types:
- WebBrowser: Discovers text servers, retrieves and caches text/media files, assembles content.
- ChatClient: Discovers chat servers, registers clients, manages messaging and chat histories.
Both implement the Processor trait for packet processing, command handling, and event notifications.
- Modular clients with shared
Processorlogic for commands, packets, and fragmentation. - In-memory storage: HashMaps for server/file caches, client lists, chat histories; HashSets for server tracking.
- Response handling: Deserializes JSON responses (e.g.,
WebResponse,ChatResponse) and processes via routing/events. - Command system: Supports node operations (add/remove neighbors, shutdown) and client-specific actions (queries, retrievals, sends).
- Error management: Via
ClientErrorenum (network, fragmentation, protocol, timeout, etc.); handles invalid responses/IDs. - Request forwarding: Uses routing handler for targeted/broadcast sends; discovers servers via queries.
- Testing: Unit tests cover response handling (e.g., server types, lists, messages), command processing, and storage/caching.
- Processor Trait: Interface for receivers (commands, packets), assembler, routing handler, message/command handling.
- RoutingHandler: Manages neighbors and message sending (with optional destination/session ID).
- FragmentAssembler: Reassembles packet fragments.
- Types: From
common::types, includes commands/events (e.g.,NodeCommand,WebEvent), requests/responses. - Common Commands (NodeCommand): Handled by both clients.
AddSender(node_id, sender): Adds a neighbor to the routing handler.RemoveSender(node_id): Removes a neighbor from the routing handler.Shutdown: Signals termination (returns true to exit processing loop).
- Storage:
HashMap<NodeId, Vec<String>>for text server file lists (UUID:title);HashMap<TextFile, Vec<MediaFile>>for cached files. - Messages (WebResponse variants; received from servers):
ServerType { server_type }: IfServerType::TextServer, adds server to text_servers and forwardsWebRequest::TextFilesListQuery; sends eventNodeEvent::MessageReceived.TextFilesList { files }: Sets file list for server.TextFile { file_data }: Deserializes toTextFile, forwardsWebRequest::MediaQueryfor each media ref, caches file; if no refs, sends eventWebEvent::File.MediaFile { media_data }: Deserializes toMediaFile, associates with cached text file; if all media complete, sends eventWebEvent::File; else sendsWebEvent::MediaFile.ErrorFileNotFound(uuid): Sends eventWebEvent::FileNotFound { uuid }.BadUuid(uuid): Sends eventWebEvent::BadUuid { from, uuid }.
- Commands (WebCommand variants):
QueryTextFilesList: BroadcastsWebRequest::TextFilesListQuery(discovers servers if empty).GetTextFilesList: Sends eventWebEvent::FilesLists { files_map: ... }with server file lists.GetCachedFiles: Sends eventWebEvent::CachedFiles { files: ... }with assembled files.GetFile(uuid): If cached, sends eventWebEvent::File; else forwardsWebRequest::FileQuery.GetTextFiles: Sends eventWebEvent::TextFiles { files: ... }with cached text files.GetTextFile(uuid): If cached, sends eventWebEvent::TextFile; else forwardsWebRequest::FileQuery.GetMediaFiles: Sends eventWebEvent::MediaFiles { files: ... }with all cached media.GetMediaFile { media_id, location }: If cached, sends eventWebEvent::MediaFile; else forwardsWebRequest::MediaQueryto location.
- Storage:
HashMap<NodeId, Vec<NodeId>>for registered clients per server;HashSet<NodeId>for communication servers;HashMap<NodeId, Vec<Message>>for chat histories;VecDeque<ChatRequest>for pending requests. - Messages (ChatResponse variants; received from servers):
ServerType { server_type }: IfServerType::ChatServer, adds to communication_servers and forwardsChatRequest::ClientListQuery; sends eventNodeEvent::MessageReceived.ClientList { list_of_client_ids }: Adds clients to registered_clients for server, sends eventChatEvent::RegisteredClients { list: ... }.MessageFrom { client_id, message }: CreatesMessage, sends eventChatEvent::MessageReceived { msg: ... }, inserts to history.ErrorWrongClientId { wrong_id }: Sends eventChatEvent::ErrorClientNotFound { not_found: ... }.RegistrationSuccess: Sends eventChatEvent::RegistrationSucceeded { to: ... }.
- Commands (ChatCommand variants):
RegisterToServer(server_id): ForwardsChatRequest::RegistrationToChat { client_id }to server.GetChatsHistory: Sends eventChatEvent::ChatHistory { history: ... }with all chats.GetRegisteredClients: If servers empty, discovers viaChatRequest::ServerTypeQuery; if lists empty, broadcastsChatRequest::ClientListQuery; else sends eventChatEvent::RegisteredClients { list: ... }.SendMessage(message): If destination server found, forwardsChatRequest::MessageFor { client_id: message.to, message: message.text }, sends eventChatEvent::MessageSent { to: ... }, inserts to history; else sendsChatEvent::ErrorClientNotFound.