mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-11-10 10:05:09 +03:00
Merge branch 'pr' into philip/tomb
This commit is contained in:
commit
2e31f87068
@ -1440,25 +1440,27 @@
|
||||
event-core
|
||||
::
|
||||
=/ =open-packet (decode-open-packet packet our life.ames-state)
|
||||
:: store comet as peer in our state
|
||||
:: add comet as an %alien if we haven't already
|
||||
::
|
||||
=? peers.ames-state ?=(~ ship-state)
|
||||
(~(put by peers.ames-state) sndr.packet %alien *alien-agenda)
|
||||
:: upgrade comet to %known via on-publ-full
|
||||
::
|
||||
=. event-core
|
||||
=/ crypto-suite=@ud 1
|
||||
=/ =point
|
||||
:* ^= rift 0
|
||||
^= life sndr-life.open-packet
|
||||
^= keys (my [sndr-life.open-packet crypto-suite public-key.open-packet]~)
|
||||
^= sponsor `(^sein:title sndr.packet)
|
||||
==
|
||||
(on-publ / [%full (my [sndr.packet point]~)])
|
||||
:: manually add the lane to the peer state
|
||||
::
|
||||
=. peers.ames-state
|
||||
%+ ~(put by peers.ames-state) sndr.packet
|
||||
^- ^ship-state
|
||||
:- %known
|
||||
=| =peer-state
|
||||
=/ our-private-key sec:ex:crypto-core.ames-state
|
||||
=/ =symmetric-key
|
||||
(derive-symmetric-key public-key.open-packet our-private-key)
|
||||
::
|
||||
%_ peer-state
|
||||
qos [%unborn now]
|
||||
symmetric-key symmetric-key
|
||||
life sndr-life.open-packet
|
||||
public-key public-key.open-packet
|
||||
sponsor (^sein:title sndr.packet)
|
||||
route `[direct=%.n lane]
|
||||
==
|
||||
=/ =peer-state (gut-peer-state sndr.packet)
|
||||
=. route.peer-state `[direct=%.n lane]
|
||||
(~(put by peers.ames-state) sndr.packet %known peer-state)
|
||||
::
|
||||
event-core
|
||||
:: +on-hear-shut: handle receipt of encrypted packet
|
||||
@ -1468,7 +1470,9 @@
|
||||
|= [=lane =packet dud=(unit goof)]
|
||||
^+ event-core
|
||||
=/ sndr-state (~(get by peers.ames-state) sndr.packet)
|
||||
:: if we don't know them, ask jael for their keys and enqueue
|
||||
:: If we don't know them, ask Jael for their keys. On comets, this will
|
||||
:: also cause us to send a self-attestation to the sender. The packet
|
||||
:: itself is dropped; we can assume it will be resent.
|
||||
::
|
||||
?. ?=([~ %known *] sndr-state)
|
||||
(enqueue-alien-todo sndr.packet |=(alien-agenda +<))
|
||||
@ -1577,6 +1581,20 @@
|
||||
|= [=wire error=(unit tang)]
|
||||
^+ event-core
|
||||
::
|
||||
?: ?=([%alien @ ~] wire)
|
||||
:: if we haven't received an attestation, ask again
|
||||
::
|
||||
?^ error
|
||||
%- (slog leaf+"ames: attestation timer failed: {<u.error>}" ~)
|
||||
event-core
|
||||
?~ ship=`(unit @p)`(slaw %p i.t.wire)
|
||||
%- (slog leaf+"ames: got timer for strange wire: {<wire>}" ~)
|
||||
event-core
|
||||
=/ ship-state (~(get by peers.ames-state) u.ship)
|
||||
?: ?=([~ %known *] ship-state)
|
||||
event-core
|
||||
(request-attestation u.ship)
|
||||
::
|
||||
=/ res=(unit [her=ship =bone]) (parse-pump-timer-wire wire)
|
||||
?~ res
|
||||
%- (slog leaf+"ames: got timer for strange wire: {<wire>}" ~)
|
||||
@ -1887,7 +1905,7 @@
|
||||
:: +enqueue-alien-todo: helper to enqueue a pending request
|
||||
::
|
||||
:: Also requests key and life from Jael on first request.
|
||||
:: On a comet, enqueues self-attestation packet on first request.
|
||||
:: If talking to a comet, requests attestation packet.
|
||||
::
|
||||
++ enqueue-alien-todo
|
||||
|= [=ship mutate=$-(alien-agenda alien-agenda)]
|
||||
@ -1904,14 +1922,32 @@
|
||||
::
|
||||
=. todos (mutate todos)
|
||||
=. peers.ames-state (~(put by peers.ames-state) ship %alien todos)
|
||||
:: ask jael for .sndr life and keys on first contact
|
||||
::
|
||||
?: already-pending
|
||||
event-core
|
||||
::
|
||||
?: =(%pawn (clan:title ship))
|
||||
(request-attestation ship)
|
||||
:: NB: we specifically look for this wire in +public-keys-give in
|
||||
:: Jael. if you change it here, you must change it there.
|
||||
::
|
||||
(emit duct %pass /public-keys %j %public-keys [n=ship ~ ~])
|
||||
:: +request-attestation: helper to request attestation from comet
|
||||
::
|
||||
:: Comets will respond to any unknown peer with a self-attestation,
|
||||
:: so we either send a sendkeys packet (a dummy shut packet) or, if
|
||||
:: we're a comet, our own self-attestation, saving a roundtrip.
|
||||
::
|
||||
:: Also sets a timer to resend the request every 30s.
|
||||
::
|
||||
++ request-attestation
|
||||
|= =ship
|
||||
^+ event-core
|
||||
=/ packet ?. =(%pawn (clan:title our))
|
||||
(sendkeys-packet ship)
|
||||
(attestation-packet ship 1)
|
||||
=. event-core (send-blob | ship packet)
|
||||
=/ =wire /alien/(scot %p ship)
|
||||
(emit duct %pass wire %b %wait (add now ~s30))
|
||||
:: +send-blob: fire packet at .ship and maybe sponsors
|
||||
::
|
||||
:: Send to .ship and sponsors until we find a direct lane,
|
||||
@ -1932,6 +1968,8 @@
|
||||
=/ ship-state (~(get by peers.ames-state) ship)
|
||||
::
|
||||
?. ?=([~ %known *] ship-state)
|
||||
?: ?=(%pawn (clan:title ship))
|
||||
(try-next-sponsor (^sein:title ship))
|
||||
%+ enqueue-alien-todo ship
|
||||
|= todos=alien-agenda
|
||||
todos(packets (~(put in packets.todos) blob))
|
||||
@ -1995,6 +2033,23 @@
|
||||
^= rcvr her
|
||||
^= rcvr-life her-life
|
||||
==
|
||||
:: +sendkeys-packet: generate a request for a self-attestation.
|
||||
::
|
||||
:: Sent by non-comets to comets. Not acked.
|
||||
::
|
||||
++ sendkeys-packet
|
||||
|= her=ship
|
||||
^- blob
|
||||
?> ?=(%pawn (clan:title her))
|
||||
%- encode-packet
|
||||
%- encode-shut-packet
|
||||
:* ^= shut-packet *shut-packet
|
||||
^= symmetric-key *symmetric-key
|
||||
^= sndr our
|
||||
^= rcvr her
|
||||
^= sndr-life 0
|
||||
^= rcvr-life 0
|
||||
==
|
||||
:: +get-peer-state: lookup .her state or ~
|
||||
::
|
||||
++ get-peer-state
|
||||
|
@ -3,9 +3,14 @@
|
||||
/= jael /sys/vane/jael
|
||||
:: construct some test fixtures
|
||||
::
|
||||
=/ nec (ames ~nec)
|
||||
=/ bud (ames ~bud)
|
||||
=/ comet (ames ~bosrym-podwyl-magnes-dacrys--pander-hablep-masrym-marbud)
|
||||
=/ nec (ames ~nec)
|
||||
=/ bud (ames ~bud)
|
||||
=/ marbud (ames ~marbud)
|
||||
::
|
||||
=/ our-comet ~bosrym-podwyl-magnes-dacrys--pander-hablep-masrym-marbud
|
||||
=/ our-comet2 ~togdut-rosled-fadlev-siddys--botmun-wictev-sapfus-marbud
|
||||
=/ comet (ames our-comet)
|
||||
=/ comet2 (ames our-comet2)
|
||||
::
|
||||
=. now.nec ~1111.1.1
|
||||
=. eny.nec 0xdead.beef
|
||||
@ -23,8 +28,17 @@
|
||||
=/ bud-pub pub:ex:crypto-core.ames-state.bud
|
||||
=/ bud-sec sec:ex:crypto-core.ames-state.bud
|
||||
::
|
||||
=. now.marbud ~1111.1.1
|
||||
=. eny.marbud 0xbeef.beef
|
||||
=. life.ames-state.marbud 4
|
||||
=. rof.marbud |=(* ``[%noun !>(*(list turf))])
|
||||
=. crypto-core.ames-state.marbud (pit:nu:crub:crypto 512 (shaz 'marbud'))
|
||||
=/ marbud-pub pub:ex:crypto-core.ames-state.marbud
|
||||
=/ marbud-sec sec:ex:crypto-core.ames-state.marbud
|
||||
::
|
||||
=. now.comet ~1111.1.1
|
||||
=. eny.comet 0xbeef.cafe
|
||||
=. life.ames-state.comet 1
|
||||
=. rof.comet |=(* ``[%noun !>(*(list turf))])
|
||||
=. crypto-core.ames-state.comet
|
||||
%- nol:nu:crub:crypto
|
||||
@ -32,10 +46,23 @@
|
||||
3q3td.T4UF0.d5sDL.JGpZq.S3A92.QUuWg.IHdw7.izyny.j9W92
|
||||
=/ comet-pub pub:ex:crypto-core.ames-state.comet
|
||||
=/ comet-sec sec:ex:crypto-core.ames-state.comet
|
||||
|
||||
::
|
||||
=. now.comet2 ~1111.1.1
|
||||
=. eny.comet2 0xcafe.cafe
|
||||
=. life.ames-state.comet2 1
|
||||
=. rof.comet2 |=(* ``[%noun !>(*(list turf))])
|
||||
=. crypto-core.ames-state.comet2 (pit:nu:crub:crypto 512 0v1eb4)
|
||||
=/ comet2-pub pub:ex:crypto-core.ames-state.comet2
|
||||
=/ comet2-sec sec:ex:crypto-core.ames-state.comet2
|
||||
::
|
||||
=/ nec-sym (derive-symmetric-key:ames bud-pub nec-sec)
|
||||
=/ bud-sym (derive-symmetric-key:ames nec-pub bud-sec)
|
||||
?> =(nec-sym bud-sym)
|
||||
=/ nec-marbud-sym (derive-symmetric-key:ames marbud-pub nec-sec)
|
||||
::
|
||||
=/ marbud-sym (derive-symmetric-key:ames marbud-pub comet-sec)
|
||||
=/ marbud2-sym (derive-symmetric-key:ames marbud-pub comet2-sec)
|
||||
=/ bud-marbud-sym (derive-symmetric-key:ames bud-pub marbud-sec)
|
||||
::
|
||||
=/ comet-sym (derive-symmetric-key:ames bud-pub comet-sec)
|
||||
::
|
||||
@ -52,6 +79,18 @@
|
||||
=. route.peer-state `[direct=%.y `lane:ames`[%& ~nec]]
|
||||
[%known peer-state]
|
||||
::
|
||||
=. peers.ames-state.nec
|
||||
%+ ~(put by peers.ames-state.nec) ~marbud
|
||||
=| =peer-state:ames
|
||||
=. -.peer-state
|
||||
:* symmetric-key=nec-marbud-sym
|
||||
life=5
|
||||
public-key=marbud-pub
|
||||
sponsor=~bud
|
||||
==
|
||||
=. route.peer-state `[direct=%.y `lane:ames`[%| `@`%lane-bar]]
|
||||
[%known peer-state]
|
||||
::
|
||||
=. peers.ames-state.bud
|
||||
%+ ~(put by peers.ames-state.bud) ~nec
|
||||
=| =peer-state:ames
|
||||
@ -64,12 +103,59 @@
|
||||
==
|
||||
=. route.peer-state `[direct=%.y `lane:ames`[%| `@`%lane-bar]]
|
||||
[%known peer-state]
|
||||
::
|
||||
=. peers.ames-state.comet
|
||||
%+ ~(put by peers.ames-state.comet) ~marbud
|
||||
=| =peer-state:ames
|
||||
=. -.peer-state
|
||||
:* symmetric-key=marbud-sym
|
||||
life=5
|
||||
public-key=marbud-pub
|
||||
sponsor=~bud
|
||||
==
|
||||
=. route.peer-state `[direct=%.y `lane:ames`[%| `@`%lane-bar]]
|
||||
[%known peer-state]
|
||||
=. peers.ames-state.comet
|
||||
%+ ~(put by peers.ames-state.comet) ~bud
|
||||
=| =peer-state:ames
|
||||
=. -.peer-state
|
||||
:* symmetric-key=bud-marbud-sym
|
||||
life=3
|
||||
public-key=bud-pub
|
||||
sponsor=~bud
|
||||
==
|
||||
=. route.peer-state `[direct=%.y `lane:ames`[%| `@`%lane-bar]]
|
||||
[%known peer-state]
|
||||
=. peers.ames-state.comet2
|
||||
%+ ~(put by peers.ames-state.comet2) ~marbud
|
||||
=| =peer-state:ames
|
||||
=. -.peer-state
|
||||
:* symmetric-key=marbud2-sym
|
||||
life=5
|
||||
public-key=marbud-pub
|
||||
sponsor=~bud
|
||||
==
|
||||
=. route.peer-state `[direct=%.y `lane:ames`[%| `@`%lane-bar]]
|
||||
[%known peer-state]
|
||||
=. peers.ames-state.comet2
|
||||
%+ ~(put by peers.ames-state.comet2) ~bud
|
||||
=| =peer-state:ames
|
||||
=. -.peer-state
|
||||
:* symmetric-key=bud-marbud-sym
|
||||
life=3
|
||||
public-key=bud-pub
|
||||
sponsor=~bud
|
||||
==
|
||||
=. route.peer-state `[direct=%.y `lane:ames`[%| `@`%lane-bar]]
|
||||
[%known peer-state]
|
||||
:: metamorphose
|
||||
::
|
||||
=> .(nec +:(call:(nec) ~[//unix] ~ %born ~))
|
||||
=> .(bud +:(call:(bud) ~[//unix] ~ %born ~))
|
||||
=> .(comet +:(call:(comet) ~[//unix] ~ %born ~))
|
||||
=> .(comet2 +:(call:(comet2) ~[//unix] ~ %born ~))
|
||||
:: helper core
|
||||
::
|
||||
::
|
||||
=>
|
||||
|%
|
||||
++ move-to-packet
|
||||
@ -225,6 +311,7 @@
|
||||
!> (sy ,.moves3)
|
||||
==
|
||||
::
|
||||
<<<<<<< HEAD
|
||||
++ test-comet-encounter ^- tang
|
||||
::
|
||||
=/ lane-foo=lane:ames [%| `@ux``@`%lane-foo]
|
||||
@ -276,6 +363,60 @@
|
||||
!> moves1
|
||||
==
|
||||
::
|
||||
||||||| c4bc9b3428
|
||||
++ test-comet-encounter ^- tang
|
||||
::
|
||||
=/ lane-foo=lane:ames [%| `@ux``@`%lane-foo]
|
||||
::
|
||||
=/ =open-packet:ames
|
||||
:* public-key=`@`comet-pub
|
||||
sndr=our.comet
|
||||
sndr-life=1
|
||||
rcvr=~bud
|
||||
rcvr-life=3
|
||||
==
|
||||
=/ packet
|
||||
~! ames
|
||||
(encode-open-packet:ames open-packet crypto-core.ames-state.comet)
|
||||
=/ blob (encode-packet:ames packet)
|
||||
::
|
||||
=^ moves0 bud (call bud ~[//unix] %hear lane-foo blob)
|
||||
::
|
||||
=/ =plea:ames [%g /talk [%first %post]]
|
||||
=/ =shut-packet:ames
|
||||
:* bone=1
|
||||
message-num=1
|
||||
[%& num-fragments=1 fragment-num=0 (jam plea)]
|
||||
==
|
||||
=/ =packet:ames
|
||||
%: encode-shut-packet:ames
|
||||
shut-packet
|
||||
comet-sym
|
||||
our.comet
|
||||
~bud
|
||||
sndr-life=1
|
||||
rcvr-life=3
|
||||
==
|
||||
=/ blob (encode-packet:ames packet)
|
||||
=^ moves1 bud (call bud ~[//unix] %hear lane-foo blob)
|
||||
::
|
||||
;: weld
|
||||
%+ expect-eq
|
||||
!> ~
|
||||
!> moves0
|
||||
::
|
||||
%+ expect-eq
|
||||
!> :~ :* ~[//unix] %pass /qos %d %flog %text
|
||||
"; {<our.comet>} is your neighbor"
|
||||
==
|
||||
:* ~[//unix] %pass /bone/(scot %p our.comet)/1
|
||||
%g %plea our.comet plea
|
||||
== ==
|
||||
!> moves1
|
||||
==
|
||||
::
|
||||
=======
|
||||
>>>>>>> pr
|
||||
++ test-message-flow ^- tang
|
||||
:: ~nec -> %plea -> ~bud
|
||||
::
|
||||
@ -314,6 +455,77 @@
|
||||
!> (snag 0 `(list move:ames)`moves6)
|
||||
==
|
||||
::
|
||||
++ test-comet-message-flow ^- tang
|
||||
:: same as test-message-flow, but ~nec will send a sendkeys packet to request
|
||||
:: comet's self-attestation directly
|
||||
::
|
||||
=^ moves0 nec (call nec ~[/g/talk] %plea our-comet %g /talk [%get %post])
|
||||
=^ moves1 comet (call comet ~[//unix] %hear (snag-packet 0 moves0))
|
||||
=^ moves2 comet
|
||||
=/ =point:ames
|
||||
:* rift=1
|
||||
life=2
|
||||
keys=[[life=2 [crypto-suite=1 `@`nec-pub]] ~ ~]
|
||||
sponsor=`~nec
|
||||
==
|
||||
%- take
|
||||
:^ comet /public-keys ~[//unix]
|
||||
^- sign:ames
|
||||
[%jael %public-keys %full [n=[~nec point] ~ ~]]
|
||||
:: give comet's self-attestation to ~nec; at this point, we have established
|
||||
:: a channel, and can proceed as usual
|
||||
::
|
||||
=^ moves3 nec (call nec ~[//unix] %hear (snag-packet 0 moves2))
|
||||
=^ moves4 comet (call comet ~[//unix] %hear (snag-packet 0 moves3))
|
||||
=^ moves5 comet (take comet /bone/~nec/0/1 ~[//unix] %g %done ~)
|
||||
=^ moves6 nec (call nec ~[//unix] %hear (snag-packet 0 moves5))
|
||||
=^ moves7 comet (take comet /bone/~nec/0/1 ~[//unix] %g %boon [%post 'first1!!'])
|
||||
=^ moves8 nec (call nec ~[//unix] %hear (snag-packet 0 moves7))
|
||||
::
|
||||
;: weld
|
||||
%+ expect-eq
|
||||
!> [~[//unix] %pass /qos %d %flog %text "; ~nec is your neighbor"]
|
||||
!> (snag 0 `(list move:ames)`moves4)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> [~[//unix] %pass /qos %d %flog %text "; {<our-comet>} is your neighbor"]
|
||||
!> (snag 0 `(list move:ames)`moves6)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> [~[/g/talk] %give %boon [%post 'first1!!']]
|
||||
!> (snag 0 `(list move:ames)`moves8)
|
||||
==
|
||||
::
|
||||
++ test-comet-comet-message-flow ^- tang
|
||||
:: same as test-message-flow, but the comets need to exchange
|
||||
:: self-attestations to establish a channel
|
||||
::
|
||||
=^ moves0 comet (call comet ~[/g/talk] %plea our-comet2 %g /talk [%get %post])
|
||||
=^ moves1 comet2 (call comet2 ~[//unix] %hear (snag-packet 0 moves0))
|
||||
=^ moves2 comet (call comet ~[//unix] %hear (snag-packet 0 moves1))
|
||||
:: channel is now established; comet also emitted a duplicate
|
||||
:: self-attestation, which we ignore
|
||||
::
|
||||
=^ moves3 comet2 (call comet2 ~[//unix] %hear (snag-packet 1 moves2))
|
||||
=^ moves4 comet2 (take comet2 /bone/(scot %p our-comet)/0/1 ~[//unix] %g %done ~)
|
||||
=^ moves5 comet (call comet ~[//unix] %hear (snag-packet 0 moves4))
|
||||
=^ moves6 comet2 (take comet2 /bone/(scot %p our-comet)/0/1 ~[//unix] %g %boon [%post 'first1!!'])
|
||||
=^ moves7 comet (call comet ~[//unix] %hear (snag-packet 0 moves6))
|
||||
::
|
||||
;: weld
|
||||
%+ expect-eq
|
||||
!> [~[//unix] %pass /qos %d %flog %text "; {<our-comet>} is your neighbor"]
|
||||
!> (snag 0 `(list move:ames)`moves3)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> [~[//unix] %pass /qos %d %flog %text "; {<our-comet2>} is your neighbor"]
|
||||
!> (snag 0 `(list move:ames)`moves5)
|
||||
::
|
||||
%+ expect-eq
|
||||
!> [~[/g/talk] %give %boon [%post 'first1!!']]
|
||||
!> (snag 0 `(list move:ames)`moves7)
|
||||
==
|
||||
::
|
||||
++ test-nack ^- tang
|
||||
:: ~nec -> %plea -> ~bud
|
||||
::
|
||||
|
Loading…
Reference in New Issue
Block a user