config.go 6.2 KB

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