exchange

package
v0.5.6 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 17 Imported by: 0

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")
)

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 added in v0.5.0

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

Types

type AddressesMap added in v0.5.0

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

AddressesMap -

func NewAddressesMap added in v0.5.0

func NewAddressesMap() *AddressesMap

NewAddressesMap constructs a new SyncMap

func (*AddressesMap) Delete added in v0.5.0

func (m *AddressesMap) Delete(k string)

Delete -

func (*AddressesMap) Get added in v0.5.0

func (m *AddressesMap) Get(k string) (*addressState, bool)

Get -

func (*AddressesMap) GetOrPut added in v0.5.0

func (m *AddressesMap) GetOrPut(k string, v *addressState) (*addressState, bool)

GetOrPut -

func (*AddressesMap) Put added in v0.5.0

func (m *AddressesMap) Put(k string, v *addressState)

Put -

func (*AddressesMap) Range added in v0.5.0

func (m *AddressesMap) Range(i func(k string, v *addressState) bool)

Range -

type ConnectionManager

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

func (*ConnectionManager) Add

func (cm *ConnectionManager) Add(address string, conn *net.Connection)

func (*ConnectionManager) Close

func (cm *ConnectionManager) Close(fingerprint string)

func (*ConnectionManager) Get

func (cm *ConnectionManager) Get(remoteID string) (*net.Connection, error)

type DataForward added in v0.5.0

type DataForward struct {
	Stream     object.Hash
	Parents    []object.Hash
	Owners     []crypto.PublicKey
	Policy     object.Policy
	Signatures []object.Signature
	Recipient  crypto.PublicKey
	Data       []byte
	// contains filtered or unexported fields
}

func (*DataForward) FromObject added in v0.5.0

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

func (DataForward) GetSchema added in v0.5.0

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

func (DataForward) GetType added in v0.5.0

func (e DataForward) GetType() string

func (DataForward) ToObject added in v0.5.0

func (e DataForward) ToObject() object.Object

type Envelope

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

Envelope -

type EnvelopeFilter added in v0.5.0

type EnvelopeFilter func(*Envelope) bool

func FilterByObjectType added in v0.5.0

func FilterByObjectType(typePatterns ...string) EnvelopeFilter

func FilterBySender added in v0.5.0

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

type EnvelopePubSub added in v0.5.0

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

EnvelopePubSub -

func NewEnvelopePubSub added in v0.5.0

func NewEnvelopePubSub() EnvelopePubSub

NewEnvelope constructs and returns a new EnvelopePubSub

type EnvelopeSubscription added in v0.5.0

type EnvelopeSubscription interface {
	Next() (*Envelope, error)
	Cancel()
}

EnvelopeSubscription is returned for every subscription

type Exchange

type Exchange interface {
	Request(
		ctx context.Context,
		object object.Hash,
		recipient peer.LookupOption,
		options ...Option,
	) error
	Subscribe(
		filters ...EnvelopeFilter,
	) EnvelopeSubscription
	Send(
		ctx context.Context,
		object object.Object,
		recipient peer.LookupOption,
		options ...Option,
	) error
	SendToAddress(
		ctx context.Context,
		object object.Object,
		address string,
		options ...Option,
	) error
}

Exchange interface for mocking exchange

func New

func New(
	ctx context.Context,
	key crypto.PrivateKey,
	n net.Network,
	store *sqlobjectstore.Store,
	discover discovery.PeerStorer,
	localInfo *peer.LocalPeer,
) (Exchange, error)

New creates a exchange on a given network

type MockEnvelopeSubscription added in v0.5.0

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

func (*MockEnvelopeSubscription) AddNext added in v0.5.0

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

func (*MockEnvelopeSubscription) Cancel added in v0.5.0

func (s *MockEnvelopeSubscription) Cancel()

func (*MockEnvelopeSubscription) Next added in v0.5.0

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

type MockExchange

type MockExchange struct {
	mock.Mock
}

MockExchange is an autogenerated mock type for the Exchange type

func (*MockExchange) Request

func (_m *MockExchange) Request(ctx context.Context, _a1 object.Hash, recipient peer.LookupOption, options ...Option) error

Request provides a mock function with given fields: ctx, _a1, recipient, options

func (*MockExchange) Send

func (_m *MockExchange) Send(ctx context.Context, _a1 object.Object, recipient peer.LookupOption, options ...Option) error

Send provides a mock function with given fields: ctx, _a1, recipient, options

func (*MockExchange) SendToAddress added in v0.5.0

func (_m *MockExchange) SendToAddress(ctx context.Context, _a1 object.Object, address string, options ...Option) error

SendToAddress provides a mock function with given fields: ctx, _a1, address, options

func (*MockExchange) Subscribe added in v0.5.0

func (_m *MockExchange) Subscribe(filters ...EnvelopeFilter) EnvelopeSubscription

Subscribe provides a mock function with given fields: filters

type ObjectRequest

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

func (*ObjectRequest) FromObject

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

func (ObjectRequest) GetSchema added in v0.5.0

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

func (ObjectRequest) GetType

func (e ObjectRequest) GetType() string

func (ObjectRequest) ToObject

func (e ObjectRequest) ToObject() object.Object

type Option

type Option func(*Options)

func WithAsync added in v0.5.0

func WithAsync() Option

WithAsync will not wait to actually send the object

func WithLocalDiscoveryOnly

func WithLocalDiscoveryOnly() Option

WithLocalDiscoveryOnly will only use local discovery to resolve addresses.

type Options

type Options struct {
	LocalDiscovery bool
	Async          bool
}

Options (mostly) for Send()

type OutboxesMap added in v0.5.0

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

OutboxesMap -

func NewOutboxesMap added in v0.5.0

func NewOutboxesMap() *OutboxesMap

NewOutboxesMap constructs a new SyncMap

func (*OutboxesMap) Delete added in v0.5.0

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

Delete -

func (*OutboxesMap) Get added in v0.5.0

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

Get -

func (*OutboxesMap) GetOrPut added in v0.5.0

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

GetOrPut -

func (*OutboxesMap) Put added in v0.5.0

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

Put -

func (*OutboxesMap) Range added in v0.5.0

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