shrub/pkg/arvo/app/ping.hoon

96 lines
2.6 KiB
Plaintext
Raw Normal View History

2019-12-01 01:45:21 +03:00
:: To traverse NAT, we need the response to come back from someone
:: we've sent a message to. We ping our sponsor so that they know
:: where we are. However, we also need to ping our galaxy because if
:: the other ship tries to respond directly, it may be blocked by our
:: firewall or NAT. Thus, the response must come from a ship we've
:: messaged direclty, and the only one we can guarantee is our galaxy.
:: Note this issue manifests itself even for bootstrapping a planet to
:: talk to its own star.
::
/+ default-agent
2019-08-10 04:24:47 +03:00
=* point point:able:kale
::
=> |%
+$ card card:agent:gall
2019-08-10 04:24:47 +03:00
:: +print-error: maybe +slog
::
++ print-error
|= [=tape error=(unit tang)]
^+ same
?~ error same
%- (slog leaf+tape u.error) same
:: +set-timer: send a card to behn to set a timer
::
++ set-timer
2019-12-01 01:45:21 +03:00
|= [now=@da n=@ud]
^- (list card)
2019-12-01 01:45:21 +03:00
[%pass /ping-wait/(scot %ud n) %arvo %b %wait `@da`(add ~s30 now)]~
:: +send-ping: scry our sponsor from jael and poke their %ping app
::
++ send-ping
2019-12-01 01:45:21 +03:00
|= [our=@p now=@da n=@ud]
^- (list card)
::
2019-12-01 01:45:21 +03:00
=/ sponsor=ship (snag n (saxo:title our now our))
::
~> %slog.0^leaf/"ping: {<our>} -> {<sponsor>}"
2019-12-01 01:45:21 +03:00
[%pass /ping-send/(scot %ud n) %agent [sponsor %ping] %poke %noun !>(~)]~
2019-08-10 04:24:47 +03:00
--
^- agent:gall
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
2019-08-10 04:24:47 +03:00
::
:: +on-init: initializing on startup
2019-08-10 04:24:47 +03:00
::
++ on-init
^- [(list card) _this]
2019-08-10 04:24:47 +03:00
:: first load; galaxies no-op; everyone else pings sponsor
::
:_ this
2019-08-14 03:56:37 +03:00
~> %slog.0^leaf/"ping: prep {<our.bowl>}"
2019-12-01 01:45:21 +03:00
=/ saxo (tail (saxo:title our.bowl now.bowl our.bowl))
%- zing
%+ turn (gulf 1 (lent saxo))
|= n=@ud
(send-ping our.bowl now.bowl n)
2019-08-10 04:24:47 +03:00
::
++ on-save on-save:def
2019-12-01 01:45:21 +03:00
++ on-load :: on-load:def
|= vase
on-init
:: +on-poke: positively acknowledge pokes
2019-08-10 04:24:47 +03:00
::
++ on-poke
|= [=mark =vase]
`this
2019-08-10 04:24:47 +03:00
::
++ on-watch on-watch:def
++ on-leave on-leave:def
++ on-peek on-peek:def
:: +on-agent: handle ames ack
2019-08-10 04:24:47 +03:00
::
++ on-agent
|= [=wire =sign:agent:gall]
^- [(list card) _this]
2019-12-01 01:45:21 +03:00
?> ?=([%ping-send @ ~] wire)
?> ?=(%poke-ack -.sign)
:_ this
2019-08-10 04:24:47 +03:00
::
%- (print-error "ping: ack" p.sign)
2019-12-01 01:45:21 +03:00
(set-timer now.bowl (slav %ud i.t.wire))
:: +on-arvo: handle timer firing
2019-08-10 04:24:47 +03:00
::
++ on-arvo
|= [=wire =sign-arvo]
^- [(list card) _this]
2019-12-01 01:45:21 +03:00
?> ?=([%ping-wait @ ~] wire)
?> ?=(%wake +<.sign-arvo)
:_ this
~! error.sign-arvo
%- (print-error "ping: wake" error.sign-arvo)
2019-12-01 01:45:21 +03:00
(send-ping our.bowl now.bowl (slav %ud i.t.wire))
::
++ on-fail on-fail:def
2019-08-10 04:24:47 +03:00
--