5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-23 12:15:39 +00:00

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,6 +322,8 @@ func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {
if err != nil { if err != nil {
continue continue
} }
go func(conn net.Conn) {
defer conn.Close()
pu := *u pu := *u
pu.Host = conn.RemoteAddr().String() pu.Host = conn.RemoteAddr().String()
lu := urlForLinkInfo(pu) lu := urlForLinkInfo(pu)
@ -331,8 +333,7 @@ func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {
linkType: linkTypeEphemeral, // TODO: should be incoming linkType: linkTypeEphemeral, // TODO: should be incoming
} }
if l.isConnectedTo(info) { if l.isConnectedTo(info) {
_ = conn.Close() return
continue
} }
l.RLock() l.RLock()
state, ok := l._links[info] state, ok := l._links[info]
@ -358,15 +359,10 @@ func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {
if err = l.handler(&info, options, lc); err != nil && err != io.EOF { 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.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.Lock() l.Lock()
delete(l._links, info) delete(l._links, info)
l.Unlock() l.Unlock()
}(conn)
} }
}() }()
return li, nil return li, nil