1package centrifuge 2 3import ( 4 "time" 5) 6 7// Config contains Node configuration options. 8type 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 client-side channels each client 45 // can subscribe to. Client-side subscriptions attempts will get an ErrorLimitExceeded 46 // in subscribe reply. Server-side subscriptions above limit will result into 47 // DisconnectChannelLimit. 48 ClientChannelLimit int 49 // UserConnectionLimit limits number of client connections to single Node 50 // from user with the same ID. Zero value means unlimited. Anonymous users 51 // can't be tracked. 52 UserConnectionLimit int 53 // ChannelMaxLength is the maximum length of a channel name. This is only checked 54 // for client-side subscription requests. 55 ChannelMaxLength int 56 // MetricsNamespace is a Prometheus metrics namespace to use for internal metrics. 57 // If not set then the default namespace name `centrifuge` will be used. 58 MetricsNamespace string 59 // HistoryMaxPublicationLimit allows limiting the maximum number of publications to be 60 // asked over client API history call. This is useful when you have large streams and 61 // want to prevent a massive number of missed messages to be sent to a client when 62 // calling history without any limit explicitly set. By default no limit used. 63 // This option does not affect Node.History method. See also RecoveryMaxPublicationLimit. 64 HistoryMaxPublicationLimit int 65 // RecoveryMaxPublicationLimit allows limiting the number of Publications that could be 66 // restored during the automatic recovery process. See also HistoryMaxPublicationLimit. 67 RecoveryMaxPublicationLimit int 68 // UseSingleFlight allows turning on mode where singleflight will be automatically used for 69 // Node.History (including recovery) and Node.Presence/Node.PresenceStats calls. 70 UseSingleFlight bool 71} 72 73const ( 74 // nodeInfoPublishInterval is an interval how often node must publish 75 // node control message. 76 nodeInfoPublishInterval = 3 * time.Second 77 // nodeInfoCleanInterval is an interval in seconds, how often node must 78 // clean information about other running nodes. 79 nodeInfoCleanInterval = nodeInfoPublishInterval * 3 80 // nodeInfoMaxDelay is an interval in seconds – how many seconds node 81 // info considered actual. 82 nodeInfoMaxDelay = nodeInfoPublishInterval*2 + time.Second 83) 84 85// DefaultConfig is Config initialized with default values for all fields. 86var DefaultConfig = Config{ 87 NodeInfoMetricsAggregateInterval: 60 * time.Second, 88 ClientPresenceUpdateInterval: 25 * time.Second, 89 ClientExpiredCloseDelay: 25 * time.Second, 90 ClientExpiredSubCloseDelay: 25 * time.Second, 91 ClientStaleCloseDelay: 25 * time.Second, 92 ClientChannelPositionCheckDelay: 40 * time.Second, 93 ClientQueueMaxSize: 10485760, // 10MB by default. 94 ClientChannelLimit: 128, 95 ChannelMaxLength: 255, 96} 97