From 3b12dec207cfac0e8695708a6427fdc504c23b00 Mon Sep 17 00:00:00 2001 From: Jeremy Latt Date: Thu, 27 Mar 2014 18:58:12 -0700 Subject: [PATCH] cleanup --- irc/client.go | 20 +++----------------- irc/socket.go | 8 ++++++++ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/irc/client.go b/irc/client.go index e6f95787..15e1c23a 100644 --- a/irc/client.go +++ b/irc/client.go @@ -60,19 +60,9 @@ func NewClient(server *Server, conn net.Conn) *Client { // command goroutine // -func (client *Client) send(command Command) { - command.SetClient(client) - client.server.commands <- command -} - func (client *Client) run() { - client.send(&ProxyCommand{ - hostname: AddrLookupHostname(client.socket.conn.RemoteAddr()), - }) - for command := range client.commands { - checkPass, ok := command.(checkPasswordCommand) - if ok { + if checkPass, ok := command.(checkPasswordCommand); ok { checkPass.LoadPassword(client.server) // Block the client thread while handling a potentially expensive // password bcrypt operation. Since the server is single-threaded @@ -81,13 +71,9 @@ func (client *Client) run() { // completes. This could be a form of DoS if handled naively. checkPass.CheckPassword() } - - client.send(command) + command.SetClient(client) + client.server.commands <- command } - - client.send(&QuitCommand{ - message: "connection closed", - }) } func (client *Client) connectionTimeout() { diff --git a/irc/socket.go b/irc/socket.go index aa9be493..f3eaa16e 100644 --- a/irc/socket.go +++ b/irc/socket.go @@ -38,6 +38,10 @@ func (socket *Socket) Close() { } func (socket *Socket) readLines(commands chan<- Command) { + commands <- &ProxyCommand{ + hostname: AddrLookupHostname(socket.conn.RemoteAddr()), + } + scanner := bufio.NewScanner(socket.conn) for scanner.Scan() { line := scanner.Text() @@ -58,6 +62,10 @@ func (socket *Socket) readLines(commands chan<- Command) { Log.debug.Printf("%s error: %s", socket, err) } + commands <- &QuitCommand{ + message: "connection closed", + } + close(commands) }