瀏覽代碼

use custime.Duration for more config fields

tags/v2.0.0-rc1
Shivaram Lingamneni 4 年之前
父節點
當前提交
ef161c47ed
共有 6 個檔案被更改,包括 38 行新增27 行删除
  1. 1
    1
      irc/accounts.go
  2. 14
    19
      irc/config.go
  3. 15
    0
      irc/custime/parseduration.go
  4. 3
    2
      irc/hostserv.go
  5. 4
    4
      irc/server.go
  6. 1
    1
      oragono.yaml

+ 1
- 1
irc/accounts.go 查看文件

381
 	callbackSpec := fmt.Sprintf("%s:%s", callbackNamespace, callbackValue)
381
 	callbackSpec := fmt.Sprintf("%s:%s", callbackNamespace, callbackValue)
382
 
382
 
383
 	var setOptions *buntdb.SetOptions
383
 	var setOptions *buntdb.SetOptions
384
-	ttl := config.Registration.VerifyTimeout
384
+	ttl := time.Duration(config.Registration.VerifyTimeout)
385
 	if ttl != 0 {
385
 	if ttl != 0 {
386
 		setOptions = &buntdb.SetOptions{Expires: true, TTL: ttl}
386
 		setOptions = &buntdb.SetOptions{Expires: true, TTL: ttl}
387
 	}
387
 	}

+ 14
- 19
irc/config.go 查看文件

233
 // AccountRegistrationConfig controls account registration.
233
 // AccountRegistrationConfig controls account registration.
