interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / collab / co9comp.om

138 lines · 3282 bytes Raw Blame History
1note collab/co9comp.om (ForgePatches): Phase A of docs/collab-write.md, the compose store.
2note The web composes and checks a comment, a review, a new issue or a new patch; it never writes to
3note Radicle. A checked compose is kept in memory for 15 minutes in one of 32 slots, bound to the
4note session's CSRF token, the repo and a 128-bit random id (/dev/urandom); GET compose/<cid> shows the
5note preview and the exact rad or git command the author runs in a clone, signing with their own key.
6note Kinds: 1 issue comment, 2 patch comment, 3 patch review, 4 new issue, 5 new patch; 0 free slot.
7text tcurnd "/dev/urandom"
8global gczk ulong 32
9global gczt ulong 32
10global gczix ulong 32
11global gczid uchar 1024
12global gczcs uchar 1024
13global gcztg uchar 1280
14global gczrv uchar 1280
15global gczrn ulong 32
16global gczf ulong 32
17global gczti uchar 8192
18global gcztl ulong 32
19global gczb uchar 1920000
20global gczbl ulong 32
21note staging for cozsave: title, flags (1 accept, 2 reject, 3 review without verdict, 8 draft), revision
22global gcsti uchar 256
23global gcstil ulong 1
24global gcsf ulong 1
25global gcsrv ulong 1
26note ---- slots
27fn conow to ulong
28ret div ulong realns 1000000000
29end
30fn cozlive s ulong to bool
31if eq get gczk s 0
32ret false
33end
34ret le sub conow get gczt s 900
35end
36note cozslot: a free or expired slot, else the oldest
37fn cozslot to ulong
38w = ulong 0
39for s ulong 32
40if eq cozlive s false
41ret s
42end
43if lt get gczt s get gczt w
44w = s
45end
46end
47ret w
48end
49note cozsave kd n: store a compose of kind kd with body gcfv[0,n) and the staged title, flags and
50note revision; the slot, or 99 when no random id could be read
51fn cozsave kd ulong n ulong to ulong
52s = cozslot
53if eq cozrand s false
54ret ulong 99
55end
56put gczk s kd
57put gczt s conow
58put gczix s get fridx 0
59put gczf s get gcsf 0
60put gczbl s n
61o = mul s 60000
62for k ulong n bound 60000
63put gczb add o k get gcfv k
64end
65cozsave2 s
66ret s
67end
68fn cozsave2 s ulong to void
69for k ulong 32
70put gczcs add mul s 32 k get fcsrf k
71end
72for k ulong 40
73put gcztg add mul s 40 k get gcid k
74end
75r = get gcsrv 0
76put gczrn s add r 1
77if lt r 64
78for k ulong 40
79put gczrv add mul s 40 k get gcrv add mul r 40 k
80end
81end
82n = get gcstil 0
83put gcztl s n
84for k ulong n bound 256
85put gczti add mul s 256 k get gcsti k
86end
87end
88note cozrand s: the slot's id, 32 lowercase hex characters of 16 bytes from /dev/urandom
89fn cozrand s ulong to bool
90b = new uchar 16 0
91fd = fopen tcurnd 0 len tcurnd 524288 0
92if lt fd 0
93ret false
94end
95r = read int fd b 0 16
96x = fclose int fd
97if ne r 16
98ret false
99end
100for i ulong 16
101v = get b i
102put gczid add mul s 32 mul i 2 cohxd shr v 4
103put gczid add add mul s 32 mul i 2 1 cohxd and v 15
104end
105ret true
106end
107fn cohxd v uchar to uchar
108if lt v 10
109ret uchar add v 48
110end
111ret uchar add v 87
112end
113note cozfind a: the live slot whose id is frest[a,a+32), made in this session (CSRF token) for this
114note repo; 99 when there is none
115fn cozfind a ulong to ulong
116if or ne get fcsrfl 0 32 gt add a 32 get frestl 0
117ret ulong 99
118end
119for s ulong 32
120if cozlive s
121if cozmat s a
122ret s
123end
124end
125end
126ret ulong 99
127end
128fn cozmat s ulong a ulong to bool
129if ne get gczix s get fridx 0
130ret false
131end
132d = uchar 0
133for k ulong 32
134d = or d xor get gczid add mul s 32 k get frest add a k
135d = or d xor get gczcs add mul s 32 k get fcsrf k
136end
137ret eq d 0
138end