@jsm-mit/map-routes-package 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,303 @@
1
+ export const idlFactory = ({ IDL }) => {
2
+ const Mode = IDL.Variant({
3
+ 'Local' : IDL.Null,
4
+ 'Stage' : IDL.Null,
5
+ 'Prod' : IDL.Null,
6
+ });
7
+ const InitArgs = IDL.Record({
8
+ 'mode' : Mode,
9
+ 'superadmins' : IDL.Vec(IDL.Principal),
10
+ });
11
+ const Bbox = IDL.Record({
12
+ 'minLat' : IDL.Float64,
13
+ 'minLon' : IDL.Float64,
14
+ 'maxLat' : IDL.Float64,
15
+ 'maxLon' : IDL.Float64,
16
+ });
17
+ const Shard = IDL.Record({
18
+ 'sha256' : IDL.Opt(IDL.Text),
19
+ 'area' : IDL.Text,
20
+ 'bbox' : Bbox,
21
+ 'osmDate' : IDL.Opt(IDL.Text),
22
+ });
23
+ const Error = IDL.Variant({
24
+ 'CallFailed' : IDL.Text,
25
+ 'Blocked' : IDL.Text,
26
+ 'NotFound' : IDL.Text,
27
+ 'NotAuthorized' : IDL.Text,
28
+ 'LimitReached' : IDL.Text,
29
+ 'InvalidData' : IDL.Text,
30
+ 'RateLimited' : IDL.Text,
31
+ 'Waiting' : IDL.Text,
32
+ });
33
+ const Result = IDL.Variant({ 'Ok' : Shard, 'Err' : Error });
34
+ const Result_1 = IDL.Variant({
35
+ 'Ok' : IDL.Vec(IDL.Principal),
36
+ 'Err' : Error,
37
+ });
38
+ const CopyState = IDL.Variant({
39
+ 'Copying' : IDL.Null,
40
+ 'Live' : IDL.Null,
41
+ 'Installing' : IDL.Null,
42
+ 'AwaitingData' : IDL.Null,
43
+ 'MarkedForRemoval' : IDL.Null,
44
+ });
45
+ const Copy = IDL.Record({
46
+ 'area' : IDL.Text,
47
+ 'createdAtNs' : IDL.Nat64,
48
+ 'state' : CopyState,
49
+ 'subnet' : IDL.Opt(IDL.Principal),
50
+ 'canister' : IDL.Principal,
51
+ 'lastError' : IDL.Opt(IDL.Text),
52
+ 'markedAtNs' : IDL.Opt(IDL.Nat64),
53
+ });
54
+ const Result_2 = IDL.Variant({ 'Ok' : Copy, 'Err' : Error });
55
+ const CoreState = IDL.Variant({ 'Live' : IDL.Null, 'Installing' : IDL.Null });
56
+ const CoreCanister = IDL.Record({
57
+ 'syncedVersion' : IDL.Opt(IDL.Nat64),
58
+ 'createdAtNs' : IDL.Nat64,
59
+ 'cycles' : IDL.Opt(IDL.Nat),
60
+ 'state' : CoreState,
61
+ 'subnet' : IDL.Opt(IDL.Principal),
62
+ 'canister' : IDL.Principal,
63
+ 'lastError' : IDL.Opt(IDL.Text),
64
+ });
65
+ const Result_3 = IDL.Variant({ 'Ok' : CoreCanister, 'Err' : Error });
66
+ const AreaInfo = IDL.Record({
67
+ 'sha256' : IDL.Opt(IDL.Text),
68
+ 'area' : IDL.Text,
69
+ 'bbox' : Bbox,
70
+ 'copies' : IDL.Vec(IDL.Principal),
71
+ 'osmDate' : IDL.Opt(IDL.Text),
72
+ });
73
+ const Areas = IDL.Record({
74
+ 'ttlSeconds' : IDL.Nat32,
75
+ 'areas' : IDL.Vec(AreaInfo),
76
+ });
77
+ const WasmKind = IDL.Variant({ 'Core' : IDL.Null, 'Worker' : IDL.Null });
78
+ const BeginWasmArgs = IDL.Record({
79
+ 'sha256' : IDL.Text,
80
+ 'kind' : IDL.Opt(WasmKind),
81
+ 'size' : IDL.Nat64,
82
+ });
83
+ const WasmMeta = IDL.Record({
84
+ 'sha256' : IDL.Text,
85
+ 'size' : IDL.Nat64,
86
+ 'ready' : IDL.Bool,
87
+ });
88
+ const Result_4 = IDL.Variant({ 'Ok' : WasmMeta, 'Err' : Error });
89
+ const Result_5 = IDL.Variant({ 'Ok' : IDL.Nat32, 'Err' : Error });
90
+ const UserKey = IDL.Record({
91
+ 'user' : IDL.Principal,
92
+ 'system' : IDL.Principal,
93
+ });
94
+ const Block = IDL.Record({
95
+ 'who' : UserKey,
96
+ 'atNs' : IDL.Nat64,
97
+ 'load' : IDL.Opt(IDL.Float64),
98
+ 'reason' : IDL.Text,
99
+ });
100
+ const CoreReport = IDL.Record({
101
+ 'blocks' : IDL.Vec(Block),
102
+ 'users' : IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat64)),
103
+ 'rateLimited' : IDL.Vec(IDL.Principal),
104
+ });
105
+ const Result_6 = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : Error });
106
+ const QueryTotals = IDL.Record({
107
+ 'calls' : IDL.Nat,
108
+ 'instructions' : IDL.Nat,
109
+ 'responseBytes' : IDL.Nat,
110
+ });
111
+ const FeedArgs = IDL.Record({
112
+ 'totals' : QueryTotals,
113
+ 'canister' : IDL.Principal,
114
+ });
115
+ const System = IDL.Record({
116
+ 'id' : IDL.Principal,
117
+ 'demo' : IDL.Bool,
118
+ 'blocked' : IDL.Bool,
119
+ 'name' : IDL.Text,
120
+ 'hourlyLimit' : IDL.Opt(IDL.Nat32),
121
+ 'hourStartNs' : IDL.Nat64,
122
+ 'passesThisHour' : IDL.Nat32,
123
+ 'perMinute' : IDL.Nat32,
124
+ });
125
+ const BisectionRun = IDL.Record({
126
+ 'endedAtNs' : IDL.Opt(IDL.Nat64),
127
+ 'area' : IDL.Text,
128
+ 'copyA' : IDL.Principal,
129
+ 'copyB' : IDL.Principal,
130
+ 'suspects' : IDL.Nat64,
131
+ 'steps' : IDL.Nat32,
132
+ 'stepStartedNs' : IDL.Nat64,
133
+ });
134
+ const PassState = IDL.Record({
135
+ 'keys' : IDL.Vec(IDL.Tuple(IDL.Principal, IDL.Nat32, IDL.Bool)),
136
+ 'cores' : IDL.Vec(CoreCanister),
137
+ 'activePasses' : IDL.Nat64,
138
+ 'systems' : IDL.Vec(System),
139
+ 'blocks' : IDL.Vec(Block),
140
+ 'bisections' : IDL.Vec(BisectionRun),
141
+ });
142
+ const Result_7 = IDL.Variant({ 'Ok' : PassState, 'Err' : Error });
143
+ const AreaLoad = IDL.Record({
144
+ 'above' : IDL.Nat32,
145
+ 'lastGrowthNs' : IDL.Opt(IDL.Nat64),
146
+ 'belowSinceNs' : IDL.Opt(IDL.Nat64),
147
+ 'area' : IDL.Text,
148
+ });
149
+ const Rates = IDL.Record({
150
+ 'responseBytesPerS' : IDL.Float64,
151
+ 'callsPerS' : IDL.Float64,
152
+ 'instructionsPerS' : IDL.Float64,
153
+ });
154
+ const Reading = IDL.Record({
155
+ 'atNs' : IDL.Nat64,
156
+ 'sinceNs' : IDL.Opt(IDL.Nat64),
157
+ 'cycles' : IDL.Nat,
158
+ 'totals' : QueryTotals,
159
+ 'canister' : IDL.Principal,
160
+ 'rates' : IDL.Opt(Rates),
161
+ });
162
+ const Subnet = IDL.Record({ 'id' : IDL.Principal, 'sev' : IDL.Bool });
163
+ const Settings = IDL.Record({
164
+ 'hInstructionsPerS' : IDL.Nat64,
165
+ 'subnets' : IDL.Vec(Subnet),
166
+ 'copyCycles' : IDL.Nat,
167
+ 'passRequired' : IDL.Opt(IDL.Bool),
168
+ 'mode' : Mode,
169
+ 'coreCycles' : IDL.Opt(IDL.Nat),
170
+ 'superadmins' : IDL.Vec(IDL.Principal),
171
+ 'maxCopies' : IDL.Nat32,
172
+ });
173
+ const State = IDL.Record({
174
+ 'coreWasm' : IDL.Opt(WasmMeta),
175
+ 'shards' : IDL.Vec(Shard),
176
+ 'lastRoundNs' : IDL.Opt(IDL.Nat64),
177
+ 'cores' : IDL.Vec(CoreCanister),
178
+ 'wasm' : IDL.Opt(WasmMeta),
179
+ 'loads' : IDL.Vec(AreaLoad),
180
+ 'cycles' : IDL.Nat,
181
+ 'readings' : IDL.Vec(Reading),
182
+ 'settings' : Settings,
183
+ 'copies' : IDL.Vec(Copy),
184
+ });
185
+ const Result_8 = IDL.Variant({ 'Ok' : State, 'Err' : Error });
186
+ const HttpRequest = IDL.Record({
187
+ 'url' : IDL.Text,
188
+ 'method' : IDL.Text,
189
+ 'body' : IDL.Vec(IDL.Nat8),
190
+ 'headers' : IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
191
+ 'certificate_version' : IDL.Opt(IDL.Nat16),
192
+ });
193
+ const HttpResponse = IDL.Record({
194
+ 'body' : IDL.Vec(IDL.Nat8),
195
+ 'headers' : IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
196
+ 'upgrade' : IDL.Opt(IDL.Bool),
197
+ 'status_code' : IDL.Nat16,
198
+ });
199
+ const NoticeKind = IDL.Variant({
200
+ 'StatusFailed' : IDL.Null,
201
+ 'BisectionStarted' : IDL.Null,
202
+ 'CopyCreated' : IDL.Null,
203
+ 'CopyDeleted' : IDL.Null,
204
+ 'MaxCopiesReached' : IDL.Null,
205
+ 'KeysFailed' : IDL.Null,
206
+ 'CopyMarked' : IDL.Null,
207
+ 'CopyUnmarked' : IDL.Null,
208
+ 'CopyFailed' : IDL.Null,
209
+ 'BisectionEnded' : IDL.Null,
210
+ 'CoreFailed' : IDL.Null,
211
+ 'SystemRateLimited' : IDL.Null,
212
+ 'UserBlocked' : IDL.Null,
213
+ 'CyclesLow' : IDL.Null,
214
+ });
215
+ const Notice = IDL.Record({
216
+ 'id' : IDL.Nat64,
217
+ 'area' : IDL.Opt(IDL.Text),
218
+ 'atNs' : IDL.Nat64,
219
+ 'kind' : NoticeKind,
220
+ 'text' : IDL.Text,
221
+ 'canister' : IDL.Opt(IDL.Principal),
222
+ });
223
+ const Result_9 = IDL.Variant({ 'Ok' : IDL.Vec(Notice), 'Err' : Error });
224
+ const Result_10 = IDL.Variant({ 'Ok' : System, 'Err' : Error });
225
+ const RoundReport = IDL.Record({
226
+ 'atNs' : IDL.Nat64,
227
+ 'actions' : IDL.Vec(IDL.Text),
228
+ 'loads' : IDL.Vec(AreaLoad),
229
+ 'readings' : IDL.Vec(Reading),
230
+ });
231
+ const Result_11 = IDL.Variant({ 'Ok' : RoundReport, 'Err' : Error });
232
+ const SettingsArgs = IDL.Record({
233
+ 'hInstructionsPerS' : IDL.Nat64,
234
+ 'subnets' : IDL.Vec(Subnet),
235
+ 'copyCycles' : IDL.Nat,
236
+ 'passRequired' : IDL.Opt(IDL.Bool),
237
+ 'coreCycles' : IDL.Opt(IDL.Nat),
238
+ 'maxCopies' : IDL.Nat32,
239
+ });
240
+ const Result_12 = IDL.Variant({ 'Ok' : Settings, 'Err' : Error });
241
+ const SystemArgs = IDL.Record({
242
+ 'id' : IDL.Principal,
243
+ 'demo' : IDL.Bool,
244
+ 'blocked' : IDL.Bool,
245
+ 'name' : IDL.Text,
246
+ 'hourlyLimit' : IDL.Opt(IDL.Nat32),
247
+ 'perMinute' : IDL.Nat32,
248
+ });
249
+ const Result_13 = IDL.Variant({ 'Ok' : IDL.Bool, 'Err' : Error });
250
+ const WasmChunkArgs = IDL.Record({
251
+ 'kind' : IDL.Opt(WasmKind),
252
+ 'offset' : IDL.Nat64,
253
+ 'bytes' : IDL.Vec(IDL.Nat8),
254
+ });
255
+ return IDL.Service({
256
+ 'addShard' : IDL.Func([IDL.Text, Bbox], [Result], []),
257
+ 'addSuperadmin' : IDL.Func([IDL.Principal], [Result_1], []),
258
+ 'advanceCopy' : IDL.Func([IDL.Principal], [Result_2], []),
259
+ 'advanceCore' : IDL.Func([IDL.Principal], [Result_3], []),
260
+ 'areas' : IDL.Func([], [Areas], ['query']),
261
+ 'beginWasm' : IDL.Func([BeginWasmArgs], [Result_4], []),
262
+ 'clearNotifications' : IDL.Func([IDL.Nat64], [Result_5], []),
263
+ 'commitWasm' : IDL.Func([IDL.Opt(WasmKind)], [Result_4], []),
264
+ 'coreReport' : IDL.Func([CoreReport], [Result_6], []),
265
+ 'createCopy' : IDL.Func([IDL.Text], [Result_2], []),
266
+ 'createCore' : IDL.Func([], [Result_3], []),
267
+ 'deleteCopy' : IDL.Func([IDL.Principal], [Result_6], []),
268
+ 'feedQueryStats' : IDL.Func([IDL.Vec(FeedArgs)], [Result_6], []),
269
+ 'getPassState' : IDL.Func([], [Result_7], ['query']),
270
+ 'getState' : IDL.Func([], [Result_8], ['query']),
271
+ 'hasDependents' : IDL.Func([], [IDL.Bool], ['query']),
272
+ 'http_request' : IDL.Func([HttpRequest], [HttpResponse], ['query']),
273
+ 'issuerFor' : IDL.Func(
274
+ [IDL.Principal],
275
+ [IDL.Opt(IDL.Principal)],
276
+ ['query'],
277
+ ),
278
+ 'listDependents' : IDL.Func([], [IDL.Vec(IDL.Principal)], ['query']),
279
+ 'markCopy' : IDL.Func([IDL.Principal], [Result_2], []),
280
+ 'notifications' : IDL.Func([], [Result_9], ['query']),
281
+ 'removeSuperadmin' : IDL.Func([IDL.Principal], [Result_1], []),
282
+ 'removeSystem' : IDL.Func([IDL.Principal], [Result_10], []),
283
+ 'runRound' : IDL.Func([], [Result_11], []),
284
+ 'setSettings' : IDL.Func([SettingsArgs], [Result_12], []),
285
+ 'setSystem' : IDL.Func([SystemArgs], [Result_10], []),
286
+ 'unblockUser' : IDL.Func([UserKey], [Result_13], []),
287
+ 'upgradeCopy' : IDL.Func([IDL.Principal], [Result_2], []),
288
+ 'upgradeCore' : IDL.Func([IDL.Principal], [Result_3], []),
289
+ 'wasmChunk' : IDL.Func([WasmChunkArgs], [Result_6], []),
290
+ });
291
+ };
292
+ export const init = ({ IDL }) => {
293
+ const Mode = IDL.Variant({
294
+ 'Local' : IDL.Null,
295
+ 'Stage' : IDL.Null,
296
+ 'Prod' : IDL.Null,
297
+ });
298
+ const InitArgs = IDL.Record({
299
+ 'mode' : Mode,
300
+ 'superadmins' : IDL.Vec(IDL.Principal),
301
+ });
302
+ return [InitArgs];
303
+ };
@@ -0,0 +1,107 @@
1
+ // An area as the core needs it to issue a pass.
2
+ type AreaPasses = record {
3
+ area : text;
4
+ bbox : Bbox;
5
+ // Short passes: the area is under load or in a bisection.
6
+ short : bool;
7
+ split : opt Split;
8
+ // The live copies with a key; none = no pass yet (`Waiting`).
9
+ copies : vec CopyKey;
10
+ };
11
+ // A rectangle in degrees, edges included.
12
+ type Bbox = record {
13
+ minLat : float64;
14
+ minLon : float64;
15
+ maxLat : float64;
16
+ maxLon : float64;
17
+ };
18
+ // Stored: a blocked user (key = system/user). The coordinator lifts it (`setBlock`).
19
+ type Block = record {
20
+ who : UserKey;
21
+ atNs : nat64;
22
+ load : opt float64;
23
+ reason : text;
24
+ };
25
+ // A live copy and the newest key it holds (passes are signed with it).
26
+ type CopyKey = record { key : blob; copy : principal; keyId : nat32 };
27
+ type CoreStats = record {
28
+ areas : nat32;
29
+ activePasses : nat64;
30
+ version : nat64;
31
+ systems : nat32;
32
+ blocks : nat64;
33
+ };
34
+ type Error = variant {
35
+ // The user gets no pass: the reason and whom to contact.
36
+ Blocked : text;
37
+ NotFound : text;
38
+ NotAuthorized : text;
39
+ InvalidData : text;
40
+ // The system asks too often (or the demo used its hour): try later.
41
+ RateLimited : text;
42
+ // Waits for something outside (named): e.g. the keys of the copies.
43
+ Waiting : text;
44
+ };
45
+ type InitArgs = record { mode : Mode; coordinator : principal };
46
+ type IssuePassArgs = record {
47
+ area : text;
48
+ // Cut to the bbox of the area.
49
+ bbox : Bbox;
50
+ // The principal that will call the worker (`caller` of the query).
51
+ user : principal;
52
+ // The registered system the caller belongs to, when the caller is not a system itself:
53
+ // the coordinator of the caller's group (e.g. a core of Tigi names the Tigi coordinator).
54
+ // The pass core asks that coordinator once (`isGroupCore`) and remembers the answer.
55
+ system : opt principal;
56
+ };
57
+ type Mode = variant { Local; Stage; Prod };
58
+ type PassInfo = record {
59
+ area : text;
60
+ bbox : Bbox;
61
+ // The copy to ask: the pass is valid there only.
62
+ copy : principal;
63
+ pass : blob;
64
+ validUntilNs : nat64;
65
+ };
66
+ type Result = variant { Ok : opt UserKey; Err : Error };
67
+ type Result_1 = variant { Ok : nat64; Err : Error };
68
+ type Result_2 = variant { Ok; Err : Error };
69
+ type Result_3 = variant { Ok : PassInfo; Err : Error };
70
+ // Stored (key 0): what the coordinator sent last. A newer `version` replaces it.
71
+ type Snapshot = record {
72
+ areas : vec AreaPasses;
73
+ version : nat64;
74
+ systems : vec SystemInfo;
75
+ };
76
+ // The two copies of a running bisection of an area (the lists of users stay here).
77
+ type Split = record { copyA : principal; copyB : principal };
78
+ type SystemInfo = record {
79
+ id : principal;
80
+ demo : bool;
81
+ blocked : bool;
82
+ name : text;
83
+ hourlyLimit : opt nat32;
84
+ perMinute : nat32;
85
+ };
86
+ type UserKey = record { user : principal; system : principal };
87
+ service : (InitArgs) -> {
88
+ // The one suspect left is blocked; answers it (none when this core holds none).
89
+ bisectionBlock : (text, text, opt float64) -> (Result);
90
+ // The half on copy A (`heavyA`) or on copy B carried the surplus: it stays and is split again.
91
+ // Answers the suspects left in this core.
92
+ bisectionStep : (text, bool) -> (Result_1);
93
+ endBisection : (text) -> (Result_2);
94
+ // A registered system — or a core of its group, naming the system's coordinator — asks for
95
+ // the pass of its user: valid on one copy, for the bbox cut to the area, for 15 min (2 min
96
+ // under load, in a bisection and for demo). The same valid pass comes back without a write.
97
+ issuePass : (IssuePassArgs) -> (Result_3);
98
+ // A block from the coordinator (a superadmin, a bisection in another core), or its end.
99
+ setBlock : (UserKey, opt Block) -> (Result_2);
100
+ // A bisection of `area` over two copies: the users with a valid pass there, split in halves.
101
+ // Answers their number in this core.
102
+ startBisection : (text, Split) -> (Result_1);
103
+ // Counts only (no user, no key): for the coordinator's front and the checks.
104
+ stats : () -> (CoreStats) query;
105
+ // The coordinator's snapshot: replaces the held one when newer. Answers the version held.
106
+ sync : (Snapshot) -> (Result_1);
107
+ }
@@ -0,0 +1,171 @@
1
+ import type { Principal } from '@icp-sdk/core/principal';
2
+ import type { ActorMethod } from '@icp-sdk/core/agent';
3
+ import type { IDL } from '@icp-sdk/core/candid';
4
+
5
+ /**
6
+ * An area as the core needs it to issue a pass.
7
+ */
8
+ export interface AreaPasses {
9
+ 'area' : string,
10
+ 'bbox' : Bbox,
11
+ /**
12
+ * Short passes: the area is under load or in a bisection.
13
+ */
14
+ 'short' : boolean,
15
+ 'split' : [] | [Split],
16
+ /**
17
+ * The live copies with a key; none = no pass yet (`Waiting`).
18
+ */
19
+ 'copies' : Array<CopyKey>,
20
+ }
21
+ /**
22
+ * A rectangle in degrees, edges included.
23
+ */
24
+ export interface Bbox {
25
+ 'minLat' : number,
26
+ 'minLon' : number,
27
+ 'maxLat' : number,
28
+ 'maxLon' : number,
29
+ }
30
+ /**
31
+ * Stored: a blocked user (key = system/user). The coordinator lifts it (`setBlock`).
32
+ */
33
+ export interface Block {
34
+ 'who' : UserKey,
35
+ 'atNs' : bigint,
36
+ 'load' : [] | [number],
37
+ 'reason' : string,
38
+ }
39
+ /**
40
+ * A live copy and the newest key it holds (passes are signed with it).
41
+ */
42
+ export interface CopyKey {
43
+ 'key' : Uint8Array | number[],
44
+ 'copy' : Principal,
45
+ 'keyId' : number,
46
+ }
47
+ export interface CoreStats {
48
+ 'areas' : number,
49
+ 'activePasses' : bigint,
50
+ 'version' : bigint,
51
+ 'systems' : number,
52
+ 'blocks' : bigint,
53
+ }
54
+ export type Error = {
55
+ /**
56
+ * The user gets no pass: the reason and whom to contact.
57
+ */
58
+ 'Blocked' : string
59
+ } |
60
+ { 'NotFound' : string } |
61
+ { 'NotAuthorized' : string } |
62
+ { 'InvalidData' : string } |
63
+ {
64
+ /**
65
+ * The system asks too often (or the demo used its hour): try later.
66
+ */
67
+ 'RateLimited' : string
68
+ } |
69
+ {
70
+ /**
71
+ * Waits for something outside (named): e.g. the keys of the copies.
72
+ */
73
+ 'Waiting' : string
74
+ };
75
+ export interface InitArgs { 'mode' : Mode, 'coordinator' : Principal }
76
+ export interface IssuePassArgs {
77
+ 'area' : string,
78
+ /**
79
+ * Cut to the bbox of the area.
80
+ */
81
+ 'bbox' : Bbox,
82
+ /**
83
+ * The principal that will call the worker (`caller` of the query).
84
+ */
85
+ 'user' : Principal,
86
+ /**
87
+ * The registered system the caller belongs to, when the caller is not a system itself:
88
+ * the coordinator of the caller's group (e.g. a core of Tigi names the Tigi coordinator).
89
+ * The pass core asks that coordinator once (`isGroupCore`) and remembers the answer.
90
+ */
91
+ 'system' : [] | [Principal],
92
+ }
93
+ export type Mode = { 'Local' : null } |
94
+ { 'Stage' : null } |
95
+ { 'Prod' : null };
96
+ export interface PassInfo {
97
+ 'area' : string,
98
+ 'bbox' : Bbox,
99
+ /**
100
+ * The copy to ask: the pass is valid there only.
101
+ */
102
+ 'copy' : Principal,
103
+ 'pass' : Uint8Array | number[],
104
+ 'validUntilNs' : bigint,
105
+ }
106
+ export type Result = { 'Ok' : [] | [UserKey] } |
107
+ { 'Err' : Error };
108
+ export type Result_1 = { 'Ok' : bigint } |
109
+ { 'Err' : Error };
110
+ export type Result_2 = { 'Ok' : null } |
111
+ { 'Err' : Error };
112
+ export type Result_3 = { 'Ok' : PassInfo } |
113
+ { 'Err' : Error };
114
+ /**
115
+ * Stored (key 0): what the coordinator sent last. A newer `version` replaces it.
116
+ */
117
+ export interface Snapshot {
118
+ 'areas' : Array<AreaPasses>,
119
+ 'version' : bigint,
120
+ 'systems' : Array<SystemInfo>,
121
+ }
122
+ /**
123
+ * The two copies of a running bisection of an area (the lists of users stay here).
124
+ */
125
+ export interface Split { 'copyA' : Principal, 'copyB' : Principal }
126
+ export interface SystemInfo {
127
+ 'id' : Principal,
128
+ 'demo' : boolean,
129
+ 'blocked' : boolean,
130
+ 'name' : string,
131
+ 'hourlyLimit' : [] | [number],
132
+ 'perMinute' : number,
133
+ }
134
+ export interface UserKey { 'user' : Principal, 'system' : Principal }
135
+ export interface _SERVICE {
136
+ /**
137
+ * The one suspect left is blocked; answers it (none when this core holds none).
138
+ */
139
+ 'bisectionBlock' : ActorMethod<[string, string, [] | [number]], Result>,
140
+ /**
141
+ * The half on copy A (`heavyA`) or on copy B carried the surplus: it stays and is split again.
142
+ * Answers the suspects left in this core.
143
+ */
144
+ 'bisectionStep' : ActorMethod<[string, boolean], Result_1>,
145
+ 'endBisection' : ActorMethod<[string], Result_2>,
146
+ /**
147
+ * A registered system — or a core of its group, naming the system's coordinator — asks for
148
+ * the pass of its user: valid on one copy, for the bbox cut to the area, for 15 min (2 min
149
+ * under load, in a bisection and for demo). The same valid pass comes back without a write.
150
+ */
151
+ 'issuePass' : ActorMethod<[IssuePassArgs], Result_3>,
152
+ /**
153
+ * A block from the coordinator (a superadmin, a bisection in another core), or its end.
154
+ */
155
+ 'setBlock' : ActorMethod<[UserKey, [] | [Block]], Result_2>,
156
+ /**
157
+ * A bisection of `area` over two copies: the users with a valid pass there, split in halves.
158
+ * Answers their number in this core.
159
+ */
160
+ 'startBisection' : ActorMethod<[string, Split], Result_1>,
161
+ /**
162
+ * Counts only (no user, no key): for the coordinator's front and the checks.
163
+ */
164
+ 'stats' : ActorMethod<[], CoreStats>,
165
+ /**
166
+ * The coordinator's snapshot: replaces the held one when newer. Answers the version held.
167
+ */
168
+ 'sync' : ActorMethod<[Snapshot], Result_1>,
169
+ }
170
+ export declare const idlFactory: IDL.InterfaceFactory;
171
+ export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[];
@@ -0,0 +1,108 @@
1
+ export const idlFactory = ({ IDL }) => {
2
+ const Mode = IDL.Variant({
3
+ 'Local' : IDL.Null,
4
+ 'Stage' : IDL.Null,
5
+ 'Prod' : IDL.Null,
6
+ });
7
+ const InitArgs = IDL.Record({ 'mode' : Mode, 'coordinator' : IDL.Principal });
8
+ const UserKey = IDL.Record({
9
+ 'user' : IDL.Principal,
10
+ 'system' : IDL.Principal,
11
+ });
12
+ const Error = IDL.Variant({
13
+ 'Blocked' : IDL.Text,
14
+ 'NotFound' : IDL.Text,
15
+ 'NotAuthorized' : IDL.Text,
16
+ 'InvalidData' : IDL.Text,
17
+ 'RateLimited' : IDL.Text,
18
+ 'Waiting' : IDL.Text,
19
+ });
20
+ const Result = IDL.Variant({ 'Ok' : IDL.Opt(UserKey), 'Err' : Error });
21
+ const Result_1 = IDL.Variant({ 'Ok' : IDL.Nat64, 'Err' : Error });
22
+ const Result_2 = IDL.Variant({ 'Ok' : IDL.Null, 'Err' : Error });
23
+ const Bbox = IDL.Record({
24
+ 'minLat' : IDL.Float64,
25
+ 'minLon' : IDL.Float64,
26
+ 'maxLat' : IDL.Float64,
27
+ 'maxLon' : IDL.Float64,
28
+ });
29
+ const IssuePassArgs = IDL.Record({
30
+ 'area' : IDL.Text,
31
+ 'bbox' : Bbox,
32
+ 'user' : IDL.Principal,
33
+ 'system' : IDL.Opt(IDL.Principal),
34
+ });
35
+ const PassInfo = IDL.Record({
36
+ 'area' : IDL.Text,
37
+ 'bbox' : Bbox,
38
+ 'copy' : IDL.Principal,
39
+ 'pass' : IDL.Vec(IDL.Nat8),
40
+ 'validUntilNs' : IDL.Nat64,
41
+ });
42
+ const Result_3 = IDL.Variant({ 'Ok' : PassInfo, 'Err' : Error });
43
+ const Block = IDL.Record({
44
+ 'who' : UserKey,
45
+ 'atNs' : IDL.Nat64,
46
+ 'load' : IDL.Opt(IDL.Float64),
47
+ 'reason' : IDL.Text,
48
+ });
49
+ const Split = IDL.Record({
50
+ 'copyA' : IDL.Principal,
51
+ 'copyB' : IDL.Principal,
52
+ });
53
+ const CoreStats = IDL.Record({
54
+ 'areas' : IDL.Nat32,
55
+ 'activePasses' : IDL.Nat64,
56
+ 'version' : IDL.Nat64,
57
+ 'systems' : IDL.Nat32,
58
+ 'blocks' : IDL.Nat64,
59
+ });
60
+ const CopyKey = IDL.Record({
61
+ 'key' : IDL.Vec(IDL.Nat8),
62
+ 'copy' : IDL.Principal,
63
+ 'keyId' : IDL.Nat32,
64
+ });
65
+ const AreaPasses = IDL.Record({
66
+ 'area' : IDL.Text,
67
+ 'bbox' : Bbox,
68
+ 'short' : IDL.Bool,
69
+ 'split' : IDL.Opt(Split),
70
+ 'copies' : IDL.Vec(CopyKey),
71
+ });
72
+ const SystemInfo = IDL.Record({
73
+ 'id' : IDL.Principal,
74
+ 'demo' : IDL.Bool,
75
+ 'blocked' : IDL.Bool,
76
+ 'name' : IDL.Text,
77
+ 'hourlyLimit' : IDL.Opt(IDL.Nat32),
78
+ 'perMinute' : IDL.Nat32,
79
+ });
80
+ const Snapshot = IDL.Record({
81
+ 'areas' : IDL.Vec(AreaPasses),
82
+ 'version' : IDL.Nat64,
83
+ 'systems' : IDL.Vec(SystemInfo),
84
+ });
85
+ return IDL.Service({
86
+ 'bisectionBlock' : IDL.Func(
87
+ [IDL.Text, IDL.Text, IDL.Opt(IDL.Float64)],
88
+ [Result],
89
+ [],
90
+ ),
91
+ 'bisectionStep' : IDL.Func([IDL.Text, IDL.Bool], [Result_1], []),
92
+ 'endBisection' : IDL.Func([IDL.Text], [Result_2], []),
93
+ 'issuePass' : IDL.Func([IssuePassArgs], [Result_3], []),
94
+ 'setBlock' : IDL.Func([UserKey, IDL.Opt(Block)], [Result_2], []),
95
+ 'startBisection' : IDL.Func([IDL.Text, Split], [Result_1], []),
96
+ 'stats' : IDL.Func([], [CoreStats], ['query']),
97
+ 'sync' : IDL.Func([Snapshot], [Result_1], []),
98
+ });
99
+ };
100
+ export const init = ({ IDL }) => {
101
+ const Mode = IDL.Variant({
102
+ 'Local' : IDL.Null,
103
+ 'Stage' : IDL.Null,
104
+ 'Prod' : IDL.Null,
105
+ });
106
+ const InitArgs = IDL.Record({ 'mode' : Mode, 'coordinator' : IDL.Principal });
107
+ return [InitArgs];
108
+ };