swarm

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2022 License: MIT Imports: 7 Imported by: 133

README

DEPRECATION NOTICE

This package has moved into go-libp2p as a sub-package, github.com/libp2p/go-libp2p/p2p/net/swarm.

go-libp2p-swarm

==================

Go Reference Code Coverage Discourse posts

The libp2p swarm manages groups of connections to peers, and handles incoming and outgoing streams.

The libp2p swarm is the 'low level' interface for working with a given libp2p network. It gives you more fine grained control over various aspects of the system. Most applications don't need this level of access, so the Swarm is generally wrapped in a Host abstraction that provides a more friendly interface. See the host interface for more info on that.

Table of Contents

Install

go get github.com/libp2p/go-libp2p-swarm

Usage

Creating a swarm

To construct a swarm, you'll be calling NewSwarm. That function looks like this:

swarm, err := NewSwarm(peerID, peerstore)

The first parameter of the swarm constructor is an identity in the form of a peer.ID.

The second argument is a peerstore. This is essentially a database that the swarm will use to store peer IDs, addresses, public keys, protocol preferences and more.

Streams

The swarm is designed around using multiplexed streams to communicate with other peers. When working with a swarm, you will want to set a function to handle incoming streams from your peers:

swrm.SetStreamHandler(func(s network.Stream) {
	defer s.Close()
	fmt.Println("Got a stream from: ", s.SwarmConn().RemotePeer())
	fmt.Fprintln(s, "Hello Friend!")
})

Tip: Always make sure to close streams when you're done with them.

Contribute

PRs are welcome!

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Jeromy Johnson


The last gx published version of this module was: 3.0.35: QmQVoMEL1CxrVusTSUdYsiJXVBnvSqNUpBsGybkwSfksEF

Documentation

Overview

Deprecated: This package has moved into go-libp2p as a sub-package: github.com/libp2p/go-libp2p/p2p/net/swarm.

Index

Constants

View Source
const ConcurrentFdDials = swarm.ConcurrentFdDials

ConcurrentFdDials is the number of concurrent outbound dials over transports that consume file descriptors Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ConcurrentFdDials instead.

View Source
const DefaultPerPeerRateLimit = swarm.DefaultPerPeerRateLimit

DefaultPerPeerRateLimit is the number of concurrent outbound dials to make per peer Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.DefaultPerPeerRateLimit instead.

View Source
const DialAttempts = swarm.DialAttempts

DialAttempts governs how many times a goroutine will try to dial a given peer. Note: this is down to one, as we have _too many dials_ atm. To add back in, add loop back in Dial(.) Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.DialAttempts instead.

Variables

View Source
var (
	// ErrDialBackoff is returned by the backoff code when a given peer has
	// been dialed too frequently
	// Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrDialBackoff instead.
	ErrDialBackoff = swarm.ErrDialBackoff

	// ErrDialToSelf is returned if we attempt to dial our own peer
	// Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrDialToSelf instead.
	ErrDialToSelf = swarm.ErrDialToSelf

	// ErrNoTransport is returned when we don't know a transport for the
	// given multiaddr.
	// Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrNoTransport instead.
	ErrNoTransport = swarm.ErrNoTransport

	// ErrAllDialsFailed is returned when connecting to a peer has ultimately failed
	// Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrAllDialsFailed instead.
	ErrAllDialsFailed = swarm.ErrAllDialsFailed

	// ErrNoAddresses is returned when we fail to find any addresses for a
	// peer we're trying to dial.
	// Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrNoAddresses instead.
	ErrNoAddresses = swarm.ErrNoAddresses

	// ErrNoGoodAddresses is returned when we find addresses for a peer but
	// can't use any of them.
	// Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrNoGoodAddresses instead.
	ErrNoGoodAddresses = swarm.ErrNoGoodAddresses

	// ErrGaterDisallowedConnection is returned when the gater prevents us from
	// forming a connection with a peer.
	// Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrGaterDisallowedConnection instead.
	ErrGaterDisallowedConnection = swarm.ErrGaterDisallowedConnection
)
View Source
var BackoffBase = swarm.BackoffBase

