5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-24 16:01:35 +00:00

add metric to metadata exchange, but currently left at default 0 value

This commit is contained in:
Arceliar 2021-05-23 18:40:36 -05:00
parent 6bc2044ced
commit 58af92812e
2 changed files with 9 additions and 1 deletions

View File

@ -158,6 +158,8 @@ func (intf *link) handler() (chan struct{}, error) {
defer intf.conn.Close()
meta := version_getBaseMetadata()
meta.key = intf.links.core.public
// TODO set meta.metric
metric := uint64(meta.metric)
metaBytes := meta.encode()
// TODO timeouts on send/recv (goroutine for send/recv, channel select w/ timer)
var err error
@ -190,6 +192,9 @@ func (intf *link) handler() (chan struct{}, error) {
if !meta.decode(metaBytes) {
return nil, errors.New("failed to decode metadata")
}
if metric < uint64(meta.metric) {
metric = uint64(meta.metric)
}
if !meta.check() {
intf.links.core.log.Errorf("Failed to connect to node: %s is incompatible version (local %s, remote %s)",
intf.lname,
@ -250,7 +255,6 @@ func (intf *link) handler() (chan struct{}, error) {
intf.links.core.log.Infof("Connected %s: %s, source %s",
strings.ToUpper(intf.info.linkType), themString, intf.info.local)
// Run the handler
var metric uint64 // TODO exchange metric in matadata, use max value
err = intf.links.core.PacketConn.HandleConn(ed25519.PublicKey(intf.info.key[:]), intf.conn, metric)
// TODO don't report an error if it's just a 'use of closed network connection'
if err != nil {

View File

@ -14,6 +14,7 @@ type version_metadata struct {
ver uint8 // 1 byte in this version
// Everything after this point potentially depends on the version number, and is subject to change in future versions
minorVer uint8 // 1 byte in this version
metric uint8 // 1 byte in this version
key ed25519.PublicKey
}
@ -31,6 +32,7 @@ func version_getMetaLength() (mlen int) {
mlen += 4 // meta
mlen++ // ver, as long as it's < 127, which it is in this version
mlen++ // minorVer, as long as it's < 127, which it is in this version
mlen++ // metric
mlen += ed25519.PublicKeySize // key
return
}
@ -41,6 +43,7 @@ func (m *version_metadata) encode() []byte {
bs = append(bs, m.meta[:]...)
bs = append(bs, m.ver)
bs = append(bs, m.minorVer)
bs = append(bs, m.metric)
bs = append(bs, m.key[:]...)
if len(bs) != version_getMetaLength() {
panic("Inconsistent metadata length")
@ -57,6 +60,7 @@ func (m *version_metadata) decode(bs []byte) bool {
offset += copy(m.meta[:], bs[offset:])
m.ver, offset = bs[offset], offset+1
m.minorVer, offset = bs[offset], offset+1
m.metric, offset = bs[offset], offset+1
m.key = append([]byte(nil), bs[offset:]...)
return true
}