package client

import "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/client"

Index

Variables

var (
	StatLimitDuration = statLimitDuration{}
	StatLimitData     = statLimitData{}
)
var (
	StreamTimeout = 1 * time.Minute
	AcceptTimeout = 10 * time.Second
)
var DialRelayTimeout = 5 * time.Second
var DialTimeout = time.Minute
var HopTagWeight = 5

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

var ReserveTimeout = time.Minute

Functions

func AddTransport

func AddTransport(h host.Host, upgrader transport.Upgrader) error

AddTransport constructs a new p2p-circuit/v2 client and adds it as a transport to the host network

Types

type Client

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

Client implements the client-side of the p2p-circuit/v2 protocol: - it implements dialing through v2 relays - it listens for incoming connections through v2 relays.

For backwards compatibility with v1 relays and older nodes, the client will also accept relay connections through v1 relays and fallback dial peers using p2p-circuit/v1. This allows us to use the v2 code as drop in replacement for v1 in a host without breaking existing code and interoperability with older nodes.

func New

func New(h host.Host, upgrader transport.Upgrader) (*Client, error)

New constructs a new p2p-circuit/v2 client, attached to the given host and using the given upgrader to perform connection upgrades.

func (*Client) CanDial

func (c *Client) CanDial(addr ma.Multiaddr) bool

func (*Client) Close

func (c *Client) Close() error

func (*Client) Dial

func (*Client) Listen

func (c *Client) Listen(addr ma.Multiaddr) (transport.Listener, error)

func (*Client) Listener

func (c *Client) Listener() *Listener

func (*Client) Protocols

func (c *Client) Protocols() []int

func (*Client) Proxy

func (c *Client) Proxy() bool

func (*Client) SkipResolve

func (c *Client) SkipResolve(_ context.Context, _ ma.Multiaddr) bool

SkipResolve returns true since we always defer to the inner transport for the actual connection. By skipping resolution here, we let the inner transport decide how to resolve the multiaddr

func (*Client) Start

func (c *Client) Start()

Start registers the circuit (client) protocol stream handlers

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) Stat

func (c *Conn) Stat() network.ConnStats

func (*Conn) Write

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

type Listener

type Listener Client

func (*Listener) Accept

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

func (*Listener) Addr

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

func (*Listener) Close

func (l *Listener) Close() error

func (*Listener) Multiaddr

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

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 Reservation

type Reservation struct {
	// Expiration is the expiration time of the reservation
	Expiration time.Time
	// Addrs contains the vouched public addresses of the reserving peer, which can be
	// announced to the network
	Addrs []ma.Multiaddr

	// LimitDuration is the time limit for which the relay will keep a relayed connection
	// open. If 0, there is no limit.
	LimitDuration time.Duration
	// LimitData is the number of bytes that the relay will relay in each direction before
	// resetting a relayed connection.
	LimitData uint64

	// Voucher is a signed reservation voucher provided by the relay
	Voucher *proto.ReservationVoucher
}

Reservation is a struct carrying information about a relay/v2 slot reservation.

func Reserve

func Reserve(ctx context.Context, h host.Host, ai peer.AddrInfo) (*Reservation, error)

Reserve reserves a slot in a relay and returns the reservation information. Clients must reserve slots in order for the relay to relay connections to them.

type ReservationError

type ReservationError struct {

	// Status is the status returned by the relay for rejecting the reservation
	// request. It is set to pbv2.Status_CONNECTION_FAILED on other failures
	Status pbv2.Status

	// Reason is the reason for reservation failure
	Reason string
	// contains filtered or unexported fields
}

ReservationError is the error returned on failure to reserve a slot in the relay

func (ReservationError) Error

func (re ReservationError) Error() string

func (ReservationError) Unwrap

func (re ReservationError) Unwrap() error

Source Files

client.go conn.go dial.go handlers.go listen.go reservation.go transport.go

Version
v0.42.0 (latest)
Published
Jun 18, 2025
Platform
linux/amd64
Imports
18 packages
Last checked
1 week ago

Tools for package owners.