Abbreviate {upstream,downstream}Conn with uc and dc

This makes it clearer than just `c` when we manipulate both kinds at the
same time.
This commit is contained in:
Simon Ser 2020-02-17 12:36:42 +01:00
parent 0cf731aeab
commit 09dffc0f68
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 141 additions and 141 deletions

View File

@ -56,7 +56,7 @@ type downstreamConn struct {
func newDownstreamConn(srv *Server, netConn net.Conn) *downstreamConn { func newDownstreamConn(srv *Server, netConn net.Conn) *downstreamConn {
msgs := make(chan *irc.Message, 64) msgs := make(chan *irc.Message, 64)
conn := &downstreamConn{ dc := &downstreamConn{
net: netConn, net: netConn,
irc: irc.NewConn(netConn), irc: irc.NewConn(netConn),
srv: srv, srv: srv,
@ -66,48 +66,48 @@ func newDownstreamConn(srv *Server, netConn net.Conn) *downstreamConn {
go func() { go func() {
for msg := range msgs { for msg := range msgs {
if err := conn.irc.WriteMessage(msg); err != nil { if err := dc.irc.WriteMessage(msg); err != nil {
conn.logger.Printf("failed to write message: %v", err) dc.logger.Printf("failed to write message: %v", err)
} }
} }
if err := conn.net.Close(); err != nil { if err := dc.net.Close(); err != nil {
conn.logger.Printf("failed to close connection: %v", err) dc.logger.Printf("failed to close connection: %v", err)
} else { } else {
conn.logger.Printf("connection closed") dc.logger.Printf("connection closed")
} }
}() }()
return conn return dc
} }
func (c *downstreamConn) prefix() *irc.Prefix { func (dc *downstreamConn) prefix() *irc.Prefix {
return &irc.Prefix{ return &irc.Prefix{
Name: c.nick, Name: dc.nick,
User: c.username, User: dc.username,
// TODO: fill the host? // TODO: fill the host?
} }
} }
func (c *downstreamConn) readMessages() error { func (dc *downstreamConn) readMessages() error {
c.logger.Printf("new connection") dc.logger.Printf("new connection")
for { for {
msg, err := c.irc.ReadMessage() msg, err := dc.irc.ReadMessage()
if err == io.EOF { if err == io.EOF {
break break
} else if err != nil { } else if err != nil {
return fmt.Errorf("failed to read IRC command: %v", err) return fmt.Errorf("failed to read IRC command: %v", err)
} }
err = c.handleMessage(msg) err = dc.handleMessage(msg)
if ircErr, ok := err.(ircError); ok { if ircErr, ok := err.(ircError); ok {
ircErr.Message.Prefix = c.srv.prefix() ircErr.Message.Prefix = dc.srv.prefix()
c.SendMessage(ircErr.Message) dc.SendMessage(ircErr.Message)
} else if err != nil { } else if err != nil {
return fmt.Errorf("failed to handle IRC command %q: %v", msg.Command, err) return fmt.Errorf("failed to handle IRC command %q: %v", msg.Command, err)
} }
if c.closed { if dc.closed {
return nil return nil
} }
} }
@ -115,15 +115,15 @@ func (c *downstreamConn) readMessages() error {
return nil return nil
} }
func (c *downstreamConn) Close() error { func (dc *downstreamConn) Close() error {
if c.closed { if dc.closed {
return fmt.Errorf("downstream connection already closed") return fmt.Errorf("downstream connection already closed")
} }
if u := c.user; u != nil { if u := dc.user; u != nil {
u.lock.Lock() u.lock.Lock()
for i := range u.downstreamConns { 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:]...) u.downstreamConns = append(u.downstreamConns[:i], u.downstreamConns[i+1:]...)
} }
} }
@ -136,109 +136,109 @@ func (c *downstreamConn) Close() error {
}) })
} }
close(c.messages) close(dc.messages)
c.closed = true dc.closed = true
return nil return nil
} }
func (c *downstreamConn) SendMessage(msg *irc.Message) { func (dc *downstreamConn) SendMessage(msg *irc.Message) {
c.messages <- msg dc.messages <- msg
} }
func (c *downstreamConn) handleMessage(msg *irc.Message) error { func (dc *downstreamConn) handleMessage(msg *irc.Message) error {
switch msg.Command { switch msg.Command {
case "QUIT": case "QUIT":
return c.Close() return dc.Close()
case "PING": case "PING":
// TODO: handle params // TODO: handle params
c.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: c.srv.prefix(), Prefix: dc.srv.prefix(),
Command: "PONG", Command: "PONG",
Params: []string{c.srv.Hostname}, Params: []string{dc.srv.Hostname},
}) })
return nil return nil
default: default:
if c.registered { if dc.registered {
return c.handleMessageRegistered(msg) return dc.handleMessageRegistered(msg)
} else { } else {
return c.handleMessageUnregistered(msg) return dc.handleMessageUnregistered(msg)
} }
} }
} }
func (c *downstreamConn) handleMessageUnregistered(msg *irc.Message) error { func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
switch msg.Command { switch msg.Command {
case "NICK": case "NICK":
if err := parseMessageParams(msg, &c.nick); err != nil { if err := parseMessageParams(msg, &dc.nick); err != nil {
return err return err
} }
case "USER": case "USER":
var username string var username string
if err := parseMessageParams(msg, &username, nil, nil, &c.realname); err != nil { if err := parseMessageParams(msg, &username, nil, nil, &dc.realname); err != nil {
return err return err
} }
c.username = "~" + username dc.username = "~" + username
default: default:
c.logger.Printf("unhandled message: %v", msg) dc.logger.Printf("unhandled message: %v", msg)
return newUnknownCommandError(msg.Command) return newUnknownCommandError(msg.Command)
} }
if c.username != "" && c.nick != "" { if dc.username != "" && dc.nick != "" {
return c.register() return dc.register()
} }
return nil return nil
} }
func (c *downstreamConn) register() error { func (dc *downstreamConn) register() error {
u := c.srv.getUser(strings.TrimPrefix(c.username, "~")) u := dc.srv.getUser(strings.TrimPrefix(dc.username, "~"))
if u == nil { if u == nil {
c.logger.Printf("failed authentication: unknown username %q", c.username) dc.logger.Printf("failed authentication: unknown username %q", dc.username)
c.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: c.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.ERR_PASSWDMISMATCH, Command: irc.ERR_PASSWDMISMATCH,
Params: []string{"*", "Invalid username or password"}, Params: []string{"*", "Invalid username or password"},
}) })
return nil return nil
} }
c.registered = true dc.registered = true
c.user = u dc.user = u
u.lock.Lock() u.lock.Lock()
u.downstreamConns = append(u.downstreamConns, c) u.downstreamConns = append(u.downstreamConns, dc)
u.lock.Unlock() u.lock.Unlock()
c.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: c.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_WELCOME, Command: irc.RPL_WELCOME,
Params: []string{c.nick, "Welcome to jounce, " + c.nick}, Params: []string{dc.nick, "Welcome to jounce, " + dc.nick},
}) })
c.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: c.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_YOURHOST, Command: irc.RPL_YOURHOST,
Params: []string{c.nick, "Your host is " + c.srv.Hostname}, Params: []string{dc.nick, "Your host is " + dc.srv.Hostname},
}) })
c.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: c.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_CREATED, Command: irc.RPL_CREATED,
Params: []string{c.nick, "Who cares when the server was created?"}, Params: []string{dc.nick, "Who cares when the server was created?"},
}) })
c.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: c.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_MYINFO, Command: irc.RPL_MYINFO,
Params: []string{c.nick, c.srv.Hostname, "jounce", "aiwroO", "OovaimnqpsrtklbeI"}, Params: []string{dc.nick, dc.srv.Hostname, "jounce", "aiwroO", "OovaimnqpsrtklbeI"},
}) })
c.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: c.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.ERR_NOMOTD, Command: irc.ERR_NOMOTD,
Params: []string{c.nick, "No MOTD"}, Params: []string{dc.nick, "No MOTD"},
}) })
u.forEachUpstream(func(uc *upstreamConn) { u.forEachUpstream(func(uc *upstreamConn) {
// TODO: fix races accessing upstream connection data // TODO: fix races accessing upstream connection data
for _, ch := range uc.channels { for _, ch := range uc.channels {
if ch.complete { if ch.complete {
forwardChannel(c, ch) forwardChannel(dc, ch)
} }
} }
@ -250,22 +250,22 @@ func (c *downstreamConn) register() error {
if msg == nil { if msg == nil {
break break
} }
c.SendMessage(msg) dc.SendMessage(msg)
} }
}) })
return nil return nil
} }
func (c *downstreamConn) handleMessageRegistered(msg *irc.Message) error { func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
switch msg.Command { switch msg.Command {
case "USER": case "USER":
return ircError{&irc.Message{ return ircError{&irc.Message{
Command: irc.ERR_ALREADYREGISTERED, Command: irc.ERR_ALREADYREGISTERED,
Params: []string{c.nick, "You may not reregister"}, Params: []string{dc.nick, "You may not reregister"},
}} }}
case "NICK": case "NICK":
c.user.forEachUpstream(func(uc *upstreamConn) { dc.user.forEachUpstream(func(uc *upstreamConn) {
uc.messages <- msg uc.messages <- msg
}) })
case "JOIN": case "JOIN":
@ -274,7 +274,7 @@ func (c *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
return err return err
} }
if ch, _ := c.user.getChannel(name); ch != nil { if ch, _ := dc.user.getChannel(name); ch != nil {
break // already joined break // already joined
} }
@ -289,7 +289,7 @@ func (c *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
return err return err
} }
ch, err := c.user.getChannel(name) ch, err := dc.user.getChannel(name)
if err != nil { if err != nil {
return err return err
} }
@ -308,7 +308,7 @@ func (c *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
} }
if msg.Prefix.Name != name { if msg.Prefix.Name != name {
ch, err := c.user.getChannel(name) ch, err := dc.user.getChannel(name)
if err != nil { if err != nil {
return err return err
} }
@ -316,34 +316,34 @@ func (c *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
if modeStr != "" { if modeStr != "" {
ch.conn.messages <- msg ch.conn.messages <- msg
} else { } else {
c.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: c.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_CHANNELMODEIS, Command: irc.RPL_CHANNELMODEIS,
Params: []string{ch.Name, string(ch.modes)}, Params: []string{ch.Name, string(ch.modes)},
}) })
} }
} else { } else {
if name != c.nick { if name != dc.nick {
return ircError{&irc.Message{ return ircError{&irc.Message{
Command: irc.ERR_USERSDONTMATCH, 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 != "" { if modeStr != "" {
c.user.forEachUpstream(func(uc *upstreamConn) { dc.user.forEachUpstream(func(uc *upstreamConn) {
uc.messages <- msg uc.messages <- msg
}) })
} else { } else {
c.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{
Prefix: c.srv.prefix(), Prefix: dc.srv.prefix(),
Command: irc.RPL_UMODEIS, Command: irc.RPL_UMODEIS,
Params: []string{""}, // TODO Params: []string{""}, // TODO
}) })
} }
} }
default: default:
c.logger.Printf("unhandled message: %v", msg) dc.logger.Printf("unhandled message: %v", msg)
return newUnknownCommandError(msg.Command) return newUnknownCommandError(msg.Command)
} }
return nil return nil

