communication

package
v0.0.0-...-6bb340f Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: GPL-3.0 Imports: 5 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCodecBytes

func NewCodecBytes() *codecBytes

NewCodecBytes returns codec which:

  • supports only byte payloads
  • does not perform any fancy encoding/decoding on payloads

func NewCodecFake

func NewCodecFake() *codecFake

NewCodecFake returns codec which:

  • allows to mock encoded/decoded payloads

func NewCodecJSON

func NewCodecJSON() *codecJSON

NewCodecJSON returns codec which:

  • encodes/decodes payloads forward & backward JSON format

Types

type Codec

type Codec interface {
	Pack(payloadPtr interface{}) (data []byte, err error)
	Unpack(data []byte, payloadPtr interface{}) error
}

Codec interface defines how communication payload messages are encoded/decoded forward & backward before sending via communication Sender/Receiver

type Dialog

type Dialog interface {
	PeerID() identity.Identity
	Sender
	Receiver
	Close() error
}

Dialog represent established connection between 2 peers in network. Enables bidirectional communication with another peer.

type DialogEstablisher

type DialogEstablisher interface {
	EstablishDialog(peerID identity.Identity, peerContact market.Contact) (Dialog, error)
}

DialogEstablisher interface defines client which:

  • initiates Dialog requests to network
  • creates Dialog, when it is negotiated

type DialogHandler

type DialogHandler interface {
	Handle(Dialog) error
}

DialogHandler defines how to handle incoming Dialog

type DialogWaiter

type DialogWaiter interface {
	GetContact() market.Contact
	Start(DialogHandler) error
	Stop() error
}

DialogWaiter defines server which:

  • waits and serves incoming dialog requests
  • negotiates with Dialog initiator
  • finally creates Dialog, when it is accepted

type MessageConsumer

type MessageConsumer interface {
	// GetMessageEndpoint returns endpoint where to receive messages
	GetMessageEndpoint() (MessageEndpoint, error)
	// NewMessage creates struct where message from endpoint will be serialized
	NewMessage() (messagePtr interface{})
	// Consume handles messages from endpoint
	Consume(messagePtr interface{}) error
}

MessageConsumer represents instance which handles messages of specific endpoint

type MessageEndpoint

type MessageEndpoint string

MessageEndpoint is special type that describes unique message endpoint

type MessageProducer

type MessageProducer interface {
	// GetMessageEndpoint returns endpoint where to send messages
	GetMessageEndpoint() (MessageEndpoint, error)
	// Produce creates message which will be serialized to endpoint
	Produce() (messagePtr interface{})
}

MessageProducer represents instance which creates messages to specific endpoint

type Receiver

type Receiver interface {
	Receive(consumer MessageConsumer) error
	ReceiveUnsubscribe(endpoint MessageEndpoint)
	Respond(consumer RequestConsumer) error
	Unsubscribe()
}

Receiver represents interface for:

  • listening for asynchronous messages
  • listening and serving HTTP-like requests

type RequestConsumer

type RequestConsumer interface {
	// GetRequestEndpoint returns endpoint where to receive requests
	GetRequestEndpoint() (RequestEndpoint, error)
	// NewRequest creates struct where request from endpoint will be serialized
	NewRequest() (requestPtr interface{})
	// Consume handles requests from endpoint and replies with response
	Consume(requestPtr interface{}) (responsePtr interface{}, err error)
}

RequestConsumer represents instance which handles requests/responses of specific endpoint

type RequestEndpoint

type RequestEndpoint string

RequestEndpoint is special type that describes unique requests endpoint

type RequestProducer

type RequestProducer interface {
	// GetRequestEndpoint returns endpoint where to send requests
	GetRequestEndpoint() (RequestEndpoint, error)
	// Produce creates request which will be serialized to endpoint
	Produce() (requestPtr interface{})
	// NewResponse creates struct where responses from endpoint will be serialized
	NewResponse() (responsePtr interface{})
}

RequestProducer represents instance which creates requests/responses of specific endpoint

type Sender

type Sender interface {
	Send(producer MessageProducer) error
	Request(producer RequestProducer) (responsePtr interface{}, err error)
}

Sender represents interface for:

  • sending asynchronous messages
  • sending and HTTP-like request and waiting for response

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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