Documentation
¶
Index ¶
- Constants
- func RandomPort() (int, error)
- func StubbedPacket(_ *Peer, _ protocol.Packet) error
- type PacketEvent
- type PacketHandler
- type Peer
- type Service
- func (srvc *Service) AddPacketHandler(pktID uint32, handler PacketHandler)
- func (srvc *Service) Lock()
- func (srvc *Service) RangePeers(f func(peer *Peer) bool)
- func (srvc *Service) Reset(ctx context.Context)
- func (srvc *Service) Start() error
- func (srvc *Service) Started() <-chan struct{}
- func (srvc *Service) Stopped() <-chan struct{}
- func (srvc *Service) Unlock()
Constants ¶
View Source
const ( USE_E = iota USE_FE )
Variables ¶
This section is empty.
Functions ¶
func RandomPort ¶
Types ¶
type Peer ¶
type Peer struct {
// May not be set while Send() or Handler() are concurrently running.
E_key []byte
// May not be set while Send() or Handler() are concurrently running.
FE_key []byte
// contains filtered or unexported fields
}
Peer is a simple wrapper for net.Conn connections to send/recv packets over the Fusionfall packet protocol.
func (*Peer) Handler ¶
func (peer *Peer) Handler(eRecv chan<- *PacketEvent) error
meant to be invoked as a goroutine
func (*Peer) SetActiveKey ¶
func (*Peer) SetUserData ¶
func (peer *Peer) SetUserData(uData interface{})
type Service ¶
type Service struct {
Name string
// OnDisconnect is called when a peer disconnects from the service.
// uData is the stored value of the key/value pair in the peer map.
// It may not be set while the service is running. (eg. srvc.Start() has been called)
OnDisconnect func(peer *Peer)
// OnConnect is called when a peer connects to the service.
// return value is used as the value in the peer map.
// It may not be set while the service is running. (eg. srvc.Start() has been called)
OnConnect func(peer *Peer)
// contains filtered or unexported fields
}
func (*Service) AddPacketHandler ¶
func (srvc *Service) AddPacketHandler(pktID uint32, handler PacketHandler)
may not be called while the service is running (eg. srvc.Start() has been called)
func (*Service) RangePeers ¶
calls f for each peer in the service passing the peer and the stored uData. if f returns false, the iteration is stopped. NOTE: the peer map is not locked while iterating, if you're calling this outside of the service's event loop, you'll need to lock the peer map yourself.
func (*Service) Started ¶
func (srvc *Service) Started() <-chan struct{}
returns a channel that is closed when the service has started. this is useful if you need to wait until after the service has started.
Click to show internal directories.
Click to hide internal directories.