Only set network.conn when registered
This commit is contained in:
parent
dd13e1cb62
commit
190f0d3fd0
19
upstream.go
19
upstream.go
@ -1326,6 +1326,25 @@ func (uc *upstreamConn) register() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (uc *upstreamConn) runUntilRegistered() error {
|
||||||
|
for !uc.registered {
|
||||||
|
msg, err := uc.irc.ReadMessage()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to read message: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if uc.srv.Debug {
|
||||||
|
uc.logger.Printf("received: %v", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := uc.handleMessage(msg); err != nil {
|
||||||
|
return fmt.Errorf("failed to handle message %q: %v", msg, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (uc *upstreamConn) requestSASL() bool {
|
func (uc *upstreamConn) requestSASL() bool {
|
||||||
if uc.network.SASL.Mechanism == "" {
|
if uc.network.SASL.Mechanism == "" {
|
||||||
return false
|
return false
|
||||||
|
10
user.go
10
user.go
@ -71,10 +71,12 @@ func (net *network) run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uc.register()
|
uc.register()
|
||||||
|
if err := uc.runUntilRegistered(); err != nil {
|
||||||
|
uc.logger.Printf("failed to register: %v", err)
|
||||||
|
uc.Close()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: wait for the connection to be registered before adding it to
|
|
||||||
// net, otherwise messages might be sent to it while still being
|
|
||||||
// unauthenticated
|
|
||||||
net.lock.Lock()
|
net.lock.Lock()
|
||||||
net.conn = uc
|
net.conn = uc
|
||||||
net.lock.Unlock()
|
net.lock.Unlock()
|
||||||
@ -134,7 +136,7 @@ func (u *user) forEachNetwork(f func(*network)) {
|
|||||||
func (u *user) forEachUpstream(f func(uc *upstreamConn)) {
|
func (u *user) forEachUpstream(f func(uc *upstreamConn)) {
|
||||||
for _, network := range u.networks {
|
for _, network := range u.networks {
|
||||||
uc := network.upstream()
|
uc := network.upstream()
|
||||||
if uc == nil || !uc.registered {
|
if uc == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
f(uc)
|
f(uc)
|
||||||
|
Loading…
Reference in New Issue
Block a user