holepunch

package
v0.0.0-...-40c7712 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DirectDialEvtT       = "DirectDial"
	ProtocolErrorEvtT    = "ProtocolError"
	StartHolePunchEvtT   = "StartHolePunch"
	EndHolePunchEvtT     = "EndHolePunch"
	HolePunchAttemptEvtT = "HolePunchAttempt"
)

Event Types

View Source
const Protocol protocol.ID = "/libp2p/dcutr"

Protocol is the libp2p protocol for Hole Punching.

View Source
const (
	ServiceName = "libp2p.holepunch"
)

TODO Should we have options for these ?

Variables

View Source
var (

	// ErrHolePunchActive is returned from DirectConnect when another hole punching attempt is currently running
	ErrHolePunchActive = errors.New("another hole punching attempt to this peer is active")
	// ErrClosed is returned when the hole punching is closed
	ErrClosed = errors.New("hole punching service closing")
)
View Source
var StreamTimeout = 1 * time.Minute

StreamTimeout is the timeout for the hole punch protocol stream.

Functions

This section is empty.

Types

type DirectDialEvt

type DirectDialEvt struct {
	Success      bool
	EllapsedTime time.Duration
	Error        string `json:",omitempty"`
}

Event Objects

type EndHolePunchEvt

type EndHolePunchEvt struct {
	Success      bool
	EllapsedTime time.Duration
	Error        string `json:",omitempty"`
}

type Event

type Event struct {
	Timestamp int64       // UNIX nanos
	Peer      peer.ID     // local peer ID
	Remote    peer.ID     // remote peer ID
	Type      string      // event type
	Evt       interface{} // the actual event
}

type EventTracer

type EventTracer interface {
	Trace(evt *Event)
}

type HolePunchAttemptEvt

type HolePunchAttemptEvt struct {
	Attempt int
}

type Option

type Option func(*Service) error

func WithTracer

func WithTracer(tr EventTracer) Option

WithTracer is a Service option that enables hole punching tracing

type ProtocolErrorEvt

type ProtocolErrorEvt struct {
	Error string
}

type Service

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

The Service is used to make direct connections with a peer via hole-punching.

func NewService

func NewService(h host.Host, ids identify.IDService, opts ...Option) (*Service, error)

NewService creates a new service that can be used for hole punching

func (*Service) Close

func (hs *Service) Close() error

Close closes the Hole Punch Service.

func (*Service) DirectConnect

func (hs *Service) DirectConnect(p peer.ID) error

DirectConnect attempts to make a direct connection with a remote peer. It first attempts a direct dial (if we have a public address of that peer), and then coordinates a hole punch over the given relay connection.

type StartHolePunchEvt

type StartHolePunchEvt struct {
	RemoteAddrs []string
	RTT         time.Duration
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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