urbit/pkg/arvo/sys/vane/khan.hoon

149 lines
3.6 KiB
Plaintext
Raw Normal View History

2022-01-21 21:48:05 +03:00
:: %khan, thread runner
!:
!? 164
::
|= our=ship
=> |%
+$ move [p=duct q=(wite note gift:khan)]
+$ note :: out request $->
2022-01-26 02:37:48 +03:00
$~ [%g %deal *sock *term *deal:gall]
2022-01-22 04:46:59 +03:00
$% $: %g :: to %gall
$>(%deal task:gall) :: full transmission
== == ::
2022-01-21 21:48:05 +03:00
+$ sign :: in response $<-
$% $: %gall
$>(%unto gift:gall)
==
$: %khan
$>(%avow gift:khan)
== ==
2022-01-21 21:48:05 +03:00
+$ khan-state
$: %0
hey=duct :: current unix duct
run=(map duct thread-state) :: running threads
2022-01-21 21:48:05 +03:00
==
:: TODO move to lull
::
+$ thread-state [tid=@ta mak=mark bek=beak]
2022-01-21 21:48:05 +03:00
--
2022-01-22 04:46:59 +03:00
=>
|%
2022-01-27 04:41:01 +03:00
++ get-dais
|= [=beak =mark rof=roof]
^- dais:clay
?~ ret=(rof ~ %cb beak /[mark])
~|(%mark-unknown !!)
?~ u.ret
~|(%mark-invalid !!)
?> =(%dais p.u.u.ret)
!<(dais:clay q.u.u.ret)
2022-01-22 04:46:59 +03:00
++ start-spider
2022-01-26 02:37:48 +03:00
|= [our=@p =cage]
^- note
[%g %deal [our our] %spider %poke cage]
2022-01-22 04:46:59 +03:00
++ watch-spider
2022-01-26 02:37:48 +03:00
|= [our=@p =path]
^- note
[%g %deal [our our] %spider %watch path]
2022-01-22 04:46:59 +03:00
--
2022-01-21 21:48:05 +03:00
=| khan-state
=* state -
|= [now=@da eny=@uvJ rof=roof]
=* khan-gate .
^?
|%
:: +call: handle a +task:khan request
::
++ call
|= $: hen=duct
dud=(unit goof)
wrapped-task=(hobo task:khan)
==
^- [(list move) _khan-gate]
::
=/ =task:khan ((harden task:khan) wrapped-task)
2022-01-26 08:28:45 +03:00
?+ -.task [~ khan-gate]
2022-01-22 01:09:01 +03:00
%born
2022-01-27 04:41:01 +03:00
:- ~
%= khan-gate
hey hen
run *(map duct thread-state)
2022-01-27 04:41:01 +03:00
==
::
2022-01-22 01:09:01 +03:00
%fyrd
2022-01-26 08:28:45 +03:00
=/ wir=wire (head hen)
=/ rid=@ta (rear wir)
=* fyd p.task
?: (~(has by run) hen)
2022-01-27 04:41:01 +03:00
~|(%fyrd-duplicate-rid !!)
2022-01-22 04:46:59 +03:00
=/ tid=@ta
(cat 3 'khan-fyrd--' rid)
=/ =beak
2022-01-28 09:28:30 +03:00
?@(bear.fyd [our bear.fyd %da now] bear.fyd)
2022-01-27 04:41:01 +03:00
=/ =dais:clay (get-dais beak p.data.fyd rof)
2022-01-26 02:37:48 +03:00
=/ args
:* ~ `tid beak name.fyd
(vale.dais q.data.fyd)
2022-01-22 04:46:59 +03:00
==
2022-01-26 02:37:48 +03:00
=/ start-moves=(list move)
%+ turn
2022-01-26 08:28:45 +03:00
:~ (watch-spider our /thread-result/[tid])
(start-spider our %spider-start !>(args))
2022-01-26 02:37:48 +03:00
==
|=(=note ^-(move [hen %pass //g note]))
=. run (~(put by run) hen tid mark.fyd beak)
2022-01-22 04:46:59 +03:00
[start-moves khan-gate]
2022-01-22 01:09:01 +03:00
==
2022-01-21 21:48:05 +03:00
:: +load: migrate an old state to a new khan version
::
++ load
|= old=khan-state
^+ khan-gate
khan-gate(state old)
2022-01-26 08:28:45 +03:00
:: +scry: nothing to see as yet
2022-01-21 21:48:05 +03:00
::
++ scry
^- roon
|= [lyc=gang car=term bem=beam]
^- (unit (unit cage))
~
++ stay state
2022-01-26 08:28:45 +03:00
:: +take: handle responses.
::
2022-01-21 21:48:05 +03:00
++ take
|= [tea=wire hen=duct dud=(unit goof) hin=sign]
^- [(list move) _khan-gate]
?^ dud
=. run (~(del by run) hen)
2022-01-21 21:48:05 +03:00
~|(%khan-take-dud (mean tang.u.dud))
2022-01-27 04:41:01 +03:00
?. ?=(%gall -.hin)
[~ khan-gate]
?+ -.p.hin [~ khan-gate]
?(%poke-ack %watch-ack)
?~ p.p.hin [~ khan-gate]
=. run (~(del by run) hen)
2022-01-28 09:20:31 +03:00
%- (slog 'khan-ack' u.p.p.hin)
2022-01-27 04:41:01 +03:00
:_ khan-gate
[hen %give %avow %| -.p.hin u.p.p.hin]~
::
%fact
=* cag cage.p.hin
?+ p.cag ~&(bad-fact+p.cag !!)
%thread-fail
=/ =tang !<(tang q.cag)
2022-01-28 09:20:31 +03:00
%- (slog 'khan-fact' tang)
2022-01-26 08:28:45 +03:00
:_ khan-gate
2022-01-27 04:41:01 +03:00
[hen %give %avow %| p.cag tang]~
::
2022-01-27 04:41:01 +03:00
%thread-done
:_ khan-gate
=/ tad=thread-state (~(got by run) hen)
=/ =dais:clay (get-dais bek.tad mak.tad rof)
=/ =vase (vale:dais q.q.cag)
[hen %give %avow %& mak.tad q.vase]~
==
2022-01-27 04:45:25 +03:00
%kick
[~ khan-gate(run (~(del by run) hen))]
==
2022-01-21 21:48:05 +03:00
--