3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

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{
createdTime: time.Now(), // may be overwritten by applyRegInfo
createdTime: time.Now().UTC(), // may be overwritten by applyRegInfo
lists: map[modes.Mode]*UserMaskSet{
modes.BanMask: NewUserMaskSet(),
modes.ExceptMask: NewUserMaskSet(),
@ -292,7 +292,7 @@ func (channel *Channel) SetRegistered(founder string) error {
return errChannelAlreadyRegistered
}
channel.registeredFounder = founder
channel.registeredTime = time.Now()
channel.registeredTime = time.Now().UTC()
channel.accountToUMode[founder] = modes.ChannelFounder
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)
// 3. Replay missed message history to the client
func (channel *Channel) Resume(newClient, oldClient *Client, timestamp time.Time) {
now := time.Now()
now := time.Now().UTC()
channel.resumeAndAnnounce(newClient, oldClient)
if !timestamp.IsZero() {
channel.replayHistoryForResume(newClient, timestamp, now)
@ -910,7 +910,7 @@ func (channel *Channel) SetTopic(client *Client, topic string, rb *ResponseBuffe
channel.stateMutex.Lock()
channel.topic = topic
channel.topicSetBy = client.nickMaskString
channel.topicSetTime = time.Now()
channel.topicSetTime = time.Now().UTC()
channel.stateMutex.Unlock()
prefix := client.NickMaskString()

View File

@ -165,7 +165,7 @@ type ClientDetails struct {
// NewClient sets up a new client and runs its goroutine.
func RunNewClient(server *Server, conn clientConn) {
now := time.Now()
now := time.Now().UTC()
config := server.Config()
fullLineLenLimit := ircmsg.MaxlenTagsFromClient + config.Limits.LineLen.Rest
// 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).
func (client *Client) Active(session *Session) {
// TODO normalize all times to utc?
now := time.Now()
now := time.Now().UTC()
client.stateMutex.Lock()
defer client.stateMutex.Unlock()
session.atime = now
@ -472,7 +471,7 @@ func (client *Client) tryResume() (success bool) {
success = true
// this is a bit racey
client.resumeDetails.ResumedAt = time.Now()
client.resumeDetails.ResumedAt = time.Now().UTC()
client.nickTimer.Touch(nil)
@ -496,7 +495,7 @@ func (client *Client) tryResume() (success bool) {
hostname := client.Hostname()
friends := make(ClientSet)
oldestLostMessage := time.Now()
oldestLostMessage := time.Now().UTC()
// work out how much time, if any, is not covered by history buffers
for _, channel := range channels {
@ -569,7 +568,7 @@ func (client *Client) tryResumeChannels() {
// replay direct PRIVSMG history
if !details.Timestamp.IsZero() {
now := time.Now()
now := time.Now().UTC()
items, complete := client.history.Between(details.Timestamp, now, false, 0)
rb := NewResponseBuffer(client.Sessions()[0])
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)
// and records it
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) {

View File

@ -34,7 +34,7 @@ type IPBanInfo struct {
}
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 {
@ -114,7 +114,7 @@ func (dm *DLineManager) AddNetwork(network net.IPNet, duration time.Duration, re
Reason: reason,
OperReason: operReason,
OperName: operName,
TimeCreated: time.Now(),
TimeCreated: time.Now().UTC(),
Duration: duration,
}

View File

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

View File

@ -2377,7 +2377,7 @@ func setnameHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *R
// TIME
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
}

View File

@ -176,7 +176,7 @@ func hsRequestHandler(server *Server, client *Client, command string, params []s
hsNotice(rb, client.t("An error occurred"))
return
}
elapsed := time.Now().Sub(account.VHost.LastRequestTime)
elapsed := time.Since(account.VHost.LastRequestTime)
remainingTime := server.AccountConfig().VHosts.UserRequests.Cooldown - elapsed
// you can update your existing request, but if you were rejected,
// 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,
OperReason: operReason,
OperName: operName,
TimeCreated: time.Now(),
TimeCreated: time.Now().UTC(),
Duration: duration,
}
km.addMaskInternal(mask, info)

View File

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