relay

package module
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2023 License: MIT Imports: 29 Imported by: 0

README

DEPRECATION NOTICE

This package has moved into go-libp2p as a sub-package, github.com/dn3010/go-libp2p-circuitv1/p2p/protocol/internal/circuitv1-deprecated.

go-libp2p-circuit

Coverage Status Travis CI Discourse posts

The libp2p relay allows peers to relay connections on behalf of others.

Table of Contents

Install

go get -u github.com/dn3010/go-libp2p-circuit

Usage

Refer to the relay example in the go-libp2p-examples repository for usage instructions.

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: 2.3.15: QmRTkLxADQRbgnhpt2zzQQJr8Ri764b7dujoDkZw33b3iE

Documentation

Index

Constants

View Source
const ProtoID = "/libp2p/circuit/relay/0.1.0"

Variables

View Source
var (
	RelayAcceptTimeout   = 10 * time.Second
	HopConnectTimeout    = 30 * time.Second
	StopHandshakeTimeout = 1 * time.Minute

	HopStreamBufferSize = 4096
	HopStreamLimit      = 1 << 19 // 512K hops for 1M goroutines

)
View Source
var (
	// OptActive configures the relay transport to actively establish
	// outbound connections on behalf of clients. You probably don't want to
	// enable this unless you know what you're doing.
	OptActive = RelayOpt(0)
	// OptHop configures the relay transport to accept requests to relay
	// traffic on behalf of third-parties. Unless OptActive is specified,
	// this will only relay traffic between peers already connected to this
	// node.
	OptHop = RelayOpt(1)
	// OptDiscovery is a no-op. It was introduced as a way to probe new
	// peers to see if they were willing to act as a relays. However, in
	// practice, it's useless. While it does test to see if these peers are
	// relays, it doesn't (and can't), check to see if these peers are
	// _active_ relays (i.e., will actively dial the target peer).
	//
	// This option may be re-enabled in the future but for now you shouldn't
	// use it.
	OptDiscovery = RelayOpt(2)
)
View Source
var HopTagWeight = 5

HopTagWeight is the connection manager weight for connections carrying relay hop streams

Functions

func AddRelayTransport

func AddRelayTransport(h host.Host, upgrader transport.Upgrader, opts ...RelayOpt) error

AddRelayTransport constructs a relay and adds it as a transport to the host network.

func CanHop

func CanHop(ctx context.Context, host host.Host, id peer.ID) (bool, error)

Queries a peer for support of hop relay

func GenUpgrader added in v0.7.1

func GenUpgrader(n *swarm.Swarm, connGater connmgr.ConnectionGater, opts ...tptu.Option) (transport.Upgrader, error)

GenUpgrader creates a new connection upgrader for use with this swarm.

Types

type Conn

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

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) LocalMultiaddr

func (c *Conn) LocalMultiaddr() ma.Multiaddr

func (*Conn) Read

func (c *Conn) Read(buf []byte) (int, error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) RemoteMultiaddr

func (c *Conn) RemoteMultiaddr() ma.Multiaddr

TODO: is it okay to cast c.Conn().RemotePeer() into a multiaddr? might be "user input"

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

func (*Conn) Write

func (c *Conn) Write(buf []byte) (int, error)

type Host added in v0.16.0

