Index: trunk/downstream.go
===================================================================
--- trunk/downstream.go	(revision 54)
+++ trunk/downstream.go	(revision 55)
@@ -57,5 +57,5 @@
 func newDownstreamConn(srv *Server, netConn net.Conn) *downstreamConn {
 	msgs := make(chan *irc.Message, 64)
-	conn := &downstreamConn{
+	dc := &downstreamConn{
 		net:      netConn,
 		irc:      irc.NewConn(netConn),
@@ -67,31 +67,31 @@
 	go func() {
 		for msg := range msgs {
-			if err := conn.irc.WriteMessage(msg); err != nil {
-				conn.logger.Printf("failed to write message: %v", err)
-			}
-		}
-		if err := conn.net.Close(); err != nil {
-			conn.logger.Printf("failed to close connection: %v", err)
+			if err := dc.irc.WriteMessage(msg); err != nil {
+				dc.logger.Printf("failed to write message: %v", err)
+			}
+		}
+		if err := dc.net.Close(); err != nil {
+			dc.logger.Printf("failed to close connection: %v", err)
 		} else {
-			conn.logger.Printf("connection closed")
+			dc.logger.Printf("connection closed")
 		}
 	}()
 
-	return conn
-}
-
-func (c *downstreamConn) prefix() *irc.Prefix {
+	return dc
+}
+
+func (dc *downstreamConn) prefix() *irc.Prefix {
 	return &irc.Prefix{
-		Name: c.nick,
-		User: c.username,
+		Name: dc.nick,
+		User: dc.username,
 		// TODO: fill the host?
 	}
 }
 
-func (c *downstreamConn) readMessages() error {
-	c.logger.Printf("new connection")
+func (dc *downstreamConn) readMessages() error {
+	dc.logger.Printf("new connection")
 
 	for {
-		msg, err := c.irc.ReadMessage()
+		msg, err := dc.irc.ReadMessage()
 		if err == io.EOF {
 			break
@@ -100,13 +100,13 @@
 		}
 
-		err = c.handleMessage(msg)
+		err = dc.handleMessage(msg)
 		if ircErr, ok := err.(ircError); ok {
-			ircErr.Message.Prefix = c.srv.prefix()
-			c.SendMessage(ircErr.Message)
+			ircErr.Message.Prefix = dc.srv.prefix()
+			dc.SendMessage(ircErr.Message)
 		} else if err != nil {
 			return fmt.Errorf("failed to handle IRC command %q: %v", msg.Command, err)
 		}
 
-		if c.closed {
+		if dc.closed {
 			return nil
 		}
@@ -116,13 +116,13 @@
 }
 
-func (c *downstreamConn) Close() error {
-	if c.closed {
+func (dc *downstreamConn) Close() error {
+	if dc.closed {
 		return fmt.Errorf("downstream connection already closed")
 	}
 
-	if u := c.user; u != nil {
+	if u := dc.user; u != nil {
 		u.lock.Lock()
 		for i := range u.downstreamConns {
-			if u.downstreamConns[i] == c {
+			if u.downstreamConns[i] == dc {
 				u.downstreamConns = append(u.downstreamConns[:i], u.downstreamConns[i+1:]...)
 			}
@@ -137,63 +137,63 @@
 	}
 
-	close(c.messages)
-	c.closed = true
-
-	return nil
-}
-
-func (c *downstreamConn) SendMessage(msg *irc.Message) {
-	c.messages <- msg
-}
-
-func (c *downstreamConn) handleMessage(msg *irc.Message) error {
+	close(dc.messages)
+	dc.closed = true
+
+	return nil
+}
+
+func (dc *downstreamConn) SendMessage(msg *irc.Message) {
+	dc.messages <- msg
+}
+
+func (dc *downstreamConn) handleMessage(msg *irc.Message) error {
 	switch msg.Command {
 	case "QUIT":
-		return c.Close()
+		return dc.Close()
 	case "PING":
 		// TODO: handle params
-		c.SendMessage(&irc.Message{
-			Prefix:  c.srv.prefix(),
+		dc.SendMessage(&irc.Message{
+			Prefix:  dc.srv.prefix(),
 			Command: "PONG",
-			Params:  []string{c.srv.Hostname},
+			Params:  []string{dc.srv.Hostname},
 		})
 		return nil
 	default:
-		if c.registered {
-			return c.handleMessageRegistered(msg)
+		if dc.registered {
+			return dc.handleMessageRegistered(msg)
 		} else {
-			return c.handleMessageUnregistered(msg)
-		}
-	}
-}
-
-func (c *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
+			return dc.handleMessageUnregistered(msg)
+		}
+	}
+}
+
+func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
 	switch msg.Command {
 	case "NICK":
-		if err := parseMessageParams(msg, &c.nick); err != nil {
+		if err := parseMessageParams(msg, &dc.nick); err != nil {
 			return err
 		}
 	case "USER":
 		var username string
-		if err := parseMessageParams(msg, &username, nil, nil, &c.realname); err != nil {
-			return err
-		}
-		c.username = "~" + username
+		if err := parseMessageParams(msg, &username, nil, nil, &dc.realname); err != nil {
+			return err
+		}
+		dc.username = "~" + username
 	default:
-		c.logger.Printf("unhandled message: %v", msg)
+		dc.logger.Printf("unhandled message: %v", msg)
 		return newUnknownCommandError(msg.Command)
 	}
-	if c.username != "" && c.nick != "" {
-		return c.register()
-	}
-	return nil
-}
-
-func (c *downstreamConn) register() error {
-	u := c.srv.getUser(strings.TrimPrefix(c.username, "~"))
+	if dc.username != "" && dc.nick != "" {
+		return dc.register()
+	}
+	return nil
+}
+
+func (dc *downstreamConn) register() error {
+	u := dc.srv.getUser(strings.TrimPrefix(dc.username, "~"))
 	if u == nil {
-		c.logger.Printf("failed authentication: unknown username %q", c.username)
-		c.SendMessage(&irc.Message{
-			Prefix:  c.srv.prefix(),
+		dc.logger.Printf("failed authentication: unknown username %q", dc.username)
+		dc.SendMessage(&irc.Message{
+			Prefix:  dc.srv.prefix(),
 			Command: irc.ERR_PASSWDMISMATCH,
 			Params:  []string{"*", "Invalid username or password"},
@@ -202,35 +202,35 @@
 	}
 
-	c.registered = true
-	c.user = u
+	dc.registered = true
+	dc.user = u
 
 	u.lock.Lock()
-	u.downstreamConns = append(u.downstreamConns, c)
+	u.downstreamConns = append(u.downstreamConns, dc)
 	u.lock.Unlock()
 
-	c.SendMessage(&irc.Message{
-		Prefix:  c.srv.prefix(),
+	dc.SendMessage(&irc.Message{
+		Prefix:  dc.srv.prefix(),
 		Command: irc.RPL_WELCOME,
-		Params:  []string{c.nick, "Welcome to jounce, " + c.nick},
-	})
-	c.SendMessage(&irc.Message{
-		Prefix:  c.srv.prefix(),
+		Params:  []string{dc.nick, "Welcome to jounce, " + dc.nick},
+	})
+	dc.SendMessage(&irc.Message{
+		Prefix:  dc.srv.prefix(),
 		Command: irc.RPL_YOURHOST,
-		Params:  []string{c.nick, "Your host is " + c.srv.Hostname},
-	})
-	c.SendMessage(&irc.Message{
-		Prefix:  c.srv.prefix(),
+		Params:  []string{dc.nick, "Your host is " + dc.srv.Hostname},
+	})
+	dc.SendMessage(&irc.Message{
+		Prefix:  dc.srv.prefix(),
 		Command: irc.RPL_CREATED,
-		Params:  []string{c.nick, "Who cares when the server was created?"},
-	})
-	c.SendMessage(&irc.Message{
-		Prefix:  c.srv.prefix(),
+		Params:  []string{dc.nick, "Who cares when the server was created?"},
+	})
+	dc.SendMessage(&irc.Message{
+		Prefix:  dc.srv.prefix(),
 		Command: irc.RPL_MYINFO,
-		Params:  []string{c.nick, c.srv.Hostname, "jounce", "aiwroO", "OovaimnqpsrtklbeI"},
-	})
-	c.SendMessage(&irc.Message{
-		Prefix:  c.srv.prefix(),
+		Params:  []string{dc.nick, dc.srv.Hostname, "jounce", "aiwroO", "OovaimnqpsrtklbeI"},
+	})
+	dc.SendMessage(&irc.Message{
+		Prefix:  dc.srv.prefix(),
 		Command: irc.ERR_NOMOTD,
-		Params:  []string{c.nick, "No MOTD"},
+		Params:  []string{dc.nick, "No MOTD"},
 	})
 
@@ -239,5 +239,5 @@
 		for _, ch := range uc.channels {
 			if ch.complete {
-				forwardChannel(c, ch)
+				forwardChannel(dc, ch)
 			}
 		}
@@ -251,20 +251,20 @@
 				break
 			}
-			c.SendMessage(msg)
-		}
-	})
-
-	return nil
-}
-
-func (c *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
+			dc.SendMessage(msg)
+		}
+	})
+
+	return nil
+}
+
+func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
 	switch msg.Command {
 	case "USER":
 		return ircError{&irc.Message{
 			Command: irc.ERR_ALREADYREGISTERED,
-			Params:  []string{c.nick, "You may not reregister"},
+			Params:  []string{dc.nick, "You may not reregister"},
 		}}
 	case "NICK":
-		c.user.forEachUpstream(func(uc *upstreamConn) {
+		dc.user.forEachUpstream(func(uc *upstreamConn) {
 			uc.messages <- msg
 		})
@@ -275,5 +275,5 @@
 		}
 
-		if ch, _ := c.user.getChannel(name); ch != nil {
+		if ch, _ := dc.user.getChannel(name); ch != nil {
 			break // already joined
 		}
@@ -290,5 +290,5 @@
 		}
 
-		ch, err := c.user.getChannel(name)
+		ch, err := dc.user.getChannel(name)
 		if err != nil {
 			return err
@@ -309,5 +309,5 @@
 
 		if msg.Prefix.Name != name {
-			ch, err := c.user.getChannel(name)
+			ch, err := dc.user.getChannel(name)
 			if err != nil {
 				return err
@@ -317,6 +317,6 @@
 				ch.conn.messages <- msg
 			} else {
-				c.SendMessage(&irc.Message{
-					Prefix:  c.srv.prefix(),
+				dc.SendMessage(&irc.Message{
+					Prefix:  dc.srv.prefix(),
 					Command: irc.RPL_CHANNELMODEIS,
 					Params:  []string{ch.Name, string(ch.modes)},
@@ -324,18 +324,18 @@
 			}
 		} else {
-			if name != c.nick {
+			if name != dc.nick {
 				return ircError{&irc.Message{
 					Command: irc.ERR_USERSDONTMATCH,
-					Params:  []string{c.nick, "Cannot change mode for other users"},
+					Params:  []string{dc.nick, "Cannot change mode for other users"},
 				}}
 			}
 
 			if modeStr != "" {
-				c.user.forEachUpstream(func(uc *upstreamConn) {
+				dc.user.forEachUpstream(func(uc *upstreamConn) {
 					uc.messages <- msg
 				})
 			} else {
-				c.SendMessage(&irc.Message{
-					Prefix:  c.srv.prefix(),
+				dc.SendMessage(&irc.Message{
+					Prefix:  dc.srv.prefix(),
 					Command: irc.RPL_UMODEIS,
 					Params:  []string{""}, // TODO
@@ -344,5 +344,5 @@
 		}
 	default:
-		c.logger.Printf("unhandled message: %v", msg)
+		dc.logger.Printf("unhandled message: %v", msg)
 		return newUnknownCommandError(msg.Command)
 	}
Index: trunk/upstream.go
===================================================================
--- trunk/upstream.go	(revision 54)
+++ trunk/upstream.go	(revision 55)
@@ -57,5 +57,5 @@
 
 	msgs := make(chan *irc.Message, 64)
-	conn := &upstreamConn{
+	uc := &upstreamConn{
 		upstream: upstream,
 		logger:   logger,
@@ -71,29 +71,29 @@
 	go func() {
 		for msg := range msgs {
-			if err := conn.irc.WriteMessage(msg); err != nil {
-				conn.logger.Printf("failed to write message: %v", err)
-			}
-		}
-		if err := conn.net.Close(); err != nil {
-			conn.logger.Printf("failed to close connection: %v", err)
+			if err := uc.irc.WriteMessage(msg); err != nil {
+				uc.logger.Printf("failed to write message: %v", err)
+			}
+		}
+		if err := uc.net.Close(); err != nil {
+			uc.logger.Printf("failed to close connection: %v", err)
 		} else {
-			conn.logger.Printf("connection closed")
+			uc.logger.Printf("connection closed")
 		}
 	}()
 
-	return conn, nil
-}
-
-func (c *upstreamConn) Close() error {
-	if c.closed {
+	return uc, nil
+}
+
+func (uc *upstreamConn) Close() error {
+	if uc.closed {
 		return fmt.Errorf("upstream connection already closed")
 	}
-	close(c.messages)
-	c.closed = true
+	close(uc.messages)
+	uc.closed = true
 	return nil
 }
 
-func (c *upstreamConn) getChannel(name string) (*upstreamChannel, error) {
-	ch, ok := c.channels[name]
+func (uc *upstreamConn) getChannel(name string) (*upstreamChannel, error) {
+	ch, ok := uc.channels[name]
 	if !ok {
 		return nil, fmt.Errorf("unknown channel %q", name)
@@ -102,11 +102,11 @@
 }
 
-func (c *upstreamConn) handleMessage(msg *irc.Message) error {
+func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
 	switch msg.Command {
 	case "PING":
 		// TODO: handle params
-		c.messages <- &irc.Message{
+		uc.messages <- &irc.Message{
 			Command: "PONG",
-			Params:  []string{c.srv.Hostname},
+			Params:  []string{uc.srv.Hostname},
 		}
 		return nil
@@ -118,10 +118,10 @@
 
 		if name == msg.Prefix.Name { // user mode change
-			if name != c.nick {
+			if name != uc.nick {
 				return fmt.Errorf("received MODE message for unknow nick %q", name)
 			}
-			return c.modes.Apply(modeStr)
+			return uc.modes.Apply(modeStr)
 		} else { // channel mode change
-			ch, err := c.getChannel(name)
+			ch, err := uc.getChannel(name)
 			if err != nil {
 				return err
@@ -132,15 +132,15 @@
 		}
 
-		c.user.forEachDownstream(func(dc *downstreamConn) {
+		uc.user.forEachDownstream(func(dc *downstreamConn) {
 			dc.SendMessage(msg)
 		})
 	case "NOTICE":
-		c.logger.Print(msg)
+		uc.logger.Print(msg)
 	case irc.RPL_WELCOME:
-		c.registered = true
-		c.logger.Printf("connection registered")
-
-		for _, ch := range c.upstream.Channels {
-			c.messages <- &irc.Message{
+		uc.registered = true
+		uc.logger.Printf("connection registered")
+
+		for _, ch := range uc.upstream.Channels {
+			uc.messages <- &irc.Message{
 				Command: "JOIN",
 				Params:  []string{ch},
@@ -148,9 +148,9 @@
 		}
 	case irc.RPL_MYINFO:
-		if err := parseMessageParams(msg, nil, &c.serverName, nil, &c.availableUserModes, &c.availableChannelModes); err != nil {
+		if err := parseMessageParams(msg, nil, &uc.serverName, nil, &uc.availableUserModes, &uc.availableChannelModes); err != nil {
 			return err
 		}
 		if len(msg.Params) > 5 {
-			c.channelModesWithParam = msg.Params[5]
+			uc.channelModesWithParam = msg.Params[5]
 		}
 	case "NICK":
@@ -160,10 +160,10 @@
 		}
 
-		if msg.Prefix.Name == c.nick {
-			c.logger.Printf("changed nick from %q to %q", c.nick, newNick)
-			c.nick = newNick
-		}
-
-		for _, ch := range c.channels {
+		if msg.Prefix.Name == uc.nick {
+			uc.logger.Printf("changed nick from %q to %q", uc.nick, newNick)
+			uc.nick = newNick
+		}
+
+		for _, ch := range uc.channels {
 			if membership, ok := ch.Members[msg.Prefix.Name]; ok {
 				delete(ch.Members, msg.Prefix.Name)
@@ -172,5 +172,5 @@
 		}
 
-		c.user.forEachDownstream(func(dc *downstreamConn) {
+		uc.user.forEachDownstream(func(dc *downstreamConn) {
 			dc.SendMessage(msg)
 		})
@@ -182,13 +182,13 @@
 
 		for _, ch := range strings.Split(channels, ",") {
-			if msg.Prefix.Name == c.nick {
-				c.logger.Printf("joined channel %q", ch)
-				c.channels[ch] = &upstreamChannel{
+			if msg.Prefix.Name == uc.nick {
+				uc.logger.Printf("joined channel %q", ch)
+				uc.channels[ch] = &upstreamChannel{
 					Name:    ch,
-					conn:    c,
+					conn:    uc,
 					Members: make(map[string]membership),
 				}
 			} else {
-				ch, err := c.getChannel(ch)
+				ch, err := uc.getChannel(ch)
 				if err != nil {
 					return err
@@ -198,5 +198,5 @@
 		}
 
-		c.user.forEachDownstream(func(dc *downstreamConn) {
+		uc.user.forEachDownstream(func(dc *downstreamConn) {
 			dc.SendMessage(msg)
 		})
@@ -208,9 +208,9 @@
 
 		for _, ch := range strings.Split(channels, ",") {
-			if msg.Prefix.Name == c.nick {
-				c.logger.Printf("parted channel %q", ch)
-				delete(c.channels, ch)
+			if msg.Prefix.Name == uc.nick {
+				uc.logger.Printf("parted channel %q", ch)
+				delete(uc.channels, ch)
 			} else {
-				ch, err := c.getChannel(ch)
+				ch, err := uc.getChannel(ch)
 				if err != nil {
 					return err
@@ -220,5 +220,5 @@
 		}
 
-		c.user.forEachDownstream(func(dc *downstreamConn) {
+		uc.user.forEachDownstream(func(dc *downstreamConn) {
 			dc.SendMessage(msg)
 		})
@@ -228,5 +228,5 @@
 			return err
 		}
-		ch, err := c.getChannel(name)
+		ch, err := uc.getChannel(name)
 		if err != nil {
 			return err
@@ -242,5 +242,5 @@
 			return err
 		}
-		ch, err := c.getChannel(name)
+		ch, err := uc.getChannel(name)
 		if err != nil {
 			return err
@@ -256,5 +256,5 @@
 			return err
 		}
-		ch, err := c.getChannel(name)
+		ch, err := uc.getChannel(name)
 		if err != nil {
 			return err
@@ -271,5 +271,5 @@
 			return err
 		}
-		ch, err := c.getChannel(name)
+		ch, err := uc.getChannel(name)
 		if err != nil {
 			return err
@@ -291,5 +291,5 @@
 			return err
 		}
-		ch, err := c.getChannel(name)
+		ch, err := uc.getChannel(name)
 		if err != nil {
 			return err
@@ -301,10 +301,10 @@
 		ch.complete = true
 
-		c.user.forEachDownstream(func(dc *downstreamConn) {
+		uc.user.forEachDownstream(func(dc *downstreamConn) {
 			forwardChannel(dc, ch)
 		})
 	case "PRIVMSG":
-		c.ring.Produce(msg)
-		c.user.forEachDownstream(func(dc *downstreamConn) {
+		uc.ring.Produce(msg)
+		uc.user.forEachDownstream(func(dc *downstreamConn) {
 			dc.SendMessage(msg)
 		})
@@ -320,24 +320,24 @@
 		// Ignore
 	default:
-		c.logger.Printf("unhandled upstream message: %v", msg)
+		uc.logger.Printf("unhandled upstream message: %v", msg)
 	}
 	return nil
 }
 
-func (c *upstreamConn) register() {
-	c.nick = c.upstream.Nick
-	c.messages <- &irc.Message{
+func (uc *upstreamConn) register() {
+	uc.nick = uc.upstream.Nick
+	uc.messages <- &irc.Message{
 		Command: "NICK",
-		Params:  []string{c.upstream.Nick},
-	}
-	c.messages <- &irc.Message{
+		Params:  []string{uc.upstream.Nick},
+	}
+	uc.messages <- &irc.Message{
 		Command: "USER",
-		Params:  []string{c.upstream.Username, "0", "*", c.upstream.Realname},
-	}
-}
-
-func (c *upstreamConn) readMessages() error {
+		Params:  []string{uc.upstream.Username, "0", "*", uc.upstream.Realname},
+	}
+}
+
+func (uc *upstreamConn) readMessages() error {
 	for {
-		msg, err := c.irc.ReadMessage()
+		msg, err := uc.irc.ReadMessage()
 		if err == io.EOF {
 			break
@@ -346,6 +346,6 @@
 		}
 
-		if err := c.handleMessage(msg); err != nil {
-			c.logger.Printf("failed to handle message %q: %v", msg, err)
+		if err := uc.handleMessage(msg); err != nil {
+			uc.logger.Printf("failed to handle message %q: %v", msg, err)
 		}
 	}
