mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-23 10:05:17 +00:00
Don't reject multiple genuine links from the same host
This commit is contained in:
parent
d66b3ffb7a
commit
8fe1c41295
@ -320,9 +320,6 @@ func (intf *link) close() error {
|
||||
}
|
||||
|
||||
func linkInfoFor(linkType, sintf, remote string) linkInfo {
|
||||
if h, _, err := net.SplitHostPort(remote); err == nil {
|
||||
remote = h
|
||||
}
|
||||
return linkInfo{
|
||||
linkType: linkType,
|
||||
local: sintf,
|
||||
|
@ -31,14 +31,14 @@ func (l *links) newLinkTCP() *linkTCP {
|
||||
}
|
||||
|
||||
func (l *linkTCP) dial(url *url.URL, options linkOptions, sintf string) error {
|
||||
info := linkInfoFor("tcp", sintf, strings.SplitN(url.Host, "%", 2)[0])
|
||||
if l.links.isConnectedTo(info) {
|
||||
return nil
|
||||
}
|
||||
addr, err := net.ResolveTCPAddr("tcp", url.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info := linkInfoFor("tcp", sintf, addr.String())
|
||||
if l.links.isConnectedTo(info) {
|
||||
return nil
|
||||
}
|
||||
dialer, err := l.dialerFor(addr, sintf)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -47,7 +47,8 @@ func (l *linkTCP) dial(url *url.URL, options linkOptions, sintf string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return l.handler(url.String(), info, conn, options, false, false)
|
||||
uri := strings.TrimRight(strings.SplitN(url.String(), "?", 2)[0], "/")
|
||||
return l.handler(uri, info, conn, options, false, false)
|
||||
}
|
||||
|
||||
func (l *linkTCP) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||
@ -83,7 +84,7 @@ func (l *linkTCP) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||
}
|
||||
addr := conn.RemoteAddr().(*net.TCPAddr)
|
||||
name := fmt.Sprintf("tcp://%s", addr)
|
||||
info := linkInfoFor("tcp", sintf, strings.SplitN(addr.IP.String(), "%", 2)[0])
|
||||
info := linkInfoFor("tcp", sintf, addr.String())
|
||||
if err = l.handler(name, info, conn, linkOptions{}, true, addr.IP.IsLinkLocalUnicast()); err != nil {
|
||||
l.core.log.Errorln("Failed to create inbound link:", err)
|
||||
}
|
||||
|
@ -47,14 +47,14 @@ func (l *links) newLinkTLS(tcp *linkTCP) *linkTLS {
|
||||
}
|
||||
|
||||
func (l *linkTLS) dial(url *url.URL, options linkOptions, sintf, sni string) error {
|
||||
info := linkInfoFor("tls", sintf, strings.SplitN(url.Host, "%", 2)[0])
|
||||
if l.links.isConnectedTo(info) {
|
||||
return nil
|
||||
}
|
||||
addr, err := net.ResolveTCPAddr("tcp", url.Host)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info := linkInfoFor("tls", sintf, addr.String())
|
||||
if l.links.isConnectedTo(info) {
|
||||
return nil
|
||||
}
|
||||
dialer, err := l.tcp.dialerFor(addr, sintf)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -69,7 +69,8 @@ func (l *linkTLS) dial(url *url.URL, options linkOptions, sintf, sni string) err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return l.handler(url.String(), info, conn, options, false, false)
|
||||
uri := strings.TrimRight(strings.SplitN(url.String(), "?", 2)[0], "/")
|
||||
return l.handler(uri, info, conn, options, false, false)
|
||||
}
|
||||
|
||||
func (l *linkTLS) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||
@ -106,7 +107,7 @@ func (l *linkTLS) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||
}
|
||||
addr := conn.RemoteAddr().(*net.TCPAddr)
|
||||
name := fmt.Sprintf("tls://%s", addr)
|
||||
info := linkInfoFor("tls", sintf, strings.SplitN(addr.IP.String(), "%", 2)[0])
|
||||
info := linkInfoFor("tls", sintf, addr.String())
|
||||
if err = l.handler(name, info, conn, linkOptions{}, true, addr.IP.IsLinkLocalUnicast()); err != nil {
|
||||
l.core.log.Errorln("Failed to create inbound link:", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user