5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-23 07:35:39 +00:00

Fix negotiating priority on connection

This commit is contained in:
Neil Alexander 2023-07-15 22:34:29 +01:00
parent ff96740ac7
commit 63b214f6b7
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -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 { func (l *links) handler(linkType linkType, options linkOptions, conn net.Conn) error {
meta := version_getBaseMetadata() meta := version_getBaseMetadata()
meta.publicKey = l.core.public meta.publicKey = l.core.public
meta.priority = options.priority
metaBytes := meta.encode() metaBytes := meta.encode()
if err := conn.SetDeadline(time.Now().Add(time.Second * 6)); err != nil { if err := conn.SetDeadline(time.Now().Add(time.Second * 6)); err != nil {
return fmt.Errorf("failed to set handshake deadline: %w", err) 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() remoteAddr := net.IP(address.AddrForKey(meta.publicKey)[:]).String()
remoteStr := fmt.Sprintf("%s@%s", remoteAddr, conn.RemoteAddr()) remoteStr := fmt.Sprintf("%s@%s", remoteAddr, conn.RemoteAddr())
localStr := conn.LocalAddr() localStr := conn.LocalAddr()
priority := options.priority
if meta.priority > priority {
priority = meta.priority
}
l.core.log.Infof("Connected %s: %s, source %s", l.core.log.Infof("Connected %s: %s, source %s",
dir, remoteStr, localStr) dir, remoteStr, localStr)
err = l.core.HandleConn(meta.publicKey, conn, options.priority) err = l.core.HandleConn(meta.publicKey, conn, priority)
switch err { switch err {
case io.EOF, net.ErrClosed, nil: case io.EOF, net.ErrClosed, nil:
l.core.log.Infof("Disconnected %s: %s, source %s", l.core.log.Infof("Disconnected %s: %s, source %s",