go-waku/examples/chat2-reliable
Akhil 8ab0764350
feat: e2e reliable chat example POC (#1153)
2024-08-19 13:30:15 +04:00
..
build feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
pb feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
.gitignore feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
Makefile feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
README.md feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
chat.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
chat_reliability_test.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
exec.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
flags.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
go.mod feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
go.sum feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
main.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
options.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
peer_retrieval.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
reliability.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
rolling_bloom_filter.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
screen.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
test_utils.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00
ui.go feat: e2e reliable chat example POC (#1153) 2024-08-19 13:30:15 +04:00

README.md

chat2-reliable: A Reliable P2P Chat Application

Background

chat2-reliable is an enhanced version of a basic command-line chat application that uses the Waku v2 suite of protocols. This version implements an end-to-end reliability protocol to ensure message delivery and causal ordering in a distributed environment.

Features

  • P2P chat capabilities using Waku v2 protocols
  • Implementation of e2e reliability protocol
  • Support for group chats and direct communication
  • Scalable to large groups (up to 10K participants)
  • Transport-agnostic design

E2E Reliability Protocol

The e2e reliability protocol in chat2-reliable is an implementation of the proposal at Vac Forum and includes the following key features:

  1. Lamport Clocks: Each participant maintains a Lamport clock for logical timestamping of messages.

  2. Causal History: Messages include a short causal history (preceding message IDs) to establish causal relationships.

  3. Bloom Filters: A rolling bloom filter is used to track received message IDs and detect duplicates.

  4. Lazy Pull Mechanism: Missing messages are requested from peers when causal dependencies are unmet.

  5. Eager Push Mechanism: Unacknowledged messages are resent to ensure delivery.

Usage

Building the Application

make

Starting the Application

Basic usage:

./build/chat2-reliable

With custom DNS server:

./build/chat2-reliable --dns-discovery-name-server 8.8.8.8

In-chat Commands

  • /help: Display available commands
  • /connect: Interactively connect to a new peer
  • /peers: Display the list of connected peers

Example:

/connect /ip4/127.0.0.1/tcp/58426/p2p/16Uiu5rGt2QDLmPKas9zpsBgtr5kRzk473s9wkKSWoYwfcY4Hco33

Message Format

Messages in chat2-reliable use the following protobuf format:

message Message {
  string sender_id = 1;
  string message_id = 2;
  int32 lamport_timestamp = 3;
  repeated string causal_history = 4;
  string channel_id = 5;
  bytes bloom_filter = 6;
  string content = 7;
}

Implementation Details

  1. Lamport Clocks: Implemented in the Chat struct with methods to increment, update, and retrieve the timestamp.

  2. Causal History: Stored in the CausalHistory field of each message, containing IDs of recent preceding messages.

  3. Bloom Filters: Implemented as a RollingBloomFilter to efficiently track received messages and detect duplicates.

  4. Message Processing:

    • Incoming messages are checked against the bloom filter for duplicates.
    • Causal dependencies are verified before processing.
    • Messages with unmet dependencies are stored in an incoming buffer.
  5. Message Recovery:

    • Missing messages are requested from peers.
    • A retry mechanism with exponential backoff is implemented for failed retrievals.
  6. Conflict Resolution:

    • Messages are ordered based on Lamport timestamps and message IDs for consistency.
  7. Periodic Tasks:

    • Buffer sweeps to process buffered messages and resend unacknowledged ones.
    • Sync messages to maintain consistency across peers.

Testing

The implementation includes various tests to ensure the reliability features work as expected:

  • Lamport timestamp correctness
  • Causal ordering of messages
  • Duplicate detection using bloom filters
  • Message recovery after network partitions
  • Concurrent message sending
  • Large group scaling
  • Eager push mechanism effectiveness
  • Bloom filter window functionality
  • Conflict resolution
  • New node synchronization
go test -v