Fix incoming connection handlers

This commit is contained in:
Neil Alexander 2023-05-20 22:22:15 +01:00
parent c0188f5600
commit aff3201084
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -322,51 +322,47 @@ func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {
if err != nil { if err != nil {
continue continue
} }
pu := *u go func(conn net.Conn) {
pu.Host = conn.RemoteAddr().String() defer conn.Close()
lu := urlForLinkInfo(pu) pu := *u
info := linkInfo{ pu.Host = conn.RemoteAddr().String()
uri: lu.String(), lu := urlForLinkInfo(pu)
sintf: sintf, info := linkInfo{
linkType: linkTypeEphemeral, // TODO: should be incoming uri: lu.String(),
} sintf: sintf,
if l.isConnectedTo(info) { linkType: linkTypeEphemeral, // TODO: should be incoming
_ = conn.Close()
continue
}
l.RLock()
state, ok := l._links[info]
l.RUnlock()
if !ok || state == nil {
state = &link{
info: info,
} }
} if l.isConnectedTo(info) {
lc := &linkConn{ return
Conn: conn,
up: time.Now(),
}
var options linkOptions
phony.Block(state, func() {
state._conn = lc
state._err = nil
state.linkProto = strings.ToUpper(u.Scheme)
})
l.Lock()
l._links[info] = state
l.Unlock()
if err = l.handler(&info, options, lc); err != nil && err != io.EOF {
l.core.log.Debugf("Link %s error: %s\n", u.Host, err)
}
phony.Block(state, func() {
state._conn = nil
if state._err = err; state._err != nil {
state._errtime = time.Now()
} }
}) l.RLock()
l.Lock() state, ok := l._links[info]
delete(l._links, info) l.RUnlock()
l.Unlock() if !ok || state == nil {
state = &link{
info: info,
}
}
lc := &linkConn{
Conn: conn,
up: time.Now(),
}
var options linkOptions
phony.Block(state, func() {
state._conn = lc
state._err = nil
state.linkProto = strings.ToUpper(u.Scheme)
})
l.Lock()
l._links[info] = state
l.Unlock()
if err = l.handler(&info, options, lc); err != nil && err != io.EOF {
l.core.log.Debugf("Link %s error: %s\n", u.Host, err)
}
l.Lock()
delete(l._links, info)
l.Unlock()
}(conn)
} }
}() }()
return li, nil return li, nil