A distributed file storage system built in Go that allows for secure peer-to-peer file storage, retrieval, and distribution across a network.
This project implements a peer-to-peer distributed file server where files are stored across multiple nodes in the network. Each node can act as both a client and a server, allowing for decentralized file storage and retrieval. The system includes content-addressable storage (CAS) for efficient file management and basic peer discovery mechanisms.
- Peer-to-Peer Architecture: Nodes can connect directly to each other without a central server
- Content-Addressable Storage: Files are stored based on their content hash for efficient retrieval
- File Replication: Files are automatically replicated across the network for redundancy
- Bootstrap Mechanism: New nodes can join the network by connecting to known bootstrap nodes
- TCP Transport Layer: Reliable communication between nodes
Clone the repository and build the project:
git clone https://github.com/aniketh3014/gstore
cd gstore
make buildStart a node by running the built binary:
make runBy default, this will start two nodes on your local machine:
- One node listening on port 4000
- Another node listening on port 5000, connecting to the first node
To customize the node configuration, you can modify the main.go file to specify different:
- Port numbers
- Storage directories
- Bootstrap node addresses
The file server provides functions for storing and retrieving data:
// Store data
server.StoreData(key, dataReader)
// Retrieve data
size, reader, err := server.GetData(key)main.go: Entry point and demo setupfileserver.go: Core file server implementationstore.go: Storage management and content-addressable storagecrypto.go: Cryptographic utilitiesp2p/: Peer-to-peer networking componentstcp_transport.go: TCP-based transport layertransport.go: Transport interface definitionsmessage.go: Message format definitionsencoding.go: Encoding/decoding utilitieshandshaker.go: Connection handshake protocols
make testThe system is built around these main components:
- File Server: Manages file storage, retrieval, and network operations
- Store: Handles the local file system operations and implements content-addressable storage
- Transport Layer: Manages network communications between nodes
- Peer Management: Handles peer discovery and connection management
The system uses several message types for communication:
MessageStoreFile: Request to store a fileMessageGetFile: Request to retrieve a file
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- DHT (Distributed Hash Table) implementation for better node discovery
- File encryption and secure transfer
- Authentication and access control mechanisms
- Bandwidth optimization and file chunking
- Web interface for file management