transporter

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: MIT Imports: 10 Imported by: 3

Documentation

Index

Constants

View Source
const (
	RandomDelivery types.DeliveryMethod = "random"
)

Variables

View Source
var (
	ErrInvalidDeliveryMethod = errors.New("invalid delivery method")
)

Functions

This section is empty.

Types

type Channel

type Channel string
const (
	ChanPrefix                  = "bn_"
	ChanDiscovery       Channel = ChanPrefix + "discovery"
	ChanMessage         Channel = ChanPrefix + "msg"
	ChanMessageResponse Channel = ChanPrefix + "msg_res"
	ChanStorage         Channel = ChanPrefix + "storage"
)

type DaemonCmd

type DaemonCmd uint
const (
	DaemonStop DaemonCmd = iota
	DaemonStart
)

type Event

type Event uint
const (
	EventConnected Event = iota + 1
	EventDisconnected
	EventHeartbeat
)

type PayloadDiscovery

type PayloadDiscovery struct {
	Blocks map[types.BlockName][]types.ActionName `json:"blocks"`
	Event  Event                                  `json:"event"`
}

type PayloadMessage

type PayloadMessage struct {
	Data any `json:"data"`
}

func NewPayloadMessage

func NewPayloadMessage(data any) PayloadMessage

func (*PayloadMessage) DataBytes

func (pa *PayloadMessage) DataBytes(data any) ([]byte, error)

func (*PayloadMessage) JSON

func (pa *PayloadMessage) JSON() ([]byte, error)

type Pocket

type Pocket[P []byte | any] struct {
	Channel      Channel               `json:"channel"`
	VersionName  types.NodeVersionName `json:"version_name"`
	FromID       types.NodeID          `json:"from_id"`
	TargetID     *types.NodeID         `json:"target_id"`
	TargetAction *types.TargetAction   `json:"target_action"`
	Payload      P                     `json:"payload"`
	Hash         string                `json:"hash"`
	ResponseHash string                `json:"hash_res"`
}

func NewPocket

func NewPocket[P PayloadDiscovery | PayloadMessage](channel Channel, versionName types.NodeVersionName, fromID types.NodeID, targetID *types.NodeID, targetAction *types.TargetAction, payload P) Pocket[[]byte]

NewPocket creates new network pocket

type PubDaemon

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

func NewPubDaemon

func NewPubDaemon(channel Channel, redisClient *redis.Client) PubDaemon

func (*PubDaemon) Start

func (pd *PubDaemon) Start()

func (*PubDaemon) Stop

func (pd *PubDaemon) Stop()

type Redis

type Redis struct {
	Transporter
	// contains filtered or unexported fields
}

func NewRedis

func NewRedis(nodeID types.NodeID, configRedis *config.RedisTransporter) (*Redis, error)

func (*Redis) Connect

func (r *Redis) Connect() error

func (*Redis) Disconnect

func (r *Redis) Disconnect() error

func (*Redis) Send

func (r *Redis) Send(channel Channel, payload []byte) error

func (*Redis) Subscribe

func (r *Redis) Subscribe(channel Channel, callback func(payload []byte)) error

type SubDaemon

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

func NewSubDaemon

func NewSubDaemon(nodeID types.NodeID, channel Channel, redisSub *redis.PubSub) SubDaemon

func (*SubDaemon) OutChan

func (sd *SubDaemon) OutChan() chan []byte

func (*SubDaemon) Start

func (sd *SubDaemon) Start(callback func(payload []byte))

func (*SubDaemon) Stop

func (sd *SubDaemon) Stop()

type Transporter

type Transporter interface {
	Connect() error
	Disconnect() error
	Send(channel Channel, payload []byte) error
	Subscribe(channel Channel, callback func(payload []byte)) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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