tiny.reticulum.node.transport.relay
Defined in node.transport.
API (4)
Actions
Public operations.
applies: Answers whether an arriving packet is one for this node to move onward, so the receive path tells a packet this node carries for others from one addressed to the node itself.proof: Relays a proof along its reverse entry, following Reticulum@1.5.0 RNS/Transport.py:2670-2679, so the proof travels back along the way its packet came as the only route the sender is reachable by.run: Forwards or strips one packet, following Reticulum@1.5.0 RNS/Transport.py:1929-1946,2012-2028, so the packet moves a hop closer to its destination and the step records the way back for the proof.
Types and contracts
Public types and contracts.
Outcome: Whether a packet under a HEADER_2 header went out toward the next hop its path names, so the receive path tells a packet that went onward from one it has to handle itself.
Source
Source: lib/reticulum/src/node/transport/relay.zig
zig
const std = @import("std");const reticulum = @import("../../root.zig");const carrier = reticulum.carrier;const node = reticulum.node;const packet = reticulum.packet;const wire = reticulum.wire;/// Whether a packet under a HEADER_2 header went out toward the next hop its/// path names, so the receive path tells a packet that went onward from one it/// has to handle itself.pub const Outcome = enum { relayed, unrouted,};/// Answers whether an arriving packet is one for this node to move onward, so/// the receive path tells a packet this node carries for others from one/// addressed to the node itself. The condition holds when the node carries/// traffic for others, the packet names a node it is crossing, the packet is no/// announce, and its destination belongs to no address of this node.pub fn applies(node_owner: *node.Node, value: wire.Packet) bool { if (!node_owner.transport.enabled) return false; if (value.transport_id == null) return false; if (value.packet_type == .announce) return false; return node_owner.destinations.find(value.destination) == null;}/// Forwards or strips one packet, following Reticulum@1.5.0/// RNS/Transport.py:1929-1946,2012-2028, so the packet moves a hop closer to/// its destination and the step records the way back for the proof. A packet/// more than one hop from its destination keeps the transport header and takes/// the path's next hop, and a packet one hop away loses it. The step writes a/// reverse entry naming the carrier the packet arrived on and the carrier it/// left on. A destination with no live path, or a path whose carrier sends/// nothing, reports `unrouted` and sends no frame.pub fn run( node_owner: *node.Node, value: wire.Packet, raw: []const u8, interface: carrier.Index, hash: packet.Hash, now: node.Seconds,) node.StepError!Outcome { std.debug.assert(applies(node_owner, value)); std.debug.assert(raw.len >= wire.header_two_bytes); const path = node_owner.transport.paths.find(value.destination, now) orelse return .unrouted; std.debug.assert(path.hops >= 1); const fanout: node.outbound.Fanout = .{ .one = path.carrier }; if (node.outbound.frameCount(node_owner, fanout) == 0) return .unrouted; try node.outbound.reserve(node_owner, 1, 1); const frame = if (path.hops > 1) node.transport.rewrite.forward(raw, value.hops, path.next_hop, node_owner.scratch) else node.transport.rewrite.strip(raw, value.hops, node_owner.scratch); node_owner.transport.reverse_entries.insert(.{ .truncated = hash[0..16].*, .timestamp = now, .receiving = interface, .outbound = path.carrier, }); path.timestamp = now; try node.outbound.transmit(node_owner, fanout, frame); return .relayed;}/// Relays a proof along its reverse entry, following Reticulum@1.5.0/// RNS/Transport.py:2670-2679, so the proof travels back along the way its/// packet came as the only route the sender is reachable by. A proof that/// arrives on a carrier other than the one the packet left on drops the reverse/// entry and reports `proof_relay_wrong_interface`. The reverse entry is/// removed whether the proof goes on or stops here, so one relayed packet/// carries one proof back.pub fn proof( node_owner: *node.Node, value: wire.Packet, raw: []const u8, interface: carrier.Index, hash: packet.Hash, now: node.Seconds,) node.StepError!bool { std.debug.assert(value.packet_type == .proof); std.debug.assert(raw.len >= wire.header_one_bytes); if (!node_owner.transport.enabled) return false; const entry = node_owner.transport.reverse_entries.find(value.destination, now) orelse return false; if (entry.outbound != interface) { try node.outbound.reserve(node_owner, 2, 0); _ = node_owner.transport.reverse_entries.remove(value.destination); node.inbound.diagnostic(node_owner, .proof_relay_wrong_interface, hash); return false; } const fanout: node.outbound.Fanout = .{ .one = entry.receiving }; const carriers = node.outbound.frameCount(node_owner, fanout); try node.outbound.reserve(node_owner, carriers + 1, carriers); _ = node_owner.transport.reverse_entries.remove(value.destination); if (carriers == 0) return false; const frame = node.transport.rewrite.rehop(raw, value.hops, node_owner.scratch); try node.outbound.transmit(node_owner, fanout, frame); return true;}Source: lib/reticulum/src/node/transport/root.zig:108
zig
pub const relay = @import("relay.zig");Audit
| Definitions | 5 |
|---|---|
| Public names | 5 |
| Members | 2 |
| Version | 26.7.0 |
| Revision | daab053ee433 |