P2P communication between participants
(Section: Ecosystem and Network)
1) Why P2P in the ecosystem
The P2P approach allows participants (operators, providers, studios, affiliates, validators/nodes, wallets, analytical and orchestration services) to exchange data and perform operations without the mandatory "central pipe," reducing bottlenecks, latency and dependence on individual points of failure. Key effects:- Resilience and fault tolerance: there is no single SPOF, it is easier to survive network/regional failures.
- Scalability as you grow: Each new member contributes resources (channels, computation, storage).
- Reducing the cost of delivery: traffic goes along the shortest paths, savings on centralized gateways.
- Data privacy and sovereignty: granular control over what and to whom to give.
2) P2P topologies
1. Fully connected (mesh) - high stability, but expensive in the number of channels (O (n ²)). Suitable for small groups with high exchange rates.
2. Super-peers - some peers take over routing/relaying, a compromise between mesh and star.
3. Cluster overlays - thematic sub-networks (for example, "provayder↔operator," "affiliat↔operator") connected by bridges (gateways).
4. DHT overlay - distributed table of routing/search for services and content, logarithmic complexity of search.
Recommendation: for an ecosystem with many roles - a hybrid: local mesh within "contract" groups (operator↔provayder), super-peers for routing, DHT for global search and Pub/Sub for events.
3) Network stack and protocols
Transport: QUIC/UDP (0-RTT summaries, loss tolerance, multiplexing), TCP (fallback), WebRTC (browsers, P2P media/datagrams).
Encryption: TLS 1. 3 for QUIC/TCP; for overlay - Noise/Libp2p-SECIO/ECDH + AEAD. End-to-End encryption over transport for private channels.
Identities: long-term node keys (ed25519/secp256k1), self-signed peer-ID, optionally X.509/PKI to meet compliance requirements.
Discovery and addressing: mDNS (LAN), DHT/Kademlia (WAN), static bootstraps (bootstrap peers), service directories/registries.
NAT traversal: STUN, UDP hole-punching, TURN/relay fallback, TCP hole-punching, port proxying through super-nodes.
- Req/Resp (RPC) for spot requests (price quotes, limits, payment statuses).
- Pub/Sub for events (transactions, game statuses, compliance alerts).
- Stream-muxing (yamux/mplex/QUIC) for parallel logical channels.
- CRDT/operational logs to reconcile caches and metadata without a "wizard."
4) NAT traversal and relay
Three-step strategy:1. Direct P2P: hole-punch attempt (UDP preferred, then TCP).
2. TURN/Relay via super-nodes: limit the volume, encrypt end-to-end, billing relay.
3. Fallback on HTTPS/HTTP3: tunneling through allowed corporate proxies, if required.
Monitor the proportion of direct vs relay connections as relay increases cost and latency.
5) Routing, search and discovery
DHT (Kademlia class): store only "pointers" (provider records), protect them with signatures, enter TTL and reading quorum.
Content-based routing: publishing keys of the form 'service: limits/operator: XYZ/region: TR'.
Private namespace: separate prefixes/keys for closed communities (partner overlays).
Anti-poisoning: validation of records by signatures of owners, reputation of publishing nodes, rate-limit publications.
6) Data models and reconciliation
Event-sourcing + Pub/Sub: all meaningful changes as idempotency-key events.
CRDT (GCounter, OR-Set, LWW-register): for configs, accesses, cached limits/quotes, which are edited by many participants.
Consensus is not always required: for reference books and metadata, "eventual consistency" is enough; for financial transactions - solid finalization (external register/blockchain/notary).
7) QoS, SLO and metrics
Network SLOs (example):- p99 latency P2P-RPC ≤ 250-400 ms (interregional ≤ 600 ms), success-rate ≥ 99. 5%.
- Pub/Sub end-to-end delay p95 ≤ 2 с.
- Relay share ≤ 30% (the goal is direct connectivity ≥ 70%).
- Churn resistance: loss of up to 20% of feasts without SLA degradation.
- Connectivity: percentage of achievable peers, percentage of direct connections, average number of neighbors.
- Path quality: RTT, Jitter, Packet loss; p95/p99 by service class.
- Throughput: average/peak bandwidth across streams.
- Reliability: reconnect rate, RPC error rate, Pub/Sub reordering/drop.
- Discovery health: DHT hit/miss, key resolution time, proportion of obsolete records.
- Security: share with E2E encryption, invalid signatures, rate anomalies.
- Cost: traffic via relay (GB/day), CTS per GB, CTS per RPC.
8) P2P security
Identities and trust: long-term peer-ID, binding to a legal entity (operator/provider), register of trusted keys; short-lived session keys.
Encryption: Transport TLS 1. 3/Noise + E2E over (Double-Ratchet, HPKE) for private channels.
Authorization: capability-tokens/pasta (tied to operations and volume), ACL by Pub/Sub topics.
Anti-Sybil and spam: proof-of-authority for "register" nodes, reputations/credit-limits, input captchas/payment pledges for open communities.
Channel abuse: circuit-breaker on traffic, leaky-bucket rate-limit on RPC and publish, "greylisting" noisy feasts.
Data verification: event signatures, merkle proofs for large batches, idempotency-key grandfather.
9) Engineering patterns
RPC idempotency: 'x-idempotency-key' + "at-least-once" delivery + deadpan at the receiver.
Backpressure: window-size by stream, priorities (money operations> telemetry).
Partial failure tolerance: fast timeout + half-modes of operation (read-only, cache-only, feature degradation).
Observability: p2p-hop traces, correlation IDs, export of metrics by OpenTelemetry.
json
{
"id": "evt_01J...",
"ts": "2025-10-31T18:25:43Z",
"topic": "limits. update/operator:ACME/region:TR",
"payload_hash": "sha256:...",
"payload": { "limit": 10000, "currency": "TRY", "valid_until": "2025-11-01T00:00:00Z" },
"sig": "ed25519:base64..."
}
10) Pub/Sub and gossip
Gossip networks for broadcast events: anti-duplication, random walk, subscription sliding windows.
Topics and politicians: separation of "public" and "private" topics; private - only for subscribers with ACLs.
Shipping: at-least-once warranty + deterministic deduplication at subscribers.
11) Storage and caching
Snapshots + logs: a quick cold start to the feast from the last snapshot and an event log lift.
Cache policies: TTL/ETag/schema versioning; validation by signature.
Edge cache: super-peers can store hot keys/state pieces by signing as "caching proxies."
12) Operation, monitoring and dashboards
Daily Ops:- Connectivity %, relay %, DHT hit/miss, RPC success/latency p95/p99, Pub/Sub delay, error rate, churn.
- Map of super-nodes (load, saturation, delays by region).
- Relay share trends, traffic cost, hot topics, E2E channel share, attacks/anomalies.
- NAT traversal efficiency (direct share), CTS per GB/RPC, super node expansion plan, compliance KPI (logging, storage).
13) Testing and quality
Chaos scenarios: shutdown% of super-nodes, artificial losses/jitter, loads on Pub/Sub.
Interop-matrix: SDK/protocol versions × NAT type × regions.
Fuzzing protocols: random fields/sizes, malicious payloads (in the sandbox).
Security-drills: leaking a peer key, compromising a super-node (republishing trust lists, revoking keys).
14) Compliance and legal aspects
Logging and immutability: log hash chains, timestamping, storage by region (data residency).
Data access control: minimization, encryption "at rest," DLP policies on topics, end-to-end pseudonymization of user attributes.
Right to delete/restrict: "tombstone-events" and "redaction-events" policy with cryptographic editing proofs.
Audit - Exports signed logs for external checks.
15) Network Economics and Billing
Cost model: relay traffic × GB, storage of snapshots, super-nodes as "supplier nodes" (compensation per GB/RPC).
Fair-usage: publishing and RPC quotas; paid "accelerated" channels/priorities.
Motivation for direct channels: discounts on P2P-direct, raising limits for "good citizens" of the network.
16) SLO/OKR Template (Quarter)
KR1: ≥ 75% of direct connections, DHT resolve p95 ≤ 300 ms.
KR2 (Performance): p99 RPC ≤ 400 ms globally; Pub/Sub p95 ≤ 2 с.
KR3: RPC success ≥ 99. 7%; churn-resistance to 20% of drops.
KR4 (Security): ≥ 95% of channels with E2E; 0 critical signature/substitution incidents.
KR5: relay traffic on 1 RPC − 20% QoQ; CTS per GB −15% QoQ.
17) Playbook incidents (cheat sheet)
Jump in relay share and increase in latency:- Enable aggressive hole-punch, change STUN pools, expand the geography of super-nodes, enable prioritization of critical topics.
- Reissue trusted keys of publishers, enable quorum of checks, clear outdated records, temporarily restrict publications from suspicious peers.
- Rate-limit + proof-of-work/fee-gate, gray list, overlay rebuild with new signature thresholds.
- Immediate recall, publication of "revoke-event," rotation of keys of dependent peers, recalculation of ACL.
18) Configuration Example (Pseudo-YAML)
yaml p2p:
transport: [quic, tcp]
encryption: [tls13, noise]
discovery:
bootstrap_peers:
- /dns4/bootstrap-1. ecosys/p2p/12D3KooW...
- /dns4/bootstrap-2. ecosys/p2p/12D3KooX...
dht: kademlia mdns: true nat_traversal:
stun_servers: [stun1. ecosys. net, stun2. ecosys. net]
turn_relays:
- turn1. ecosys. net
- turn2. ecosys. net hole_punching: {udp: true, tcp: true}
relay_threshold_pct: 30 pubsub:
engine: gossip topics:
- name: limits. update acl: allow: [operators, providers]
- name: payouts. status acl: allow: [operators]
security:
e2e_required_topics: [payouts. status, limits. update]
acls:
operators: [12D3KooA..., 12D3KooB...]
providers: [12D3KooC..., 12D3KooD...]
rate_limits:
rpc_per_minute: 600 publish_per_minute: 1200
19) Implementation checklist
1. Select the combined topology (mesh within + super-peers + DHT contract groups).
2. Raise bootstraps and super-knots in key regions, add STUN/TURN.
3. Define event formats, signatures, ACLs, and e2e policies.
4. Enable traces and metrics (RTT, relay-%, DHT-latency, RPC success).
5. Fix SLO/OKR, turn on burn-rate alert.
6. Spend chaos day: outages, losses, load on Pub/Sub.
7. Regulate key rotation, log audit, response procedure.
Bottom line: a well-designed P2P network in the ecosystem reduces dependence on central gateways, speeds up exchange and increases stability. By combining QUIC, DHT, Pub/Sub, E2E encryption, strict ACLs and measurable exploitation (SLO/metrics), you get a scalable and secure network fabric where each participant is a complete value node, not a passive client.