mirror of
https://github.com/urbit/shrub.git
synced 2024-12-01 06:35:32 +03:00
ames: move etch-hunk out of the fine core
This commit is contained in:
parent
8b0bd25a45
commit
3c158b2491
@ -321,6 +321,82 @@
|
|||||||
|- ^+ b
|
|- ^+ b
|
||||||
?~ a b
|
?~ a b
|
||||||
$(a t.a, b [i.a b])
|
$(a t.a, b [i.a b])
|
||||||
|
:: +etch-hunk: helper core to serialize a $hunk
|
||||||
|
::
|
||||||
|
++ etch-hunk
|
||||||
|
|= [=ship =life =acru:ames]
|
||||||
|
|%
|
||||||
|
::
|
||||||
|
+| %helpers
|
||||||
|
:: +show-meow: prepare $meow for printing
|
||||||
|
::
|
||||||
|
++ show-meow
|
||||||
|
|= =meow
|
||||||
|
:* sig=`@q`(mug sig.meow)
|
||||||
|
num=num.meow
|
||||||
|
siz=siz.meow
|
||||||
|
dat=`@q`(mug dat.meow)
|
||||||
|
==
|
||||||
|
::
|
||||||
|
++ make-meow
|
||||||
|
|= [=path mes=@ num=@ud]
|
||||||
|
^- meow
|
||||||
|
=/ tot (met 13 mes)
|
||||||
|
=/ dat (cut 13 [(dec num) 1] mes)
|
||||||
|
=/ wid (met 3 dat)
|
||||||
|
:* sig=(sign-fra path num dat) :: fragment signature
|
||||||
|
num=tot :: number of fragments
|
||||||
|
siz=?:(=(num tot) (met 3 dat) 1.024) :: fragment byte width
|
||||||
|
dat=dat :: response data fragment
|
||||||
|
==
|
||||||
|
::
|
||||||
|
++ etch-meow
|
||||||
|
|= =meow
|
||||||
|
^- @uxmeow
|
||||||
|
%+ can 3
|
||||||
|
:~ 64^sig.meow
|
||||||
|
4^num.meow
|
||||||
|
2^siz.meow
|
||||||
|
(met 3 dat.meow)^dat.meow
|
||||||
|
==
|
||||||
|
+| %keys
|
||||||
|
::
|
||||||
|
++ sign sigh:as:acru
|
||||||
|
++ sign-fra
|
||||||
|
|= [=path fra=@ud dat=@ux]
|
||||||
|
::~> %bout.[1 %sign-fra]
|
||||||
|
(sign (jam path fra dat))
|
||||||
|
::
|
||||||
|
++ full
|
||||||
|
|= [=path data=$@(~ (cask))]
|
||||||
|
=/ buf (jam ship life path data)
|
||||||
|
::=/ nam (crip "sign-full {<(met 3 buf)>}")
|
||||||
|
::~> %bout.[1 nam]
|
||||||
|
(sign buf)
|
||||||
|
::
|
||||||
|
+| %serialization
|
||||||
|
::
|
||||||
|
++ etch
|
||||||
|
|= [=path =hunk data=$@(~ (cask))]
|
||||||
|
^- (list @uxmeow)
|
||||||
|
=/ mes=@
|
||||||
|
=/ sig=@ (full path data)
|
||||||
|
?~ data sig
|
||||||
|
(mix sig (lsh 9 (jam data)))
|
||||||
|
::(cat 9 sig (jam data))
|
||||||
|
::
|
||||||
|
=/ las (met 13 mes)
|
||||||
|
=/ tip (dec (add [lop len]:hunk))
|
||||||
|
=/ top (min las tip)
|
||||||
|
=/ num lop.hunk
|
||||||
|
?> (lte num top)
|
||||||
|
=| res=(list @uxmeow)
|
||||||
|
|- ^+ res
|
||||||
|
?: =(num top)
|
||||||
|
=- (flop - res)
|
||||||
|
(etch-meow (make-meow path mes num))
|
||||||
|
$(num +(num), res :_(res (etch-meow (make-meow path mes num))))
|
||||||
|
--
|
||||||
:: +etch-open-packet: convert $open-packet attestation to $shot
|
:: +etch-open-packet: convert $open-packet attestation to $shot
|
||||||
::
|
::
|
||||||
++ etch-open-packet
|
++ etch-open-packet
|
||||||
@ -643,7 +719,6 @@
|
|||||||
$: peers=(map ship ship-state-12)
|
$: peers=(map ship ship-state-12)
|
||||||
=unix=duct
|
=unix=duct
|
||||||
=life
|
=life
|
||||||
:: =rift
|
|
||||||
crypto-core=acru-12
|
crypto-core=acru-12
|
||||||
=bug
|
=bug
|
||||||
snub=[form=?(%allow %deny) ships=(set ship)]
|
snub=[form=?(%allow %deny) ships=(set ship)]
|
||||||
@ -2216,7 +2291,6 @@
|
|||||||
=/ =channel [[our ship] now channel-state -.peer-state]
|
=/ =channel [[our ship] now channel-state -.peer-state]
|
||||||
=/ peer-core (pe peer-state channel)
|
=/ peer-core (pe peer-state channel)
|
||||||
fi-abet:(on-pine:fi:peer-core path duct)
|
fi-abet:(on-pine:fi:peer-core path duct)
|
||||||
|
|
||||||
:: XX: crashing correct behaviour?
|
:: XX: crashing correct behaviour?
|
||||||
=+ blk=(need (de-part:balk our rift.ames-state life.ames-state path))
|
=+ blk=(need (de-part:balk our rift.ames-state life.ames-state path))
|
||||||
?> ?=(%c van.blk)
|
?> ?=(%c van.blk)
|
||||||
@ -3714,7 +3788,66 @@
|
|||||||
:: XX TODO rethink core naming/structure to follow current ames
|
:: XX TODO rethink core naming/structure to follow current ames
|
||||||
::
|
::
|
||||||
++ fi
|
++ fi
|
||||||
=< |%
|
=> |%
|
||||||
|
::
|
||||||
|
++ orm ((on @ud keen-state) lte)
|
||||||
|
:: +gum: glue together a list of $byts into one
|
||||||
|
::
|
||||||
|
:: TODO: move to hoon.hoon (see +cad in lib/tiny)
|
||||||
|
::
|
||||||
|
++ gum
|
||||||
|
::~/ %gum
|
||||||
|
|= biz=(list byts)
|
||||||
|
^- byts
|
||||||
|
:- (roll biz |=([[wid=@ *] acc=@] (add wid acc)))
|
||||||
|
(can 3 biz)
|
||||||
|
::
|
||||||
|
++ etch-peep
|
||||||
|
|= [=path num=@ud]
|
||||||
|
^- byts
|
||||||
|
?> (lth num (bex 32))
|
||||||
|
=+ (spit path)
|
||||||
|
%- gum
|
||||||
|
:~ 4^num :: fragment number
|
||||||
|
2^wid :: path size
|
||||||
|
wid^`@`pat :: namespace path
|
||||||
|
==
|
||||||
|
::
|
||||||
|
++ etch-keen
|
||||||
|
|= [=path num=@ud]
|
||||||
|
^- hoot ^- @
|
||||||
|
=/ sic (mod life.ames-state 16)
|
||||||
|
=/ ric (mod life.peer-state 16)
|
||||||
|
=/ syn
|
||||||
|
=/ bod (etch-peep path num)
|
||||||
|
=/ sig 64^(sign:keys dat.bod)
|
||||||
|
(can 3 sig bod ~)
|
||||||
|
(etch-shot [our her] req=& sam=| sic ric ~ syn)
|
||||||
|
::
|
||||||
|
++ keys
|
||||||
|
|%
|
||||||
|
++ mess
|
||||||
|
|= [=ship life=@ud =path dat=$@(~ (cask))]
|
||||||
|
(jam +<)
|
||||||
|
::
|
||||||
|
++ sign sigh:as:crypto-core.ames-state
|
||||||
|
::
|
||||||
|
++ veri-fra
|
||||||
|
|= [=path fra=@ud dat=@ux sig=@]
|
||||||
|
(veri sig (jam path fra dat))
|
||||||
|
::
|
||||||
|
++ veri
|
||||||
|
|= [sig=@ dat=@]
|
||||||
|
^- ?
|
||||||
|
(safe:as:(com:nu:crub:crypto public-key.peer-state) sig dat)
|
||||||
|
::
|
||||||
|
++ meri
|
||||||
|
|= [pax=path sig=@ dat=$@(~ (cask))]
|
||||||
|
(veri sig (mess her life.peer-state pax dat))
|
||||||
|
--
|
||||||
|
--
|
||||||
|
::
|
||||||
|
|%
|
||||||
::
|
::
|
||||||
+| %helpers
|
+| %helpers
|
||||||
::
|
::
|
||||||
@ -3848,7 +3981,7 @@
|
|||||||
::
|
::
|
||||||
++ ke-etch-keen
|
++ ke-etch-keen
|
||||||
|= frag=@ud
|
|= frag=@ud
|
||||||
(etch-keen her ke-full-path frag)
|
(etch-keen ke-full-path frag)
|
||||||
::
|
::
|
||||||
++ ke-on-ack
|
++ ke-on-ack
|
||||||
=| marked=(list want)
|
=| marked=(list want)
|
||||||
@ -3891,7 +4024,7 @@
|
|||||||
::
|
::
|
||||||
++ ke-done
|
++ ke-done
|
||||||
|= [sig=@ data=$@(~ (cask))]
|
|= [sig=@ data=$@(~ (cask))]
|
||||||
?> (meri:keys her life.peer-state ke-full-path sig data)
|
?> (meri:keys ke-full-path sig data)
|
||||||
~> %slog.0^leaf/"fine: done {(spud ke-full-path)}"
|
~> %slog.0^leaf/"fine: done {(spud ke-full-path)}"
|
||||||
=/ listeners ~(tap in listeners.keen)
|
=/ listeners ~(tap in listeners.keen)
|
||||||
=/ dat=(unit (cask))
|
=/ dat=(unit (cask))
|
||||||
@ -3985,8 +4118,7 @@
|
|||||||
?. =(`rift.peer-state (slaw %ud i.t.full-path))
|
?. =(`rift.peer-state (slaw %ud i.t.full-path))
|
||||||
~| fine-path-bunk-rift+[full-path rift.peer-state]
|
~| fine-path-bunk-rift+[full-path rift.peer-state]
|
||||||
!!
|
!!
|
||||||
?. %- veri-fra:keys
|
?. (veri-fra:keys [full-path num [dat sig]:meow])
|
||||||
[her life.peer-state full-path num [dat sig]:meow]
|
|
||||||
~| fine-purr-fail-signature/num^`@ux`sig.meow
|
~| fine-purr-fail-signature/num^`@ux`sig.meow
|
||||||
~| life.peer-state
|
~| life.peer-state
|
||||||
!!
|
!!
|
||||||
@ -4075,151 +4207,6 @@
|
|||||||
(ke-send hoot.u.want)
|
(ke-send hoot.u.want)
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
|%
|
|
||||||
::
|
|
||||||
++ orm ((on @ud keen-state) lte)
|
|
||||||
:: +gum: glue together a list of $byts into one
|
|
||||||
::
|
|
||||||
:: TODO: move to hoon.hoon (see +cad in lib/tiny)
|
|
||||||
::
|
|
||||||
++ gum
|
|
||||||
::~/ %gum
|
|
||||||
|= biz=(list byts)
|
|
||||||
^- byts
|
|
||||||
:- (roll biz |=([[wid=@ *] acc=@] (add wid acc)))
|
|
||||||
(can 3 biz)
|
|
||||||
::
|
|
||||||
++ etch-peep
|
|
||||||
|= [=path num=@ud]
|
|
||||||
^- byts
|
|
||||||
?> (lth num (bex 32))
|
|
||||||
=+ (spit path)
|
|
||||||
%- gum
|
|
||||||
:~ 4^num :: fragment number
|
|
||||||
2^wid :: path size
|
|
||||||
wid^`@`pat :: namespace path
|
|
||||||
==
|
|
||||||
:: +show-meow: prepare $meow for printing
|
|
||||||
::
|
|
||||||
++ show-meow
|
|
||||||
|= =meow
|
|
||||||
:* sig=`@q`(mug sig.meow)
|
|
||||||
num=num.meow
|
|
||||||
siz=siz.meow
|
|
||||||
dat=`@q`(mug dat.meow)
|
|
||||||
==
|
|
||||||
::
|
|
||||||
++ make-meow
|
|
||||||
|= [=path mes=@ num=@ud]
|
|
||||||
^- meow
|
|
||||||
=/ tot (met 13 mes)
|
|
||||||
=/ dat (cut 13 [(dec num) 1] mes)
|
|
||||||
=/ wid (met 3 dat)
|
|
||||||
:* sig=(sign-fra:keys path num dat) :: fragment signature
|
|
||||||
num=tot :: number of fragments
|
|
||||||
siz=?:(=(num tot) (met 3 dat) 1.024) :: fragment byte width
|
|
||||||
dat=dat :: response data fragment
|
|
||||||
==
|
|
||||||
::
|
|
||||||
++ etch-meow
|
|
||||||
|= =meow
|
|
||||||
^- @uxmeow
|
|
||||||
%+ can 3
|
|
||||||
:~ 64^sig.meow
|
|
||||||
4^num.meow
|
|
||||||
2^siz.meow
|
|
||||||
(met 3 dat.meow)^dat.meow
|
|
||||||
==
|
|
||||||
::
|
|
||||||
++ etch-keen
|
|
||||||
|= [=ship =path num=@ud]
|
|
||||||
^- hoot ^- @
|
|
||||||
=/ sic (mod life.ames-state 16)
|
|
||||||
=/ ric (mod (lyfe:keys ship) 16)
|
|
||||||
=/ syn
|
|
||||||
=/ bod (etch-peep path num)
|
|
||||||
=/ sig 64^(sign:keys dat.bod)
|
|
||||||
(can 3 sig bod ~)
|
|
||||||
(etch-shot [our ship] req=& sam=| sic ric ~ syn)
|
|
||||||
::
|
|
||||||
++ etch-hunk
|
|
||||||
|= [=path =hunk data=$@(~ (cask))]
|
|
||||||
^- (list @uxmeow)
|
|
||||||
=/ mes=@
|
|
||||||
=/ sig=@ (full:keys path data)
|
|
||||||
?~ data sig
|
|
||||||
(mix sig (lsh 9 (jam data)))
|
|
||||||
::(cat 9 sig (jam data))
|
|
||||||
::
|
|
||||||
=/ las (met 13 mes)
|
|
||||||
=/ tip (dec (add [lop len]:hunk))
|
|
||||||
=/ top (min las tip)
|
|
||||||
=/ num lop.hunk
|
|
||||||
?> (lte num top)
|
|
||||||
=| res=(list @uxmeow)
|
|
||||||
|- ^+ res
|
|
||||||
?: =(num top)
|
|
||||||
=- (flop - res)
|
|
||||||
(etch-meow (make-meow path mes num))
|
|
||||||
$(num +(num), res :_(res (etch-meow (make-meow path mes num))))
|
|
||||||
::
|
|
||||||
++ keys
|
|
||||||
|%
|
|
||||||
++ mess
|
|
||||||
|= [=ship life=@ud =path dat=$@(~ (cask))]
|
|
||||||
(jam +<)
|
|
||||||
::
|
|
||||||
++ full
|
|
||||||
|= [=path data=$@(~ (cask))]
|
|
||||||
=/ buf (mess our life.ames-state path data)
|
|
||||||
::=/ nam (crip "sign-full {<(met 3 buf)>}")
|
|
||||||
::~> %bout.[1 nam]
|
|
||||||
(sign buf)
|
|
||||||
::
|
|
||||||
++ frag
|
|
||||||
|= [=path fra=@ud dat=@ux]
|
|
||||||
(jam +<)
|
|
||||||
::
|
|
||||||
++ sign-fra
|
|
||||||
|= [=path fra=@ud dat=@ux]
|
|
||||||
::~> %bout.[1 %sign-fra]
|
|
||||||
(sign (frag path fra dat))
|
|
||||||
::
|
|
||||||
++ veri-fra
|
|
||||||
|= [who=ship lyf=life =path fra=@ud dat=@ux sig=@]
|
|
||||||
(veri who lyf sig (frag path fra dat))
|
|
||||||
::
|
|
||||||
++ sign
|
|
||||||
sigh:as:crypto-core.ames-state
|
|
||||||
::
|
|
||||||
++ lyfe :: XX remove
|
|
||||||
|= who=ship
|
|
||||||
^- life
|
|
||||||
~| [%fine %unknown-peer who]
|
|
||||||
=/ ship-state (~(got by peers.ames-state) who)
|
|
||||||
?> ?=([%known *] ship-state)
|
|
||||||
life.ship-state
|
|
||||||
::
|
|
||||||
++ pass :: XX remove
|
|
||||||
|= [who=ship lyf=life]
|
|
||||||
~| [%fine %unknown-peer who lyf]
|
|
||||||
=/ ship-state (~(got by peers.ames-state) who)
|
|
||||||
?> ?=([%known *] ship-state)
|
|
||||||
~| [%fine %life-mismatch who lyf]
|
|
||||||
?> =(lyf life.ship-state)
|
|
||||||
public-key.ship-state
|
|
||||||
::
|
|
||||||
++ veri
|
|
||||||
|= [who=ship lyf=life sig=@ dat=@]
|
|
||||||
^- ?
|
|
||||||
=/ =^pass (pass who lyf)
|
|
||||||
(safe:as:(com:nu:crub:crypto pass) sig dat)
|
|
||||||
::
|
|
||||||
++ meri
|
|
||||||
|= [who=ship lyf=life pax=path sig=@ dat=$@(~ (cask))]
|
|
||||||
(veri who lyf sig (mess who lyf pax dat))
|
|
||||||
--
|
|
||||||
--
|
|
||||||
:: +ga: construct |pump-gauge congestion control core
|
:: +ga: construct |pump-gauge congestion control core
|
||||||
::
|
::
|
||||||
++ ga
|
++ ga
|
||||||
@ -4725,14 +4712,12 @@
|
|||||||
?. =([%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)]
|
=/ =hunk [(slav %ud lop.tyl) (slav %ud len.tyl)]
|
||||||
::TODO suggests we need to factor differently
|
|
||||||
::
|
::
|
||||||
=/ ev-co (ev [now 0v0 rof] *duct ames-state)
|
=/ hu-co (etch-hunk our [life crypto-core]:ames-state)
|
||||||
=/ fin fi:(pe:ev-co *peer-state *channel)
|
|
||||||
?- res
|
?- res
|
||||||
~ ~
|
~ ~
|
||||||
[~ ~] ``noun+!>((etch-hunk:fin pax.tyl hunk ~))
|
[~ ~] ``noun+!>((etch:hu-co pax.tyl hunk ~))
|
||||||
[~ ~ *] ``noun+!>((etch-hunk:fin pax.tyl hunk [p q.q]:u.u.res))
|
[~ ~ *] ``noun+!>((etch:hu-co pax.tyl hunk [p q.q]:u.u.res))
|
||||||
==
|
==
|
||||||
==
|
==
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user