api

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package api contains the Unix Domain Socket API.

Index

Constants

View Source
const (
	TypeNone = iota
	TypeOK
	TypeError
	TypeVPNConfigUpdate
	TypeUndefined
)

Message types.

View Source
const (
	// MaxPayloadLength is the maximum allowed length of a message payload.
	MaxPayloadLength = 2097152
)

Variables

View Source
var (
	// SocketFile is the unix socket file.
	SocketFile = "/run/oc-daemon/daemon.sock"

	// SocketOwner is the owner of the socket file.
	SocketOwner = ""

	// SocketGroup is the group of the socket file.
	SocketGroup = ""

	// SocketPermissions are the file permissions of the socket file.
	SocketPermissions = "0700"

	// RequestTimeout is the timeout for an entire request/response
	// exchange initiated by a client.
	RequestTimeout = 30 * time.Second
)

Functions

func WriteMessage

func WriteMessage(w io.Writer, m *Message) error

WriteMessage writes message m to r.

Types

type Config added in v0.1.0

type Config struct {
	SocketFile        string
	SocketOwner       string
	SocketGroup       string
	SocketPermissions string
	RequestTimeout    time.Duration
}

Config is a server configuration.

func NewConfig added in v0.1.0

func NewConfig() *Config

NewConfig returns a new server configuration.

func (*Config) Valid added in v0.1.0

func (c *Config) Valid() bool

Valid returns whether server config is valid.

type Header struct {
	Type   uint16
	Length uint32
}

Header is a message header.

type Message

type Message struct {
	Header
	Value []byte
}

Message is an API message.

func NewError

func NewError(p []byte) *Message

NewError returns a new error message with payload p.

func NewMessage

func NewMessage(t uint16, p []byte) *Message

NewMessage returns a new message with type t and payload p.

func NewOK

func NewOK(p []byte) *Message

NewOK returns a new OK message with payload p.

func ReadMessage

func ReadMessage(r io.Reader) (*Message, error)

ReadMessage returns the next message from r.

type Request

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

Request is a request from a client.

func (*Request) Close

func (r *Request) Close()

Close closes the API request.

func (*Request) Data

func (r *Request) Data() []byte

Data returns the data in the API request.

func (*Request) Error

func (r *Request) Error(msg string)

Error sets the error reply message for this request.

func (*Request) Reply

func (r *Request) Reply(b []byte)

Reply sets the data in the reply for this request.

func (*Request) Type

func (r *Request) Type() uint16

Type returns the type of the request.

type Server

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

Server is a Daemon API server.

func NewServer

func NewServer(config *Config) *Server

NewServer returns a new API server.

func (*Server) Requests

func (s *Server) Requests() chan *Request

Requests returns the clients channel.

func (*Server) Start

func (s *Server) Start() error

Start starts the API server.

func (*Server) Stop

func (s *Server) Stop()

Stop stops the API server.

Jump to

Keyboard shortcuts

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