// Returns a NodeDB ID that matches the specified criteria. static int nodedbGetDBID(struct s_nodedb *db, struct s_nodeid *nodeid, const int max_lastseen, const int max_lastconnect, const int min_lastconntry) { int i, i_max, nid, tnow, ret; tnow = utilGetClock(); i_max = mapGetKeyCount(db->addrdb); ret = -1; if(nodeid == NULL) { // find DBID for any NodeID i = 0; while((i < i_max) && (ret < 0)) { nid = mapGetNextKeyID(db->addrdb); ret = nodedbGetDBIDByID(db, nid, tnow, max_lastseen, max_lastconnect, min_lastconntry); i++; } } else { // find DBID for specified NodeID nid = mapGetKeyID(db->addrdb, nodeid->id); if(!(nid < 0)) { ret = nodedbGetDBIDByID(db, nid, tnow, max_lastseen, max_lastconnect, min_lastconntry); } } return ret; }
// Get PeerID of NodeID. Returns -1 if it is not found. static int peermgtGetID(struct s_peermgt *mgt, const struct s_nodeid *nodeid) { return mapGetKeyID(&mgt->map, nodeid->id); }