18. P2P Network (KortanaNet)
The Kortana P2P networking layer (KortanaNet) provides an authenticated, encrypted, and DDoS-resilient communication fabric connecting all distributed full nodes, validators, and RPC gateways.
18.1 Transport Layer
The Kortana transport architecture establishes a dual-channel communication model that segregates low-overhead network discovery from high-bandwidth consensus data replication. All network communication operates over standard Port 30303, multiplexing UDP and TCP sockets with dedicated operating system buffer optimizations.
UDP sockets are exclusively assigned to high-frequency peer discovery, liveness heartbeats, and distance routing queries. By keeping UDP datagrams lightweight and stateless, nodes can maintain network topology awareness without exhausting connection file descriptors. In contrast, all block gossip, transaction propagation, state synchronization, and BLS12-381 vote accumulation run across persistent, stream-oriented TCP sockets. TCP connections enforce strict kernel-level send/receive buffer boundaries, TCP nodelay (TCP_NODELAY) to minimize packet transmission latency, and keep-alive probes to detect silent link failures instantly.
18.2 Peer Discovery & Peer Table
KortanaNet locates distributed nodes using a modified Kademlia Distributed Hash Table (DHT) keyed by 256-bit node public key identifiers. The network topology organizes peers into discrete $k$-buckets based on the XOR metric distance between node IDs, ensuring logarithmic lookup latency across global networks.
To protect the network against Eclipse Attacks—where an adversary attempts to isolate a validator by populating all of its routing table entries with malicious nodes—the discovery engine enforces strict geographic and topological diversity filters. A single /24 IPv4 subnet (or /48 IPv6 prefix) is restricted to occupying a maximum of 2 slots in the active peer table. Furthermore, Autonomous System Number (ASN) tracking prevents multi-cloud Sybil campaigns from dominating peer tables. Nodes periodically issue random lookup queries to refresh dormant routing buckets and prune dead endpoints.
18.3 SIGMA Mutual Authentication & Encryption
Every TCP connection in KortanaNet is cryptographically authenticated and encrypted using the SIGMA (Sign-and-MAC) protocol before any consensus or transaction data can be exchanged. This eliminates man-in-the-middle attacks, eavesdropping, and connection spoofing at the transport layer.
During the SIGMA handshake, the initiating and responding nodes generate ephemeral secp256k1 key pairs and perform an Elliptic Curve Diffie-Hellman (ECDH) exchange. The resulting shared secret is fed into HKDF-SHA256 to derive symmetric encryption and MAC keys. Crucially, each peer signs the complete handshake transcript using its permanent node identity key and transmits the signature alongside its identity certificate under the newly established session cipher (AES-256-GCM). If the identity signature fails or the peer certificate is blacklisted, the socket is severed immediately without allocating application buffers.
18.4 Message Protocol & Framing
Network packets transmitted over KortanaNet utilize strict binary length-prefix framing designed for zero-copy deserialization and memory safety. Every protocol frame consists of an immutable 10-byte header: a 4-byte network magic number (0x4B544E01 for Mainnet), a 2-byte big-endian message type identifier, and a 4-byte payload length field.
To prevent memory exhaustion (OOM) denial-of-service attacks, the protocol enforces a hard ceiling of 16 MB on all network frames. If an incoming header declares a payload length exceeding 16,777,216 bytes, the connection handler aborts the read, logs a protocol violation, and closes the TCP socket before allocating any heap memory. Payloads passing validation are deserialized directly into fixed-size buffer arenas, preventing memory fragmentation during sustained high-throughput transaction gossip.
18.5 Peer Scoring
To maintain a healthy, high-performance network mesh, every Kortana node runs an internal Peer Reputation Engine. The engine assigns dynamic floating-point scores to each connected peer, continually updating scores based on observed network behavior.
Positive scoring credits are awarded for timely delivery of canonical block proposals, valid BLS12-381 Quorum Certificates, well-formed transactions that successfully enter the mempool, and rapid responses to sync requests. Conversely, severe penalties are assessed for broadcasting invalid blocks, malformed RLP frames, out-of-order nonces, duplicate messages, or failing liveness heartbeats. If a peer's score drops below a configurable disconnect threshold, the node gracefully drops the connection; if the score drops below a ban threshold, the remote IP is added to the kernel-level firewall blacklist for a mandatory cooldown period (typically 24 hours).
18.6 Gossip & Backpressure
Transactions and finalized block headers propagate throughout KortanaNet using an adaptive epidemic gossip protocol. When a node validates a new transaction or block, it broadcasts the message to a pseudo-random subset of its connected peers (the gossip fanout parameter, default sqrt(N)), ensuring exponential network propagation within milliseconds.
To prevent packet loss and thread starvation during massive transaction bursts, the networking layer implements bi-directional Socket Backpressure. When a node's internal worker queues or mempool ingestion pipelines reach 80% capacity, the transport manager halts reading from inbound peer sockets. This causes the operating system's TCP receive window to shrink, signaling upstream sending peers to throttle their transmission rates naturally through standard TCP flow control. Once internal queues clear, reading resumes automatically without dropping a single transaction.