urbit/pkg/arvo/app/aqua-eyre.hoon

158 lines
3.7 KiB
Plaintext
Raw Normal View History

2019-03-07 10:31:14 +03:00
:: Pass-through Eyre driver
::
/- aquarium
=, aquarium
2019-03-30 01:39:01 +03:00
=> |%
2019-03-07 10:31:14 +03:00
+$ move (pair bone card)
+$ card
$% [%poke wire dock %aqua-events (list aqua-event)]
[%peer wire dock path]
[%pull wire dock ~]
[%hiss wire p=(unit user:eyre) q=mark r=(cask hiss:eyre)]
==
::
+$ state
$: %0
subscribed=_|
2019-03-08 08:15:42 +03:00
piers=(map ship pier)
2019-03-07 10:31:14 +03:00
==
2019-03-08 08:15:42 +03:00
::
+$ pier http-requests=(set @ud)
2019-03-07 10:31:14 +03:00
--
=, gall
=| moves=(list move)
|_ $: bowl
state
==
++ this .
++ apex %_(this moves ~)
++ abet [(flop moves) this]
++ emit-moves
|= ms=(list move)
%_(this moves (weld ms moves))
::
++ emit-aqua-events
|= aes=(list aqua-event)
%- emit-moves
2019-03-08 08:15:42 +03:00
[ost %poke /aqua-events [our %aqua] %aqua-events aes]~
2019-03-07 10:31:14 +03:00
::
++ poke-aqua-vane-control
|= command=?(%subscribe %unsubscribe)
2019-03-08 08:15:42 +03:00
:_ this(subscribed =(command %subscribe))
(aqua-vane-control-handler our ost subscribed command)
2019-03-07 10:31:14 +03:00
::
++ diff-aqua-effects
|= [way=wire afs=aqua-effects]
^- (quip move _this)
=. this apex =< abet
|- ^+ this
?~ ufs.afs
this
=. this
?+ -.q.i.ufs.afs this
%sleep abet-pe:handle-sleep:(pe who.afs)
%restore abet-pe:handle-restore:(pe who.afs)
%thus abet-pe:(handle-thus:(pe who.afs) i.ufs.afs)
2019-03-08 08:15:42 +03:00
==
2019-03-07 10:31:14 +03:00
$(ufs.afs t.ufs.afs)
::
:: Received inbound HTTP response
::
++ sigh-httr
|= [way=wire res=httr:eyre]
^- (quip move _this)
2019-03-08 08:15:42 +03:00
=. this apex =< abet
2019-03-07 10:31:14 +03:00
?> ?=([@ *] way)
=/ who (,@p (slav %p i.way))
~& [%received-httr who]
abet-pe:(take-sigh-httr:(pe who) t.way res)
::
:: Received inbound HTTP response error
::
++ sigh-tang
|= [way=wire tan=tang]
^- (quip move _this)
2019-03-08 08:15:42 +03:00
=. this apex =< abet
2019-03-07 10:31:14 +03:00
?> ?=([@ *] way)
=/ who (,@p (slav %p i.way))
~& [%received-httr who]
abet-pe:(take-sigh-tang:(pe who) t.way tan)
::
++ pe
|= who=ship
=+ (~(gut by piers) who *pier)
2019-03-07 10:31:14 +03:00
=* pier-data -
|%
++ abet-pe
^+ this
=. piers (~(put by piers) who pier-data)
this
::
++ handle-sleep
^+ ..abet-pe
..abet-pe(pier-data *pier)
::
++ handle-restore
^+ ..abet-pe
2019-03-08 08:15:42 +03:00
=. this
%- emit-aqua-events
[%event who [//http/0v1n.2m9vh %born ~]]~
..abet-pe
2019-03-07 10:31:14 +03:00
::
++ handle-thus
|= [way=wire %thus num=@ud req=(unit hiss:eyre)]
^+ ..abet-pe
?~ req
?. (~(has in http-requests) num)
..abet-pe
:: Eyre doesn't support cancelling HTTP requests from userspace,
:: so we remove it from our state so we won't pass along the
:: response.
::
~& [who=who %aqua-eyre-cant-cancel-thus num=num]
=. http-requests (~(del in http-requests) num)
..abet-pe
~& [who=who %aqua-eyre-requesting u.req]
=. http-requests (~(put in http-requests) num)
2019-03-08 08:15:42 +03:00
=. this
%- emit-moves :_ ~
:* ost
%hiss
/(scot %p who)/(scot %ud num)
~
%httr
[%hiss u.req]
==
..abet-pe
2019-03-07 10:31:14 +03:00
::
:: Pass HTTP response back to virtual ship
::
++ take-sigh-httr
|= [way=wire res=httr:eyre]
^+ ..abet-pe
?> ?=([@ ~] way)
=/ num (slav %ud i.way)
?. (~(has in http-requests) num)
~& [who=who %ignoring-httr num=num]
..abet-pe
=. http-requests (~(del in http-requests) num)
2019-03-08 08:15:42 +03:00
=. this
2019-05-14 23:39:09 +03:00
(emit-aqua-events [%event who [//http/0v1n.2m9vh %receive num [%start [p.res q.res] r.res &]]]~)
2019-03-08 08:15:42 +03:00
..abet-pe
2019-03-07 10:31:14 +03:00
::
:: Got error in HTTP response
::
++ take-sigh-tang
|= [way=wire tan=tang]
^+ ..abet-pe
?> ?=([@ ~] way)
=/ num (slav %ud i.way)
?. (~(has in http-requests) num)
~& [who=who %ignoring-httr num=num]
..abet-pe
=. http-requests (~(del in http-requests) num)
%- (slog tan)
..abet-pe
2019-03-08 08:15:42 +03:00
--
2019-03-07 10:31:14 +03:00
--