urbit/main/app/rodeo/core.hook

500 lines
17 KiB
Plaintext
Raw Normal View History

2014-12-06 01:54:11 +03:00
::
:::: /hook/core/rodeo/app
::
/? 314
/- *radio
::
::::
::
!:
=> |% :: data structures
++ house ,[%0 house-0] :: full state
++ house-any :: app history
$% [%0 house-0] :: 0: initial version
== ::
2014-12-06 01:54:11 +03:00
++ house-0 ::
$: parties=(map span party) :: conversations
2014-12-09 22:04:09 +03:00
general=(set bone) :: meta-subscribe
outbox=(pair ,@ud (map ,@ud thought)) :: urbit outbox
2014-12-06 01:54:11 +03:00
== ::
++ party :: a conversation
$: count=@ud :: (lent grams)
grams=(list telegram) :: all history
present=(map ship status) :: presence state
sequence=(map station ,@ud) :: stations heard
shape=config :: configuration
known=(map serial ,@ud) :: messages heard
2014-12-09 22:04:09 +03:00
guests=(map bone river) :: message followers
viewers=(set bone) :: presence followers
owners=(set bone) :: config followers
== ::
++ river (pair point point) :: stream definition
++ point :: stream endpoint
$% [%ud p=@ud] :: by number
[%da p=@da] :: by date
2014-12-06 01:54:11 +03:00
== ::
++ gift :: result
$% [%rush report] :: update
[%rust report] :: refresh
[%mean ares] :: cancel
[%nice ~] :: accept
== ::
++ sign :: response
$? $: %g :: application
$% [%mean p=ares] :: cancel
[%nice ~] :: acknowledge
2014-12-09 22:04:09 +03:00
[%rush p=report] :: update
[%rust p=report] :: refresh
2014-12-06 01:54:11 +03:00
== == == ::
++ move ,[p=bone q=(mold note gift)] :: all actions
++ hapt ,[p=ship q=path] :: app instance
++ note :: requests
$? $: %g :: network
$% [%mess p=hapt q=ship r=cage] :: message
[%nuke p=hapt q=ship] :: cancel
[%show p=hapt q=ship r=path] :: subscribe
== == == ::
--
|_ [hid=hide house]
2014-12-06 01:54:11 +03:00
++ ra :: transaction core
|_ [ost=bone moves=(list move)]
++ ra-abet :: resolve core
^- [(list move) _+>]
[(flop moves) +>]
2014-12-06 01:54:11 +03:00
::
++ ra-emil :: ra-emit move list
2014-12-06 01:54:11 +03:00
|= mol=(list move)
%_(+> moves (welp (flop mol) moves))
::
++ ra-emit :: emit a move
2014-12-06 01:54:11 +03:00
|= mov=move
%_(+> moves [mov moves])
::
++ ra-ever :: emit success
(ra-emit ost %give %nice ~)
2014-12-06 01:54:11 +03:00
::
++ ra-evil :: emit error
|= msg=cord
(ra-emit ost %give %mean ~ msg ~)
2014-12-06 01:54:11 +03:00
::
2014-12-09 22:04:09 +03:00
++ ra-house :: emit stations
%+ ra-emit ost
:^ %give %rust %house
%- ~(gas in *(set span))
^- (list span)
(turn (~(tap by parties) ~) |=([a=span *] a))
::
++ ra-homes :: update stations
=+ gel=general
|- ^+ +>
?~ gel +>
=. +> $(gel l.gel)
=. +> $(gel r.gel)
ra-house(ost n.gel)
::
++ ra-apply :: apply command
|= [her=ship cod=command]
2014-12-06 01:54:11 +03:00
^+ +>
?- -.cod
%design
?. =(her our.hid)
(ra-evil %radio-no-owner)
2014-12-06 01:54:11 +03:00
=+ pur=(~(get by parties) p.cod)
?~ q.cod
?~ pur
(ra-evil %radio-no-party)
2014-12-09 22:04:09 +03:00
=. +>.$ pa-abet:(~(pa-reform pa p.cod u.pur) *config)
=. +>.$ ra-homes
ra-ever(parties (~(del by parties) p.cod))
=+ poy=`(pair ,? party)`?~(pur [| *party] [& u.pur])
=. +>.$ pa-abet:(~(pa-reform pa p.cod q.poy) u.q.cod)
=. +>.$ ?:(p.poy +>.$ ra-homes)
ra-ever
2014-12-06 01:54:11 +03:00
::
%review ra-ever:(ra-think | her +.cod)
%publish ra-ever:(ra-think & her +.cod)
2014-12-06 01:54:11 +03:00
%ping
=+ pur=(~(get by parties) p.cod)
?~ pur
(ra-evil %radio-no-party)
=< ra-ever =< pa-abet
2014-12-09 22:04:09 +03:00
(~(pa-notify pa p.cod u.pur) her q.cod)
==
::
++ ra-friend :: %friend response
|= [man=span sih=sign]
^+ +>
=+ pur=(~(get by parties) man)
?~ pur ~& [%ra-friend-none man] +>.$
pa-abet:(~(pa-friend pa man u.pur) sih)
::
++ ra-repeat :: %repeat response
|= [num=@ud her=ship man=span sih=sign]
=+ oot=(~(get by q.outbox) num)
?~ oot ~& [%ra-repeat-none num] +>.$
=. q.outbox (~(del by q.outbox) num)
=. q.u.oot
%+ ~(put by q.u.oot)
[%& her man]
?+ sih !!
[%g %mean *] ~&([%radio-repeat-rejected num her man sih] %rejected)
[%g %nice ~] %received
==
(ra-think | her u.oot ~)
::
++ ra-cancel :: drop a bone
%_ .
general (~(del in general) ost)
parties
|- ^- (map span party)
?~ parties ~
:- :- p.n.parties
%= q.n.parties
guests (~(del by guests.q.n.parties) ost)
viewers (~(del in viewers.q.n.parties) ost)
owners (~(del in owners.q.n.parties) ost)
==
[$(parties l.parties) $(parties r.parties)]
2014-12-06 01:54:11 +03:00
==
::
++ ra-subscribe :: listen to
|= [her=ship pax=path]
2014-12-06 01:54:11 +03:00
^+ +>
2014-12-09 22:04:09 +03:00
~& [%ra-subscribe pax]
2014-12-10 00:59:08 +03:00
?: ?=(~ pax)
ra-house(general (~(put in general) ost))
2014-12-09 22:04:09 +03:00
?: ?=([%am @ ~] pax)
=+ pur=(~(get by parties) i.t.pax)
?~ pur
~& [%bad-subscribe-party i.t.pax]
(ra-evil %radio-no-party)
pa-abet:(~(pa-watch pa i.t.pax u.pur) her)
?: ?=([%xm @ ~] pax)
=+ pur=(~(get by parties) i.t.pax)
?~ pur
~& [%bad-subscribe-party i.t.pax]
(ra-evil %radio-no-party)
pa-abet:(~(pa-master pa i.t.pax u.pur) her)
?. ?=([%fm *] pax)
~& [%bad-subscribe pax]
(ra-evil %radio-bad-path)
?. &(?=([@ *] t.pax) ((sane %tas) i.t.pax))
2014-12-06 01:54:11 +03:00
~& [%bad-subscribe pax]
(ra-evil %radio-bad-path)
2014-12-06 01:54:11 +03:00
=+ pur=(~(get by parties) i.t.pax)
?~ pur
~& [%bad-subscribe-party i.t.pax]
(ra-evil %radio-no-party)
2014-12-09 22:04:09 +03:00
pa-abet:(~(pa-listen pa i.t.pax u.pur) her t.t.pax)
2014-12-06 01:54:11 +03:00
::
++ ra-think :: publish/review
2014-12-06 01:54:11 +03:00
|= [pub=? her=ship tiz=(list thought)]
^+ +>
?~ tiz +>
$(tiz t.tiz, +> (ra-consume pub her i.tiz))
2014-12-06 01:54:11 +03:00
::
++ ra-consume :: consume thought
2014-12-06 01:54:11 +03:00
|= [pub=? her=ship tip=thought]
=+ aud=`(list (pair station delivery))`(~(tap by q.tip) ~)
2014-12-06 01:54:11 +03:00
|- ^+ +>.^$
?~ aud +>.^$
$(aud t.aud, +>.^$ (ra-conduct pub her p.i.aud tip))
2014-12-06 01:54:11 +03:00
::
++ ra-conduct :: thought to station
2014-12-06 01:54:11 +03:00
|= [pub=? her=ship tay=station tip=thought]
^+ +>
?- -.tay
%& ?: pub
=. her our.hid :: XX security!
?: =(her p.p.tay)
(ra-record q.p.tay p.p.tay tip)
(ra-transmit p.tay tip)
?: =(our.hid q.p.tay)
2014-12-06 01:54:11 +03:00
+>
(ra-record q.p.tay p.p.tay tip)
2014-12-06 01:54:11 +03:00
%| ?. pub +>
~& [%conduct-twitters]
!!
==
::
++ ra-record :: add to party
2014-12-06 01:54:11 +03:00
|= [man=span gam=telegram]
^+ +>
=+ pur=(~(get by parties) man)
?~ pur
~& [%no-party man]
+>.$
2014-12-09 22:04:09 +03:00
pa-abet:(~(pa-learn pa man u.pur) gam)
2014-12-06 01:54:11 +03:00
::
++ ra-transmit :: send to neighbor
2014-12-06 01:54:11 +03:00
|= [cuz=cousin tip=thought]
^+ +>
=. +>
%+ ra-emit ost
:* %pass
2014-12-09 22:04:09 +03:00
/repeat/(scot %ud p.outbox)/(scot %p p.cuz)/[q.cuz]
%g
%mess
[p.cuz /rodeo]
our.hid
[%command !>(`command`[%review tip ~])]
==
+>(p.outbox +(p.outbox), q.outbox (~(put by q.outbox) p.outbox tip))
2014-12-06 01:54:11 +03:00
::
++ pa :: party core
|_ $: man=span
party
==
++ pa-abet
2014-12-06 01:54:11 +03:00
^+ +>
+>(parties (~(put by parties) man `party`+<+))
2014-12-06 01:54:11 +03:00
::
2014-12-09 22:04:09 +03:00
++ pa-admire :: accept from
2014-12-06 01:54:11 +03:00
|= her=ship
^- ?
?- -.cordon.shape
%& (~(has in p.cordon.shape) her)
%| !(~(has in p.cordon.shape) her)
2014-12-06 01:54:11 +03:00
==
::
2014-12-09 22:04:09 +03:00
++ pa-watch :: watch presence
|= her=ship
?. (pa-admire her)
(pa-sauce [[%mean ~ %radio-watch-unauthorized ~] ~])
=. viewers (~(put in viewers) ost)
(pa-sauce [[%rust %group present] ~])
::
2014-12-09 22:04:09 +03:00
++ pa-master :: hear config
|= her=ship
?. (pa-admire her)
(pa-sauce [[%mean ~ %radio-master-unauthorized ~] ~])
=. owners (~(put in owners) ost)
(pa-sauce [[%rust %config shape] ~])
::
++ pa-display :: update presence
=+ vew=viewers
|- ^+ +>
?~ vew +>
=. +> $(vew l.vew)
=. +> $(vew r.vew)
(pa-sauce(ost n.vew) [[%rust %group present] ~])
::
::
++ pa-monitor :: update config
=+ owe=owners
|- ^+ +>
?~ owe +>
=. +> $(owe l.owe)
=. +> $(owe r.owe)
(pa-sauce(ost n.owe) [[%rust %config shape] ~])
::
++ pa-friend :: subscribed update
|= sih=sign
2014-12-06 01:54:11 +03:00
^+ +>
2014-12-09 22:04:09 +03:00
?. ?=([%g %rust *] sih)
~& [%radio-bad-friend sih]
!!
?+ -.+>.sih ~&([%radio-odd-friend sih] !!)
%grams
(pa-lesson q.+.+>.sih)
==
2014-12-06 01:54:11 +03:00
::
2014-12-09 22:04:09 +03:00
++ pa-scrub :: pass forward
|= bub=(list (pair path note))
%_ +>.$
moves
(welp (flop (turn bub |=(a=(pair path note) [ost %pass a]))) moves)
==
::
++ pa-sauce :: send backward
|= gub=(list gift)
%_ +>.$
moves
(welp (flop (turn gub |=(a=gift [ost %give a]))) moves)
==
::
2014-12-09 22:04:09 +03:00
++ pa-abjure :: unsubscribe move
|= tal=(list station)
%- pa-scrub %+ turn tal
2014-12-06 01:54:11 +03:00
|= tay=station
?- -.tay
2014-12-09 22:04:09 +03:00
%| !!
%& :- /friend/nuke/[man]
[%g %nuke [p.p.tay /rodeo] our.hid]
2014-12-06 01:54:11 +03:00
==
::
2014-12-09 22:04:09 +03:00
++ pa-acquire :: subscribe to
|= tal=(list station)
%- pa-scrub %+ turn tal
|= tay=station
=+ num=(fall (~(get by sequence) tay) 0)
?- -.tay
%| !!
%& :- /friend/show/[man]
[%g %show [p.p.tay /rodeo] our.hid /fm/(scot %ud num)]
==
::
2014-12-09 22:04:09 +03:00
++ pa-reform :: reconfigure, ugly
2014-12-06 01:54:11 +03:00
|= cof=config
2014-12-09 22:04:09 +03:00
=+ ^= dif ^- (pair (list station) (list station))
=+ old=`(list station)`(~(tap in sources.shape) ~)
=+ new=`(list station)`(~(tap in sources.cof) ~)
:- (skip new |=(a=station (~(has in sources.shape) a)))
(skip old |=(a=station (~(has in sources.cof) a)))
2014-12-09 22:04:09 +03:00
=. +>.$ (pa-acquire(ost 0) p.dif)
=. +>.$ (pa-abjure(ost 0) q.dif)
pa-monitor
2014-12-06 01:54:11 +03:00
::
2014-12-09 22:04:09 +03:00
++ pa-cancel :: unsubscribe from
^+ .
2014-12-06 01:54:11 +03:00
=. guests (~(del in guests) ost)
2014-12-09 22:04:09 +03:00
(pa-sauce [[%mean ~] ~])
2014-12-06 01:54:11 +03:00
::
2014-12-09 22:04:09 +03:00
++ pa-notify :: new presence
|= [her=ship per=presence]
^+ +>
2014-12-09 22:04:09 +03:00
pa-display(present (~(put by present) her [per lat.hid *human]))
::
2014-12-09 22:04:09 +03:00
++ pa-start :: start stream
|= riv=river
^+ +>
2014-12-09 22:04:09 +03:00
=- =. +>.$ (pa-sauce [[%rust %grams q.lab r.lab] ~])
?: p.lab
+>.$(guests (~(put by guests) ost riv))
(pa-sauce [[%mean ~] ~])
^= lab
=+ [end=count gaz=grams dun=| zeg=*(list telegram)]
|- ^- (trel ,? ,@ud (list telegram))
?~ gaz [dun end (flop zeg)]
?: ?- -.q.riv :: after the end
%ud (lte end p.q.riv)
%da (lte p.r.q.i.gaz p.q.riv)
==
$(end (dec end), gaz t.gaz)
?: ?- -.p.riv :: before the start
%ud (lth p.p.riv end)
%da (lth p.p.riv p.r.q.i.gaz)
==
[dun end (flop zeg)]
$(end (dec end), gaz t.gaz, zeg [i.gaz zeg])
2014-12-06 01:54:11 +03:00
::
2014-12-09 22:04:09 +03:00
++ pa-listen :: subscribe
|= [her=ship pax=path]
2014-12-06 01:54:11 +03:00
^+ +>
2014-12-09 22:04:09 +03:00
?. (pa-admire her)
(pa-sauce [[%mean ~ %radio-listen-unauthorized ~] ~])
=+ ^= ruv ^- (unit river)
?: ?=(~ pax)
`[[%ud count] [%da (dec (bex 128))]]
?: ?=([@ ~] pax)
=+ say=(slay i.pax)
?. ?=([~ %$ ?(%ud %da) @] say) ~
`[(point +>.say) [%da (dec (bex 128))]]
?. ?=([@ @ ~] pax) ~
=+ [say=(slay i.pax) den=(slay i.t.pax)]
?. ?=([~ %$ ?(%ud %da) @] say) ~
?. ?=([~ %$ ?(%ud %da) @] den) ~
`[(point +>.say) (point +>.den)]
?~ ruv
(pa-sauce [[%mean ~ %radio-malformed ~] ~])
(pa-start u.ruv)
::
++ pa-refresh :: update stream
|= [num=@ud gam=telegram]
=+ ^= moy
|- ^- (pair (list bone) (list move))
?~ guests [~ ~]
=+ lef=$(guests l.guests)
=+ rit=$(guests r.guests)
=+ old=[p=(welp p.lef p.rit) q=(welp q.lef q.rit)]
?: ?- -.q.q.n.guests :: after the end
%ud (lte num p.q.q.n.guests)
%da (lte p.r.q.gam p.q.q.n.guests)
==
[[p.n.guests p.old] [`move`[p.n.guests %give %mean ~] q.old]]
?: ?- -.p.q.n.guests :: before the start
%ud (lth p.p.q.n.guests num)
%da (lth p.p.q.n.guests p.r.q.gam)
==
old
[p.old [[p.n.guests %give %rust %grams num gam ~] q.old]]
=. moves (welp q.moy moves)
2014-12-06 01:54:11 +03:00
|- ^+ +>.^$
2014-12-09 22:04:09 +03:00
?~ p.moy +>.^$
$(p.moy t.p.moy, guests (~(del by guests) i.p.moy))
2014-12-06 01:54:11 +03:00
::
2014-12-09 22:04:09 +03:00
++ pa-lesson :: learn multiple
|= gaz=(list telegram)
^+ +>
?~ gaz +>
$(gaz t.gaz, +> (pa-learn i.gaz))
::
++ pa-learn :: learn message
2014-12-06 01:54:11 +03:00
|= gam=telegram
^+ +>
2014-12-09 22:04:09 +03:00
?. (pa-admire p.gam)
~& %pa-admire-rejected
2014-12-06 01:54:11 +03:00
+>.$
=+ old=(~(get by known) p.q.gam)
?~ old
2014-12-09 22:04:09 +03:00
(pa-append gam)
(pa-revise u.old gam)
2014-12-06 01:54:11 +03:00
::
2014-12-09 22:04:09 +03:00
++ pa-append :: append new
2014-12-06 01:54:11 +03:00
|= gam=telegram
^+ +>
2014-12-09 22:04:09 +03:00
%+ pa-refresh(count +(count), known (~(put by known) p.q.gam count))
count
gam
2014-12-06 01:54:11 +03:00
::
2014-12-09 22:04:09 +03:00
++ pa-revise :: revise existing
2014-12-06 01:54:11 +03:00
|= [num=@ud gam=telegram]
=+ way=(sub count num)
2014-12-09 22:04:09 +03:00
=. grams (welp (scag (dec way) grams) [gam (slag way grams)])
(pa-refresh num gam)
2014-12-06 01:54:11 +03:00
--
--
++ peer
|= [ost=bone her=ship pax=path]
^- [(list move) _+>]
ra-abet:(~(ra-subscribe ra ost ~) her pax)
2014-12-06 01:54:11 +03:00
::
++ poke-command
|= [ost=bone her=ship cod=command]
^- [(list move) _+>]
~& [%rodeo-poke-command her cod]
ra-abet:(~(ra-apply ra ost ~) her cod)
2014-12-06 01:54:11 +03:00
::
++ pour
|= [ost=bone pax=path sih=*]
^- [(list move) _+>]
2014-12-09 22:04:09 +03:00
~& [%rodeo-pour ost pax]
2014-12-06 01:54:11 +03:00
:: ~& sih=sih
=+ sih=((hard sign) sih)
2014-12-09 22:04:09 +03:00
?+ pax ~& [%rodeo-strange-path pax] !!
[%friend *]
?> ?=([@ @ @ ~] t.pax)
?. =(%show i.t.pax)
~& [%pour-friend-nuke-nuke pax]
[~ +>.$]
ra-abet:(~(ra-friend ra ost ~) i.t.t.pax sih)
::
[%repeat *]
?> ?=([@ @ @ ~] t.pax)
=+ [num her man]=[(slav %ud i.t.pax) (slav %p i.t.t.pax) i.t.t.t.pax]
ra-abet:(~(ra-repeat ra ost ~) num her man sih)
==
::
++ prep
|= old=(unit (unit house))
^- [(list move) _+>]
~& %rodeo-prep
2014-12-10 00:59:08 +03:00
[~ +>]
2014-12-06 01:54:11 +03:00
::
++ pull
|= ost=bone
^- [(list move) _+>]
~& [%pull ost]
2014-12-09 22:04:09 +03:00
ra-abet:~(ra-cancel ra ost ~)
2014-12-06 01:54:11 +03:00
--