client

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CommunicationTimeout = 30 * time.Second
	RetryCount           = 3
	PingDuration         = 10 * time.Second
	MaxPingCount         = 10
)
View Source
var App = &cli.App{
	Name:      "punchrclient",
	Usage:     "A libp2p host that is capable of DCUtR.",
	UsageText: "punchrclient [global options] command [command options] [arguments...]",
	Action:    RootAction,
	Version:   Version,
	Flags: []cli.Flag{
		&cli.StringFlag{
			Name:        "telemetry-host",
			Usage:       "To which network address should the telemetry (prometheus, pprof) server bind",
			EnvVars:     []string{"PUNCHR_CLIENT_TELEMETRY_HOST"},
			Value:       "localhost",
			DefaultText: "localhost",
		},
		&cli.StringFlag{
			Name:        "telemetry-port",
			Usage:       "On which port should the telemetry (prometheus, pprof) server listen",
			EnvVars:     []string{"PUNCHR_CLIENT_TELEMETRY_PORT"},
			Value:       "12001",
			DefaultText: "12001",
		},
		&cli.StringFlag{
			Name:        "server-host",
			Usage:       "Where does the the punchr server listen",
			EnvVars:     []string{"PUNCHR_CLIENT_SERVER_HOST"},
			Value:       "punchr.dtrautwein.eu",
			DefaultText: "punchr.dtrautwein.eu",
		},
		&cli.StringFlag{
			Name:        "server-port",
			Usage:       "On which port listens the punchr server",
			EnvVars:     []string{"PUNCHR_CLIENT_SERVER_PORT"},
			Value:       "443",
			DefaultText: "443",
		},
		&cli.BoolFlag{
			Name:        "server-ssl",
			Usage:       "Whether or not to use a SSL connection to the server.",
			EnvVars:     []string{"PUNCHR_CLIENT_SERVER_SSL"},
			Value:       true,
			DefaultText: "true",
		},
		&cli.BoolFlag{
			Name:        "server-ssl-skip-verify",
			Usage:       "Whether or not to skip SSL certificate verification.",
			EnvVars:     []string{"PUNCHR_CLIENT_SERVER_SSL_SKIP_VERIFY"},
			Value:       false,
			DefaultText: "false",
		},
		&cli.IntFlag{
			Name:        "host-count",
			Usage:       "How many libp2p hosts should be used to hole punch",
			EnvVars:     []string{"PUNCHR_CLIENT_HOST_COUNT"},
			DefaultText: "10",
			Value:       10,
		},
		&cli.StringFlag{
			Name:    "api-key",
			Usage:   "The key to authenticate against the API. If not set, it's read from $XDG_CONFIG_HOME/punchr/api-key.txt",
			EnvVars: []string{"PUNCHR_CLIENT_API_KEY"},
		},
		&cli.StringFlag{
			Name:        "key-file",
			Usage:       "File where punchr saves the host identities.",
			TakesFile:   true,
			EnvVars:     []string{"PUNCHR_CLIENT_KEY_FILE"},
			DefaultText: "$XDG_CONFIG_HOME/punchr/client.keys",
			Value:       "$XDG_CONFIG_HOME/punchr/client.keys",
		},
		&cli.StringSliceFlag{
			Name:    "bootstrap-peers",
			Usage:   "Comma separated list of multi addresses of bootstrap peers",
			EnvVars: []string{"PUNCHR_BOOTSTRAP_PEERS"},
		},
		&cli.BoolFlag{
			Name:  "disable-router-check",
			Usage: "Set this flag if you don't want punchr to check your router home page",
			Value: false,
		},
	},
	EnableBashCompletion: true,
}
View Source
var Version = "dev"

Functions

func Ping added in v0.6.0

func Ping(ctx context.Context, h host.Host, p peer.ID) (<-chan ping.Result, network.Stream)

Ping pings the remote peer until the context is canceled, returning a stream of RTTs or errors.

func RootAction

func RootAction(c *cli.Context) error

Types

type HolePunchAttempt

type HolePunchAttempt struct {
	HostID      peer.ID
	RemoteID    peer.ID
	RemoteAddrs []multiaddr.Multiaddr

	// Time when the /libp2p/dcutr stream was opened
	OpenedAt time.Time
	// Time when we received a hole punch started event
	StartedAt time.Time
	// Time when this hole punch attempt stopped (failure, cancel, timeout)
	EndedAt time.Time
	// The measured round trip time from the holepunch start event
	StartRTT time.Duration

	ElapsedTime     time.Duration
	Error           string
	DirectDialError string
	Outcome         pb.HolePunchAttemptOutcome
}

func (*HolePunchAttempt) ToProto

func (hpa *HolePunchAttempt) ToProto() *pb.HolePunchAttempt

type HolePunchState

type HolePunchState struct {
	// The host that established the connection to the remote peer via a relay, and it's listening multi addresses
	HostID      peer.ID
	LocalMaddrs []multiaddr.Multiaddr

	// The remote peer and its multi addresses - usually relayed ones. We use that set for the first connection.
	RemoteID     peer.ID
	RemoteMaddrs []multiaddr.Multiaddr

	// Start and end times for the establishment of the relayed connection
	ConnectStartedAt time.Time
	ConnectEndedAt   time.Time

	// Multi addresses of the open connections before the hole punch aka the multi addresses we
	// managed to get a connection to the remote peer.
	OpenMaddrsBefore []multiaddr.Multiaddr

	// Information about each individual hole punch attempt
	HolePunchAttempts []*HolePunchAttempt

	// Multi addresses of the open connections after the hole punch
	OpenMaddrsAfter []multiaddr.Multiaddr
	HasDirectConns  bool

	Error   string
	Outcome pb.HolePunchOutcome
	EndedAt time.Time

	NetworkInformation *pb.NetworkInformation

	ProtocolFilters []int32

	// Remote Peer data
	RemoteRttAfterHolePunch time.Duration

	// LatencyMeasurements of different types
	LatencyMeasurements []LatencyMeasurement

	// NAT Mappings
	NATMappings []nat.Mapping
}

