config.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. package server
  2. import (
  3. "io/fs"
  4. "time"
  5. )
  6. // Defines default config settings (excluding limits, see below)
  7. const (
  8. DefaultListenHTTP = ":80"
  9. DefaultCacheDuration = 12 * time.Hour
  10. DefaultKeepaliveInterval = 45 * time.Second // Not too frequently to save battery (Android read timeout used to be 77s!)
  11. DefaultManagerInterval = time.Minute
  12. DefaultDelayedSenderInterval = 10 * time.Second
  13. DefaultMinDelay = 10 * time.Second
  14. DefaultMaxDelay = 3 * 24 * time.Hour
  15. DefaultFirebaseKeepaliveInterval = 3 * time.Hour // ~control topic (Android), not too frequently to save battery
  16. DefaultFirebasePollInterval = 20 * time.Minute // ~poll topic (iOS), max. 2-3 times per hour (see docs)
  17. DefaultFirebaseQuotaExceededPenaltyDuration = 10 * time.Minute // Time that over-users are locked out of Firebase if it returns "quota exceeded"
  18. )
  19. // Defines all global and per-visitor limits
  20. // - message size limit: the max number of bytes for a message
  21. // - total topic limit: max number of topics overall
  22. // - various attachment limits
  23. const (
  24. DefaultMessageLengthLimit = 4096 // Bytes
  25. DefaultTotalTopicLimit = 15000
  26. DefaultAttachmentTotalSizeLimit = int64(5 * 1024 * 1024 * 1024) // 5 GB
  27. DefaultAttachmentFileSizeLimit = int64(15 * 1024 * 1024) // 15 MB
  28. DefaultAttachmentExpiryDuration = 3 * time.Hour
  29. )
  30. // Defines all per-visitor limits
  31. // - per visitor subscription limit: max number of subscriptions (active HTTP connections) per per-visitor/IP
  32. // - per visitor request limit: max number of PUT/GET/.. requests (here: 60 requests bucket, replenished at a rate of one per 5 seconds)
  33. // - per visitor email limit: max number of emails (here: 16 email bucket, replenished at a rate of one per hour)
  34. // - per visitor attachment size limit: total per-visitor attachment size in bytes to be stored on the server
  35. // - per visitor attachment daily bandwidth limit: number of bytes that can be transferred to/from the server
  36. const (
  37. DefaultVisitorSubscriptionLimit = 30
  38. DefaultVisitorRequestLimitBurst = 60
  39. DefaultVisitorRequestLimitReplenish = 5 * time.Second
  40. DefaultVisitorEmailLimitBurst = 16
  41. DefaultVisitorEmailLimitReplenish = time.Hour
  42. DefaultVisitorAttachmentTotalSizeLimit = 100 * 1024 * 1024 // 100 MB
  43. DefaultVisitorAttachmentDailyBandwidthLimit = 500 * 1024 * 1024 // 500 MB
  44. )
  45. // Config is the main config struct for the application. Use New to instantiate a default config struct.
  46. type Config struct {
  47. BaseURL string
  48. ListenHTTP string
  49. ListenHTTPS string
  50. ListenUnix string
  51. ListenUnixMode fs.FileMode
  52. KeyFile string
  53. CertFile string
  54. FirebaseKeyFile string
  55. CacheFile string
  56. CacheDuration time.Duration
  57. CacheStartupQueries string
  58. AuthFile string
  59. AuthDefaultRead bool
  60. AuthDefaultWrite bool
  61. AttachmentCacheDir string
  62. AttachmentTotalSizeLimit int64
  63. AttachmentFileSizeLimit int64
  64. AttachmentExpiryDuration time.Duration
  65. KeepaliveInterval time.Duration
  66. ManagerInterval time.Duration
  67. WebRootIsApp bool
  68. DelayedSenderInterval time.Duration
  69. FirebaseKeepaliveInterval time.Duration
  70. FirebasePollInterval time.Duration
  71. FirebaseQuotaExceededPenaltyDuration time.Duration
  72. UpstreamBaseURL string
  73. SMTPSenderAddr string
  74. SMTPSenderUser string
  75. SMTPSenderPass string
  76. SMTPSenderFrom string
  77. SMTPServerListen string
  78. SMTPServerDomain string
  79. SMTPServerAddrPrefix string
  80. MessageLimit int
  81. MinDelay time.Duration
  82. MaxDelay time.Duration
  83. TotalTopicLimit int
  84. TotalAttachmentSizeLimit int64
  85. VisitorSubscriptionLimit int
  86. VisitorAttachmentTotalSizeLimit int64
  87. VisitorAttachmentDailyBandwidthLimit int
  88. VisitorRequestLimitBurst int
  89. VisitorRequestLimitReplenish time.Duration
  90. VisitorRequestExemptIPAddrs []string
  91. VisitorEmailLimitBurst int
  92. VisitorEmailLimitReplenish time.Duration
  93. BehindProxy bool
  94. EnableWeb bool
  95. Version string // injected by App
  96. }
  97. // NewConfig instantiates a default new server config
  98. func NewConfig() *Config {
  99. return &Config{
  100. BaseURL: "",
  101. ListenHTTP: DefaultListenHTTP,
  102. ListenHTTPS: "",
  103. ListenUnix: "",
  104. ListenUnixMode: 0,
  105. KeyFile: "",
  106. CertFile: "",
  107. FirebaseKeyFile: "",
  108. CacheFile: "",
  109. CacheDuration: DefaultCacheDuration,
  110. AuthFile: "",
  111. AuthDefaultRead: true,
  112. AuthDefaultWrite: true,
  113. AttachmentCacheDir: "",
  114. AttachmentTotalSizeLimit: DefaultAttachmentTotalSizeLimit,
  115. AttachmentFileSizeLimit: DefaultAttachmentFileSizeLimit,
  116. AttachmentExpiryDuration: DefaultAttachmentExpiryDuration,
  117. KeepaliveInterval: DefaultKeepaliveInterval,
  118. ManagerInterval: DefaultManagerInterval,
  119. MessageLimit: DefaultMessageLengthLimit,
  120. MinDelay: DefaultMinDelay,
  121. MaxDelay: DefaultMaxDelay,
  122. DelayedSenderInterval: DefaultDelayedSenderInterval,
  123. FirebaseKeepaliveInterval: DefaultFirebaseKeepaliveInterval,
  124. FirebasePollInterval: DefaultFirebasePollInterval,
  125. FirebaseQuotaExceededPenaltyDuration: DefaultFirebaseQuotaExceededPenaltyDuration,
  126. TotalTopicLimit: DefaultTotalTopicLimit,
  127. VisitorSubscriptionLimit: DefaultVisitorSubscriptionLimit,
  128. VisitorAttachmentTotalSizeLimit: DefaultVisitorAttachmentTotalSizeLimit,
  129. VisitorAttachmentDailyBandwidthLimit: DefaultVisitorAttachmentDailyBandwidthLimit,
  130. VisitorRequestLimitBurst: DefaultVisitorRequestLimitBurst,
  131. VisitorRequestLimitReplenish: DefaultVisitorRequestLimitReplenish,
  132. VisitorRequestExemptIPAddrs: make([]string, 0),
  133. VisitorEmailLimitBurst: DefaultVisitorEmailLimitBurst,
  134. VisitorEmailLimitReplenish: DefaultVisitorEmailLimitReplenish,
  135. BehindProxy: false,
  136. EnableWeb: true,
  137. Version: "",
  138. }
  139. }