normalize most times in the app to UTC

Fixes #480
This commit is contained in:
Shivaram Lingamneni 2019-05-12 03:12:50 -04:00
parent 13dda00989
commit 353aeb0389
9 changed files with 17 additions and 18 deletions

View File

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

View File

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

View File

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

View File

@ -34,7 +34,7 @@ type IPBanInfo struct {
} }
func (info IPBanInfo) timeLeft() time.Duration { func (info IPBanInfo) timeLeft() time.Duration {
return info.TimeCreated.Add(info.Duration).Sub(time.Now()) return time.Until(info.TimeCreated.Add(info.Duration))
} }
func (info IPBanInfo) TimeLeft() string { func (info IPBanInfo) TimeLeft() string {
@ -114,7 +114,7 @@ func (dm *DLineManager) AddNetwork(network net.IPNet, duration time.Duration, re
Reason: reason, Reason: reason,
OperReason: operReason, OperReason: operReason,
OperName: operName, OperName: operName,
TimeCreated: time.Now(), TimeCreated: time.Now().UTC(),
Duration: duration, Duration: duration,
} }

View File

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

View File

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

View File

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

View File

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

View File

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