Skip to content

RustDoIt/client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview of the client library

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.

Features

  • Modular clients with shared Processor logic 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 ClientError enum (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.

Architecture

Core Components

  • 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).

Client Details

WebBrowser

  • 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 }: If ServerType::TextServer, adds server to text_servers and forwards WebRequest::TextFilesListQuery; sends event NodeEvent::MessageReceived.
    • TextFilesList { files }: Sets file list for server.
    • TextFile { file_data }: Deserializes to TextFile, forwards WebRequest::MediaQuery for each media ref, caches file; if no refs, sends event WebEvent::File.
    • MediaFile { media_data }: Deserializes to MediaFile, associates with cached text file; if all media complete, sends event WebEvent::File; else sends WebEvent::MediaFile.
    • ErrorFileNotFound(uuid): Sends event WebEvent::FileNotFound { uuid }.
    • BadUuid(uuid): Sends event WebEvent::BadUuid { from, uuid }.
  • Commands (WebCommand variants):
    • QueryTextFilesList: Broadcasts WebRequest::TextFilesListQuery (discovers servers if empty).
    • GetTextFilesList: Sends event WebEvent::FilesLists { files_map: ... } with server file lists.
    • GetCachedFiles: Sends event WebEvent::CachedFiles { files: ... } with assembled files.
    • GetFile(uuid): If cached, sends event WebEvent::File; else forwards WebRequest::FileQuery.
    • GetTextFiles: Sends event WebEvent::TextFiles { files: ... } with cached text files.
    • GetTextFile(uuid): If cached, sends event WebEvent::TextFile; else forwards WebRequest::FileQuery.
    • GetMediaFiles: Sends event WebEvent::MediaFiles { files: ... } with all cached media.
    • GetMediaFile { media_id, location }: If cached, sends event WebEvent::MediaFile; else forwards WebRequest::MediaQuery to location.

ChatClient

  • 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 }: If ServerType::ChatServer, adds to communication_servers and forwards ChatRequest::ClientListQuery; sends event NodeEvent::MessageReceived.
    • ClientList { list_of_client_ids }: Adds clients to registered_clients for server, sends event ChatEvent::RegisteredClients { list: ... }.
    • MessageFrom { client_id, message }: Creates Message, sends event ChatEvent::MessageReceived { msg: ... }, inserts to history.
    • ErrorWrongClientId { wrong_id }: Sends event ChatEvent::ErrorClientNotFound { not_found: ... }.
    • RegistrationSuccess: Sends event ChatEvent::RegistrationSucceeded { to: ... }.
  • Commands (ChatCommand variants):
    • RegisterToServer(server_id): Forwards ChatRequest::RegistrationToChat { client_id } to server.
    • GetChatsHistory: Sends event ChatEvent::ChatHistory { history: ... } with all chats.
    • GetRegisteredClients: If servers empty, discovers via ChatRequest::ServerTypeQuery; if lists empty, broadcasts ChatRequest::ClientListQuery; else sends event ChatEvent::RegisteredClients { list: ... }.
    • SendMessage(message): If destination server found, forwards ChatRequest::MessageFor { client_id: message.to, message: message.text }, sends event ChatEvent::MessageSent { to: ... }, inserts to history; else sends ChatEvent::ErrorClientNotFound.

About

Drone developed by Matteo Bordignon (@Bordi00) for the Advanced Programming course.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages