Documentation
¶
Index ¶
- Variables
- type AcceptStreamFunc
- type AuthFunc
- type Config
- type Init
- type InitAcceptStreams
- type InitControl
- type InitControls
- type InitMany
- type InitSignal
- type InitSignaler
- type InitSignalers
- type Server
- type ServerConfig
- type Session
- func ClientSession(conn net.Conn, config *Config) (s *Session, err error)
- func ClientSessionWithCloser(conn net.Conn, config *Config, cl closer.Closer) (s *Session, err error)
- func ServerSession(conn net.Conn, config *Config) (s *Session, err error)
- func ServerSessionWithCloser(conn net.Conn, config *Config, cl closer.Closer) (s *Session, err error)
- func (s *Session) AcceptStream(channel string, f AcceptStreamFunc)
- func (s *Session) ID() string
- func (s *Session) Init(opts *Init) (control *control.Control, signaler *signaler.Signaler, err error)
- func (s *Session) InitMany(opts *InitMany) (controls map[string]*control.Control, signalers map[string]*signaler.Signaler, ...)
- func (s *Session) IsClient() bool
- func (s *Session) IsServer() bool
- func (s *Session) LocalAddr() net.Addr
- func (s *Session) OpenStream(channel string) (stream net.Conn, err error)
- func (s *Session) OpenStreamTimeout(channel string, timeout time.Duration) (stream net.Conn, err error)
- func (s *Session) RemoteAddr() net.Addr
- func (s *Session) SetID(id string)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidVersion defines the error if the version of both peers do not match // during the version exchange. ErrIncompatibleVersion = errors.New("invalid version") // ErrOpenTimeout defines the error if the opening of a stream timeouts. ErrOpenTimeout = errors.New("open timeout") // ErrClosed defines the error if a stream is unexpectedly closed. ErrClosed = errors.New("closed") )
Functions ¶
This section is empty.
Types ¶
type AcceptStreamFunc ¶
The AcceptStreamFunc type describes the function that is called whenever a new connection is requested on a peer. It must then handle the new connection, if it could be set up correctly.
type AuthFunc ¶
The AuthFunc type describes the function that is used during the authentication phase of the session initialization. It may use the given connection to perform some kind of data exchange between the client and the server. It can return some arbitrary data that will be saved to the session. It must return a non nil error, if the authentication did fail.
type Config ¶
type Config struct {
// Codec used to encode and decode orbit messages.
// Defaults to msgpack.
Codec codec.Codec
// KeepAliveInterval is how often to perform the keep alive.
// Default to 30 seconds.
KeepAliveInterval time.Duration
// Logger is used to pass in the logger to be used.
// Uses a default logger to os.Stderr.
Logger *log.Logger
// AuthFunc authenticates the session connection if defined.
// It gets called right after the version byte has been exchanged
// between client and server. Therefore, not much resources are wasted
// in case the authentication fails.
AuthFunc AuthFunc
}
type Init ¶
type Init struct {
AcceptStreams InitAcceptStreams
Control InitControl
Signaler InitSignaler
}
The Init type is used during the initialization of the orbit session and contains the definition to accept streams and define exactly one control and one signaler.
type InitAcceptStreams ¶
type InitAcceptStreams map[string]AcceptStreamFunc
The InitAcceptStreams type is a map of AcceptStreamFunc, where the key is the id of the stream and the value the func that is used to accept it.
type InitControl ¶
The InitControl type is used to initialize one control. It contains the functions that the remote peer can call and a config.
type InitControls ¶
type InitControls map[string]InitControl
The InitControls type is a map, where the key is the id of a control and the value the associated InitControl.
type InitMany ¶
type InitMany struct {
AcceptStreams InitAcceptStreams
Controls InitControls
Signalers InitSignalers
}
The Init type is used during the initialization of the orbit session and contains the definition to accept streams and define many controls and many signalers.
type InitSignal ¶
type InitSignal struct {
ID string
Filter signaler.FilterFunc
}
The InitSignal type is used to initialize one signal. It contains the id of the signal and a filter for it.
type InitSignaler ¶
type InitSignaler struct {
Signals []InitSignal
Config *control.Config
}
The InitSignaler type is used to initialize one signaler. It contains the signals that can be triggered and a config.
type InitSignalers ¶
type InitSignalers map[string]InitSignaler
The InitSignalers type is a map, where the key is the id of a signaler and the value the associated InitSignaler.
type Server ¶
Server implements a simple orbit server. It listens with serverWorkers many routines for incoming connections.
func NewServer ¶
func NewServer(ln net.Listener, config *ServerConfig) *Server
NewServer creates a new orbit server. A listener is required the server will use to listen for incoming connections. A config can be provided, where every property of it that has not been set will be initialized with a default value. That makes it possible to overwrite only the interesting properties for the caller.
func NewServerWithCloser ¶
NewServerWithCloser creates a new orbit server just like NewServer() does, but you can provide your own closer for it.
func (*Server) Listen ¶
Listen listens for new socket connections, which it passes to the new connection channel that is read by the server workers. This method is blocking.
func (*Server) NewSessionChan ¶
NewSessionChan returns the channel for new incoming sessions.
type ServerConfig ¶
type ServerConfig struct {
// Embed the standard config that both clients and servers share.
*Config
// The number of goroutines that handle incoming connections on the server.
NewConnNumberWorkers int
// The size of the channel on which new connections are passed to the
// server workers.
// Should not be less than NewConnNumberWorkers.
NewConnChanSize int
// The size of the channel on which new server sessions are passed into,
// so that a user of this package can read them from it.
// Should not be less than NewConnNumberWorkers.
NewSessionChanSize int
}
type Session ¶
type Session struct {
closer.Closer
// Value is a custom value which can be set. In case the config contains
// a valid AuthFunc, the Value will be set to the return value of it.
Value interface{}
// contains filtered or unexported fields
}
The Session type describes a orbit session that is used on both the client and server side, so in general for peers. It contains its underlying connection to the remote peer and may accept new incoming connections by defining AcceptStreamFuncs.
func ClientSession ¶
ClientSession is used to initialize a new client-side session. A config can be provided, where every property of it that has not been set will be initialized with a default value. That makes it possible to overwrite only the interesting properties for the caller. When the connection to the server has been established, one byte containing the version of the client is sent to the server. In case the versions do not match, the server will close the connection. As part of the session setup, the auth func of the config is called, if it has been defined.
func ClientSessionWithCloser ¶
func ClientSessionWithCloser(conn net.Conn, config *Config, cl closer.Closer) (s *Session, err error)
ClientSessionWithCloser initializes a new client-side session, just like ClientSession() does, but allows to hand in an own closer.
func ServerSession ¶
ServerSession is used to initialize a new server-side session. A config can be provided, where every property of it that has not been set will be initialized with a default value. That makes it possible to overwrite only the interesting properties for the caller. When the connection has been established, the server waits for the API version byte of the client. If the versions do not match, the server immediately closes the connection. As part of the session setup, the auth func of the config is called, if it has been defined.
func ServerSessionWithCloser ¶
func ServerSessionWithCloser(conn net.Conn, config *Config, cl closer.Closer) (s *Session, err error)
ServerSessionWithCloser initializes a new server-side session, just as ServerSession() does, but allows to hand in an own closer.
func (*Session) AcceptStream ¶
func (s *Session) AcceptStream(channel string, f AcceptStreamFunc)
AcceptStream registers the given accept handler for the specific channel.
func (*Session) Init ¶
func (s *Session) Init(opts *Init) ( control *control.Control, signaler *signaler.Signaler, err error, )
Init initializes the session by using InitMany(), but only defining one control and one signaler. If no more than one control/signaler are needed, this is the more convenient method to call. Ready() must be called manually for the control and signaler afterwards.
func (*Session) InitMany ¶
func (s *Session) InitMany(opts *InitMany) ( controls map[string]*control.Control, signalers map[string]*signaler.Signaler, err error, )
InitMany initializes this session. Pass nil to just start accepting streams. Ready() must be called manually for all controls and signaler afterwards.
func (*Session) OpenStream ¶
OpenStream performs the same task as OpenStreamTimeout, but uses the default write timeout openStreamWriteTimeout.
func (*Session) OpenStreamTimeout ¶
func (s *Session) OpenStreamTimeout(channel string, timeout time.Duration) (stream net.Conn, err error)
OpenStreamTimeout opens a new stream with the given channel ID. Expires after the timeout and returns ErrOpenTimeout.
func (*Session) RemoteAddr ¶
RemoteAddr returns the remote network address.