node

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package node contains the network communication code for Rufs via RPC calls.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNodeComm        = errors.New("Network error")
	ErrRemoteAction    = errors.New("Remote error")
	ErrUnknownTarget   = errors.New("Unknown target node")
	ErrUntrustedTarget = errors.New("Unexpected SSL certificate from target node")
	ErrInvalidToken    = errors.New("Invalid node token")
)

Network related error types

View Source
var DialTimeout = 10 * time.Second

DialTimeout is the dial timeout for RPC connections

View Source
var LogDebug = Logger(LogNull)

LogDebug is called if a debug message is logged (by default disabled)

View Source
var LogInfo = Logger(log.Print)

LogInfo is called if an info message is logged

View Source
var LogNull = func(v ...interface{}) {
}

LogNull is a discarding logger to be used for disabling loggers

Functions

This section is empty.

Types

type Client

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

Client is the client for the RPC API of a node.

func NewClient

func NewClient(secret string, clientCert *tls.Certificate) *Client

NewClient create a new Client object.

func (*Client) Peers

func (c *Client) Peers() ([]string, []string)

Peers returns all registered peers and their expected fingerprints.

func (*Client) RegisterPeer

func (c *Client) RegisterPeer(node string, rpc string, fingerprint string) error

RegisterPeer registers a new peer to communicate with. An empty fingerprint means that the client will accept any certificate from the server.

func (*Client) RemovePeer

func (c *Client) RemovePeer(node string)

RemovePeer removes a registered peer.

func (*Client) SSLFingerprint

func (c *Client) SSLFingerprint() string

SSLFingerprint returns the SSL fingerprint of the client.

func (*Client) SendData

func (c *Client) SendData(node string, ctrl map[string]string, data []byte) ([]byte, error)

SendData sends a portion of data and some control information to a node and returns the result.

func (*Client) SendPing

func (c *Client) SendPing(node string, rpc string) ([]string, string, error)

SendPing sends a ping to a node and returns the result. Second argument is optional if the target member is not a known peer. Should be an empty string in all other cases. Returns the answer, the fingerprint of the presented server certificate and any errors.

func (*Client) SendRequest

func (c *Client) SendRequest(node string, remoteCall RPCFunction,
	args map[RequestArgument]interface{}) (interface{}, error)

SendRequest sends a request to another node.

func (*Client) Shutdown

func (c *Client) Shutdown()

Shutdown closes all stored connections.

type Error

type Error struct {
	Type       error  // Error type (to be used for equal checks)
	Detail     string // Details of this error
	IsNotExist bool   // Error is file or directory does not exist
}

Error is a network related error

func (*Error) Error

func (ge *Error) Error() string

Error returns a human-readable string representation of this error.

type Logger

type Logger func(v ...interface{})

Logger is a function which processes log messages

type RPCFunction

type RPCFunction string

RPCFunction is used to identify the called function in a RPC call

const (
	RPCPing RPCFunction = "Ping"
	RPCData RPCFunction = "Data"
)

List of all possible RPC functions. The list includes all RPC callable functions in this file.

type RequestArgument

type RequestArgument int

RequestArgument is used to identify arguments in a RPC call

const (
	RequestTARGET RequestArgument = iota // Required argument which identifies the target node
	RequestTOKEN                         // Client token which is used for authorization checks
	RequestCTRL                          // Control object (i.e. what to do with the data)
	RequestDATA                          // Data object
)

List of all possible arguments in a RPC request. There are usually no checks which give back an error if a required argument is missing. The RPC API is an internal API and might change without backwards compatibility.

type RequestHandler

type RequestHandler func(ctrl map[string]string, data []byte) ([]byte, error)

RequestHandler is a function to handle incoming requests. A request has a control object which contains information on what the data is and how it should be used and the data itself. The request handler should return the result or an error.

type RufsNode

type RufsNode struct {
	Client *Client // RPC client object

	DataHandler RequestHandler // Handler function for data requests
	// contains filtered or unexported fields
}

RufsNode is the management object for a node in the Rufs network.

A RufsNode registers itself to the rpc server which is the global server object. Each node needs to have a unique name. Communication between nodes is secured by using a secret string which is never exchanged over the network and a hash generated token which identifies a member.

Each RufsNode object contains a Client object which can be used to communicate with other nodes. This object should be used by pure clients - code which should communicate with the cluster without running an actual member.

func NewNode

func NewNode(rpcInterface string, name string, secret string, clientCert *tls.Certificate,
	dataHandler RequestHandler) *RufsNode

NewNode create a new RufsNode object.

func (*RufsNode) LogInfo

func (rn *RufsNode) LogInfo(v ...interface{})

LogInfo logs a node related message at info level.

func (*RufsNode) Name

func (rn *RufsNode) Name() string

Name returns the name of the node.

func (*RufsNode) SSLFingerprint

func (rn *RufsNode) SSLFingerprint() string

SSLFingerprint returns the SSL fingerprint of the node.

func (*RufsNode) Shutdown

func (rn *RufsNode) Shutdown() error

Shutdown shuts the member manager rpc server for this cluster member down.

func (*RufsNode) Start

func (rn *RufsNode) Start(serverCert *tls.Certificate) error

Start starts process for this node.

type RufsNodeToken

type RufsNodeToken struct {
	NodeName string
	NodeAuth string
}

RufsNodeToken is used to authenticate a node in the network to other nodes

type RufsServer

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

RufsServer is the RPC exposed Rufs API of a machine. Server is a singleton and will route incoming (authenticated) requests to registered RufsNodes. The calling node is referred to as source node and the called node is referred to as target node.

func (*RufsServer) Data

func (s *RufsServer) Data(request map[RequestArgument]interface{},
	response *interface{}) error

Data handles data requests.

func (*RufsServer) Ping

func (s *RufsServer) Ping(request map[RequestArgument]interface{},
	response *interface{}) error

Ping answers with a Pong if the given client token was verified and the local node exists.

Jump to

Keyboard shortcuts

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