BackoffBase is the base amount of time to backoff (default: 5s). Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.BackoffBase instead.

View Source
var BackoffCoef = swarm.BackoffCoef

BackoffCoef is the backoff coefficient (default: 1s). Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.BackoffCoef instead.

View Source
var BackoffMax = swarm.BackoffMax

BackoffMax is the maximum backoff time (default: 5m). Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.BackoffMax instead.

View Source
var ErrAddrFiltered = swarm.ErrAddrFiltered

ErrAddrFiltered is returned when trying to register a connection to a filtered address. You shouldn't see this error unless some underlying transport is misbehaving. Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrAddrFiltered instead.

View Source
var ErrConnClosed = swarm.ErrConnClosed

ErrConnClosed is returned when operating on a closed connection. Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrConnClosed instead.

View Source
var ErrDialTimeout = swarm.ErrDialTimeout

ErrDialTimeout is returned when one a dial times out due to the global timeout Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrDialTimeout instead.

View Source
var ErrSwarmClosed = swarm.ErrSwarmClosed

ErrSwarmClosed is returned when one attempts to operate on a closed swarm. Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.ErrSwarmClosed instead.

Functions

This section is empty.

Types

type Conn

type Conn = swarm.Conn

Conn is the connection type used by swarm. In general, you won't use this type directly. Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.Conn instead.

type DialBackoff

type DialBackoff = swarm.DialBackoff

DialBackoff is a type for tracking peer dial backoffs.

* It's safe to use its zero value. * It's thread-safe. * It's *not* safe to move this type after using. Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.DialBackoff instead.

type DialError added in v0.0.3

type DialError = swarm.DialError

DialError is the error type returned when dialing. Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.DialError instead.

type Option deprecated added in v0.6.0

type Option = swarm.Option

Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.Option instead.

func WithConnectionGater added in v0.6.0

func WithConnectionGater(gater connmgr.ConnectionGater) Option

WithConnectionGater sets a connection gater Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.WithConnectionGater instead.

func WithDialTimeout deprecated added in v0.10.0

func WithDialTimeout(t time.Duration) Option

Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.WithDialTimeout instead.

func WithDialTimeoutLocal deprecated added in v0.10.0

func WithDialTimeoutLocal(t time.Duration) Option

Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.WithDialTimeoutLocal instead.

func WithMetrics added in v0.6.0

func WithMetrics(reporter metrics.Reporter) Option

WithMetrics sets a metrics reporter Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.WithMetrics instead.

func WithResourceManager deprecated added in v0.10.0

func WithResourceManager(m network.ResourceManager) Option

Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.WithResourceManager instead.

type Stream

type Stream = swarm.Stream

Stream is the stream type used by swarm. In general, you won't use this type directly. Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.Stream instead.

type Swarm

type Swarm = swarm.Swarm

Swarm is a connection muxer, allowing connections to other peers to be opened and closed, while still using the same Chan for all communication. The Chan sends/receives Messages, which note the destination or source Peer. Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.Swarm instead.

func NewSwarm

func NewSwarm(local peer.ID, peers peerstore.Peerstore, opts ...Option) (*Swarm, error)

NewSwarm constructs a Swarm. Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.NewSwarm instead.

type TransportError added in v0.0.3

type TransportError = swarm.TransportError

TransportError is the error returned when dialing a specific address. Deprecated: use github.com/libp2p/go-libp2p/p2p/net/swarm.TransportError instead.

Directories

Path Synopsis
Deprecated: This package has moved into go-libp2p as a sub-package: github.com/libp2p/go-libp2p/p2p/net/swarm/testing.
Deprecated: This package has moved into go-libp2p as a sub-package: github.com/libp2p/go-libp2p/p2p/net/swarm/testing.

Jump to

Keyboard shortcuts

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