From b8bbc7eeb59e538d16d2b104e6ef18b67004dc8f Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Thu, 13 Feb 2014 18:59:45 -0800 Subject: [PATCH] add more logging --- irc/client.go | 18 +++++++++++++++--- irc/net.go | 11 ++++++++++- irc/server.go | 4 ++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/irc/client.go b/irc/client.go index 2409d0e1..ffce8323 100644 --- a/irc/client.go +++ b/irc/client.go @@ -15,6 +15,7 @@ type Client struct { awayMessage string channels ChannelSet conn net.Conn + ctime time.Time destroyed bool hostname string idleTimer *time.Timer @@ -32,9 +33,12 @@ type Client struct { } func NewClient(server *Server, conn net.Conn) *Client { + now := time.Now() client := &Client{ + atime: now, channels: make(ChannelSet), conn: conn, + ctime: now, hostname: AddrLookupHostname(conn.RemoteAddr()), replies: make(chan Reply), server: server, @@ -136,7 +140,7 @@ func (client *Client) writeConn() { for reply := range client.replies { if DEBUG_CLIENT { - log.Printf("%s ← %s %s", client, reply.Source(), reply) + log.Printf("%s ← %s", client, reply) } for _, str := range reply.Format(client) { if DEBUG_NET { @@ -161,6 +165,12 @@ func (client *Client) Destroy() { return } + if DEBUG_CLIENT { + log.Printf("%s destroy", client) + } + + client.destroyed = true + client.conn.Close() close(client.replies) @@ -179,11 +189,13 @@ func (client *Client) Destroy() { client.server.clients.Remove(client) - client.destroyed = true } func (client *Client) Reply(replies ...Reply) { - if client.replies == nil { + if client.destroyed { + if DEBUG_CLIENT { + log.Printf("%s.Reply: destroyed", client) + } return } for _, reply := range replies { diff --git a/irc/net.go b/irc/net.go index efadfba3..312cf8fb 100644 --- a/irc/net.go +++ b/irc/net.go @@ -1,6 +1,7 @@ package irc import ( + "log" "net" "strings" ) @@ -19,9 +20,17 @@ func AddrLookupHostname(addr net.Addr) string { } func LookupHostname(addr string) string { + if DEBUG_NET { + log.Printf("LookupHostname(%s)", addr) + } names, err := net.LookupAddr(addr) if err != nil { return addr } - return strings.TrimSuffix(names[0], ".") + + hostname := strings.TrimSuffix(names[0], ".") + if DEBUG_NET { + log.Printf("LookupHostname(%s) → %s", addr, hostname) + } + return hostname } diff --git a/irc/server.go b/irc/server.go index 0a6475b1..94627ca3 100644 --- a/irc/server.go +++ b/irc/server.go @@ -52,7 +52,7 @@ func NewServer(config *Config) *Server { func (server *Server) receiveCommands(commands <-chan Command) { for command := range commands { if DEBUG_SERVER { - log.Printf("%s → %s %s", command.Client(), server, command) + log.Printf("%s → %s %+v", command.Client(), server, command) } client := command.Client() @@ -65,7 +65,7 @@ func (server *Server) receiveCommands(commands <-chan Command) { command.HandleServer(server) if DEBUG_SERVER { - log.Printf("%s → %s %s processed", command.Client(), server, command) + log.Printf("%s → %s %+v processed", command.Client(), server, command) } } }