Documentation
¶
Overview ¶
Package A.L.F.R.E.D. contains functionality resembling that of the C variant, to be found here: http://git.open-mesh.org/alfred.git/ This is a pure Go reimplementation.
Index ¶
- Constants
- Variables
- type AnnounceMasterV0
- type ChangeInterfaceV0
- type Client
- func (c *Client) ChangeInterface(interfaces []byte) error
- func (c *Client) Connect(handler func(net.Conn, *bufio.Writer) error) error
- func (c *Client) ModeSwitch(mode uint8) error
- func (c *Client) PushData(packettype uint8, data []byte) error
- func (c *Client) Request(packettype uint8, handler func(Data) error) error
- func (c *Client) RequestContent(contentitem Content, handler func() error) error
- func (c *Client) Updater(contentitem Content, updatewait time.Duration, retrywait time.Duration, ...)
- type Content
- type Data
- type HardwareAddr
- type ModeSwitchV0
- type Packet
- type PushDataV0
- type ReqGetAll
- type ReqPut
- type RequestV0
- type Server
- type StatusV0
- type Store
- type TLV
- type TransactionMgmt
Constants ¶
const ( ALFRED_IFNAMSIZ = 16 ALFRED_VERSION = 0 ALFRED_PORT = 0x4242 ALFRED_MAX_RESERVED_TYPE = 64 ALFRED_MAX_PAYLOAD = 65535 - 20 )
const ( ALFRED_PUSH_DATA = 0 ALFRED_ANNOUNCE_MASTER = 1 ALFRED_REQUEST = 2 ALFRED_STATUS_TXEND = 3 ALFRED_STATUS_ERROR = 4 ALFRED_MODESWITCH = 5 ALFRED_CHANGE_INTERFACE = 6 )
packet types
const ( ALFRED_MODESWITCH_SLAVE = 0 ALFRED_MODESWITCH_MASTER = 1 )
operation modes
const ( // slave mode: regularly forward local data SERVER_MODE_SLAVE = iota // master mode: receive and cache data from slaves, local data, and sync it all to all other known masters // announce presence via broadcasts SERVER_MODE_MASTER // special mode not present in reference implementation: // announce presence via unicast to other known masters // receive sync data from them, but only propagate local // data to one of them (like a slave server) SERVER_MODE_STEALTH_MASTER )
const PACKETTYPE_ALL = 0
for requests, this means to return data of all packettypes
Variables ¶
var ErrParseMAC = errors.New("error parsing MAC address")
var ErrProtocol = errors.New("Bad data received from A.L.F.R.E.D. server")
var ErrRead = errors.New("cannot read data")
var ErrStatus = errors.New("A.L.F.R.E.D. server reported an error")
var ErrTooLarge = errors.New("data chunk is too large to fit into packet")
var ErrUnknownType = errors.New("unknown data type")
var NullHardwareAddr = HardwareAddr([]byte{0, 0, 0, 0, 0, 0})
Functions ¶
This section is empty.
Types ¶
type AnnounceMasterV0 ¶
type AnnounceMasterV0 struct {
Header *TLV
}
Header-only packet sent by an A.L.F.R.E.D. server to announce that it is an available master server and ready to receive data from slave servers or to be queried for collected data
func NewAnnounceMasterV0 ¶
func NewAnnounceMasterV0() *AnnounceMasterV0
func (*AnnounceMasterV0) Size ¶
func (a *AnnounceMasterV0) Size() int
type ChangeInterfaceV0 ¶
type ChangeInterfaceV0 struct { Header *TLV Ifaces *[ALFRED_IFNAMSIZ * 16]byte }
A client sends this to a server to request the server to (re-)bind its interfaces to send/receive on.
func NewChangeInterfaceV0 ¶
func NewChangeInterfaceV0(interfaces []byte) *ChangeInterfaceV0
func ReadChangeInterfaceV0 ¶
Read a ChangeInterfaceV0 packet Returns the packet, an error if anything went wrong, and the number of bytes read from the io.Reader
func (*ChangeInterfaceV0) Size ¶
func (c *ChangeInterfaceV0) Size() int
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
An A.L.F.R.E.D. client.
It will create a new connection for each request - since the C implementation will close the connection when it has handled a request.
func (*Client) ChangeInterface ¶
change interface(s) the server listens on for UDP connections
func (*Client) RequestContent ¶
Request data and put it into structured data conforming to the Content interface
func (*Client) Updater ¶
func (c *Client) Updater( contentitem Content, updatewait time.Duration, retrywait time.Duration, notifyQuit *topic.Topic, notifySuccess *topic.Topic, handler func() error)
Create a new update client. the time to wait between updates in updatewait and the time to wait after failure before retrying in retrywait. The updatewait duration is also the timeout duration for the actual network connections.
type Data ¶
type Data struct { // origin of the data Source HardwareAddr // descriptor for the data Header *TLV // the actual data Data []byte }
A wrapper for data received from or transmitted to another instance of A.L.F.R.E.D.
type HardwareAddr ¶
type HardwareAddr net.HardwareAddr
Wrapper for the MAC addresses found as main identifier.
func (*HardwareAddr) IsUnset ¶
func (i *HardwareAddr) IsUnset() bool
check if it is unset - i.e. nil pointer or 00:00:00:00:00:00
func (HardwareAddr) MarshalJSON ¶
func (i HardwareAddr) MarshalJSON() ([]byte, error)
JSON encoder for MAC addresses
func (*HardwareAddr) Parse ¶
func (i *HardwareAddr) Parse(addr string) error
parse address from a string
func (HardwareAddr) String ¶
func (i HardwareAddr) String() string
wrap printing from net.HardwareAddr
func (*HardwareAddr) UnmarshalJSON ¶
func (i *HardwareAddr) UnmarshalJSON(data []byte) error
very forgiving parser for MAC addresses
type ModeSwitchV0 ¶
A client sends this to a server to request a switch of the operation mode
func NewModeSwitchV0 ¶
func NewModeSwitchV0(mode uint8) *ModeSwitchV0
func ReadModeSwitchV0 ¶
Read a ModeSwitchV0 packet Returns the packet, an error if anything went wrong, and the number of bytes read from the io.Reader
func (*ModeSwitchV0) Size ¶
func (m *ModeSwitchV0) Size() int
type Packet ¶
type PushDataV0 ¶
type PushDataV0 struct { Header *TLV Tx *TransactionMgmt Data []Data }
Wrapper for a data "push" transaction, to be sent from the "pushing" instance of A.L.F.R.E.D. to a receiving instance. It refers to a transaction and contains the actually pushed data.
func NewPushDataV0 ¶
func NewPushDataV0(tx *TransactionMgmt, data []Data) *PushDataV0
func ReadPushDataV0 ¶
Read a TransactionMgmt packet Returns the packet, an error if anything went wrong, and the number of bytes read from the io.Reader
func (*PushDataV0) Size ¶
func (p *PushDataV0) Size() int
func (*PushDataV0) SizeData ¶
func (p *PushDataV0) SizeData() int
As a PushDataV0 packet can contain many Data packets in its data part, this convenience method can be used to query their combined size.
type ReqGetAll ¶
type ReqGetAll struct { // if PACKETTYPE_ALL, return data of all types, otherwise // specify type to return TypeFilter uint8 // if set to true, return only data that has its origin // locally, i.e. was not propagated by another master server LocalOnly bool // data will be sent back via this channel, it will get // closed as soon as all data has been sent Return chan<- Data }
send this to fetch data from the store
type ReqPut ¶
type ReqPut struct { // flag that tells if the data origin is the local server // instance (i.e. not propagated by another master server) IsLocal bool // actual data item Data }
send this to the store to put data into it (or update data)
type RequestV0 ¶
Query send either from client to server or from server to server for requesting (all) data of a given type, initializing a transaction.
func NewRequestV0 ¶
func ReadRequestV0 ¶
Read a RequestV0 packet Returns the packet, an error if anything went wrong, and the number of bytes read from the io.Reader
type Server ¶
type Server struct { // this will typically be auto-calculated MaxPayload int // interval between sending master announcements in master modes AnnouncementInterval time.Duration // keep information about known masters for this duration after having last // heard of them MasterMaxAge time.Duration // interval between checks MasterPurgeInterval time.Duration // wait for outstanding packets for this time after // receiving final packet (which might arrive out of band) TransactionWaitComplete time.Duration // after this time, a started transaction is removed // from the list, regardless in what state it is TransactionMaxAge time.Duration // interval between checks TransactionPurgeInterval time.Duration // wait this duration for a reply of a master server // after forwarding a (client) request to it WaitForMasterReply time.Duration // interval between data synchronization pushes to other // master servers SyncInterval time.Duration // should we drop transactions that are not complete? // defaults to true, and should better be left that way // except your data/network policy mandates differently DropIncompleteTransactions bool // operation mode Mode int sync.Mutex // contains filtered or unexported fields }
state information for an A.L.F.R.E.D. server
func (*Server) NewListenerStream ¶
start a task for listening on a TCP or Unix socket
func (*Server) NewListenerUDP ¶
spawn a task that listens of incoming UDP packets
type StatusV0 ¶
type StatusV0 struct { Header *TLV Tx *TransactionMgmt }
This is used as the packet format for various status reports which differ in their numerical packet type.
func NewStatusV0 ¶
func NewStatusV0(statustype uint8, tx *TransactionMgmt) *StatusV0
func ReadStatusV0 ¶
Read a StatusV0 packet Returns the packet, an error if anything went wrong, and the number of bytes read from the io.Reader
type Store ¶
the state of the data storage used by an A.L.F.R.E.D. server
type TLV ¶
type TLV struct { // type of the data following (or the information expressed by // just the TLV itself) Type uint8 // version of the typed data Version uint8 // length of the data following Length uint16 }
A type-length-version data element. It is the main descriptor used in the data stream provided or received by an instance of A.L.F.R.E.D.
type TransactionMgmt ¶
Information referring to a transaction between two instances of A.L.F.R.E.D.
func ReadTransactionMgmt ¶
func ReadTransactionMgmt(r io.Reader) (*TransactionMgmt, error, int)
Read a TransactionMgmt packet Returns the packet, an error if anything went wrong, and the number of bytes read from the io.Reader
func (*TransactionMgmt) Size ¶
func (t *TransactionMgmt) Size() int