mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-09 23:20:26 +03:00
Fix incoming connection handlers
This commit is contained in:
parent
c0188f5600
commit
aff3201084
@ -322,6 +322,8 @@ func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
go func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
pu := *u
|
||||
pu.Host = conn.RemoteAddr().String()
|
||||
lu := urlForLinkInfo(pu)
|
||||
@ -331,8 +333,7 @@ func (l *links) listen(u *url.URL, sintf string) (*Listener, error) {
|
||||
linkType: linkTypeEphemeral, // TODO: should be incoming
|
||||
}
|
||||
if l.isConnectedTo(info) {
|
||||
_ = conn.Close()
|
||||
continue
|
||||
return
|
||||
}
|
||||
l.RLock()
|
||||
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 {
|
||||
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()
|
||||
delete(l._links, info)
|
||||
l.Unlock()
|
||||
}(conn)
|
||||
}
|
||||
}()
|
||||
return li, nil
|
||||
|
Loading…
Reference in New Issue
Block a user