exchange

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 25 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,
)

func Send added in v0.9.0

func Send(ctx context.Context, obj object.Object, p *peer.Peer) error

func WithEventbus added in v0.8.0

func WithEventbus(eb eventbus.Eventbus) func(*exchange)

WithEventbus overrides the default eventbusfor the exchange.

func WithKeychain added in v0.8.0

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

WithKeychain overrides the default keychain for the exchange.

func WithNet added in v0.8.0

func WithNet(n net.Network) func(*exchange)

WithNet overrides the default network for the exchange.

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
	Ephermeral 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

func Subscribe added in v0.9.0

func Subscribe(filters ...EnvelopeFilter) EnvelopeSubscription

type Exchange

type Exchange interface {
	Subscribe(filters ...EnvelopeFilter) EnvelopeSubscription
	Send(ctx context.Context, object object.Object, p *peer.Peer) error
}

Exchange interface for mocking exchange

func New

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

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

func (_m *MockExchange) Send(ctx context.Context, _a1 object.Object, p *peer.Peer) error

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

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(*exchange)

Option for customizing a new exchange

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