bzz

package
v2.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2026 License: BSD-3-Clause Imports: 14 Imported by: 6

Documentation

Overview

Package bzz exposes the data structure and operations necessary on the bzz.Address type which used in the handshake protocol, address-book and hive protocol.

Index

Constants

View Source
const (
	MaxClockSkew          = 60 * time.Second
	MinimumUpdateInterval = 300 * time.Second
)
View Source
const NonceLength = 32

Variables

View Source
var (
	ErrTimestampInvalid  = errors.New("bzz: timestamp must be positive")
	ErrTimestampInFuture = errors.New("bzz: timestamp in future")
	ErrTimestampStale    = errors.New("bzz: timestamp not newer than existing")
	ErrTimestampTooSoon  = errors.New("bzz: timestamp within minimum update interval")
)
View Source
var (
	// ErrUnderlayByteSizeExceeded is returned when the serialized underlay data
	// exceeds the maximum allowed byte size.
	ErrUnderlayByteSizeExceeded = errors.New("underlay byte size exceeded")

	// ErrUnderlayCountExceeded is returned when the number of underlay addresses
	// exceeds the maximum allowed per peer.
	ErrUnderlayCountExceeded = errors.New("underlay count exceeded")
)
View Source
var ErrInvalidAddress = errors.New("invalid address")

Functions

func AreUnderlaysEqual added in v2.7.0

func AreUnderlaysEqual(a, b []ma.Multiaddr) bool

func CheckTimestamp added in v2.8.0

func CheckTimestamp(newTimestamp int64, existing *Address, source TimestampSource, now time.Time) error

CheckTimestamp validates a newly received record's timestamp against an existing stored record. existing is nil when no prior record is held for the overlay. Semantics follow issue #6:

  • wire records must carry a strictly-positive Timestamp (zero and negative values are rejected);
  • records with a timestamp more than MaxClockSkew in the future are rejected;
  • first-time records are accepted;
  • an existing stored record with Timestamp == 0 (legacy, pre-timestamp) is overwritten by any received record (which is guaranteed > 0);
  • handshake records are rejected as stale only when strictly older than the existing record. Equal timestamps are accepted (re-presentation of the peer's current record during reconnect is benign);
  • gossip records must be strictly newer than existing, and additionally must exceed the existing Timestamp by at least MinimumUpdateInterval.

func ContainsAddress

func ContainsAddress(addrs []Address, a *Address) bool

ContainsAddress reports whether a is present in addrs.

func DeserializeUnderlays added in v2.7.0

func DeserializeUnderlays(data []byte) ([]multiaddr.Multiaddr, error)

DeserializeUnderlays deserializes a byte slice into a slice of multiaddrs. The data format is automatically detected as either a single legacy multiaddr or a list of multiaddrs (identified by underlayListPrefix), and is parsed accordingly.

func SelectBestAdvertisedAddress added in v2.7.0

func SelectBestAdvertisedAddress(addrs []ma.Multiaddr, fallback ma.Multiaddr) ma.Multiaddr

func SerializeUnderlays added in v2.7.0

func SerializeUnderlays(addrs []multiaddr.Multiaddr) ([]byte, error)

SerializeUnderlays serializes a slice of multiaddrs into a single byte slice. If the slice contains exactly one address, the standard, backward-compatible multiaddr format is used. For zero or more than one address, a custom list format prefixed with a magic byte is utilized. Returns an error wrapping ErrUnderlayCountExceeded or ErrUnderlayByteSizeExceeded if the limits are violated.

func SortUnderlaysByPriority added in v2.8.0

func SortUnderlaysByPriority(addrs []ma.Multiaddr) []ma.Multiaddr

SortUnderlaysByPriority returns a copy of the addresses sorted by priority. Priority: IPv4 public TCP first, then by transport, then private, then IPv6.

func TimestampErrorLabel added in v2.8.0

func TimestampErrorLabel(err error) (string, bool)

TimestampErrorLabel returns the metric label for a CheckTimestamp error, or ("", false) if err is not a timestamp sentinel.

func TruncateUnderlays added in v2.8.0

func TruncateUnderlays(addrs []ma.Multiaddr) ([]ma.Multiaddr, bool)

TruncateUnderlays sorts addresses by priority and truncates to fit within maxUnderlaysPerPeer count and maxUnderlayBytes byte budget. It returns true as the second value if truncation occurred.

Types

type Address

type Address struct {
	Underlays         []ma.Multiaddr
	Overlay           swarm.Address
	Signature         []byte
	Nonce             []byte
	Timestamp         int64
	EthereumAddress   []byte
	ChequebookAddress common.Address
}

Address represents the bzz address in swarm. It consists of a peers underlay (physical) address, overlay (topology) address and signature. Signature is used to verify the `Overlay/Underlay` pair, as it is based on `underlay|networkID|nonce|timestamp|chequebook`, signed with the public key of Overlay address.

func NewAddress

func NewAddress(signer crypto.Signer, underlays []ma.Multiaddr, overlay swarm.Address, networkID uint64, nonce []byte, timestamp int64, chequebookAddress common.Address) (*Address, error)

func ParseAddress

func ParseAddress(underlay, overlay, signature, nonce []byte, timestamp int64, networkID uint64, chequebookAddress []byte) (*Address, error)

ParseAddress validates a wire-encoded BzzAddress. The chequebook bytes must be either empty or exactly common.AddressLength — other lengths would be silently truncated or left-padded by common.BytesToAddress.

func (*Address) Equal

func (a *Address) Equal(b *Address) bool

func (*Address) MarshalJSON

func (a *Address) MarshalJSON() ([]byte, error)

func (*Address) ShortString

func (a *Address) ShortString() string

ShortString returns shortened versions of bzz address in a format: [Overlay, Underlay] It can be used for logging

func (*Address) String

func (a *Address) String() string

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(b []byte) error

type TimestampSource added in v2.8.0

type TimestampSource int
const (
	TimestampSourceHandshake TimestampSource = iota
	TimestampSourceGossip
)

type TransportType added in v2.7.1

type TransportType int

TransportType represents the transport protocol of a multiaddress.

const (
	// TransportUnknown indicates an unrecognized transport.
	TransportUnknown TransportType = iota
	// TransportTCP indicates plain TCP without WebSocket.
	TransportTCP
	// TransportWS indicates WebSocket without TLS.
	TransportWS
	// TransportWSS indicates WebSocket with TLS (secure).
	TransportWSS
)

func ClassifyTransport added in v2.7.1

func ClassifyTransport(addr ma.Multiaddr) TransportType

ClassifyTransport returns the transport type of a multiaddress. It distinguishes between plain TCP, WebSocket (WS), and secure WebSocket (WSS).

func (TransportType) Priority added in v2.7.1

func (t TransportType) Priority() int

Priority returns the sorting priority for the transport type. Lower value = higher priority: TCP (0) > WS (1) > WSS (2) > Unknown (3)

func (TransportType) String added in v2.7.1

func (t TransportType) String() string

String returns a string representation of the transport type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL