utils

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 22 Imported by: 12

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

View Source
var NTPServer = "pool.ntp.org"

Functions

func DecodeHexString

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

func EcdsaPrivKeyToSecp256k1PrivKey

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

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

func EcdsaPubKeyToSecp256k1PublicKey

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 GetNTPMetadata

func GetNTPMetadata() (*ntp.Response, error)

func GetNTPTime

func GetNTPTime() (time.Time, error)

func GetTimeOffset

func GetTimeOffset() (time.Duration, error)

func GetUnixEpoch

func GetUnixEpoch(timesource ...Timesource) int64

GetUnixEpoch returns the current time in unix timestamp with the integer part representing seconds and the decimal part representing subseconds. Optionally receives a timesource to obtain the time from

func GetUnixEpochFrom

func GetUnixEpochFrom(now time.Time) int64

GetUnixEpochFrom converts a time into a unix timestamp with nanoseconds

func InitLogger

func InitLogger(encoding string, output 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) (peer.ID, []multiaddr.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 protocol.ID, specificPeers []peer.ID, log *zap.Logger) (peer.ID, error)

SelectPeer is used to return a random peer that supports a given protocol. If a list of specific peers is passed, the peer will be chosen from that list assuming it supports the chosen protocol, otherwise it will chose a peer from the node peerstore

func SelectPeerWithLowestRTT

func SelectPeerWithLowestRTT(ctx context.Context, host host.Host, protocolId protocol.ID, specificPeers []peer.ID, log *zap.Logger) (peer.ID, error)

SelectPeerWithLowestRTT will select a peer that supports a specific protocol with the lowest reply time If a list of specific peers is passed, the peer will be chosen from that list assuming it supports the chosen protocol, otherwise it will chose a peer from the node peerstore

Types

type Timesource

type Timesource interface {
	Now() time.Time
}

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