mirror of
https://github.com/urbit/shrub.git
synced 2024-09-11 12:25:43 +03:00
Merge remote-tracking branch 'origin/jb/chum' into lf/back-to-school-arc
This commit is contained in:
commit
ab3a4b05f8
@ -45,7 +45,6 @@
|
||||
|= [=mark =vase]
|
||||
^- (quip card _this)
|
||||
|^
|
||||
?> (team:title our.bowl src.bowl)
|
||||
?+ mark (on-poke:def mark vase)
|
||||
%handle-http-request
|
||||
=+ !<([id=@ta req=inbound-request:eyre] vase)
|
||||
@ -53,6 +52,7 @@
|
||||
(handle-http-request id req)
|
||||
::
|
||||
%azimuth-action
|
||||
?> (team:title our.bowl src.bowl)
|
||||
=+ !<([%disconnect bind=binding:eyre] vase)
|
||||
~& >>> "disconnecting at {<bind>}"
|
||||
:_ this
|
||||
|
@ -764,6 +764,7 @@
|
||||
:: Messaging Tasks
|
||||
::
|
||||
:: %hear: packet from unix
|
||||
:: %dear: lane from unix
|
||||
:: %heed: track peer's responsiveness; gives %clog if slow
|
||||
:: %jilt: stop tracking peer's responsiveness
|
||||
:: %cork: request to delete message flow
|
||||
@ -787,13 +788,14 @@
|
||||
:: %snub: set packet blocklist to .ships
|
||||
:: %spew: set verbosity toggles
|
||||
:: %cong: adjust congestion control parameters
|
||||
:: %stir: recover from timer desync
|
||||
:: %stir: recover from timer desync and assorted debug commands
|
||||
:: %trim: release memory
|
||||
:: %vega: kernel reload notification
|
||||
::
|
||||
+$ task
|
||||
$+ ames-task
|
||||
$% [%hear =lane =blob]
|
||||
[%dear =ship =lane]
|
||||
[%heed =ship]
|
||||
[%jilt =ship]
|
||||
[%cork =ship]
|
||||
@ -803,6 +805,7 @@
|
||||
[%deep =deep]
|
||||
::
|
||||
[%keen sec=(unit [idx=@ key=@]) spar]
|
||||
[%chum spar]
|
||||
[%yawn spar]
|
||||
[%wham spar]
|
||||
[%plug vane=term =path]
|
||||
@ -844,6 +847,7 @@
|
||||
[%send =lane =blob]
|
||||
::
|
||||
[%stub num=@ud key=@]
|
||||
[%near spar dat=(unit (unit page))]
|
||||
[%tune spar roar=(unit roar)]
|
||||
::
|
||||
[%turf turfs=(list turf)]
|
||||
|
@ -567,7 +567,7 @@
|
||||
:: bug: debug printing configuration
|
||||
:: snub: blocklist for incoming packets
|
||||
:: cong: parameters for marking a flow as clogged
|
||||
:: dead: dead flow consolidation timer, if set
|
||||
:: dead: dead flow consolidation timer and recork timer, if set
|
||||
::
|
||||
+$ ames-state
|
||||
$+ ames-state
|
||||
@ -1271,7 +1271,7 @@
|
||||
+$ note
|
||||
$~ [%b %wait *@da]
|
||||
$% $: %a
|
||||
$>(%deep task:ames)
|
||||
$>(?(%deep %keen) task:ames)
|
||||
==
|
||||
$: %b
|
||||
$>(?(%wait %rest) task:behn)
|
||||
@ -1300,7 +1300,10 @@
|
||||
::
|
||||
+$ sign
|
||||
$~ [%behn %wake ~]
|
||||
$% $: %behn
|
||||
$% $: %ames
|
||||
$>(%tune gift:ames)
|
||||
==
|
||||
$: %behn
|
||||
$>(%wake gift:behn)
|
||||
==
|
||||
$: %gall
|
||||
@ -2096,15 +2099,44 @@
|
||||
event-core
|
||||
:: +on-stir: recover from timer desync, setting new timers as needed
|
||||
::
|
||||
:: .arg is unused, meant to ease future debug commands
|
||||
:: .arg can be %rift or %dead
|
||||
::
|
||||
++ on-stir
|
||||
|= arg=@t
|
||||
^+ event-core
|
||||
|^ ?+ arg do-stir
|
||||
%rift do-rift
|
||||
%dead do-dead
|
||||
==
|
||||
::
|
||||
++ do-dead
|
||||
=/ ded=(unit dead-timer) +.flow.dead.ames-state
|
||||
?^ ded
|
||||
%- (slog leaf+"ames: turning off dead flow consolidation" ~)
|
||||
=. event-core
|
||||
(emit:event-core duct.u.ded %pass wire.u.ded %b %rest date.u.ded)
|
||||
(wake-dead-flows:event-core %.n ~)
|
||||
::
|
||||
%- (slog leaf+"ames: switching to dead flow consolidation" ~)
|
||||
=; cor=event-core
|
||||
(wake-dead-flows:cor %.y ~)
|
||||
%- ~(rep by peers.ames-state:event-core)
|
||||
|= [[=ship =ship-state] core=_event-core]
|
||||
^+ event-core
|
||||
=/ peer-state=(unit peer-state) (get-peer-state:core ship)
|
||||
?~ peer-state core
|
||||
%- ~(rep by snd.u.peer-state)
|
||||
|= [[=bone =message-pump-state] cor=_core]
|
||||
^+ event-core
|
||||
=/ next-wake next-wake.packet-pump-state.message-pump-state
|
||||
?. ?& =(~m2 rto.metrics.packet-pump-state.message-pump-state)
|
||||
?=(^ next-wake)
|
||||
==
|
||||
cor
|
||||
=/ peer-core (abed-peer:pe:cor ship u.peer-state)
|
||||
=/ message-pump (abed:mu:peer-core bone)
|
||||
abet:(pu-emit:packet-pump:message-pump %b %rest u.next-wake)
|
||||
::
|
||||
++ do-rift
|
||||
=/ =rift
|
||||
=- ~|(%no-rift (,@ q.q:(need (need -))))
|
||||
@ -2179,6 +2211,27 @@
|
||||
%^ enqueue-alien-todo ship ship-state
|
||||
|= todos=alien-agenda
|
||||
todos(heeds (~(del in heeds.todos) duct))
|
||||
:: +on-dear: handle lane from unix
|
||||
::
|
||||
++ on-dear
|
||||
|= [=ship =lane]
|
||||
^+ event-core
|
||||
?: ?=(%.y -.lane)
|
||||
event-core
|
||||
=/ ip=@if (end [0 32] p.lane)
|
||||
=/ pt=@ud (cut 0 [32 16] p.lane)
|
||||
?: =(%czar (clan:title ship))
|
||||
%- %^ ev-trace odd.veb ship
|
||||
|.("ignoring %dear lane {(scow %if ip)}:{(scow %ud pt)} for galaxy")
|
||||
event-core
|
||||
=/ peer-state=(unit peer-state) (get-peer-state ship)
|
||||
?~ peer-state
|
||||
%- %^ ev-trace odd.veb ship
|
||||
|.("no peer-state for ship, ignoring %dear")
|
||||
event-core
|
||||
%- %^ ev-trace rcv.veb ship
|
||||
|.("incoming %dear lane {(scow %if ip)}:{(scow %ud pt)}")
|
||||
abet:(on-dear:(abed-peer:pe ship u.peer-state) lane)
|
||||
:: +on-hear: handle raw packet receipt
|
||||
::
|
||||
++ on-hear
|
||||
@ -2441,6 +2494,30 @@
|
||||
%- (slog leaf+"ames: no peer-state for {(scow %p ship)}, ignoring" ~)
|
||||
event-core
|
||||
abet:on-tame:(abed-peer:pe ship u.peer-state)
|
||||
::
|
||||
::
|
||||
++ on-tune
|
||||
|= [=wire s=[=ship path=(pole knot)] roar=(unit roar)]
|
||||
^+ event-core
|
||||
?> ?=([%chum *] wire)
|
||||
:: XX save or decrypt path?
|
||||
:: XX crash in decryption/cue indicates misbehaving peer
|
||||
::
|
||||
=/ per (~(get by peers.ames-state) ship.s)
|
||||
?> ?=([~ %known *] per)
|
||||
?> ?=([%a %x %~.1 %$ %chum her=@ lyf=@ cyf=@ ~] path.s)
|
||||
=/ pax
|
||||
=- (,path (cue -))
|
||||
(dy:crub:crypto symmetric-key.u.per (slav %uv cyf.path.s))
|
||||
=/ dat=(unit (unit page))
|
||||
?: ?| ?=(~ roar)
|
||||
?=(~ q.dat.u.roar)
|
||||
==
|
||||
~ :: XX weird
|
||||
?> ?=([%atom @] u.q.dat.u.roar)
|
||||
=- `?~(- ~ `(,page (cue -)))
|
||||
(dy:crub:crypto symmetric-key.u.per q.u.q.dat.u.roar)
|
||||
(emit duct [%give %near [ship.s pax] dat])
|
||||
:: +on-cork: handle request to kill a flow
|
||||
::
|
||||
++ on-cork
|
||||
@ -2520,6 +2597,35 @@
|
||||
++ cork-bone |=(=bone abet:(on-cork-flow:peer-core bone))
|
||||
++ kill-bone |=(=bone abet:(on-kill-flow:peer-core bone))
|
||||
--
|
||||
:: +wake-dead-flow: call on-wake on all dead flows, optionally setting new
|
||||
:: dead flow timer
|
||||
::
|
||||
++ wake-dead-flows
|
||||
|= [set-new-timer=? error=(unit tang)]
|
||||
^+ event-core
|
||||
=. flow.dead.ames-state.event-core
|
||||
?. set-new-timer
|
||||
flow/~
|
||||
flow/`[~[/ames] /dead-flow `@da`(add now ~m2)]
|
||||
=. event-core
|
||||
?. set-new-timer
|
||||
event-core
|
||||
(emit:event-core ~[/ames] %pass /dead-flow %b %wait `@da`(add now ~m2))
|
||||
%- ~(rep by peers.ames-state:event-core)
|
||||
|= [[=ship =ship-state] core=_event-core]
|
||||
^+ event-core
|
||||
=/ peer-state=(unit peer-state) (get-peer-state:core ship)
|
||||
?~ peer-state core
|
||||
=/ peer-core (abed-peer:pe:core ship u.peer-state)
|
||||
=< abet
|
||||
^+ peer-core
|
||||
%- ~(rep by snd.u.peer-state)
|
||||
|= [[=bone =message-pump-state] cor=_peer-core]
|
||||
?. ?& =(~m2 rto.metrics.packet-pump-state.message-pump-state)
|
||||
?=(^ next-wake.packet-pump-state.message-pump-state)
|
||||
==
|
||||
cor
|
||||
(on-wake:cor bone error)
|
||||
:: +on-take-wake: receive wakeup or error notification from behn
|
||||
::
|
||||
++ on-take-wake
|
||||
@ -2540,22 +2646,7 @@
|
||||
(request-attestation u.ship)
|
||||
::
|
||||
?: ?=([%dead-flow ~] wire)
|
||||
=; cor=event-core
|
||||
=. flow.dead.ames-state.cor
|
||||
flow/`[~[/ames] /dead-flow `@da`(add now ~m2)]
|
||||
(emit:cor duct %pass /dead-flow %b %wait `@da`(add now ~m2))
|
||||
%- ~(rep by peers.ames-state)
|
||||
|= [[=ship =ship-state] core=_event-core]
|
||||
^+ event-core
|
||||
=/ peer-state=(unit peer-state) (get-peer-state:core ship)
|
||||
?~ peer-state core
|
||||
%- ~(rep by snd.u.peer-state)
|
||||
|= [[=bone =message-pump-state] cor=_core]
|
||||
?. ?& =(~m2 rto.metrics.packet-pump-state.message-pump-state)
|
||||
?=(^ next-wake.packet-pump-state.message-pump-state)
|
||||
==
|
||||
cor
|
||||
abet:(on-wake:(abed-peer:pe:cor ship u.peer-state) bone error)
|
||||
(wake-dead-flows %.y error)
|
||||
::
|
||||
?. ?=([%recork ~] wire)
|
||||
=/ res=(unit ?([%fine her=ship =^wire] [%pump her=ship =bone]))
|
||||
@ -2924,17 +3015,15 @@
|
||||
::
|
||||
=* duct unix-duct.ames-state
|
||||
::
|
||||
=^ dead-moves dead.ames-state
|
||||
?. ?=([~ ~] [+.flow +.cork]:dead.ames-state)
|
||||
`dead.ames-state
|
||||
:- :- [~[/ames] %pass /dead-flow %b %wait `@da`(add now ~m2)]
|
||||
[~[/ames] %pass /recork %b %wait `@da`(add now ~d1)]~
|
||||
:- flow/`[~[/ames] /dead-flow `@da`(add now ~m2)]
|
||||
cork/`[~[/ames] /recork `@da`(add now ~d1)]
|
||||
=^ cork-moves cork.dead.ames-state
|
||||
?. ?=(~ +.cork.dead.ames-state)
|
||||
`cork.dead.ames-state
|
||||
:- [~[/ames] %pass /recork %b %wait `@da`(add now ~d1)]~
|
||||
cork/`[~[/ames] /recork `@da`(add now ~d1)]
|
||||
::
|
||||
%- emil
|
||||
%+ weld
|
||||
dead-moves
|
||||
cork-moves
|
||||
^- (list move)
|
||||
:~ [duct %give %turf turfs]
|
||||
[duct %pass /ping %g %deal [our our /ames] %ping %poke %noun !>(%kick)]
|
||||
@ -2991,6 +3080,23 @@
|
||||
|= todos=alien-agenda
|
||||
todos(keens (~(put ju keens.todos) path duct))
|
||||
::
|
||||
++ on-chum
|
||||
|= spar
|
||||
^+ event-core
|
||||
=/ ship-state (~(get by peers.ames-state) ship)
|
||||
?. ?=([~ %known *] ship-state)
|
||||
:: XX add state for queued chum
|
||||
::
|
||||
:: %^ enqueue-alien-todo ship ship-state
|
||||
:: |= todos=alien-agenda
|
||||
:: todos(keens (~(put ju keens.todos) path duct))
|
||||
!!
|
||||
=/ cyf
|
||||
(scot %uv (en:crub:crypto symmetric-key.u.ship-state (jam path)))
|
||||
=/ lav
|
||||
/a/x/1//chum/(scot %p our)/(scot %ud life.ames-state)/[cyf]
|
||||
(emit duct [%pass /chum %a %keen ~ ship lav])
|
||||
::
|
||||
++ on-cancel-scry
|
||||
|= [all=? spar]
|
||||
^+ event-core
|
||||
@ -3376,6 +3482,11 @@
|
||||
=. keens (~(put by keens) path *keen-state)
|
||||
fi-abet:(fi-start:(abed:fi path) duct)
|
||||
::
|
||||
++ on-dear
|
||||
|= =lane
|
||||
^+ peer-core
|
||||
peer-core(route.peer-state `[%.y lane])
|
||||
::
|
||||
++ on-tame
|
||||
^+ peer-core
|
||||
peer-core(route.peer-state ~)
|
||||
@ -4174,7 +4285,7 @@
|
||||
:: and we don't want to consolidate that
|
||||
::
|
||||
=? peer-core ?=(^ new-wake)
|
||||
?: =(~m2 rto.metrics.state)
|
||||
?: ?&(?=(^ +.flow.dead.ames-state) =(~m2 rto.metrics.state))
|
||||
peer-core
|
||||
(pu-emit %b %wait u.new-wake)
|
||||
::
|
||||
@ -5037,6 +5148,7 @@
|
||||
?- -.task
|
||||
%born on-born:event-core
|
||||
%hear (on-hear:event-core [lane blob ~]:task)
|
||||
%dear (on-dear:event-core +.task)
|
||||
%heed (on-heed:event-core ship.task)
|
||||
%init on-init:event-core
|
||||
%jilt (on-jilt:event-core ship.task)
|
||||
@ -5056,6 +5168,7 @@
|
||||
%plug (on-plug:event-core [vane path]:task)
|
||||
::
|
||||
%keen (on-keen:event-core +.task)
|
||||
%chum (on-chum:event-core +.task)
|
||||
%yawn (on-cancel-scry:event-core | +.task)
|
||||
%wham (on-cancel-scry:event-core & +.task)
|
||||
==
|
||||
@ -5079,6 +5192,8 @@
|
||||
?- sign
|
||||
[@ %done *] (on-take-done:event-core wire error.sign)
|
||||
[@ %boon *] (on-take-boon:event-core wire payload.sign)
|
||||
::
|
||||
[%ames %tune *] (on-tune:event-core wire [[ship path] roar]:sign)
|
||||
::
|
||||
[%behn %wake *] (on-take-wake:event-core wire error.sign)
|
||||
::
|
||||
@ -5277,7 +5392,7 @@
|
||||
%= old
|
||||
cong
|
||||
:+ cong.old
|
||||
flow/`[~[/ames] /dead-flow `@da`(add now ~m2)]
|
||||
flow/~
|
||||
cork/`[~[/ames] /recork `@da`(add now ~d1)]
|
||||
::
|
||||
peers
|
||||
@ -5350,6 +5465,35 @@
|
||||
=* lot=coin $/r.bem
|
||||
=* tyl s.bem
|
||||
::
|
||||
?: ?& =(&+our why)
|
||||
=([%$ %ud 1] lot)
|
||||
=(%$ syd)
|
||||
=(%x ren)
|
||||
==
|
||||
=> .(tyl `(pole knot)`tyl)
|
||||
?+ tyl ~
|
||||
[%chum her=@ lyf=@ cyf=@ ~]
|
||||
=/ who (slaw %p her.tyl)
|
||||
=/ lyf (slaw %ud lyf.tyl)
|
||||
=/ cyf (slaw %uv cyf.tyl)
|
||||
?: |(?=(~ who) ?=(~ lyf) ?=(~ cyf))
|
||||
[~ ~]
|
||||
=/ per (~(get by peers.ames-state) u.who)
|
||||
?. &(?=([~ %known *] per) =(life.u.per u.lyf))
|
||||
~
|
||||
=/ bal=(unit balk)
|
||||
?~ tex=(de:crub:crypto symmetric-key.u.per u.cyf) ~
|
||||
?~ pax=(mole |.((,path (cue u.tex)))) ~
|
||||
(de-part:balk our 0 0 u.pax)
|
||||
?~ bal
|
||||
[~ ~]
|
||||
?~ res=(rof `[u.who ~ ~] /ames (as-omen:balk u.bal))
|
||||
~
|
||||
=- ``atom+!>(`@ux`-)
|
||||
%+ en:crub:crypto symmetric-key.u.per
|
||||
?~(u.res ~ (jam [p q.q]:u.u.res))
|
||||
==
|
||||
::
|
||||
:: only respond for the local identity, %$ desk, current timestamp
|
||||
::
|
||||
?. ?& =(&+our why)
|
||||
@ -5502,7 +5646,14 @@
|
||||
~| nom
|
||||
|^
|
||||
=/ van ?@(vis.nom (end 3 vis.nom) way.vis.nom)
|
||||
=/ kyr ?@(vis.nom (rsh 3 vis.nom) car.vis.nom)
|
||||
?+ van ~
|
||||
%a
|
||||
%- en-hunk
|
||||
?+ kyr ~
|
||||
%x (rof ~ /ames nom)
|
||||
==
|
||||
::
|
||||
%c
|
||||
=+ pem=(rof lyc /ames nom(vis %cp))
|
||||
?. ?=(^ pem) ~
|
||||
@ -5513,7 +5664,6 @@
|
||||
(en-hunk (rof ~ /ames nom))
|
||||
::
|
||||
%e
|
||||
=/ kyr ?@(vis.nom (rsh 3 vis.nom) car.vis.nom)
|
||||
%- en-hunk
|
||||
?+ kyr ~
|
||||
%x (rof ~ /ames nom)
|
||||
@ -5534,7 +5684,6 @@
|
||||
(handle-shut spr.u.new p.r.bem.nom res)
|
||||
::
|
||||
%g
|
||||
=/ kyr ?@(vis.nom (rsh 3 vis.nom) car.vis.nom)
|
||||
%- en-hunk
|
||||
?+ kyr ~
|
||||
%x (rof ~ /ames nom)
|
||||
|
@ -789,8 +789,7 @@
|
||||
%. (~(put by connections.state) duct connection)
|
||||
(trace 2 |.("{<duct>} creating local"))
|
||||
::
|
||||
:_ state
|
||||
(subscribe-to-app [%ours ~] app.act inbound-request.connection)
|
||||
(request-to-app [%ours ~] app.act inbound-request.connection)
|
||||
:: +request: starts handling an inbound http request
|
||||
::
|
||||
++ request
|
||||
@ -964,8 +963,7 @@
|
||||
==
|
||||
::
|
||||
%app
|
||||
:_ state
|
||||
(subscribe-to-app identity app.action inbound-request.connection)
|
||||
(request-to-app identity app.action inbound-request.connection)
|
||||
::
|
||||
%authentication
|
||||
(handle-request:authentication secure host address [suv identity] request)
|
||||
@ -1100,11 +1098,24 @@
|
||||
%^ return-static-data-on-duct status 'text/html'
|
||||
(error-page status authenticated url.request tape)
|
||||
--
|
||||
:: +subscribe-to-app: subscribe to app and poke it with request data
|
||||
:: +request-to-app: subscribe to app and poke it with request data
|
||||
::
|
||||
++ subscribe-to-app
|
||||
++ request-to-app
|
||||
|= [=identity app=term =inbound-request:eyre]
|
||||
^- (list move)
|
||||
^- (quip move server-state)
|
||||
:: if the agent isn't running, we synchronously serve a 503
|
||||
::
|
||||
?. !<(? q:(need (need (rof ~ /eyre %gu [our app da+now] /$))))
|
||||
%^ return-static-data-on-duct 503 'text/html'
|
||||
%: error-page
|
||||
503
|
||||
?=(%ours -.identity)
|
||||
url.request.inbound-request
|
||||
"%{(trip app)} not running"
|
||||
==
|
||||
:: otherwise, subscribe to the agent and poke it with the request
|
||||
::
|
||||
:_ state
|
||||
:~ %+ deal-as
|
||||
/watch-response/[eyre-id]
|
||||
[identity our app %watch /http-response/[eyre-id]]
|
||||
@ -1347,14 +1358,15 @@
|
||||
^- (unit @uv)
|
||||
:: are there cookies passed with this request?
|
||||
::
|
||||
:: TODO: In HTTP2, the client is allowed to put multiple 'Cookie'
|
||||
:: headers.
|
||||
=/ cookie-header=@t
|
||||
%+ roll header-list.request
|
||||
|= [[key=@t value=@t] c=@t]
|
||||
?. =(key 'cookie')
|
||||
c
|
||||
(cat 3 (cat 3 c ?~(c 0 '; ')) value)
|
||||
:: is the cookie line valid?
|
||||
::
|
||||
?~ cookie-header=(get-header:http 'cookie' header-list.request)
|
||||
~
|
||||
:: is the cookie line is valid?
|
||||
::
|
||||
?~ cookies=(rush u.cookie-header cock:de-purl:html)
|
||||
?~ cookies=(rush cookie-header cock:de-purl:html)
|
||||
~
|
||||
:: is there an urbauth cookie?
|
||||
::
|
||||
@ -2111,7 +2123,7 @@
|
||||
duct-to-key.channel-state
|
||||
(~(del by duct-to-key.channel-state.state) duct)
|
||||
==
|
||||
:: +set-timeout-timer-for: sets a timeout timer on a channel
|
||||
:: +update-timeout-timer-for: sets a timeout timer on a channel
|
||||
::
|
||||
:: This creates a channel if it doesn't exist, cancels existing timers
|
||||
:: if they're already set (we cannot have duplicate timers), and (if
|
||||
@ -2185,53 +2197,76 @@
|
||||
++ on-get-request
|
||||
|= [channel-id=@t [session-id=@uv =identity] =request:http]
|
||||
^- [(list move) server-state]
|
||||
:: if there's no channel-id, we must 404
|
||||
::TODO but arm description says otherwise?
|
||||
::
|
||||
?~ maybe-channel=(~(get by session.channel-state.state) channel-id)
|
||||
%^ return-static-data-on-duct 404 'text/html'
|
||||
(error-page 404 | url.request ~)
|
||||
:: find the channel creator's identity, make sure it matches
|
||||
::
|
||||
?. =(identity identity.u.maybe-channel)
|
||||
%^ return-static-data-on-duct 403 'text/html'
|
||||
(error-page 403 | url.request ~)
|
||||
:: find the requested "mode" and make sure it doesn't conflict
|
||||
::
|
||||
=/ mode=?(%json %jam)
|
||||
(find-channel-mode %'GET' header-list.request)
|
||||
?. =(mode mode.u.maybe-channel)
|
||||
%^ return-static-data-on-duct 406 'text/html'
|
||||
=; msg=tape (error-page 406 %.y url.request msg)
|
||||
"channel already established in {(trip mode.u.maybe-channel)} mode"
|
||||
:: when opening an event-stream, we must cancel our timeout timer
|
||||
:: if there's no duct already bound. Else, kill the old request
|
||||
:: and replace it
|
||||
::
|
||||
=^ cancel-moves state
|
||||
?. ?=([%| *] state.u.maybe-channel)
|
||||
:_ state
|
||||
(cancel-timeout-move channel-id p.state.u.maybe-channel)^~
|
||||
=/ cancel-heartbeat
|
||||
?~ heartbeat.u.maybe-channel ~
|
||||
:_ ~
|
||||
%+ cancel-heartbeat-move channel-id
|
||||
[date duct]:u.heartbeat.u.maybe-channel
|
||||
=- [(weld cancel-heartbeat -<) ->]
|
||||
(handle-response(duct p.state.u.maybe-channel) [%cancel ~])
|
||||
:: the request may include a 'Last-Event-Id' header
|
||||
::
|
||||
=/ maybe-last-event-id=(unit @ud)
|
||||
?~ maybe-raw-header=(get-header:http 'last-event-id' header-list.request)
|
||||
~
|
||||
(rush u.maybe-raw-header dum:ag)
|
||||
:: flush events older than the passed in 'Last-Event-ID'
|
||||
::
|
||||
=? state ?=(^ maybe-last-event-id)
|
||||
(acknowledge-events channel-id u.maybe-last-event-id)
|
||||
:: combine the remaining queued events to send to the client
|
||||
::
|
||||
=/ event-replay=wall
|
||||
=^ [exit=? =wall moves=(list move)] state
|
||||
:: the request may include a 'Last-Event-Id' header
|
||||
::
|
||||
=/ maybe-last-event-id=(unit @ud)
|
||||
?~ maybe-raw-header=(get-header:http 'last-event-id' header-list.request)
|
||||
~
|
||||
(rush u.maybe-raw-header dum:ag)
|
||||
:: if the channel doesn't exist yet, simply instantiate it here
|
||||
::
|
||||
?~ maybe-channel=(~(get by session.channel-state.state) channel-id)
|
||||
=- [[| ~ ~] state(session.channel-state -)]
|
||||
%+ ~(put by session.channel-state.state) channel-id
|
||||
::NOTE some other fields initialized at the end of this arm
|
||||
%* . *channel
|
||||
identity identity
|
||||
next-id (fall maybe-last-event-id 0)
|
||||
last-ack now
|
||||
==
|
||||
:: if the channel does exist, we put some demands on the get request,
|
||||
:: and may need to do some cleanup for prior requests.
|
||||
::
|
||||
:: find the channel creator's identity, make sure it matches
|
||||
::
|
||||
?. =(identity identity.u.maybe-channel)
|
||||
=^ mos state
|
||||
%^ return-static-data-on-duct 403 'text/html'
|
||||
(error-page 403 | url.request ~)
|
||||
[[& ~ mos] state]
|
||||
:: make sure the request "mode" doesn't conflict with a prior request
|
||||
::
|
||||
::TODO or could we change that on the spot, given that only a single
|
||||
:: request will ever be listening to this channel?
|
||||
?. =(mode mode.u.maybe-channel)
|
||||
=^ mos state
|
||||
%^ return-static-data-on-duct 406 'text/html'
|
||||
=; msg=tape (error-page 406 %.y url.request msg)
|
||||
"channel already established in {(trip mode.u.maybe-channel)} mode"
|
||||
[[& ~ mos] state]
|
||||
:: when opening an event-stream, we must cancel our timeout timer
|
||||
:: if there's no duct already bound. else, kill the old request,
|
||||
:: we will replace its duct at the end of this arm
|
||||
::
|
||||
=^ cancel-moves state
|
||||
?: ?=([%& *] state.u.maybe-channel)
|
||||
:_ state
|
||||
(cancel-timeout-move channel-id p.state.u.maybe-channel)^~
|
||||
=. duct-to-key.channel-state.state
|
||||
(~(del by duct-to-key.channel-state.state) p.state.u.maybe-channel)
|
||||
=/ cancel-heartbeat
|
||||
?~ heartbeat.u.maybe-channel ~
|
||||
:_ ~
|
||||
%+ cancel-heartbeat-move channel-id
|
||||
[date duct]:u.heartbeat.u.maybe-channel
|
||||
=- [(weld cancel-heartbeat -<) ->]
|
||||
(handle-response(duct p.state.u.maybe-channel) [%cancel ~])
|
||||
:: flush events older than the passed in 'Last-Event-ID'
|
||||
::
|
||||
=? state ?=(^ maybe-last-event-id)
|
||||
(acknowledge-events channel-id u.maybe-last-event-id)
|
||||
::TODO that did not remove them from the u.maybe-channel queue though!
|
||||
:: we may want to account for maybe-last-event-id, for efficiency.
|
||||
:: (the client _should_ ignore events it heard previously if we do
|
||||
:: end up re-sending them, but _requiring_ that feels kinda risky)
|
||||
::
|
||||
:: combine the remaining queued events to send to the client
|
||||
::
|
||||
=; event-replay=wall
|
||||
[[| - cancel-moves] state]
|
||||
%- zing
|
||||
%- flop
|
||||
=/ queue events.u.maybe-channel
|
||||
@ -2249,6 +2284,7 @@
|
||||
(channel-event-to-tape u.maybe-channel request-id channel-event)
|
||||
?~ said $
|
||||
$(events [(event-tape-to-wall id +.u.said) events])
|
||||
?: exit [moves state]
|
||||
:: send the start event to the client
|
||||
::
|
||||
=^ http-moves state
|
||||
@ -2259,7 +2295,7 @@
|
||||
['cache-control' 'no-cache']
|
||||
['connection' 'keep-alive']
|
||||
==
|
||||
(wall-to-octs event-replay)
|
||||
(wall-to-octs wall)
|
||||
complete=%.n
|
||||
==
|
||||
:: associate this duct with this session key
|
||||
@ -2289,7 +2325,7 @@
|
||||
heartbeat (some [heartbeat-time duct])
|
||||
==
|
||||
::
|
||||
[[heartbeat :(weld http-moves cancel-moves moves)] state]
|
||||
[[heartbeat :(weld http-moves moves)] state]
|
||||
:: +acknowledge-events: removes events before :last-event-id on :channel-id
|
||||
::
|
||||
++ acknowledge-events
|
||||
@ -2337,11 +2373,6 @@
|
||||
?: ?=(%| -.maybe-requests)
|
||||
%^ return-static-data-on-duct 400 'text/html'
|
||||
(error-page 400 & url.request (trip p.maybe-requests))
|
||||
:: while weird, the request list could be empty
|
||||
::
|
||||
?: =(~ p.maybe-requests)
|
||||
%^ return-static-data-on-duct 400 'text/html'
|
||||
(error-page 400 %.y url.request "empty list of actions")
|
||||
:: check for the existence of the channel-id
|
||||
::
|
||||
:: if we have no session, create a new one set to expire in
|
||||
|
@ -306,6 +306,7 @@
|
||||
0xb.130c.ab37.ca24.49cd.aecb.23ba.70f1.6f1c.4d00.124e.c9a5.
|
||||
3413.3843.d81c.47c4.7040.6e62.3700.0200.0132.e1ab.9000
|
||||
==
|
||||
:- ~[/ames] [%pass /pump/~bud/0 %b %wait ~1111.1.5..00.02.00]
|
||||
==
|
||||
==
|
||||
:: publisher ames hears %kick ack
|
||||
|
@ -262,7 +262,7 @@
|
||||
==
|
||||
::
|
||||
++ ex-channel-response
|
||||
|= body=@t
|
||||
|= body=(unit @t)
|
||||
|= mov=move
|
||||
^- tang
|
||||
?. ?=([[[%http-blah ~] ~] %give %response %start * * %.n] mov)
|
||||
@ -273,7 +273,7 @@
|
||||
['connection' 'keep-alive']
|
||||
['set-cookie' cookie-string]
|
||||
==
|
||||
=/ body `(as-octs:mimes:html body)
|
||||
=/ body (bind body as-octs:mimes:html)
|
||||
;: weld
|
||||
(expect-eq !>(200) !>(status-code.response-header.http-event.p.card.mov))
|
||||
(expect-eq !>(body) !>(data.http-event.p.card.mov))
|
||||
@ -375,6 +375,7 @@
|
||||
|= [gang pov=path =view =beam]
|
||||
^- (unit (unit cage))
|
||||
?: =(%gd view) ``noun+!>(%base)
|
||||
?: =(%gu view) ``noun+!>(=(%app1 q.beam))
|
||||
?: &(=(%ca view) =(/gen/handler/hoon s.beam))
|
||||
:+ ~ ~
|
||||
vase+!>(!>(|=(* |=(* [[%404 ~] ~]))))
|
||||
@ -553,6 +554,21 @@
|
||||
(take /watch-response/[eyre-id] ~[/http-blah] sign)
|
||||
=/ headers ['content-type' 'text/html']~
|
||||
(expect-moves mos (ex-continue-response `[3 'ya!'] %.n) ~)
|
||||
::
|
||||
++ test-dead-app-request
|
||||
%- eval-mare
|
||||
=/ m (mare ,~)
|
||||
;< ~ bind:m perform-init-wo-timer
|
||||
;< ~ bind:m (wait ~d1)
|
||||
:: dead-app binds successfully
|
||||
::
|
||||
;< ~ bind:m (connect %dead-app /)
|
||||
;< ~ bind:m (wait ~d1)
|
||||
:: outside requests a path that dead-app has bound to
|
||||
::
|
||||
;< mos=(list move) bind:m (get '/' ~)
|
||||
=/ body `(error-page:eyre-gate 503 %.n '/' "%dead-app not running")
|
||||
(expect-moves mos (ex-response 503 ['content-type' 'text/html']~ body) ~)
|
||||
:: tests an app redirecting to the login handler, which then receives a post
|
||||
:: and redirects back to app
|
||||
::
|
||||
@ -727,6 +743,32 @@
|
||||
=/ wire /channel/subscription/'0123456789abcdef'/1/~nul/two/~nul
|
||||
(expect-moves mos (ex-gall-deal wire ~nul %two %leave ~) ~)
|
||||
::
|
||||
++ test-channel-open-with-get
|
||||
%- eval-mare
|
||||
=/ m (mare ,~)
|
||||
;< ~ bind:m perform-init-wo-timer
|
||||
;< ~ bind:m perform-born
|
||||
;< ~ bind:m (wait ~d1)
|
||||
;< ~ bind:m perform-authentication-2
|
||||
;< mos=(list move) bind:m
|
||||
(get '/~/channel/0123456789abcdef' cookie)
|
||||
;< now=@da bind:m get-now
|
||||
=/ mov-1 (ex-wait /channel/heartbeat/'0123456789abcdef' (add now ~s20))
|
||||
=/ mov-2 (ex-channel-response ~)
|
||||
(expect-moves mos mov-1 mov-2 ~)
|
||||
::
|
||||
++ test-channel-put-zero-requests
|
||||
%- eval-mare
|
||||
=/ m (mare ,~)
|
||||
;< ~ bind:m perform-init-start-channel-2
|
||||
;< ~ bind:m (wait ~m1)
|
||||
;< mos=(list move) bind:m
|
||||
(put '/~/channel/0123456789abcdef' cookie '[]')
|
||||
=/ mov-1 ex-204
|
||||
=/ mov-2 (ex-rest /channel/timeout/'0123456789abcdef' ~1111.1.2..12.00.00)
|
||||
=/ mov-3 (ex-wait /channel/timeout/'0123456789abcdef' ~1111.1.2..12.01.00)
|
||||
(expect-moves mos mov-1 mov-2 mov-3 ~)
|
||||
::
|
||||
++ test-channel-results-before-open
|
||||
%- eval-mare
|
||||
=/ m (mare ,~)
|
||||
@ -760,7 +802,7 @@
|
||||
;< now=@da bind:m get-now
|
||||
=/ mov-1 (ex-wait /channel/heartbeat/'0123456789abcdef' (add now ~s20))
|
||||
=/ mov-2
|
||||
%- ex-channel-response
|
||||
%+ ex-channel-response ~
|
||||
'''
|
||||
id: 0
|
||||
data: {"ok":"ok","id":0,"response":"poke"}
|
||||
@ -904,7 +946,7 @@
|
||||
;< now=@da bind:m get-now
|
||||
=/ mov-1 (ex-wait /channel/heartbeat/'0123456789abcdef' (add now ~s20))
|
||||
=/ mov-2
|
||||
%- ex-channel-response
|
||||
%+ ex-channel-response ~
|
||||
'''
|
||||
id: 0
|
||||
data: {"ok":"ok","id":0,"response":"poke"}
|
||||
@ -1006,7 +1048,7 @@
|
||||
=/ heartbeat (add now ~s20)
|
||||
=/ mov-1 (ex-wait /channel/heartbeat/'0123456789abcdef' heartbeat)
|
||||
=/ mov-2
|
||||
%- ex-channel-response
|
||||
%+ ex-channel-response ~
|
||||
'''
|
||||
id: 0
|
||||
data: {"ok":"ok","id":0,"response":"poke"}
|
||||
@ -1076,7 +1118,7 @@
|
||||
=/ heartbeat (add now ~s20)
|
||||
=/ mov-1 (ex-wait /channel/heartbeat/'0123456789abcdef' heartbeat)
|
||||
=/ mov-2
|
||||
%- ex-channel-response
|
||||
%+ ex-channel-response ~
|
||||
'''
|
||||
id: 2
|
||||
data: {"json":[1],"id":1,"response":"diff"}
|
||||
|
Loading…
Reference in New Issue
Block a user