Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

JoshWheeler08/LAN-file-sharing-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LAN File Sharing System

A distributed file-sharing application for local area networks (LANs) that enables peer-to-peer file discovery, transfer, and management across multiple network nodes.

Overview

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.

Features

  • 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

Architecture

Communication Channels

The application uses three parallel communication channels:

  1. User Interface (UI): Text-based command interface for user input
  2. UDP Multicast: Connection-less discovery and control plane messaging
  3. TCP Unicast: Reliable file transfer between nodes

Protocol Design

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

Key Design Principles

  • 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

Installation

Prerequisites

  • Java Development Kit (JDK) 8 or higher
  • Access to a local area network
  • Multicast support on your network

Compilation

javac Common/*.java Common/Message/*.java TCP/*.java Discovery/*.java UI/*.java

Usage

Starting the Application

java UI.FileTreeBrowser <config-file>

Example:

java UI.FileTreeBrowser host1.properties

Configuration

Create 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

Available Commands

  • :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

Example Workflow

  1. Start multiple instances on different machines with different configuration files
  2. List active nodes:
    :nodes
    
  3. Search for files:
    :search
    > 2 (filename search)
    > image.jpg
    
  4. Download a file:
    :download
    > 1 (proceed)
    > node-id@hostname
    > /local/destination/path/
    > /remote/source/path/file.txt
    

Protocol Specification

Discovery Protocol

  • Advertisement: discovery-adv : <system-id>
    • Broadcast periodically to announce presence

Search Protocol

  • Request: search-request : <search-type> : <search-string>
  • Response: search-result : <response-id> : <file-path> : <completed-flag>
  • Error: search-error : <response-id>

Download Protocol

  • Request: download-request : <target-system-id> : <filepath>
  • Response: download-result : <response-id> : <tcp-port-number>
  • Error: download-error : <response-id>

Upload Protocol

  • Request: upload-request : <target-system-id> : <remote-path> : <local-path>
  • Response: upload-result : <response-id>
  • Error: upload-error : <response-id>

Delete Protocol

  • Request: delete-request : <target-system-id> : <filepath>
  • Response: delete-result : <response-id>
  • Error: delete-error : <response-id>

Performance Characteristics

Scalability

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.

Network Traffic Analysis

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)

Security Considerations

Current Implementation

  • File path validation to prevent directory traversal attacks
  • Session state management to prevent unauthorized file access
  • Target identifier verification for request/response matching

Potential Improvements

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

Technical Details

Threading Model

The application uses separate threads for:

  • User input handling
  • Multicast message processing
  • TCP server for file transfers
  • Individual client handlers for concurrent downloads

State Management

  • 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

Error Handling

  • Timeout mechanisms for unreliable multicast responses (5-second default)
  • Graceful handling of network failures
  • Input validation and sanitization

Project Structure

.
├── 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

Limitations

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

Future Enhancements

  • 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

License

This project is provided as-is for educational and demonstration purposes.

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.

About

A distributed file-sharing application for local area networks (LANs) that enables peer-to-peer file discovery, transfer, and management across multiple network nodes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages