Documentation
¶
Overview ¶
Package transport provides a listener and sender channel for unicast and multicast UDP IPv4 short message chat protocol with a pre shared key, forward error correction facilities with a nice friendly declaration syntax
Index ¶
- Constants
- func DecryptMessage(creator string, ciph cipher.AEAD, data []byte) (msg []byte, err error)
- func EncryptMessage(creator string, ciph cipher.AEAD, magic []byte, nonce, data []byte) (msg []byte, err error)
- func GetNonce(ciph cipher.AEAD) (nonce []byte, err error)
- func GetShards(data []byte) (shards [][]byte)
- func Handle(address string, channel *Channel, handlers Handlers, maxDatagramSize int, ...)
- func Listen(address string, channel *Channel, maxDatagramSize int, handlers Handlers, ...) (conn *net.UDPConn, err error)
- func ListenBroadcast(port int, channel *Channel, maxDatagramSize int, handlers Handlers, ...) (conn *net.UDPConn, err error)
- func NewBroadcaster(port int, maxDatagramSize int) (conn *net.UDPConn, err error)
- func NewSender(address string, maxDatagramSize int) (conn *net.UDPConn, err error)
- func PrevCallers() (out string)
- type Channel
- type Connection
- func (c *Connection) CreateShards(b, magic []byte) (shards [][]byte, err error)
- func (c *Connection) Listen(handlers HandleFunc, ifc interface{}, lastSent *time.Time, firstSender *string) (err error)
- func (c *Connection) Send(b, magic []byte) (err error)
- func (c *Connection) SendShards(shards [][]byte) (err error)
- func (c *Connection) SendShardsTo(shards [][]byte, addr *net.UDPAddr) (err error)
- func (c *Connection) SendTo(addr *net.UDPAddr, b, magic []byte) (err error)
- func (c *Connection) SetSendConn(ad string) (err error)
- type HandleFunc
- type HandlerFunc
- type Handlers
- type MsgBuffer
Constants ¶
const ( UDPMulticastAddress = "224.0.0.1" DefaultPort = 11049 )
Variables ¶
This section is empty.
Functions ¶
func DecryptMessage ¶
func EncryptMessage ¶
func EncryptMessage(creator string, ciph cipher.AEAD, magic []byte, nonce, data []byte) (msg []byte, err error)
EncryptMessage encrypts a message, if the nonce is given it uses that otherwise it generates a new one. If there is no cipher this just returns a message with the given magic prepended.
func GetShards ¶
GetShards returns a buffer iterator to feed to Channel.SendMany containing fec encoded shards built from the provided buffer
func Handle ¶
func Handle(address string, channel *Channel, handlers Handlers, maxDatagramSize int, quit chan struct{})
Handle listens for messages, decodes them, aggregates them, recovers the data from the reed solomon fec shards received and invokes the handler provided matching the magic on the complete received messages
func Listen ¶
func Listen(address string, channel *Channel, maxDatagramSize int, handlers Handlers, quit chan struct{}) (conn *net.UDPConn, err error)
Listen binds to the UDP Address and port given and writes packets received from that Address to a buffer which is passed to a handler
func ListenBroadcast ¶
func ListenBroadcast(port int, channel *Channel, maxDatagramSize int, handlers Handlers, quit chan struct{}) (conn *net.UDPConn, err error)
ListenBroadcast binds to the UDP Address and port given and writes packets received from that Address to a buffer which is passed to a handler
func NewBroadcaster ¶
NewBroadcaster creates a new UDP multicast connection on which to broadcast
func PrevCallers ¶
func PrevCallers() (out string)
Types ¶
type Channel ¶
type Channel struct {
Ready chan struct{}
Creator string
MaxDatagramSize int
Receiver *net.UDPConn
Sender *net.UDPConn
// contains filtered or unexported fields
}
func NewBroadcastChannel ¶
func NewBroadcastChannel(creator string, ctx interface{}, key string, port int, maxDatagramSize int, handlers Handlers, quit chan struct{}) ( channel *Channel, err error)
NewBroadcastChannel returns a broadcaster and listener with a given handler on a multicast address and specified port. The handlers define the messages that will be processed and any other messages are ignored
func NewUnicastChannel ¶
func NewUnicastChannel(creator string, ctx interface{}, key, sender, receiver string, maxDatagramSize int, handlers Handlers, quit chan struct{}, ) ( channel *Channel, err error)
NewUnicastChannel sets up a listener and sender for a specified destination
func (*Channel) SetDestination ¶
SetDestination changes the address the outbound connection of a channel directs to
type Connection ¶
Connection is the state and working memory references for a simple reliable UDP lan transport, encrypted by a GCM AES cipher, with the simple protocol of sending out 9 packets containing encrypted FEC shards containing a slice of bytes. This protocol probably won't work well outside of a multicast lan in adverse conditions but it is designed for local network control systems
func (*Connection) CreateShards ¶
func (c *Connection) CreateShards(b, magic []byte) (shards [][]byte, err error)
func (*Connection) Listen ¶
func (c *Connection) Listen(handlers HandleFunc, ifc interface{}, lastSent *time.Time, firstSender *string) (err error)
func (*Connection) Send ¶
func (c *Connection) Send(b, magic []byte) (err error)
func (*Connection) SendShards ¶
func (c *Connection) SendShards(shards [][]byte) (err error)
func (*Connection) SendShardsTo ¶
func (c *Connection) SendShardsTo(shards [][]byte, addr *net.UDPAddr) (err error)
func (*Connection) SendTo ¶
func (c *Connection) SendTo(addr *net.UDPAddr, b, magic []byte) (err error)
func (*Connection) SetSendConn ¶
func (c *Connection) SetSendConn(ad string) (err error)
type HandleFunc ¶
type HandlerFunc ¶
HandlerFunc is a function that is used to process a received message
type Handlers ¶
type Handlers map[string]HandlerFunc