uint32_t lastutxos,lastinfo;

This commit is contained in:
jl777
2019-07-02 05:49:14 -11:00
parent 49a7008f95
commit e9a2714441
3 changed files with 9 additions and 33 deletions

View File

@@ -26,9 +26,6 @@
#define NSPV_UTXOS 0x02 #define NSPV_UTXOS 0x02
#define NSPV_UTXOSRESP 0x03 #define NSPV_UTXOSRESP 0x03
uint32_t CNode_lastinfo(CNode *pnode,uint32_t lastutxos);
uint32_t CNode_lastutxos(CNode *pnode,uint32_t lastutxos);
uint32_t NSPV_lastinfo,NSPV_lastutxos; uint32_t NSPV_lastinfo,NSPV_lastutxos;
void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a request void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a request
@@ -39,19 +36,19 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a req
response.resize(1); response.resize(1);
if ( len == 1 && request[0] == NSPV_INFO ) // info if ( len == 1 && request[0] == NSPV_INFO ) // info
{ {
if ( timestamp > CNode_lastinfo(pfrom,0) + ASSETCHAINS_BLOCKTIME/2 ) if ( timestamp > pfrom->lastinfo + ASSETCHAINS_BLOCKTIME/2 )
{ {
response[0] = NSPV_INFORESP; response[0] = NSPV_INFORESP;
CNode_lastinfo(pfrom,timestamp); pfrom->lastinfo = timestamp;
pfrom->PushMessage("nSPV",response); pfrom->PushMessage("nSPV",response);
} }
} }
else if ( request[0] == NSPV_UTXOS ) else if ( request[0] == NSPV_UTXOS )
{ {
if ( timestamp > CNode_lastutxos(pfrom,0) + ASSETCHAINS_BLOCKTIME/2 ) if ( timestamp > pfrom->lastutxos + ASSETCHAINS_BLOCKTIME/2 )
{ {
response[0] = NSPV_UTXOSRESP; response[0] = NSPV_UTXOSRESP;
CNode_lastutxos(pfrom,timestamp); pfrom->lastutxos = timestamp;
pfrom->PushMessage("nSPV",response); pfrom->PushMessage("nSPV",response);
} }
} }
@@ -83,29 +80,27 @@ void komodo_nSPV(CNode *pto)
// limit frequency! // limit frequency!
if ( timestamp > NSPV_lastutxos + ASSETCHAINS_BLOCKTIME/2 ) if ( timestamp > NSPV_lastutxos + ASSETCHAINS_BLOCKTIME/2 )
{ {
if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > CNode_lastutxos(pto,0) + ASSETCHAINS_BLOCKTIME ) if ( (pto->nServices & NODE_ADDRINDEX) != 0 && timestamp > ptr->lastutxos + ASSETCHAINS_BLOCKTIME )
{ {
// get utxo since lastheight // get utxo since lastheight
if ( (rand() % 100) < 10 ) if ( (rand() % 100) < 10 )
{ {
request.resize(1); request.resize(1);
request[0] = NSPV_UTXOS; request[0] = NSPV_UTXOS;
NSPV_lastutxos = timestamp; NSPV_lastutxos = pto->lastutxos = timestamp;
CNode_lastutxos(pto,NSPV_lastutxos);
pto->PushMessage("getnSPV",request); pto->PushMessage("getnSPV",request);
return; return;
} }
} }
} }
if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > CNode_lastinfo(pto,0) + ASSETCHAINS_BLOCKTIME ) if ( timestamp > NSPV_lastinfo + ASSETCHAINS_BLOCKTIME/2 && timestamp > ptr->lastinfo + ASSETCHAINS_BLOCKTIME )
{ {
if ( (rand() % 100) < 10 ) if ( (rand() % 100) < 10 )
{ {
// query current height, blockhash, notarization info // query current height, blockhash, notarization info
request.resize(1); request.resize(1);
request[0] = NSPV_INFO; request[0] = NSPV_INFO;
NSPV_lastinfo = timestamp; NSPV_lastinfo = pto->lastinfo = timestamp;
CNode_lastinfo(pto,NSPV_lastinfo);
pto->PushMessage("getnSPV",request); pto->PushMessage("getnSPV",request);
} }
} }

View File

@@ -682,25 +682,6 @@ int CNetMessage::readData(const char *pch, unsigned int nBytes)
uint32_t CNode_lastutxos(CNode *pnode,uint32_t lastutxos)
{
uint32_t prev = pnode->lastutxos;
if ( lastutxos != 0 )
pnode->lastutxos = lastutxos;
return(prev);
}
uint32_t CNode_lastinfo(CNode *pnode,uint32_t lastinfo)
{
uint32_t prev = pnode->lastinfo;
if ( lastinfo != 0 )
pnode->lastinfo = lastinfo;
return(prev);
}
// requires LOCK(cs_vSend) // requires LOCK(cs_vSend)
void SocketSendData(CNode *pnode) void SocketSendData(CNode *pnode)
{ {

View File

@@ -204,7 +204,6 @@ public:
bool fWhitelisted; bool fWhitelisted;
double dPingTime; double dPingTime;
double dPingWait; double dPingWait;
uint32_t lastutxos,lastinfo;
std::string addrLocal; std::string addrLocal;
}; };
@@ -277,6 +276,7 @@ public:
int64_t nLastRecv; int64_t nLastRecv;
int64_t nTimeConnected; int64_t nTimeConnected;
int64_t nTimeOffset; int64_t nTimeOffset;
uint32_t lastutxos,lastinfo;
CAddress addr; CAddress addr;
std::string addrName; std::string addrName;
CService addrLocal; CService addrLocal;