lib/reticulum/src/node/step.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const reticulum = @import("../root.zig");
 2 
 3 const node = reticulum.node;
 4 
 5 /// Runs one transition for a caller to drive the node by handing it one event and reading back what
 6 /// to do: the call clears the effect list, sends the event to the handler for its kind, and returns
 7 /// the effects that handler appended. Every value the transition uses comes from the event,
 8 /// including the current second and the step entropy, so the same events replayed give the same
 9 /// effects. The returned effects point into the node's own storage and stay valid until the next
10 /// call. A `storage_complete` event changes nothing, because the caller's write has already
11 /// finished.
12 pub fn run(node_owner: *node.Node, value: node.Event) node.StepError![]const node.Effect {
13     node_owner.effects.reset();
14     switch (value) {
15         .carrier_frame => |frame| try node.inbound.run(node_owner, frame),
16         .timer_expired => |timer| try node.inbound.timerExpired(node_owner, timer),
17         .application_send => |send| try node.outbound.run(node_owner, send),
18         .application_announce => |announce| try node.announce.run(node_owner, announce),
19         .application_prove => |proof| try node.inbound.prove(node_owner, proof),
20         .application_path_request => |request| {
21             try node.transport.requests.send(node_owner, request);
22         },
23         .application_link_open => |open| try node.link.open(node_owner, open),
24         .application_link_send => |send| try node.link.send(node_owner, send),
25         .application_link_close => |close| try node.link.close(node_owner, close),
26         .application_link_prove => |proof| try node.link.prove(node_owner, proof),
27         .storage_complete => {},
28     }
29     return node_owner.effects.items();
30 }