tiny.peer.TicketStorage
Defined in tiny.peer.
API (17)
Actions
Public operations.
Types and contracts
Public types and contracts.
Fields and members
Public fields and members.
Source
Source: lib/peer/src/ticket.zig:72
zig
pub const TicketStorage = struct { pub const storage_alignment: usize = @alignOf(Address); pub const Storage = []align(storage_alignment) u8; pub const Limits: type = TicketLimits; pub const Capacity: type = TicketCapacity; pub const Exhaustion = error{TooManyAddresses}; pub const InitError = TicketCapacity.DeriveError || error{StorageTooShort}; pub const work_limits: alloc_phase.capacity.WorkLimits = .{ .transition_steps_max = 1, .cleanup_steps_per_call_max = 0, .cleanup_calls_at_capacity_max = 0, }; pub const claim: alloc_phase.capacity.Declaration = .{ .source = .{ .id = "peer.bootstrap_ticket", .kind = .phase_static, .limit_source = .caller, .storage = .{ .covered = &.{.{ .id = "caller_bootstrap_address_slots", .lifetime = .transferred, .detail = "caller address slots including inline relay host bytes", }}, .excluded = &.{ "fixed peer identifier, count, capacity, and phase fields", "caller-owned wire, text, and codec scratch buffers", }, }, .capacity = .{ .inputs = &.{ alloc_phase.capacity.bindInput( TicketLimits, "max_addresses", "max_addresses", ), }, .type_selectors = &.{ alloc_phase.capacity.bindType(Address, "address"), }, .nodes = &.{ .{ .input = 0 }, .{ .scale = .{ .node = 0, .coefficient = .{ .size_of_concrete_type = 0 }, } }, }, .assertions = &.{.{ .scope = .closure_total, .measure = .retained, .relation = .exact, .expression = 1, }}, }, .overload = .{ .kind = .reject_before_mutation, .detail = "max-plus-one address admission rejects before storage mutation", }, .risks = .{ .transitive = .{ .status = .witnessed, .detail = "ticket codecs and admission use caller slices and value operations", }, .foreign = .{ .status = .excluded, .detail = "ticket storage crosses no operating-system or foreign boundary", }, }, .work = .{ .equation = "activate <= 1 and codec steps <= max_addresses", }, .obligations = &.{ .{ .key = "peer_ticket_capacity", .role = .capacity_model }, .{ .key = "peer_ticket_overload", .role = .overload }, .{ .key = "peer_ticket_transitive", .role = .transitive_risk }, .{ .key = "peer_ticket_work", .role = .work_bound }, }, }, .bindings = .{ .owner = @This(), .seal = .{ .family = alloc_phase.capacity.selector(@This().activate), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, .teardown = .{ .family = alloc_phase.capacity.selector(@This().deinit), .premise = .{ .class = .checked_semantic_fact, .authority = .checker, }, }, }, }; phase: alloc_phase.capacity.Phase, capacity: TicketCapacity, storage: Storage, address_count: u8, pub fn init(bytes: Storage, limits: TicketLimits) InitError!TicketStorage { const capacity = try TicketCapacity.derive(limits); if (bytes.len < capacity.storage_bytes) return error.StorageTooShort; return .{ .phase = .initialization, .capacity = capacity, .storage = bytes[0..capacity.storage_bytes], .address_count = 0, }; } pub fn activate(self: *TicketStorage) void { std.debug.assert(self.phase == .initialization); self.phase = .steady; } pub fn append(self: *TicketStorage, address: Address) Exhaustion!void { self.assertSteady(); if (self.address_count >= self.capacity.max_addresses) { return error.TooManyAddresses; } self.slots()[self.address_count] = address; self.address_count += 1; } pub fn items(self: *const TicketStorage) []const Address { self.assertSteady(); const pointer: [*]const Address = @ptrCast(self.storage.ptr); return pointer[0..self.address_count]; } pub fn deinit(self: *TicketStorage) Storage { std.debug.assert(self.phase == .steady); self.phase = .teardown; const bytes = self.storage; self.* = undefined; return bytes; } fn slots(self: *TicketStorage) []Address { self.assertSteady(); const pointer: [*]Address = @ptrCast(self.storage.ptr); return pointer[0..self.capacity.max_addresses]; } fn assertSteady(self: *const TicketStorage) void { std.debug.assert(self.phase == .steady); std.debug.assert(self.address_count <= self.capacity.max_addresses); std.debug.assert(self.storage.len == self.capacity.storage_bytes); }};Source: lib/peer/src/root.zig:33
zig
pub const TicketStorage = ticket.TicketStorage;Audit
| Definitions | 14 |
|---|---|
| Public names | 14 |
| Members | 5 |
| Version | 26.7.0 |
| Revision | daab053ee433 |