github.com/nats-io/nats-server/v2@v2.11.0-preview.2/server/const.go (about)

     1  // Copyright 2012-2024 The NATS Authors
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package server
    15  
    16  import (
    17  	"regexp"
    18  	"time"
    19  )
    20  
    21  // Command is a signal used to control a running nats-server process.
    22  type Command string
    23  
    24  // Valid Command values.
    25  const (
    26  	CommandStop   = Command("stop")
    27  	CommandQuit   = Command("quit")
    28  	CommandReopen = Command("reopen")
    29  	CommandReload = Command("reload")
    30  
    31  	// private for now
    32  	commandLDMode = Command("ldm")
    33  	commandTerm   = Command("term")
    34  )
    35  
    36  var (
    37  	// gitCommit injected at build
    38  	gitCommit string
    39  	// trustedKeys is a whitespace separated array of trusted operator's public nkeys.
    40  	trustedKeys string
    41  	// SemVer regexp to validate the VERSION.
    42  	semVerRe = regexp.MustCompile(`^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$`)
    43  )
    44  
    45  const (
    46  	// VERSION is the current version for the server.
    47  	VERSION = "2.11.0-preview.2"
    48  
    49  	// PROTO is the currently supported protocol.
    50  	// 0 was the original
    51  	// 1 maintains proto 0, adds echo abilities for CONNECT from the client. Clients
    52  	// should not send echo unless proto in INFO is >= 1.
    53  	PROTO = 1
    54  
    55  	// DEFAULT_PORT is the default port for client connections.
    56  	DEFAULT_PORT = 4222
    57  
    58  	// RANDOM_PORT is the value for port that, when supplied, will cause the
    59  	// server to listen on a randomly-chosen available port. The resolved port
    60  	// is available via the Addr() method.
    61  	RANDOM_PORT = -1
    62  
    63  	// DEFAULT_HOST defaults to all interfaces.
    64  	DEFAULT_HOST = "0.0.0.0"
    65  
    66  	// MAX_CONTROL_LINE_SIZE is the maximum allowed protocol control line size.
    67  	// 4k should be plenty since payloads sans connect/info string are separate.
    68  	MAX_CONTROL_LINE_SIZE = 4096
    69  
    70  	// MAX_PAYLOAD_SIZE is the maximum allowed payload size. Should be using
    71  	// something different if > 1MB payloads are needed.
    72  	MAX_PAYLOAD_SIZE = (1024 * 1024)
    73  
    74  	// MAX_PAYLOAD_MAX_SIZE is the size at which the server will warn about
    75  	// max_payload being too high. In the future, the server may enforce/reject
    76  	// max_payload above this value.
    77  	MAX_PAYLOAD_MAX_SIZE = (8 * 1024 * 1024)
    78  
    79  	// MAX_PENDING_SIZE is the maximum outbound pending bytes per client.
    80  	MAX_PENDING_SIZE = (64 * 1024 * 1024)
    81  
    82  	// DEFAULT_MAX_CONNECTIONS is the default maximum connections allowed.
    83  	DEFAULT_MAX_CONNECTIONS = (64 * 1024)
    84  
    85  	// TLS_TIMEOUT is the TLS wait time.
    86  	TLS_TIMEOUT = 2 * time.Second
    87  
    88  	// DEFAULT_TLS_HANDSHAKE_FIRST_FALLBACK_DELAY is the default amount of
    89  	// time for the server to wait for the TLS handshake with a client to
    90  	// be initiated before falling back to sending the INFO protocol first.
    91  	// See TLSHandshakeFirst and TLSHandshakeFirstFallback options.
    92  	DEFAULT_TLS_HANDSHAKE_FIRST_FALLBACK_DELAY = 50 * time.Millisecond
    93  
    94  	// AUTH_TIMEOUT is the authorization wait time.
    95  	AUTH_TIMEOUT = 2 * time.Second
    96  
    97  	// DEFAULT_PING_INTERVAL is how often pings are sent to clients, etc...
    98  	DEFAULT_PING_INTERVAL = 2 * time.Minute
    99  
   100  	// DEFAULT_PING_MAX_OUT is maximum allowed pings outstanding before disconnect.
   101  	DEFAULT_PING_MAX_OUT = 2
   102  
   103  	// CR_LF string
   104  	CR_LF = "\r\n"
   105  
   106  	// LEN_CR_LF hold onto the computed size.
   107  	LEN_CR_LF = len(CR_LF)
   108  
   109  	// DEFAULT_FLUSH_DEADLINE is the write/flush deadlines.
   110  	DEFAULT_FLUSH_DEADLINE = 10 * time.Second
   111  
   112  	// DEFAULT_HTTP_PORT is the default monitoring port.
   113  	DEFAULT_HTTP_PORT = 8222
   114  
   115  	// DEFAULT_HTTP_BASE_PATH is the default base path for monitoring.
   116  	DEFAULT_HTTP_BASE_PATH = "/"
   117  
   118  	// ACCEPT_MIN_SLEEP is the minimum acceptable sleep times on temporary errors.
   119  	ACCEPT_MIN_SLEEP = 10 * time.Millisecond
   120  
   121  	// ACCEPT_MAX_SLEEP is the maximum acceptable sleep times on temporary errors
   122  	ACCEPT_MAX_SLEEP = 1 * time.Second
   123  
   124  	// DEFAULT_ROUTE_CONNECT Route solicitation intervals.
   125  	DEFAULT_ROUTE_CONNECT = 1 * time.Second
   126  
   127  	// DEFAULT_ROUTE_RECONNECT Route reconnect intervals.
   128  	DEFAULT_ROUTE_RECONNECT = 1 * time.Second
   129  
   130  	// DEFAULT_ROUTE_DIAL Route dial timeout.
   131  	DEFAULT_ROUTE_DIAL = 1 * time.Second
   132  
   133  	// DEFAULT_ROUTE_POOL_SIZE Route default pool size
   134  	DEFAULT_ROUTE_POOL_SIZE = 3
   135  
   136  	// DEFAULT_LEAF_NODE_RECONNECT LeafNode reconnect interval.
   137  	DEFAULT_LEAF_NODE_RECONNECT = time.Second
   138  
   139  	// DEFAULT_LEAF_TLS_TIMEOUT TLS timeout for LeafNodes
   140  	DEFAULT_LEAF_TLS_TIMEOUT = 2 * time.Second
   141  
   142  	// PROTO_SNIPPET_SIZE is the default size of proto to print on parse errors.
   143  	PROTO_SNIPPET_SIZE = 32
   144  
   145  	// MAX_CONTROL_LINE_SNIPPET_SIZE is the default size of proto to print on max control line errors.
   146  	MAX_CONTROL_LINE_SNIPPET_SIZE = 128
   147  
   148  	// MAX_MSG_ARGS Maximum possible number of arguments from MSG proto.
   149  	MAX_MSG_ARGS = 4
   150  
   151  	// MAX_RMSG_ARGS Maximum possible number of arguments from RMSG proto.
   152  	MAX_RMSG_ARGS = 6
   153  
   154  	// MAX_HMSG_ARGS Maximum possible number of arguments from HMSG proto.
   155  	MAX_HMSG_ARGS = 7
   156  
   157  	// MAX_PUB_ARGS Maximum possible number of arguments from PUB proto.
   158  	MAX_PUB_ARGS = 3
   159  
   160  	// MAX_HPUB_ARGS Maximum possible number of arguments from HPUB proto.
   161  	MAX_HPUB_ARGS = 4
   162  
   163  	// DEFAULT_MAX_CLOSED_CLIENTS is the maximum number of closed connections we hold onto.
   164  	DEFAULT_MAX_CLOSED_CLIENTS = 10000
   165  
   166  	// DEFAULT_LAME_DUCK_DURATION is the time in which the server spreads
   167  	// the closing of clients when signaled to go in lame duck mode.
   168  	DEFAULT_LAME_DUCK_DURATION = 2 * time.Minute
   169  
   170  	// DEFAULT_LAME_DUCK_GRACE_PERIOD is the duration the server waits, after entering
   171  	// lame duck mode, before starting closing client connections.
   172  	DEFAULT_LAME_DUCK_GRACE_PERIOD = 10 * time.Second
   173  
   174  	// DEFAULT_LEAFNODE_INFO_WAIT Route dial timeout.
   175  	DEFAULT_LEAFNODE_INFO_WAIT = 1 * time.Second
   176  
   177  	// DEFAULT_LEAFNODE_PORT is the default port for remote leafnode connections.
   178  	DEFAULT_LEAFNODE_PORT = 7422
   179  
   180  	// DEFAULT_CONNECT_ERROR_REPORTS is the number of attempts at which a
   181  	// repeated failed route, gateway or leaf node connection is reported.
   182  	// This is used for initial connection, that is, when the server has
   183  	// never had a connection to the given endpoint. Once connected, and
   184  	// if a disconnect occurs, DEFAULT_RECONNECT_ERROR_REPORTS is used
   185  	// instead.
   186  	// The default is to report every 3600 attempts (roughly every hour).
   187  	DEFAULT_CONNECT_ERROR_REPORTS = 3600
   188  
   189  	// DEFAULT_RECONNECT_ERROR_REPORTS is the default number of failed
   190  	// attempt to reconnect a route, gateway or leaf node connection.
   191  	// The default is to report every attempt.
   192  	DEFAULT_RECONNECT_ERROR_REPORTS = 1
   193  
   194  	// DEFAULT_RTT_MEASUREMENT_INTERVAL is how often we want to measure RTT from
   195  	// this server to clients, routes, gateways or leafnode connections.
   196  	DEFAULT_RTT_MEASUREMENT_INTERVAL = time.Hour
   197  
   198  	// DEFAULT_ALLOW_RESPONSE_MAX_MSGS is the default number of responses allowed
   199  	// for a reply subject.
   200  	DEFAULT_ALLOW_RESPONSE_MAX_MSGS = 1
   201  
   202  	// DEFAULT_ALLOW_RESPONSE_EXPIRATION is the default time allowed for a given
   203  	// dynamic response permission.
   204  	DEFAULT_ALLOW_RESPONSE_EXPIRATION = 2 * time.Minute
   205  
   206  	// DEFAULT_SERVICE_EXPORT_RESPONSE_THRESHOLD is the default time that the system will
   207  	// expect a service export response to be delivered. This is used in corner cases for
   208  	// time based cleanup of reverse mapping structures.
   209  	DEFAULT_SERVICE_EXPORT_RESPONSE_THRESHOLD = 2 * time.Minute
   210  
   211  	// DEFAULT_SERVICE_LATENCY_SAMPLING is the default sampling rate for service
   212  	// latency metrics
   213  	DEFAULT_SERVICE_LATENCY_SAMPLING = 100
   214  
   215  	// DEFAULT_SYSTEM_ACCOUNT
   216  	DEFAULT_SYSTEM_ACCOUNT = "$SYS"
   217  
   218  	// DEFAULT GLOBAL_ACCOUNT
   219  	DEFAULT_GLOBAL_ACCOUNT = "$G"
   220  
   221  	// DEFAULT_FETCH_TIMEOUT is the default time that the system will wait for an account fetch to return.
   222  	DEFAULT_ACCOUNT_FETCH_TIMEOUT = 1900 * time.Millisecond
   223  )