Documentation ¶
Overview ¶
Package fmtp provides Flight Message Transfer Protocol (FMTP) support. It currently supports v2.0
Note that the FMTP protocol is a layer 5,6,7 protocol in the OSI stack.
Index ¶
- Constants
- Variables
- type Client
- type ClientSetter
- type Conn
- func (conn *Conn) Associate(ctx context.Context) error
- func (conn *Conn) Close() error
- func (conn *Conn) Deassociate(ctx context.Context) error
- func (conn *Conn) Disconnect(ctx context.Context) error
- func (conn *Conn) Init(ctx context.Context, addr string, remote ID) error
- func (conn *Conn) RemoteAddr() net.Addr
- func (conn *Conn) RemoteID() ID
- func (conn *Conn) Send(ctx context.Context, msg *Message) error
- func (conn *Conn) SetAcceptRemote(f func(ID) bool) error
- func (conn *Conn) SetHandler(h Handler)
- func (conn *Conn) SetTimers(ti, tr, ts time.Duration)
- func (conn *Conn) SetUnderlying(rwc io.ReadWriteCloser) error
- func (conn *Conn) Write(b []byte) error
- type Handler
- type HandlerFunc
- type ID
- type Message
- type Server
- type Typ
Constants ¶
const ( DefaultTi = 12 * time.Second DefaultTs = 60 * time.Second DefaultTr = 120 * time.Second )
These are the default timer durations
const ( // MaxBodyLen is the maximum body len in bytes MaxBodyLen = maxLength - headerLen // 65530 is the max body length // CompatBodyLen is the minimum size that shall be accepted by FMTP implementations CompatBodyLen = 10240 )
const ExpectedPrefix = "2001:4b50::/32"
ExpectedPrefix is the prefix of FMTP systems from which FMTP systems IPv6 addresses are derived
const ListeningPort = "8500"
ListeningPort is the port a server should listen to. It is not forced to use it, but it is highly recommended.
Variables ¶
var ( // ErrConnectionDeadlineExceeded is returned when the connection deadline (Ti) is exceeded ErrConnectionDeadlineExceeded = errors.New("connection deadline exceeded") // ErrConnectionRejectedByRemote is returned when the connection has been rejected by the remote party ErrConnectionRejectedByRemote = errors.New("connection rejected by remote party") // ErrConnectionRejectedByLocal is returned when the connection has been rejected by the local party ErrConnectionRejectedByLocal = errors.New("connection rejected for invalid credentials") )
var ( // ErrAssociationTimeoutExceeded happens when the association reception timeout (tr) is exceeded // It is returned when associating. Once associated, such error will shutdown the association. ErrAssociationTimeoutExceeded = errors.New("association reception timeout exceeded") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is what allows you to do FMTP requests.
func NewClient ¶
func NewClient(id ID, setters ...ClientSetter) (*Client, error)
NewClient creates a new FMTP client
func (*Client) Connect ¶
Connect initiates an FMTP Connection. It is a wrapper around (*Client).NewConn(nil) and NewConn.Init(ctx, address, id) If the given context expires before the connection is complete, an error is returned. But once successfully established, the context has no effect.
type ClientSetter ¶
ClientSetter is a client configuration setter
func SetTimers ¶
func SetTimers(ti, ts, tr time.Duration) ClientSetter
SetTimers sets the timers
ti is the connection timer, it is only used when establishing connections ts is the ... tr is the ...
type Conn ¶
type Conn struct { // ti is the maximum period of time in which data must be received during an FMTP connection attempt in order for it to be successful Ti time.Duration // ts is the maximum period of time in which data must be transmitted in order to maintain an FMTP association Ts time.Duration // tr is the maximum period of time in which data is to be received over an FMTP association Tr time.Duration // handler is the user's handler for OPERATOR and OPERATIONAL messages Handler Handler // ShutdownNotify notifies the user that a shutdown has been initiated ShutdownNotify func() // contains filtered or unexported fields }
Conn holds the connection with an endpoint
func (*Conn) Associate ¶
Associate upgrades an FMTP Connection to an association If the given context expires before the connection is complete, an error is returned. But once successfully established, the context has no effect.
func (*Conn) Deassociate ¶
Deassociate de-associates gracefully
func (*Conn) Disconnect ¶
Disconnect disconnects a connection, gracefully
func (*Conn) RemoteAddr ¶
RemoteAddr returns the remote address behind a connection, if there is one
func (*Conn) RemoteID ¶
RemoteID returns the ID of the connection's remote party, empty ID if not currently set
func (*Conn) Send ¶
Send sends a message over a connection, making the agent associate it if needed.
func (*Conn) SetAcceptRemote ¶
SetAcceptRemote sets the function that accepts remote IDs for incoming connections
func (*Conn) SetHandler ¶
SetHandler sets the handler for the incomming messages in a transmission
func (*Conn) SetUnderlying ¶
func (conn *Conn) SetUnderlying(rwc io.ReadWriteCloser) error
SetUnderlying sets the underlying connection. The protocol requires TCP connection. However, for debugging, tunneling or other usecases, it can be beneficial to set a custom one. Note that in order for Remote Address reporting to work, it is best if the given io.ReadWriteCloser also has a RemoteAddr() net.Addr method !
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as FMTP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
func (HandlerFunc) ServeFMTP ¶
func (hf HandlerFunc) ServeFMTP(conn *Conn, msg *Message)
ServeFMTP satisfies the Handler interface
type Message ¶
type Message struct { Body io.ReadCloser // contains filtered or unexported fields }
A Message is an FMTP message
func NewMessage ¶
NewMessage returns a message of either Operational or Operator type See MaxBodyLen for the maximum size of a message's body
func NewOperationalMessage ¶
NewOperationalMessage returns a message of Operational type
func NewOperatorMessage ¶
NewOperatorMessage returns a message of Operator type
func NewOperatorMessageString ¶
NewOperatorMessageString returns a message of Operator type built from the given string
type Server ¶
type Server struct { // TCP address to listen on Addr string // Handler is the handler for new connections. Handler Handler // Timeouts Ti time.Duration Ts time.Duration Tr time.Duration // AcceptTCP is called when a new TCP connection is inbound // If AcceptTCP is nil, every incoming connections are accepted AcceptTCP func(remoteAddr net.Addr) bool // NotifyConn is called when a connection was successfuly established NotifyConn func(remoteAddr net.Addr, remoteID ID) // contains filtered or unexported fields }
A Server defines parameters for running an FMTP server.
func (*Server) ListenAndServe ¶
ListenAndServe listens to an IP Address, and handles functions