234
 type AccountRegistrationConfig struct {
234
 type AccountRegistrationConfig struct {
235
 	Enabled                bool
235
 	Enabled                bool
236
-	EnabledCallbacks       []string      `yaml:"enabled-callbacks"`
237
-	EnabledCredentialTypes []string      `yaml:"-"`
238
-	VerifyTimeout          time.Duration `yaml:"verify-timeout"`
236
+	EnabledCallbacks       []string         `yaml:"enabled-callbacks"`
237
+	EnabledCredentialTypes []string         `yaml:"-"`
238
+	VerifyTimeout          custime.Duration `yaml:"verify-timeout"`
239
 	Callbacks              struct {
239
 	Callbacks              struct {
240
 		Mailto struct {
240
 		Mailto struct {
241
 			Server string
241
 			Server string
263
 	UserRequests   struct {
263
 	UserRequests   struct {
264
 		Enabled  bool
264
 		Enabled  bool
265
 		Channel  string
265
 		Channel  string
266
-		Cooldown time.Duration
266
+		Cooldown custime.Duration
267
 	} `yaml:"user-requests"`
267
 	} `yaml:"user-requests"`
268
 	OfferList []string `yaml:"offer-list"`
268
 	OfferList []string `yaml:"offer-list"`
269
 }
269
 }
406
 
406
 
407
 // STSConfig controls the STS configuration/
407
 // STSConfig controls the STS configuration/
408
 type STSConfig struct {
408
 type STSConfig struct {
409
-	Enabled        bool
410
-	Duration       time.Duration `yaml:"duration-real"`
411
-	DurationString string        `yaml:"duration"`
412
-	Port           int
413
-	Preload        bool
414
-	STSOnlyBanner  string `yaml:"sts-only-banner"`
415
-	bannerLines    []string
409
+	Enabled       bool
410
+	Duration      custime.Duration
411
+	Port          int
412
+	Preload       bool
413
+	STSOnlyBanner string `yaml:"sts-only-banner"`
414
+	bannerLines   []string
416
 }
415
 }
417
 
416
 
418
 // Value returns the STS value to advertise in CAP
417
 // Value returns the STS value to advertise in CAP
419
 func (sts *STSConfig) Value() string {
418
 func (sts *STSConfig) Value() string {
420
-	val := fmt.Sprintf("duration=%d", int(sts.Duration.Seconds()))
419
+	val := fmt.Sprintf("duration=%d", int(time.Duration(sts.Duration).Seconds()))
421
 	if sts.Enabled && sts.Port > 0 {
420
 	if sts.Enabled && sts.Port > 0 {
422
 		val += fmt.Sprintf(",port=%d", sts.Port)
421
 		val += fmt.Sprintf(",port=%d", sts.Port)
423
 	}
422
 	}
553
 		ChathistoryMax   int           `yaml:"chathistory-maxmessages"`
552
 		ChathistoryMax   int           `yaml:"chathistory-maxmessages"`
554
 		ZNCMax           int           `yaml:"znc-maxmessages"`
553
 		ZNCMax           int           `yaml:"znc-maxmessages"`
555
 		Restrictions     struct {
554
 		Restrictions     struct {
556
-			ExpireTime              time.Duration `yaml:"expire-time"`
557
-			EnforceRegistrationDate bool          `yaml:"enforce-registration-date"`
558
-			GracePeriod             time.Duration `yaml:"grace-period"`
555
+			ExpireTime              custime.Duration `yaml:"expire-time"`
556
+			EnforceRegistrationDate bool             `yaml:"enforce-registration-date"`
557
+			GracePeriod             custime.Duration `yaml:"grace-period"`
559
 		}
558
 		}
560
 		Persistent struct {
559
 		Persistent struct {
561
 			Enabled              bool
560
 			Enabled              bool
828
 	}
827
 	}
829
 
828
 
830
 	if config.Server.STS.Enabled {
829
 	if config.Server.STS.Enabled {
831
-		config.Server.STS.Duration, err = custime.ParseDuration(config.Server.STS.DurationString)
832
-		if err != nil {
833
-			return nil, fmt.Errorf("Could not parse STS duration: %s", err.Error())
834
-		}
835
 		if config.Server.STS.Port < 0 || config.Server.STS.Port > 65535 {
830
 		if config.Server.STS.Port < 0 || config.Server.STS.Port > 65535 {
836
 			return nil, fmt.Errorf("STS port is incorrect, should be 0 if disabled: %d", config.Server.STS.Port)
831
 			return nil, fmt.Errorf("STS port is incorrect, should be 0 if disabled: %d", config.Server.STS.Port)
837
 		}
832
 		}

+ 15
- 0
irc/custime/parseduration.go 查看文件

182
 	}
182
 	}
183
 	return time.Duration(d), nil
183
 	return time.Duration(d), nil
184
 }
184
 }
185
+
186
+type Duration time.Duration
187
+
188
+func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
189
+	var orig string
190
+	var err error
191
+	if err = unmarshal(&orig); err != nil {
192
+		return err
193
+	}
194
+	result, err := ParseDuration(orig)
195
+	if err == nil {
196
+		*d = Duration(result)
197
+	}
198
+	return err
199
+}

+ 3
- 2
irc/hostserv.go 查看文件

7
 	"errors"
7
 	"errors"
8
 	"fmt"
8
 	"fmt"
9
 	"regexp"
9
 	"regexp"
10
+	"time"
10
 
11
 
11
 	"github.com/oragono/oragono/irc/sno"
12
 	"github.com/oragono/oragono/irc/sno"
12
 )
13
 )
214
 	}
215
 	}
215
 
216
 
216
 	accountName := client.Account()
217
 	accountName := client.Account()
