summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-07 16:41:56 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-07 16:41:56 -0700
commit9e55f882d3ca5a5615c21ebaec0702aaaf436e2b (patch)
treef9a62121f1ef2d0a458812eb2c60b8e00c006fb5
parent8210ed480553a5e98268da7147ce332d1f7643d0 (diff)
downloadinfinitytier-9e55f882d3ca5a5615c21ebaec0702aaaf436e2b.tar.gz
infinitytier-9e55f882d3ca5a5615c21ebaec0702aaaf436e2b.zip
Starting to port from old Node() -- identity generation.
-rw-r--r--include/ZeroTierOne.h2
-rw-r--r--node/Node.cpp27
-rw-r--r--node/Node.hpp2
3 files changed, 24 insertions, 7 deletions
diff --git a/include/ZeroTierOne.h b/include/ZeroTierOne.h
index e787f7f1..a893aed3 100644
--- a/include/ZeroTierOne.h
+++ b/include/ZeroTierOne.h
@@ -755,7 +755,7 @@ enum ZT1_ResultCode ZT1_Node_processVirtualNetworkFrame(
* @param nextCallDeadline Result: set to deadline for next call to one of the three processXXX() methods
* @return OK (0) or error code if a fatal error condition has occurred
*/
-enum ZT1_ResultCode ZT1_Node_processNothing(ZT1_Node *node,uint64_t now,uint64_t *nextCallDeadline);
+enum ZT1_ResultCode ZT1_Node_processBackgroundTasks(ZT1_Node *node,uint64_t now,uint64_t *nextCallDeadline);
/**
* Join a network
diff --git a/node/Node.cpp b/node/Node.cpp
index 39132302..33ed82dc 100644
--- a/node/Node.cpp
+++ b/node/Node.cpp
@@ -72,6 +72,21 @@ Node::Node(
_newestVersionSeen[1] = ZEROTIER_ONE_VERSION_MINOR;
_newestVersionSeen[2] = ZEROTIER_ONE_VERSION_REVISION;
+ std::string idtmp(dataStoreGet("identity.secret"));
+ if ((!idtmp.length())||(!RR->identity.fromString(idtmp))||(!RR->identity.hasPrivate())) {
+ RR->identity.generate();
+ idtmp = RR->identity.toString(true);
+ if (!dataStorePut("identity.secret",idtmp,true)) {
+ delete RR;
+ throw std::runtime_error("unable to write identity.secret");
+ }
+ idtmp = RR->identity.toString(false);
+ if (!dataStorePut("identity.public",idtmp,false)) {
+ delete RR;
+ throw std::runtime_error("unable to write identity.public");
+ }
+ }
+
try {
RR->prng = new CMWC4096();
RR->sw = new Switch(RR);
@@ -90,6 +105,8 @@ Node::Node(
delete RR;
throw;
}
+
+ postEvent(ZT1_EVENT_UP);
}
Node::~Node()
@@ -112,7 +129,7 @@ ZT1_ResultCode Node::processWirePacket(
unsigned int packetLength,
uint64_t *nextCallDeadline)
{
- _now = now;
+ processBackgroundTasks(now,nextCallDeadline);
}
ZT1_ResultCode Node::processVirtualNetworkFrame(
@@ -126,10 +143,10 @@ ZT1_ResultCode Node::processVirtualNetworkFrame(
unsigned int frameLength,
uint64_t *nextCallDeadline)
{
- _now = now;
+ processBackgroundTasks(now,nextCallDeadline);
}
-ZT1_ResultCode Node::processNothing(uint64_t now,uint64_t *nextCallDeadline)
+ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,uint64_t *nextCallDeadline)
{
_now = now;
}
@@ -309,10 +326,10 @@ enum ZT1_ResultCode ZT1_Node_processVirtualNetworkFrame(
}
}
-enum ZT1_ResultCode ZT1_Node_processNothing(ZT1_Node *node,uint64_t now,uint64_t *nextCallDeadline)
+enum ZT1_ResultCode ZT1_Node_processBackgroundTasks(ZT1_Node *node,uint64_t now,uint64_t *nextCallDeadline)
{
try {
- return reinterpret_cast<ZeroTier::Node *>(node)->processNothing(now,nextCallDeadline);
+ return reinterpret_cast<ZeroTier::Node *>(node)->processBackgroundTasks(now,nextCallDeadline);
} catch (std::bad_alloc &exc) {
return ZT1_RESULT_FATAL_ERROR_OUT_OF_MEMORY;
} catch ( ... ) {
diff --git a/node/Node.hpp b/node/Node.hpp
index 3f6bbc46..d6be609e 100644
--- a/node/Node.hpp
+++ b/node/Node.hpp
@@ -85,7 +85,7 @@ public:
const void *frameData,
unsigned int frameLength,
uint64_t *nextCallDeadline);
- ZT1_ResultCode processNothing(uint64_t now,uint64_t *nextCallDeadline);
+ ZT1_ResultCode processBackgroundTasks(uint64_t now,uint64_t *nextCallDeadline);
ZT1_ResultCode join(uint64_t nwid);
ZT1_ResultCode leave(uint64_t nwid);
ZT1_ResultCode multicastSubscribe(uint64_t nwid,uint64_t multicastGroup,unsigned long multicastAdi);