diff options
-rw-r--r-- | src/main.cpp | 18 | ||||
-rw-r--r-- | test/discovery.test | 16 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index d403d29..84dfe2a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -229,6 +229,23 @@ void watchSharedIdentity(const vector<string> &) }); } +void updateLocalIdentity(const vector<string> & params) +{ + if (params.size() != 1) { + throw invalid_argument("usage: update-local-identity <name>"); + } + + auto nh = h->update([¶ms] (const Stored<LocalState> & loc) { + auto st = loc.ref().storage(); + + auto b = loc->identity()->modify(); + b.name(params[0]); + return st.store(loc->identity(b.commit())); + }); + if (nh) + *h = *nh; +} + void updateSharedIdentity(const vector<string> & params) { if (params.size() != 1) { @@ -270,6 +287,7 @@ vector<Command> commands = { { "stop-server", stopServer }, { "watch-local-identity", watchLocalIdentity }, { "watch-shared-identity", watchSharedIdentity }, + { "update-local-identity", updateLocalIdentity }, { "update-shared-identity", updateSharedIdentity }, { "attach-to", attachTo }, { "attach-accept", attachAccept }, diff --git a/test/discovery.test b/test/discovery.test index 60db1dc..b477dc0 100644 --- a/test/discovery.test +++ b/test/discovery.test @@ -1,7 +1,7 @@ test: spawn on node1 as p1 spawn on node2 as p2 - send "create-identity Device1" to p1 + send "create-identity Device1 Owner" to p1 send "create-identity Device2" to p2 send "start-server" to p1 send "start-server" to p2 @@ -10,4 +10,16 @@ test: /peer 1 id Device2/ expect from p2: /peer 1 addr 192.168.0.11 29665/ - /peer 1 id Device1/ + /peer 1 id Device1 Owner/ + + send "update-local-identity Device1A" to p1 + expect /peer 1 id Device1A Owner/ from p2 + + send "update-shared-identity OwnerA" to p1 + expect /peer 1 id Device1A OwnerA/ from p2 + + send "update-local-identity Device1B" to p1 + expect /peer 1 id Device1B OwnerA/ from p2 + + send "update-shared-identity OwnerB" to p1 + expect /peer 1 id Device1B OwnerB/ from p2 |