Documentation ¶
Index ¶
Constants ¶
const (
ClosedConnection = "use of closed network connection"
)
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Communication ¶
type Communication interface { io.Closer // Start the Communication primitive, this method only return when // the context is closed and will run the whole life cycle. Start() // Send the given data to the connect at the given address. Send(Address, []byte) error // Receive listen for incoming messages. Receive() <-chan Datagram // Addr returns the current communication address. Addr() net.Addr }
Communication is the base communication interface that should be implemented. This will be the interface the client will interact with, using the defined method is possible to send messages and to listen incoming messages.
func NewCommunication ¶ added in v1.0.1
func NewCommunication(configuration Configuration) (Communication, error)
type Configuration ¶ added in v1.0.1
type Configuration struct { // Address to bind the connection. Address Address // Timeout used when handling messages. Timeout time.Duration // Connections can be pooled, this is the max size. PoolSize int // The parent context to handle the life-cycle of // the primitive. Ctx context.Context }
Configuration for the Communication instance. This will provide the parameters for binding the connection, timeout when handling messages.
type Connection ¶ added in v1.0.1
type Connection interface { io.Closer // Write sends the encoded date to the target peer. Write([]byte) error // Listen start listening for incoming data. Listen() }
Connection interface represents a connection between two peers. The connection can be incoming, outgoing or duplex.
func NewNetworkConnection ¶ added in v1.0.1
func NewNetworkConnection(configuration ConnectionConfiguration) Connection
type ConnectionConfiguration ¶ added in v1.0.1
type ConnectionConfiguration struct { // Timeout to apply for reading/writing to the connection. // Will only be applied if the value is greater than zero. Timeout time.Duration // Channel to publish the bytes received by the connection. Read *SharedChannel // Parent context to bound the connection methods. Ctx context.Context // Cancel the current context. Cancel context.CancelFunc // The actual connection. Connection net.Conn // Peer address of the connection. Target Address }
ConnectionConfiguration gather all needed configuration for managing the connection.
type Datagram ¶
type Datagram struct { // Received data from the underlining connection. Data *bytes.Buffer // Errors received from the connection. Err error // Address that sent the message. From Address // Message destination. To Address }
Datagram represent a datagram for the transport layer. Wraps the received data and errors from the connection.
type DefaultCommunication ¶ added in v1.0.1
type DefaultCommunication struct {
// contains filtered or unexported fields
}
DefaultCommunication default struct that implements the Communication interface. Using this implementation is possible to send and receive messages.
func (*DefaultCommunication) Addr ¶ added in v1.0.1
func (d *DefaultCommunication) Addr() net.Addr
Addr returns the current communication address.
func (*DefaultCommunication) Close ¶ added in v1.0.1
func (d *DefaultCommunication) Close() error
Close implements the Communication interface.
func (*DefaultCommunication) Receive ¶ added in v1.0.1
func (d *DefaultCommunication) Receive() <-chan Datagram
Receive implements the Communication interface.
func (*DefaultCommunication) Send ¶ added in v1.0.1
func (d *DefaultCommunication) Send(address Address, data []byte) error
Send implements the Communication interface.
func (*DefaultCommunication) Start ¶ added in v1.0.1
func (d *DefaultCommunication) Start()
Start implements the Communication interface. Accept new connections from external peers and start a new goroutine to start the life-cycle asynchronously. The Accept method to receive a new connection is a blocking call.
type Flag ¶ added in v1.0.2
type Flag struct {
// contains filtered or unexported fields
}
The Flag structure. Only some transitions are available when using this structure, so this will not act as an atomic boolean. The accepted transitions are:
IsActive if flag is 0x0, returns `true`; IsInactive if flag is 0x1, returns `true`; Inactivate iff IsActive change value to IsInactive.
The start value will be `active`.
func (*Flag) Inactivate ¶ added in v1.0.2
Inactivate will inactivate the flag. Returns `true` if was active and now is inactive and returns `false` if it was already inactivated.
func (*Flag) IsInactive ¶ added in v1.0.2
IsInactive returns `true` if the flag is inactive.
type GoRoutineHandler ¶ added in v1.0.1
type GoRoutineHandler struct {
// contains filtered or unexported fields
}
GoRoutineHandler is responsible for handling goroutines. This is used so go routines do not leak and are spawned without any control. Using the handler to spawn new routines will guarantee that any routine that is not controller careful will be known when the application finishes.
func NewRoutineHandler ¶ added in v1.0.1
func NewRoutineHandler() *GoRoutineHandler
NewRoutineHandler create a instance for the GoRoutineHandler struct. This is used to ensure that throughout the application exists only one single point where go routines are spawned, thus avoiding a leak.
func (*GoRoutineHandler) Close ¶ added in v1.0.1
func (h *GoRoutineHandler) Close()
Close blocks while waiting for go routines to stop. This will set the working mode to off, so after this is called any spawned go routine will panic.
func (*GoRoutineHandler) Spawn ¶ added in v1.0.1
func (h *GoRoutineHandler) Spawn(f func())
Spawn will increase the size of the group count and spawn the new go routine. After the routine is done, the group will be decreased.
This method will panic if the handler is already closed.
type NetworkConnection ¶ added in v1.0.1
type NetworkConnection struct {
// contains filtered or unexported fields
}
NetworkConnection is the default Connection implementation. This will connect the peer to a target over the network. Commands will be sent/received using the available Conn.
func (*NetworkConnection) Close ¶ added in v1.0.1
func (n *NetworkConnection) Close() error
Close implements the Connection interface.
func (*NetworkConnection) Listen ¶ added in v1.0.1
func (n *NetworkConnection) Listen()
Listen implements the Connection interface. Digest bytes received from the underlining connection.
func (*NetworkConnection) Write ¶ added in v1.0.1
func (n *NetworkConnection) Write(bytes []byte) error
Implements the Connection interface.
type SharedChannel ¶ added in v1.0.8
type SharedChannel struct {
// contains filtered or unexported fields
}
SharedChannel is structure that holds a channel that can be shared across multiple goroutines, without danger of publishing to a closed channel nor data race while publishing and closing.
func NewSharedChannel ¶ added in v1.0.8
func NewSharedChannel() *SharedChannel
func (*SharedChannel) Close ¶ added in v1.0.8
func (s *SharedChannel) Close() error
Close will close the channel.
func (*SharedChannel) Consume ¶ added in v1.0.8
func (s *SharedChannel) Consume() <-chan Datagram
Consume will return the channel to listen to messages.
type TCP ¶ added in v1.0.1
type TCP struct {
// contains filtered or unexported fields
}
A TCP transport that implements the Transport interface. This struct will delegate the functions to the available listener.