summaryrefslogtreecommitdiff
path: root/root-topology
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-30 15:31:01 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-30 15:31:01 -0700
commit918fc8884b142452e350ff32beb90b34bbd442c1 (patch)
treea7003759c968fb5b813ae4b04768055148440f3a /root-topology
parentf3d7c9d681d6badff866c31041ba81e6fc2a882b (diff)
downloadinfinitytier-918fc8884b142452e350ff32beb90b34bbd442c1.tar.gz
infinitytier-918fc8884b142452e350ff32beb90b34bbd442c1.zip
Update mktopology so it works again and can easily be used to create test dictionaries.
Diffstat (limited to 'root-topology')
-rw-r--r--root-topology/Makefile2
-rw-r--r--root-topology/mktopology.cpp47
2 files changed, 25 insertions, 24 deletions
diff --git a/root-topology/Makefile b/root-topology/Makefile
index 58226fd0..3ddd916f 100644
--- a/root-topology/Makefile
+++ b/root-topology/Makefile
@@ -1,5 +1,5 @@
all: FORCE
- g++ -o mktopology mktopology.cpp ../node/Utils.cpp ../node/Identity.cpp ../node/C25519.cpp ../node/Salsa20.cpp ../node/Dictionary.cpp ../node/SHA512.cpp
+ g++ -o mktopology mktopology.cpp ../osdep/OSUtils.cpp ../node/Utils.cpp ../node/InetAddress.cpp ../node/Identity.cpp ../node/C25519.cpp ../node/Salsa20.cpp ../node/Dictionary.cpp ../node/SHA512.cpp
gcc -o bin2c bin2c.c
official: FORCE
diff --git a/root-topology/mktopology.cpp b/root-topology/mktopology.cpp
index 2a551cf7..00ada7b7 100644
--- a/root-topology/mktopology.cpp
+++ b/root-topology/mktopology.cpp
@@ -6,7 +6,7 @@
#include <iostream>
#include <map>
-#include "../node/Utils.hpp"
+#include "../osdep/OSUtils.hpp"
#include "../node/Identity.hpp"
#include "../node/Dictionary.hpp"
@@ -17,47 +17,48 @@ int main(int argc,char **argv)
std::string buf;
// Read root-topology-authority.secret signing authority, must be symlinked and online
- if (!Utils::readFile("root-topology-authority.secret",buf)) {
- std::cerr << "Cannot read root-topology-authority.secret" << std::endl;
- return 1;
- }
- Identity topologyAuthority(buf);
+ Identity topologyAuthority;
+ if (OSUtils::readFile("root-topology-authority.secret",buf))
+ topologyAuthority.fromString(buf);
+ else std::cerr << "Warning: root-topology-authority.secret not found, creating unsigned topology." << std::endl;
Dictionary topology;
// Read template.dict to populate default fields in root topology
// if this file exists. Otherwise we just start empty.
buf.clear();
- if (Utils::readFile("template.dict",buf))
+ if (OSUtils::readFile("template.dict",buf))
topology.fromString(buf);
// Read all entries in supernodes/ that correspond to supernode entry dictionaries
// and add them to topology under supernodes/ subkey.
Dictionary supernodes;
- std::map<std::string,bool> supernodeDictionaries(Utils::listDirectory("supernodes"));
- for(std::map<std::string,bool>::iterator sn(supernodeDictionaries.begin());sn!=supernodeDictionaries.end();++sn) {
- if ((sn->first.length() == 10)&&(!sn->second)) {
+ std::vector<std::string> supernodeDictionaries(OSUtils::listDirectory("supernodes"));
+ for(std::vector<std::string>::const_iterator sn(supernodeDictionaries.begin());sn!=supernodeDictionaries.end();++sn) {
+ if (sn->length() == 10) {
buf.clear();
- if (!Utils::readFile((std::string("supernodes/")+sn->first).c_str(),buf)) {
- std::cerr << "Cannot read supernodes/" << sn->first << std::endl;
+ if (!OSUtils::readFile((std::string("supernodes/")+(*sn)).c_str(),buf)) {
+ std::cerr << "Cannot read supernodes/" << *sn << std::endl;
return 1;
}
- supernodes[sn->first] = buf;
+ supernodes[*sn] = buf;
}
}
topology["supernodes"] = supernodes.toString();
- // Sign topology with root-topology-authority.secret
- if (!topology.sign(topologyAuthority)) {
- std::cerr << "Unable to sign!" << std::endl;
- return 1;
- }
+ if ((topologyAuthority)&&(topologyAuthority.hasPrivate())) {
+ // Sign topology with root-topology-authority.secret
+ if (!topology.sign(topologyAuthority,OSUtils::now())) {
+ std::cerr << "Unable to sign!" << std::endl;
+ return 1;
+ }
- // Test signature to make sure signing worked
- Dictionary test(topology.toString());
- if (!test.verify(topologyAuthority)) {
- std::cerr << "Test verification of signed dictionary failed!" << std::endl;
- return 1;
+ // Test signature to make sure signing worked
+ Dictionary test(topology.toString());
+ if (!test.verify(topologyAuthority)) {
+ std::cerr << "Test verification of signed dictionary failed!" << std::endl;
+ return 1;
+ }
}
// Output to stdout