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/aien/blob/main/src/bots/bots.om # aien aien-dev/aien Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien / src / bots / bots.om` 755 lines ยท 11556 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-or-later 2 note Local bot journal only. Concatenate after pinned Omega sha256-om2 unit. 3 global BR uchar 1024 4 global BJ uchar `1048576` 5 global BB uchar 65536 6 global BL uchar 2048 7 global BM uchar 262144 8 global BC uchar 8192 9 global BS ulong 256 10 global BT ulong 64 11 global BV ulong 12 12 global BA uchar 4096 13 global BP uchar 4096 14 global BK uchar 4096 15 global BF uchar 4096 16 global BD uchar 4096 17 global BN uchar 8192 18 global BO uchar 4096 19 text bdom "AIEN-BOT-V1" 20 text mdom "AIEN-BOT-MESSAGE-V1" 21 text hx "`0123456789abcdef`" 22 text ec "REFUSE " 23 text ok "OK " 24 text dup "DUPLICATE " 25 text bn "BOT " 26 text ln "LEASE " 27 text mn "MESSAGE " 28 text cmds "register rotate deliver claim ack nack expire retire show" 29 text kenv "BOTS_KILL=" 30 31 text lockend ".lock" 32 text candend ".cand" 33 global BH uchar 32 34 fn bg s ulong p ulong to uchar 35 if eq s 1 36 ret get BR p 37 end 38 if eq s 2 39 ret get BJ p 40 end 41 if eq s 3 42 ret get BB p 43 end 44 if eq s 4 45 ret get BL p 46 end 47 if eq s 5 48 ret get BM p 49 end 50 if eq s 6 51 ret get BC p 52 end 53 if eq s 7 54 ret get BA p 55 end 56 if eq s 8 57 ret get BP p 58 end 59 if eq s 9 60 ret get BK p 61 end 62 if eq s 10 63 ret get BF p 64 end 65 if eq s 11 66 ret get BD p 67 end 68 if eq s 12 69 ret get BN p 70 end 71 if eq s 13 72 ret get BO p 73 end 74 if eq s 14 75 ret get BH p 76 end 77 if eq s 15 78 ret get cmds p 79 end 80 if eq s 16 81 ret get kenv p 82 end 83 if eq s 17 84 ret get lockend p 85 end 86 if eq s 18 87 ret get candend p 88 end 89 bfail 3 90 ret 0 91 end 92 fn bp s ulong p ulong v uchar to void 93 if eq s 1 94 put BR p v 95 ret 96 end 97 if eq s 2 98 put BJ p v 99 ret 100 end 101 if eq s 3 102 put BB p v 103 ret 104 end 105 if eq s 4 106 put BL p v 107 ret 108 end 109 if eq s 5 110 put BM p v 111 ret 112 end 113 if eq s 6 114 put BC p v 115 ret 116 end 117 if eq s 7 118 put BA p v 119 ret 120 end 121 if eq s 8 122 put BP p v 123 ret 124 end 125 if eq s 9 126 put BK p v 127 ret 128 end 129 if eq s 10 130 put BF p v 131 ret 132 end 133 if eq s 11 134 put BD p v 135 ret 136 end 137 if eq s 12 138 put BN p v 139 ret 140 end 141 if eq s 13 142 put BO p v 143 ret 144 end 145 if eq s 14 146 put BH p v 147 ret 148 end 149 bfail 3 150 end 151 fn bfail code int to void 152 w = write 1 ec 0 len ec 153 bdecimal ulong code 154 bend 155 exit code 156 end 157 fn bcheck yes bool code int to void 158 if not yes 159 bfail code 160 end 161 end 162 fn bwrite fd int s ulong off ulong n ulong to void 163 p = ulong 0 164 while lt p n bound 999999 165 w = long 0 166 if eq s 1 167 w = write fd BR add off p sub n p 168 else 169 w = write fd BJ add off p sub n p 170 end 171 bcheck gt w 0 3 172 p = add p ulong w 173 end 174 end 175 fn bdecimal v ulong to void 176 if gt v 9 177 bdecimal div v 10 178 end 179 put BO 0 uchar add rem v 10 48 180 w = write 1 BO 0 1 181 bcheck eq w 1 3 182 end 183 fn bend to void 184 put BO 0 10 185 w = write 1 BO 0 1 186 bcheck eq w 1 3 187 end 188 fn bspace to void 189 put BO 0 32 190 w = write 1 BO 0 1 191 bcheck eq w 1 3 192 end 193 fn bhex s ulong off ulong n ulong to void 194 for i ulong n 195 v = ulong bg s add off i 196 put BO mul i 2 get hx shr v 4 197 put BO add mul i 2 1 get hx and v 15 198 end 199 w = write 1 BO 0 mul n 2 200 bcheck eq w long mul n 2 3 201 end 202 fn bcopy ds ulong dp ulong ss ulong sp ulong n ulong to void 203 for i ulong n 204 bp ds add dp i bg ss add sp i 205 end 206 end 207 fn bequal ds ulong dp ulong ss ulong sp ulong n ulong to bool 208 for i ulong n 209 if ne bg ds add dp i bg ss add sp i 210 ret false 211 end 212 end 213 ret true 214 end 215 fn bzero s ulong off ulong n ulong to bool 216 v = uchar 0 217 for i ulong n 218 v = or v bg s add off i 219 end 220 ret eq v 0 221 end 222 fn bget a ulong to ulong 223 v = ulong 0 224 for i ulong 8 225 v = or shl v 8 ulong get BR add a i 226 end 227 ret v 228 end 229 fn bset a ulong v ulong to void 230 for i ulong 8 231 put BR add a i uchar and shr v mul sub 7 i 8 255 232 end 233 end 234 fn bclear to void 235 for i ulong 1024 236 put BR i 0 237 end 238 end 239 fn barg n ulong to ulong 240 r = argread n BA 0 len BA 241 bcheck ge r 0 2 242 ret ulong r 243 end 244 fn bnyb c uchar to uchar 245 if and ge c 48 le c 57 246 ret sub c 48 247 end 248 if and ge c 97 le c 102 249 ret add sub c 97 10 250 end 251 bfail 2 252 ret 0 253 end 254 fn bparse n ulong off ulong to void 255 r = barg n 256 note BOT-GUARD hex 257 bcheck eq r 64 2 258 for i ulong 32 259 v = shl bnyb get BA mul i 2 4 260 put BR add off i or v bnyb get BA add mul i 2 1 261 end 262 note BOT-GUARD nonzero 263 bcheck not bzero 1 off 32 4 264 end 265 fn brefs n ulong off ulong to void 266 r = barg n 267 if and eq r 1 eq get BA 0 45 268 ret 269 end 270 note BOT-GUARD refs 271 bcheck and le r 259 eq rem add r 1 65 0 2 272 cnt = div add r 1 65 273 for j ulong cnt 274 for i ulong 32 275 p = add mul j 65 mul i 2 276 v = shl bnyb get BA p 4 277 v = or v bnyb get BA add p 1 278 p = add off mul j 32 279 put BR add p i v 280 end 281 bcheck not bzero 1 add off mul j 32 32 4 282 if lt add j 1 cnt 283 bcheck eq get BA add mul j 65 64 44 2 284 end 285 end 286 end 287 fn bhash mode ulong to void 288 p = new uchar 1024 0 289 d = new uchar 32 0 290 n = ulong 992 291 dest = ulong 992 292 if eq mode 0 293 for i ulong 992 294 put p i get BR i 295 end 296 else 297 if eq mode 1 298 for i ulong len bdom 299 put p i get bdom i 300 end 301 n = add len bdom 97 302 for i ulong 96 303 put p add add len bdom 1 i get BR add 48 i 304 end 305 dest = 16 306 else 307 for i ulong len mdom 308 put p i get mdom i 309 end 310 n = add len mdom 129 311 for i ulong 32 312 put p add add len mdom 1 i get BR add 16 i 313 end 314 for i ulong 96 315 put p add add len mdom 33 i get BR add 48 i 316 end 317 dest = 144 318 end 319 end 320 sha256_hash part p 0 n d 321 for i ulong 32 322 put BR add dest i get d i 323 end 324 end 325 fn bpayload n ulong to void 326 p = new uchar 4096 0 327 d = new uchar 32 0 328 r = barg n 329 for i ulong r 330 put p i get BA i 331 end 332 sha256_hash part p 0 r d 333 for i ulong 32 334 put BR add 80 i get d i 335 end 336 end 337 fn bcommand to ulong 338 n = barg 1 339 p = ulong 0 340 for k ulong 9 341 q = p 342 while lt p len cmds bound 64 343 if eq get cmds p 32 344 break 345 end 346 p = add p 1 347 end 348 if eq n sub p q 349 if bequal 7 0 15 q n 350 ret add k 1 351 end 352 end 353 p = add p 1 354 end 355 bfail 2 356 ret 0 357 end 358 fn bargs t ulong to void 359 bclear 360 put BR 0 66 361 put BR 1 74 362 put BR 2 84 363 put BR 3 49 364 put BR 4 uchar t 365 if eq t 1 366 bcheck eq argcnt 10 2 367 bparse 3 48 368 bparse 4 80 369 bparse 5 112 370 r = barg 6 371 note BOT-GUARD name 372 bcheck and gt r 0 le r 64 2 373 for i ulong r 374 bcheck and ge get BA i 32 le get BA i 126 2 375 put BR add 144 i get BA i 376 end 377 brefs 7 208 378 brefs 8 336 379 brefs 9 464 380 bhash 1 381 ret 382 end 383 if eq t 9 384 bcheck eq argcnt 3 2 385 ret 386 end 387 bparse 3 16 388 if eq t 8 389 bcheck eq argcnt 4 2 390 ret 391 end 392 if eq t 2 393 bcheck eq argcnt 5 2 394 bparse 4 48 395 ret 396 end 397 if eq t 3 398 bcheck eq argcnt 7 2 399 bparse 4 48 400 bpayload 5 401 bparse 6 112 402 bhash 2 403 ret 404 end 405 bcheck eq argcnt 6 2 406 bparse 4 48 407 bparse 5 80 408 end 409 fn bfind to ulong 410 for i ulong get BV 1 411 if bequal 1 16 3 add mul i 1024 16 32 412 ret i 413 end 414 end 415 bfail 11 416 ret 0 417 end 418 fn bmfind to ulong 419 for i ulong get BV 2 420 if bequal 1 16 5 add mul i 1024 16 32 421 if bequal 1 48 5 add mul i 1024 144 32 422 ret i 423 end 424 end 425 end 426 bfail 14 427 ret 0 428 end 429 fn bcurrent b ulong off ulong to void 430 note BOT-GUARD current 431 bcheck bequal 1 off 4 mul b 32 32 15 432 end 433 fn bregister to void 434 for i ulong get BV 1 435 note BOT-GUARD registered 436 bcheck not bequal 1 16 3 add mul i 1024 16 32 10 437 end 438 note BOT-GUARD botcap 439 bcheck lt get BV 1 64 5 440 b = get BV 1 441 bcopy 3 mul b 1024 1 0 1024 442 put BT b 1 443 put BV 1 add b 1 444 end 445 fn brotate b ulong to void 446 for i ulong sub bget 8 1 447 p = mul i 1024 448 if eq get BJ add p 4 2 449 if bequal 2 add p 16 1 16 32 450 note BOT-GUARD leaseunique 451 bcheck not bequal 2 add p 48 1 48 32 13 452 end 453 end 454 end 455 bcopy 4 mul b 32 1 48 32 456 end 457 fn bdeliver to void 458 for i ulong get BV 2 459 if bequal 1 144 5 add mul i 1024 144 32 460 note BOT-GUARD dedup 461 put BV 3 1 462 ret 463 end 464 end 465 note BOT-GUARD msgcap 466 bcheck lt get BV 2 256 5 467 i = get BV 2 468 bcopy 5 mul i 1024 1 0 1024 469 put BS i 1 470 put BV 2 add i 1 471 end 472 fn bmessage t ulong b ulong to void 473 m = bmfind 474 s = get BS m 475 if eq t 4 476 note BOT-GUARD pending 477 bcheck eq s 1 16 478 bcurrent b 80 479 bcopy 6 mul m 32 1 80 32 480 put BS m 2 481 ret 482 end 483 note BOT-GUARD claimed 484 bcheck eq s 2 17 485 note BOT-GUARD claimant 486 bcheck bequal 1 80 6 mul m 32 32 18 487 if eq t 7 488 note BOT-GUARD expiry 489 bcheck not bequal 1 80 4 mul b 32 32 19 490 else 491 bcurrent b 80 492 end 493 if eq t 5 494 put BS m 3 495 else 496 put BS m 1 497 end 498 for i ulong 32 499 put BC add mul m 32 i 0 500 end 501 end 502 fn bapply to void 503 put BV 3 0 504 t = ulong get BR 4 505 note BOT-GUARD type 506 bcheck and gt t 0 le t 8 6 507 if eq t 1 508 bregister 509 ret 510 end 511 b = bfind 512 note BOT-GUARD active 513 bcheck eq get BT b 1 12 514 if eq t 2 515 brotate b 516 ret 517 end 518 if eq t 3 519 bdeliver 520 ret 521 end 522 if eq t 8 523 put BT b 2 524 ret 525 end 526 bmessage t b 527 end 528 fn bshape to void 529 note BOT-GUARD magic 530 bcheck and and eq get BR 0 66 eq get BR 1 74 and eq get BR 2 84 eq get BR 3 49 6 531 t = ulong get BR 4 532 note BOT-GUARD botvalue 533 bcheck not bzero 1 16 32 6 534 note BOT-GUARD reserved 535 bcheck bzero 1 5 3 6 536 if eq t 1 537 note BOT-GUARD bindings 538 bcheck and not bzero 1 48 32 and not bzero 1 80 32 not bzero 1 112 32 6 539 bcopy 14 0 1 16 32 540 bhash 1 541 note BOT-GUARD identity 542 bcheck bequal 14 0 1 16 32 6 543 z = ulong 0 544 for i ulong 64 545 v = get BR add 144 i 546 if eq v 0 547 z = 1 548 else 549 note BOT-GUARD display 550 bcheck and eq z 0 and ge v 32 le v 126 6 551 end 552 end 553 note BOT-GUARD nonempty 554 bcheck ne get BR 144 0 6 555 end 556 if eq t 2 557 note BOT-GUARD leasevalue 558 bcheck not bzero 1 48 32 6 559 end 560 if eq t 3 561 note BOT-GUARD envelope 562 bcheck and not bzero 1 48 32 not bzero 1 112 32 6 563 bcopy 14 0 1 144 32 564 bhash 2 565 note BOT-GUARD content 566 bcheck bequal 14 0 1 144 32 6 567 end 568 if and ge t 4 le t 7 569 note BOT-GUARD transition 570 bcheck and not bzero 1 48 32 not bzero 1 80 32 6 571 end 572 n = ulong 48 573 if eq t 1 574 n = 592 575 end 576 if eq t 2 577 n = 80 578 end 579 if eq t 3 580 n = 176 581 end 582 if and ge t 4 le t 7 583 n = 112 584 end 585 note BOT-GUARD padding 586 bcheck bzero 1 n sub 992 n 6 587 end 588 fn breplay to void 589 p = ulong 0 590 while lt p get BV 0 bound 1024 591 bcopy 1 0 2 p 1024 592 bshape 593 note BOT-GUARD sequence 594 bcheck eq bget 8 add div p 1024 1 7 595 bcopy 14 0 1 992 32 596 bhash 0 597 note BOT-GUARD checksum 598 bcheck bequal 14 0 1 992 32 8 599 bapply 600 p = add p 1024 601 end 602 end 603 fn bpaths to void 604 n = argread 2 BP 0 2048 605 bcheck and gt n 0 lt n 2048 2 606 put BV 4 ulong n 607 bcopy 9 0 8 0 ulong n 608 bcopy 10 0 8 0 ulong n 609 bcopy 9 ulong n 17 0 5 610 bcopy 10 ulong n 18 0 5 611 p = ulong 0 612 for i ulong ulong n 613 if eq get BP i 47 614 p = add i 1 615 end 616 end 617 bcheck lt p ulong n 2 618 if eq p 0 619 put BD 0 46 620 put BV 5 1 621 else 622 bcopy 11 0 8 0 p 623 put BV 5 p 624 end 625 note packed path pair for renameat2 626 put BN 0 2 627 put BN 2 uchar and add ulong n 5 255 628 put BN 3 uchar shr add ulong n 5 8 629 bcopy 12 4 10 0 add ulong n 5 630 p = add ulong n 9 631 put BN p uchar and ulong n 255 632 put BN add p 1 uchar shr ulong n 8 633 bcopy 12 add p 2 8 0 ulong n 634 put BV 6 add p add ulong n 2 635 end 636 fn bload to void 637 n = get BV 4 638 note Linux aarch64 O_NOFOLLOW=`0100000` and O_DIRECTORY=040000 639 lk = int fopen BK 0 add n 5 or int 32768 int 66 384 640 bcheck ge lk 0 3 641 note BOT-GUARD lock 642 bcheck eq flock lk 6 0 9 643 put BV 7 ulong lk 644 fd = fopen BP 0 n 32768 0 645 if eq fd -2 646 ret 647 end 648 bcheck ge fd 0 3 649 p = ulong 0 650 while lt p len BJ bound 999999 651 r = read int fd BJ p sub len BJ p 652 bcheck ge r 0 3 653 if eq r 0 654 break 655 end 656 p = add p ulong r 657 end 658 x = new uchar 1 0 659 r = read int fd x 0 1 660 bcheck eq r 0 5 661 bcheck eq fclose int fd 0 3 662 note BOT-GUARD alignment 663 bcheck eq rem p 1024 0 6 664 put BV 0 p 665 breplay 666 end 667 fn bfault n ulong to void 668 for i ulong ulong envcnt 669 r = envread i BA 0 len BA 670 if eq r 11 671 if bequal 7 0 16 0 10 672 if eq ulong get BA 10 add n 48 673 w = killpid int getpid 9 674 bfail 3 675 end 676 end 677 end 678 end 679 end 680 fn bcommit to void 681 n = get BV 4 682 note BOT-GUARD eventcap 683 bcheck lt get BV 0 len BJ 5 684 fd = int fopen BF 0 add n 5 or int 32768 int 578 384 685 bcheck ge fd 0 3 686 bfault 1 687 bwrite fd 2 0 get BV 0 688 bfault 2 689 bwrite fd 1 0 1024 690 bfault 3 691 bcheck eq fsync fd 0 3 692 bfault 4 693 bcheck eq fclose fd 0 3 694 bcheck eq renames BN 0 get BV 6 0 0 3 695 bfault 5 696 df = int fopen BD 0 get BV 5 or int 32768 int 16384 0 697 bcheck ge df 0 3 698 bcheck eq fsync df 0 3 699 bfault 6 700 bcheck eq fclose df 0 3 701 end 702 fn bshow to void 703 for i ulong get BV 1 704 w = write 1 bn 0 len bn 705 bhex 3 mul i 1024 592 706 bspace 707 bdecimal get BT i 708 bend 709 w = write 1 ln 0 len ln 710 bhex 3 add mul i 1024 16 32 711 bspace 712 bhex 4 mul i 32 32 713 bend 714 end 715 for i ulong get BV 2 716 w = write 1 mn 0 len mn 717 bhex 5 add mul i 1024 16 160 718 bspace 719 bdecimal get BS i 720 bspace 721 bhex 6 mul i 32 32 722 bend 723 end 724 end 725 fn main to int 726 bcheck ge argcnt 3 2 727 bpaths 728 bload 729 t = bcommand 730 if eq t 9 731 bcheck eq argcnt 3 2 732 bshow 733 ret 0 734 end 735 bargs t 736 bset 8 add div get BV 0 1024 1 737 bshape 738 bapply 739 if eq get BV 3 1 740 w = write 1 dup 0 len dup 741 bhex 1 144 32 742 bend 743 ret 0 744 end 745 bhash 0 746 bcommit 747 w = write 1 ok 0 len ok 748 if eq t 3 749 bhex 1 144 32 750 else 751 bhex 1 16 32 752 end 753 bend 754 ret 0 755 end