int p2psecStart(P2PSEC_CTX *p2psec) { if((!p2psec->started) && (p2psec->key_loaded) && (p2psec->dh_loaded)) { if(peermgtCreate(&p2psec->mgt, p2psec->peer_count, p2psec->auth_count, &p2psec->nk, &p2psec->dh)) { peermgtSetLoopback(&p2psec->mgt, p2psec->loopback_enable); peermgtSetFastauth(&p2psec->mgt, p2psec->fastauth_enable); peermgtSetFragmentation(&p2psec->mgt, p2psec->fragmentation_enable); peermgtSetNetID(&p2psec->mgt, p2psec->netname, p2psec->netname_len); peermgtSetPassword(&p2psec->mgt, p2psec->password, p2psec->password_len); peermgtSetFlags(&p2psec->mgt, p2psec->flags); p2psec->started = 1; return 1; } } return 0; }
void p2psecSetPassword(P2PSEC_CTX *p2psec, const char *password, const int password_len) { int len; if(password_len < 1024) { len = password_len; } else { len = 1023; } memset(p2psec->password, 0, 1024); if(len > 0) { memcpy(p2psec->password, password, len); p2psec->password_len = len; } else { memcpy(p2psec->password, "default", 7); p2psec->password_len = 7; } if(p2psec->started) peermgtSetPassword(&p2psec->mgt, p2psec->password, p2psec->password_len); }
// Initialize peer manager object. static int peermgtInit(struct s_peermgt *mgt) { const char *defaultpw = "default"; int i; int s = mapGetMapSize(&mgt->map); struct s_peeraddr empty_addr; struct s_nodeid *local_nodeid = &mgt->nodekey->nodeid; mgt->msgsize = 0; mgt->loopback = 0; mgt->outmsg.len = 0; mgt->outmsgbroadcast = 0; mgt->outmsgbroadcastcount = 0; mgt->rrmsg.len = 0; mgt->rrmsgpeerid = 0; mgt->rrmsgusetargetaddr = 0; mgt->fragoutpeerid = 0; mgt->fragoutcount = 0; mgt->fragoutsize = 0; mgt->fragoutpos = 0; mgt->localflags = 0; for(i=0; i<s; i++) { mgt->data[i].state = peermgt_STATE_INVALID; } memset(empty_addr.addr, 0, peeraddr_SIZE); mapInit(&mgt->map); authmgtReset(&mgt->authmgt); nodedbInit(&mgt->nodedb); nodedbSetMaxAge(&mgt->nodedb, peermgt_NEWCONNECT_MAX_AGE); if(peermgtNew(mgt, local_nodeid, &empty_addr) == 0) { // ID 0 should always represent local NodeID if(peermgtGetID(mgt, local_nodeid) == 0) { if(peermgtSetNetID(mgt, defaultpw, 7) && peermgtSetPassword(mgt, defaultpw, 7)) { mgt->data[0].state = peermgt_STATE_COMPLETE; return 1; } } } return 0; }