horde

package module
v0.0.0-...-83b46c7 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2019 License: MIT Imports: 6 Imported by: 0

README

Horde

Masterless node tracker.

What is this for?

To have nodes talk to eachother and be aware of eachother in realtime 🚀

Think EPMD in erlang as a library for your go web apps 🎉

TODO

All of it 🙏

Example (very early API)
package main

import (
	"fmt"
	"net/http"

	"github.com/selfup/horde"
)

func main() {
	hordeManager := horde.Boot()

	res := hordeManager.Ping()

	fmt.Println(res)

	http.ListenAndServe(":8080", nil)
}

Documentation

Overview

Package horde is an attempt at behaving like erlang for distributed systems.

Lok'tar!

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	sync.Mutex

	// Nodes that are about to be added to the horde
	StagedNodes []Node

	// StageSha is a unique sha that represents the latest StagedNodes
	StageSha string

	// Nodes that have have been committed in the horde
	CommittedNodes []Node

	// CommitSha is a unique sha that represents the latest CommittedNodes
	CommitSha string

	// ReadEpoch is a simple mechanism to keep track of pending or current reads.
	// If the ReadEpoch is odd, the Manager is reading.
	// If the ReadEpoch is even, the Manager has finished reading.
	ReadEpoch int

	// WriteEpoch is a simple mechanism to keep track of pending or current writes.
	// If the WriteEpoch is odd, the Manager is writting.
	// If the WriteEpoch is even, the Manager has finished writting.
	WriteEpoch int

	// Self contains static information about the node.
	// This information is set on boot.
	Self Node
}

Manager keeps track of Nodes and Self. Each Manager is self managing. This is a holistic network. For the horde!

func Boot

func Boot() *Manager

Boot starts up the Horde and returns the horde Manager

func (*Manager) Nodes

func (m *Manager) Nodes() []Node

Nodes returns a list of known nodes and their network info in the horde. This method will not include Self

func (*Manager) Ping

func (m *Manager) Ping() string

Ping calls another node that is known to exist. Returns "pong" on success and "pang" on failure ala erlang. If properly load balanced (round robin) it should not matter which node. So we ping the first!

func (*Manager) RemoveSelfFromHorde

func (m *Manager) RemoveSelfFromHorde(stop chan os.Signal)

RemoveSelfFromHorde is for when the http server fails or is shutdown. Something needs to happen. Gotta clean up the mess. This _will_ make a network call to a known node and remove itself from the horde!

type Node

type Node struct {
	LocalIP  string
	PublicIP string
}

Node represents a node in the mesh. Contains basic network info.

Jump to

Keyboard shortcuts

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