Skip to content

Commit

Permalink
p2p: generate random node name
Browse files Browse the repository at this point in the history
  • Loading branch information
inciner8r committed Apr 14, 2024
1 parent 2e239e9 commit bafdaa6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/docker/docker v26.0.1+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/elastic/gosigar v0.14.2 // indirect
github.com/fatih/color v1.13.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5il
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/docker/docker v26.0.1+incompatible h1:t39Hm6lpXuXtgkF0dm1t9a5HkbUfdGy6XbWexmGr+hA=
github.com/docker/docker v26.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
Expand Down
4 changes: 3 additions & 1 deletion p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/NetSepio/erebrus/util/pkg/node"
"github.com/docker/docker/pkg/namesgenerator"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/multiformats/go-multiaddr"
)
Expand All @@ -23,6 +24,7 @@ const DiscoveryServiceTag = "erebrus"
var StartTimeStamp int64

func Init() {
name := namesgenerator.GetRandomName(0)
StartTimeStamp = time.Now().Unix()
ctx := context.Background()

Expand Down Expand Up @@ -66,7 +68,7 @@ func Init() {
go func() {
time.Sleep(5 * time.Second)
fmt.Println("sending status")
node_data := node.CreateNodeStatus(remoteAddr, ha.ID().String(), StartTimeStamp)
node_data := node.CreateNodeStatus(remoteAddr, ha.ID().String(), StartTimeStamp, name)
msgBytes, err := json.Marshal(node_data)
if err != nil {
panic(err)
Expand Down
4 changes: 3 additions & 1 deletion util/pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ type NodeStatus struct {
DownloadSpeed float64 `json:"downloadSpeed"`
UploadSpeed float64 `json:"uploadSpeed"`
StartTimeStamp int64 `json:"startTimeStamp"`
Name string `json:"name"`
}

func CreateNodeStatus(address string, id string, startTimeStamp int64) *NodeStatus {
func CreateNodeStatus(address string, id string, startTimeStamp int64, name string) *NodeStatus {
speedtestResult, err := speedtest.GetSpeedtestResults()
if err != nil {
logrus.Error("failed to fetch network speed: ", err.Error())
Expand All @@ -32,6 +33,7 @@ func CreateNodeStatus(address string, id string, startTimeStamp int64) *NodeStat
DownloadSpeed: speedtestResult.DownloadSpeed,
UploadSpeed: speedtestResult.UploadSpeed,
StartTimeStamp: startTimeStamp,
Name: name,
}
return nodeStatus
}

0 comments on commit bafdaa6

Please sign in to comment.