Documentation ¶
Overview ¶
Package node contains the network communication code for Rufs via RPC calls.
Index ¶
- Variables
- type Client
- func (c *Client) Peers() ([]string, []string)
- func (c *Client) RegisterPeer(node string, rpc string, fingerprint string) error
- func (c *Client) RemovePeer(node string)
- func (c *Client) SSLFingerprint() string
- func (c *Client) SendData(node string, ctrl map[string]string, data []byte) ([]byte, error)
- func (c *Client) SendPing(node string, rpc string) ([]string, string, error)
- func (c *Client) SendRequest(node string, remoteCall RPCFunction, args map[RequestArgument]interface{}) (interface{}, error)
- func (c *Client) Shutdown()
- type Error
- type Logger
- type RPCFunction
- type RequestArgument
- type RequestHandler
- type RufsNode
- type RufsNodeToken
- type RufsServer
Constants ¶
This section is empty.
Variables ¶
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
var DialTimeout = 10 * time.Second
DialTimeout is the dial timeout for RPC connections
var LogDebug = Logger(LogNull)
LogDebug is called if a debug message is logged (by default disabled)
var LogInfo = Logger(log.Print)
LogInfo is called if an info message is logged
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) RegisterPeer ¶
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 ¶
RemovePeer removes a registered peer.
func (*Client) SSLFingerprint ¶
SSLFingerprint returns the SSL fingerprint of the client.
func (*Client) SendData ¶
SendData sends a portion of data and some control information to a node and returns the result.
func (*Client) SendPing ¶
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.
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
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 ¶
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) SSLFingerprint ¶
SSLFingerprint returns the SSL fingerprint of the node.
type RufsNodeToken ¶
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.