config.go 6.2 KB

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