Files
zeekayandHanzo Dev 37e2940ead mesh is the peer layer, network is the validator set
Two packages were named for the same word and meant different things. network/
dialed peers, exchanged keys, throttled and tracked them; nets/ tracked which
chains share a validator set and when they have all bootstrapped. One letter
apart, and neither name said which was which.

The peer layer is mesh — the word this estate already uses for it, in
lux-rs/node's own mesh.rs. That frees network for the thing that is actually a
network: a set of chains sharing a validator set. A network holds chains; a
chain belongs to one network.

github.com/luxfi/p2p stays what it is, the gossip library the VMs use. Three
concerns, three names, none of them borrowed from another.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-07 21:17:09 -07:00

57 lines
1.2 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package peer
import (
"encoding/binary"
"errors"
"fmt"
"github.com/luxfi/node/utils/wrappers"
)
var (
errInvalidMessageLength = errors.New("invalid message length")
errMaxMessageLengthExceeded = errors.New("maximum message length exceeded")
)
func writeMsgLen(msgLen uint32, maxMsgLen uint32) ([wrappers.IntLen]byte, error) {
if msgLen > maxMsgLen {
return [wrappers.IntLen]byte{}, fmt.Errorf(
"%w; the message length %d exceeds the specified limit %d",
errMaxMessageLengthExceeded,
msgLen,
maxMsgLen,
)
}
b := [wrappers.IntLen]byte{}
binary.BigEndian.PutUint32(b[:], msgLen)
return b, nil
}
func readMsgLen(b []byte, maxMsgLen uint32) (uint32, error) {
if len(b) != wrappers.IntLen {
return 0, fmt.Errorf(
"%w; readMsgLen only supports 4 bytes (got %d bytes)",
errInvalidMessageLength,
len(b),
)
}
// parse the message length
msgLen := binary.BigEndian.Uint32(b)
if msgLen > maxMsgLen {
return 0, fmt.Errorf(
"%w; the message length %d exceeds the specified limit %d",
errMaxMessageLengthExceeded,
msgLen,
maxMsgLen,
)
}
return msgLen, nil
}