Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/apps/interplane-forge/server/util.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / apps / interplane-forge / server / util.om` 1219 lines ยท 23303 bytes Raw Blame History 1 note forged server/util.om: the shared request / response globals and helpers of docs/CONTRACT.md. 2 note Every name here starts with f (functions, globals) or tf (texts). Composed after http.om. 3 note ---- request (set by server/main.om before dispatch) 4 global fmeth ulong 1 5 global fpath uchar 4096 6 global fpathl ulong 1 7 global fqs uchar 4096 8 global fqsl ulong 1 9 global fbody uchar 65536 10 global fbodyl ulong 1 11 note fbig: the body of a POST whose path ends in /patches/new (git patch intake, docs/API.md), at most 12 note 3 MiB (`3145728` bytes: a 2 MiB mbox as base64url is `2796203` bytes, a 60000-byte description 13 note percent-encoded at most 180000, the rest under 20000). server/main.om freqbig fills it and leaves 14 note fbody empty; every other POST keeps the 64 KiB fbody and has fbigl 0. 15 global fbig uchar `3145728` 16 global fbigl ulong 1 17 global fck uchar 4096 18 global fckl ulong 1 19 global fip uchar 64 20 global fipl ulong 1 21 global fbase uchar 64 22 global fbasel ulong 1 23 global fridx ulong 1 24 global frid uchar 64 25 global fridl ulong 1 26 global fown uchar 64 27 global fownl ulong 1 28 global frepo uchar 128 29 global frepol ulong 1 30 global frest uchar 4096 31 global frestl ulong 1 32 global fuser uchar 64 33 global fuserl ulong 1 34 global fcsrf uchar 64 35 global fcsrfl ulong 1 36 global finm uchar 256 37 global finml ulong 1 38 global forig uchar 256 39 global forigl ulong 1 40 global fag uchar 256 41 global fagl ulong 1 42 global frf uchar 256 43 global frfl ulong 1 44 note ---- response 45 global fob uchar `8388608` 46 global fobl ulong 1 47 global fobtr ulong 1 48 global ftxmore ulong 1 49 global fkind ulong 1 50 global fct uchar 128 51 global fctl ulong 1 52 global fcd uchar 512 53 global fcdl ulong 1 54 global fsck uchar 512 55 global fsckl ulong 1 56 global floc uchar 4096 57 global flocl ulong 1 58 global fti uchar 256 59 global ftil ulong 1 60 global ffile uchar 4096 61 global ffilel ulong 1 62 global fetag uchar 128 63 global fetagl ulong 1 64 global fcc uchar 128 65 global fccl ulong 1 66 global fval uchar 4096 67 note ---- allow-list (server/repos.om fills it). FAMAX rows: every table below indexed by the row has 68 note FAMAX entries, and every loop over the rows is bound FAMAX. The pools hold FAMAX rows at the 69 note longest each row may be (name 100 + slack, id 64, branch 60, description and last commit as 70 note before, times four). Sized 2026-11-14 from 64 to 256 for the native store (105 public projects 71 note in it); store/tests/capacity.sh fails loudly when a store or RIDS.md table passes 192 rows. 72 const FAMAX ulong 256 73 global fan ulong 1 74 global fanm uchar 32768 75 global fano ulong 256 76 global fanl ulong 256 77 global faid uchar 16384 78 global faio ulong 256 79 global fail ulong 256 80 global fabr uchar 16384 81 global fabo ulong 256 82 global fabl ulong 256 83 global fadesc uchar 262144 84 global fado ulong 256 85 global fadl ulong 256 86 global falc uchar 262144 87 global falco ulong 256 88 global falcl ulong 256 89 global famt ulong 1 90 note ---- exec 91 global fpk uchar 8192 92 global fpkl ulong 1 93 global fpkr ulong 1 94 global fxo uchar `16777216` 95 global fxol ulong 1 96 global fxotr ulong 1 97 note streaming exec (fsopen / fsnext / fsclose): 0 read fd, 1 pid, 2 deadline, 3 state (0 open, 98 note 1 end of output, 2 failed); fsp the first unread byte of fxo, fsq the first byte not yet scanned 99 note for the separator, fsrs the start of the record fsnext returned last 100 global fsst long 4 101 global fsp ulong 1 102 global fsq ulong 1 103 global fsrs ulong 1 104 global fpfd uchar 8 105 global fwst uchar 4 106 global fjunk uchar 4096 107 global fpth uchar 4096 108 global fpthl ulong 1 109 global fstb uchar 128 110 note ---- write rate limit: 256 slots keyed by the 64-bit FNV-1a hash of the client IP, 30 writes per 111 note 60 s window; an unknown IP takes a free slot, else the slot whose window started first 112 global frlk ulong 256 113 global frlt ulong 256 114 global frlc ulong 256 115 note ---- per-response hooks (cleared per request by fresetr in main.om) 116 note fretry: nonzero = send "Retry-After: " (seconds) with the response (dl 503) 117 global fretry ulong 1 118 note fcspsb: nonzero = send the sandbox CSP instead of the page CSP (browse /raw/), see fsetsbx 119 global fcspsb ulong 1 120 note fmvng: 1 = this 503 is the "moving" answer of a part that is moving to the new Interplane store 121 note (store/moving.om, store build only): ferrti, ferrmsg and fyerr then give its title, its text and 122 note "reason":"moving"; every other 503 (door fail-closed, dl Retry-After) keeps its own words 123 global fmvng ulong 1 124 note fsrcst: 1 when the repositories are a native Interplane store (store/repos.om sets it when it 125 note loads; the default build never does): fkgit / fkgiti then name projects//repo.git, 126 note fsrt being the store root with its final "/". 0: , Radicle storage. 127 global fsrcst ulong 1 128 global fsrt uchar 4096 129 global fsrtl ulong 1 130 text tfsprj "projects/" 131 text tfsrg "/repo.git" 132 text tfstore "/home/drakestapleton/.radicle/storage/" 133 text tfgit "/usr/bin/git" 134 text tfdata "/home/drakestapleton/forge-data/" 135 text tfowner "drakestapleton" 136 text tfnid "`z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK`" 137 text tfdevnul "/dev/null" 138 text tfgitdir "--git-dir=" 139 text tfamp "&" 140 text tflt "<" 141 text tfgt ">" 142 text tfquot """ 143 text tfapos "'" 144 note ---- body builder fob 145 note fputc: a byte that does not fit fob is dropped and fobtr is set. fsend (server/main.om) reads 146 note fobtr before any header goes out and then sends a whole 500 instead of the cut body. 147 fn fputc c uchar to void 148 n = get fobl 0 149 if lt n len fob 150 put fob n c 151 put fobl 0 add n 1 152 ret 153 end 154 put fobtr 0 1 155 end 156 fn fput s view uchar * to void 157 for i ulong len s bound `16777216` 158 fputc get s i 159 end 160 end 161 fn fescc c uchar to void 162 if eq c 38 163 fput tfamp 164 ret 165 end 166 if eq c 60 167 fput tflt 168 ret 169 end 170 if eq c 62 171 fput tfgt 172 ret 173 end 174 if eq c 34 175 fput tfquot 176 ret 177 end 178 if eq c 39 179 fput tfapos 180 ret 181 end 182 fputc c 183 end 184 fn fesc s view uchar * to void 185 for i ulong len s bound `16777216` 186 fescc get s i 187 end 188 end 189 fn fnum v ulong to void 190 d = new uchar 20 0 191 i = ulong 20 192 x = v 193 for it ulong 20 194 i = sub i 1 195 put d i uchar add rem x 10 48 196 x = div x 10 197 if eq x 0 198 break 199 end 200 end 201 for k ulong sub 20 i bound 20 202 fputc get d add i k 203 end 204 end 205 fn fputb to void 206 for i ulong get fbasel 0 bound 64 207 fputc get fbase i 208 end 209 end 210 fn flink p view uchar * to void 211 fputb 212 fput p 213 end 214 fn fputown to void 215 for i ulong get fownl 0 bound 64 216 fescc get fown i 217 end 218 end 219 fn fputrnm to void 220 for i ulong get frepol 0 bound 128 221 fescc get frepo i 222 end 223 end 224 fn fputrepo to void 225 fputown 226 fputc 47 227 fputrnm 228 end 229 note fputrl: base + owner/repo, for links into the current repo 230 fn fputrl to void 231 fputb 232 fputrepo 233 end 234 note ---- allow-list accessors 235 fn frnlen i ulong to ulong 236 ret get fanl i 237 end 238 fn fridlen i ulong to ulong 239 ret get fail i 240 end 241 fn frnbyte i ulong k ulong to uchar 242 ret get fanm add get fano i k 243 end 244 fn fridbyte i ulong k ulong to uchar 245 ret get faid add get faio i k 246 end 247 fn fputrn i ulong to void 248 for k ulong get fanl i bound 256 249 fescc frnbyte i k 250 end 251 end 252 fn fputrid i ulong to void 253 for k ulong get fail i bound 64 254 fputc fridbyte i k 255 end 256 end 257 fn fputbr i ulong to void 258 o = get fabo i 259 for k ulong get fabl i bound 64 260 fescc get fabr add o k 261 end 262 end 263 fn fdesc i ulong to void 264 o = get fado i 265 for k ulong get fadl i bound 4096 266 fescc get fadesc add o k 267 end 268 end 269 note fputlc: last commit of repo i, "YYYY-MM-DD shortsha subject", escaped, at most 200 bytes (falc keeps 270 note up to 1000 for the JSON subject) 271 fn fputlc i ulong to void 272 o = get falco i 273 for k ulong hmin get falcl i 200 bound 1024 274 fescc get falc add o k 275 end 276 end 277 fn fnmeq i ulong to bool 278 l = get fanl i 279 if ne l get frepol 0 280 ret false 281 end 282 o = get fano i 283 for k ulong l bound 256 284 if ne get fanm add o k get frepo k 285 ret false 286 end 287 end 288 ret true 289 end 290 fn frepoix to ulong 291 for i ulong get fan 0 bound FAMAX 292 if fnmeq i 293 ret i 294 end 295 end 296 ret 9999 297 end 298 note ---- query and form fields: s 0 = fqs, 1 = fbody 299 fn fsrcb s ulong k ulong to uchar 300 if eq s 0 301 ret get fqs k 302 end 303 ret get fbody k 304 end 305 fn fsrcl s ulong to ulong 306 if eq s 0 307 ret get fqsl 0 308 end 309 ret get fbodyl 0 310 end 311 fn fhexv c uchar to long 312 if and ge c 48 le c 57 313 ret long sub c 48 314 end 315 if and ge c 97 le c 102 316 ret long sub c 87 317 end 318 if and ge c 65 le c 70 319 ret long sub c 55 320 end 321 ret -1 322 end 323 note fpmat: field name n starts at i and is followed by '=' 324 fn fpmat s ulong i ulong ln ulong n view uchar * to bool 325 e = add i len n 326 if ge e ln 327 ret false 328 end 329 for k ulong len n bound 4096 330 if ne fsrcb s add i k get n k 331 ret false 332 end 333 end 334 ret eq fsrcb s e 61 335 end 336 fn fpnext s ulong i ulong ln ulong to ulong 337 j = i 338 while lt j ln bound 70000 339 if eq fsrcb s j 38 340 ret add j 1 341 end 342 j = add j 1 343 end 344 ret ln 345 end 346 note fpdec: percent-decode from a to the next '&' into fval; returns the length (cap 4096) 347 fn fpdec s ulong a ulong ln ulong to long 348 j = a 349 o = ulong 0 350 while lt j ln bound 70000 351 c = fsrcb s j 352 if eq c 38 353 break 354 end 355 if ge o 4096 356 break 357 end 358 j = add j 1 359 if eq c 43 360 c = uchar 32 361 end 362 if eq c 37 363 c = fpct s j ln 364 if lt add j 1 ln 365 j = add j 2 366 end 367 end 368 put fval o c 369 o = add o 1 370 end 371 ret long o 372 end 373 fn fpct s ulong j ulong ln ulong to uchar 374 if ge add j 1 ln 375 ret uchar 37 376 end 377 a = fhexv fsrcb s j 378 b = fhexv fsrcb s add j 1 379 if or lt a 0 lt b 0 380 ret uchar 37 381 end 382 ret uchar add mul a 16 b 383 end 384 fn fparam s ulong n view uchar * to long 385 ln = fsrcl s 386 i = ulong 0 387 while lt i ln bound 70000 388 if fpmat s i ln n 389 ret fpdec s add add i len n 1 ln 390 end 391 i = fpnext s i ln 392 end 393 ret -1 394 end 395 fn fqget n view uchar * to long 396 ret fparam 0 n 397 end 398 fn fbget n view uchar * to long 399 ret fparam 1 n 400 end 401 note ---- response setters 402 fn flocb to void 403 put flocl 0 0 404 for i ulong get fbasel 0 bound 64 405 flocc get fbase i 406 end 407 end 408 fn flocc c uchar to void 409 n = get flocl 0 410 if lt n len floc 411 put floc n c 412 put flocl 0 add n 1 413 ret 414 end 415 note a Location over 4096 bytes is not sent cut either: the same flag, the same 500 416 put fobtr 0 1 417 end 418 fn floct t view uchar * to void 419 for i ulong len t bound 4096 420 flocc get t i 421 end 422 end 423 note flocrepo: Location = base + owner/repo 424 fn flocrepo to void 425 flocb 426 for i ulong get fownl 0 bound 64 427 flocc get fown i 428 end 429 flocc 47 430 for i ulong get frepol 0 bound 128 431 flocc get frepo i 432 end 433 end 434 fn fctc c uchar to void 435 n = get fctl 0 436 if lt n len fct 437 put fct n c 438 put fctl 0 add n 1 439 end 440 end 441 fn fsetct t view uchar * to void 442 put fctl 0 0 443 for i ulong len t bound 128 444 fctc get t i 445 end 446 end 447 fn fcdc c uchar to void 448 n = get fcdl 0 449 if lt n len fcd 450 put fcd n c 451 put fcdl 0 add n 1 452 end 453 end 454 fn fsetcd t view uchar * to void 455 put fcdl 0 0 456 for i ulong len t bound 512 457 fcdc get t i 458 end 459 end 460 fn ftic c uchar to void 461 n = get ftil 0 462 if lt n len fti 463 put fti n c 464 put ftil 0 add n 1 465 end 466 end 467 fn fsetti t view uchar * to void 468 put ftil 0 0 469 for i ulong len t bound 256 470 ftic get t i 471 end 472 end 473 note ftirepo: append owner/repo to the title 474 fn ftirepo to void 475 for i ulong get fownl 0 bound 64 476 ftic get fown i 477 end 478 ftic 47 479 for i ulong get frepol 0 bound 128 480 ftic get frepo i 481 end 482 end 483 fn fscc c uchar to void 484 n = get fsckl 0 485 if lt n len fsck 486 put fsck n c 487 put fsckl 0 add n 1 488 end 489 end 490 fn fsetsck t view uchar * to void 491 put fsckl 0 0 492 for i ulong len t bound 512 493 fscc get t i 494 end 495 end 496 fn fetc c uchar to void 497 n = get fetagl 0 498 if lt n len fetag 499 put fetag n c 500 put fetagl 0 add n 1 501 end 502 end 503 fn fccc c uchar to void 504 n = get fccl 0 505 if lt n len fcc 506 put fcc n c 507 put fccl 0 add n 1 508 end 509 end 510 fn fsetcc t view uchar * to void 511 put fccl 0 0 512 for i ulong len t bound 128 513 fccc get t i 514 end 515 end 516 fn ffilc c uchar to void 517 n = get ffilel 0 518 if lt n 4095 519 put ffile n c 520 put ffilel 0 add n 1 521 end 522 end 523 note ---- packed argument list fpk (u16 count, then u16 length + bytes per record) 524 fn fkb to void 525 put fpk 0 0 526 put fpk 1 0 527 put fpkl 0 2 528 end 529 fn fkopen to void 530 n = get fpkl 0 531 if ge n 8190 532 ret 533 end 534 put fpkr 0 n 535 put fpk n 0 536 put fpk add n 1 0 537 put fpkl 0 add n 2 538 c = add or ulong get fpk 0 shl ulong get fpk 1 8 1 539 put fpk 0 uchar and c 255 540 put fpk 1 uchar shr c 8 541 end 542 fn fkc c uchar to void 543 n = get fpkl 0 544 if lt n 8191 545 put fpk n c 546 put fpkl 0 add n 1 547 r = get fpkr 0 548 k = add or ulong get fpk r shl ulong get fpk add r 1 8 1 549 put fpk r uchar and k 255 550 put fpk add r 1 uchar shr k 8 551 end 552 end 553 fn fkt t view uchar * to void 554 for i ulong len t bound 8192 555 fkc get t i 556 end 557 end 558 fn fka t view uchar * to void 559 fkopen 560 fkt t 561 end 562 note fkrid: append the current repo RID to the open argument 563 fn fkrid to void 564 for i ulong get fridl 0 bound 64 565 fkc get frid i 566 end 567 end 568 note fkgit: argv = /usr/bin/git --git-dir=/ (store: the current repo's repo.git) 569 global fpubgit ulong 1 570 text tfpubgit "/app/public-git/" 571 text tfpubext ".git" 572 note fksource: public browse and download objects. Signed catalog, records and proposal checks use fkgit/fkgiti. 573 fn fksource to void 574 if eq get fpubgit 0 0 575 fkgit 576 ret 577 end 578 fkb 579 fka tfgit 580 fkopen 581 fkt tfgitdir 582 fkt tfpubgit 583 i = get fridx 0 584 if lt i get fan 0 585 for k ulong get fanl i bound 128 586 fkc frnbyte i k 587 end 588 end 589 fkt tfpubext 590 end 591 fn fkgit to void 592 fkb 593 fka tfgit 594 fkopen 595 fkt tfgitdir 596 if eq get fsrcst 0 1 597 fksdir get fridx 0 598 ret 599 end 600 fkt tfstore 601 fkrid 602 end 603 note fkgiti: the same for allow-list repo i 604 fn fkgiti i ulong to void 605 fkb 606 fka tfgit 607 fkopen 608 fkt tfgitdir 609 if eq get fsrcst 0 1 610 fksdir i 611 ret 612 end 613 fkt tfstore 614 for k ulong get fail i bound 64 615 fkc fridbyte i k 616 end 617 end 618 note fksdir: projects//repo.git into the open argument (no name past the list) 619 fn fksdir i ulong to void 620 for k ulong get fsrtl 0 bound 4096 621 fkc get fsrt k 622 end 623 fkt tfsprj 624 if lt i get fan 0 625 for k ulong get fanl i bound 128 626 fkc frnbyte i k 627 end 628 end 629 fkt tfsrg 630 end 631 note ---- run argv fpk: no shell, no PATH, empty environment, stdout into fxo 632 fn fpfdv i ulong to int 633 b = mul i 4 634 v = or ulong get fpfd b shl ulong get fpfd add b 1 8 635 v = or v shl ulong get fpfd add b 2 16 636 v = or v shl ulong get fpfd add b 3 24 637 ret int v 638 end 639 fn fchild wfd int to void 640 fchildin wfd -1 641 end 642 fn fchildin wfd int infd int to void 643 nul = fopen tfdevnul 0 len tfdevnul 2 0 644 if lt nul 0 645 exit 126 646 end 647 input = infd 648 if lt input 0 649 input = int nul 650 end 651 x = dupfd input 0 0 652 if lt x 0 653 exit 126 654 end 655 x = dupfd wfd 1 0 656 x = dupfd int nul 2 0 657 x = execprog fpk 0 get fpkl 0 658 exit 127 659 end 660 fn fdrain fd int dl long to bool 661 for it ulong `10000000` 662 left = sub dl long monons 663 if le left 0 664 ret false 665 end 666 w = waitio fd 1 left 667 if lt w 0 668 if ne w -4 669 ret false 670 end 671 continue 672 end 673 if eq w 0 674 continue 675 end 676 n = get fxol 0 677 if ge n len fxo 678 put fxotr 0 1 679 r = read fd fjunk 0 4096 680 if eq r 0 681 ret true 682 end 683 if lt r 0 684 if and ne r -4 ne r -11 685 ret false 686 end 687 end 688 continue 689 end 690 r = read fd fxo n sub len fxo n 691 if eq r 0 692 ret true 693 end 694 if lt r 0 695 if and ne r -4 ne r -11 696 ret false 697 end 698 continue 699 end 700 put fxol 0 add n ulong r 701 end 702 ret false 703 end 704 fn freap pid int dl long to long 705 for it ulong `1000000` 706 w = waitpid pid fwst 0 4 1 707 if eq w long pid 708 s = or ulong get fwst 0 shl ulong get fwst 1 8 709 if eq and s 127 0 710 ret long and shr s 8 255 711 end 712 ret -3 713 end 714 if lt w 0 715 if ne w -4 716 ret -4 717 end 718 continue 719 end 720 if gt long monons dl 721 x = killpid pid 9 722 w = waitpid pid fwst 0 4 0 723 ret -1 724 end 725 x = sleepns 200000 726 end 727 ret -4 728 end 729 fn fexec tmo long to long 730 ret fexecin tmo -1 731 end 732 fn fexecin tmo long infd int to long 733 put fxol 0 0 734 put fxotr 0 0 735 r = pipefds fpfd 0 8 524288 736 if lt r 0 737 ret -2 738 end 739 rfd = fpfdv 0 740 wfd = fpfdv 1 741 dl = add long monons tmo 742 pid = fork 743 if lt pid 0 744 x = fclose rfd 745 x = fclose wfd 746 ret -2 747 end 748 if eq pid 0 749 fchildin wfd infd 750 exit 127 751 end 752 x = fclose wfd 753 ok = fdrain rfd dl 754 x = fclose rfd 755 if not ok 756 x = killpid int pid 9 757 end 758 st = freap int pid dl 759 if not ok 760 ret -1 761 end 762 ret st 763 end 764 fn fxput a ulong n ulong to void 765 for i ulong n bound `16777216` 766 fputc get fxo add a i 767 end 768 end 769 fn fxesc a ulong n ulong to void 770 for i ulong n bound `16777216` 771 fescc get fxo add a i 772 end 773 end 774 note ---- streaming exec: a listing longer than fxo is read through it in windows, one record at a time 775 note (the cut copy of fexec is never taken for the whole). fsopen starts argv fpk like fexec; fsnext C 776 note returns the end e of the next record (the bytes up to the next C, or up to the end of the output), 777 note which is fxo[get fsrs 0, e) until the next fsnext call. fsnext returns FSEND at the end of the output 778 note and FSFAIL on a timeout, a read error, or one record longer than fxo (fxotr is set then: the 779 note caller answers the whole 500 of fincut). fsclose ends the child (killed if it is still writing) 780 note and returns its exit status, or -1 when the output was not read to its end. 781 const FSEND ulong `16777217` 782 const FSFAIL ulong `16777218` 783 fn fsopen tmo long to bool 784 put fxol 0 0 785 put fxotr 0 0 786 put fsp 0 0 787 put fsq 0 0 788 put fsrs 0 0 789 put fsst 3 2 790 r = pipefds fpfd 0 8 524288 791 if lt r 0 792 ret false 793 end 794 rfd = fpfdv 0 795 wfd = fpfdv 1 796 pid = fork 797 if lt pid 0 798 x = fclose rfd 799 x = fclose wfd 800 ret false 801 end 802 if eq pid 0 803 fchild wfd 804 exit 127 805 end 806 x = fclose wfd 807 put fsst 0 long rfd 808 put fsst 1 long pid 809 put fsst 2 add long monons tmo 810 put fsst 3 0 811 ret true 812 end 813 note fsfill: move the unread bytes fxo[fsp, fxol) to the front, then read until fxo is full or the 814 note output ends. false on a timeout or read error. 815 fn fsfill to bool 816 p = get fsp 0 817 n = get fxol 0 818 if gt p 0 819 for i ulong sub n p bound `16777216` 820 put fxo i get fxo add p i 821 end 822 put fxol 0 sub n p 823 put fsq 0 sub get fsq 0 p 824 put fsrs 0 0 825 put fsp 0 0 826 end 827 if ne get fsst 3 0 828 ret eq get fsst 3 1 829 end 830 fd = int get fsst 0 831 dl = get fsst 2 832 for it ulong `100000000` 833 m = get fxol 0 834 if ge m len fxo 835 ret true 836 end 837 left = sub dl long monons 838 if le left 0 839 put fsst 3 2 840 ret false 841 end 842 w = waitio fd 1 left 843 if lt w 0 844 if ne w -4 845 put fsst 3 2 846 ret false 847 end 848 continue 849 end 850 if eq w 0 851 continue 852 end 853 r = read fd fxo m sub len fxo m 854 if eq r 0 855 put fsst 3 1 856 ret true 857 end 858 if lt r 0 859 if and ne r -4 ne r -11 860 put fsst 3 2 861 ret false 862 end 863 continue 864 end 865 put fxol 0 add m ulong r 866 end 867 put fsst 3 2 868 ret false 869 end 870 fn fsnext c uchar to ulong 871 for it ulong `100000000` 872 s = get fsp 0 873 n = get fxol 0 874 q = get fsq 0 875 while lt q n bound `16777216` 876 if eq get fxo q c 877 put fsrs 0 s 878 put fsp 0 add q 1 879 put fsq 0 add q 1 880 ret q 881 end 882 q = add q 1 883 end 884 put fsq 0 q 885 if eq get fsst 3 1 886 if lt s n 887 put fsrs 0 s 888 put fsp 0 n 889 ret n 890 end 891 ret FSEND 892 end 893 if and eq s 0 ge n len fxo 894 put fxotr 0 1 895 ret FSFAIL 896 end 897 if not fsfill 898 ret FSFAIL 899 end 900 end 901 ret FSFAIL 902 end 903 fn fsclose to long 904 fd = int get fsst 0 905 x = fclose fd 906 pid = int get fsst 1 907 done = eq get fsst 3 1 908 if not done 909 x = killpid pid 9 910 end 911 st = freap pid get fsst 2 912 put fsst 3 2 913 if not done 914 ret -1 915 end 916 ret st 917 end 918 note ---- path builder fpth and whole-file read into fxo 919 fn fpb to void 920 put fpthl 0 0 921 end 922 fn fpc c uchar to void 923 n = get fpthl 0 924 if lt n 4095 925 put fpth n c 926 put fpthl 0 add n 1 927 end 928 end 929 fn fpt t view uchar * to void 930 for i ulong len t bound 4096 931 fpc get t i 932 end 933 end 934 note frdall: read the file at fpth (up to the size of fxo) into fxo; returns bytes or -errno 935 fn frdall to long 936 put fxol 0 0 937 put fxotr 0 0 938 fd = fopen fpth 0 get fpthl 0 524288 0 939 if lt fd 0 940 ret fd 941 end 942 for it ulong 100000 943 n = get fxol 0 944 if ge n len fxo 945 put fxotr 0 1 946 break 947 end 948 r = read int fd fxo n sub len fxo n 949 if le r 0 950 break 951 end 952 put fxol 0 add n ulong r 953 end 954 x = fclose int fd 955 ret long get fxol 0 956 end 957 note fmtime: modification time (s) of the file at fpth, 0 when missing 958 fn fmtime to ulong 959 r = stat fpth 0 get fpthl 0 fstb 0 128 960 if lt r 0 961 ret 0 962 end 963 v = ulong 0 964 for i ulong 8 965 v = or v shl ulong get fstb add 88 i mul i 8 966 end 967 ret v 968 end 969 fn flog t view uchar * to void 970 w = write 2 t 0 len t 971 end 972 note ---- per-IP write limit 973 fn frlkey to ulong 974 h = ulong `14695981039346656037` 975 for i ulong get fipl 0 bound 64 976 c = ulong get fip i 977 h = mul xor h c `1099511628211` 978 end 979 ret or h 1 980 end 981 fn frlslot h ulong to ulong 982 e = ulong 256 983 o = ulong 0 984 for i ulong 256 985 k = get frlk i 986 if eq k h 987 ret i 988 end 989 if and eq k 0 eq e 256 990 e = i 991 end 992 a = get frlt i 993 b = get frlt o 994 if lt a b 995 o = i 996 end 997 end 998 if lt e 256 999 ret e 1000 end 1001 ret o 1002 end 1003 fn fratelim to bool 1004 h = frlkey 1005 b = frlslot h 1006 now = div ulong monons `1000000000` 1007 if ne get frlk b h 1008 put frlk b h 1009 put frlt b now 1010 put frlc b 0 1011 end 1012 if gt sub now get frlt b 60 1013 put frlt b now 1014 put frlc b 0 1015 end 1016 c = get frlc b 1017 if ge c 30 1018 ret false 1019 end 1020 put frlc b add c 1 1021 ret true 1022 end 1023 fn fsetsbx to void 1024 put fcspsb 0 1 1025 end 1026 note ---- small byte helpers 1027 fn fisdig c uchar to bool 1028 ret and ge c 48 le c 57 1029 end 1030 fn fisaln c uchar to bool 1031 if fisdig c 1032 ret true 1033 end 1034 if and ge c 65 le c 90 1035 ret true 1036 end 1037 ret and ge c 97 le c 122 1038 end 1039 note fpathat: fpath[i] or 0 past the end 1040 fn fpathat i ulong to uchar 1041 if lt i get fpathl 0 1042 ret get fpath i 1043 end 1044 ret uchar 0 1045 end 1046 note fpeq: fpath equals t exactly 1047 fn fpeq t view uchar * to bool 1048 if ne len t get fpathl 0 1049 ret false 1050 end 1051 for i ulong len t bound 4096 1052 if ne get t i get fpath i 1053 ret false 1054 end 1055 end 1056 ret true 1057 end 1058 note fpre: fpath starts with t 1059 fn fpre t view uchar * to bool 1060 if gt len t get fpathl 0 1061 ret false 1062 end 1063 for i ulong len t bound 4096 1064 if ne get t i get fpath i 1065 ret false 1066 end 1067 end 1068 ret true 1069 end 1070 note frsteq / frstpre: the same tests on frest 1071 fn frsteq t view uchar * to bool 1072 if ne len t get frestl 0 1073 ret false 1074 end 1075 for i ulong len t bound 4096 1076 if ne get t i get frest i 1077 ret false 1078 end 1079 end 1080 ret true 1081 end 1082 fn frstpre t view uchar * to bool 1083 if gt len t get frestl 0 1084 ret false 1085 end 1086 for i ulong len t bound 4096 1087 if ne get t i get frest i 1088 ret false 1089 end 1090 end 1091 ret true 1092 end 1093 note ---- fdclean: the description of repo i as the forge shows it (fadesc[fado i, +fadl i]). 1094 note Radicle was removed from Interplane on 2026-11-14 and some identity documents still name it. 1095 note The stored document is not changed; the copy loaded into fadesc is cut once, at load 1096 note (server/repos.om fdcopy): sentences (ending ". ") that name the retired network are dropped; 1097 note when none is left, the text before the first " (" or ": " is kept if it names nothing retired; 1098 note otherwise the description is empty. 1099 text tfdt1 "radicle" 1100 text tfdt2 "heartwood" 1101 text tfdt3 "rad:z" 1102 text tfdt4 "/rad/" 1103 text tfdt5 "rad clone" 1104 text tfdt6 "rad init" 1105 text tfdt7 "rad sync" 1106 text tfdt8 "rad id" 1107 text tfdt9 "rad patch" 1108 text tfdt10 "rad auth" 1109 note fdhas: does fadesc[a, b) hold t (lowercase ASCII), compared without case 1110 fn fdhas a ulong b ulong t view uchar * to bool 1111 n = len t 1112 if lt b add a n 1113 ret false 1114 end 1115 m = add sub sub b a n 1 1116 for i ulong m bound 65536 1117 ok = true 1118 for k ulong n bound 16 1119 c = get fadesc add add a i k 1120 if and ge c 65 le c 90 1121 c = add c 32 1122 end 1123 if ne c get t k 1124 ok = false 1125 end 1126 end 1127 if ok 1128 ret true 1129 end 1130 end 1131 ret false 1132 end 1133 fn fdterm a ulong b ulong to bool 1134 if or fdhas a b tfdt1 or fdhas a b tfdt2 or fdhas a b tfdt3 fdhas a b tfdt4 1135 ret true 1136 end 1137 if or fdhas a b tfdt5 or fdhas a b tfdt6 or fdhas a b tfdt7 fdhas a b tfdt8 1138 ret true 1139 end 1140 ret or fdhas a b tfdt9 fdhas a b tfdt10 1141 end 1142 note fdfind: the first p in [a, b-1) with fadesc[p] = c1 and fadesc[p+1] = c2, else b 1143 fn fdfind a ulong b ulong c1 uchar c2 uchar to ulong 1144 if le b add a 1 1145 ret b 1146 end 1147 for i ulong sub sub b a 1 bound 65536 1148 p = add a i 1149 x = get fadesc p 1150 y = get fadesc add p 1 1151 if and eq x c1 eq y c2 1152 ret p 1153 end 1154 end 1155 ret b 1156 end 1157 note fdmove: copy fadesc[s, x) down to w (w <= s); the new end of what was written 1158 fn fdmove w ulong s ulong x ulong to ulong 1159 for k ulong sub x s bound 65536 1160 c = get fadesc add s k 1161 put fadesc add w k c 1162 end 1163 ret add w sub x s 1164 end 1165 fn fdskip s ulong e ulong to ulong 1166 p = s 1167 while lt p e bound 65537 1168 if ne get fadesc p 32 1169 ret p 1170 end 1171 p = add p 1 1172 end 1173 ret p 1174 end 1175 note fdsent: keep the sentences of fadesc[o, e) that name nothing retired, packed from o, one 1176 note space apart; the end of what was kept (o when none was) 1177 fn fdsent o ulong e ulong to ulong 1178 w = o 1179 s = o 1180 while lt s e bound 65537 1181 d = fdfind s e 46 32 1182 x = e 1183 if lt d e 1184 x = add d 1 1185 end 1186 if not fdterm s x 1187 if gt w o 1188 put fadesc w 32 1189 w = add w 1 1190 end 1191 w = fdmove w s x 1192 end 1193 s = fdskip x e 1194 end 1195 ret w 1196 end 1197 fn fdclean i ulong to void 1198 o = get fado i 1199 e = add o get fadl i 1200 if not fdterm o e 1201 ret 1202 end 1203 w = fdsent o e 1204 if gt w o 1205 put fadl i sub w o 1206 ret 1207 end 1208 p = fdfind o e 32 40 1209 if and gt p o not fdterm o p 1210 put fadl i sub p o 1211 ret 1212 end 1213 p = fdfind o e 58 32 1214 if and gt p o not fdterm o p 1215 put fadl i sub p o 1216 ret 1217 end 1218 put fadl i 0 1219 end