Pruthvi Prakash Navada
This project implements a distributed peer-to-peer system with membership management, leader election, and fault tolerance. The system utilizes both TCP and UDP for communication, implements heartbeat-based failure detection, and maintains consistency through a view-based approach.
.
├── Dockerfile
├── docker-compose-testcase-1.yml
├── docker-compose-testcase-2.yml
├── docker-compose-testcase-3.yml
├── docker-compose-testcase-4.yml
├── hostsfile.txt
├── main.go
└── peer/
├── config/
│ └── config.go
├── datastructures/
│ ├── safelist.go
│ └── safevalue.go
├── handlers/
│ └── messagehandler.go
├── network/
│ ├── connection.go
│ └── peer.go
├── types/
│ └── types.go
└── utils/
└── utils.go
- Docker
- Docker Compose
- Go 1.18 or higher (for local development)
# Build the Docker image
docker build -t prj3 .
The system includes four different test scenarios, each with its own docker-compose file:
# Test Case 1: Basic Join Operations
docker-compose -f docker-compose-testcase-1.yml up
# Test Case 2: Single Node Failure
docker-compose -f docker-compose-testcase-2.yml up
# Test Case 3: Multiple Node Failures
docker-compose -f docker-compose-testcase-3.yml up
# Test Case 4: Leader Failure with Message Loss
docker-compose -f docker-compose-testcase-4.yml up
The program accepts the following command-line flags:
-h string
: Path to the hosts file (required)-d int
: Initial delay in seconds (default: 0)-c int
: Crash delay in seconds-t bool
: Trigger crash simulation
- TCP Port: 8080 (membership management)
- UDP Port: 8081 (heartbeat messages)
- Heartbeat Interval: 1.1 seconds
- Monitor Interval: 2.2 seconds
-
Membership Management
- View-based consistency
- Quorum-based acknowledgments
- Member addition/removal
-
Failure Detection
- Heartbeat-based monitoring
- UDP broadcast for efficiency
- Configurable monitoring intervals
-
Leader Election
- Automatic leader election on failure
- State synchronization after election
- Pending operation recovery
-
Network Configuration
- Ensure ports 8080 and 8081 are available
- Docker network must support UDP broadcast
- Hostname resolution must be functional
-
Safety Mechanisms
- Thread-safe data structures
- Mutex-protected state changes
- Atomic view updates
-
Failure Handling
- Graceful handling of network partitions
- Recovery from message loss
- State consistency maintenance
-
Network Errors
Error starting TCP listener: address already in use Error reading from UDP connection: connection refused Error getting hostname from address: no such host
-
State Errors
Error: member ID not found in peerIdToName map Error encoding integer: invalid argument Error decoding byte array to integers: unexpected EOF
The system includes four test scenarios:
-
Test Case 1: Basic membership protocol
- Tests join operations
- Verifies view synchronization
- Validates message handling
-
Test Case 2: Single node failure
- Tests failure detection
- Verifies member removal
- Validates state updates
-
Test Case 3: Multiple node failures
- Tests multiple node failures
- Verifies member removal
- Validates state updates
-
Test Case 4: Leader failure with message loss
- Tests leader failure handling
- Verifies message loss recovery
- Validates consistency maintenance