Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pkg/arvo/sys/lull.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -3158,7 +3158,6 @@
::
[%websocket-event ws-id=@ event=websocket-event]
[%websocket-handshake ws-id=@ secure=? =address =request:http]

==
:: UIP-125
::
Expand Down Expand Up @@ -3985,7 +3984,6 @@
::
[%websocket-handshake id=@ud url=@t]
[%websocket-response id=@ud websocket-event:eyre]

==
::
+$ task
Expand All @@ -4012,12 +4010,12 @@
::
[%cancel-websocket id=@ud]
:: receives websocket event from earth
::
[%websocket-connect app=term url=@t]
:: receives websocket event from earth
::
[%websocket-event id=@ud event=websocket-event:eyre]
==

:: UIP-125
::
+$ websocket-connection
Expand Down
191 changes: 97 additions & 94 deletions pkg/arvo/sys/vane/eyre.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
::
check-session-timer=_|
:: UIP 125
::
sockets=(map @ud websocket-connection)
==
:: channel-request: an action requested on a channel
Expand Down Expand Up @@ -1041,79 +1042,76 @@
%^ return-static-data-on-duct 404 'text/html'
(error-page 404 authenticated url.request ~)
==
:: WebSockets event
::
++ ws-event
|= [wid=@ event=websocket-event]
=/ conn (~(get by connections.state) duct)
:: ~& ws-conn=conn
?~ conn `state
?. ?=(%app -.action.u.conn) `state
=/ url url.request.inbound-request.u.conn
=/ pat=(unit path) (rush url stap)
?~ pat ~& error-parsing-path=pat `state
=/ pat=(unit (list @t))
(rush url ;~(pfix fas (more fas smeg:de-purl:html)))
?~ pat ~&(error-parsing-path=url `state)
=/ app app.action.u.conn
=/ identity identity.u.conn
=/ wsid (scot %ud wid)
:: ~& >> ws-event=[identity app pat wsid]
:: TODO damn how
:: ~& eyre-ws-event=-.event
?+ -.event `state
%message
:_ state
:~ %+ deal-as
/run-ws-app-request/[wsid]
:^ identity our app
:+ %poke %websocket-server-message
!>([wid u.pat message.event])
==
%disconnect
=. connections.state (~(del by connections.state) duct)
:_ state
:~ %+ deal-as
/ws-watch-response/[wsid]
[identity our app %leave ~]
==
?+ -.event `state
%message
:_ state
:~ %+ deal-as
/run-ws-app-request/[wsid]
:^ identity our app
:+ %poke %websocket-server-message
!>([wid u.pat message.event])
==
::
%disconnect
=. connections.state (~(del by connections.state) duct)
:_ state
:~ %+ deal-as
/ws-watch-response/[wsid]
[identity our app %leave ~]
==
==
::
++ ws-handshake
|= [wid=@ secure=? =address:eyre =request:http]
^- [(list move) server-state]

