util

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConverMultiaddrsToStrings added in v1.3.0

func ConverMultiaddrsToStrings(multiaddrs []ma.Multiaddr) []string

ConverMultiaddrsToStrings converts multiaddr to a string

func ConverStringsToMultiaddrs added in v1.3.0

func ConverStringsToMultiaddrs(addrs []string) []ma.Multiaddr

ConverStringsToMultiaddrs converts string to a multiaddr

func CreateMultiAddrWithPid

func CreateMultiAddrWithPid(pid peer.ID) ma.Multiaddr

CreateMultiAddrWithPid parse a peer.ID to p2p multiaddr. For example, "QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4" -->> "/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4"

func CreateMultiAddrWithPidAndNetAddr

func CreateMultiAddrWithPidAndNetAddr(pid peer.ID, netAddr ma.Multiaddr) ma.Multiaddr

CreateMultiAddrWithPidAndNetAddr will parse the peer.ID to p2p multiaddr then join the net addr with it. For example, "QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4" & "/ip4/127.0.0.1/tcp/8080" -->> "/ip4/127.0.0.1/tcp/8080/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4"

func CreateMultiAddrWithPidAndNetAddrSlice added in v1.3.0

func CreateMultiAddrWithPidAndNetAddrSlice(pid peer.ID, netAddr []ma.Multiaddr) []ma.Multiaddr

CreateMultiAddrWithPidAndNetAddrSlice will parse the peer.ID to p2p multiaddr then join the net addr with it. For example, "QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4" & "/ip4/127.0.0.1/tcp/8080" -->> "/ip4/127.0.0.1/tcp/8080/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4"

func GetLocalAddrs

func GetLocalAddrs() ([]net.Addr, error)

GetLocalAddrs return a list of net.Addr can be used that bound in each net interfaces.

func GetNetAddrAndPidFromNormalMultiAddr

func GetNetAddrAndPidFromNormalMultiAddr(addr ma.Multiaddr) (ma.Multiaddr, peer.ID)

GetNetAddrAndPidFromNormalMultiAddr resolves a NetAddr and a peer.ID from addr given. For example, if addr is "/ip4/127.0.0.1/tcp/8080/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4", will return "/ip4/127.0.0.1/tcp/8080" as net addr and "QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4" as peer.ID. If addr is "/ip4/127.0.0.1/tcp/8080", will return "/ip4/127.0.0.1/tcp/8080" as net addr and "" as peer.ID.

func IsConnClosedError

func IsConnClosedError(err error) bool

IsConnClosedError return true if the info of err contains closed strings.

func IsNetError

func IsNetError(err error) (net.Error, bool)

IsNetError parse an error to a net.Error if it is an implementation of net.Error interface.

func IsNetErrorTemporary

func IsNetErrorTemporary(err error) bool

IsNetErrorTemporary return the value of err.Temporary() if err is a net.Error. If err is not a net.Error, return false.

func IsNetErrorTimeout

func IsNetErrorTimeout(err error) bool

IsNetErrorTimeout return the value of err.Timeout() if err is a net.Error. If err is not a net.Error, return false.

func ParseErrsToStr

func ParseErrsToStr(errs []error) string

ParseErrsToStr convert error message to string form

func ReadPackageData

func ReadPackageData(stream network.ReceiveStream, length uint64) ([]byte, error)

ReadPackageData will read some bytes from network.ReceiveStream. The length is the size of bytes will be read.

func ReadPackageLength

func ReadPackageLength(stream network.ReceiveStream) (uint64, []byte, error)

ReadPackageLength will read 8 bytes from network.ReceiveStream, then parse these bytes to an uint64 value.

func ResolvePIDFromCertDER

func ResolvePIDFromCertDER(der []byte) (peer.ID, error)

ResolvePIDFromCertDER load the peer.ID from cert der bytes.

func ResolvePIDFromPubKey

func ResolvePIDFromPubKey(pubKey crypto.PublicKey) (peer.ID, error)

ResolvePIDFromPubKey create a peer.ID with a crypto.PublicKey.

Types

This section is empty.

Jump to

Keyboard shortcuts

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