server

package
v0.6.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2015 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CLIENT is an end user.
	CLIENT = iota
	// ROUTER is another router in the cluster.
	ROUTER
)

Type of client

View Source
const (
	// VERSION is the current version for the server.
	VERSION = "0.6.8"

	// DEFAULT_PORT is the deault port for client connections.
	DEFAULT_PORT = 4222

	// RANDOM_PORT is the value for port that, when supplied, will cause the
	// server to listen on a randomly-chosen available port. The resolved port
	// is available via the Addr() method.
	RANDOM_PORT = -1

	// DEFAULT_HOST defaults to all interfaces.
	DEFAULT_HOST = "0.0.0.0"

	// MAX_CONTROL_LINE_SIZE is the maximum allowed protocol control line size.
	// 1k should be plenty since payloads sans connect string are separate
	MAX_CONTROL_LINE_SIZE = 1024

	// MAX_PAYLOAD_SIZE is the maximum allowed payload size. Should be using
	// something different if > 1MB payloads are needed.
	MAX_PAYLOAD_SIZE = (1024 * 1024)

	// MAX_PENDING_SIZE is the maximum outbound size (in bytes) per client.
	MAX_PENDING_SIZE = (10 * 1024 * 1024)

	// DEFAULT_MAX_CONNECTIONS is the default maximum connections allowed.
	DEFAULT_MAX_CONNECTIONS = (64 * 1024)

	// SSL_TIMEOUT is the TLS/SSL wait time.
	SSL_TIMEOUT = 500 * time.Millisecond

	// AUTH_TIMEOUT is the authorization wait time.
	AUTH_TIMEOUT = 2 * SSL_TIMEOUT

	// DEFAULT_PING_INTERVAL is how often pings are sent to clients and routes.
	DEFAULT_PING_INTERVAL = 2 * time.Minute

	// DEFAULT_PING_MAX_OUT is maximum allowed pings outstanding before disconnect.
	DEFAULT_PING_MAX_OUT = 2

	// CRLF string
	CR_LF = "\r\n"

	// LEN_CR_LF hold onto the computed size.
	LEN_CR_LF = len(CR_LF)

	// DEFAULT_FLUSH_DEADLINE is the write/flush deadlines.
	DEFAULT_FLUSH_DEADLINE = 2 * time.Second

	// DEFAULT_HTTP_PORT is the default monitoring port.
	DEFAULT_HTTP_PORT = 8222

	// ACCEPT_MIN_SLEEP is the minimum acceptable sleep times on temporary errors.
	ACCEPT_MIN_SLEEP = 10 * time.Millisecond

	// ACCEPT_MAX_SLEEP is the maximum acceptable sleep times on temporary errors
	ACCEPT_MAX_SLEEP = 1 * time.Second

	// DEFAULT_ROUTE_CONNECT Route solicitation intervals.
	DEFAULT_ROUTE_CONNECT = 1 * time.Second

	// DEFAULT_ROUTE_RECONNECT Route reconnect intervals.
	DEFAULT_ROUTE_RECONNECT = 1 * time.Second

	// DEFAULT_ROUTE_DIAL Route dial timeout.
	DEFAULT_ROUTE_DIAL = 1 * time.Second

	// PROTO_SNIPPET_SIZE is the default size of proto to print on parse errors.
	PROTO_SNIPPET_SIZE = 32

	// MAX_MSG_ARGS Maximum possible number of arguments from MSG proto.
	MAX_MSG_ARGS = 4

	// MAX_PUB_ARGS Maximum possible number of arguments from PUB proto.
	MAX_PUB_ARGS = 3

	// Default Buffer size for reads and writes per connection. Will be replaced by dynamic
	// system in the long run.
	DEFAULT_BUF_SIZE = 32768
)
View Source
const (
	OP_START = iota
	OP_PLUS
	OP_PLUS_O
	OP_PLUS_OK
	OP_MINUS
	OP_MINUS_E
	OP_MINUS_ER
	OP_MINUS_ERR
	OP_MINUS_ERR_SPC
	MINUS_ERR_ARG
	OP_C
	OP_CO
	OP_CON
	OP_CONN
	OP_CONNE
	OP_CONNEC
	OP_CONNECT
	CONNECT_ARG
	OP_P
	OP_PU
	OP_PUB
	OP_PUB_SPC
	PUB_ARG
	OP_PI
	OP_PIN
	OP_PING
	OP_PO
	OP_PON
	OP_PONG
	MSG_PAYLOAD
	MSG_END
	OP_S
	OP_SU
	OP_SUB
	OP_SUB_SPC
	SUB_ARG
	OP_U
	OP_UN
	OP_UNS
	OP_UNSU
	OP_UNSUB
	UNSUB_ARG
	OP_M
	OP_MS
	OP_MSG
	OP_MSG_SPC
	MSG_ARG
	OP_I
	OP_IN
	OP_INF
	OP_INFO
	INFO_ARG
)
View Source
const (
	RSID  = "RSID"
	QRSID = "QRSID"

	RSID_CID_INDEX   = 1
	RSID_SID_INDEX   = 2
	EXPECTED_MATCHES = 3
)
View Source
const DefaultConnListSize = 1024