func NewHolePunchState

func NewHolePunchState(hostID peer.ID, remoteID peer.ID, rmaddrs []multiaddr.Multiaddr, lmaddrs []multiaddr.Multiaddr, filters []int32, mappings []nat.Mapping) *HolePunchState

func (HolePunchState) ToProto

func (hps HolePunchState) ToProto(apiKey string) (*pb.TrackHolePunchRequest, error)

func (HolePunchState) TrackHolePunch

func (hps HolePunchState) TrackHolePunch(ctx context.Context, remoteID peer.ID, evtChan <-chan *holepunch.Event) HolePunchAttempt

type Host

type Host struct {
	host.Host
	// contains filtered or unexported fields
}

Host holds information of the honeypot libp2p host.

func InitHost

func InitHost(c *cli.Context, privKey crypto.PrivKey) (*Host, error)

func (*Host) Bootstrap

func (h *Host) Bootstrap(ctx context.Context) error

Bootstrap connects this host to bootstrap peers.

func (*Host) Close

func (h *Host) Close() error

func (*Host) FilterLocal added in v0.6.0

func (h *Host) FilterLocal(remoteID peer.ID, maddrs []multiaddr.Multiaddr) []multiaddr.Multiaddr

func (*Host) FilterRemote added in v0.6.0

func (h *Host) FilterRemote(remoteID peer.ID, maddrs []multiaddr.Multiaddr) []multiaddr.Multiaddr

func (*Host) GetAgentVersion

func (h *Host) GetAgentVersion(pid peer.ID) *string

GetAgentVersion pulls the agent version from the peer store. Returns nil if no information is available.

func (*Host) GetProtocols

func (h *Host) GetProtocols(pid peer.ID) []string

GetProtocols pulls the supported protocols of a peer from the peer store. Returns nil if no information is available.

func (*Host) HolePunch

func (h *Host) HolePunch(ctx context.Context, addrInfo peer.AddrInfo) (*HolePunchState, <-chan LatencyMeasurement)

func (*Host) MeasurePing added in v0.6.0

func (h *Host) MeasurePing(ctx context.Context, pid peer.ID, mType pb.LatencyMeasurementType) <-chan LatencyMeasurement

func (*Host) PingRelays added in v0.6.0

func (h *Host) PingRelays(ctx context.Context, addrInfo map[peer.ID]*peer.AddrInfo) []LatencyMeasurement

func (*Host) ProtocolFilters added in v0.6.0

func (h *Host) ProtocolFilters() []int32

ProtocolFilters copies the slice

func (*Host) RegisterPeerToTrace

func (h *Host) RegisterPeerToTrace(pid peer.ID) <-chan *holepunch.Event

func (*Host) Trace

func (h *Host) Trace(evt *holepunch.Event)

Trace is called during the hole punching process

func (*Host) UnregisterPeerToTrace

func (h *Host) UnregisterPeerToTrace(pid peer.ID)

func (*Host) WaitForDCUtRStream

func (h *Host) WaitForDCUtRStream(pid peer.ID) <-chan struct{}

func (*Host) WaitForPublicAddr

func (h *Host) WaitForPublicAddr(ctx context.Context) error

WaitForPublicAddr blocks execution until the host has identified its public address. As we currently don't have an event like this, just check our observed addresses regularly (exponential backoff starting at 250 ms, capped at 5s). TODO: There should be an event here that fires when identify discovers a new address

type LatencyMeasurement added in v0.6.0

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

type Punchr

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

Punchr is responsible for fetching information from the server, distributing the work load to different hosts and then reporting the results back.

func NewPunchr

func NewPunchr(c *cli.Context) (*Punchr, error)

func (Punchr) Bootstrap

func (p Punchr) Bootstrap(ctx context.Context) error

Bootstrap loops through all hosts, connects each of them to the canonical bootstrap nodes, and waits until they have identified their public address(es).

func (Punchr) Close

func (p Punchr) Close() error

func (Punchr) InitHosts

func (p Punchr) InitHosts(c *cli.Context) error

func (Punchr) Register

func (p Punchr) Register(c *cli.Context) error

Register makes all hosts known to the server.

func (Punchr) RequestAddrInfo

func (p Punchr) RequestAddrInfo(ctx context.Context, clientID peer.ID) (*peer.AddrInfo, []int32, error)

RequestAddrInfo calls the hole punching server for a new peer + multi address to hole punch.

func (Punchr) StartHolePunching

func (p Punchr) StartHolePunching(ctx context.Context) error

StartHolePunching requests a peer from the server, chooses a host to perform a hole punch, and then reports back the result.

func (Punchr) TrackHolePunchResult

func (p Punchr) TrackHolePunchResult(ctx context.Context, hps *HolePunchState) error

type ResourceManager

type ResourceManager struct {
	network.ResourceManager
	// contains filtered or unexported fields
}

func NewResourceManager

func NewResourceManager() (*ResourceManager, error)

func (*ResourceManager) OpenStream

func (*ResourceManager) Register

func (r *ResourceManager) Register(pid peer.ID) <-chan struct{}

func (*ResourceManager) Unregister

func (r *ResourceManager) Unregister(pid peer.ID)

type StreamManagementScope

type StreamManagementScope struct {
	network.StreamManagementScope
	// contains filtered or unexported fields
}

func (*StreamManagementScope) SetProtocol

func (s *StreamManagementScope) SetProtocol(proto protocol.ID) error

Jump to

Keyboard shortcuts

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