=/ host=(unit @t) (get-header:http 'host' header-list.request)
=/ [=action suburl=@t]
(get-action-for-binding host url.request)
:: TODO enable other actions
?. ?=(%app -.action) `state

:: TODO!! get clear what all the identity thing has to be
:: TODO!! get clear what all the identity thing has to be
=/ app app.action
=^ ?(invalid=@uv [@uv identity (list move)]) state
=^ $@(invalid=@uv [@uv identity (list move)]) state
(session-for-request:authentication request)
=/ [session-id=@uv =identity som=(list move)]
?@ - ~& invalid-session=-
[invalid [%fake *@p] ~] -

?^ - -
~&(invalid-session=invalid [invalid [%fake *@p] ~])
=/ authenticated ?=(%ours -.identity)

=/ connection=outstanding-connection
[action [authenticated secure address request] [session-id identity] ~ 0]

[action [authenticated secure address request] [session-id identity] ~ 0]
=. connections.state
(~(put by connections.state) duct connection)
:: eyre-id is assigned way up in this arm
=/ wsid (scot %ud wid)
:_ state
~& som=som
%+ weld som
:~ %+ deal-as
/ws-watch-response/[wsid]
:~ %+ deal-as /ws-watch-response/[wsid]
[identity our app %watch /websocket-server/[wsid]]
::
%+ deal-as
/run-ws-app-request/[wsid]
%+ deal-as /run-ws-app-request/[wsid]
:^ identity our app
:+ %poke %websocket-handshake
!>(`[@ inbound-request:eyre]`[wid inbound-request.connection])
==

:: +handle-ip: respond with the requester's ip
::
++ handle-ip
Expand Down Expand Up @@ -3201,34 +3199,38 @@
tang
==
[(weld moves-1 moves-2) state]
:: +handle-response: check a response for correctness and send to earth
::
:: All outbound responses including %http-server generated responses need to go
:: through this interface because we want to have one centralized place
:: where we perform logging and state cleanup for connections that we're
:: done with.
::
++ handle-ws-response
|= [wid=@ event=websocket-event]
^- [(list move) server-state]
=. connections.state
?: ?=(%reject -.event) (~(del by connections.state) duct)
?: ?=(%disconnect -.event) (~(del by connections.state) duct)
connections.state
?+ -.event connections.state
?(%reject %disconnect) (~(del by connections.state) duct)
==
=. sockets.state
?: ?=(%reject -.event) (~(del by sockets.state) wid)
?: ?=(%disconnect -.event) (~(del by sockets.state) wid)
?: ?=(%accept -.event)
?+ -.event sockets.state
?(%reject %disconnect)
(~(del by sockets.state) wid)
::
%accept
=/ outstanding (~(get by connections.state) duct)
?~ outstanding ~& >>> eyre-ws-error=[wid event] sockets.state
?~ outstanding
~& >>> eyre-ws-error=[wid event] sockets.state
=/ req=inbound-request inbound-request.u.outstanding
:: TODO this is bad
?> ?=(%app -.action.u.outstanding)
(~(put by sockets.state) wid +.action.u.outstanding req)
sockets.state

(~(put by sockets.state) wid +.action.u.outstanding req)
==
[[duct %give %websocket-response [wid event]]~ state]

::
:: +handle-response: check a response for correctness and send to earth
::
:: All outbound responses including %http-server generated responses need to go
:: through this interface because we want to have one centralized place
:: where we perform logging and state cleanup for connections that we're
:: done with.
::
::
++ handle-response
|= =http-event:http
^- [(list move) server-state]
Expand Down Expand Up @@ -3968,11 +3970,11 @@
%set-response
=^ moves server-state.ax (set-response:server +.task)
[moves http-server-gate]
::
%websocket-event
=^ moves server-state.ax (ws-event:server +.task)
[moves http-server-gate]


::
%websocket-handshake
=^ moves server-state.ax (ws-handshake:server +.task)
[moves http-server-gate]
Expand Down Expand Up @@ -4002,61 +4004,59 @@
?+ i.wire
~|([%bad-take-wire wire] !!)
::
%run-app-request run-app-request
%watch-response watch-response
%sessions sessions
%channel channel
%acme acme-ack
%conversion-cache `http-server-gate
%run-app-request run-app-request
%watch-response watch-response
%sessions sessions
%channel channel
%acme acme-ack
%conversion-cache `http-server-gate
%run-ws-app-request run-ws-app-request
%ws-watch-response watch-ws-response
==
::
++ watch-ws-response
=/ event-args [[eny duct now rof] server-state.ax]
?> ?=([@ *] t.wire)
?+ sign `http-server-gate
[%gall %unto %watch-ack *]
?~ p.p.sign
:: received a positive acknowledgment: take no action
::
[~ http-server-gate]
:: we have an error; propagate it to the client
?+ sign `http-server-gate
[%gall %unto %watch-ack *]
?~ p.p.sign
:: received a positive acknowledgment: take no action
::
~& gall-error=u.p.p.sign
=/ handle-gall-error
handle-gall-error:(per-server-event event-args)
=^ moves server-state.ax (handle-gall-error u.p.p.sign)
[moves http-server-gate]
::
[%gall %unto %kick ~]
=/ handle-ws-response handle-ws-response:(per-server-event event-args)
=^ moves server-state.ax
[~ http-server-gate]
:: we have an error; propagate it to the client
::
~& gall-error=u.p.p.sign
=/ handle-gall-error
handle-gall-error:(per-server-event event-args)
=^ moves server-state.ax (handle-gall-error u.p.p.sign)
[moves http-server-gate]
::
[%gall %unto %kick ~]
=/ handle-ws-response handle-ws-response:(per-server-event event-args)
=^ moves server-state.ax
:: TODO not great
=/ wids (head (flop wire))
=/ wid (slav %ud wids)
(handle-ws-response wid [%disconnect ~])
[moves http-server-gate]
::
[%gall %unto %fact *]
=/ mark p.cage.p.sign
?. ?=(%websocket-response mark)
=/ handle-gall-error
handle-gall-error:(per-server-event event-args)
=^ moves server-state.ax
(handle-gall-error leaf+"eyre bad mark {(trip mark)}" ~)
[moves http-server-gate]
=/ event !<([@ websocket-event] q.cage.p.sign)
=/ handle-ws-response handle-ws-response:(per-server-event event-args)
(handle-ws-response wid [%disconnect ~])
[moves http-server-gate]
::
[%gall %unto %fact *]
=/ mark p.cage.p.sign
?. ?=(%websocket-response mark)
=/ handle-gall-error
handle-gall-error:(per-server-event event-args)
=^ moves server-state.ax
(handle-ws-response event)
(handle-gall-error leaf+"eyre bad mark {(trip mark)}" ~)
[moves http-server-gate]
=/ event !<([@ websocket-event] q.cage.p.sign)
=/ handle-ws-response handle-ws-response:(per-server-event event-args)
=^ moves server-state.ax
(handle-ws-response event)
[moves http-server-gate]

==
++ run-ws-app-request

`http-server-gate

::
++ run-ws-app-request `http-server-gate
::
++ run-app-request
::
?> ?=([%gall %unto *] sign)
Expand Down Expand Up @@ -4419,6 +4419,7 @@
outgoing-duct=duct
verb=@
==
::
+$ server-state-5
$: bindings=(list [=binding =duct =action])
cache=(map url=@t [aeon=@ud val=(unit cache-entry)])
Expand Down Expand Up @@ -4551,6 +4552,9 @@
date.old %~2025.1.31
verb.old [verb.old check-session-timer=&]
==
::
:: adds web sockets: UIP-125
::
%~2025.1.31
%= $
date.old %~2025.10.28
Expand Down Expand Up @@ -4748,4 +4752,3 @@
==
==
--

Loading
Loading