Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding trusted visors from config on startup #392

Merged
merged 5 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/transport/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import (
"github.com/SkycoinProject/skywire-mainnet/pkg/snet/snettest"
)

const (
// TrustedVisorsDelay defines a delay before adding transports to trusted visors.
TrustedVisorsDelay = 5 * time.Second
)

// ManagerConfig configures a Manager.
type ManagerConfig struct {
PubKey cipher.PubKey
Expand Down Expand Up @@ -282,8 +287,6 @@ func isSTCPTableError(remotePK cipher.PubKey, err error) bool {
return err.Error() == fmt.Sprintf("pk table: entry of %s does not exist", remotePK.String())
}

var ()

func (tm *Manager) saveTransport(remote cipher.PubKey, netName string) (*ManagedTransport, error) {
if !snet.IsKnownNetwork(netName) {
return nil, snet.ErrUnknownNetwork
Expand Down
28 changes: 28 additions & 0 deletions pkg/visor/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/SkycoinProject/skywire-mainnet/pkg/skyenv"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet/arclient"
"github.com/SkycoinProject/skywire-mainnet/pkg/snet/directtp/tptypes"
"github.com/SkycoinProject/skywire-mainnet/pkg/transport"
"github.com/SkycoinProject/skywire-mainnet/pkg/transport/tpdclient"
"github.com/SkycoinProject/skywire-mainnet/pkg/util/updater"
Expand All @@ -47,6 +48,7 @@ func initStack() []initFunc {
initCLI,
initHypervisors,
initUptimeTracker,
initTrustedVisors,
}
}

Expand Down Expand Up @@ -454,6 +456,32 @@ func initUptimeTracker(v *Visor) bool {
return true
}

func initTrustedVisors(v *Visor) bool {
const trustedVisorsTransportType = tptypes.STCPR

go func() {
time.Sleep(transport.TrustedVisorsDelay)
for _, pk := range v.tpM.Conf.DefaultVisors {
v.log.WithField("pk", pk).Infof("Adding trusted visor")

if _, err := v.tpM.SaveTransport(context.Background(), pk, trustedVisorsTransportType); err != nil {
v.log.
WithError(err).
WithField("pk", pk).
WithField("type", trustedVisorsTransportType).
Warnf("Failed to add transport to trusted visor via")
} else {
v.log.
WithField("pk", pk).
WithField("type", trustedVisorsTransportType).
Infof("Added transport to trusted visor")
}
}
}()

return true
}

func connectToTpDisc(v *Visor) (transport.DiscoveryClient, error) {
const (
initBO = 1 * time.Second
Expand Down
3 changes: 0 additions & 3 deletions pkg/visor/visor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ const (
supportedProtocolVersion = "0.1.0"
ownerRWX = 0700
shortHashLen = 6
)

const (
// moduleShutdownTimeout is the timeout given to a module to shutdown cleanly.
// Otherwise the shutdown logic will continue and report a timeout error.
moduleShutdownTimeout = time.Second * 2
Expand Down