type Host interface {
	// ID returns the (local) peer.ID associated with this Host
	ID() peer.ID

	// Peerstore returns the Host's repository of Peer Addresses and Keys.
	Peerstore() peerstore.Peerstore

	// Returns the listen addresses of the Host
	Addrs() []ma.Multiaddr

	// Networks returns the Network interface of the Host
	Network() network.Network

	// Mux returns the Mux multiplexing incoming streams to protocol handlers
	Mux() protocol.Switch

	// Connect ensures there is a connection between this host and the peer with
	// given peer.ID. Connect will absorb the addresses in pi into its internal
	// peerstore. If there is not an active connection, Connect will issue a
	// h.Network.Dial, and block until a connection is open, or an error is
	// returned. // TODO: Relay + NAT.
	Connect(ctx context.Context, pi peer.AddrInfo) error

	// SetStreamHandler sets the protocol handler on the Host's Mux.
	// This is equivalent to:
	//   host.Mux().SetHandler(proto, handler)
	// (Threadsafe)
	SetStreamHandler(pid protocol.ID, handler network.StreamHandler)

	// SetStreamHandlerMatch sets the protocol handler on the Host's Mux
	// using a matching function for protocol selection.
	SetStreamHandlerMatch(protocol.ID, func(protocol.ID) bool, network.StreamHandler)

	// RemoveStreamHandler removes a handler on the mux that was set by
	// SetStreamHandler
	RemoveStreamHandler(pid protocol.ID)

	// NewStream opens a new stream to given peer p, and writes a p2p/protocol
	// header with given ProtocolID. If there is no connection to p, attempts
	// to create one. If ProtocolID is "", writes no header.
	// (Threadsafe)
	NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error)

	// Close shuts down the host, its Network, and services.
	Close() error

	// ConnManager returns this hosts connection manager
	ConnManager() connmgr.ConnManager

	// EventBus returns the hosts eventbus
	EventBus() event.Bus
}

Host is an object participating in a p2p network, which implements protocols or provides services. It handles requests like a Server, and issues requests like a Client. It is called Host because it is both Server and Client (and Peer may be confusing).

type NetAddr

type NetAddr struct {
	Relay  string
	Remote string
}

func (*NetAddr) Network

func (n *NetAddr) Network() string

func (*NetAddr) String

func (n *NetAddr) String() string

type Relay

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

Relay is the relay transport and service.

func NewRelay

func NewRelay(h host.Host, upgrader transport.Upgrader, opts ...RelayOpt) (*Relay, error)

NewRelay constructs a new relay.

func (*Relay) CanHop

func (r *Relay) CanHop(ctx context.Context, id peer.ID) (bool, error)

func (*Relay) Dial

func (r *Relay) Dial(ctx context.Context, a ma.Multiaddr, p peer.ID) (*Conn, error)

func (*Relay) DialPeer

func (r *Relay) DialPeer(ctx context.Context, relay peer.AddrInfo, dest peer.AddrInfo) (*Conn, error)

func (*Relay) GetActiveHops

func (r *Relay) GetActiveHops() int32

func (*Relay) Listener

func (r *Relay) Listener() *RelayListener

func (*Relay) Matches

func (r *Relay) Matches(addr ma.Multiaddr) bool

func (*Relay) Transport

func (r *Relay) Transport() *RelayTransport

type RelayError

type RelayError struct {
	Code pb.CircuitRelay_Status
}

func (RelayError) Error

func (e RelayError) Error() string

type RelayListener

type RelayListener Relay

func (*RelayListener) Accept

func (l *RelayListener) Accept() (manet.Conn, error)

func (*RelayListener) Addr

func (l *RelayListener) Addr() net.Addr

func (*RelayListener) Close

func (l *RelayListener) Close() error

func (*RelayListener) Multiaddr

func (l *RelayListener) Multiaddr() ma.Multiaddr

func (*RelayListener) Relay

func (l *RelayListener) Relay() *Relay

type RelayOpt

type RelayOpt int

RelayOpts are options for configuring the relay transport.

type RelayTransport

type RelayTransport Relay

func (*RelayTransport) CanDial

func (t *RelayTransport) CanDial(raddr ma.Multiaddr) bool

func (*RelayTransport) Close

func (r *RelayTransport) Close() error

func (*RelayTransport) Dial

func (*RelayTransport) Listen

func (t *RelayTransport) Listen(laddr ma.Multiaddr) (transport.Listener, error)

func (*RelayTransport) Protocols

func (t *RelayTransport) Protocols() []int

func (*RelayTransport) Proxy

func (t *RelayTransport) Proxy() bool

func (*RelayTransport) Relay

func (t *RelayTransport) Relay() *Relay

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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