From 430882327e477d419f8b6485361c22e1e2844d32 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 7 Oct 2013 15:00:38 -0400 Subject: [PATCH] Couple of small fixes, works again with new ID code. --- node/Identity.cpp | 32 ++++++++++++++++---------------- node/Node.cpp | 4 +++- node/NodeConfig.cpp | 8 +++++--- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/node/Identity.cpp b/node/Identity.cpp index e0d5afd7c..0ea3dc188 100644 --- a/node/Identity.cpp +++ b/node/Identity.cpp @@ -90,26 +90,26 @@ static inline void _computeMemoryHardHash(const void *publicKey,unsigned int pub struct _Identity_generate_cond { _Identity_generate_cond() throw() {} - _Identity_generate_cond(unsigned char *sb,char *gm) throw() : sha512digest(sb),genmem(gm) {} + _Identity_generate_cond(unsigned char *sb,char *gm) throw() : digest(sb),genmem(gm) {} inline bool operator()(const C25519::Pair &kp) const throw() { - _computeMemoryHardHash(kp.pub.data,kp.pub.size(),sha512digest,genmem); - return (sha512digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN); + _computeMemoryHardHash(kp.pub.data,kp.pub.size(),digest,genmem); + return (digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN); } - unsigned char *sha512digest; + unsigned char *digest; char *genmem; }; void Identity::generate() { - unsigned char sha512digest[64]; + unsigned char digest[64]; char *genmem = new char[ZT_IDENTITY_GEN_MEMORY]; C25519::Pair kp; do { - kp = C25519::generateSatisfying(_Identity_generate_cond(sha512digest,genmem)); - _address.setTo(sha512digest + 59,ZT_ADDRESS_LENGTH); // last 5 bytes are address + kp = C25519::generateSatisfying(_Identity_generate_cond(digest,genmem)); + _address.setTo(digest + 59,ZT_ADDRESS_LENGTH); // last 5 bytes are address } while (_address.isReserved()); _publicKey = kp.pub; @@ -125,21 +125,21 @@ bool Identity::locallyValidate() const if (_address.isReserved()) return false; - unsigned char sha512digest[64]; + unsigned char digest[64]; char *genmem = new char[ZT_IDENTITY_GEN_MEMORY]; - _computeMemoryHardHash(_publicKey.data,_publicKey.size(),sha512digest,genmem); + _computeMemoryHardHash(_publicKey.data,_publicKey.size(),digest,genmem); delete [] genmem; unsigned char addrb[5]; _address.copyTo(addrb,5); return ( - (sha512digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN)&& - (sha512digest[59] == addrb[0])&& - (sha512digest[60] == addrb[1])&& - (sha512digest[61] == addrb[2])&& - (sha512digest[62] == addrb[3])&& - (sha512digest[63] == addrb[4])); + (digest[0] < ZT_IDENTITY_GEN_HASHCASH_FIRST_BYTE_LESS_THAN)&& + (digest[59] == addrb[0])&& + (digest[60] == addrb[1])&& + (digest[61] == addrb[2])&& + (digest[62] == addrb[3])&& + (digest[63] == addrb[4])); } std::string Identity::toString(bool includePrivate) const @@ -176,7 +176,7 @@ bool Identity::fromString(const char *str) return false; break; case 1: - if (f[0] != '0') + if ((f[0] != '0')||(f[1])) return false; break; case 2: diff --git a/node/Node.cpp b/node/Node.cpp index 740bc89e6..1efbf7b5a 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -323,6 +323,8 @@ Node::ReasonForTermination Node::run() std::string idser; if (Utils::readFile(identitySecretPath.c_str(),idser)) gotId = _r->identity.fromString(idser); + if ((gotId)&&(!_r->identity.locallyValidate())) + gotId = false; if (gotId) { // Make sure identity.public matches identity.secret idser = std::string(); @@ -419,7 +421,7 @@ Node::ReasonForTermination Node::run() // Core I/O loop try { - uint64_t lastNetworkAutoconfCheck = 0; + uint64_t lastNetworkAutoconfCheck = Utils::now() - 5000; // check autoconf again after 5s for startup uint64_t lastPingCheck = 0; uint64_t lastClean = Utils::now(); // don't need to do this immediately uint64_t lastNetworkFingerprintCheck = 0; diff --git a/node/NodeConfig.cpp b/node/NodeConfig.cpp index 4c9f284f2..5f593b4d6 100644 --- a/node/NodeConfig.cpp +++ b/node/NodeConfig.cpp @@ -78,13 +78,15 @@ NodeConfig::NodeConfig(const RuntimeEnvironment *renv,const char *authToken,unsi if (dot != std::string::npos) { uint64_t nwid = strtoull(d->first.substr(0,dot).c_str(),(char **)0,16); - // TODO: remove legacy code -- this changes the network - // ID for Earth if it's subscribed. Also deletes old - // config file. New one will be created. + // TODO: remove legacy code once out of beta if (nwid == 0x6c92786fee000001ULL) { nwid = 0xbc8f9a8ee3000001ULL; Utils::rm((networksFolder + ZT_PATH_SEPARATOR_S + d->first).c_str()); } + if (nwid == 0xbc8f9a8ee3000001ULL) { + nwid = 0x8D93FBE886000001ULL; + Utils::rm((networksFolder + ZT_PATH_SEPARATOR_S + d->first).c_str()); + } if (nwid > 0) nwids.insert(nwid);