Skip to content

Commit 18beff8

Browse files
committed
(fix) #102: allow to specify peers.json in mpcium-cli
1 parent fbcb3bb commit 18beff8

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

cmd/mpcium-cli/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ func main() {
5151
Action: registerPeers,
5252
Flags: []cli.Flag{
5353
&cli.StringFlag{
54-
Name: "input",
55-
Aliases: []string{"i"},
56-
Usage: "Input peers JSON file path (default: peers.json)",
57-
Value: peersFileName,
54+
Name: "peers",
55+
Aliases: []string{"p"},
56+
Usage: "Path to peers.json file",
57+
Required: true,
5858
},
5959
&cli.StringFlag{
6060
Name: "environment",

cmd/mpcium-cli/register-peers.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func registerPeers(ctx context.Context, c *cli.Command) error {
18-
inputPath := c.String("input")
18+
inputPath := c.String("peers")
1919
environment := c.String("environment")
2020

2121
// Hardcoded prefix for MPC peers in Consul
@@ -58,10 +58,26 @@ func registerPeers(ctx context.Context, c *cli.Command) error {
5858
// Register peers in Consul
5959
for nodeName, nodeID := range peerMap {
6060
key := prefix + nodeName
61+
62+
// Check if the key already exists
63+
existing, _, err := kv.Get(key, nil)
64+
if err != nil {
65+
return fmt.Errorf("failed to check existing key %s: %w", key, err)
66+
}
67+
68+
if existing != nil {
69+
existingID := string(existing.Value)
70+
if existingID != nodeID {
71+
return fmt.Errorf("conflict detected: peer %s already exists with ID %s, but trying to register with different ID %s", nodeName, existingID, nodeID)
72+
}
73+
fmt.Printf("Peer %s already registered with same ID %s, skipping\n", nodeName, nodeID)
74+
continue
75+
}
76+
6177
p := &api.KVPair{Key: key, Value: []byte(nodeID)}
6278

6379
// Store the key-value pair
64-
_, err := kv.Put(p, nil)
80+
_, err = kv.Put(p, nil)
6581
if err != nil {
6682
return fmt.Errorf("failed to store key %s: %w", key, err)
6783
}

0 commit comments

Comments
 (0)