mirror of
https://github.com/urbit/shrub.git
synced 2024-12-23 19:05:48 +03:00
ames: merge driver rework
This commit is contained in:
commit
062fbc71d7
@ -1196,7 +1196,7 @@
|
|||||||
::
|
::
|
||||||
+$ hoot @uxhoot :: request packet
|
+$ hoot @uxhoot :: request packet
|
||||||
+$ purr @uxpurr :: response packet
|
+$ purr @uxpurr :: response packet
|
||||||
+$ song (list purr) :: full response
|
+$ hunk [lop=@ len=@] :: range specifier
|
||||||
::
|
::
|
||||||
:: +| %kinetics
|
:: +| %kinetics
|
||||||
:: $dyad: pair of sender and receiver ships
|
:: $dyad: pair of sender and receiver ships
|
||||||
@ -1211,8 +1211,13 @@
|
|||||||
:: address. Routes are opaque to Arvo and only have meaning in the
|
:: address. Routes are opaque to Arvo and only have meaning in the
|
||||||
:: interpreter. This enforces that Ames is transport-agnostic.
|
:: interpreter. This enforces that Ames is transport-agnostic.
|
||||||
::
|
::
|
||||||
|
:: req: is a request
|
||||||
|
:: sam: is using the ames protocol (not fine or another protocol)
|
||||||
|
::
|
||||||
+$ packet
|
+$ packet
|
||||||
$: dyad
|
$: dyad
|
||||||
|
req=?
|
||||||
|
sam=?
|
||||||
sndr-tick=@ubC
|
sndr-tick=@ubC
|
||||||
rcvr-tick=@ubC
|
rcvr-tick=@ubC
|
||||||
origin=(unit @uxaddress)
|
origin=(unit @uxaddress)
|
||||||
@ -1306,9 +1311,9 @@
|
|||||||
==
|
==
|
||||||
+$ have
|
+$ have
|
||||||
$: fra=@ud
|
$: fra=@ud
|
||||||
rawr
|
meow
|
||||||
==
|
==
|
||||||
+$ rawr :: response packet ::TODO meow
|
+$ meow :: response packet
|
||||||
$: sig=@
|
$: sig=@
|
||||||
siz=@ud
|
siz=@ud
|
||||||
byts
|
byts
|
||||||
@ -1542,16 +1547,16 @@
|
|||||||
::
|
::
|
||||||
++ decode-packet
|
++ decode-packet
|
||||||
|= =blob
|
|= =blob
|
||||||
^- [ames=? =packet]
|
^- packet
|
||||||
~| %decode-packet-fail
|
~| %decode-packet-fail
|
||||||
:: first 32 (2^5) bits are header; the rest is body
|
:: first 32 (2^5) bits are header; the rest is body
|
||||||
::
|
::
|
||||||
=/ header (end 5 blob)
|
=/ header (end 5 blob)
|
||||||
=/ body (rsh 5 blob)
|
=/ body (rsh 5 blob)
|
||||||
:: read header; first three bits are reserved
|
:: read header; first two bits are reserved
|
||||||
::
|
::
|
||||||
=/ is-ames (cut 0 [3 1] header)
|
=/ req =(& (cut 0 [2 1] header))
|
||||||
:- =(& is-ames)
|
=/ sam =(& (cut 0 [3 1] header))
|
||||||
::
|
::
|
||||||
=/ version (cut 0 [4 3] header)
|
=/ version (cut 0 [4 3] header)
|
||||||
?. =(protocol-version version)
|
?. =(protocol-version version)
|
||||||
@ -1597,7 +1602,7 @@
|
|||||||
:: read variable-length .content from the rest of .body
|
:: read variable-length .content from the rest of .body
|
||||||
::
|
::
|
||||||
=/ content (cut 3 [off (sub (met 3 body) off)] body)
|
=/ content (cut 3 [off (sub (met 3 body) off)] body)
|
||||||
[[sndr rcvr] sndr-tick rcvr-tick origin content]
|
[[sndr rcvr] req sam sndr-tick rcvr-tick origin content]
|
||||||
::
|
::
|
||||||
++ decode-request
|
++ decode-request
|
||||||
|= =hoot
|
|= =hoot
|
||||||
@ -1611,13 +1616,14 @@
|
|||||||
=+ num=(cut 3 [0 4] hoot)
|
=+ num=(cut 3 [0 4] hoot)
|
||||||
=+ len=(cut 3 [4 2] hoot)
|
=+ len=(cut 3 [4 2] hoot)
|
||||||
=+ pat=(cut 3 [6 len] hoot)
|
=+ pat=(cut 3 [6 len] hoot)
|
||||||
|
~| pat=pat
|
||||||
:- [(stab pat) num]
|
:- [(stab pat) num]
|
||||||
:: if there is data remaining, it's the response
|
:: if there is data remaining, it's the response
|
||||||
(rsh [3 (add 6 len)] hoot)
|
(rsh [3 (add 6 len)] hoot)
|
||||||
:: +encode-packet: serialize a packet into a bytestream
|
:: +encode-packet: serialize a packet into a bytestream
|
||||||
::
|
::
|
||||||
++ encode-packet
|
++ encode-packet
|
||||||
|= [ames=? packet]
|
|= packet
|
||||||
^- blob
|
^- blob
|
||||||
::
|
::
|
||||||
=/ sndr-meta (encode-ship-metadata sndr)
|
=/ sndr-meta (encode-ship-metadata sndr)
|
||||||
@ -1636,8 +1642,9 @@
|
|||||||
::
|
::
|
||||||
=/ header=@
|
=/ header=@
|
||||||
%+ can 0
|
%+ can 0
|
||||||
:~ [3 reserved=0]
|
:~ [2 reserved=0]
|
||||||
[1 is-ames=ames]
|
[1 req]
|
||||||
|
[1 sam]
|
||||||
[3 protocol-version]
|
[3 protocol-version]
|
||||||
[2 rank.sndr-meta]
|
[2 rank.sndr-meta]
|
||||||
[2 rank.rcvr-meta]
|
[2 rank.rcvr-meta]
|
||||||
|
@ -269,9 +269,9 @@
|
|||||||
::
|
::
|
||||||
++ decode-response-packet
|
++ decode-response-packet
|
||||||
|= =purr
|
|= =purr
|
||||||
=; =rawr
|
=; =meow
|
||||||
~? !=(wid.rawr (met 3 dat.rawr)) [%fine %unexpected-dat-size]
|
~? !=(wid.meow (met 3 dat.meow)) [%fine %unexpected-dat-size]
|
||||||
rawr
|
meow
|
||||||
:* sig=(cut 3 [0 64] purr)
|
:* sig=(cut 3 [0 64] purr)
|
||||||
siz=(cut 3 [64 4] purr)
|
siz=(cut 3 [64 4] purr)
|
||||||
wid=(cut 3 [68 2] purr)
|
wid=(cut 3 [68 2] purr)
|
||||||
@ -308,6 +308,7 @@
|
|||||||
|= [pac=open-packet =acru:ames]
|
|= [pac=open-packet =acru:ames]
|
||||||
^- packet
|
^- packet
|
||||||
:* [sndr rcvr]:pac
|
:* [sndr rcvr]:pac
|
||||||
|
req=& sam=&
|
||||||
(mod sndr-life.pac 16)
|
(mod sndr-life.pac 16)
|
||||||
(mod rcvr-life.pac 16)
|
(mod rcvr-life.pac 16)
|
||||||
origin=~
|
origin=~
|
||||||
@ -367,8 +368,15 @@
|
|||||||
=/ vec ~[sndr rcvr sndr-life rcvr-life]
|
=/ vec ~[sndr rcvr sndr-life rcvr-life]
|
||||||
=/ [siv=@uxH len=@ cyf=@ux]
|
=/ [siv=@uxH len=@ cyf=@ux]
|
||||||
(~(en sivc:aes:crypto (shaz symmetric-key) vec) (jam shut-packet))
|
(~(en sivc:aes:crypto (shaz symmetric-key) vec) (jam shut-packet))
|
||||||
=/ content :(mix siv (lsh 7 len) (lsh [3 18] cyf))
|
::
|
||||||
[[sndr rcvr] (mod sndr-life 16) (mod rcvr-life 16) origin=~ content]
|
:* ^= dyad [sndr rcvr]
|
||||||
|
^= req ?=(%& -.meat.shut-packet)
|
||||||
|
^= sam &
|
||||||
|
^= sndr-tick (mod sndr-life 16)
|
||||||
|
^= sndr-tick (mod rcvr-life 16)
|
||||||
|
^= origin ~
|
||||||
|
^= content :(mix siv (lsh 7 len) (lsh [3 18] cyf))
|
||||||
|
==
|
||||||
:: +decode-shut-packet: decrypt a $shut-packet from a $packet
|
:: +decode-shut-packet: decrypt a $shut-packet from a $packet
|
||||||
::
|
::
|
||||||
++ decode-shut-packet
|
++ decode-shut-packet
|
||||||
@ -1113,6 +1121,7 @@
|
|||||||
:: /ax/fine/message/[path/...] song
|
:: /ax/fine/message/[path/...] song
|
||||||
::
|
::
|
||||||
?. ?=(%x ren) ~
|
?. ?=(%x ren) ~
|
||||||
|
=> .(tyl `(pole knot)`tyl)
|
||||||
?+ tyl ~
|
?+ tyl ~
|
||||||
[%protocol %version ~]
|
[%protocol %version ~]
|
||||||
``noun+!>(protocol-version)
|
``noun+!>(protocol-version)
|
||||||
@ -1122,11 +1131,11 @@
|
|||||||
!> ^- (map ship ?(%alien %known))
|
!> ^- (map ship ?(%alien %known))
|
||||||
(~(run by peers.ames-state) head)
|
(~(run by peers.ames-state) head)
|
||||||
::
|
::
|
||||||
[%peers @ *]
|
[%peers her=@ req=*]
|
||||||
=/ who (slaw %p i.t.tyl)
|
=/ who (slaw %p her.tyl)
|
||||||
?~ who [~ ~]
|
?~ who [~ ~]
|
||||||
=/ peer (~(get by peers.ames-state) u.who)
|
=/ peer (~(get by peers.ames-state) u.who)
|
||||||
?+ t.t.tyl [~ ~]
|
?+ req.tyl [~ ~]
|
||||||
~
|
~
|
||||||
?~ peer
|
?~ peer
|
||||||
[~ ~]
|
[~ ~]
|
||||||
@ -1164,8 +1173,8 @@
|
|||||||
$(peer next)
|
$(peer next)
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
[%bones @ ~]
|
[%bones her=@ ~]
|
||||||
=/ who (slaw %p i.t.tyl)
|
=/ who (slaw %p her.tyl)
|
||||||
?~ who [~ ~]
|
?~ who [~ ~]
|
||||||
=/ per (~(get by peers.ames-state) u.who)
|
=/ per (~(get by peers.ames-state) u.who)
|
||||||
?. ?=([~ %known *] per) [~ ~]
|
?. ?=([~ %known *] per) [~ ~]
|
||||||
@ -1174,10 +1183,10 @@
|
|||||||
[snd=~(key by snd) rcv=~(key by rcv)]
|
[snd=~(key by snd) rcv=~(key by rcv)]
|
||||||
``noun+!>(res)
|
``noun+!>(res)
|
||||||
::
|
::
|
||||||
[%snd-bones @ @ ~]
|
[%snd-bones her=@ bon=@ ~]
|
||||||
=/ who (slaw %p i.t.tyl)
|
=/ who (slaw %p her.tyl)
|
||||||
?~ who [~ ~]
|
?~ who [~ ~]
|
||||||
=/ ost (slaw %ud i.t.t.tyl)
|
=/ ost (slaw %ud bon.tyl)
|
||||||
?~ ost [~ ~]
|
?~ ost [~ ~]
|
||||||
=/ per (~(get by peers.ames-state) u.who)
|
=/ per (~(get by peers.ames-state) u.who)
|
||||||
?. ?=([~ %known *] per) [~ ~]
|
?. ?=([~ %known *] per) [~ ~]
|
||||||
@ -1187,14 +1196,12 @@
|
|||||||
u.mps
|
u.mps
|
||||||
``noun+!>(!>(res))
|
``noun+!>(!>(res))
|
||||||
::
|
::
|
||||||
[%fine %message @ *]
|
[%fine %hunk lop=@t len=@t pax=^]
|
||||||
::TODO separate endpoint for the full message (instead of packet list)
|
::TODO separate endpoint for the full message (instead of packet list)
|
||||||
:: t.t.tyl is expected to be a scry path of the shape /vc/desk/rev/etc,
|
:: .pax is expected to be a scry path of the shape /vc/desk/rev/etc,
|
||||||
:: so we need to give it the right shape
|
:: so we need to give it the right shape
|
||||||
::
|
::
|
||||||
=* path t.t.tyl
|
?~ blk=(de-path-soft:balk pax.tyl) ~
|
||||||
~| path
|
|
||||||
?~ blk=(de-path-soft:balk path) ~
|
|
||||||
=+ nom=(en-roof:balk u.blk)
|
=+ nom=(en-roof:balk u.blk)
|
||||||
~| nom
|
~| nom
|
||||||
:: we only support scrying into clay,
|
:: we only support scrying into clay,
|
||||||
@ -1208,12 +1215,13 @@
|
|||||||
=+ per=!<([r=dict:clay w=dict:clay] q.u.u.pem)
|
=+ per=!<([r=dict:clay w=dict:clay] q.u.u.pem)
|
||||||
?. =([%black ~ ~] rul.r.per) ~
|
?. =([%black ~ ~] rul.r.per) ~
|
||||||
=+ res=(rof lyc nom)
|
=+ res=(rof lyc nom)
|
||||||
|
=/ =hunk [(slav %ud lop.tyl) (slav %ud len.tyl)]
|
||||||
::TODO suggests we need to factor differently
|
::TODO suggests we need to factor differently
|
||||||
=+ ven=(per-event [now 0v0 rof] *duct ames-state)
|
=/ fin fine:(per-event [now 0v0 rof] *duct ames-state)
|
||||||
?- res
|
?- res
|
||||||
~ ~
|
~ ~
|
||||||
[~ ~] ``noun+!>((encode-response:fine:ven path ~))
|
[~ ~] ``noun+!>((encode-hunk:fin pax.tyl hunk ~))
|
||||||
[~ ~ *] ``noun+!>((encode-response:fine:ven path [p q.q]:u.u.res))
|
[~ ~ *] ``noun+!>((encode-hunk:fin pax.tyl hunk [p q.q]:u.u.res))
|
||||||
==
|
==
|
||||||
==
|
==
|
||||||
--
|
--
|
||||||
@ -1436,11 +1444,10 @@
|
|||||||
++ on-hear
|
++ on-hear
|
||||||
|= [l=lane b=blob d=(unit goof)]
|
|= [l=lane b=blob d=(unit goof)]
|
||||||
^+ event-core
|
^+ event-core
|
||||||
=/ [ames=? =packet]
|
=/ =packet (decode-packet b)
|
||||||
(decode-packet b)
|
?: sam.packet
|
||||||
?: ames
|
|
||||||
(on-hear-packet l packet d)
|
(on-hear-packet l packet d)
|
||||||
?. response==(& (cut 0 [2 1] b))
|
?: req.packet
|
||||||
~|([%fine %request-events-forbidden] !!)
|
~|([%fine %request-events-forbidden] !!)
|
||||||
(on-hear-response:fine l packet d)
|
(on-hear-response:fine l packet d)
|
||||||
:: +on-hear-packet: handle mildly processed packet receipt
|
:: +on-hear-packet: handle mildly processed packet receipt
|
||||||
@ -1485,7 +1492,7 @@
|
|||||||
~| ames-lane-size+p.lane !!
|
~| ames-lane-size+p.lane !!
|
||||||
`p.lane
|
`p.lane
|
||||||
::
|
::
|
||||||
=/ =blob (encode-packet & packet)
|
=/ =blob (encode-packet packet)
|
||||||
(send-blob & rcvr.packet blob)
|
(send-blob & rcvr.packet blob)
|
||||||
:: +on-hear-open: handle receipt of plaintext comet self-attestation
|
:: +on-hear-open: handle receipt of plaintext comet self-attestation
|
||||||
::
|
::
|
||||||
@ -2105,7 +2112,7 @@
|
|||||||
++ attestation-packet
|
++ attestation-packet
|
||||||
|= [her=ship =her=life]
|
|= [her=ship =her=life]
|
||||||
^- blob
|
^- blob
|
||||||
%+ encode-packet &
|
%- encode-packet
|
||||||
%- encode-open-packet
|
%- encode-open-packet
|
||||||
:_ crypto-core.ames-state
|
:_ crypto-core.ames-state
|
||||||
:* ^= public-key pub:ex:crypto-core.ames-state
|
:* ^= public-key pub:ex:crypto-core.ames-state
|
||||||
@ -2122,7 +2129,7 @@
|
|||||||
|= her=ship
|
|= her=ship
|
||||||
^- blob
|
^- blob
|
||||||
?> ?=(%pawn (clan:title her))
|
?> ?=(%pawn (clan:title her))
|
||||||
%+ encode-packet &
|
%- encode-packet
|
||||||
%- encode-shut-packet
|
%- encode-shut-packet
|
||||||
:* ^= shut-packet *shut-packet
|
:* ^= shut-packet *shut-packet
|
||||||
^= symmetric-key *symmetric-key
|
^= symmetric-key *symmetric-key
|
||||||
@ -2394,7 +2401,7 @@
|
|||||||
::
|
::
|
||||||
=. event-core
|
=. event-core
|
||||||
%^ send-blob | her.channel
|
%^ send-blob | her.channel
|
||||||
%+ encode-packet &
|
%- encode-packet
|
||||||
%: encode-shut-packet
|
%: encode-shut-packet
|
||||||
shut-packet(bone (mix 1 bone.shut-packet))
|
shut-packet(bone (mix 1 bone.shut-packet))
|
||||||
symmetric-key.channel
|
symmetric-key.channel
|
||||||
@ -2643,12 +2650,9 @@
|
|||||||
|= [=path =^duct]
|
|= [=path =^duct]
|
||||||
?: (~(has by order.scry) path)
|
?: (~(has by order.scry) path)
|
||||||
ke-abet:(ke-sub:(ke-abed:keen-core path) duct)
|
ke-abet:(ke-sub:(ke-abed:keen-core path) duct)
|
||||||
=/ keen-id=@ud seq.scry
|
=^ keen-id=@ud seq.scry [seq.scry +(seq.scry)]
|
||||||
=. seq.scry +(seq.scry)
|
=. order.scry (~(put by order.scry) path keen-id)
|
||||||
=. order.scry
|
=. keens.scry (put:orm keens.scry keen-id *keen-state)
|
||||||
(~(put by order.scry) path keen-id)
|
|
||||||
=| =keen-state
|
|
||||||
=. keens.scry (put:orm keens.scry keen-id keen-state)
|
|
||||||
ke-abet:(ke-start:(ke-abed:keen-core path) duct)
|
ke-abet:(ke-start:(ke-abed:keen-core path) duct)
|
||||||
::
|
::
|
||||||
++ pe-pine
|
++ pe-pine
|
||||||
@ -2848,18 +2852,18 @@
|
|||||||
$(listeners t.listeners)
|
$(listeners t.listeners)
|
||||||
::
|
::
|
||||||
++ ke-first-rcv
|
++ ke-first-rcv
|
||||||
|= =rawr
|
|= =meow
|
||||||
^+ ke-core
|
^+ ke-core
|
||||||
=- ke-core(keen -)
|
=- ke-core(keen -)
|
||||||
::
|
::
|
||||||
=/ paz=(list want)
|
=/ paz=(list want)
|
||||||
%+ turn (gulf 1 siz.rawr)
|
%+ turn (gulf 1 siz.meow)
|
||||||
|= fra=@ud
|
|= fra=@ud
|
||||||
^- want
|
^- want
|
||||||
[fra (ke-encode-req fra) now 0 0]
|
[fra (ke-encode-req fra) now 0 0]
|
||||||
::
|
::
|
||||||
%_ keen
|
%_ keen
|
||||||
num-fragments siz.rawr
|
num-fragments siz.meow
|
||||||
nex (tail paz)
|
nex (tail paz)
|
||||||
==
|
==
|
||||||
:: +ke-continue: send packets according to normal congestion flow
|
:: +ke-continue: send packets according to normal congestion flow
|
||||||
@ -2915,28 +2919,28 @@
|
|||||||
++ ke-rcv
|
++ ke-rcv
|
||||||
|= [fra=@ud =purr =lane:ames]
|
|= [fra=@ud =purr =lane:ames]
|
||||||
^+ ke-core
|
^+ ke-core
|
||||||
=/ =rawr (decode-response-packet purr)
|
=/ =meow (decode-response-packet purr)
|
||||||
=/ og ke-core
|
=/ og ke-core
|
||||||
=. pe-core (pe-update-qos %live last-contact=now)
|
=. pe-core (pe-update-qos %live last-contact=now)
|
||||||
:: handle empty
|
:: handle empty
|
||||||
?: =(0 siz.rawr)
|
?: =(0 siz.meow)
|
||||||
?> =(~ dat.rawr)
|
?> =(~ dat.meow)
|
||||||
(ke-done sig.rawr ~)
|
(ke-done sig.meow ~)
|
||||||
:: update congestion, or fill details
|
:: update congestion, or fill details
|
||||||
::
|
::
|
||||||
=? ke-core =(0 num-fragments.keen)
|
=? ke-core =(0 num-fragments.keen)
|
||||||
?> =(fra 1)
|
?> =(fra 1)
|
||||||
(ke-first-rcv rawr)
|
(ke-first-rcv meow)
|
||||||
::
|
::
|
||||||
~| failed-signature/fra^`@ux`sig.rawr
|
~| failed-signature/fra^`@ux`sig.meow
|
||||||
~| life.peer
|
~| life.peer
|
||||||
?> (veri-fra:keys ship life.peer ke-full-path fra [dat sig]:rawr)
|
?> (veri-fra:keys ship life.peer ke-full-path fra [dat sig]:meow)
|
||||||
=^ found=? ke-core
|
=^ found=? ke-core
|
||||||
(ke-on-ack fra)
|
(ke-on-ack fra)
|
||||||
::
|
::
|
||||||
?. found
|
?. found
|
||||||
(ke-fast-retransmit:og fra)
|
(ke-fast-retransmit:og fra)
|
||||||
=/ =have [fra rawr]
|
=/ =have [fra meow]
|
||||||
=. hav.keen
|
=. hav.keen
|
||||||
`(list ^have)`[have hav.keen]
|
`(list ^have)`[have hav.keen]
|
||||||
=. num-received.keen +(num-received.keen)
|
=. num-received.keen +(num-received.keen)
|
||||||
@ -3067,9 +3071,11 @@
|
|||||||
=+ !<(=cass:clay q.u.u.cag)
|
=+ !<(=cass:clay q.u.u.cag)
|
||||||
(emit duct %give %boon `*`ud.cass)
|
(emit duct %give %boon `*`ud.cass)
|
||||||
==
|
==
|
||||||
|
::
|
||||||
++ on-keen
|
++ on-keen
|
||||||
|= [=ship =path]
|
|= [=ship =path]
|
||||||
^+ event-core
|
^+ event-core
|
||||||
|
=+ ~:(spit path) :: assert length
|
||||||
=/ peer-core (pe-abed:fine-peer ship)
|
=/ peer-core (pe-abed:fine-peer ship)
|
||||||
?^ peer-core pe-abet:(pe-keen:u.peer-core path duct)
|
?^ peer-core pe-abet:(pe-keen:u.peer-core path duct)
|
||||||
%+ enqueue-alien-todo ship
|
%+ enqueue-alien-todo ship
|
||||||
@ -3127,7 +3133,7 @@
|
|||||||
num=@ud
|
num=@ud
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
+$ rawr :: response packet ::TODO meow
|
+$ meow :: response packet
|
||||||
$: sig=@
|
$: sig=@
|
||||||
siz=@ud
|
siz=@ud
|
||||||
byts
|
byts
|
||||||
@ -3138,81 +3144,74 @@
|
|||||||
dat=$@(~ (cask))
|
dat=$@(~ (cask))
|
||||||
==
|
==
|
||||||
++ orm ((on @ud keen-state) lte)
|
++ orm ((on @ud keen-state) lte)
|
||||||
|
:: +gum: glue together a list of $byts into one
|
||||||
|
::
|
||||||
|
:: TODO: move to hoon.hoon
|
||||||
|
::
|
||||||
|
++ gum
|
||||||
|
~/ %gum
|
||||||
|
|= biz=(list byts)
|
||||||
|
^- byts
|
||||||
|
:- (roll biz |=([[wid=@ *] acc=@] (add wid acc)))
|
||||||
|
(can 3 biz)
|
||||||
::
|
::
|
||||||
++ spit
|
++ spit
|
||||||
|= =path
|
|= =path
|
||||||
^- [pat=@t wid=@ud]
|
^- [pat=@t wid=@ud]
|
||||||
=+ pat=(spat path)
|
=+ pat=(spat path)
|
||||||
=+ wid=(met 3 pat)
|
=+ wid=(met 3 pat)
|
||||||
?> (lte wid 384) ::TODO check when we handle %keen, in addition to here
|
?> (lte wid 384)
|
||||||
[pat wid]
|
[pat wid]
|
||||||
::
|
::
|
||||||
++ request-body
|
++ request-body
|
||||||
|= [=path num=@ud]
|
|= [=path num=@ud]
|
||||||
::NOTE path is expected to be a namespace path without the ship
|
|
||||||
^- byts
|
^- byts
|
||||||
?> (lth num (bex 32))
|
?> (lth num (bex 32))
|
||||||
=+ (spit path)
|
=+ (spit path)
|
||||||
:- :(add 4 2 wid)
|
%- gum
|
||||||
%+ can 3
|
|
||||||
:~ 4^num :: fragment number
|
:~ 4^num :: fragment number
|
||||||
2^wid :: path size
|
2^wid :: path size
|
||||||
wid^`@`pat :: namespace path
|
wid^`@`pat :: namespace path
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
|
++ frag-body
|
||||||
|
|= [=path mes=@ num=@ud]
|
||||||
|
^- @uxmeow
|
||||||
|
=/ tot (met 13 mes)
|
||||||
|
=/ fra (cut 13 [(dec num) 1] mes)
|
||||||
|
=/ wid (met 3 fra)
|
||||||
|
%+ can 3
|
||||||
|
:~ 64^(sign-fra:keys path num fra)
|
||||||
|
4^tot :: number of fragments
|
||||||
|
2^wid :: response data fragment size in bytes
|
||||||
|
wid^fra :: response data fragment
|
||||||
|
==
|
||||||
|
::
|
||||||
++ encode-request
|
++ encode-request
|
||||||
|= [=ship =path num=@ud]
|
|= [=ship =path num=@ud]
|
||||||
::NOTE path is expected to be a namespace path without the ship
|
|
||||||
^- hoot ^- @
|
^- hoot ^- @
|
||||||
=+ bod=(request-body path num)
|
=/ sic (mod life.ames-state 16)
|
||||||
=+ sig=64^(sign:keys dat.bod)
|
=/ ric (mod (lyfe:keys ship) 16)
|
||||||
=+ syn=(can 3 sig bod ~)
|
=/ syn
|
||||||
%+ con 0b100 ::NOTE request bit
|
=/ bod (request-body path num)
|
||||||
%^ encode-packet |
|
=/ sig 64^(sign:keys dat.bod)
|
||||||
[our ship]
|
(can 3 sig bod ~)
|
||||||
[(mod life.ames-state 16) (mod (lyfe:keys ship) 16) ~ syn]
|
(encode-packet [our ship] req=& sam=| sic ric ~ syn)
|
||||||
::
|
::
|
||||||
++ encode-response ::TODO unit tests
|
++ encode-hunk ::TODO unit tests
|
||||||
|= [=path data=$@(~ (cask))]
|
|= [=path =hunk data=$@(~ (cask))]
|
||||||
^- song
|
^- (list @uxmeow)
|
||||||
:: prepend request descriptions to each response packet
|
=/ mes=@
|
||||||
::
|
|
||||||
=; pacs=(list @ux)
|
|
||||||
%- head
|
|
||||||
%^ spin pacs 1
|
|
||||||
|= [pac=@ux num=@ud]
|
|
||||||
^- [purr _num]
|
|
||||||
:_ +(num)
|
|
||||||
^- @ux
|
|
||||||
::NOTE we stub out the receiver & origin details,
|
|
||||||
:: runtime should replace them as appropriate.
|
|
||||||
(encode-packet | [our ~zod] (mod life.ames-state 16) 0b0 ~ pac)
|
|
||||||
:: prepend a signature and split the data into 1024-byte fragments
|
|
||||||
::
|
|
||||||
=/ frag=(list @)
|
|
||||||
=/ sig=@ (full:keys path data)
|
=/ sig=@ (full:keys path data)
|
||||||
?~ data [sig]~
|
?~ data sig
|
||||||
%+ rip response-size ::NOTE 1024 bytes
|
(cat 9 sig (jam data))
|
||||||
(cat 9 sig (jam data)) ::TODO should include life
|
|
||||||
:: sign & packetize the fragments
|
|
||||||
::
|
::
|
||||||
%- head
|
=/ top +((min (met 13 mes) (add [lop len]:hunk)))
|
||||||
%^ spin frag 1
|
=/ num lop.hunk
|
||||||
|= [dat=@ num=@ud]
|
=| res=(list @uxmeow)
|
||||||
:_ +(num)
|
|- ^+ res
|
||||||
^- @ux
|
?: =(num top) (flop res)
|
||||||
=/ req=byts (request-body path num)
|
$(num +(num), res :_(res (frag-body path mes num)))
|
||||||
=/ bod=byts
|
|
||||||
=/ wid=@ud (met 3 dat)
|
|
||||||
:- :(add 4 2 wid)
|
|
||||||
%+ can 3
|
|
||||||
:~ 4^(lent frag) :: number of fragments
|
|
||||||
2^wid :: response data fragment size in bytes
|
|
||||||
wid^dat :: response data fragment
|
|
||||||
==
|
|
||||||
=/ sig=byts
|
|
||||||
64^(sign-fra:keys path num dat)
|
|
||||||
(can 3 req sig bod ~)
|
|
||||||
::
|
::
|
||||||
++ keys
|
++ keys
|
||||||
|%
|
|%
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
} u3_prel;
|
} u3_prel;
|
||||||
|
|
||||||
typedef struct _u3_body {
|
typedef struct _u3_body {
|
||||||
u3_prel pre_u; // prelude
|
|
||||||
c3_s con_s; // content size
|
c3_s con_s; // content size
|
||||||
c3_y* con_y; // content
|
c3_y* con_y; // content
|
||||||
c3_l mug_l; // checksum
|
c3_l mug_l; // checksum
|
||||||
@ -61,52 +60,53 @@ _test_ames(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
//TODO: rewrite with more types: purr, wail, body,etc.
|
||||||
_test_sift_etch()
|
//static void
|
||||||
{
|
//_test_sift_etch()
|
||||||
u3_head* hed_u = c3_calloc(sizeof(*hed_u));
|
//{
|
||||||
u3_body* bod_u = c3_calloc(sizeof(*bod_u));
|
// u3_head* hed_u = c3_calloc(sizeof(*hed_u));
|
||||||
|
// u3_body* bod_u = c3_calloc(sizeof(*bod_u));
|
||||||
|
//
|
||||||
|
// hed_u->sim_o = c3y;
|
||||||
|
// hed_u->ver_y = 1;
|
||||||
|
// hed_u->sac_y = 4;
|
||||||
|
// hed_u->rac_y = 4;
|
||||||
|
// hed_u->rel_o = c3n;
|
||||||
|
//
|
||||||
|
// bod_u->pre_u.sen_d[0] = 0;
|
||||||
|
// bod_u->pre_u.sen_d[1] = 0;
|
||||||
|
// bod_u->pre_u.rec_d[0] = 182;
|
||||||
|
// bod_u->pre_u.rec_d[1] = 0;
|
||||||
|
//
|
||||||
|
// c3_y* str = (c3_y*)"test";
|
||||||
|
//
|
||||||
|
// bod_u->con_y = str;
|
||||||
|
// bod_u->con_s = 5;
|
||||||
|
//
|
||||||
|
// c3_y** out_y;
|
||||||
|
//
|
||||||
|
// c3_w pac_w = _ames_etch_pack(hed_u, bod_u, out_y);
|
||||||
|
//
|
||||||
|
// u3_head* nhed_u = c3_calloc(sizeof(*nhed_u));
|
||||||
|
// u3_body* nbod_u = c3_calloc(sizeof(*nbod_u));
|
||||||
|
// _ames_sift_head(nhed_u, *out_y);
|
||||||
|
// *out_y += 4;
|
||||||
|
// c3_y_ames_sift_body(nbod_u, *out_y);
|
||||||
|
//
|
||||||
|
// if( 0 != memcmp(hed_u, nhed_u, sizeof(*hed_u))) {
|
||||||
|
// fprintf(stderr, "ames: header serialisation mismatch(a)\r\n");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
// if( 0 != memcmp(bod_u, nbod_u, sizeof(*bod_u))) {
|
||||||
|
// fprintf(stderr, "ames: body serialisation fail(a)\r\n");
|
||||||
|
// exit(1);
|
||||||
|
// } else {
|
||||||
|
// fprintf(stderr, "ames: pass (a)\r\n");
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
|
||||||
hed_u->sim_o = c3y;
|
|
||||||
hed_u->ver_y = 1;
|
|
||||||
hed_u->sac_y = 4;
|
|
||||||
hed_u->rac_y = 4;
|
|
||||||
hed_u->rel_o = c3n;
|
|
||||||
|
|
||||||
bod_u->pre_u.sen_d[0] = 0;
|
|
||||||
bod_u->pre_u.sen_d[1] = 0;
|
|
||||||
bod_u->pre_u.rec_d[0] = 182;
|
|
||||||
bod_u->pre_u.rec_d[1] = 0;
|
|
||||||
|
|
||||||
c3_y* str = (c3_y*)"test";
|
|
||||||
|
|
||||||
bod_u->con_y = str;
|
|
||||||
bod_u->con_s = 5;
|
|
||||||
|
|
||||||
c3_y** out_y;
|
|
||||||
|
|
||||||
//TODO fix me!
|
|
||||||
// c3_w pac_w = _ames_etch_pack(hed_u, bod_u, out_y);
|
|
||||||
|
|
||||||
// u3_head* nhed_u = c3_calloc(sizeof(*nhed_u));
|
|
||||||
// u3_body* nbod_u = c3_calloc(sizeof(*nbod_u));
|
|
||||||
// _ames_sift_head(nhed_u, *out_y);
|
|
||||||
// *out_y += 4;
|
|
||||||
// c3_y_ames_sift_body(nbod_u, *out_y);
|
|
||||||
|
|
||||||
// if( 0 != memcmp(hed_u, nhed_u, sizeof(*hed_u))) {
|
|
||||||
// fprintf(stderr, "ames: header serialisation mismatch(a)\r\n");
|
|
||||||
// exit(1);
|
|
||||||
// }
|
|
||||||
// if( 0 != memcmp(bod_u, nbod_u, sizeof(*bod_u))) {
|
|
||||||
// fprintf(stderr, "ames: body serialisation fail(a)\r\n");
|
|
||||||
// exit(1);
|
|
||||||
// } else {
|
|
||||||
// fprintf(stderr, "ames: pass (a)\r\n");
|
|
||||||
// exit(1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
/* main(): run all test cases.
|
/* main(): run all test cases.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user