mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 10:05:17 +00: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 {
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user