Documentation ¶
Overview ¶
Package agent describes an interface for modules to receive and send bundles.
The main interface is the ApplicationAgent, which only requires two channels for incoming and outgoing Messages. Additionally, it requests a list of endpoints. Due to this flexibility, an ApplicationAgent can be implemented in various forms, e.g., as an external interface for third-party programs or as an internal module. Both possibilities are already included in this package, for example the WebSocketAgent or the PingAgent.
Index ¶
- func AppAgentContainsEndpoint(app ApplicationAgent, eids []bundle.EndpointID) bool
- func AppAgentHasEndpoint(app ApplicationAgent, eid bundle.EndpointID) bool
- type ApplicationAgent
- type BundleMessage
- type Message
- type MuxAgent
- type PingAgent
- type RestAgent
- type RestBuildRequest
- type RestBuildResponse
- type RestFetchRequest
- type RestFetchResponse
- type RestRegisterRequest
- type RestRegisterResponse
- type RestUnregisterRequest
- type RestUnregisterResponse
- type ShutdownMessage
- type SyscallRequestMessage
- type SyscallResponseMessage
- type WebSocketAgent
- type WebSocketAgentConnector
- func (wac *WebSocketAgentConnector) Close()
- func (wac *WebSocketAgentConnector) ReadBundle() (b bundle.Bundle, err error)
- func (wac *WebSocketAgentConnector) Syscall(request string, timeout time.Duration) (response []byte, err error)
- func (wac *WebSocketAgentConnector) WriteBundle(b bundle.Bundle) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppAgentContainsEndpoint ¶
func AppAgentContainsEndpoint(app ApplicationAgent, eids []bundle.EndpointID) bool
AppAgentContainsEndpoint checks if an ApplicationAgent listens to at least one of the requested endpoints.
func AppAgentHasEndpoint ¶
func AppAgentHasEndpoint(app ApplicationAgent, eid bundle.EndpointID) bool
AppAgentHasEndpoint checks if an ApplicationAgent listens to this endpoint.
Types ¶
type ApplicationAgent ¶
type ApplicationAgent interface { // Endpoints returns the EndpointIDs that this ApplicationAgent answers to. Endpoints() []bundle.EndpointID // MessageReceiver is a channel on which the ApplicationAgent must listen for incoming Messages. MessageReceiver() chan Message // MessageSender is a channel to which the ApplicationAgent can send outgoing Messages. MessageSender() chan Message }
ApplicationAgent is an interface to describe application agents, which can both receive and transmit Bundles. Each implementation must provide the following methods to communicate its addresses. Furthermore two channels must be available, one for receiving and one for sending Messages.
On closing down, an ApplicationAgent MUST close its MessageSender channel and MUST leave the MessageReceiver open. The supervising code MUST close the MessageReceiver of its subjects.
type BundleMessage ¶
BundleMessage indicates a transmitted Bundle. If the Message is received from an ApplicationAgent, it is an incoming Bundle. If the Message is sent from an ApplicationAgent, it is an outgoing Bundle.
func (BundleMessage) Recipients ¶
func (bm BundleMessage) Recipients() []bundle.EndpointID
Recipients are the Bundle destination for a BundleMessage.
type Message ¶
type Message interface { // Recipients returns a list of endpoints to which this message is addressed. // However, if this message is not addressed to some specific endpoint, nil must be returned. Recipients() []bundle.EndpointID }
Message is a generic interface to specify an information exchange between an ApplicationAgent and some Manager. The following types named *Message are implementations of this interface.
type MuxAgent ¶
MuxAgent mimics an ApplicationAgent to be used as a multiplexer for different ApplicationAgents.
func NewMuxAgent ¶
func NewMuxAgent() (mux *MuxAgent)
NewMuxAgent creates a new MuxAgent used to multiplex different ApplicationAgents.
func (*MuxAgent) Endpoints ¶
func (mux *MuxAgent) Endpoints() (endpoints []bundle.EndpointID)
func (*MuxAgent) MessageReceiver ¶
func (*MuxAgent) MessageSender ¶
func (*MuxAgent) Register ¶
func (mux *MuxAgent) Register(agent ApplicationAgent)
Register a new ApplicationAgent for this multiplexer. If this ApplicationAgent closes its channel or broadcasts a ShutdownMessage, it will be unregistered.
type PingAgent ¶
type PingAgent struct {
// contains filtered or unexported fields
}
PingAgent is a simple ApplicationAgent to "pong" / acknowledge incoming Bundles.
func NewPing ¶
func NewPing(endpoint bundle.EndpointID) *PingAgent
NewPing creates a new PingAgent ApplicationAgent.
func (*PingAgent) Endpoints ¶
func (p *PingAgent) Endpoints() []bundle.EndpointID
func (*PingAgent) MessageReceiver ¶
func (*PingAgent) MessageSender ¶
type RestAgent ¶
type RestAgent struct {
// contains filtered or unexported fields
}
RestAgent is a RESTful Application Agent for simple bundle dispatching.
A client must register itself for some endpoint ID at first. After that, bundles sent to this endpoint can be retrieved or new bundles can be sent. For sending, bundles can be created by calling the BundleBuilder. Finally, a client should unregister itself.
This is all done by HTTP POSTing JSON objects. Their structure is described in `rest_agent_messages.go` by the types with the `Rest` prefix in their names.
A possible conversation follows as an example.
// 1. Registration of our client, POST to /register // -> {"endpoint_id":"dtn://foo/bar"} // <- {"error":"","uuid":"75be76e2-23fc-da0e-eeb8-4773f84a9d2f"} // 2. Fetching bundles for our client, POST to /fetch // There will be to answers, one with new bundles and one without // -> {"uuid":"75be76e2-23fc-da0e-eeb8-4773f84a9d2f"} // <- {"error":"","bundles":[ // { // "primaryBlock": { // "bundleControlFlags":null, // "destination":"dtn://foo/bar", // "source":"dtn://sender/", // "reportTo":"dtn://sender/", // "creationTimestamp":{"date":"2020-04-14 14:32:06","sequenceNo":0}, // "lifetime":86400000000 // }, // "canonicalBlocks": [ // {"blockNumber":1,"blockTypeCode":1,"blockControlFlags":null,"data":"S2hlbGxvIHdvcmxk"} // ] // } // ]} // <- {"error":"No data","bundles":null} // 3. Create and dispatch a new bundle, POST to /build // -> { // "uuid": "75be76e2-23fc-da0e-eeb8-4773f84a9d2f", // "arguments": { // "destination": "dtn://dst/", // "source": "dtn://foo/bar", // "creation_timestamp_now": 1, // "lifetime": "24h", // "payload_block": "hello world" // } // } // <- {"error":""} // 4. Unregister the client, POST to /unregister // -> {"uuid":"75be76e2-23fc-da0e-eeb8-4773f84a9d2f"} // <- {}
func NewRestAgent ¶
NewRestAgent creates a new RESTful Application Agent.
func (*RestAgent) Endpoints ¶
func (ra *RestAgent) Endpoints() (eids []bundle.EndpointID)
func (*RestAgent) MessageReceiver ¶
func (*RestAgent) MessageSender ¶
type RestBuildRequest ¶
type RestBuildRequest struct { UUID string `json:"uuid"` Args map[string]interface{} `json:"arguments"` }
RestBuildRequest describes a JSON to be POSTed to /build.
type RestBuildResponse ¶
type RestBuildResponse struct {
Error string `json:"error"`
}
RestBuildResponse describes a JSON response for /build.
type RestFetchRequest ¶
type RestFetchRequest struct {
UUID string `json:"uuid"`
}
RestFetchRequest describes a JSON to be POSTed to /fetch.
type RestFetchResponse ¶
type RestFetchResponse struct { Error string `json:"error"` Bundles []bundle.Bundle `json:"bundles"` }
RestFetchResponse describes a JSON response for /fetch.
type RestRegisterRequest ¶
type RestRegisterRequest struct {
EndpointId string `json:"endpoint_id"`
}
RestRegisterRequest describes a JSON to be POSTed to /register.
type RestRegisterResponse ¶
RestRegisterResponse describes a JSON response for /register.
type RestUnregisterRequest ¶
type RestUnregisterRequest struct {
UUID string `json:"uuid"`
}
RestUnregisterRequest describes a JSON to be POSTed to /unregister.
type RestUnregisterResponse ¶
type RestUnregisterResponse struct{}
RestUnregisterResponse describes a JSON response for /unregister.
type ShutdownMessage ¶
type ShutdownMessage struct{}
ShutdownMessage indicates the closing down of an ApplicationAgent. If the Message is received from an ApplicationAgent, it must close itself down. If the Message is sent from an ApplicationAgent, it is closing down itself.
func (ShutdownMessage) Recipients ¶
func (sm ShutdownMessage) Recipients() []bundle.EndpointID
Recipients are not available for a ShutdownMessage.
type SyscallRequestMessage ¶
type SyscallRequestMessage struct { Sender bundle.EndpointID Request string }
SyscallRequestMessage is sent from an ApplicationAgent to request some "syscall" specific information.
func (SyscallRequestMessage) Recipients ¶
func (srm SyscallRequestMessage) Recipients() []bundle.EndpointID
Recipients are not available for a SyscallRequestMessage.
type SyscallResponseMessage ¶
type SyscallResponseMessage struct { Request string Response []byte Recipient bundle.EndpointID }
SyscallResponseMessage is the answer to a SyscallRequestMessage, sent to an ApplicationAgent. The Response is stored as a generic byte array. However, its content is defined for each syscall.
func (SyscallResponseMessage) Recipients ¶
func (srm SyscallResponseMessage) Recipients() []bundle.EndpointID
Recipients are the sender of the SyscallRequestMessage.
type WebSocketAgent ¶
type WebSocketAgent struct {
// contains filtered or unexported fields
}
WebSocketAgent is a WebSocket based ApplicationAgent. It can be used together with the WebSocketAgentConnector to exchange Messages.
func NewWebSocketAgent ¶
func NewWebSocketAgent() (wa *WebSocketAgent)
NewWebSocketAgent will be started with its handler. The ServeHTTP function must be bound to the HTTP server.
func (*WebSocketAgent) Endpoints ¶
func (w *WebSocketAgent) Endpoints() []bundle.EndpointID
Endpoints of all currently connected clients.
func (*WebSocketAgent) MessageReceiver ¶
func (w *WebSocketAgent) MessageReceiver() chan Message
MessageReceiver is a channel on which the ApplicationAgent must listen for incoming Messages.
func (*WebSocketAgent) MessageSender ¶
func (w *WebSocketAgent) MessageSender() chan Message
MessageSender is a channel to which the ApplicationAgent can send outgoing Messages.
func (*WebSocketAgent) ServeHTTP ¶
func (w *WebSocketAgent) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP must be bound to a HTTP endpoint, e.g., to /ws by a http.ServeMux.
type WebSocketAgentConnector ¶
type WebSocketAgentConnector struct {
// contains filtered or unexported fields
}
WebSocketAgentConnector is the client side version of the WebSocketAgent.
func NewWebSocketAgentConnector ¶
func NewWebSocketAgentConnector(apiUrl, endpointId string) (wac *WebSocketAgentConnector, err error)
NewWebSocketAgentConnector creates a new WebSocketAgentConnector connection to a WebSocketAgent.
func (*WebSocketAgentConnector) Close ¶
func (wac *WebSocketAgentConnector) Close()
Close this WebSocketAgentConnector.
func (*WebSocketAgentConnector) ReadBundle ¶
func (wac *WebSocketAgentConnector) ReadBundle() (b bundle.Bundle, err error)
ReadBundle returns the next incoming Bundle. This method blocks.
func (*WebSocketAgentConnector) Syscall ¶
func (wac *WebSocketAgentConnector) Syscall(request string, timeout time.Duration) (response []byte, err error)
Syscall will be send to the server. An answer or an error after a timeout will be returned.
func (*WebSocketAgentConnector) WriteBundle ¶
func (wac *WebSocketAgentConnector) WriteBundle(b bundle.Bundle) (err error)
WriteBundle sends a Bundle to a server.