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)
 		}
 	}
