A robust distributed file storage system implemented in Go, featuring peer-to-peer networking, encryption, and distributed storage capabilities.
This project implements a sophisticated distributed file storage system where multiple nodes work together to store, retrieve, and manage files across a network. Each node functions as both client and server, creating a true peer-to-peer network with built-in encryption for security.
- 🔗 Peer-to-peer architecture with dynamic node discovery
- 🔒 AES encryption for secure file storage
- 📁 Content-addressable storage using SHA-1 and MD5 hashing
- 🔄 Automatic file distribution across network nodes
- 🚀 Custom TCP-based transport layer
- 🔍 Distributed file retrieval with streaming support
- ⚡ Non-blocking concurrent operations
- 🔐 Secure file removal across the network
The project is organized into several core components:
- Initializes server instances with customizable configurations
- Processes user commands through an interactive CLI
- Manages node bootstrapping and peer connections
- Implements command validation and processing
- Handles core distributed storage operations
- Manages peer-to-peer message routing
- Implements file streaming and chunked transfer
- Coordinates network-wide file operations
- Provides content-addressable storage
- Manages local file system operations
- Implements path transformation and file handling
- Supports atomic file operations
- Implements AES-CTR encryption
- Provides secure key generation
- Handles stream-based encryption/decryption
- Includes MD5 hashing for file identification
- TCP Transport: Custom implementation for peer communication
- Message Handling: Defines RPC structures and protocols
- Stream Processing: Supports large file transfers
- Connection Management: Handles peer lifecycle
- Go 1.16 or higher
- Git
# Clone the repository
git clone https://github.com/ManManavadaria/Go_Distributed_Storage.git
cd Go_Distributed_Storage
# Install dependencies
go mod download
- For Windows:
go build -o dfss-build.exe
- For other OS:
go build -o dfss-build
- Start the first node:
./dfss-build.exe -port :3000 -nodes :4000,:5000
- Start additional nodes:
./dfss-build.exe -port :4000 -nodes :3000,:5000
./dfss-build.exe -port :5000 -nodes :4000,:3000
The system provides an interactive command interface with the following format:
action,key,content
Available commands:
- Write a file:
write,filename,content
- Read a file:
read,filename
- Remove a file:
remove,filename
Files are stored using a content-addressable system with a sophisticated path transformation:
func CASPathTransform(key string) PathKey {
hash := sha1.Sum([]byte(key))
hashStr := hex.EncodeToString(hash[:])
blockSize := 5
sliceLen := len(hashStr) / blockSize
paths := make([]string, sliceLen)
for i := 0; i < sliceLen; i++ {
from, to := i*blockSize, (i*blockSize)+blockSize
paths[i] = hashStr[from:to]
}
return PathKey{
PathName: strings.Join(paths, "/"),
FileName: hashStr,
}
}
The system uses AES-CTR mode encryption with streaming support:
func copyEncrypt(key []byte, src io.Reader, dst io.Writer) (int, error) {
block, err := aes.NewCipher(key)
// ... encryption setup
stream := cipher.NewCTR(block, iv)
return copyStream(stream, block.BlockSize(), src, dst)
}
Messages between nodes are handled through a custom RPC system:
type Message struct {
From string
Payload any
}
type MessageStoreFile struct {
Key string
Size int
}
- Nodes automatically connect to existing peers
- Dynamic peer management with concurrent connection handling
- Graceful connection lifecycle management
- End-to-end encryption for all stored files
- Secure key generation and management
- Stream-based encryption for efficient memory usage
- Content-addressable storage with SHA-1 hashing
- Automatic file replication across nodes
- Concurrent file operations handling
- Robust error management for network operations
- Graceful degradation on node failures
- Comprehensive error reporting
Contributions are welcome! Please feel free to submit a Pull Request.