Browse Source

normalize most times in the app to UTC

Fixes #480
tags/v1.1.0-rc1
Shivaram Lingamneni 5 years ago
parent
commit
353aeb0389
9 changed files with 17 additions and 18 deletions
  1. 4
    4
      irc/channel.go
  2. 5
    6
      irc/client.go
  3. 1
    1
      irc/connection_limits/throttler.go
  4. 2
    2
      irc/dline.go
  5. 1
    1
      irc/getters.go
  6. 1
    1
      irc/handlers.go
  7. 1
    1
      irc/hostserv.go
  8. 1
    1
      irc/kline.go
  9. 1
    1
      irc/server.go

+ 4
- 4
irc/channel.go View File

@@ -56,7 +56,7 @@ func NewChannel(s *Server, name string, registered bool) *Channel {
56 56
 	}
57 57
 
58 58
 	channel := &Channel{
59
-		createdTime: time.Now(), // may be overwritten by applyRegInfo
59
+		createdTime: time.Now().UTC(), // may be overwritten by applyRegInfo
60 60
 		lists: map[modes.Mode]*UserMaskSet{
61 61
 			modes.BanMask:    NewUserMaskSet(),
62 62
 			modes.ExceptMask: NewUserMaskSet(),
@@ -292,7 +292,7 @@ func (channel *Channel) SetRegistered(founder string) error {
292 292
 		return errChannelAlreadyRegistered
293 293
 	}
294 294
 	channel.registeredFounder = founder
295
-	channel.registeredTime = time.Now()
295
+	channel.registeredTime = time.Now().UTC()
296 296
 	channel.accountToUMode[founder] = modes.ChannelFounder
297 297
 	return nil
298 298
 }
@@ -686,7 +686,7 @@ func (channel *Channel) Part(client *Client, message string, rb *ResponseBuffer)
686 686
 // 2. Send JOIN and MODE lines to channel participants (including the new client)
687 687
 // 3. Replay missed message history to the client
688 688
 func (channel *Channel) Resume(newClient, oldClient *Client, timestamp time.Time) {
689
-	now := time.Now()
689
+	now := time.Now().UTC()
690 690
 	channel.resumeAndAnnounce(newClient, oldClient)
691 691
 	if !timestamp.IsZero() {
692 692
 		channel.replayHistoryForResume(newClient, timestamp, now)
@@ -910,7 +910,7 @@ func (channel *Channel) SetTopic(client *Client, topic string, rb *ResponseBuffe
910 910
 	channel.stateMutex.Lock()
911 911
 	channel.topic = topic
912 912
 	channel.topicSetBy = client.nickMaskString
913
-	channel.topicSetTime = time.Now()
913
+	channel.topicSetTime = time.Now().UTC()
914 914
 	channel.stateMutex.Unlock()
915 915
 
916 916
 	prefix := client.NickMaskString()

+ 5
- 6
irc/client.go View File

@@ -165,7 +165,7 @@ type ClientDetails struct {
165 165
 
166 166
 // NewClient sets up a new client and runs its goroutine.
167 167
 func RunNewClient(server *Server, conn clientConn) {
168
-	now := time.Now()
168
+	now := time.Now().UTC()
169 169
 	config := server.Config()
170 170
 	fullLineLenLimit := ircmsg.MaxlenTagsFromClient + config.Limits.LineLen.Rest
171 171
 	// give them 1k of grace over the limit:
@@ -409,8 +409,7 @@ func (client *Client) playReattachMessages(session *Session) {
409 409
 
410 410
 // Active updates when the client was last 'active' (i.e. the user should be sitting in front of their client).
411 411
 func (client *Client) Active(session *Session) {
412
-	// TODO normalize all times to utc?
413
-	now := time.Now()
412
+	now := time.Now().UTC()
414 413
 	client.stateMutex.Lock()
415 414
 	defer client.stateMutex.Unlock()
416 415
 	session.atime = now
@@ -472,7 +471,7 @@ func (client *Client) tryResume() (success bool) {
472 471
 	success = true
473 472
 
474 473
 	// this is a bit racey
475
-	client.resumeDetails.ResumedAt = time.Now()
474
+	client.resumeDetails.ResumedAt = time.Now().UTC()
476 475
 
477 476
 	client.nickTimer.Touch(nil)
478 477
 
@@ -496,7 +495,7 @@ func (client *Client) tryResume() (success bool) {
496 495
 	hostname := client.Hostname()
497 496
 
498 497
 	friends := make(ClientSet)
499
-	oldestLostMessage := time.Now()
498
+	oldestLostMessage := time.Now().UTC()
500 499
 
501 500
 	// work out how much time, if any, is not covered by history buffers
502 501
 	for _, channel := range channels {
@@ -569,7 +568,7 @@ func (client *Client) tryResumeChannels() {
569 568
 
570 569
 	// replay direct PRIVSMG history
571 570
 	if !details.Timestamp.IsZero() {
572
-		now := time.Now()
571
+		now := time.Now().UTC()
573 572
 		items, complete := client.history.Between(details.Timestamp, now, false, 0)
574 573
 		rb := NewResponseBuffer(client.Sessions()[0])
575 574
 		client.replayPrivmsgHistory(rb, items, complete)

+ 1
- 1
irc/connection_limits/throttler.go View File

@@ -45,7 +45,7 @@ type GenericThrottle struct {
45 45
 // it either denies it (by returning false) or allows it (by returning true)
46 46
 // and records it
47 47
 func (g *GenericThrottle) Touch() (throttled bool, remainingTime time.Duration) {
48
-	return g.touch(time.Now())
48
+	return g.touch(time.Now().UTC())
49 49
 }
50 50
 
51 51
 func (g *GenericThrottle) touch(now time.Time) (throttled bool, remainingTime time.Duration) {

+ 2
- 2
irc/dline.go View File

@@ -34,7 +34,7 @@ type IPBanInfo struct {
34 34
 }
35 35
 
36 36
 func (info IPBanInfo) timeLeft() time.Duration {
37
-	return info.TimeCreated.Add(info.Duration).Sub(time.Now())
37
+	return time.Until(info.TimeCreated.Add(info.Duration))
38 38
 }
39 39
 
40 40
 func (info IPBanInfo) TimeLeft() string {
@@ -114,7 +114,7 @@ func (dm *DLineManager) AddNetwork(network net.IPNet, duration time.Duration, re
114 114
 		Reason:      reason,
115 115
 		OperReason:  operReason,
116 116
 		OperName:    operName,
117
-		TimeCreated: time.Now(),
117
+		TimeCreated: time.Now().UTC(),
118 118
 		Duration:    duration,
119 119
 	}
120 120
 

+ 1
- 1
irc/getters.go View File

@@ -356,7 +356,7 @@ func (channel *Channel) Rename(name, nameCasefolded string) {
356 356
 	channel.name = name
357 357
 	channel.nameCasefolded = nameCasefolded
358 358
 	if channel.registeredFounder != "" {
359
-		channel.registeredTime = time.Now()
359
+		channel.registeredTime = time.Now().UTC()
360 360
 	}
361 361
 	channel.stateMutex.Unlock()
362 362
 }

+ 1
- 1
irc/handlers.go View File

@@ -2377,7 +2377,7 @@ func setnameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R
2377 2377
 
2378 2378
 // TIME
2379 2379
 func timeHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *ResponseBuffer) bool {
2380
-	rb.Add(nil, server.name, RPL_TIME, client.nick, server.name, time.Now().Format(time.RFC1123))
2380
+	rb.Add(nil, server.name, RPL_TIME, client.nick, server.name, time.Now().UTC().Format(time.RFC1123))
2381 2381
 	return false
2382 2382
 }
2383 2383
 

+ 1
- 1
irc/hostserv.go View File

@@ -176,7 +176,7 @@ func hsRequestHandler(server *Server, client *Client, command string, params []s
176 176
 		hsNotice(rb, client.t("An error occurred"))
177 177
 		return
178 178
 	}
179
-	elapsed := time.Now().Sub(account.VHost.LastRequestTime)
179
+	elapsed := time.Since(account.VHost.LastRequestTime)
180 180
 	remainingTime := server.AccountConfig().VHosts.UserRequests.Cooldown - elapsed
181 181
 	// you can update your existing request, but if you were rejected,
182 182
 	// you can't spam a replacement request

+ 1
- 1
irc/kline.go View File

@@ -72,7 +72,7 @@ func (km *KLineManager) AddMask(mask string, duration time.Duration, reason, ope
72 72
 		Reason:      reason,
73 73
 		OperReason:  operReason,
74 74
 		OperName:    operName,
75
-		TimeCreated: time.Now(),
75
+		TimeCreated: time.Now().UTC(),
76 76
 		Duration:    duration,
77 77
 	}
78 78
 	km.addMaskInternal(mask, info)

+ 1
- 1
irc/server.go View File

@@ -110,6 +110,7 @@ type clientConn struct {
110 110
 func NewServer(config *Config, logger *logger.Manager) (*Server, error) {
111 111
 	// initialize data structures
112 112
 	server := &Server{
113
+		ctime:               time.Now().UTC(),
113 114
 		connectionLimiter:   connection_limits.NewLimiter(),
114 115
 		connectionThrottler: connection_limits.NewThrottler(),
115 116
 		listeners:           make(map[string]*ListenerWrapper),
@@ -576,7 +577,6 @@ func (server *Server) rehash() error {
576 577
 
577 578
 func (server *Server) applyConfig(config *Config, initial bool) (err error) {
578 579
 	if initial {
579
-		server.ctime = time.Now()
580 580
 		server.configFilename = config.Filename
581 581
 		server.name = config.Server.Name
582 582
 		server.nameCasefolded = config.Server.nameCasefolded

Loading…
Cancel
Save