network

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2020 License: MIT Imports: 25 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// ErrInvalidRequest when received an invalid request object
	ErrInvalidRequest = errors.Error("invalid request")
	// ErrSendingTimedOut when sending times out
	ErrSendingTimedOut = errors.Error("sending timed out")
	// ErrAlreadySentDuringContext when trying to send to the same peer during
	// this context
	ErrAlreadySentDuringContext = errors.Error("already sent to peer")
)

Variables

View Source
var (
	// ErrNotFound is returned by Get() when the object was not found
	ErrNotFound = errors.New("not found")
	// ErrCannotSendToSelf is returned when trying to Send() to our own peer
	ErrCannotSendToSelf = errors.New("cannot send objects to ourself")
)

Functions

func HandleEnvelopeSubscription

func HandleEnvelopeSubscription(
	sub EnvelopeSubscription,
	handler func(*Envelope) error,
)

func ListenOnExternalPort

func ListenOnExternalPort(c *listenConfig)

func ListenOnIPV6

func ListenOnIPV6(c *listenConfig)

func ListenOnLocalIPs

func ListenOnLocalIPs(c *listenConfig)

func ListenOnPrivateIPs

func ListenOnPrivateIPs(c *listenConfig)

func WithLocalPeer

func WithLocalPeer(k localpeer.LocalPeer) func(*network)

WithLocalPeer overrides the default localpeer for the network.

Types

type DataForwardEnvelope added in v0.15.0

type DataForwardEnvelope struct {
	Metadata object.Metadata  `nimona:"metadata:m,omitempty"`
	Sender   crypto.PublicKey `nimona:"sender:s,omitempty"`
	Data     []byte           `nimona:"data:d,omitempty"`
}

func (*DataForwardEnvelope) FromObject added in v0.15.0

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

func (DataForwardEnvelope) ToObject added in v0.15.0

func (e DataForwardEnvelope) ToObject() *object.Object

func (DataForwardEnvelope) ToObjectMap added in v0.15.0

func (e DataForwardEnvelope) ToObjectMap() map[string]interface{}

func (*DataForwardEnvelope) Type added in v0.15.0

func (e *DataForwardEnvelope) Type() string

type DataForwardRequest added in v0.15.0

type DataForwardRequest struct {
	Metadata  object.Metadata  `nimona:"metadata:m,omitempty"`
	RequestID string           `nimona:"requestID:s,omitempty"`
	Recipient crypto.PublicKey `nimona:"recipient:s,omitempty"`
	Payload   *object.Object   `nimona:"payload:o,omitempty"`
}

func (*DataForwardRequest) FromObject added in v0.15.0

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

func (DataForwardRequest) ToObject added in v0.15.0

func (e DataForwardRequest) ToObject() *object.Object

func (DataForwardRequest) ToObjectMap added in v0.15.0

func (e DataForwardRequest) ToObjectMap() map[string]interface{}

func (*DataForwardRequest) Type added in v0.15.0

func (e *DataForwardRequest) Type() string

type DataForwardResponse added in v0.15.0

type DataForwardResponse struct {
	Metadata  object.Metadata `nimona:"metadata:m,omitempty"`
	RequestID string          `nimona:"requestID:s,omitempty"`
	Success   bool            `nimona:"success:b,omitempty"`
}

func (*DataForwardResponse) FromObject added in v0.15.0

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

func (DataForwardResponse) ToObject added in v0.15.0

func (e DataForwardResponse) ToObject() *object.Object

func (DataForwardResponse) ToObjectMap added in v0.15.0

func (e DataForwardResponse) ToObjectMap() map[string]interface{}

func (*DataForwardResponse) Type added in v0.15.0

func (e *DataForwardResponse) Type() string

type Envelope

type Envelope struct {
	Sender  crypto.PublicKey
	Payload *object.Object
}

Envelope -

type EnvelopeFilter

type EnvelopeFilter func(*Envelope) bool

func FilterByNonce

func FilterByNonce(nonce string) EnvelopeFilter

func FilterByObjectHash

func FilterByObjectHash(objectHashes ...object.Hash) EnvelopeFilter

func FilterByObjectType

func FilterByObjectType(typePatterns ...string) EnvelopeFilter

func FilterByRequestID added in v0.15.0

func FilterByRequestID(requestID string) EnvelopeFilter

func FilterBySender

func FilterBySender(keys ...crypto.PublicKey) EnvelopeFilter

type EnvelopePubSub

type EnvelopePubSub interface {
	Publish(*Envelope)
	Subscribe(...EnvelopeFilter) EnvelopeSubscription
}

EnvelopePubSub -

func NewEnvelopePubSub

func NewEnvelopePubSub() EnvelopePubSub

NewEnvelope constructs and returns a new Envelope

type EnvelopeSubscription

type EnvelopeSubscription interface {
	Channel() <-chan *Envelope
	Next() (*Envelope, error)
	Cancel()
}

EnvelopeSubscription is returned for every subscription

type ListenOption

type ListenOption func(c *listenConfig)

type MockEnvelopeSubscription

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

func (*MockEnvelopeSubscription) AddNext

func (s *MockEnvelopeSubscription) AddNext(env *Envelope, err error)

func (*MockEnvelopeSubscription) Cancel

func (s *MockEnvelopeSubscription) Cancel()

func (*MockEnvelopeSubscription) Next

func (s *MockEnvelopeSubscription) Next() (*Envelope, error)

type Network

type Network interface {
	Subscribe(
		filters ...EnvelopeFilter,
	) EnvelopeSubscription
	Send(
		ctx context.Context,
		object *object.Object,
		recipient *peer.ConnectionInfo,
	) error
	Listen(
		ctx context.Context,
		bindAddress string,
		options ...ListenOption,
	) (net.Listener, error)
	LocalPeer() localpeer.LocalPeer
}

Network interface for mocking

func New

func New(
	ctx context.Context,
	opts ...Option,
) Network

New creates a network on a given network

type Option

type Option func(*network)

Option for customizing a new Network

type OutboxesMap

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

OutboxesMap -

func NewOutboxesMap

func NewOutboxesMap() *OutboxesMap

NewOutboxesMap constructs a new SyncMap

func (*OutboxesMap) Delete

func (m *OutboxesMap) Delete(k crypto.PublicKey)

Delete -

func (*OutboxesMap) Get

func (m *OutboxesMap) Get(k crypto.PublicKey) (*outbox, bool)

Get -

func (*OutboxesMap) GetOrPut

func (m *OutboxesMap) GetOrPut(k crypto.PublicKey, v *outbox) (*outbox, bool)

GetOrPut -

func (*OutboxesMap) ListKeys

func (m *OutboxesMap) ListKeys() []crypto.PublicKey

ListKeys -

func (*OutboxesMap) ListValues

func (m *OutboxesMap) ListValues() []*outbox

ListValues -

func (*OutboxesMap) Put

func (m *OutboxesMap) Put(k crypto.PublicKey, v *outbox)

Put -

func (*OutboxesMap) Range

func (m *OutboxesMap) Range(i func(k crypto.PublicKey, v *outbox) bool)

Range -

Jump to

Keyboard shortcuts

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