Documentation ¶
Index ¶
- type Framework
- type GenericFramework
- func (*GenericFramework) Close(ctx *NetworkContext)
- func (*GenericFramework) Configure(*Legion) error
- func (*GenericFramework) NewMessage(ctx *MessageContext)
- func (*GenericFramework) PeerAdded(ctx *PeerContext)
- func (*GenericFramework) PeerDisconnect(ctx *PeerContext)
- func (*GenericFramework) Startup(ctx *NetworkContext)
- func (*GenericFramework) ValidateMessage(ctx *MessageContext) bool
- type Legion
- func (l *Legion) AddPeer(addresses ...utils.LegionAddress) error
- func (l *Legion) Broadcast(message *transport.Message, addresses ...utils.LegionAddress)
- func (l *Legion) BroadcastRandom(message *transport.Message, n int)
- func (l *Legion) DeletePeer(addresses ...utils.LegionAddress) error
- func (l *Legion) DoAllPeers(f func(p *Peer))
- func (l *Legion) FireMessageEvent(eventType events.MessageEvent, message *transport.Message)
- func (l *Legion) FireNetworkEvent(eventType events.NetworkEvent)
- func (l *Legion) FirePeerEvent(eventType events.PeerEvent, peer *Peer, isIncoming bool)
- func (l *Legion) Listen() error
- func (l *Legion) Me() utils.LegionAddress
- func (l *Legion) NewMessage(messageType string, body []byte) *transport.Message
- func (l *Legion) PeerExists(address utils.LegionAddress) bool
- func (l *Legion) Request(message *transport.Message, timeout time.Duration, address utils.LegionAddress) (*transport.Message, error)
- func (l *Legion) Started()
- func (l *Legion) Stop() error
- type MessageContext
- type NetworkContext
- type Peer
- func (p *Peer) BlockUntilDisconnected()
- func (p *Peer) Close() error
- func (p *Peer) CreateClient(conn net.Conn) error
- func (p *Peer) CreateServer(conn net.Conn) error
- func (p *Peer) IncomingMessages() chan *transport.Message
- func (p *Peer) QueueMessage(m *transport.Message)
- func (p *Peer) QueueReply(rpcID uint64, m *transport.Message)
- func (p *Peer) Remote() utils.LegionAddress
- func (p *Peer) Request(timeout time.Duration, m *transport.Message) (*transport.Message, error)
- type PeerContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Framework ¶ added in v0.0.5
type Framework interface { // Set anything up you want with Legion when the Listen method is called. // Should block until the framework is ready to accept messages. Configure(*Legion) error // Called before any message is passed to plugins ValidateMessage(*MessageContext) bool // Methods to interact with legion NewMessage(*MessageContext) PeerAdded(*PeerContext) PeerDisconnect(*PeerContext) Startup(*NetworkContext) Close(*NetworkContext) }
Framework is an interface that allows you to modify the underlying communication of legion
type GenericFramework ¶ added in v0.0.5
type GenericFramework struct{}
GenericFramework is a type used to expose methods so a framework doesn't need to have all of the required methods (it is also used as the default framework)
func (*GenericFramework) Close ¶ added in v0.0.5
func (*GenericFramework) Close(ctx *NetworkContext)
Close is called when the network is shutdown
func (*GenericFramework) Configure ¶ added in v0.0.5
func (*GenericFramework) Configure(*Legion) error
Configure is used to set anything up you want with Legion (loading plugins etc), it is called at startup
func (*GenericFramework) NewMessage ¶ added in v0.0.5
func (*GenericFramework) NewMessage(ctx *MessageContext)
NewMessage is called when a message is received by the network
func (*GenericFramework) PeerAdded ¶ added in v0.0.5
func (*GenericFramework) PeerAdded(ctx *PeerContext)
PeerAdded is called when a peer is added to the network
func (*GenericFramework) PeerDisconnect ¶ added in v0.0.5
func (*GenericFramework) PeerDisconnect(ctx *PeerContext)
PeerDisconnect is called when a peer is deleted
func (*GenericFramework) Startup ¶ added in v0.0.5
func (*GenericFramework) Startup(ctx *NetworkContext)
Startup is called when the local peer starts listening
func (*GenericFramework) ValidateMessage ¶ added in v0.0.5
func (*GenericFramework) ValidateMessage(ctx *MessageContext) bool
ValidateMessage is called before any message is passed to plugins
type Legion ¶
type Legion struct {
// contains filtered or unexported fields
}
Legion is a type with methods to interface with the network
func NewLegion ¶
func NewLegion(conf *config.LegionConfig, f Framework) *Legion
NewLegion creates a legion object from a config
func (*Legion) AddPeer ¶
func (l *Legion) AddPeer(addresses ...utils.LegionAddress) error
AddPeer adds the specified peer(s) to the network by dialing it and opening a stream, as well as adding it to the list of all peers.
func (*Legion) Broadcast ¶
func (l *Legion) Broadcast(message *transport.Message, addresses ...utils.LegionAddress)
Broadcast sends the message to all peers, unless a specified list of peers is provided
func (*Legion) BroadcastRandom ¶
BroadcastRandom broadcasts a message to N random peers
func (*Legion) DeletePeer ¶
func (l *Legion) DeletePeer(addresses ...utils.LegionAddress) error
DeletePeer closes all connections to a peer(s) and removes it from all peer lists. Returns an error if there is an error closing one or more peers. No matter the error, there will be an attempt to close all peers.
func (*Legion) DoAllPeers ¶
DoAllPeers runs the function f on all peers
func (*Legion) FireMessageEvent ¶
func (l *Legion) FireMessageEvent(eventType events.MessageEvent, message *transport.Message)
FireMessageEvent fires a new message event and sends context to the correct plugin methods based on the event type
func (*Legion) FireNetworkEvent ¶
func (l *Legion) FireNetworkEvent(eventType events.NetworkEvent)
FireNetworkEvent fires a network event and sends network context to the correct plugin method based on the event type. NOTE: This method blocks until all are completed
func (*Legion) FirePeerEvent ¶
FirePeerEvent fires a peer event and sends context to the correct plugin methods based on the event type
func (*Legion) Listen ¶
Listen will listen on the configured address for incoming connections, it will also wait for all plugin's Startup() methods to return before binding.
func (*Legion) NewMessage ¶
NewMessage returns a message with the sender field set to the bind address of the network and no extra data
func (*Legion) PeerExists ¶
func (l *Legion) PeerExists(address utils.LegionAddress) bool
PeerExists returns whether or not a peer has been connected to previously
type MessageContext ¶
type MessageContext struct { Sender utils.LegionAddress Message *transport.Message Legion *Legion }
MessageContext has context for a given message such as the legion object and methods to interact with the remote peer that sent the message
type NetworkContext ¶
type NetworkContext struct {
Legion *Legion
}
NetworkContext is general context of the network, gives access to just the legion object and a few other helpers
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer is an type that allows easy communication with a remote peer
func NewPeer ¶
func NewPeer(remote utils.LegionAddress) *Peer
NewPeer returns a new peer from the given remote. It also sets up the reading and writing channels
func (*Peer) BlockUntilDisconnected ¶
func (p *Peer) BlockUntilDisconnected()
BlockUntilDisconnected blocks until the remote is disconnected
func (*Peer) CreateClient ¶
CreateClient takes an outgoing connection and creates a client session from it
func (*Peer) CreateServer ¶
CreateServer takes an incoming connection and creates a server session from it
func (*Peer) IncomingMessages ¶
IncomingMessages registers a new listen channel and returns it
func (*Peer) QueueMessage ¶
QueueMessage queues the specified message to be sent to the remote
func (*Peer) QueueReply ¶ added in v0.0.5
QueueReply queues the specified message to be sent to the remote and appends the desired rpcid
func (*Peer) Remote ¶
func (p *Peer) Remote() utils.LegionAddress
Remote returns the address of the remote peer
type PeerContext ¶
PeerContext has context for a peer event such as the legion object and the peer change that fired the event