Starting to port from old Node() -- identity generation.

This commit is contained in:
Adam Ierymenko 2015-04-07 16:41:56 -07:00
parent 8210ed4805
commit 9e55f882d3
3 changed files with 24 additions and 7 deletions

View File

@ -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

View File

@ -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 ( ... ) {

View File

@ -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);