util

package
v0.0.0-...-d151d1d Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckClosedConnectionWithErr

func CheckClosedConnectionWithErr(conn network.Connection, err error) bool

CheckClosedConnectionWithErr checks if the network connection is closed based on the provided error. It returns true if the error indicates a timeout, a closed connection error, or if the connection itself is closed. Otherwise, it returns false.

func ContainsDNS

func ContainsDNS(addr ma.Multiaddr) bool

ContainsDNS returns true if the given address contains the DNS protocol, otherwise returns false

func ConvertProtocolIDsToStrArr

func ConvertProtocolIDsToStrArr(protocols ...protocol.ID) []string

ConvertProtocolIDsToStrArr converts an array of protocol.IDs to an array of strings.

func ConvertStrArrToProtocolIDs

func ConvertStrArrToProtocolIDs(strArr ...string) []protocol.ID

ConvertStrArrToProtocolIDs converts an array of strings to an array of protocol.IDs.

func EasyToUsePIDLoader

func EasyToUsePIDLoader(certs []*x509.Certificate) (peer.ID, error)

EasyToUsePIDLoader generates a peer ID based on the provided certificate chain. It extracts the public key from the certificate chain using PubKeyFromCertChain(), and then uses the extracted public key to generate a peer ID using peer.IDFromPubKey(). It returns the generated peer ID.

func EasyToUseTLSConfig

func EasyToUseTLSConfig(sk cc.PriKey, certTemplate *x509.Certificate) (*tls.Config, error)

EasyToUseTLSConfig generates a TLS configuration based on the provided private key and certificate template. If the certificate template is nil, it generates a new one using tlsCertTemplate(). It returns a *tls.Config that can be used to configure TLS settings for a server or client.

func ExcludeUnspecifiedAndLoopBack

func ExcludeUnspecifiedAndLoopBack(addresses []ma.Multiaddr) []ma.Multiaddr

ExcludeUnspecifiedAndLoopBack filters out unspecified and loopback addresses from the given list.

func GenerateSignedExtension

func GenerateSignedExtension(sk cc.PriKey, pubKey crypto.PublicKey) (pkix.Extension, error)

GenerateSignedExtension uses the provided private key to sign the public key, and returns the signature within a pkix.Extension. This extension is included in a certificate to cryptographically tie it to the rainbow-bee private key.

func IsConnClosedError

func IsConnClosedError(err error) bool

IsConnClosedError checks if the provided error corresponds to a closed connection error. It checks if the error string contains specific substrings that commonly indicate a closed connection. It returns true if the error represents a closed connection, and false otherwise.

func IsNetErrorTimeout

func IsNetErrorTimeout(err error) bool

IsNetErrorTimeout checks if the provided error is a network error and specifically a timeout error. It uses the NetError function to obtain the net.Error value and checks if the error's Timeout() method returns true. It returns true if the error represents a network timeout, and false otherwise.

func NetError

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

NetError checks if the provided error implements the net.Error interface. It returns the net.Error value and true if the error implements the interface. Otherwise, it returns nil and false.

func PIDAndNetAddrToMultiAddr

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

PIDAndNetAddrToMultiAddr joins the peer.ID's p2p multiaddress with the given network address. For example, "QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4" and "/ip4/127.0.0.1/tcp/8080" become "/ip4/127.0.0.1/tcp/8080/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4".

func PIDToMultiAddr

func PIDToMultiAddr(pid peer.ID) ma.Multiaddr

PIDToMultiAddr converts a peer.ID to a p2p multiaddress. For example, "QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4" becomes "/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4".

func PubKeyFromCertChain

func PubKeyFromCertChain(chain []*x509.Certificate) (cc.PubKey, error)

PubKeyFromCertChain verifies the certificate chain and extract the remote's public key.

func ReadPackageData

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

ReadPackageData reads the specified length of data from the receive stream. It reads the data in batches of defaultBatchSize (4KB) to optimize performance. Returns the read data and any error encountered.

func ReadPackageLength

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

ReadPackageLength reads the package length from the receive stream. It expects the length to be encoded as 8 bytes in big-endian format. Returns the package length, the length bytes, and any error encountered.

func SplitAddrToTransportAndPID

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

SplitAddrToTransportAndPID resolves a network address and peer.ID from the given multiaddress. For example, if the multiaddress is "/ip4/127.0.0.1/tcp/8080/p2p/QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4", it returns "/ip4/127.0.0.1/tcp/8080" as the network address and "QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4" as the peer.ID. If the multiaddress is "/ip4/127.0.0.1/tcp/8080", it returns "/ip4/127.0.0.1/tcp/8080" as the network address and an empty string as the peer.ID.

Types

This section is empty.

Jump to

Keyboard shortcuts

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