66 lines
4.4 KiB
Markdown
66 lines
4.4 KiB
Markdown
# Maximum Single-Packet `.bne` Event Example (`kind: 1`)
|
|
|
|
This document demonstrates the maximum size `kind: 1` Nostr event that fits into a **single 1,500-byte Ethernet IP frame** when converted to `.bne` binary format.
|
|
|
|
---
|
|
|
|
## 1. Byte Budget Breakdown
|
|
|
|
```
|
|
+-------------------------------------------------------------------------------+
|
|
| Component | Size (Bytes) |
|
|
+------------------------------------------------------+------------------------+
|
|
| Ethernet MTU Limit | 1500 bytes |
|
|
| Less IPv4 Header | - 20 bytes |
|
|
| Less UDP Header | - 8 bytes |
|
|
+------------------------------------------------------+------------------------+
|
|
| Maximum Usable UDP Datagram Size | 1472 bytes |
|
|
+------------------------------------------------------+------------------------+
|
|
| `.bne` Fixed Header (version, pubkey, created_at, | - 113 bytes |
|
|
| kind, tags_count, content_length, sig) | |
|
|
| Tag Array Overhead (`[["client", "bne-wire"]]`) | - 22 bytes |
|
|
+------------------------------------------------------+------------------------+
|
|
| NET AVAILABLE UTF-8 CONTENT CAPACITY | 1,337 bytes |
|
|
+------------------------------------------------------+------------------------+
|
|
| TOTAL `.bne` BINARY PAYLOAD SIZE | EXACTLY 1,472 BYTES |
|
|
+------------------------------------------------------+------------------------+
|
|
```
|
|
|
|
---
|
|
|
|
## 2. Equivalent JSON Event Representation
|
|
|
|
When encoded in standard Nostr JSON ([`NIP-01`](../nips/01.md:15)), this event is **1,728 bytes** (exceeding single-packet MTU due to hex expansion and JSON quotes/brackets). When transcoded to `.bne` binary format, it shrinks to **1,472 bytes**, fitting inside **1 single UDP packet**!
|
|
|
|
```json
|
|
{
|
|
"id": "426462725f7061636b65745f626f756e646172795f746573745f303030303030",
|
|
"pubkey": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
|
|
"created_at": 1772019044,
|
|
"kind": 1,
|
|
"tags": [
|
|
["client", "bne-wire"]
|
|
],
|
|
"content": "In decentralized communication networks, the physical substrate of hardware and IP networking defines the ultimate boundaries of efficiency. Standard Ethernet frames cap Maximum Transmission Unit (MTU) size at 1500 bytes. Subtracting IPv4 headers (20 bytes) and UDP headers (8 bytes) leaves exactly 1472 bytes of unfragmented payload capacity. Standard Nostr JSON events are heavily bloated by hexadecimal text encodings: a 32-byte public key expands to 64 ASCII hex bytes, and a 64-byte Schnorr signature expands to 128 ASCII hex bytes. In addition, JSON structural syntax—double quotes, commas, brackets, and escaped newlines—consumes precious bandwidth. By converting Nostr events into canonical Binary Nostr Events (.bne), fixed header fields (pubkey, created_at, kind, content_length) and the Schnorr signature are packed as raw byte slices. The fixed overhead of a .bne envelope is precisely 113 bytes. When aligned to 64-byte CPU cache lines and single-packet IP datagram boundaries, a .bne event can carry up to 1337 bytes of pure UTF-8 content in a single packet. This enables zero-copy kernel eBPF packet routing, eliminates TCP head-of-line blocking, and allows entire social notes, voice snippets, or cryptographic proofs to travel across mesh networks, satellite links, or local UDP broadcasts in a single atomic network frame without fragmentation.",
|
|
"sig": "4b57c22b1797b109530ffe5d04cabac468b1a5942873a5141334ecbc77694fc968a1b941979ba13602fceb1dad8014ab6469c6ae9cef0b5668cc23ad1449e103"
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## 3. Transcoded `.bne` Byte Wire Layout
|
|
|
|
```
|
|
Offset 0 [1B] : Version = 0x01
|
|
Offset 1 [32B] : Raw pubkey bytes = 79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
|
|
Offset 33 [8B] : created_at = 0x00000000699FA87C (1772019044)
|
|
Offset 41 [2B] : kind = 0x0001
|
|
Offset 43 [2B] : tags_count = 0x0001
|
|
Offset 45 [22B] : Tag 0: ["client", "bne-wire"] TLV bytes
|
|
Offset 67 [4B] : content_length = 0x00000539 (1,337 bytes)
|
|
Offset 71 [1337B]: "In decentralized communication networks..." UTF-8 string bytes
|
|
Offset 1408[64B] : Raw Schnorr signature bytes = 4b57c22b1797b109530ffe5d04...
|
|
|
|
TOTAL WIRE SIZE = 1,472 BYTES (100% UNFRAGMENTED SINGLE IP UDP DATAGRAM)
|
|
```
|