Skip to content

Commit

Permalink
feat: add field trustedPeersPath to the config
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Ramon Mañes <jose@celestia.org>
  • Loading branch information
tty47 committed Jun 23, 2023
1 parent 5735ce8 commit 6ed411b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type MutualPeersConfig struct {
// MutualPeer represents a mutual peer structure.
type MutualPeer struct {
// List of peers.
Peers []Peer `yaml:"peers"`
Peers []Peer `yaml:"peers"`
TrustedPeersPath string `yaml:"trustedPeersPath"` // New field
}

// Peer represents a peer structure.
Expand Down
3 changes: 2 additions & 1 deletion deployment/overlays/local/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ mutualPeers:
- nodeName: "da-bridge-1-0"
containerName: "da"
- nodeName: "da-full-1-0"
containerName: "da"
containerName: "da"
trustedPeersPath: "/home/celestia/config"
3 changes: 2 additions & 1 deletion deployment/overlays/robusta-torch-1/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ mutualPeers:
- nodeName: "da-bridge-1-0"
containerName: "da"
- nodeName: "da-full-1-0"
containerName: "da"
containerName: "da"
trustedPeersPath: "/home/celestia/config"
19 changes: 16 additions & 3 deletions pkg/k8s/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ package k8s

import (
"fmt"

"github.com/jrmanes/torch/config"
)

var (
trustedPeerFile = "/tmp/TP-ADDR"
//trustedPeers = "/home/celestia/config/"
trustedPeerFile = "/tmp/TP-ADDR"
trustedPeers = "/tmp/"
trusteedPeerPrefix = "/dns/$(hostname)/tcp/2121/p2p/"
)

func GetTrustedPeersPath(cfg config.MutualPeer) string {
// if not defined in the config, return the default value
if cfg.TrustedPeersPath == "" {
return trustedPeers
}

return cfg.TrustedPeersPath
}

// GetTrustedPeerCommand generates the command for retrieving trusted peer information.
func GetTrustedPeerCommand() []string {
script := fmt.Sprintf(`#!/bin/sh
Expand Down Expand Up @@ -54,7 +64,10 @@ fi`, trustedPeerFile, trusteedPeerPrefix)
}

// BulkTrustedPeerCommand generates the peers content in the files
func BulkTrustedPeerCommand(tp string) []string {
func BulkTrustedPeerCommand(tp string, cfg config.MutualPeer) []string {
// Get the path to write
trustedPeers = GetTrustedPeersPath(cfg)

script := fmt.Sprintf(`#!/bin/sh
# create the folder if doesnt exists
mkdir -p "%[3]s"
Expand Down
3 changes: 2 additions & 1 deletion pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ func BulkTrustedPeers(cfg config.MutualPeersConfig, pods config.MutualPeer) {
for _, pod := range pods.Peers {
if key != pod.NodeName {
log.Info("this is a different one: ", data[key], " ", pod.NodeName)
command := BulkTrustedPeerCommand(data[key])
// send the data + the config to generate the path
command := BulkTrustedPeerCommand(data[key], pods)
output, err := RunRemoteCommand(
pod.NodeName,
pod.ContainerName,
Expand Down

0 comments on commit 6ed411b

Please sign in to comment.