utils

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const MultiaddrENRField = "multiaddrs"

MultiaddrENRField is the name of the ENR field that will contain multiaddresses that cannot be described using the already available ENR fields (i.e. in the case of websocket connections)

View Source
const WakuENRField = "waku2"

WakuENRField is the name of the ENR field that contains information about which protocols are supported by the node

Variables

View Source
var ErrNoPeersAvailable = errors.New("no suitable peers found")

ErrNoPeersAvailable is emitted when no suitable peers are found for some protocol

Functions

func DecodeHexString added in v0.2.2

func DecodeHexString(input string) ([]byte, error)

func EcdsaPrivKeyToSecp256k1PrivKey added in v0.1.0

func EcdsaPrivKeyToSecp256k1PrivKey(privKey *ecdsa.PrivateKey) *crypto.Secp256k1PrivateKey

EcdsaPubKeyToSecp256k1PublicKey converts an `ecdsa.PrivateKey` into a libp2p `crypto.Secp256k1PrivateKey“

func EcdsaPubKeyToSecp256k1PublicKey added in v0.1.0

func EcdsaPubKeyToSecp256k1PublicKey(pubKey *ecdsa.PublicKey) *crypto.Secp256k1PublicKey

EcdsaPubKeyToSecp256k1PublicKey converts an `ecdsa.PublicKey` into a libp2p `crypto.Secp256k1PublicKey“

func EnodeToPeerInfo

func EnodeToPeerInfo(node *enode.Node) (*peer.AddrInfo, error)

EnodeToPeerInfo extracts the peer ID and multiaddresses defined in an ENR

func GetENRandIP

func GetENRandIP(addr ma.Multiaddr, wakuFlags WakuEnrBitfield, privK *ecdsa.PrivateKey) (*enode.Node, *net.TCPAddr, error)

GetENRandIP returns a enr Node and TCP address obtained from a multiaddress. priv key and protocols supported

func GetUnixEpoch

func GetUnixEpoch() int64

GetUnixEpoch returns the current time in unix timestamp with the integer part representing seconds and the decimal part representing subseconds

func GetUnixEpochFrom

func GetUnixEpochFrom(now time.Time) int64

GetUnixEpochFrom converts a time into a unix timestamp with nanoseconds

func InitLogger added in v0.1.0

func InitLogger(encoding string)

InitLogger initializes a global logger using an specific encoding

func Logger

func Logger() *zap.Logger

Logger creates a zap.Logger with some reasonable defaults

func Multiaddress

func Multiaddress(node *enode.Node) ([]ma.Multiaddr, error)

Multiaddress is used to extract all the multiaddresses that are part of a ENR record

func SelectPeer

func SelectPeer(host host.Host, protocolId string, log *zap.Logger) (*peer.ID, error)

SelectPeer is used to return a random peer that supports a given protocol.

func SelectPeerWithLowestRTT

func SelectPeerWithLowestRTT(ctx context.Context, host host.Host, protocolId string, log *zap.Logger) (*peer.ID, error)

SelectPeerWithLowestRTT will select a peer that supports a specific protocol with the lowest reply time

func SetLogLevel

func SetLogLevel(level string) error

SetLogLevel sets a custom log level

Types

type WakuEnrBitfield

type WakuEnrBitfield = uint8

WakuEnrBitfield is a8-bit flag field to indicate Waku capabilities. Only the 4 LSBs are currently defined according to RFC31 (https://rfc.vac.dev/spec/31/).

func NewWakuEnrBitfield

func NewWakuEnrBitfield(lightpush, filter, store, relay bool) WakuEnrBitfield

NewWakuEnrBitfield creates a WakuEnrBitField whose value will depend on which protocols are enabled in the node

Jump to

Keyboard shortcuts

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