Add network.upstream helper

This commit is contained in:
Simon Ser 2020-03-21 10:24:38 +01:00
parent 4b9168196a
commit c511a3c895
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 8 additions and 10 deletions

View File

@ -143,12 +143,7 @@ func (dc *downstreamConn) upstream() *upstreamConn {
if dc.network == nil {
return nil
}
var upstream *upstreamConn
dc.forEachUpstream(func(uc *upstreamConn) {
upstream = uc
})
return upstream
return dc.network.upstream()
}
func (dc *downstreamConn) marshalEntity(uc *upstreamConn, entity string) string {

11
user.go
View File

@ -67,6 +67,12 @@ func (net *network) run() {
}
}
func (net *network) upstream() *upstreamConn {
net.lock.Lock()
defer net.lock.Unlock()
return net.conn
}
type user struct {
User
srv *Server
@ -99,10 +105,7 @@ func (u *user) forEachNetwork(f func(*network)) {
func (u *user) forEachUpstream(f func(uc *upstreamConn)) {
u.lock.Lock()
for _, network := range u.networks {
network.lock.Lock()
uc := network.conn
network.lock.Unlock()
uc := network.upstream()
if uc == nil || !uc.registered || uc.closed {
continue
}