Skip to content

Commit 5ce5c6e

Browse files
committed
Also send node id v1 to BCDB when registring the node
this is required to be able to match nodes between v1 and v2.
1 parent 45123fc commit 5ce5c6e

File tree

4 files changed

+64
-15
lines changed

4 files changed

+64
-15
lines changed

pkg/gedis/commands_identity.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,25 @@ import (
2525
func (g *Gedis) RegisterNode(nodeID pkg.Identifier, farmID pkg.FarmID, version string, location geoip.Location) (string, error) {
2626

2727
pk := base58.Decode(nodeID.Identity())
28-
29-
resp, err := Bytes(g.Send("nodes", "add", Args{
30-
"node": directory.TfgridNode2{
31-
NodeID: nodeID.Identity(),
32-
FarmID: uint64(farmID),
33-
OsVersion: version,
34-
PublicKeyHex: hex.EncodeToString(pk),
35-
Location: directory.TfgridLocation1{
36-
Longitude: location.Longitute,
37-
Latitude: location.Latitude,
38-
Continent: location.Continent,
39-
Country: location.Country,
40-
City: location.City,
41-
},
28+
node := directory.TfgridNode2{
29+
NodeID: nodeID.Identity(),
30+
FarmID: uint64(farmID),
31+
OsVersion: version,
32+
PublicKeyHex: hex.EncodeToString(pk),
33+
Location: directory.TfgridLocation1{
34+
Longitude: location.Longitute,
35+
Latitude: location.Latitude,
36+
Continent: location.Continent,
37+
Country: location.Country,
38+
City: location.City,
4239
},
43-
}))
40+
}
41+
idv1, err := network.NodeIDv1()
42+
if err == nil {
43+
node.NodeIDv1 = idv1
44+
}
45+
46+
resp, err := Bytes(g.Send("nodes", "add", Args{"node": node}))
4447

4548
if err != nil {
4649
return "", err

pkg/gedis/types/directory/tfgrid_node_2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
//TfgridNode2 jsx schema
1010
type TfgridNode2 struct {
1111
NodeID string `json:"node_id"`
12+
NodeIDv1 string `json:"node_id_v1"`
1213
FarmID uint64 `json:"farm_id"`
1314
OsVersion string `json:"os_version"`
1415
Created schema.Date `json:"created"`

pkg/network/v1.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package network
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/vishvananda/netlink"
8+
)
9+
10+
// NodeIDv1 returns the node ID as it was calculated in 0-OS v1
11+
func NodeIDv1() (string, error) {
12+
zos, err := netlink.LinkByName(DefaultBridge)
13+
if err != nil {
14+
return "", err
15+
}
16+
17+
links, err := netlink.LinkList()
18+
if err != nil {
19+
return "", err
20+
}
21+
22+
// find the physical interface attached to the default bridge
23+
for _, l := range links {
24+
if l.Attrs().MasterIndex == zos.Attrs().Index {
25+
return convertMac(l.Attrs().HardwareAddr.String()), nil
26+
}
27+
}
28+
return "", fmt.Errorf("not physical interface attached to default bridge found")
29+
}
30+
31+
func convertMac(mac string) string {
32+
return strings.Replace(mac, ":", "", -1)
33+
}

pkg/network/v1_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package network
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestConvertMac(t *testing.T) {
10+
id := convertMac("fe:44:e1:67:a8:d2")
11+
assert.Equal(t, "fe44e167a8d2", id)
12+
}

0 commit comments

Comments
 (0)