217
-	_, err := server.accounts.VHostRequest(accountName, vhost, server.Config().Accounts.VHosts.UserRequests.Cooldown)
218
+	_, err := server.accounts.VHostRequest(accountName, vhost, time.Duration(server.Config().Accounts.VHosts.UserRequests.Cooldown))
218
 	if err != nil {
219
 	if err != nil {
219
 		if throttled, ok := err.(*vhostThrottleExceeded); ok {
220
 		if throttled, ok := err.(*vhostThrottleExceeded); ok {
220
 			hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before making another request"), throttled.timeRemaining))
221
 			hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before making another request"), throttled.timeRemaining))
411
 	}
412
 	}
412
 
413
 
413
 	account := client.Account()
414
 	account := client.Account()
414
-	_, err := server.accounts.VHostTake(account, vhost, config.Accounts.VHosts.UserRequests.Cooldown)
415
+	_, err := server.accounts.VHostTake(account, vhost, time.Duration(config.Accounts.VHosts.UserRequests.Cooldown))
415
 	if err != nil {
416
 	if err != nil {
416
 		if throttled, ok := err.(*vhostThrottleExceeded); ok {
417
 		if throttled, ok := err.(*vhostThrottleExceeded); ok {
417
 			hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before taking a vhost"), throttled.timeRemaining))
418
 			hsNotice(rb, fmt.Sprintf(client.t("You must wait an additional %v before taking a vhost"), throttled.timeRemaining))

+ 4
- 4
irc/server.go 查看文件

670
 		}
670
 		}
671
 	} else {
671
 	} else {
672
 		if config.Datastore.MySQL.Enabled {
672
 		if config.Datastore.MySQL.Enabled {
673
-			server.historyDB.SetExpireTime(config.History.Restrictions.ExpireTime)
673
+			server.historyDB.SetExpireTime(time.Duration(config.History.Restrictions.ExpireTime))
674
 		}
674
 		}
675
 	}
675
 	}
676
 
676
 
793
 	server.accounts.Initialize(server)
793
 	server.accounts.Initialize(server)
794
 
794
 
795
 	if config.Datastore.MySQL.Enabled {
795
 	if config.Datastore.MySQL.Enabled {
796
-		server.historyDB.Initialize(server.logger, config.History.Restrictions.ExpireTime)
796
+		server.historyDB.Initialize(server.logger, time.Duration(config.History.Restrictions.ExpireTime))
797
 		err = server.historyDB.Open(config.Datastore.MySQL.User, config.Datastore.MySQL.Password, config.Datastore.MySQL.Host, config.Datastore.MySQL.Port, config.Datastore.MySQL.HistoryDatabase)
797
 		err = server.historyDB.Open(config.Datastore.MySQL.User, config.Datastore.MySQL.Password, config.Datastore.MySQL.Host, config.Datastore.MySQL.Port, config.Datastore.MySQL.HistoryDatabase)
798
 		if err != nil {
798
 		if err != nil {
799
 			server.logger.Error("internal", "could not connect to mysql", err.Error())
799
 			server.logger.Error("internal", "could not connect to mysql", err.Error())
906
 
906
 
907
 	var cutoff time.Time
907
 	var cutoff time.Time
908
 	if config.History.Restrictions.ExpireTime != 0 {
908
 	if config.History.Restrictions.ExpireTime != 0 {
909
-		cutoff = time.Now().UTC().Add(-config.History.Restrictions.ExpireTime)
909
+		cutoff = time.Now().UTC().Add(-time.Duration(config.History.Restrictions.ExpireTime))
910
 	}
910
 	}
911
 	if config.History.Restrictions.EnforceRegistrationDate {
911
 	if config.History.Restrictions.EnforceRegistrationDate {
912
 		regCutoff := client.historyCutoff()
912
 		regCutoff := client.historyCutoff()
913
-		regCutoff.Add(-config.History.Restrictions.GracePeriod)
913
+		regCutoff.Add(-time.Duration(config.History.Restrictions.GracePeriod))
914
 		// take the earlier of the two cutoffs
914
 		// take the earlier of the two cutoffs
915
 		if regCutoff.After(cutoff) {
915
 		if regCutoff.After(cutoff) {
916
 			cutoff = regCutoff
916
 			cutoff = regCutoff

+ 1
- 1
oragono.yaml 查看文件

716
     restrictions:
716
     restrictions:
717
         # if this is set, messages older than this cannot be retrieved by anyone
717
         # if this is set, messages older than this cannot be retrieved by anyone
718
         # (and will eventually be deleted from persistent storage, if that's enabled)
718
         # (and will eventually be deleted from persistent storage, if that's enabled)
719
-        #expire-time: 168h # 7 days
719
+        #expire-time: 1w
720
 
720
 
721
         # if this is set, logged-in users cannot retrieve messages older than their
721
         # if this is set, logged-in users cannot retrieve messages older than their
722
         # account registration date, and logged-out users cannot retrieve messages
722
         # account registration date, and logged-out users cannot retrieve messages

Loading…
取消
儲存