| 1 |
package centrifuge |
| 2 |
|
| 3 |
import ( |
| 4 |
"time" |
| 5 |
) |
| 6 |
|
| 7 |
// Config contains Node configuration options. |
| 8 |
type Config struct { |
| 9 |
// Version of server – will be sent to a client on connection establishment |
| 10 |
// phase in reply to connect command from a client. |
| 11 |
Version string |
| 12 |
// Name is a unique name of the current server Node. Name used as human-readable |
| 13 |
// and meaningful node identifier. If not set then os.Hostname will be used. |
| 14 |
Name string |
| 15 |
// LogLevel is a log level. By default, nothing will be logged by Centrifuge. |
| 16 |
LogLevel LogLevel |
| 17 |
// LogHandler is a handler function Node will send logs to. |
| 18 |
LogHandler LogHandler |
| 19 |
// NodeInfoMetricsAggregateInterval sets interval for automatic metrics |
| 20 |
// aggregation. It's not reasonable to have it less than one second. |
| 21 |
NodeInfoMetricsAggregateInterval time.Duration |
| 22 |
// ClientPresenceUpdateInterval sets an interval how often connected |
| 23 |
// clients update presence information. |
| 24 |
ClientPresenceUpdateInterval time.Duration |
| 25 |
// ClientExpiredCloseDelay is an extra time given to client to refresh |
| 26 |
// its connection in the end of connection TTL. At moment only used for |
| 27 |
// a client-side refresh workflow. |
| 28 |
ClientExpiredCloseDelay time.Duration |
| 29 |
// ClientExpiredSubCloseDelay is an extra time given to client to |
| 30 |
// refresh its expiring subscription in the end of subscription TTL. |
| 31 |
// At the moment only used for a client-side subscription refresh workflow. |
| 32 |
ClientExpiredSubCloseDelay time.Duration |
| 33 |
// ClientStaleCloseDelay is a timeout after which connection will be |
| 34 |
// closed if still not authenticated (i.e. no valid connect command |
| 35 |
// received yet). |
| 36 |
ClientStaleCloseDelay time.Duration |
| 37 |
// ClientChannelPositionCheckDelay defines minimal time from previous |
| 38 |
// client position check in channel. If client does not pass check it will |
| 39 |
// be disconnected with DisconnectInsufficientState. |
| 40 |
ClientChannelPositionCheckDelay time.Duration |
| 41 |
// ClientQueueMaxSize is a maximum size of client's message queue in bytes. |
| 42 |
// After this queue size exceeded Centrifuge closes client's connection. |
| 43 |
ClientQueueMaxSize int |
| 44 |
// ClientChannelLimit sets upper limit of channels each client can subscribe to. |
| 45 |
ClientChannelLimit int |
| 46 |
// UserConnectionLimit limits number of client connections to single Node |
| 47 |
// from user with the same ID. Zero value means unlimited. Anonymous users |
| 48 |
// can't be tracked. |
| 49 |
UserConnectionLimit int |
| 50 |
// ChannelMaxLength is the maximum length of a channel name. |
| 51 |
ChannelMaxLength int |
| 52 |
// MetricsNamespace is a Prometheus metrics namespace to use for internal metrics. |
| 53 |
// If not set then the default namespace name `centrifuge` will be used. |
| 54 |
MetricsNamespace string |
| 55 |
// HistoryMaxPublicationLimit allows limiting the maximum number of publications to be |
| 56 |
// asked over client API history call. This is useful when you have large streams and |
| 57 |
// want to prevent a massive number of missed messages to be sent to a client when |
| 58 |
// calling history without any limit explicitly set. By default no limit used. |
| 59 |
// This option does not affect Node.History method. See also RecoveryMaxPublicationLimit. |
| 60 |
HistoryMaxPublicationLimit int |
| 61 |
// RecoveryMaxPublicationLimit allows limiting the number of Publications that could be |
| 62 |
// restored during the automatic recovery process. See also HistoryMaxPublicationLimit. |
| 63 |
RecoveryMaxPublicationLimit int |
| 64 |
} |
| 65 |
|
| 66 |
const ( |
| 67 |
// nodeInfoPublishInterval is an interval how often node must publish |
| 68 |
// node control message. |
| 69 |
nodeInfoPublishInterval = 3 * time.Second |
| 70 |
// nodeInfoCleanInterval is an interval in seconds, how often node must |
| 71 |
// clean information about other running nodes. |
| 72 |
nodeInfoCleanInterval = nodeInfoPublishInterval * 3 |
| 73 |
// nodeInfoMaxDelay is an interval in seconds – how many seconds node |
| 74 |
// info considered actual. |
| 75 |
nodeInfoMaxDelay = nodeInfoPublishInterval*2 + time.Second |
| 76 |
) |
| 77 |
|
| 78 |
// DefaultConfig is Config initialized with default values for all fields. |
| 79 |
var DefaultConfig = Config{ |
| 80 |
NodeInfoMetricsAggregateInterval: 60 * time.Second, |
| 81 |
ClientPresenceUpdateInterval: 25 * time.Second, |
| 82 |
ClientExpiredCloseDelay: 25 * time.Second, |
| 83 |
ClientExpiredSubCloseDelay: 25 * time.Second, |
| 84 |
ClientStaleCloseDelay: 25 * time.Second, |
| 85 |
ClientChannelPositionCheckDelay: 40 * time.Second, |
| 86 |
ClientQueueMaxSize: 10485760, // 10MB by default. |
| 87 |
ClientChannelLimit: 128, |
| 88 |
ChannelMaxLength: 255, |
| 89 |
} |