nx_turn_relay.nx
buildroot/runtime/nx_turn_relay.nx
about
nx_turn_relay.nx -- Sovereign TURN relay foundation (RFC 5766/8656).
Arc 4 Phase A.1 per [[NISHI_BITS_UP_EXCEED_INDUSTRY]].
Closes the openrelay.metered.ca dependency that's currently
`slow-lane-grandfathered` in web_assets/video.js. Once nx_turn_relay
ships on Texas Synology + Hetzner Frankfurt VPS, the slow-lane
audit grader can flag any remaining openrelay reference as a real
violation per [[feedback-no-slow-lane-no-paid-priority]].
This file provides the message FRAMING layer:
- nx_turn_parse_allocate: parse a TURN ALLOCATE request
- nx_turn_build_allocate_success: build a 0x0103 success response
- nx_turn_build_allocate_error: build a 0x0113 error response
Future phases (per [[NISHI_S_CLASS_ROUTING_ROADMAP]] Q1):
- Phase A.2: SEND indication forwarding (relay → peer)
- Phase A.3: DATA indication (peer → relay → client)
- Phase A.4: CREATE-PERMISSION (allow specific peer IPs)
- Phase A.5: REFRESH (extend allocation lifetime)
- Phase A.6: CHANNEL-BIND (compact data channel)
- Phase B: short-term credentials (HMAC-SHA1 MESSAGE-INTEGRITY)
- Phase C: multi-egress + QUIC-on-443 fingerprint (slow-lane cardinal)
Patent-clean math: TURN is an IETF standard, royalty-free per
IETF IPR policy. We implement the wire format; no proprietary
extensions.
dependencies 0 imports · 1 importers
imports: none
imported by: nx_turn_msgintegrity.nx
structs
| none |
consts
| 39 | const NX_TURN_TYPE_ALLOCATE_REQUEST: i64 = 0x0003 |
| 40 | const NX_TURN_TYPE_ALLOCATE_SUCCESS: i64 = 0x0103 |
| 41 | const NX_TURN_TYPE_ALLOCATE_ERROR: i64 = 0x0113 |
| 42 | const NX_TURN_TYPE_REFRESH_REQUEST: i64 = 0x0004 |
| 43 | const NX_TURN_TYPE_SEND_INDICATION: i64 = 0x0016 |
| 44 | const NX_TURN_TYPE_DATA_INDICATION: i64 = 0x0017 |
| 45 | const NX_TURN_TYPE_CREATE_PERM_REQUEST: i64 = 0x0008 |
| 46 | const NX_TURN_TYPE_CHANNEL_BIND_REQUEST: i64 = 0x0009 |
| 49 | const NX_TURN_ATTR_MAPPED_ADDR: i64 = 0x0001 |
| 50 | const NX_TURN_ATTR_USERNAME: i64 = 0x0006 |
| 51 | const NX_TURN_ATTR_MESSAGE_INTEGRITY: i64 = 0x0008 |
| 52 | const NX_TURN_ATTR_ERROR_CODE: i64 = 0x0009 |
| 53 | const NX_TURN_ATTR_REALM: i64 = 0x0014 |
| 54 | const NX_TURN_ATTR_NONCE: i64 = 0x0015 |
| 55 | const NX_TURN_ATTR_XOR_RELAYED_ADDR: i64 = 0x0016 |
| 56 | const NX_TURN_ATTR_REQUESTED_TRANSPORT: i64 = 0x0019 |
| 57 | const NX_TURN_ATTR_DONT_FRAGMENT: i64 = 0x001A |
| 58 | const NX_TURN_ATTR_LIFETIME: i64 = 0x000D |
| 59 | const NX_TURN_ATTR_XOR_MAPPED_ADDR: i64 = 0x0020 |
| 60 | const NX_TURN_ATTR_SOFTWARE: i64 = 0x8022 |
| 63 | const NX_STUN_MAGIC: i64 = 0x2112A442 |
| 66 | const NX_TURN_TRANSPORT_UDP: i64 = 17 |
| 67 | const NX_TURN_TRANSPORT_TCP: i64 = 6 |
| 70 | const NX_TURN_FAMILY_IPV4: i64 = 0x01 |
| 71 | const NX_TURN_FAMILY_IPV6: i64 = 0x02 |
| 74 | const NX_TURN_VERDICT_OK_ALLOCATE: i64 = 1 |
| 75 | const NX_TURN_VERDICT_BAD_MAGIC: i64 = 2 |
| 76 | const NX_TURN_VERDICT_TOO_SHORT: i64 = 3 |
| 77 | const NX_TURN_VERDICT_UNKNOWN_TYPE: i64 = 4 |
| 78 | const NX_TURN_VERDICT_MISSING_TRANSPORT: i64 = 5 |
| 79 | const NX_TURN_VERDICT_UNSUPP_TRANSPORT: i64 = 6 |
| 349 | const NX_TURN_ATTR_XOR_PEER_ADDR: i64 = 0x0012 |
| 350 | const NX_TURN_ATTR_DATA: i64 = 0x0013 |
| 582 | const NX_TURN_TYPE_REFRESH_SUCCESS: i64 = 0x0104 |
| 583 | const NX_TURN_TYPE_REFRESH_ERROR: i64 = 0x0114 |
| 584 | const NX_TURN_TYPE_CREATE_PERM_SUCCESS: i64 = 0x0108 |
| 585 | const NX_TURN_TYPE_CREATE_PERM_ERROR: i64 = 0x0118 |
| 586 | const NX_TURN_TYPE_CHANNEL_BIND_SUCCESS: i64 = 0x0109 |
| 587 | const NX_TURN_TYPE_CHANNEL_BIND_ERROR: i64 = 0x0119 |
| 588 | const NX_TURN_ATTR_CHANNEL_NUMBER: i64 = 0x000C |
functions
| 84 | func _turn_read_be16(buf: *u8, off: i64) -> i64 |
| 90 | func _turn_write_be16(buf: *u8, off: i64, v: i64) -> i64 |
| 96 | func _turn_write_be32(buf: *u8, off: i64, v: i64) -> i64 called by 1: _turn_write_lifetime |
| 130 | func nx_turn_parse_allocate(buf: *u8, n: i64, |
| 192 | func _turn_write_xor_address(buf: *u8, off: i64, attr_type: i64, |
| 212 | func _turn_write_lifetime(buf: *u8, off: i64, lifetime_sec: i64) -> i64 |
| 229 | func nx_turn_build_allocate_success(out_buf: *u8, tx_id: *u8, called by 1: nx_turn_build_success_test calls 3: _turn_write_be16_turn_write_xor_address_turn_write_lifetime |
| 272 | func nx_turn_build_allocate_error(out_buf: *u8, tx_id: *u8, calls 1: _turn_write_be16 |
| 314 | func nx_turn_allocate_roundtrip_test(scratch: *u8) -> i64 |
| 355 | func _turn_write_data_attr(buf: *u8, off: i64, |
| 389 | func nx_turn_build_send_indication(out_buf: *u8, tx_id: *u8, called by 1: nx_turn_send_data_roundtrip_test calls 3: _turn_write_be16_turn_write_xor_address_turn_write_data_attr |
| 413 | func nx_turn_build_data_indication(out_buf: *u8, tx_id: *u8, called by 1: nx_turn_send_data_roundtrip_test calls 3: _turn_write_be16_turn_write_xor_address_turn_write_data_attr |
| 442 | func nx_turn_parse_indication(buf: *u8, n: i64, |
| 520 | func nx_turn_send_data_roundtrip_test(scratch: *u8) -> i64 |
| 593 | func nx_turn_build_refresh_request(out_buf: *u8, tx_id: *u8, |
| 607 | func nx_turn_parse_refresh(buf: *u8, n: i64, |
| 651 | func nx_turn_build_refresh_success(out_buf: *u8, tx_id: *u8, |
| 669 | func nx_turn_build_create_perm_request(out_buf: *u8, tx_id: *u8, |
| 683 | func nx_turn_build_create_perm_success(out_buf: *u8, tx_id: *u8) -> i64 calls 1: _turn_write_be16 |
| 698 | func nx_turn_build_channel_bind_request(out_buf: *u8, tx_id: *u8, |
| 721 | func nx_turn_build_channel_bind_success(out_buf: *u8, tx_id: *u8) -> i64 calls 1: _turn_write_be16 |
| 737 | func nx_turn_build_channel_data(out_buf: *u8, |
| 760 | func nx_turn_parse_channel_data(buf: *u8, n: i64, |
| 784 | func nx_turn_phase_a3_smoke(scratch: *u8) -> i64 |
| 861 | func nx_turn_build_success_test(scratch: *u8) -> i64 |