Variables

View Source
var (
	// ErrConnectionClosed represents error condition on a closed connection.
	ErrConnectionClosed = errors.New("Connection Closed")

	// ErrAuthorization represents error condition on failed authorization.
	ErrAuthorization = errors.New("Authorization Error")

	// ErrMaxPayload represents error condition when the payload is too big.
	ErrMaxPayload = errors.New("Maximum Payload Exceeded")
)

Functions

func Debugf

func Debugf(format string, v ...interface{})

func Errorf added in v0.6.0

func Errorf(format string, v ...interface{})

func Fatalf

func Fatalf(format string, v ...interface{})

func Noticef added in v0.6.0

func Noticef(format string, v ...interface{})

func PrintAndDie

func PrintAndDie(msg string)

PrintAndDie is exported for access in other packages.

func PrintServerAndExit

func PrintServerAndExit()

PrintServerAndExit will print our version and exit.

func RemoveSelfReference added in v0.5.6

func RemoveSelfReference(clusterPort int, routes []*url.URL) ([]*url.URL, error)

func ResponseHandler added in v0.6.6

func ResponseHandler(w http.ResponseWriter, r *http.Request, data []byte)

ResponseHandler handles responses for monitoring routes

func RoutesFromStr added in v0.6.2

func RoutesFromStr(routesStr string) []*url.URL

func Tracef

func Tracef(format string, v ...interface{})

func Usage

func Usage()

Usage will print out the flag options for the server.

Types

type Auth added in v0.6.0

type Auth interface {
	Check(c ClientAuth) bool
}

type ByCid added in v0.6.2

type ByCid []Pair

func (ByCid) Len added in v0.6.2

func (d ByCid) Len() int

func (ByCid) Less added in v0.6.2

func (d ByCid) Less(i, j int) bool

func (ByCid) Swap added in v0.6.2

func (d ByCid) Swap(i, j int)

type ByInBytes added in v0.6.2

type ByInBytes []Pair

func (ByInBytes) Len added in v0.6.2

func (d ByInBytes) Len() int

func (ByInBytes) Less added in v0.6.2

func (d ByInBytes) Less(i, j int) bool

func (ByInBytes) Swap added in v0.6.2

func (d ByInBytes) Swap(i, j int)

type ByInMsgs added in v0.6.2

type ByInMsgs []Pair

func (ByInMsgs) Len added in v0.6.2

func (d ByInMsgs) Len() int

func (ByInMsgs) Less added in v0.6.2

func (d ByInMsgs) Less(i, j int) bool

func (ByInMsgs) Swap added in v0.6.2

func (d ByInMsgs) Swap(i, j int)

type ByOutBytes added in v0.6.2

type ByOutBytes []Pair

func (ByOutBytes) Len added in v0.6.2

func (d ByOutBytes) Len() int

func (ByOutBytes) Less added in v0.6.2

func (d ByOutBytes) Less(i, j int) bool

func (ByOutBytes) Swap added in v0.6.2

func (d ByOutBytes) Swap(i, j int)

type ByOutMsgs added in v0.6.2

type ByOutMsgs []Pair

func (ByOutMsgs) Len added in v0.6.2

func (d ByOutMsgs) Len() int

func (ByOutMsgs) Less added in v0.6.2

func (d ByOutMsgs) Less(i, j int) bool

func (ByOutMsgs) Swap added in v0.6.2

func (d ByOutMsgs) Swap(i, j int)

type ByPending added in v0.6.6

type ByPending []Pair

func (ByPending) Len added in v0.6.6

func (d ByPending) Len() int

func (ByPending) Less added in v0.6.6

func (d ByPending) Less(i, j int) bool

