broker

package module
v0.0.0-...-65eca49 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2021 License: MIT Imports: 17 Imported by: 0

README

illchi

Federated P2P message broker

Go Go Report Card GitHub Go Reference

Messaging is part of every app nova days

Most of the current solutions are bloated with features that make maintaining them complicated. We implemented a simple but powerful peer to peer message broken that is inspired by email architecture. The email has successful that implemented many years ago but effective still.

Goals:

  • Cross-platform (and browser support) with no plugin.
  • Use standard protocols and do not invent new ones as is possible
  • Fully distributed with no Single Point Of Failure (SPOF)
  • Equal and same nodes responsibility to decrease maintenance complexity
  • Security and authorization at heart
  • Flexible authentication method
  • Keep It So Simple (KISS) and understandable architecture
  • Federated architecture like email
  • Firewall and (reverse) proxy friendly

In this solution, nodes can send binary messages to each other after the authentication and authorization of each one separately. Optionally others can listen and receive messages after authentication.

This system addressing Each node with two parameters:

  • the broker address (IP:port) used for making the net connection to the broker by IP address and port number
  • and a numeric ID. that is used to identify the target node connection and is a decimal between 1 and 2^31-1

Send

for sending, each node uses target node broker and target node id to make an HTTP POST call:

https://{target broker}/{target ID}

then returns 204 status without a body if was successful In case of error, other status codes with a body that is the error description.

Receive

for receiving, each node should connect to itself broker and makes a GET request

https://{broker address}/{desired ID}

At first, the broker authenticates the request and then upgrades that to a Web-Socket connection thence upgrade-related headers are required. In case of failure, returns a non-successful status code with a body that describes that error.

more features like multi-target send is on the way.

notes

each node should send the id listening to

it's clear that the sender must post the message to the broker that the target is listening to why there is no between brokers message routing.

authentication parameters can send as query strings in HTTP calls to pass them to the authorization module.

handling Cross-Origin Resource Sharing (CORS) over OPTIONS requests is configurable

anycast DNS breaks the architecture but can use DNS for service discovery purpose

to get broker statics should make a get call with no path: GET http://{broker address}/

IPv6 is supported


TODO
  • Docs
  • Cmd
  • Persistence
  • IP and score in stats

Documentation

Index

Constants

View Source
const Version = "1.0.0"

Version returns this source code semantic version

Variables

View Source
var ErrBadContentLength = errors.New("bad content length")

ErrBadContentLength represents "bad content length" error

View Source
var ErrConflictID = errors.New("conflict id")

ErrConflictID represents "conflict id" error

Functions

This section is empty.

Types

type Authenticator

type Authenticator = func(Broker, *fasthttp.RequestCtx) error

Authenticator is authenticator function interface

type Broker

type Broker interface {
	//Close closes the Broker
	Close() error
	//Listen starts the Broker and listen to incoming connections
	Listen() error
	//Stat returns the Broker Statics
	Stat() *Statics
}

Broker impl illchi server-side protocol

func New

func New(config Config) (broker Broker, err error)

New creates a new Broker with config as its Config or return (nil,error) in case of failure

type Config

type Config struct {
	Addr           string
	Origin         string
	Authenticator  Authenticator
	Cert           []byte
	Key            []byte
	Logger         fasthttp.Logger
	MaxConn        uintptr
	MaxMessageSize int
}

Config is Broker config

func (*Config) HasTLS

func (c *Config) HasTLS() bool

HasTLS returns true if the Config has Key and Cert value

type ID

type ID uintptr

func (ID) String

func (id ID) String() string

type Statics

type Statics struct {
	UpTime int32
	Conn   struct {
		Count, Limit uintptr
	}
	Version string
}

Statics represents Broker status and statics

func (*Statics) JsonWithIP

func (s *Statics) JsonWithIP(ip string) string

JsonWithIP encodes the Statics to json with appended `"IP":{ip}` value

Jump to

Keyboard shortcuts

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