network

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: Apache-2.0, MIT Imports: 15 Imported by: 56

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitHTTPAddrs added in v0.29.0

func SplitHTTPAddrs(pi peer.AddrInfo) (httpPeer peer.AddrInfo, otherPeer peer.AddrInfo)

SplitHTTPAddrs splits a peer.AddrInfo into two: one containing HTTP/HTTPS addresses, and the other containing the rest.

Types

type BitSwapNetwork

type BitSwapNetwork interface {
	// SendMessage sends a BitSwap message to a peer.
	SendMessage(
		context.Context,
		peer.ID,
		bsmsg.BitSwapMessage) error

	// Start registers the Reciver and starts handling new messages, connectivity events, etc.
	Start(...Receiver)
	// Stop stops the network service.
	Stop()

	Connect(context.Context, peer.AddrInfo) error
	DisconnectFrom(context.Context, peer.ID) error

	NewMessageSender(context.Context, peer.ID, *MessageSenderOpts) (MessageSender, error)

	Stats() Stats

	Self() peer.ID
	Pinger
	PeerTagger
}

BitSwapNetwork provides network connectivity for BitSwap sessions.

func New added in v0.29.0

New returns a BitSwapNetwork supported by underlying IPFS host.

type ConnectEventManager added in v0.29.0

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

func NewConnectEventManager added in v0.29.0

func NewConnectEventManager(connListeners ...ConnectionListener) *ConnectEventManager

func (*ConnectEventManager) Connected added in v0.29.0

func (c *ConnectEventManager) Connected(p peer.ID)

Called whenever we receive a new connection. May be called many times.

func (*ConnectEventManager) Disconnected added in v0.29.0

func (c *ConnectEventManager) Disconnected(p peer.ID)

Called when we drop the final connection to a peer.

func (*ConnectEventManager) MarkUnresponsive added in v0.29.0

func (c *ConnectEventManager) MarkUnresponsive(p peer.ID)

Called whenever a peer is unresponsive.

func (*ConnectEventManager) OnMessage added in v0.29.0

func (c *ConnectEventManager) OnMessage(p peer.ID)

Called whenever we receive a message from a peer.

- When we're connected to the peer, this will mark the peer as responsive (from unresponsive). - When not connected, we ignore this call. Unfortunately, a peer may disconnect before we process

the "on message" event, so we can't treat this as evidence of a connection.

func (*ConnectEventManager) Start added in v0.29.0

func (c *ConnectEventManager) Start()

func (*ConnectEventManager) Stop added in v0.29.0

func (c *ConnectEventManager) Stop()

type ConnectionListener

type ConnectionListener interface {
	PeerConnected(peer.ID)
	PeerDisconnected(peer.ID)
}

type MessageSender

type MessageSender interface {
	SendMsg(context.Context, bsmsg.BitSwapMessage) error
	Reset() error
	// Indicates whether the remote peer supports HAVE / DONT_HAVE messages
	SupportsHave() bool
}

MessageSender is an interface for sending a series of messages over the bitswap network

type MessageSenderOpts

type MessageSenderOpts struct {
	MaxRetries       int
	SendTimeout      time.Duration
	SendErrorBackoff time.Duration
}

type ParsedURL added in v0.29.0

type ParsedURL struct {
	URL *url.URL
	SNI string
}

ParsedURL contains the result of parsing an "http" transport multiaddress. SNI is set when the multiaddress specifies an SNI value.

func ExtractHTTPAddress added in v0.29.0

func ExtractHTTPAddress(ma multiaddr.Multiaddr) (ParsedURL, error)

ExtractHTTPAddress extracts the HTTP schema+host+port from a multiaddress and returns a *url.URL and an SNI string if present.

func ExtractURLsFromPeer added in v0.29.0

func ExtractURLsFromPeer(info peer.AddrInfo) []ParsedURL

ExtractURLsFromPeer extracts all HTTP schema+host+port addresses as ParsedURL from a peer.AddrInfo object.

type PeerTagger added in v0.29.0

type PeerTagger interface {
	TagPeer(peer.ID, string, int)
	UntagPeer(peer.ID, string)
	Protect(peer.ID, string)
	Unprotect(peer.ID, string) bool
}

PeerTagger is an interface for tagging peers with metadata

type Pinger

type Pinger interface {
	// Ping a peer
	Ping(context.Context, peer.ID) ping.Result
	// Get the average latency of all pings
	Latency(peer.ID) time.Duration
}

Pinger is an interface to ping a peer and get the average latency of all pings

type Receiver

type Receiver interface {
	ReceiveMessage(
		ctx context.Context,
		sender peer.ID,
		incoming bsmsg.BitSwapMessage)

	ReceiveError(error)

	// Connected/Disconnected warns bitswap about peer connections.
	PeerConnected(peer.ID)
	PeerDisconnected(peer.ID)
}

Receiver is an interface that can receive messages from the BitSwapNetwork.

type Routing

type Routing interface {
	routing.ContentDiscovery

	// Provide provides the key to the network.
	Provide(context.Context, cid.Cid) error
}

Routing is an interface to providing and finding providers on a bitswap network.

type Stats

type Stats struct {
	MessagesSent  uint64
	MessagesRecvd uint64
}

Stats is a container for statistics about the bitswap network the numbers inside are specific to bitswap, and not any other protocols using the same underlying network.

Directories

Path Synopsis
Package httpnet implements an Exchange network that sends and receives Exchange messages from peers' HTTP endpoints.
Package httpnet implements an Exchange network that sends and receives Exchange messages from peers' HTTP endpoints.

Jump to

Keyboard shortcuts

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