mirror of
https://github.com/yggdrasil-network/yggdrasil-go
synced 2024-11-09 23:20:26 +03:00
Fix negotiating priority on connection
This commit is contained in:
parent
ff96740ac7
commit
63b214f6b7
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user