]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/cypherpunks.ru/nncp/pkt.go
Humanized priorities
[nncp.git] / src / cypherpunks.ru / nncp / pkt.go
index 0e98d4beacb4c7d7483793c293e3b2fd99990134..1d1ff34bf0b082dc3bce06381513b3927372889a 100644 (file)
@@ -42,15 +42,11 @@ const (
 
        PktTypeFile PktType = iota
        PktTypeFreq PktType = iota
-       PktTypeMail PktType = iota
+       PktTypeExec PktType = iota
        PktTypeTrns PktType = iota
 
        MaxPathSize = 1<<8 - 1
 
-       DefaultNiceMail = 64
-       DefaultNiceFreq = 64
-       DefaultNiceFile = 196
-
        NNCPBundlePrefix = "NNCP"
 )
 
@@ -121,19 +117,18 @@ func init() {
        PktEncOverhead = int64(n)
 }
 
-func NewPkt(typ PktType, nice uint8, path string) (*Pkt, error) {
-       pb := []byte(path)
-       if len(pb) > MaxPathSize {
+func NewPkt(typ PktType, nice uint8, path []byte) (*Pkt, error) {
+       if len(path) > MaxPathSize {
                return nil, errors.New("Too long path")
        }
        pkt := Pkt{
                Magic:   MagicNNCPPv2,
                Type:    typ,
                Nice:    nice,
-               PathLen: uint8(len(pb)),
+               PathLen: uint8(len(path)),
                Path:    new([MaxPathSize]byte),
        }
-       copy(pkt.Path[:], pb)
+       copy(pkt.Path[:], path)
        return &pkt, nil
 }
 
@@ -175,7 +170,14 @@ func ae(keyEnc *[32]byte, r io.Reader, w io.Writer) (int, error) {
        return written, nil
 }
 
-func PktEncWrite(our *NodeOur, their *Node, pkt *Pkt, nice uint8, size, padSize int64, data io.Reader, out io.Writer) error {
+func PktEncWrite(
+       our *NodeOur,
+       their *Node,
+       pkt *Pkt,
+       nice uint8,
+       size, padSize int64,
+       data io.Reader,
+       out io.Writer) error {
        pubEph, prvEph, err := box.GenerateKey(rand.Reader)
        if err != nil {
                return err
@@ -254,7 +256,7 @@ func PktEncWrite(our *NodeOur, their *Node, pkt *Pkt, nice uint8, size, padSize
        if err != nil {
                return err
        }
-       lr := io.LimitedReader{data, size}
+       lr := io.LimitedReader{R: data, N: size}
        mr := io.MultiReader(&pktBuf, &lr)
        mw := io.MultiWriter(out, mac)
        fullSize := pktBuf.Len() + int(size)
@@ -272,7 +274,7 @@ func PktEncWrite(our *NodeOur, their *Node, pkt *Pkt, nice uint8, size, padSize
                if _, err = io.ReadFull(kdf, keyEnc[:]); err != nil {
                        return err
                }
-               lr = io.LimitedReader{DevZero{}, padSize}
+               lr = io.LimitedReader{R: DevZero{}, N: padSize}
                written, err = ae(keyEnc, &lr, out)
                if err != nil {
                        return err
@@ -299,7 +301,11 @@ func TbsVerify(our *NodeOur, their *Node, pktEnc *PktEnc) (bool, error) {
        return ed25519.Verify(their.SignPub, tbsBuf.Bytes(), pktEnc.Sign[:]), nil
 }
 
-func PktEncRead(our *NodeOur, nodes map[NodeId]*Node, data io.Reader, out io.Writer) (*Node, int64, error) {
+func PktEncRead(
+       our *NodeOur,
+       nodes map[NodeId]*Node,
+       data io.Reader,
+       out io.Writer) (*Node, int64, error) {
        var pktEnc PktEnc
        _, err := xdr.Unmarshal(data, &pktEnc)
        if err != nil {
@@ -374,7 +380,7 @@ func PktEncRead(our *NodeOur, nodes map[NodeId]*Node, data io.Reader, out io.Wri
        }
 
        fullSize := PktOverhead + size - 8 - 2*blake2b.Size256
-       lr := io.LimitedReader{data, fullSize}
+       lr := io.LimitedReader{R: data, N: fullSize}
        tr := io.TeeReader(&lr, mac)
        written, err := ae(keyEnc, tr, out)
        if err != nil {