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 != "" { if network != "" {
dc.upstream = dc.srv.getUpstream(network) dc.upstream = dc.user.getUpstream(network)
if dc.upstream == nil { if dc.upstream == nil {
dc.logger.Printf("failed registration: unknown upstream %q", network) dc.logger.Printf("failed registration: unknown upstream %q", network)
dc.SendMessage(&irc.Message{ dc.SendMessage(&irc.Message{

View File

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