View File

@ -56,7 +56,7 @@ func connectToUpstream(u *user, upstream *Upstream) (*upstreamConn, error) {
} }
msgs := make(chan *irc.Message, 64) msgs := make(chan *irc.Message, 64)
conn := &upstreamConn{ uc := &upstreamConn{
upstream: upstream, upstream: upstream,
logger: logger, logger: logger,
net: netConn, net: netConn,
@ -70,44 +70,44 @@ func connectToUpstream(u *user, upstream *Upstream) (*upstreamConn, error) {
go func() { go func() {
for msg := range msgs { for msg := range msgs {
if err := conn.irc.WriteMessage(msg); err != nil { if err := uc.irc.WriteMessage(msg); err != nil {
conn.logger.Printf("failed to write message: %v", err) uc.logger.Printf("failed to write message: %v", err)
} }
} }
if err := conn.net.Close(); err != nil { if err := uc.net.Close(); err != nil {
conn.logger.Printf("failed to close connection: %v", err) uc.logger.Printf("failed to close connection: %v", err)
} else { } else {
conn.logger.Printf("connection closed") uc.logger.Printf("connection closed")
} }
}() }()
return conn, nil return uc, nil
} }
func (c *upstreamConn) Close() error { func (uc *upstreamConn) Close() error {
if c.closed { if uc.closed {
return fmt.Errorf("upstream connection already closed") return fmt.Errorf("upstream connection already closed")
} }
close(c.messages) close(uc.messages)
c.closed = true uc.closed = true
return nil return nil
} }
func (c *upstreamConn) getChannel(name string) (*upstreamChannel, error) { func (uc *upstreamConn) getChannel(name string) (*upstreamChannel, error) {
ch, ok := c.channels[name] ch, ok := uc.channels[name]
if !ok { if !ok {
return nil, fmt.Errorf("unknown channel %q", name) return nil, fmt.Errorf("unknown channel %q", name)
} }
return ch, nil return ch, nil
} }
func (c *upstreamConn) handleMessage(msg *irc.Message) error { func (uc *upstreamConn) handleMessage(msg *irc.Message) error {
switch msg.Command { switch msg.Command {
case "PING": case "PING":
// TODO: handle params // TODO: handle params
c.messages <- &irc.Message{ uc.messages <- &irc.Message{
Command: "PONG", Command: "PONG",
Params: []string{c.srv.Hostname}, Params: []string{uc.srv.Hostname},
} }
return nil return nil
case "MODE": case "MODE":
@ -117,12 +117,12 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
} }
if name == msg.Prefix.Name { // user mode change 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 fmt.Errorf("received MODE message for unknow nick %q", name)
} }
return c.modes.Apply(modeStr) return uc.modes.Apply(modeStr)
} else { // channel mode change } else { // channel mode change
ch, err := c.getChannel(name) ch, err := uc.getChannel(name)
if err != nil { if err != nil {
return err return err
} }
@ -131,27 +131,27 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
} }
} }
c.user.forEachDownstream(func(dc *downstreamConn) { uc.user.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(msg) dc.SendMessage(msg)
}) })
case "NOTICE": case "NOTICE":
c.logger.Print(msg) uc.logger.Print(msg)
case irc.RPL_WELCOME: case irc.RPL_WELCOME:
c.registered = true uc.registered = true
c.logger.Printf("connection registered") uc.logger.Printf("connection registered")
for _, ch := range c.upstream.Channels { for _, ch := range uc.upstream.Channels {
c.messages <- &irc.Message{ uc.messages <- &irc.Message{
Command: "JOIN", Command: "JOIN",
Params: []string{ch}, Params: []string{ch},
} }
} }
case irc.RPL_MYINFO: 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 return err
} }
if len(msg.Params) > 5 { if len(msg.Params) > 5 {
c.channelModesWithParam = msg.Params[5] uc.channelModesWithParam = msg.Params[5]
} }
case "NICK": case "NICK":
var newNick string var newNick string
@ -159,19 +159,19 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
return err return err
} }
if msg.Prefix.Name == c.nick { if msg.Prefix.Name == uc.nick {
c.logger.Printf("changed nick from %q to %q", c.nick, newNick) uc.logger.Printf("changed nick from %q to %q", uc.nick, newNick)
c.nick = newNick uc.nick = newNick
} }
for _, ch := range c.channels { for _, ch := range uc.channels {
if membership, ok := ch.Members[msg.Prefix.Name]; ok { if membership, ok := ch.Members[msg.Prefix.Name]; ok {
delete(ch.Members, msg.Prefix.Name) delete(ch.Members, msg.Prefix.Name)
ch.Members[newNick] = membership ch.Members[newNick] = membership
} }
} }
c.user.forEachDownstream(func(dc *downstreamConn) { uc.user.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(msg) dc.SendMessage(msg)
}) })
case "JOIN": case "JOIN":
@ -181,15 +181,15 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
} }
for _, ch := range strings.Split(channels, ",") { for _, ch := range strings.Split(channels, ",") {
if msg.Prefix.Name == c.nick { if msg.Prefix.Name == uc.nick {
c.logger.Printf("joined channel %q", ch) uc.logger.Printf("joined channel %q", ch)
c.channels[ch] = &upstreamChannel{ uc.channels[ch] = &upstreamChannel{
Name: ch, Name: ch,
conn: c, conn: uc,
Members: make(map[string]membership), Members: make(map[string]membership),
} }
} else { } else {
ch, err := c.getChannel(ch) ch, err := uc.getChannel(ch)
if err != nil { if err != nil {
return err return err
} }
@ -197,7 +197,7 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
} }
} }
c.user.forEachDownstream(func(dc *downstreamConn) { uc.user.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(msg) dc.SendMessage(msg)
}) })
case "PART": case "PART":
@ -207,11 +207,11 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
} }
for _, ch := range strings.Split(channels, ",") { for _, ch := range strings.Split(channels, ",") {
if msg.Prefix.Name == c.nick { if msg.Prefix.Name == uc.nick {
c.logger.Printf("parted channel %q", ch) uc.logger.Printf("parted channel %q", ch)
delete(c.channels, ch) delete(uc.channels, ch)
} else { } else {
ch, err := c.getChannel(ch) ch, err := uc.getChannel(ch)
if err != nil { if err != nil {
return err return err
} }
@ -219,7 +219,7 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
} }
} }
c.user.forEachDownstream(func(dc *downstreamConn) { uc.user.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(msg) dc.SendMessage(msg)
}) })
case irc.RPL_TOPIC, irc.RPL_NOTOPIC: case irc.RPL_TOPIC, irc.RPL_NOTOPIC:
@ -227,7 +227,7 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
if err := parseMessageParams(msg, nil, &name, &topic); err != nil { if err := parseMessageParams(msg, nil, &name, &topic); err != nil {
return err return err
} }
ch, err := c.getChannel(name) ch, err := uc.getChannel(name)
if err != nil { if err != nil {
return err return err
} }
@ -241,7 +241,7 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
if err := parseMessageParams(msg, nil, &name); err != nil { if err := parseMessageParams(msg, nil, &name); err != nil {
return err return err
} }
ch, err := c.getChannel(name) ch, err := uc.getChannel(name)
if err != nil { if err != nil {
return err return err
} }
@ -255,7 +255,7 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
if err := parseMessageParams(msg, nil, &name, &who, &timeStr); err != nil { if err := parseMessageParams(msg, nil, &name, &who, &timeStr); err != nil {
return err return err
} }
ch, err := c.getChannel(name) ch, err := uc.getChannel(name)
if err != nil { if err != nil {
return err return err
} }
@ -270,7 +270,7 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
if err := parseMessageParams(msg, nil, &statusStr, &name, &members); err != nil { if err := parseMessageParams(msg, nil, &statusStr, &name, &members); err != nil {
return err return err
} }
ch, err := c.getChannel(name) ch, err := uc.getChannel(name)
if err != nil { if err != nil {
return err return err
} }
@ -290,7 +290,7 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
if err := parseMessageParams(msg, nil, &name); err != nil { if err := parseMessageParams(msg, nil, &name); err != nil {
return err return err
} }
ch, err := c.getChannel(name) ch, err := uc.getChannel(name)
if err != nil { if err != nil {
return err return err
} }
@ -300,12 +300,12 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
} }
ch.complete = true ch.complete = true
c.user.forEachDownstream(func(dc *downstreamConn) { uc.user.forEachDownstream(func(dc *downstreamConn) {
forwardChannel(dc, ch) forwardChannel(dc, ch)
}) })
case "PRIVMSG": case "PRIVMSG":
c.ring.Produce(msg) uc.ring.Produce(msg)
c.user.forEachDownstream(func(dc *downstreamConn) { uc.user.forEachDownstream(func(dc *downstreamConn) {
dc.SendMessage(msg) dc.SendMessage(msg)
}) })
case irc.RPL_YOURHOST, irc.RPL_CREATED: case irc.RPL_YOURHOST, irc.RPL_CREATED:
@ -319,34 +319,34 @@ func (c *upstreamConn) handleMessage(msg *irc.Message) error {
case irc.RPL_STATSVLINE, irc.RPL_STATSPING, irc.RPL_STATSBLINE, irc.RPL_STATSDLINE: case irc.RPL_STATSVLINE, irc.RPL_STATSPING, irc.RPL_STATSBLINE, irc.RPL_STATSDLINE:
// Ignore // Ignore
default: default:
c.logger.Printf("unhandled upstream message: %v", msg) uc.logger.Printf("unhandled upstream message: %v", msg)
} }
return nil return nil
} }
func (c *upstreamConn) register() { func (uc *upstreamConn) register() {
c.nick = c.upstream.Nick uc.nick = uc.upstream.Nick
c.messages <- &irc.Message{ uc.messages <- &irc.Message{
Command: "NICK", Command: "NICK",
Params: []string{c.upstream.Nick}, Params: []string{uc.upstream.Nick},
} }
c.messages <- &irc.Message{ uc.messages <- &irc.Message{
Command: "USER", Command: "USER",
Params: []string{c.upstream.Username, "0", "*", c.upstream.Realname}, Params: []string{uc.upstream.Username, "0", "*", uc.upstream.Realname},
} }
} }
func (c *upstreamConn) readMessages() error { func (uc *upstreamConn) readMessages() error {
for { for {
msg, err := c.irc.ReadMessage() msg, err := uc.irc.ReadMessage()
if err == io.EOF { if err == io.EOF {
break break
} else if err != nil { } else if err != nil {
return fmt.Errorf("failed to read IRC command: %v", err) return fmt.Errorf("failed to read IRC command: %v", err)
} }
if err := c.handleMessage(msg); err != nil { if err := uc.handleMessage(msg); err != nil {
c.logger.Printf("failed to handle message %q: %v", msg, err) uc.logger.Printf("failed to handle message %q: %v", msg, err)
} }
} }