From 63b214f6b707f1f7ea837d495fa5ae97300b755b Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sat, 15 Jul 2023 22:34:29 +0100 Subject: [PATCH] Fix negotiating priority on connection --- src/core/link.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/link.go b/src/core/link.go index f7afd8b..1a16804 100644 --- a/src/core/link.go +++ b/src/core/link.go @@ -479,6 +479,7 @@ func (l *links) connect(u *url.URL, info linkInfo, options linkOptions) (net.Con func (l *links) handler(linkType linkType, options linkOptions, conn net.Conn) error { meta := version_getBaseMetadata() meta.publicKey = l.core.public + meta.priority = options.priority metaBytes := meta.encode() if err := conn.SetDeadline(time.Now().Add(time.Second * 6)); err != nil { return fmt.Errorf("failed to set handshake deadline: %w", err) @@ -536,10 +537,14 @@ func (l *links) handler(linkType linkType, options linkOptions, conn net.Conn) e remoteAddr := net.IP(address.AddrForKey(meta.publicKey)[:]).String() remoteStr := fmt.Sprintf("%s@%s", remoteAddr, conn.RemoteAddr()) localStr := conn.LocalAddr() + priority := options.priority + if meta.priority > priority { + priority = meta.priority + } l.core.log.Infof("Connected %s: %s, source %s", dir, remoteStr, localStr) - err = l.core.HandleConn(meta.publicKey, conn, options.priority) + err = l.core.HandleConn(meta.publicKey, conn, priority) switch err { case io.EOF, net.ErrClosed, nil: l.core.log.Infof("Disconnected %s: %s, source %s",