From f5c7956c94b5b23cb29ffc36012385bedc386aa6 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Wed, 29 Jan 2025 07:12:22 +0200 Subject: [PATCH] make RPC new-host new-node also highlight the ID of created host/node, as well fix bugs in these RPC calls --- main.go | 6 +++++- node/lux_node.go | 6 ++++-- rpc/lux_rpc_data.go | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index a64ccad..b84a1d2 100644 --- a/main.go +++ b/main.go @@ -710,6 +710,8 @@ func rpcMain() { if err != nil { fmt.Fprintf(os.Stderr, "failed to save host keystore: %v\n", err) } + + fmt.Printf("New host ID: %s\n", rpcRes.NewHostID) } if rpcNewNode != "" { @@ -741,10 +743,12 @@ func rpcMain() { } // deserialize keystore - _, err = crypto.LuxKeyStoreFromRpc(rpcRes.Keystore, rpcNewHost) + _, err = crypto.LuxKeyStoreFromRpc(rpcRes.Keystore, rpcNewNode) if err != nil { fmt.Fprintf(os.Stderr, "failed to save node keystore: %v\n", err) } + + fmt.Printf("New neighbor node ID: %s\n", rpcRes.NewNodeID) } if rpcQueryHost != "" || rpcQueryHostname != "" { diff --git a/node/lux_node.go b/node/lux_node.go index 7d15d83..66ca33d 100644 --- a/node/lux_node.go +++ b/node/lux_node.go @@ -343,7 +343,8 @@ func (node *LuxNode) Handle(request rpc.LuxRpcRequest, rpcType rpc.LuxRpcType) ( ksHost.Put(host) return rpc.LuxRpcResponse{ - Keystore: crypto.LuxKeyStoreIntoRpc(&ksHost), + Keystore: crypto.LuxKeyStoreIntoRpc(&ksHost), + NewHostID: host.Id.String(), }, rpc.LuxRpcError{}, true } else if request.Command == "new-node" { if rpcType != rpc.LuxRpcTypeRoot { @@ -364,7 +365,8 @@ func (node *LuxNode) Handle(request rpc.LuxRpcRequest, rpcType rpc.LuxRpcType) ( // yeah we just serialize our own keystore return rpc.LuxRpcResponse{ - Keystore: crypto.LuxKeyStoreIntoRpc(ks), + Keystore: crypto.LuxKeyStoreIntoRpc(ks), + NewNodeID: newNode.Id.String(), }, rpc.LuxRpcError{}, true } else if request.Command == "query" { // now we get host states either by ID or hostname diff --git a/rpc/lux_rpc_data.go b/rpc/lux_rpc_data.go index 3c94f47..5bcf2ae 100644 --- a/rpc/lux_rpc_data.go +++ b/rpc/lux_rpc_data.go @@ -119,6 +119,9 @@ type LuxRpcResponse struct { Keystore LuxRpcKeyStore `xml:"keystore"` Routes []LuxRpcRoute `xml:"route"` Hosts []LuxRpcHost `xml:"host"` + + NewHostID string `xml:"newHostId"` + NewNodeID string `xml:"newNodeId"` } type LuxRpcError struct {