func (ByPending) Swap added in v0.6.6

func (d ByPending) Swap(i, j int)

type BySubs added in v0.6.2

type BySubs []Pair

func (BySubs) Len added in v0.6.2

func (d BySubs) Len() int

func (BySubs) Less added in v0.6.2

func (d BySubs) Less(i, j int) bool

func (BySubs) Swap added in v0.6.2

func (d BySubs) Swap(i, j int)

type ClientAuth added in v0.6.0

type ClientAuth interface {
	GetOpts() *clientOpts
}

type ConnInfo

type ConnInfo struct {
	Cid      uint64   `json:"cid"`
	IP       string   `json:"ip"`
	Port     int      `json:"port"`
	Pending  int      `json:"pending_bytes"`
	InMsgs   int64    `json:"in_msgs"`
	OutMsgs  int64    `json:"out_msgs"`
	InBytes  int64    `json:"in_bytes"`
	OutBytes int64    `json:"out_bytes"`
	NumSubs  uint32   `json:"subscriptions"`
	Lang     string   `json:"lang,omitempty"`
	Version  string   `json:"version,omitempty"`
	Subs     []string `json:"subscriptions_list,omitempty"`
}

ConnInfo has detailed information on a per connection basis.

type Connz

type Connz struct {
	Now      time.Time   `json:"now"`
	NumConns int         `json:"num_connections"`
	Offset   int         `json:"offset"`
	Limit    int         `json:"limit"`
	Conns    []*ConnInfo `json:"connections"`
}

Connz represents detailed information on current client connections.

type Info

type Info struct {
	ID           string `json:"server_id"`
	Version      string `json:"version"`
	GoVersion    string `json:"go"`
	Host         string `json:"host"`
	Port         int    `json:"port"`
	AuthRequired bool   `json:"auth_required"`
	SslRequired  bool   `json:"ssl_required"`
	MaxPayload   int    `json:"max_payload"`
}

Info is the information sent to clients to help them understand information about this server.

type Logger added in v0.6.0

type Logger interface {
	Noticef(format string, v ...interface{})
	Fatalf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Debugf(format string, v ...interface{})
	Tracef(format string, v ...interface{})
}

type Options

type Options struct {
	Host               string        `json:"addr"`
	Port               int           `json:"port"`
	Trace              bool          `json:"-"`
	Debug              bool          `json:"-"`
	NoLog              bool          `json:"-"`
	NoSigs             bool          `json:"-"`
	Logtime            bool          `json:"-"`
	MaxConn            int           `json:"max_connections"`
	Username           string        `json:"user,omitempty"`
	Password           string        `json:"-"`
	Authorization      string        `json:"-"`
	PingInterval       time.Duration `json:"ping_interval"`
	MaxPingsOut        int           `json:"ping_max"`
	HTTPPort           int           `json:"http_port"`
	SslTimeout         float64       `json:"ssl_timeout"`
	AuthTimeout        float64       `json:"auth_timeout"`
	MaxControlLine     int           `json:"max_control_line"`
	MaxPayload         int           `json:"max_payload"`
	MaxPending         int           `json:"max_pending_size"`
	ClusterHost        string        `json:"addr"`
	ClusterPort        int           `json:"port"`
	ClusterUsername    string        `json:"-"`
	ClusterPassword    string        `json:"-"`
	ClusterAuthTimeout float64       `json:"auth_timeout"`
	ProfPort           int           `json:"-"`
	PidFile            string        `json:"-"`
	LogFile            string        `json:"-"`
	Syslog             bool          `json:"-"`
	RemoteSyslog       string        `json:"-"`
	Routes             []*url.URL    `json:"-"`
	RoutesStr          string        `json:"-"`
	BufSize            int           `json:"-"`
}

Options block for gnatsd server.

func MergeOptions

func MergeOptions(fileOpts, flagOpts *Options) *Options

MergeOptions will merge two options giving preference to the flagOpts if the item is present.

func ProcessConfigFile

func ProcessConfigFile(configFile string) (*Options, error)

ProcessConfigFile processes a configuration file. FIXME(dlc): Hacky

type Pair added in v0.6.2

type Pair struct {
	Key uint64
	Val *client
}

type RouteInfo added in v0.6.0

