net

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrAllAddressesFailed for when a peer cannot be dialed
	ErrAllAddressesFailed = errors.Error("all addresses failed to dial")
	// ErrNoAddresses for when a peer has no addresses
	ErrNoAddresses = errors.Error("no addresses")
	// ErrMissingSignature is when the signature is missing
	ErrMissingSignature = errors.Error("signature missing")
	// ErrAllAddressesBlocked all peer's addresses are currently blocked
	ErrAllAddressesBlocked = errors.Error("all addresses blocked")
	// ErrInvalidSignature signature is invalid
	ErrInvalidSignature = errors.Error("invalid signature")
	// ErrConnectionClosed connection is closed, will usually be merged with
	// an underlying error
	ErrConnectionClosed = errors.Error("connection closed")
)

Variables

This section is empty.

Functions

func GetAddresses

func GetAddresses(
	protocol string,
	l net.Listener,
	includeLocal bool,
	includePrivate bool,
	includeIPV6 bool,
) []string

GetAddresses returns the addresses the transport is listening to

func GetLocalPeerAddresses

func GetLocalPeerAddresses(
	port int,
	includeLocal bool,
	includePrivate bool,
	includeIPV6 bool,
) ([]string, error)

GetLocalPeerAddresses returns the addresses TCP can listen to on the local machine

func Read

func Read(conn *Connection) (*object.Object, error)

func Write

func Write(o *object.Object, conn *Connection) error

Types

type Connection

type Connection struct {
	ID string

	LocalPeerKey  crypto.PublicKey
	RemotePeerKey crypto.PublicKey
	IsIncoming    bool
	// contains filtered or unexported fields
}

func (*Connection) Close

func (c *Connection) Close() error

func (*Connection) LocalAddr

func (c *Connection) LocalAddr() string

func (*Connection) RemoteAddr

func (c *Connection) RemoteAddr() string

type ListenConfig

type ListenConfig struct {
	BindLocal   bool
	BindPrivate bool
	BindIPV6    bool
}

type Listener

type Listener interface {
	Close() error
	Addresses() []string
}

type Network

type Network interface {
	Dial(
		ctx context.Context,
		peer *peer.ConnectionInfo,
	) (*Connection, error)
	Listen(
		ctx context.Context,
		bindAddress string,
		listenConfig *ListenConfig,
	) (Listener, error)
	Accept() (*Connection, error)
	Addresses() []string
}

Network interface

func New

func New(
	peerKey crypto.PrivateKey,
) Network

New creates a new p2p network

type Transport

type Transport interface {
	Dial(
		ctx context.Context,
		address string,
	) (*Connection, error)
	Listen(
		ctx context.Context,
		bindAddress string,
		key crypto.PrivateKey,
	) (net.Listener, error)
}

Jump to

Keyboard shortcuts

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