A distributed file-sharing application for local area networks (LANs) that enables peer-to-peer file discovery, transfer, and management across multiple network nodes.
This application implements a decentralized file-sharing system using IPv4 multicast for host discovery and file queries, combined with TCP for reliable file transfers. Network nodes communicate through a custom control plane protocol that maps user commands into orthogonal control plane messages.
- Host Discovery: Automatically discover and list all active application instances on the LAN
- File Search: Search for files across the combined file space of all connected nodes
- Exact path matching
- Filename matching
- Substring matching
- File Download: Download files from remote nodes to your local file space
- File Upload: Upload files from your local file space to remote nodes
- File Deletion: Delete files from remote nodes
- Multi-format Support: Transfer text files, images, videos, and other file types
The application uses three parallel communication channels:
- User Interface (UI): Text-based command interface for user input
- UDP Multicast: Connection-less discovery and control plane messaging
- TCP Unicast: Reliable file transfer between nodes
The control plane protocol follows a simple request/response mechanism:
- Multicast Channel: Used for discovery advertisements, file queries, and coordination
- TCP Channel: Used for actual file data transfer
- State Management: Request/response tracking using identifiers and serial numbers
- Modularity: Loosely coupled components for easy extension
- Simplicity: Short, orthogonal protocol messages for minimal bandwidth usage
- Scalability: Efficient for small to medium-sized LANs
- Resource Efficiency: Designed to work on resource-constrained devices
- Java Development Kit (JDK) 8 or higher
- Access to a local area network
- Multicast support on your network
javac Common/*.java Common/Message/*.java TCP/*.java Discovery/*.java UI/*.javajava UI.FileTreeBrowser <config-file>Example:
java UI.FileTreeBrowser host1.propertiesCreate a properties file with the following settings:
# Log file location
logFile=logs/node1.log
# Node identifier (will use hostname@FQDN if not specified)
#id=custom-identifier
# Root directory for file sharing
rootDir=/path/to/shared/directory
# TCP server port
tcpPort=12345
# Multicast address (default: 239.255.4.105)
mAddr=239.255.4.105
# Multicast port (default: 4105)
mPort=4105
# Discovery advertisement interval in seconds (default: 10)
advInterval=10:quit- Exit the application:nodes- List all active nodes on the network:search- Search for files across all nodes- Option 1: Exact path match
- Option 2: Filename match
- Option 3: Substring match
:download- Download a file from a remote node:upload- Upload a file to a remote node:delete- Delete files from remote nodes
- Start multiple instances on different machines with different configuration files
- List active nodes:
:nodes - Search for files:
:search > 2 (filename search) > image.jpg - Download a file:
:download > 1 (proceed) > node-id@hostname > /local/destination/path/ > /remote/source/path/file.txt
- Advertisement:
discovery-adv : <system-id>- Broadcast periodically to announce presence
- Request:
search-request : <search-type> : <search-string> - Response:
search-result : <response-id> : <file-path> : <completed-flag> - Error:
search-error : <response-id>
- Request:
download-request : <target-system-id> : <filepath> - Response:
download-result : <response-id> : <tcp-port-number> - Error:
download-error : <response-id>
- Request:
upload-request : <target-system-id> : <remote-path> : <local-path> - Response:
upload-result : <response-id> - Error:
upload-error : <response-id>
- Request:
delete-request : <target-system-id> : <filepath> - Response:
delete-result : <response-id> - Error:
delete-error : <response-id>
The protocol generates approximately 3 messages per operation on average. In a worst-case scenario with multicast duplication at layer 2 devices:
- Packets per host: 3n (where n = number of nodes)
- Total packets in transit: 3n² (quadratic growth)
This makes the system efficient for small to medium LANs but may experience performance degradation with very large numbers of nodes.
Average packets per operation:
- Discovery advertisement: 1 packet
- Search: 3 packets (1 request + 2 average responses)
- Download: 3 packets (request + response + TCP handshake)
- Upload: 5 packets (request + response + download mechanism)
- Delete: 2 packets (request + response)
- File path validation to prevent directory traversal attacks
- Session state management to prevent unauthorized file access
- Target identifier verification for request/response matching
- TLS/TCP: Encrypt file data during transfer
- DTLS: Secure multicast control messages
- Authentication: Implement node authentication mechanisms
- Random Serial Numbers: Use randomized starting serial numbers (similar to TCP sequence numbers)
The application uses separate threads for:
- User input handling
- Multicast message processing
- TCP server for file transfers
- Individual client handlers for concurrent downloads
- Request Tracking: Serial numbers and identifiers stored for pending operations
- Session State: Cached information for multi-step operations
- Connection Pooling: Multiple simultaneous TCP connections supported
- Timeout mechanisms for unreliable multicast responses (5-second default)
- Graceful handling of network failures
- Input validation and sanitization
.
├── Common/ # Shared utilities and core components
│ ├── ByteReader.java
│ ├── Configuration.java
│ ├── LogFileWriter.java
│ ├── MulticastEndpoint.java
│ ├── ProtocolRegex.java
│ ├── SearchResult.java
│ └── Message/ # Protocol message handling
│ ├── Message.java
│ ├── MessageBuilder.java
│ ├── MessageHandler.java
│ └── MessageSender.java
├── Discovery/ # Discovery protocol implementation
│ └── DiscoveryProtocol.java
├── TCP/ # TCP file transfer components
│ ├── ClientHandler.java
│ ├── TCPClient.java
│ └── TCPServer.java
├── UI/ # User interface
│ ├── FileTreeBrowser.java
│ └── *.properties # Configuration files
├── logs/ # Application logs
└── root_dir*/ # Example shared directories
- Network Scope: Limited to single LAN environments
- Scalability: Quadratic traffic growth (O(n²)) with large node counts
- Security: No built-in encryption or authentication
- Reliability: UDP multicast is best-effort (packet loss possible)
- Implement TLS/DTLS for secure communications
- Add user authentication and access control
- Support for WAN deployments with relay nodes
- Compressed file transfers
- Resume capability for interrupted transfers
- GUI interface
- File versioning and conflict resolution
This project is provided as-is for educational and demonstration purposes.
Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.