interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / store / repos.om
| 1 | note store/repos.om: the native-store source of the store-reading build. run.sh composes it in place |
| 2 | note of server/repos.om when FORGE_STORE is set, after .build/store.om (tfsroot, the store root with a |
| 3 | note final "/", and FSCB / tfcbase, the HTTPS clone base). It defines the words server/repos.om |
| 4 | note defines (fload, fsrcchg, fkgit, fkgiti, fputid, fhasal, fradsrc, fpjterms, fjclone, tfsf4) from |
| 5 | note the store that interplane-native CONTRACT.md v0 describes: |
| 6 | note ROOT/catalog.tsv name TAB id TAB default-branch TAB head TAB visibility LF |
| 7 | note ROOT/projects/NAME/repo.git the project's bare Git repository |
| 8 | note ROOT/projects/NAME/records/1 record 1: name, branch, visibility, owner key, alias, nonce |
| 9 | note The project list is the catalog and nothing else: no folder is scanned, and RIDS.md and |
| 10 | note ~/.radicle are never read on this path. Fail closed: a catalog that cannot be read or is a link, |
| 11 | note is longer than fxo, has a line without exactly five tab-separated fields or without its final |
| 12 | note line feed, holds a control byte, a name, id, branch, head or visibility outside the rules of |
| 13 | note om/landrec.om in interplane-native, two names that differ only in case or two equal ids: then |
| 14 | note fan is 0 (every repository URL is 404) and one "forged: catalog refused" line on stderr gives |
| 15 | note the reason and the line. Private lines are skipped. Every public line is served (Drake's |
| 16 | note decision: the store build serves the whole public catalog, minus the deny list), except one the |
| 17 | note allow-list table cannot hold (FAMAX rows, server/util.om; store/tests/capacity.sh alarms long |
| 18 | note before), left out with one line each. A public line is served only when (xsok): |
| 19 | note ROOT/projects, the project folder, its repo.git and records are folders, not links (lstat); |
| 20 | note records/1 (opened without following a link) hashes to the line's id with SHA-256, and is the |
| 21 | note PROJECT record of the same name, branch and visibility public; |
| 22 | note the deny list (server/repos.om fdeny) names neither the name nor the old Radicle id; |
| 23 | note no project already served has the same old Radicle id; |
| 24 | note refs/heads/<branch> in repo.git is exactly the line's head (or is absent when the head is none); |
| 25 | note the name fits the table (100 bytes, fnmput) and the branch too (60 bytes, fbrput). |
| 26 | note Otherwise that project alone is left out with one "forged: project NAME left out" line on stderr. |
| 27 | note The key of a project (faid: social targets, counts, receipts, the archive cache folder, /rad: |
| 28 | note links) is its old Radicle id from record 1 (alias) without "rad:", or its 64-hex id when it has |
| 29 | note none. New identifiers in pages and machine forms are git:<id> (fputid). |
| 30 | global xsgid uchar 16384 |
| 31 | global xshead uchar 10240 |
| 32 | global xshn ulong 256 |
| 33 | global xsown uchar 16384 |
| 34 | global xsownl ulong 256 |
| 35 | global xsal ulong 256 |
| 36 | global xskeep ulong 256 |
| 37 | global xsck ulong 4 |
| 38 | global xsmsg uchar 8192 |
| 39 | global xsml ulong 1 |
| 40 | text tfsprjd "projects" |
| 41 | text tfsrec "/records" |
| 42 | text tfsrec1 "/records/1" |
| 43 | text tfscat "catalog.tsv" |
| 44 | text tfsgitp "git:" |
| 45 | text tfradp "rad:" |
| 46 | text tfsnone "none" |
| 47 | text tfspub "public" |
| 48 | text tfspriv "private" |
| 49 | text tfsrevp "rev-parse" |
| 50 | text tfsq "-q" |
| 51 | text tfsvfy "--verify" |
| 52 | text tfscmt "^{commit}" |
| 53 | text tfsr1a "interplane-project 1\nproject " |
| 54 | text tfsr1b "branch " |
| 55 | text tfsr1c "visibility public\nowner " |
| 56 | text tfsr1d "alias " |
| 57 | text tfsr1e "nonce " |
| 58 | text tfsfp "SHA256:" |
| 59 | text tfsm1 "forged: catalog refused (" |
| 60 | text tfsm2 " at line " |
| 61 | text tfsm3 "); no repositories are served\n" |
| 62 | text tfsm4 "forged: project " |
| 63 | text tfsm5 " left out (" |
| 64 | text tfsm6 ")\n" |
| 65 | text tfsrd "cannot be read or is a link" |
| 66 | text tfsbig "longer than the read buffer" |
| 67 | text tfsnolf "no final line feed" |
| 68 | text tfsctl "control byte" |
| 69 | text tfsnf "not five tab-separated fields" |
| 70 | text tfsbn "name outside the name rule" |
| 71 | text tfsbi "id is not 64 lowercase hex digits" |
| 72 | text tfsbb "branch outside the branch rule" |
| 73 | text tfsbh "head is not 40 lowercase hex digits or none" |
| 74 | text tfsbv "visibility is not public or private" |
| 75 | text tfsdn "two names that differ only in case" |
| 76 | text tfsdn2 "two equal names" |
| 77 | text tfsdi "two equal ids" |
| 78 | text tfsful "the allow-list table is full (FAMAX rows, server/util.om)" |
| 79 | text tfsplk "ROOT/projects is a link or not a folder" |
| 80 | text tfslnm "name longer than 100 bytes (server/repos.om fnmput)" |
| 81 | text tfslbr "branch longer than 60 bytes (server/repos.om fbrput)" |
| 82 | text tfslpf "project folder is a link or not a folder" |
| 83 | text tfslrg "repo.git is a link or not a folder" |
| 84 | text tfslrc "records is a link or not a folder" |
| 85 | text tfslr1 "records/1 cannot be read or is a link" |
| 86 | text tfslhs "records/1 does not hash to the catalog id" |
| 87 | text tfslpr "records/1 is not the PROJECT record of this name, branch and visibility public" |
| 88 | text tfsldn "on the deny list" |
| 89 | text tfsldl "old Radicle id already used by a project listed before it" |
| 90 | text tfslhd "refs/heads/<branch> in repo.git is not the catalog head" |
| 91 | text tfslpl "path longer than the system allows" |
| 92 | note ---- stderr lines |
| 93 | fn xsmb to void |
| 94 | put xsml 0 0 |
| 95 | end |
| 96 | fn xsmc c uchar to void |
| 97 | n = get xsml 0 |
| 98 | if lt n len xsmsg |
| 99 | put xsmsg n c |
| 100 | put xsml 0 add n 1 |
| 101 | end |
| 102 | end |
| 103 | fn xsmt t view uchar * to void |
| 104 | for i ulong len t bound 8192 |
| 105 | xsmc get t i |
| 106 | end |
| 107 | end |
| 108 | fn xsmn v ulong to void |
| 109 | d = new uchar 20 0 |
| 110 | i = ulong 20 |
| 111 | x = v |
| 112 | for it ulong 20 |
| 113 | i = sub i 1 |
| 114 | put d i uchar add rem x 10 48 |
| 115 | x = div x 10 |
| 116 | if eq x 0 |
| 117 | break |
| 118 | end |
| 119 | end |
| 120 | for k ulong sub 20 i bound 20 |
| 121 | xsmc get d add i k |
| 122 | end |
| 123 | end |
| 124 | fn xsmw to void |
| 125 | w = write 2 xsmsg 0 get xsml 0 |
| 126 | end |
| 127 | note xsrefuse: the whole catalog is refused (line 0: no line) |
| 128 | fn xsrefuse t view uchar * ln ulong to long |
| 129 | put fan 0 0 |
| 130 | xsmb |
| 131 | xsmt tfsm1 |
| 132 | xsmt t |
| 133 | if gt ln 0 |
| 134 | xsmt tfsm2 |
| 135 | xsmn ln |
| 136 | end |
| 137 | xsmt tfsm3 |
| 138 | xsmw |
| 139 | ret -1 |
| 140 | end |
| 141 | note xsleave: project k is left out |
| 142 | fn xsleave k ulong t view uchar * to void |
| 143 | put xskeep k 0 |
| 144 | xsmb |
| 145 | xsmt tfsm4 |
| 146 | for i ulong get fanl k bound 128 |
| 147 | xsmc frnbyte k i |
| 148 | end |
| 149 | xsmt tfsm5 |
| 150 | xsmt t |
| 151 | xsmt tfsm6 |
| 152 | xsmw |
| 153 | end |
| 154 | note ---- byte rules (om/landrec.om of interplane-native: isname, isref, hex) |
| 155 | fn xsaln c uchar to bool |
| 156 | ret fisaln c |
| 157 | end |
| 158 | fn xsnamec c uchar to bool |
| 159 | ret or xsaln c or eq c 46 or eq c 95 eq c 45 |
| 160 | end |
| 161 | fn xshexc c uchar to bool |
| 162 | ret or fisdig c and ge c 97 le c 102 |
| 163 | end |
| 164 | fn xsisname a ulong b ulong to bool |
| 165 | if ge a b |
| 166 | ret false |
| 167 | end |
| 168 | if not xsaln get fxo a |
| 169 | ret false |
| 170 | end |
| 171 | if eq get fxo sub b 1 46 |
| 172 | ret false |
| 173 | end |
| 174 | j = a |
| 175 | while lt j b bound 16777216 |
| 176 | if not xsnamec get fxo j |
| 177 | ret false |
| 178 | end |
| 179 | j = add j 1 |
| 180 | end |
| 181 | ret true |
| 182 | end |
| 183 | fn xsishex a ulong b ulong n ulong to bool |
| 184 | if ne sub b a n |
| 185 | ret false |
| 186 | end |
| 187 | j = a |
| 188 | while lt j b bound 16777216 |
| 189 | if not xshexc get fxo j |
| 190 | ret false |
| 191 | end |
| 192 | j = add j 1 |
| 193 | end |
| 194 | ret true |
| 195 | end |
| 196 | fn xsrefc c uchar to bool |
| 197 | ret or xsnamec c eq c 47 |
| 198 | end |
| 199 | note xslock: fxo[e-5, e) is ".lock" and starts at or after a |
| 200 | fn xslock a ulong e ulong to bool |
| 201 | if lt sub e a 5 |
| 202 | ret false |
| 203 | end |
| 204 | s = sub e 5 |
| 205 | if ne get fxo s 46 |
| 206 | ret false |
| 207 | end |
| 208 | if ne get fxo add s 1 108 |
| 209 | ret false |
| 210 | end |
| 211 | if ne get fxo add s 2 111 |
| 212 | ret false |
| 213 | end |
| 214 | if ne get fxo add s 3 99 |
| 215 | ret false |
| 216 | end |
| 217 | ret eq get fxo add s 4 107 |
| 218 | end |
| 219 | fn xsisref a ulong b ulong to bool |
| 220 | if ge a b |
| 221 | ret false |
| 222 | end |
| 223 | f = get fxo a |
| 224 | if or eq f 45 or eq f 46 eq f 47 |
| 225 | ret false |
| 226 | end |
| 227 | l = get fxo sub b 1 |
| 228 | if or eq l 46 eq l 47 |
| 229 | ret false |
| 230 | end |
| 231 | p = uchar 0 |
| 232 | j = a |
| 233 | while lt j b bound 16777216 |
| 234 | c = get fxo j |
| 235 | if not xsrefc c |
| 236 | ret false |
| 237 | end |
| 238 | if and eq c 46 or eq p 46 eq p 47 |
| 239 | ret false |
| 240 | end |
| 241 | if and eq c 47 eq p 47 |
| 242 | ret false |
| 243 | end |
| 244 | if eq c 47 |
| 245 | if xslock a j |
| 246 | ret false |
| 247 | end |
| 248 | end |
| 249 | p = c |
| 250 | j = add j 1 |
| 251 | end |
| 252 | ret not xslock a b |
| 253 | end |
| 254 | fn xstxeq a ulong b ulong t view uchar * to bool |
| 255 | if ne sub b a len t |
| 256 | ret false |
| 257 | end |
| 258 | for k ulong len t bound 64 |
| 259 | if ne get fxo add a k get t k |
| 260 | ret false |
| 261 | end |
| 262 | end |
| 263 | ret true |
| 264 | end |
| 265 | note ---- catalog lines: fxo[p, e) is one line without its line feed |
| 266 | fn xstab p ulong e ulong k ulong to ulong |
| 267 | note start of field k (0..4); fields are known to exist |
| 268 | j = p |
| 269 | n = ulong 0 |
| 270 | while lt j e bound 16777216 |
| 271 | if eq n k |
| 272 | ret j |
| 273 | end |
| 274 | if eq get fxo j 9 |
| 275 | n = add n 1 |
| 276 | end |
| 277 | j = add j 1 |
| 278 | end |
| 279 | ret e |
| 280 | end |
| 281 | fn xsfend s ulong e ulong to ulong |
| 282 | j = s |
| 283 | while lt j e bound 16777216 |
| 284 | if eq get fxo j 9 |
| 285 | ret j |
| 286 | end |
| 287 | j = add j 1 |
| 288 | end |
| 289 | ret e |
| 290 | end |
| 291 | note xsline: the reason line p..e breaks a rule, or 0 when it is well formed |
| 292 | fn xsline p ulong e ulong to ulong |
| 293 | t = ulong 0 |
| 294 | j = p |
| 295 | while lt j e bound 16777216 |
| 296 | c = get fxo j |
| 297 | if eq c 9 |
| 298 | t = add t 1 |
| 299 | else |
| 300 | if or lt c 32 eq c 127 |
| 301 | ret 1 |
| 302 | end |
| 303 | end |
| 304 | j = add j 1 |
| 305 | end |
| 306 | if ne t 4 |
| 307 | ret 2 |
| 308 | end |
| 309 | ret xsfields p e |
| 310 | end |
| 311 | note xsfields: the five fields of a line with four tabs and no control byte |
| 312 | fn xsfields p ulong e ulong to ulong |
| 313 | s = p |
| 314 | f = xsfend s e |
| 315 | if not xsisname s f |
| 316 | ret 3 |
| 317 | end |
| 318 | s = add f 1 |
| 319 | f = xsfend s e |
| 320 | if not xsishex s f 64 |
| 321 | ret 4 |
| 322 | end |
| 323 | s = add f 1 |
| 324 | f = xsfend s e |
| 325 | if not xsisref s f |
| 326 | ret 5 |
| 327 | end |
| 328 | s = add f 1 |
| 329 | f = xsfend s e |
| 330 | if not xshdok s f |
| 331 | ret 6 |
| 332 | end |
| 333 | s = add f 1 |
| 334 | if not xsvisok s e |
| 335 | ret 7 |
| 336 | end |
| 337 | ret 0 |
| 338 | end |
| 339 | fn xshdok s ulong f ulong to bool |
| 340 | if xsishex s f 40 |
| 341 | ret true |
| 342 | end |
| 343 | ret xstxeq s f tfsnone |
| 344 | end |
| 345 | fn xsvisok s ulong e ulong to bool |
| 346 | if xstxeq s e tfspub |
| 347 | ret true |
| 348 | end |
| 349 | ret xstxeq s e tfspriv |
| 350 | end |
| 351 | fn xsreason r ulong ln ulong to long |
| 352 | if eq r 1 |
| 353 | ret xsrefuse tfsctl ln |
| 354 | end |
| 355 | if eq r 2 |
| 356 | ret xsrefuse tfsnf ln |
| 357 | end |
| 358 | if eq r 3 |
| 359 | ret xsrefuse tfsbn ln |
| 360 | end |
| 361 | if eq r 4 |
| 362 | ret xsrefuse tfsbi ln |
| 363 | end |
| 364 | if eq r 5 |
| 365 | ret xsrefuse tfsbb ln |
| 366 | end |
| 367 | if eq r 6 |
| 368 | ret xsrefuse tfsbh ln |
| 369 | end |
| 370 | if eq r 7 |
| 371 | ret xsrefuse tfsbv ln |
| 372 | end |
| 373 | if eq r 8 |
| 374 | ret xsrefuse tfsdn ln |
| 375 | end |
| 376 | if eq r 10 |
| 377 | ret xsrefuse tfsdn2 ln |
| 378 | end |
| 379 | ret xsrefuse tfsdi ln |
| 380 | end |
| 381 | fn xsfold c uchar to uchar |
| 382 | if and ge c 65 le c 90 |
| 383 | ret add c 32 |
| 384 | end |
| 385 | ret c |
| 386 | end |
| 387 | note xsdupat: line [p, e) repeats the name (10 the same bytes, 8 apart from case) or the id (9) of |
| 388 | note line [q, f); 0 if neither |
| 389 | fn xsdupat p ulong e ulong q ulong f ulong to ulong |
| 390 | b = xsfend p e |
| 391 | d = xsfend q f |
| 392 | if xsfoldeq p b q d |
| 393 | if xsexeq p b q |
| 394 | ret 10 |
| 395 | end |
| 396 | ret 8 |
| 397 | end |
| 398 | if xsideq add b 1 add d 1 |
| 399 | ret 9 |
| 400 | end |
| 401 | ret 0 |
| 402 | end |
| 403 | note xsexeq: fxo[a, b) equals the same number of bytes at c |
| 404 | fn xsexeq a ulong b ulong c ulong to bool |
| 405 | for k ulong sub b a bound 16777216 |
| 406 | if ne get fxo add a k get fxo add c k |
| 407 | ret false |
| 408 | end |
| 409 | end |
| 410 | ret true |
| 411 | end |
| 412 | note xsfoldeq: fxo[a, b) and fxo[c, d) are equal apart from the case of A-Z |
| 413 | fn xsfoldeq a ulong b ulong c ulong d ulong to bool |
| 414 | if ne sub b a sub d c |
| 415 | ret false |
| 416 | end |
| 417 | for k ulong sub b a bound 16777216 |
| 418 | x = xsfold get fxo add a k |
| 419 | y = xsfold get fxo add c k |
| 420 | if ne x y |
| 421 | ret false |
| 422 | end |
| 423 | end |
| 424 | ret true |
| 425 | end |
| 426 | fn xsideq a ulong c ulong to bool |
| 427 | for k ulong 64 |
| 428 | if ne get fxo add a k get fxo add c k |
| 429 | ret false |
| 430 | end |
| 431 | end |
| 432 | ret true |
| 433 | end |
| 434 | note xsdup: line [p, e) repeats a line before it (8 or 9), or 0 |
| 435 | fn xsdup p ulong e ulong to ulong |
| 436 | q = ulong 0 |
| 437 | while lt q p bound 16777216 |
| 438 | f = fleol q p |
| 439 | r = xsdupat p e q f |
| 440 | if ne r 0 |
| 441 | ret r |
| 442 | end |
| 443 | q = add f 1 |
| 444 | end |
| 445 | ret 0 |
| 446 | end |
| 447 | fn xsispub p ulong e ulong to bool |
| 448 | s4 = xstab p e 4 |
| 449 | ret xstxeq s4 e tfspub |
| 450 | end |
| 451 | note ---- paths |
| 452 | fn xspfold to void |
| 453 | fpb |
| 454 | fpt tfsroot |
| 455 | fpt tfsprj |
| 456 | end |
| 457 | note xspdir: ROOT/projects without the final "/", so that lstat sees a link as a link |
| 458 | fn xspdir to void |
| 459 | fpb |
| 460 | fpt tfsroot |
| 461 | fpt tfsprjd |
| 462 | end |
| 463 | fn xspproj k ulong to void |
| 464 | xspfold |
| 465 | for i ulong get fanl k bound 128 |
| 466 | fpc frnbyte k i |
| 467 | end |
| 468 | end |
| 469 | fn xspfull to bool |
| 470 | ret ge get fpthl 0 4095 |
| 471 | end |
| 472 | note xsisdir: lstat of fpth is a folder (a link is not) |
| 473 | fn xsisdir to bool |
| 474 | if xspfull |
| 475 | ret false |
| 476 | end |
| 477 | r = lstat fpth 0 get fpthl 0 fstb 0 128 |
| 478 | if lt r 0 |
| 479 | ret false |
| 480 | end |
| 481 | m = or ulong get fstb 16 shl ulong get fstb 17 8 |
| 482 | ret eq and m 61440 16384 |
| 483 | end |
| 484 | note xsrdnf: read the file at fpth into fxo without following a link (O_NOFOLLOW | O_CLOEXEC); |
| 485 | note the length, or -1 when it cannot be opened or is longer than fxo |
| 486 | fn xsrdnf to long |
| 487 | b = new uchar 1 0 |
| 488 | put fxol 0 0 |
| 489 | put fxotr 0 0 |
| 490 | if xspfull |
| 491 | ret -1 |
| 492 | end |
| 493 | fd = fopen fpth 0 get fpthl 0 557056 0 |
| 494 | if lt fd 0 |
| 495 | ret -1 |
| 496 | end |
| 497 | ok = true |
| 498 | for it ulong 16777217 |
| 499 | n = get fxol 0 |
| 500 | if ge n len fxo |
| 501 | q = read int fd b 0 1 |
| 502 | if ne q 0 |
| 503 | put fxotr 0 1 |
| 504 | ok = false |
| 505 | end |
| 506 | break |
| 507 | end |
| 508 | r = read int fd fxo n sub len fxo n |
| 509 | if lt r 0 |
| 510 | ok = false |
| 511 | break |
| 512 | end |
| 513 | if eq r 0 |
| 514 | break |
| 515 | end |
| 516 | put fxol 0 add n ulong r |
| 517 | end |
| 518 | x = fclose int fd |
| 519 | if not ok |
| 520 | ret -1 |
| 521 | end |
| 522 | ret long get fxol 0 |
| 523 | end |
| 524 | note xsstat: the change key of the catalog (inode, size, mtime s, mtime ns), all 0 when missing |
| 525 | fn xsstat k edit ulong 4 to void |
| 526 | fpb |
| 527 | fpt tfsroot |
| 528 | fpt tfscat |
| 529 | for i ulong 4 |
| 530 | put k i 0 |
| 531 | end |
| 532 | r = stat fpth 0 get fpthl 0 fstb 0 128 |
| 533 | if lt r 0 |
| 534 | ret |
| 535 | end |
| 536 | put k 0 xsle8 8 |
| 537 | put k 1 xsle8 48 |
| 538 | put k 2 xsle8 88 |
| 539 | put k 3 xsle8 96 |
| 540 | end |
| 541 | fn xsle8 o ulong to ulong |
| 542 | v = ulong 0 |
| 543 | for i ulong 8 |
| 544 | v = or v shl ulong get fstb add o i mul i 8 |
| 545 | end |
| 546 | ret v |
| 547 | end |
| 548 | fn fsrcchg to bool |
| 549 | k = new ulong 4 0 |
| 550 | xsstat k |
| 551 | for i ulong 4 |
| 552 | if ne get k i get xsck i |
| 553 | ret true |
| 554 | end |
| 555 | end |
| 556 | ret false |
| 557 | end |
| 558 | note ---- the catalog |
| 559 | fn fload to long |
| 560 | put fan 0 0 |
| 561 | put fsrcst 0 1 |
| 562 | fd = fopen tfpubgit 0 len tfpubgit 0 0 |
| 563 | put fpubgit 0 0 |
| 564 | if ge fd 0 |
| 565 | put fpubgit 0 1 |
| 566 | x = fclose int fd |
| 567 | end |
| 568 | put fsrtl 0 0 |
| 569 | for i ulong len tfsroot bound 4096 |
| 570 | put fsrt i get tfsroot i |
| 571 | put fsrtl 0 add i 1 |
| 572 | end |
| 573 | k = new ulong 4 0 |
| 574 | xsstat k |
| 575 | for i ulong 4 |
| 576 | put xsck i get k i |
| 577 | end |
| 578 | xspdir |
| 579 | if not xsisdir |
| 580 | ret xsrefuse tfsplk 0 |
| 581 | end |
| 582 | n = xscatrd |
| 583 | if lt n 0 |
| 584 | if ne get fxotr 0 0 |
| 585 | ret xsrefuse tfsbig 0 |
| 586 | end |
| 587 | ret xsrefuse tfsrd 0 |
| 588 | end |
| 589 | ln = ulong n |
| 590 | if and gt ln 0 ne get fxo sub ln 1 10 |
| 591 | ret xsrefuse tfsnolf 0 |
| 592 | end |
| 593 | p = ulong 0 |
| 594 | li = ulong 0 |
| 595 | while lt p ln bound 16777216 |
| 596 | e = fleol p ln |
| 597 | li = add li 1 |
| 598 | r = xsline p e |
| 599 | if ne r 0 |
| 600 | ret xsreason r li |
| 601 | end |
| 602 | r = xsdup p e |
| 603 | if ne r 0 |
| 604 | ret xsreason r li |
| 605 | end |
| 606 | p = add e 1 |
| 607 | end |
| 608 | m = xsfill ln |
| 609 | put fan 0 m |
| 610 | for i ulong m bound FAMAX |
| 611 | xscheck i |
| 612 | end |
| 613 | w = ulong 0 |
| 614 | for i ulong m bound FAMAX |
| 615 | if eq get xskeep i 1 |
| 616 | xsmove w i |
| 617 | w = add w 1 |
| 618 | end |
| 619 | end |
| 620 | put fan 0 w |
| 621 | for i ulong w bound FAMAX |
| 622 | fmeta i |
| 623 | end |
| 624 | ret long w |
| 625 | end |
| 626 | note xscatrd: ROOT/catalog.tsv into fxo, opened without following a link. The project list is this |
| 627 | note file and nothing else (store/tests/compare.sh mutant "scan" replaces this word with a reader |
| 628 | note of the project folders and must be caught). |
| 629 | fn xscatrd to long |
| 630 | fpb |
| 631 | fpt tfsroot |
| 632 | fpt tfscat |
| 633 | ret xsrdnf |
| 634 | end |
| 635 | note xsfill: every public line of the catalog in fxo[0, ln) into the table, in catalog order; the |
| 636 | note number of rows. A name or branch the table cannot hold, or a line past FAMAX rows, leaves that |
| 637 | note project out here. |
| 638 | fn xsfill ln ulong to ulong |
| 639 | k = ulong 0 |
| 640 | p = ulong 0 |
| 641 | while lt p ln bound 16777216 |
| 642 | e = fleol p ln |
| 643 | if xsispub p e |
| 644 | e0 = xsfend p e |
| 645 | if ge k FAMAX |
| 646 | xsleavr p e0 tfsful |
| 647 | else |
| 648 | if xsrow k p e |
| 649 | k = add k 1 |
| 650 | end |
| 651 | end |
| 652 | end |
| 653 | p = add e 1 |
| 654 | end |
| 655 | ret k |
| 656 | end |
| 657 | fn xsrow k ulong p ulong e ulong to bool |
| 658 | e0 = xsfend p e |
| 659 | if not fnmput k p e0 |
| 660 | xsleavr p e0 tfslnm |
| 661 | ret false |
| 662 | end |
| 663 | s = xstab p e 2 |
| 664 | if not fbrput k s xsfend s e |
| 665 | xsleavr p e0 tfslbr |
| 666 | ret false |
| 667 | end |
| 668 | xsrowid k xstab p e 1 |
| 669 | xsrowhd k xstab p e 3 e |
| 670 | put faio k mul k 64 |
| 671 | put fail k 0 |
| 672 | put xsal k 0 |
| 673 | put xsownl k 0 |
| 674 | put xskeep k 1 |
| 675 | ret true |
| 676 | end |
| 677 | fn xsrowid k ulong s ulong to void |
| 678 | g = mul k 64 |
| 679 | for j ulong 64 |
| 680 | put xsgid add g j get fxo add s j |
| 681 | end |
| 682 | end |
| 683 | fn xsrowhd k ulong s ulong e ulong to void |
| 684 | if xstxeq s xsfend s e tfsnone |
| 685 | put xshn k 0 |
| 686 | ret |
| 687 | end |
| 688 | put xshn k 1 |
| 689 | g = mul k 40 |
| 690 | for j ulong 40 |
| 691 | put xshead add g j get fxo add s j |
| 692 | end |
| 693 | end |
| 694 | note xsleavr: a project left out while its name is still in fxo[a, b) |
| 695 | fn xsleavr a ulong b ulong t view uchar * to void |
| 696 | xsmb |
| 697 | xsmt tfsm4 |
| 698 | for j ulong sub b a bound 16777216 |
| 699 | xsmc get fxo add a j |
| 700 | end |
| 701 | xsmt tfsm5 |
| 702 | xsmt t |
| 703 | xsmt tfsm6 |
| 704 | xsmw |
| 705 | end |
| 706 | note ---- one project (xscheck sets xskeep k to 1 when it is served) |
| 707 | fn xscheck k ulong to void |
| 708 | put xskeep k 0 |
| 709 | if not xsfolders k |
| 710 | ret |
| 711 | end |
| 712 | if not xsrec1 k |
| 713 | ret |
| 714 | end |
| 715 | if fdeny k |
| 716 | xsleave k tfsldn |
| 717 | ret |
| 718 | end |
| 719 | if xsaldup k |
| 720 | xsleave k tfsldl |
| 721 | ret |
| 722 | end |
| 723 | if not xsheadok k |
| 724 | xsleave k tfslhd |
| 725 | ret |
| 726 | end |
| 727 | put xskeep k 1 |
| 728 | end |
| 729 | fn xsfolders k ulong to bool |
| 730 | xspproj k |
| 731 | if xspfull |
| 732 | xsleave k tfslpl |
| 733 | ret false |
| 734 | end |
| 735 | if not xsisdir |
| 736 | xsleave k tfslpf |
| 737 | ret false |
| 738 | end |
| 739 | xspproj k |
| 740 | fpt tfsrg |
| 741 | if not xsisdir |
| 742 | xsleave k tfslrg |
| 743 | ret false |
| 744 | end |
| 745 | xspproj k |
| 746 | fpt tfsrec |
| 747 | if not xsisdir |
| 748 | xsleave k tfslrc |
| 749 | ret false |
| 750 | end |
| 751 | ret true |
| 752 | end |
| 753 | note xsrec1: records/1 of project k hashes to its id and is its PROJECT record; sets the key, the |
| 754 | note owner and xsal |
| 755 | fn xsrec1 k ulong to bool |
| 756 | xspproj k |
| 757 | fpt tfsrec1 |
| 758 | n = xsrdnf |
| 759 | if lt n 0 |
| 760 | xsleave k tfslr1 |
| 761 | ret false |
| 762 | end |
| 763 | if not xshashok k ulong n |
| 764 | xsleave k tfslhs |
| 765 | ret false |
| 766 | end |
| 767 | if not xsparse k ulong n |
| 768 | xsleave k tfslpr |
| 769 | ret false |
| 770 | end |
| 771 | ret true |
| 772 | end |
| 773 | fn xshashok k ulong n ulong to bool |
| 774 | c = new ulong 40 0 |
| 775 | b = new uchar 4096 0 |
| 776 | h = new uchar 32 0 |
| 777 | sha256_init c |
| 778 | o = ulong 0 |
| 779 | while lt o n bound 16777216 |
| 780 | m = hmin sub n o 4096 |
| 781 | for j ulong m bound 4096 |
| 782 | put b j get fxo add o j |
| 783 | end |
| 784 | sha256_update c part b 0 m |
| 785 | o = add o m |
| 786 | end |
| 787 | sha256_final c h |
| 788 | ret xsdgeq k h |
| 789 | end |
| 790 | note xsdgeq: the 64-hex id of row k spells the digest h |
| 791 | fn xsdgeq k ulong h view uchar 32 to bool |
| 792 | g = mul k 64 |
| 793 | for j ulong 32 |
| 794 | v = get h j |
| 795 | a = add g mul j 2 |
| 796 | if ne get xsgid a xshexd shr v 4 |
| 797 | ret false |
| 798 | end |
| 799 | if ne get xsgid add a 1 xshexd and v 15 |
| 800 | ret false |
| 801 | end |
| 802 | end |
| 803 | ret true |
| 804 | end |
| 805 | fn xshexd v uchar to uchar |
| 806 | if lt v 10 |
| 807 | ret add v 48 |
| 808 | end |
| 809 | ret add v 87 |
| 810 | end |
| 811 | note xsat: fxo[p, ...) starts with text t (within n) |
| 812 | fn xsat p ulong n ulong t view uchar * to bool |
| 813 | if gt add p len t n |
| 814 | ret false |
| 815 | end |
| 816 | for j ulong len t bound 64 |
| 817 | if ne get fxo add p j get t j |
| 818 | ret false |
| 819 | end |
| 820 | end |
| 821 | ret true |
| 822 | end |
| 823 | note xsparse: fxo[0, n) is exactly "interplane-project 1\nproject NAME\nbranch BRANCH\nvisibility |
| 824 | note public\nowner SHA256:<43 base64>\nalias <rad:z... or ->\nnonce <32 hex>\n" for project k |
| 825 | fn xsparse k ulong n ulong to bool |
| 826 | if not xsat 0 n tfsr1a |
| 827 | ret false |
| 828 | end |
| 829 | p = len tfsr1a |
| 830 | e = fleol p n |
| 831 | if not xsnmeq k p e |
| 832 | ret false |
| 833 | end |
| 834 | p = add e 1 |
| 835 | if not xsat p n tfsr1b |
| 836 | ret false |
| 837 | end |
| 838 | p = add p len tfsr1b |
| 839 | e = fleol p n |
| 840 | if not xsbreq k p e |
| 841 | ret false |
| 842 | end |
| 843 | p = add e 1 |
| 844 | if not xsat p n tfsr1c |
| 845 | ret false |
| 846 | end |
| 847 | p = add p len tfsr1c |
| 848 | e = fleol p n |
| 849 | if not xsowner k p e |
| 850 | ret false |
| 851 | end |
| 852 | p = add e 1 |
| 853 | if not xsat p n tfsr1d |
| 854 | ret false |
| 855 | end |
| 856 | p = add p len tfsr1d |
| 857 | e = fleol p n |
| 858 | if not xsalias k p e |
| 859 | ret false |
| 860 | end |
| 861 | p = add e 1 |
| 862 | if not xsat p n tfsr1e |
| 863 | ret false |
| 864 | end |
| 865 | p = add p len tfsr1e |
| 866 | e = fleol p n |
| 867 | if not xsishex p e 32 |
| 868 | ret false |
| 869 | end |
| 870 | ret eq add e 1 n |
| 871 | end |
| 872 | fn xsnmeq k ulong a ulong b ulong to bool |
| 873 | if ne sub b a get fanl k |
| 874 | ret false |
| 875 | end |
| 876 | for j ulong sub b a bound 128 |
| 877 | if ne get fxo add a j frnbyte k j |
| 878 | ret false |
| 879 | end |
| 880 | end |
| 881 | ret true |
| 882 | end |
| 883 | fn xsbreq k ulong a ulong b ulong to bool |
| 884 | if ne sub b a get fabl k |
| 885 | ret false |
| 886 | end |
| 887 | o = get fabo k |
| 888 | for j ulong sub b a bound 64 |
| 889 | if ne get fxo add a j get fabr add o j |
| 890 | ret false |
| 891 | end |
| 892 | end |
| 893 | ret true |
| 894 | end |
| 895 | fn xsb64c c uchar to bool |
| 896 | ret or xsaln c or eq c 43 eq c 47 |
| 897 | end |
| 898 | fn xsowner k ulong a ulong b ulong to bool |
| 899 | if ne sub b a 50 |
| 900 | ret false |
| 901 | end |
| 902 | if not xsat a b tfsfp |
| 903 | ret false |
| 904 | end |
| 905 | for j ulong 43 |
| 906 | if not xsb64c get fxo add add a 7 j |
| 907 | ret false |
| 908 | end |
| 909 | end |
| 910 | for j ulong 50 |
| 911 | put xsown add mul k 64 j get fxo add a j |
| 912 | end |
| 913 | put xsownl k 50 |
| 914 | ret true |
| 915 | end |
| 916 | note xsalias: "-" (no old id: the key is the 64-hex id) or "rad:z" and 20..60 letters and digits in |
| 917 | note all after "rad:" (the key is that RID) |
| 918 | fn xsalias k ulong a ulong b ulong to bool |
| 919 | g = mul k 64 |
| 920 | if and eq sub b a 1 eq get fxo a 45 |
| 921 | for j ulong 64 |
| 922 | put faid add g j get xsgid add g j |
| 923 | end |
| 924 | put fail k 64 |
| 925 | put xsal k 0 |
| 926 | ret true |
| 927 | end |
| 928 | if lt sub b a 5 |
| 929 | ret false |
| 930 | end |
| 931 | if not xsat a b tfradp |
| 932 | ret false |
| 933 | end |
| 934 | s = add a 4 |
| 935 | l = sub b s |
| 936 | if or lt l 21 gt l 61 |
| 937 | ret false |
| 938 | end |
| 939 | if ne get fxo s 122 |
| 940 | ret false |
| 941 | end |
| 942 | for j ulong l bound 64 |
| 943 | if not xsaln get fxo add s j |
| 944 | ret false |
| 945 | end |
| 946 | end |
| 947 | for j ulong l bound 64 |
| 948 | put faid add g j get fxo add s j |
| 949 | end |
| 950 | put fail k l |
| 951 | put xsal k 1 |
| 952 | ret true |
| 953 | end |
| 954 | note xsaldup: an earlier project still served has the same old Radicle id |
| 955 | fn xsaldup k ulong to bool |
| 956 | if eq get xsal k 0 |
| 957 | ret false |
| 958 | end |
| 959 | for j ulong k bound FAMAX |
| 960 | if and eq get xskeep j 1 eq get xsal j 1 |
| 961 | if xskeyeq j k |
| 962 | ret true |
| 963 | end |
| 964 | end |
| 965 | end |
| 966 | ret false |
| 967 | end |
| 968 | fn xskeyeq a ulong b ulong to bool |
| 969 | if ne get fail a get fail b |
| 970 | ret false |
| 971 | end |
| 972 | for j ulong get fail a bound 64 |
| 973 | if ne fridbyte a j fridbyte b j |
| 974 | ret false |
| 975 | end |
| 976 | end |
| 977 | ret true |
| 978 | end |
| 979 | note xsheadok: refs/heads/<branch> of repo.git is the catalog head, or is absent when the head is none |
| 980 | fn xsheadok k ulong to bool |
| 981 | fkgiti k |
| 982 | fka tfsrevp |
| 983 | fka tfsq |
| 984 | fka tfsvfy |
| 985 | fkopen |
| 986 | fkt tfrh |
| 987 | o = get fabo k |
| 988 | for j ulong get fabl k bound 64 |
| 989 | fkc get fabr add o j |
| 990 | end |
| 991 | fkt tfscmt |
| 992 | st = fexec 5000000000 |
| 993 | if eq get xshn k 0 |
| 994 | ret ne st 0 |
| 995 | end |
| 996 | if ne st 0 |
| 997 | ret false |
| 998 | end |
| 999 | if ne get fxol 0 41 |
| 1000 | ret false |
| 1001 | end |
| 1002 | if ne get fxo 40 10 |
| 1003 | ret false |
| 1004 | end |
| 1005 | g = mul k 40 |
| 1006 | for j ulong 40 |
| 1007 | if ne get fxo j get xshead add g j |
| 1008 | ret false |
| 1009 | end |
| 1010 | end |
| 1011 | ret true |
| 1012 | end |
| 1013 | note xsmove: row i to row w (w < i), with the store's own columns |
| 1014 | fn xsmove w ulong i ulong to void |
| 1015 | if eq w i |
| 1016 | ret |
| 1017 | end |
| 1018 | fmove w i |
| 1019 | put xshn w get xshn i |
| 1020 | put xsal w get xsal i |
| 1021 | put xsownl w get xsownl i |
| 1022 | put xskeep w get xskeep i |
| 1023 | for j ulong 64 |
| 1024 | put xsgid add mul w 64 j get xsgid add mul i 64 j |
| 1025 | put xsown add mul w 64 j get xsown add mul i 64 j |
| 1026 | end |
| 1027 | for j ulong 40 |
| 1028 | put xshead add mul w 40 j get xshead add mul i 40 j |
| 1029 | end |
| 1030 | end |
| 1031 | note ---- git on a project: server/util.om fkgit / fkgiti name <fsrt>projects/NAME/repo.git once |
| 1032 | note fsrcst is 1 (fload sets it and fsrt before it runs any git) |
| 1033 | note ---- identity in pages and machine forms |
| 1034 | fn fputid i ulong to void |
| 1035 | fput tfsgitp |
| 1036 | for k ulong 64 |
| 1037 | fputc get xsgid add mul i 64 k |
| 1038 | end |
| 1039 | end |
| 1040 | fn fhasal i ulong to bool |
| 1041 | ret eq get xsal i 1 |
| 1042 | end |
| 1043 | fn fradsrc to bool |
| 1044 | ret false |
| 1045 | end |
| 1046 | note fradwalk / fradseeds: the store has no routing table; server/counts.om fzseeds never calls them |
| 1047 | note here (fradsrc is false), they exist so that counts.om composes unchanged |
| 1048 | fn fradwalk to ulong |
| 1049 | ret 0 |
| 1050 | end |
| 1051 | fn fradseeds i ulong to long |
| 1052 | ret -1 |
| 1053 | end |
| 1054 | text tfsf4 "<p class=\"foot-fine\">INTERPLANE Forge: agents express intent; the forge retains authority. Repositories are plain Git kept in Interplane's own signed store, served by forged, a seeded-Omega web server, with no JavaScript.</p>\n<p class=\"foot-fine\"><a href=\"" |
| 1055 | note ---- the identity words of the "For developers" section (server/pages.om fpjdev1): ID, Owner, |
| 1056 | note Refs and HEAD, and Patch up to its link. The Seed word is gone: this build reads no routing table. |
| 1057 | text tsdv1 "<dt>ID</dt><dd>The project's permanent id on Interplane: the SHA-256 of its first signed record. This one is <code>git:" |
| 1058 | text tsdv2 "</code>." |
| 1059 | text tsdv3 " Its old id, kept only so that old links still work: <code>" |
| 1060 | text tsdv4 "</dd>\n<dt>Owner</dt><dd>The key that signs every record of the project. This forge lists the project under " |
| 1061 | text tsdv5 "; its key is <code>" |
| 1062 | text tsdv6 "</code>.</dd>\n<dt>Refs and HEAD</dt><dd>Refs are the names that point at versions: branches and tags. HEAD is the version a fresh copy starts from, the newest commit of the default branch.</dd>\n<dt>Patch</dt><dd>A proposed change, reviewed before it is merged. This forge does not show proposed changes from its own store yet. The list is under <a href=\"" |
| 1063 | fn fpjterms to void |
| 1064 | i = get fridx 0 |
| 1065 | if ge i get fan 0 |
| 1066 | ret |
| 1067 | end |
| 1068 | fput tsdv1 |
| 1069 | fputid4 i |
| 1070 | fput tsdv2 |
| 1071 | if fhasal i |
| 1072 | fput tsdv3 |
| 1073 | for k ulong get fail i bound 64 |
| 1074 | fescc fridbyte i k |
| 1075 | end |
| 1076 | fput tsdv2 |
| 1077 | end |
| 1078 | fput tsdv4 |
| 1079 | fputown |
| 1080 | fput tsdv5 |
| 1081 | for k ulong get xsownl i bound 64 |
| 1082 | fescc get xsown add mul i 64 k |
| 1083 | end |
| 1084 | fput tsdv6 |
| 1085 | end |
| 1086 | fn fputid4 i ulong to void |
| 1087 | for k ulong 64 |
| 1088 | fputc get xsgid add mul i 64 k |
| 1089 | end |
| 1090 | end |
| 1091 | note ---- the clone object of the JSON repo form. Its keys stay those of forge/repo/1 (docs/API.md: keys |
| 1092 | note are never removed): rad and rad_clone are null (no Radicle copy is served), git_https is the |
| 1093 | note HTTPS address when the build has a clone base (FSCB 1), else null. |
| 1094 | text tsjcl1 ",\n\"clone\":{\"rad\":null,\"rad_clone\":null,\"git_https\":" |
| 1095 | text tsjcl2 "\"" |
| 1096 | text tsjcl3 "\"}" |
| 1097 | text tsjcl4 "null}" |
| 1098 | fn fjclone i ulong to void |
| 1099 | fput tsjcl1 |
| 1100 | if eq FSCB 1 |
| 1101 | fput tsjcl2 |
| 1102 | fput tfcbase |
| 1103 | fput tfsprj |
| 1104 | for k ulong get fanl i bound 128 |
| 1105 | fputc frnbyte i k |
| 1106 | end |
| 1107 | fput tfsrg |
| 1108 | fput tsjcl3 |
| 1109 | ret |
| 1110 | end |
| 1111 | fput tsjcl4 |
| 1112 | end |