Remove unused user.getChannel, move getUpstream to user

This commit is contained in:
Simon Ser 2020-03-04 16:00:19 +01:00
parent 88cc4c41f1
commit 03c546e8bf
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 6 additions and 33 deletions

View File

@ -321,7 +321,7 @@ func (dc *downstreamConn) register() error {
}
if network != "" {
dc.upstream = dc.srv.getUpstream(network)
dc.upstream = dc.user.getUpstream(network)
if dc.upstream == nil {
dc.logger.Printf("failed registration: unknown upstream %q", network)
dc.SendMessage(&irc.Message{

View File

@ -82,31 +82,13 @@ func (u *user) forEachDownstream(f func(dc *downstreamConn)) {
u.lock.Unlock()
}
func (u *user) getChannel(name string, upstream *Upstream) (*upstreamChannel, error) {
var channel *upstreamChannel
var err error
u.forEachUpstream(func(uc *upstreamConn) {
if err != nil {
return
}
if upstream != nil && uc.upstream != upstream {
return
}
if ch, ok := uc.channels[name]; ok {
if channel != nil {
err = fmt.Errorf("ambiguous channel name %q", name)
} else {
channel = ch
func (u *user) getUpstream(name string) *Upstream {
for i, upstream := range u.srv.Upstreams {
if upstream.Addr == name {
return &u.srv.Upstreams[i]
}
}
})
if channel == nil {
return nil, ircError{&irc.Message{
Command: irc.ERR_NOSUCHCHANNEL,
Params: []string{name, "No such channel"},
}}
}
return channel, nil
return nil
}
type Upstream struct {
@ -199,15 +181,6 @@ func (s *Server) getUser(name string) *user {
return u
}
func (s *Server) getUpstream(name string) *Upstream {
for i, upstream := range s.Upstreams {
if upstream.Addr == name {
return &s.Upstreams[i]
}
}
return nil
}
func (s *Server) Serve(ln net.Listener) error {
for {
netConn, err := ln.Accept()