Skip to content

Commit

Permalink
Add external multiaddress to NodeInfoExtended
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed May 13, 2024
1 parent c58790e commit f73ea97
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions components/dashboard_metrics/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type dependencies struct {
dig.In

Host host.Host
MultiAddress string `name:"multiAddress"`
Protocol *protocol.Protocol
RestRouteManager *restapipkg.RestRouteManager
AppInfo *app.Info
Expand Down
7 changes: 5 additions & 2 deletions components/dashboard_metrics/info.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dashboardmetrics

import (
"fmt"
"runtime"
"time"
)
Expand All @@ -13,12 +14,14 @@ func nodeInfoExtended() *NodeInfoExtended {
var m runtime.MemStats
runtime.ReadMemStats(&m)

multiAddress := fmt.Sprintf("%s/p2p/%s", deps.MultiAddress, deps.Host.ID().String())

status := &NodeInfoExtended{
Version: deps.AppInfo.Version,
LatestVersion: deps.AppInfo.LatestGitHubVersion,
Uptime: time.Since(nodeStartupTimestamp).Milliseconds(),
NodeID: deps.Host.ID().String(),
NodeAlias: ParamsNode.Alias,
MultiAddress: multiAddress,
Alias: ParamsNode.Alias,
MemoryUsage: int64(m.HeapAlloc + m.StackSys + m.MSpanSys + m.MCacheSys + m.BuckHashSys + m.GCSys + m.OtherSys),
}

Expand Down
4 changes: 2 additions & 2 deletions components/dashboard_metrics/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ type NodeInfoExtended struct {
Version string `serix:",lenPrefix=uint8"`
LatestVersion string `serix:",lenPrefix=uint8"`
Uptime int64 `serix:""`
NodeID string `serix:",lenPrefix=uint8"`
NodeAlias string `serix:",lenPrefix=uint8"`
MultiAddress string `serix:",lenPrefix=uint8"`
Alias string `serix:",lenPrefix=uint8"`
MemoryUsage int64 `serix:""`
}

Expand Down
35 changes: 29 additions & 6 deletions components/p2p/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (

func init() {
Component = &app.Component{
Name: "P2P",
DepsFunc: func(cDeps dependencies) { deps = cDeps },
Params: params,
Provide: provide,
Configure: configure,
Run: run,
Name: "P2P",
DepsFunc: func(cDeps dependencies) { deps = cDeps },
Params: params,
InitConfigParams: initConfigParams,
Provide: provide,
Configure: configure,
Run: run,
}
}

Expand All @@ -46,6 +47,28 @@ type dependencies struct {
Protocol *protocol.Protocol
}

func initConfigParams(c *dig.Container) error {
type cfgResult struct {
dig.Out
MultiAddress string `name:"multiAddress"`
}

if err := c.Provide(func() cfgResult {
multiAddress := ParamsP2P.BindMultiAddresses[0]
if len(ParamsP2P.Autopeering.ExternalMultiAddresses) > 0 {
multiAddress = ParamsP2P.Autopeering.ExternalMultiAddresses[0]
}

return cfgResult{
MultiAddress: multiAddress,
}
}); err != nil {
Component.LogPanic(err.Error())
}

return nil
}

func provide(c *dig.Container) error {
type configManagerDeps struct {
dig.In
Expand Down

0 comments on commit f73ea97

Please sign in to comment.