p2putils

package
v0.33.11 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectednessToString

func ConnectednessToString(connectedness network.Connectedness) (string, bool)

ConnectednessToString reverse translates libp2p network connectedness to string

func CountStream

func CountStream(host host.Host, targetID peer.ID, opts ...FilterOption) int

CountStream finds total number of outbound stream to the target id

func DirectionToString

func DirectionToString(direction network.Direction) (string, bool)

DirectionToString reverse translates libp2p network direction to string

func FilterStream

func FilterStream(host host.Host, targetID peer.ID, options ...FilterOption) []network.Stream

FilterStream filters the streams to a target peer based on the provided options. The default behavior is to consider all directions and protocols, and return just the first matching stream. This behavior can be customized by providing FilterOption values.

Usage:

  • To find all outbound streams to a target peer with a specific protocol ID: streams := FilterStream(host, targetID, Direction(network.DirOutbound), Protocol(myProtocolID), All(true))

  • To find the first inbound stream to a target peer, regardless of protocol ID: stream := FilterStream(host, targetID, Direction(network.DirInbound))

host is the host from which to filter streams. targetID is the ID of the target peer. options is a variadic parameter that allows zero or more FilterOption values to be provided.

It returns a slice of network.Stream values that match the filtering criteria.

func FlowStream

func FlowStream(conn network.Conn) network.Stream

FlowStream returns the Flow protocol Stream in the connection if one exist, else it returns nil

func IPPortFromMultiAddress

func IPPortFromMultiAddress(addrs ...multiaddr.Multiaddr) (string, string, error)

IPPortFromMultiAddress returns the IP/hostname and the port for the given multi-addresses associated with a libp2p host

func NetworkingInfo

func NetworkingInfo(identity flow.Identity) (string, string, crypto.PubKey, error)

NetworkingInfo returns ip, port, libp2p public key of the identity.

func StreamLogger

func StreamLogger(log zerolog.Logger, stream network.Stream) zerolog.Logger

StreamLogger creates a logger for libp2p stream which logs the remote and local peer IDs and addresses

Types

type FilterOption added in v0.32.3

type FilterOption func(*FilterOptions)

FilterOption defines a function type that modifies FilterOptions.

func All added in v0.32.3

func All() FilterOption

All is a FilterOption for setting whether to return all matching streams or just the first matching stream.

func Direction added in v0.32.3

func Direction(dir network.Direction) FilterOption

Direction is a FilterOption for setting the direction of the streams to be filtered.

func Protocol added in v0.32.3

func Protocol(protocol protocol.ID) FilterOption

Protocol is a FilterOption for setting the protocol ID of the streams to be filtered.

type FilterOptions added in v0.32.3

type FilterOptions struct {
	// contains filtered or unexported fields
}

FilterOptions holds the filtering options used in FilterStream.

Jump to

Keyboard shortcuts

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