autonode

package module
v0.0.0-...-5cdce85 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: MIT Imports: 14 Imported by: 0

README

Autonode

Peer-to-peer event bus and queue in golang, for creating horizontally-scalable services. Easily make horizontally-scalable backend applications.

Installation

See the go app skeleton example for an autonode implementation.

To test the example, run

make build

./autonode --autonode.listen="<YourIP>:8082" --addr="0.0.0.0:8081"

and on another computer, run

make build

./autonode --autonode.listen="<YourIP>:8082" --addr="0.0.0.0:8081" --autonode.seeds="<The FirstIP>:8082"

curl -v http://127.0.0.1:8081/ will result in an event being acked and processed by the other node

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Seeds []string `long:"seeds" description:"public seed ip"`
	Host  string   `long:"listen" description:"host/port combo to listen in on"`
}

type EventStateMachine

type EventStateMachine struct {
	Dispatcher bool //is this node the event's creator?
	Event      *types.Event
	Ack        *types.Ack
	Result     *types.Result
	ResultSub  chan types.Result
}

type Processor

type Processor struct {
	State         map[string]*EventStateMachine
	Events        *queue.Queue
	Process       func(event types.Event)
	EventHandler  func(event types.Event) (types.Result, error)
	ResultHandler func(event types.Result) error
	Standalone    bool
	Lock          sync.Mutex //required to protect queue during removal
}

func NewEventProcessor

func NewEventProcessor() *Processor

func (*Processor) AcknowledgeEvent

func (processor *Processor) AcknowledgeEvent(ack types.Ack)

func (*Processor) AddResult

func (processor *Processor) AddResult(result types.Result)

func (*Processor) CompleteEvent

func (processor *Processor) CompleteEvent(idbytes []byte)

func (*Processor) GetEvent

func (processor *Processor) GetEvent(idbytes []byte) (ulid.ULID, *EventStateMachine, bool)

func (*Processor) NewEvent

func (processor *Processor) NewEvent(event types.Event, dispatching bool)

func (*Processor) Prune

func (processor *Processor) Prune()

func (*Processor) Start

func (processor *Processor) Start()

func (*Processor) WaitForResult

func (processor *Processor) WaitForResult(idbytes []byte) *types.Result

type ServerNode

type ServerNode struct {
	Config         Config
	Node           *noise.Node
	Overlay        *kademlia.Protocol
	EventProcessor *Processor
}

func NewServerNode

func NewServerNode(config Config) *ServerNode

func (*ServerNode) DispatchRandom

func (server *ServerNode) DispatchRandom(msg types.Event)

func (*ServerNode) Handle

func (server *ServerNode) Handle(ctx noise.HandlerContext) error

func (*ServerNode) Peers

func (server *ServerNode) Peers() (int, []noise.ID)

func (*ServerNode) ProcessEvent

func (server *ServerNode) ProcessEvent(event types.Event)

func (*ServerNode) SendToID

func (server *ServerNode) SendToID(id noise.ID, msg noise.Serializable) error

func (*ServerNode) SendToIdBytes

func (server *ServerNode) SendToIdBytes(id []byte, msg noise.Serializable)

func (*ServerNode) SendToNetwork

func (server *ServerNode) SendToNetwork(msg noise.Serializable)

func (*ServerNode) SendToNetworkSync

func (server *ServerNode) SendToNetworkSync(msg noise.Serializable)

func (*ServerNode) SetEventHandler

func (server *ServerNode) SetEventHandler(handler func(event types.Event) (types.Result, error))

External method- for devs

func (*ServerNode) SetEventProcessor

func (server *ServerNode) SetEventProcessor(handler func(event types.Event))

Internal method

func (*ServerNode) SetResultHandler

func (server *ServerNode) SetResultHandler(handler func(event types.Result) error)

External method- for devs

func (*ServerNode) Start

func (server *ServerNode) Start()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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