Tweaks to link handling

This commit is contained in:
Neil Alexander 2024-11-22 09:44:30 +00:00
parent ff9e90c5aa
commit b98f98318f
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -154,7 +154,7 @@ const ErrLinkPasswordInvalid = linkError("invalid password supplied")
const ErrLinkUnrecognisedSchema = linkError("link schema unknown") const ErrLinkUnrecognisedSchema = linkError("link schema unknown")
const ErrLinkMaxBackoffInvalid = linkError("max backoff duration invalid") const ErrLinkMaxBackoffInvalid = linkError("max backoff duration invalid")
const ErrLinkSNINotSupported = linkError("SNI not supported on this link type") const ErrLinkSNINotSupported = linkError("SNI not supported on this link type")
const ErrLinkNoSuitableIPs = linkError("no suitable remote IPs") const ErrLinkNoSuitableIPs = linkError("peer has no suitable addresses")
func (l *links) add(u *url.URL, sintf string, linkType linkType) error { func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
var retErr error var retErr error
@ -365,8 +365,12 @@ func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
// Give the connection to the handler. The handler will block // Give the connection to the handler. The handler will block
// for the lifetime of the connection. // for the lifetime of the connection.
if err = l.handler(linkType, options, lc, resetBackoff, false); err != nil && err != io.EOF { switch err = l.handler(linkType, options, lc, resetBackoff, false); {
l.core.log.Debugf("Link %s error: %s\n", info.uri, err) case err == nil:
case errors.Is(err, io.EOF):
case errors.Is(err, net.ErrClosed):
default:
l.core.log.Debugf("Link %s error: %s\n", u.Host, err)
} }
// The handler has stopped running so the connection is dead, // The handler has stopped running so the connection is dead,
@ -697,7 +701,16 @@ func (l *links) findSuitableIP(url *url.URL, fn func(hostname string, ip net.IP,
var _ips [64]net.IP var _ips [64]net.IP
ips := _ips[:0] ips := _ips[:0]
for _, ip := range resp { for _, ip := range resp {
if l.core.config.peerFilter != nil && !l.core.config.peerFilter(ip) { switch {
case ip.IsUnspecified():
continue
case ip.IsMulticast():
continue
case ip.IsLinkLocalMulticast():
continue
case ip.IsInterfaceLocalMulticast():
continue
case l.core.config.peerFilter != nil && !l.core.config.peerFilter(ip):
continue continue
} }
ips = append(ips, ip) ips = append(ips, ip)