interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / omega / allen / session.om

187 lines · 3233 bytes Raw Blame History
1note SPDX-License-Identifier: MIT
2note One-request-per-connection GitHub driver over TCP, TLS 1.3 and HTTP framing.
3note The platform supplies elapsed milliseconds, Unix time, packet results and 96 fresh
4note random bytes in Gsrand before every gsstart: 64 for TLS, 32 for TCP/DHCP/DNS IDs.
5global Gsrand uchar 96
6global Gsrandn ulong 1
7global Gs ulong 8
8note Gdiag: last failure code, TCP state, TCP error, TLS state, TLS error. Shown on screen.
9global Gdiag ulong 5
10note Gs: state0 idle,1 connecting,2 TLS,3 HTTP,4 completed,5 failed; deadline; request kind;
11note generation; send offset; failure code; pending close flag.
12fn gsfail now ulong code ulong to void
13if ne get Gs 0 0
14kind = get Gs 2
15gen = get Gs 3
16put Gs 0 5
17put Gs 5 code
18put Gdiag 0 code
19put Gdiag 1 get Tcpstate 0
20put Gdiag 2 get Tcpstate 1
21put Gdiag 3 get Ndrop 0
22put Gdiag 4 get Ndropw 0
23netclose now
24tlsclose
25tcwipe
26ok = ghreply kind 0 0 gen
27end
28end
29fn gsstart now ulong epoch ulong to bool
30kind = get Ghreq 0
31if or eq kind 0 ne get Gs 0 0
32ret false
33end
34if ne get Gsrandn 0 len Gsrand
35ok = ghreply kind 0 0 get Ghreq 2
36ret false
37end
38for i ulong 64
39put Tlsrand i get Gsrand i
40end
41for i ulong 32
42put Nrand i get Gsrand add i 64
43end
44for i ulong len Gsrand
45put Gsrand i 0
46end
47put Gsrandn 0 0
48if not httpstart kind get Ghreq 2 get Ghreq 3 get Ghreq 4 get Ghreq 1
49ok = ghreply kind 0 0 get Ghreq 2
50ret false
51end
52for i ulong 8
53put Gs i 0
54end
55put Gs 0 1
56put Gs 1 add now 120000
57put Gs 2 kind
58put Gs 3 get Ghreq 2
59ghtime epoch
60tlsinit epoch
61if eq get Tlsstate 0 4
62gsfail now 9
63ret false
64end
65netconnect now
66ret true
67end
68fn gstlsout now ulong to void
69if eq get Tlsoutn 0 0
70ret
71end
72if gt get Tlsoutn 0 len Tcpout
73gsfail now 2
74ret
75end
76for i ulong get Tlsoutn 0
77put Tcpout i get Tlsout i
78end
79if netwrite get Tlsoutn 0 now
80tlssent
81end
82end
83fn gstcpin now ulong to void
84n = get Tcpn 0
85if eq n 0
86ret
87end
88if gt n len Tlsin
89n = len Tlsin
90end
91for i ulong n
92put Tlsin i get Tcpin i
93end
94tlsinput n
95netconsume n
96end
97fn gshttp now ulong to void
98while gt get Tlsappn 0 0
99n = get Tlsappn 0
100if gt n len Hchunk
101n = len Hchunk
102end
103for i ulong n
104put Hchunk i get Tlsapp i
105end
106if not httpfeed n
107gsfail now 3
108ret
109end
110tlsconsume n
111end
112if eq get Hstate 0 2
113size = get Hstate 2
114status = get Hstate 1
115kind = get Gs 2
116gen = get Gs 3
117put Gs 0 4
118netclose now
119tlsclose
120tcwipe
121ok = ghreply kind status size gen
122end
123end
124fn gsrequest now ulong to void
125if or ne get Gs 4 0 ne get Tlsstate 0 2
126ret
127end
128if gt get Httpreqn 0 len Tlsplain
129gsfail now 4
130ret
131end
132for i ulong get Httpreqn 0
133put Tlsplain i get Httpreq i
134end
135if tlswrite get Httpreqn 0
136put Gs 4 1
137put Gs 0 3
138end
139end
140fn gspoll now ulong to void
141state = get Gs 0
142if or eq state 0 ge state 4
143ret
144end
145if gt now get Gs 1
146gsfail now 5
147ret
148end
149netstep now
150if eq get Tcpstate 0 6
151gsfail now 6
152ret
153end
154if eq get Tcpstate 0 4
155if eq state 1
156put Gs 0 2
157tlsinput 0
158end
159end
160gstcpin now
161if eq get Tlsstate 0 4
162gsfail now 7
163ret
164end
165gstlsout now
166gsrequest now
167gstlsout now
168gshttp now
169if ne get Gs 0 3
170ret
171end
172if or eq get Tcpstate 0 5 eq get Tlsstate 0 3
173if httpend eq get Tlsstate 2 1
174gshttp now
175else
176gsfail now 8
177end
178end
179end
180fn gsnext now ulong epoch ulong to void
181if ge get Gs 0 4
182put Gs 0 0
183end
184if and eq get Gs 0 0 ne get Ghreq 0 0
185ok = gsstart now epoch
186end
187end