diff --git a/src/core/link.go b/src/core/link.go index 9b8e089..d7de943 100644 --- a/src/core/link.go +++ b/src/core/link.go @@ -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 { diff --git a/src/core/version.go b/src/core/version.go index 6676c7b..2c449ec 100644 --- a/src/core/version.go +++ b/src/core/version.go @@ -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 }