type RouteInfo struct {
	Rid        uint64   `json:"rid"`
	RemoteId   string   `json:"remote_id"`
	DidSolicit bool     `json:"did_solicit"`
	IP         string   `json:"ip"`
	Port       int      `json:"port"`
	Pending    int      `json:"pending_size"`
	InMsgs     int64    `json:"in_msgs"`
	OutMsgs    int64    `json:"out_msgs"`
	InBytes    int64    `json:"in_bytes"`
	OutBytes   int64    `json:"out_bytes"`
	NumSubs    uint32   `json:"subscriptions"`
	Subs       []string `json:"subscriptions_list,omitempty"`
}

RouteInfo has detailed information on a per connection basis.

type Routez added in v0.6.0

type Routez struct {
	Now       time.Time    `json:"now"`
	NumRoutes int          `json:"num_routes"`
	Routes    []*RouteInfo `json:"routes"`
}

Routez represents detailed information on current client connections.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is our main struct.

func New

func New(opts *Options) *Server

New will setup a new server struct after parsing the options.

func (*Server) AcceptLoop

func (s *Server) AcceptLoop()

AcceptLoop is exported for easier testing.

func (*Server) Addr added in v0.5.4

func (s *Server) Addr() net.Addr

Addr will return the net.Addr object for the current listener.

func (*Server) HandleConnz

func (s *Server) HandleConnz(w http.ResponseWriter, r *http.Request)

HandleConnz process HTTP requests for connection information.

func (*Server) HandleRoot added in v0.6.2

func (s *Server) HandleRoot(w http.ResponseWriter, r *http.Request)

HandleRoot will show basic info and links to others handlers.

func (*Server) HandleRoutez added in v0.6.0

func (s *Server) HandleRoutez(w http.ResponseWriter, r *http.Request)

HandleRoutez process HTTP requests for route information.

func (*Server) HandleSubsz added in v0.6.0

func (s *Server) HandleSubsz(w http.ResponseWriter, r *http.Request)

HandleStats process HTTP requests for subjects stats.

func (*Server) HandleVarz

func (s *Server) HandleVarz(w http.ResponseWriter, r *http.Request)

HandleVarz will process HTTP requests for server information.

func (*Server) NumClients

func (s *Server) NumClients() int

NumClients will report the number of registered clients.

func (*Server) NumRemotes

func (s *Server) NumRemotes() int

NumRemotes will report number of registered remotes.

func (*Server) NumRoutes

func (s *Server) NumRoutes() int

NumRoutes will report the number of registered routes.

func (*Server) NumSubscriptions

func (s *Server) NumSubscriptions() uint32

NumSubscriptions will report how many subscriptions are active.

func (*Server) SetAuthMethod added in v0.6.0

func (s *Server) SetAuthMethod(authMethod Auth)

Sets the authentication method

func (*Server) SetLogger added in v0.6.0

func (s *Server) SetLogger(logger Logger, debugFlag, traceFlag bool)

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown will shutdown the server instance by kicking out the AcceptLoop and closing all associated clients.

func (*Server) Start

func (s *Server) Start()

Start up the server, this will block. Start via a Go routine if needed.

func (*Server) StartHTTPMonitoring

func (s *Server) StartHTTPMonitoring()

StartHTTPMonitoring will enable the HTTP monitoring port.

func (*Server) StartProfiler

func (s *Server) StartProfiler()

StartProfiler is called to enable dynamic profiling.

func (*Server) StartRouting

func (s *Server) StartRouting()

StartRouting will start the accept loop on the cluster host:port and will actively try to connect to listed routes.

type SortOpt added in v0.6.2

type SortOpt string

Helper types to sort by ConnInfo values

type Subsz added in v0.6.0

type Subsz struct {
	*sublist.Stats
}

Subsz represents detail information on current connections.

type Varz

type Varz struct {
	*Info
	*Options
	MaxPayload    int       `json:"max_payload"`
	Start         time.Time `json:"start"`
	Now           time.Time `json:"now"`
	Uptime        string    `json:"uptime"`
	Mem           int64     `json:"mem"`
	Cores         int       `json:"cores"`
	CPU           float64   `json:"cpu"`
	Connections   int       `json:"connections"`
	Routes        int       `json:"routes"`
	Remotes       int       `json:"remotes"`
	InMsgs        int64     `json:"in_msgs"`
	OutMsgs       int64     `json:"out_msgs"`
	InBytes       int64     `json:"in_bytes"`
	OutBytes      int64     `json:"out_bytes"`
	SlowConsumers int64     `json:"slow_consumers"`
}

Varz will output server information on the monitoring port at /varz.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL