remove string from multicast announcement format

This commit is contained in:
Arceliar 2021-06-25 21:27:29 -05:00
parent 3b38ed082f
commit d1dfe38683

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"crypto/ed25519" "crypto/ed25519"
"encoding/binary"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"net" "net"
@ -307,7 +308,10 @@ func (m *Multicast) _announce() {
a.Zone = "" a.Zone = ""
destAddr.Zone = iface.Name destAddr.Zone = iface.Name
msg := append([]byte(nil), m.core.GetSelf().Key...) msg := append([]byte(nil), m.core.GetSelf().Key...)
msg = append(msg, a.String()...) msg = append(msg, a.IP...)
pbs := make([]byte, 2)
binary.BigEndian.PutUint16(pbs, uint16(a.Port))
msg = append(msg, pbs...)
_, _ = m.sock.WriteTo(msg, nil, destAddr) _, _ = m.sock.WriteTo(msg, nil, destAddr)
} }
if info.interval.Seconds() < 15 { if info.interval.Seconds() < 15 {
@ -354,13 +358,20 @@ func (m *Multicast) listen() {
if bytes.Equal(key, m.core.GetSelf().Key) { if bytes.Equal(key, m.core.GetSelf().Key) {
continue // don't bother trying to peer with self continue // don't bother trying to peer with self
} }
anAddr := string(bs[ed25519.PublicKeySize:nBytes]) begin := ed25519.PublicKeySize
addr, err := net.ResolveTCPAddr("tcp6", anAddr) end := nBytes - 2
if end <= begin {
continue // malformed address
}
ip := bs[begin:end]
port := binary.BigEndian.Uint16(bs[end:nBytes])
anAddr := net.TCPAddr{IP: ip, Port: int(port)}
addr, err := net.ResolveTCPAddr("tcp6", anAddr.String())
if err != nil { if err != nil {
continue continue
} }
from := fromAddr.(*net.UDPAddr) from := fromAddr.(*net.UDPAddr)
if addr.IP.String() != from.IP.String() { if !from.IP.Equal(addr.IP) {
continue continue
} }
var interfaces map[string]interfaceInfo var interfaces map[string]interfaceInfo