entities

package
v0.0.0-...-7523913 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package entities contains the data components of a node. A 'entity' is a unit of information like a node, neighbor or report. A entity is derived from one or multiple events. A 'table' holds the current state of all entities which is derived from the events A 'event stream' holds all events known to the node

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrEventEntityEmpty signals that the GRPC message had no TableEntity
	ErrEventEntityEmpty = errors.New("The event contains no entity data")
)

Functions

This section is empty.

Types

type Event

type Event interface {
	//Validate checks if the event message is valid
	//Returns true if the event is valid or false and a error containing the reason it is not
	Validate(*TableSet) (bool, error)

	//GetID returns the id of the event
	GetID() uuid.UUID
}

Event is a change of data in a table

type EventObserver

type EventObserver interface {
	EventUpdate(Event)
}

EventObserver specifies a struct which can receive event updates

type EventStream

type EventStream interface {
	//GetWriteChannel returns a channel which can be used by other components to write a new event to the stream
	//The EventStream is responsible for checking the validity and uniqueness of the event
	GetWriteChannel() chan<- Event

	//GetAllEvents returns all events currently in the event stream
	GetAllEvents() []Event

	//Attach can be used by other components to subscribe to updates of the event stream
	//The EventStream must only call the callback with validated and unique events.
	Attach(observerCallback EventObserver)

	//Detach removes a subscriber
	Detach(observerCallback EventObserver)

	//Run runs the goroutine which handles changes and requests to the EventStream
	Run(context.Context) error
}

A EventStream holds all events known the node

func NewInMemoryEventStream

func NewInMemoryEventStream(tableSet *TableSet, writeChanBufferSize int) EventStream

NewInMemoryEventStream creates a new in memory event stream

type GenericEvent

type GenericEvent struct {
	abusemesh.TableEvent
}

GenericEvent is a wrapper for the protocol stub

func (*GenericEvent) GetID

func (event *GenericEvent) GetID() uuid.UUID

GetID returns the id of the event

func (*GenericEvent) Validate

func (event *GenericEvent) Validate(tableSet *TableSet) (bool, error)

Validate checks if the event message is valid Returns true if the event is valid or false and a error containing the reason it is not

type GetAllNodesRequest

type GetAllNodesRequest struct {
	//ResponseChan is the channel over which multiple nodes will be sent
	ResponseChan chan<- Node

	//Context can be used to cancel the sending of nodes
	Context context.Context
}

GetAllNodesRequest can be used to request all nodes from the nodes table

func (*GetAllNodesRequest) Process

func (req *GetAllNodesRequest) Process(tables *TableSet) error

Process processes the request and sends a slice of nodes on the ResponseChan or nil if the node was not found

type GetNodeRequest

type GetNodeRequest struct {
	ResponseChan chan<- *Node
	NodeID       uuid.UUID
}

GetNodeRequest can be used to request a specific node from a table

func (*GetNodeRequest) Process

func (req *GetNodeRequest) Process(tables *TableSet) error

Process processes the request and sends a pointer to the node on the ResponseChan or nil if the node was not found

type Node

type Node struct {
	UUID            uuid.UUID
	ProtocolVersion string
	IPAddress       net.IP
	ContactDetails  abusemesh.ContactDetails
	ASN             int32
	PGPEntity       *openpgp.Entity
}

A Node is a node as defined by the AbuseMesh protocol[inset link to docs] with extra information internal to the node

func NodeFromProtobuf

func NodeFromProtobuf(protobufNode *abusemesh.Node) (Node, error)

NodeFromProtobuf creates a node object from the node stub of the protobuf definition

func (Node) ToProtobuf

func (node Node) ToProtobuf() (*abusemesh.Node, error)

ToProtobuf converts the node struct into a protobuf stub

type NodeTable

type NodeTable struct {
	Entities map[uuid.UUID]Node
}

A NodeTable holds the current derived state of all nodes in the network known to the current node

type TableRequest

type TableRequest interface {
	Process(*TableSet) error
}

A TableRequest is request which can be made to the table set

type TableSet

type TableSet struct {
	Channel chan TableRequest
	// contains filtered or unexported fields
}

TableSet is a set containing all tables The TableSet has it's own goroutine which can be used to query data from the tables

func (*TableSet) EventUpdate

func (set *TableSet) EventUpdate(event Event)

EventUpdate creates a new update table request and queues it

func (*TableSet) Run

func (set *TableSet) Run(ctx context.Context) error

Run starts a goroutine which is used to interact with the tables

type UpdateTableRequest

type UpdateTableRequest struct {
	Event Event
}

func (*UpdateTableRequest) Process

func (req *UpdateTableRequest) Process(tables *TableSet) error

Jump to

Keyboard shortcuts

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