net

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAllAddressesFailed for when a peer cannot be dialed
	ErrAllAddressesFailed = errors.New("all addresses failed to dial")
	// ErrNoAddresses for when a peer has no addresses
	ErrNoAddresses = errors.New("no addresses")
	// ErrNotForUs object is not meant for us
	ErrNotForUs = errors.New("object not for us")
	// ErrMissingKey when a key is not passed
	ErrMissingKey = errors.New("missing key")
	// ErrECDSAPrivateKeyRequired when a key is not an ECDSA key
	ErrECDSAPrivateKeyRequired = errors.New(
		"network currently requires an ecdsa private key",
	)
	// ErrNonce is when the nonce does not match
	ErrNonce = errors.New("nonce does not match")
	// ErrMissingSignature is when the signature is missing
	ErrMissingSignature = errors.New("signature missing")
	// ErrAllAddressesBlacklisted all peer's addresses are currently blacklisted
	ErrAllAddressesBlacklisted = errors.New("all addresses blacklisted")
)
View Source
var (
	BindLocal   = false // TODO(geoah) refactor to remove global
	BindPrivate = false // TODO(geoah) refactor to remove global

)

Functions

func GetAddresses

func GetAddresses(protocol string, l net.Listener) []string

GetAddresses returns the addresses the transport is listening to

func GetLocalPeerAddresses

func GetLocalPeerAddresses(port int) ([]string, error)

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

func Read

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

func WithEventBus added in v0.8.0

func WithEventBus(k eventbus.Eventbus) func(*network)

WithEventBus overrides the default eventbus for the network.

func WithKeychain added in v0.8.0

func WithKeychain(k keychain.Keychain) func(*network)

WithKeychain overrides the default keychain for the network.

func Write

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

Types

type Connection

type Connection struct {
	LocalPeerKey  crypto.PublicKey
	RemotePeerKey crypto.PublicKey
	IsIncoming    bool
	// contains filtered or unexported fields
}

func (*Connection) Close added in v0.3.2

func (c *Connection) Close() error

func (*Connection) LocalAddr added in v0.4.0

func (c *Connection) LocalAddr() string

func (*Connection) RemoteAddr added in v0.4.0

func (c *Connection) RemoteAddr() string

type Handshake added in v0.8.0

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

Handshake middleware

func (*Handshake) Handle added in v0.8.0

func (hs *Handshake) Handle() MiddlewareHandler

Handle incoming and outgoing connections TODO needs to be able to handle both server and client interactions

type HandshakeAck added in v0.8.0

type HandshakeAck struct {
	Stream     object.Hash
	Parents    []object.Hash
	Owners     []crypto.PublicKey
	Policy     object.Policy
	Signatures []object.Signature
	Nonce      string
	// contains filtered or unexported fields
}

func (*HandshakeAck) FromObject added in v0.8.0

func (e *HandshakeAck) FromObject(o object.Object) error

func (HandshakeAck) GetSchema added in v0.8.0

func (e HandshakeAck) GetSchema() *object.SchemaObject

func (HandshakeAck) GetType added in v0.8.0

func (e HandshakeAck) GetType() string

func (HandshakeAck) ToObject added in v0.8.0

func (e HandshakeAck) ToObject() object.Object

type HandshakeSyn added in v0.8.0

type HandshakeSyn struct {
	Stream     object.Hash
	Parents    []object.Hash
	Owners     []crypto.PublicKey
	Policy     object.Policy
	Signatures []object.Signature
	Nonce      string
	// contains filtered or unexported fields
}

func (*HandshakeSyn) FromObject added in v0.8.0

func (e *HandshakeSyn) FromObject(o object.Object) error

func (HandshakeSyn) GetSchema added in v0.8.0

func (e HandshakeSyn) GetSchema() *object.SchemaObject

func (HandshakeSyn) GetType added in v0.8.0

func (e HandshakeSyn) GetType() string

func (HandshakeSyn) ToObject added in v0.8.0

func (e HandshakeSyn) ToObject() object.Object

type HandshakeSynAck added in v0.8.0

type HandshakeSynAck struct {
	Stream     object.Hash
	Parents    []object.Hash
	Owners     []crypto.PublicKey
	Policy     object.Policy
	Signatures []object.Signature
	Nonce      string
	// contains filtered or unexported fields
}

func (*HandshakeSynAck) FromObject added in v0.8.0

func (e *HandshakeSynAck) FromObject(o object.Object) error

func (HandshakeSynAck) GetSchema added in v0.8.0

func (e HandshakeSynAck) GetSchema() *object.SchemaObject

func (HandshakeSynAck) GetType added in v0.8.0

func (e HandshakeSynAck) GetType() string

func (HandshakeSynAck) ToObject added in v0.8.0

func (e HandshakeSynAck) ToObject() object.Object

type Listener added in v0.8.0

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

type Middleware

type Middleware interface {
	Handle() MiddlewareHandler
}

Middleware defines a middleware interface

type MiddlewareHandler

type MiddlewareHandler func(
	ctx context.Context,
	conn *Connection,
) (*Connection, error)

MiddlewareHandler defines a middleware handler

type Network

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

Network interface

func New

func New(opts ...Option) Network

New creates a new p2p network

type Option

type Option func(*network)

Option for customizing a new 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)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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