Skip to content

Commit

Permalink
Update substate to auto sign termns and condition (#1555)
Browse files Browse the repository at this point in the history
Also fix issue with yggdraisl if one of the urls is not reachable
  • Loading branch information
muhamadazmy authored Jan 11, 2022
1 parent 58b18a3 commit 2645ca7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
5 changes: 4 additions & 1 deletion cmds/modules/noded/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (

const (
reportUptimeEvery = 8 * time.Hour

tcUrl = ""
tcHash = ""
)

func registration(ctx context.Context, cl zbus.Client, env environment.Environment, cap gridtypes.Capacity) (nodeID, twinID uint32, err error) {
Expand Down Expand Up @@ -205,7 +208,7 @@ func registerNode(
if err != nil {
return 0, 0, err
}
if _, err := sub.EnsureAccount(id, env.ActivationURL); err != nil {
if _, err := sub.EnsureAccount(id, env.ActivationURL, tcUrl, tcHash); err != nil {
return 0, 0, errors.Wrap(err, "failed to ensure account")
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ require (
github.com/stretchr/testify v1.7.0
github.com/threefoldtech/0-fs v1.3.1-0.20201203163303-d963de9adea7
github.com/threefoldtech/go-rmb v0.1.7
github.com/threefoldtech/substrate-client v0.0.0-20211231191725-b8f9d49d9a97
github.com/threefoldtech/substrate-client v0.0.0-20220111105032-8bebe8a7d791
github.com/threefoldtech/zbus v0.1.5
github.com/tinylib/msgp v1.1.5 // indirect
github.com/tyler-smith/go-bip39 v1.1.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,10 @@ github.com/threefoldtech/go-rmb v0.1.7/go.mod h1:+9ql1bqMqmBpudtafk5HG4WO0E7Y5AX
github.com/threefoldtech/substrate-client v0.0.0-20210930125201-9bd88e80762d/go.mod h1:t/85gAaltVbJmUnCVwu5lpNKn0HLn9Z9vu/NFJlJcrk=
github.com/threefoldtech/substrate-client v0.0.0-20211231191725-b8f9d49d9a97 h1:3fm4M2cpOMgjirzLLNTxElUI7ksSu+z3z+NtP7zAY+E=
github.com/threefoldtech/substrate-client v0.0.0-20211231191725-b8f9d49d9a97/go.mod h1:kI84UXFN+t0v7I3Qtj+otQwIaGel+AT86L5B0t/zQpI=
github.com/threefoldtech/substrate-client v0.0.0-20220111085721-f87895fa386c h1:v5DLY06zepCo96PrfayXfllpur1BkJY6rO3TlToMurg=
github.com/threefoldtech/substrate-client v0.0.0-20220111085721-f87895fa386c/go.mod h1:kI84UXFN+t0v7I3Qtj+otQwIaGel+AT86L5B0t/zQpI=
github.com/threefoldtech/substrate-client v0.0.0-20220111105032-8bebe8a7d791 h1:V7tInz9sUgcbCZnoVkhUcT34FzGNihU6sQl6Mwzl5r0=
github.com/threefoldtech/substrate-client v0.0.0-20220111105032-8bebe8a7d791/go.mod h1:kI84UXFN+t0v7I3Qtj+otQwIaGel+AT86L5B0t/zQpI=
github.com/threefoldtech/zbus v0.1.5 h1:S9kXbjejoRRnJw1yKHEXFGF2vqL+Drae2n4vpj0pGHo=
github.com/threefoldtech/zbus v0.1.5/go.mod h1:ZtiRpcqzEBJetVQDsEbw0p48h/AF3O1kf0tvd30I0BU=
github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
Expand Down
4 changes: 3 additions & 1 deletion pkg/network/ndmz/dhcp_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ func (d *DHCPMon) startZinit() error {
if status.State.Exited() {
log.Info().Msgf("zinit service %s already exists but is stopped, starting it", d.service)
return d.z.Start(d.service)
} else if status.State.Is(zinit.ServiceStateRunning) {
return nil
}

log.Info().Msgf("create and start %s zinit service", d.service)
Expand All @@ -139,7 +141,7 @@ func (d *DHCPMon) startZinit() error {
return err
}

if err := d.z.Monitor(d.service); err != nil {
if err := d.z.Monitor(d.service); err != nil && err != zinit.ErrAlreadyMonitored {
log.Error().Err(err).Msg("fail to start monitoring dhcp-zos zinit service")
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/network/yggdrasil/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (n *NodeConfig) FindPeers(ctx context.Context, filter ...Filter) error {
return errors.Wrap(err, "failed to get peers list")
}

log.Info().Int("count", len(peersUp)).Msg("found yggdrasil up peers")
endpoints := make([]string, len(peersUp))
for i, p := range peersUp {
endpoints[i] = p.Endpoint
Expand Down
8 changes: 5 additions & 3 deletions pkg/network/yggdrasil/public_peerlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"net/url"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
)

//PeerListFallback is an hardcoded list of public yggdrasil node
Expand Down Expand Up @@ -116,11 +116,13 @@ next:
// we have filters, we need to process the endpoint
u, err := url.Parse(n.Endpoint)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse: %s", err)
log.Error().Err(err).Str("url", n.Endpoint).Msg("failed to parse url")
continue
}
ips, err := net.LookupIP(u.Hostname())
if err != nil {
return nil, err
log.Error().Err(err).Str("url", n.Endpoint).Msg("failed to lookup ip")
continue
}

for _, ip := range ips {
Expand Down
3 changes: 1 addition & 2 deletions pkg/network/yggdrasil/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package yggdrasil
import (
"context"
"crypto/ed25519"
"fmt"
"time"

"github.com/cenkalti/backoff"
Expand Down Expand Up @@ -59,7 +58,7 @@ func EnsureYggdrasil(ctx context.Context, privateKey ed25519.PrivateKey, ns Yggd

cfg := GenerateConfig(privateKey)
if err := cfg.FindPeers(ctx, filter); err != nil {
return nil, fmt.Errorf("cannot find public yggdrasil peer to connect to")
return nil, err
}

server := NewYggServer(&cfg)
Expand Down

0 comments on commit 2645ca7

Please sign in to comment.