urbit/pkg/arvo/app/dns-collector.hoon

155 lines
3.8 KiB
Plaintext
Raw Normal View History

2019-11-06 06:55:51 +03:00
/- dns
2019-11-26 08:30:41 +03:00
/+ default-agent, verb
2019-11-06 06:55:51 +03:00
::
:: app types and boilerplate
::
=> |%
2019-11-19 07:36:21 +03:00
+$ card card:agent:gall
2019-11-06 06:55:51 +03:00
+$ app-state
$: %0
requested=(map ship address:dns)
completed=(map ship binding:dns)
==
+$ peek-data
$% [%requested (list (pair ship address:dns))]
[%completed (list (pair ship binding:dns))]
==
+$ in-poke-data
$% [%dns-address =address:dns]
[%dns-complete =ship =binding:dns]
[%noun noun=*]
==
+$ out-peer-data
$% [%dns-binding =binding:dns]
[%dns-request =request:dns]
==
--
|%
++ give-result
|= [=the=path =cage]
^- card
[%give %fact ~[the-path] cage]
2019-11-06 06:55:51 +03:00
--
::
2019-11-19 07:36:21 +03:00
^- agent:gall
2019-11-06 06:55:51 +03:00
=| state=app-state
2019-11-26 08:30:41 +03:00
%+ verb |
2019-11-19 07:36:21 +03:00
|_ =bowl:gall
2019-11-06 06:55:51 +03:00
+* this .
def ~(. (default-agent this %|) bowl)
2019-11-06 06:55:51 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-init on-init:def
++ on-save !>(state)
++ on-load
2019-11-06 06:55:51 +03:00
|= old=vase
`this(state !<(app-state old))
::
2019-11-07 09:19:32 +03:00
++ on-poke
2019-11-06 06:55:51 +03:00
|= [=mark =vase]
^- (quip card _this)
|^
2019-11-07 09:19:32 +03:00
?+ mark (on-poke:def mark vase)
2019-11-06 06:55:51 +03:00
%noun (handle-noun !<(noun vase))
%dns-address (handle-dns-address !<(address:dns vase))
%dns-complete (handle-dns-complete !<([ship binding:dns] vase))
==
::
++ handle-noun
|= noun=*
^- (quip card _this)
?: ?=(%debug noun)
~& bowl=bowl
~& state=state
`this
::
~& %poke-unknown
`this
::
++ handle-dns-address
|= adr=address:dns
^- (quip card _this)
=* who src.bowl
=/ rac (clan:title who)
?. ?=(?(%king %duke) rac)
~| [%dns-collector-bind-invalid who] !!
?: (reserved:eyre if.adr)
~| [%dns-collector-reserved-address who if.adr] !!
::
=/ req=(unit address:dns) (~(get by requested.state) who)
=/ dun=(unit binding:dns) (~(get by completed.state) who)
?: &(?=(^ dun) =(adr address.u.dun))
=. requested.state (~(del by requested.state) who)
:_ this :_ ~
(give-result /(scot %p who) %dns-binding !>(u.dun))
::
?: &(?=(^ req) =(adr u.req))
`this
:: XX check address?
=/ =request:dns [who adr]
=. requested.state (~(put by requested.state) request)
:_ this :_ ~
(give-result /requests %dns-request !>(request))
::
++ handle-dns-complete
|= [who=ship =binding:dns]
^- (quip card _this)
:: XX or confirm valid binding?
::
?. (team:title [our src]:bowl)
~| %complete-yoself !!
=* adr address.binding
=* tuf turf.binding
=/ req=(unit address:dns) (~(get by requested.state) who)
:: ignore established bindings that don't match requested
::
?: ?| ?=(~ req)
!=(adr u.req)
==
~& %unknown-complete
`this
=: requested.state (~(del by requested.state) who)
completed.state (~(put by completed.state) who [adr tuf])
==
:_ this :_ ~
(give-result /(scot %p who) %dns-binding !>([adr tuf]))
--
::
2019-11-07 09:19:32 +03:00
++ on-watch
2019-11-06 06:55:51 +03:00
|= =path
^- (quip card _this)
?: ?=([%sole *] path)
!!
2019-11-06 06:55:51 +03:00
?. ?=([@ ~] path)
~| %invalid-path !!
?: ?=(%requests i.path)
=/ requests ~(tap by requested.state)
|- ^- (quip card _this)
=* loop $
?~ requests
`this
=/ card (give-result path %dns-request !>(i.requests))
=^ cards this loop(requests t.requests)
[[card cards] this]
::
=/ who=(unit @p) (slaw %p i.path)
?~ who
~| %invalid-path !!
?~ dun=(~(get by completed.state) u.who)
`this
:_ this :_ ~
(give-result path %dns-binding !>(u.dun))
::
2019-11-07 09:19:32 +03:00
++ on-leave on-leave:def
++ on-peek
2019-11-06 06:55:51 +03:00
|= =path
^- (unit (unit cage))
?+ path [~ ~]
[%x %requested ~] [~ ~ %requested !>(~(tap by requested.state))]
[%x %completed ~] [~ ~ %completed !>(~(tap by completed.state))]
==
::
2019-11-07 09:19:32 +03:00
++ on-agent on-agent:def
++ on-arvo on-arvo:def
++ on-fail on-fail:def
2019-11-06 06:55:51 +03:00
--