Use user's default identity as the initial identity
Change-Id: I89c35f817c863dabb9d4570b6b128092362a41a4
Refs: #2487
diff --git a/src/controller.cpp b/src/controller.cpp
index dd2392c..b45e1dd 100644
--- a/src/controller.cpp
+++ b/src/controller.cpp
@@ -311,15 +311,9 @@
std::ifstream is((chronosDir / "config").c_str ());
Conf conf;
- bool hasConfig = true;
Block confBlock;
try {
confBlock = ndn::Block::fromStream(is);
- }
- catch (tlv::Error) {
- hasConfig = false;
- }
- if (hasConfig) {
conf.wireDecode(confBlock);
m_identity.clear();
m_identity.append(conf.getIdentity());
@@ -328,12 +322,16 @@
else
m_nick = m_identity.get(-1).toUri();
}
- else {
- m_identity.clear();
- // TODO: change below to system default;
- m_identity.append("chronochat-tmp-identity")
- .append(getRandomString());
-
+ catch (tlv::Error) {
+ try {
+ ndn::KeyChain keyChain;
+ m_identity = keyChain.getDefaultIdentity();
+ }
+ catch (ndn::KeyChain::Error) {
+ m_identity.clear();
+ m_identity.append("chronochat-tmp-identity")
+ .append(getRandomString());
+ }
m_nick = m_identity.get(-1).toUri();
}
}