Documentation
¶
Index ¶
- Variables
- func UnregisterService(name string) error
- type Context
- func (c *Context) GetNetBlocks(si *network.ServerIdentity) int
- func (c *Context) RegisterProcessor(p network.Processor, msgType network.MessageTypeID)
- func (c *Context) RegisterProcessorFunc(msgType network.MessageTypeID, fn func(*network.Envelope))
- func (c *Context) SendRaw(si *network.ServerIdentity, msg interface{}, bForeConnect bool) error
- func (c *Context) ServerIdentity() *network.ServerIdentity
- func (c *Context) Service(name string) Service
- func (c *Context) ServiceID() ServiceID
- func (c *Context) String() string
- type GenericConfig
- type NewServiceFunc
- type Server
- type Service
- type ServiceID
- type ServiceProcessor
Constants ¶
This section is empty.
Variables ¶
var NilServiceID = ServiceID(uuid.Nil)
NilServiceID is the empty ServiceID
var ServiceFactory = serviceFactory{ // contains filtered or unexported fields }
ServiceFactory is the global service factory to instantiate Services
Functions ¶
func UnregisterService ¶
UnregisterService removes a service from the global pool.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents the methods that are available to a service.
func (*Context) GetNetBlocks ¶
func (c *Context) GetNetBlocks(si *network.ServerIdentity) int
func (*Context) RegisterProcessor ¶
func (c *Context) RegisterProcessor(p network.Processor, msgType network.MessageTypeID)
RegisterProcessor overrides the RegisterProcessor methods of the Dispatcher. It delegates the dispatching to the serviceManager.
func (*Context) RegisterProcessorFunc ¶
func (c *Context) RegisterProcessorFunc(msgType network.MessageTypeID, fn func(*network.Envelope))
RegisterProcessorFunc takes a message-type and a function that will be called if this message-type is received.
func (*Context) SendRaw ¶
func (c *Context) SendRaw(si *network.ServerIdentity, msg interface{}, bForeConnect bool) error
SendRaw sends a message to the ServerIdentity.
func (*Context) ServerIdentity ¶
func (c *Context) ServerIdentity() *network.ServerIdentity
ServerIdentity returns this server's identity.
type GenericConfig ¶
type GenericConfig struct {
Data []byte
}
GenericConfig is a config that can hold any type of specific configs for protocols. It is passed down to the service NewProtocol function.
type NewServiceFunc ¶
NewServiceFunc is the type of a function that is used to instantiate a given Service A service is initialized with a Server (to send messages to someone).
type Server ¶
Server connects the Router and the Services together. It sets up everything and returns once a working network has been set up.
func NewKcpServer ¶
func NewServerKCPWithListenAddr ¶
func NewServerKCPWithListenAddr(e *network.ServerIdentity, listenAddr string) *Server
NewServerKCPWithListenAddr returns a new Server out of a private-key and its related address within the ServerIdentity. The server will use a KcpRouter listening on the given address as Router.
func (*Server) AdjustConnect ¶
CloseConnect close remote connection
func (*Server) GetService ¶
GetService is kept for backward-compatibility.
type Service ¶
type Service interface { // NewProtocol is called upon a ProtocolInstance's first message when Rnet needs // to instantiate the protocol. A Service is expected to manually create // the ProtocolInstance it is using. If a Service returns (nil,nil), that // means this Service lets Rnet handle the protocol instance. //NewProtocol(*TreeNodeInstance, *GenericConfig) (ProtocolInstance, error) // ProcessClientRequest is called when a message from an // external client is received by the websocket for this // service. It returns a message that will be sent back to the // client. The returned error will be formatted as a websocket // error code 4000, using the string form of the error as the message. ProcessClientRequest(req *http.Request, handler string, msg []byte) (reply []byte, err error) // Processor makes a Service being able to handle any kind of packets // directly from the network. It is used for inter service communications, // which are mostly single packets with no or little interactions needed. If // a complex logic is used for these messages, it's best to put that logic // into a ProtocolInstance that the Service will launch, since there's nicer // utilities for ProtocolInstance. network.Processor }
Service is a generic interface to define any type of services. A Service has multiple roles:
- Processing websocket client requests with ProcessClientRequests
- Handling rnet information to ProtocolInstances created with NewProtocol
- Handling any kind of messages between Services between different hosts with the Processor interface
type ServiceID ¶
ServiceID is a type to represent a uuid for a Service
func RegisterNewService ¶
func RegisterNewService(name string, fn NewServiceFunc) (ServiceID, error)
RegisterNewService is a wrapper around service factory
type ServiceProcessor ¶
type ServiceProcessor struct { *Context // contains filtered or unexported fields }
ServiceProcessor allows for an easy integration of external messages into the Services. You have to embed it into your Service-struct as a pointer. It will process client requests that have been registered with RegisterMessage.
func NewServiceProcessor ¶
func NewServiceProcessor(c *Context) *ServiceProcessor
NewServiceProcessor initializes your ServiceProcessor.
func (*ServiceProcessor) Process ¶
func (p *ServiceProcessor) Process(env *network.Envelope)
Process implements the Processor interface and dispatches ClientRequest messages.
func (*ServiceProcessor) ProcessClientRequest ¶
func (p *ServiceProcessor) ProcessClientRequest(req *http.Request, path string, buf []byte) ([]byte, error)
ProcessClientRequest takes a request from a websocket client, calculates the reply and sends it back. It uses the path to find the appropriate handler- function. It implements the Server interface.