Remove unused user.getChannel, move getUpstream to user
This commit is contained in:
parent
88cc4c41f1
commit
03c546e8bf
@ -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{
|
||||||
|
37
server.go
37
server.go
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
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 {
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user