From 0f377bfe393138bc5076a1f83e28edd485ec19eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Apr 2016 15:35:26 -0500 Subject: [PATCH] test --- deprecated/obsolete.h | 11 ++++ iguana/iguana777.h | 12 +++- iguana/iguana_accept.c | 115 ++++++++++++++++++++++++++++++++++----- iguana/iguana_init.c | 1 + iguana/iguana_msg.c | 53 +++--------------- iguana/iguana_recv.c | 20 +------ iguana/iguana_unspents.c | 10 ++-- 7 files changed, 137 insertions(+), 85 deletions(-) diff --git a/deprecated/obsolete.h b/deprecated/obsolete.h index 88c823036..321418ed6 100755 --- a/deprecated/obsolete.h +++ b/deprecated/obsolete.h @@ -16217,6 +16217,17 @@ len = 0; } } #else + //printf("call _iguana_chainlink\n"); + /*for (i=coin->blocks.hwmchain.height%coin->chain->bundlesize; ichain->bundlesize; i++) + { + if ( (bp= coin->current) != 0 && (block= bp->blocks[i]) != 0 ) + { + //printf("i.%d %s main.%d txvalid.%d\n",i,bits256_str(str,block->RO.hash2),block->mainchain,block->txvalid); + if ( _iguana_chainlink(coin,block) == 0 ) + iguana_blockQ("mainchain",coin,bp,-i,block->RO.hash2,1); + //iguana_realtime_update(coin); + } + }*/ #endif #endif diff --git a/iguana/iguana777.h b/iguana/iguana777.h index d9d1d9529..1ec235f63 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -144,6 +144,8 @@ extern int32_t IGUANA_NUMHELPERS; #define MSG_TX 1 #define MSG_BLOCK 2 #define MSG_FILTERED_BLOCK 3 +#define MSG_BUNDLE_HEADERS 255 +#define MSG_BUNDLE 254 #define IGUANA_MAXLOCATORS 64 #define IGUANA_MAXINV 50000 @@ -194,6 +196,8 @@ struct iguana_thread struct iguana_blockreq { struct queueitem DL; bits256 hash2,*blockhashes; struct iguana_bundle *bp; int32_t n,height,bundlei; }; +struct iguana_peermsgrequest { struct queueitem DL; struct iguana_peer *addr; bits256 hash2; int32_t type; }; + struct iguana_chain { //const int32_t chain_id; @@ -494,7 +498,7 @@ struct iguana_info struct iguana_bitmap screen; //struct pollfd fds[IGUANA_MAXPEERS]; struct iguana_peer bindaddr; int32_t numsocks; struct OS_memspace TXMEM,MEM,MEMB[IGUANA_MAXBUNDLESIZE]; - queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,cacheQ,recvQ; + queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,cacheQ,recvQ,msgrequestQ; double parsemillis,avetime; uint32_t Launched[8],Terminated[8]; portable_mutex_t peers_mutex,blocks_mutex; //portable_mutex_t scripts_mutex[2]; FILE *scriptsfp[2]; void *scriptsptr[2]; long scriptsfilesize[2]; @@ -881,9 +885,10 @@ int32_t iguana_alloctxbits(struct iguana_info *coin,struct iguana_ramchain *ramc void iguana_allocvolatile(struct iguana_info *coin,struct iguana_ramchain *ramchain); int32_t iguana_rwaddr(int32_t rwflag,uint8_t *serialized,struct iguana_msgaddress *addr,int32_t protover); -int32_t iguana_peerhdrrequest(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2); +int32_t iguana_peerhdrrequest(struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_peer *addr,bits256 hash2); int32_t iguana_peeraddrrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max); -int32_t iguana_peerinvrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max); +int32_t iguana_peerdatarequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max); +int32_t iguana_peergetrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *data,int32_t recvlen,int32_t getblock); int32_t iguana_bundlefname(struct iguana_info *coin,struct iguana_bundle *bp,char *fname); int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfiles); int32_t iguana_voutsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid); @@ -894,6 +899,7 @@ int32_t iguana_blast(struct iguana_info *coin,struct iguana_peer *addr); int32_t iguana_validated(struct iguana_info *coin); void iguana_volatilesalloc(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t copyflag); int32_t iguana_send_ping(struct iguana_info *coin,struct iguana_peer *addr); +int32_t iguana_process_msgrequestQ(struct iguana_info *coin); extern int32_t HDRnet,netBLOCKS; diff --git a/iguana/iguana_accept.c b/iguana/iguana_accept.c index 26e5f6e83..7fd379b67 100755 --- a/iguana/iguana_accept.c +++ b/iguana/iguana_accept.c @@ -165,13 +165,91 @@ int32_t iguana_pendingaccept(struct iguana_info *coin) return(0); }*/ +void iguana_msgrequestQ(struct iguana_info *coin,struct iguana_peer *addr,int32_t type,bits256 hash2) +{ + struct iguana_peermsgrequest *msg; + msg = calloc(1,sizeof(*msg)); + msg->addr = addr; + msg->hash2 = hash2; + msg->type = type; + queue_enqueue("msgrequest",&coin->msgrequestQ,&msg->DL,0); +} -int32_t iguana_peerhdrrequest(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2) +int32_t iguana_process_msgrequestQ(struct iguana_info *coin) { - struct iguana_txid *tx,T; int32_t len=0,i,height,retval=-1; struct iguana_block *block; struct iguana_msgblock msgB; uint8_t *serialized; bits256 checkhash2; + struct iguana_peermsgrequest *msg; int32_t height,len,flag = 0; bits256 checktxid; struct iguana_txid *tx,T; + if ( (msg= queue_dequeue(&coin->msgrequestQ,0)) != 0 ) + { + flag = 1; + if ( msg->addr != 0 ) + { + char str[65]; printf("send type.%d %s -> (%s)\n",msg->type,bits256_str(str,msg->hash2),msg->addr->ipaddr); + if ( msg->type == MSG_BLOCK ) + { + if ( coin->RELAYNODE != 0 || coin->VALIDATENODE ) + { + if ( (len= iguana_peerblockrequest(coin,&coin->blockspace[sizeof(struct iguana_msghdr)],sizeof(coin->blockspace),0,msg->hash2,0)) > 0 ) + { + iguana_queue_send(coin,msg->addr,0,coin->blockspace,"block",len,0,0); + } + } + } + else if ( msg->type == MSG_TX ) + { + if ( coin->RELAYNODE != 0 || coin->VALIDATENODE ) + { + if ( (tx= iguana_txidfind(coin,&height,&T,msg->hash2,coin->bundlescount-1)) != 0 ) + { + if ( (len= iguana_ramtxbytes(coin,&coin->blockspace[sizeof(struct iguana_msghdr)],sizeof(coin->blockspace),&checktxid,tx,height,0,0,0)) > 0 ) + { + char str[65],str2[65]; + if ( bits256_cmp(msg->hash2,checktxid) == 0 ) + iguana_queue_send(coin,msg->addr,0,coin->blockspace,"block",len,0,0); + else printf("checktxid mismatch (%s) != (%s)\n",bits256_str(str,msg->hash2),bits256_str(str2,checktxid)); + } + } + } + } + else if ( msg->type == MSG_FILTERED_BLOCK ) + { + + } + else if ( msg->type == MSG_BUNDLE_HEADERS ) + { + + } + else if ( msg->type == MSG_BUNDLE ) + { + + } + } + free(msg); + } + return(flag); +} + +int32_t iguana_peerdatarequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max) +{ + int32_t i,type,len = 0; uint64_t x; bits256 hash2; + x = coin->bundlescount; + len += iguana_rwvarint(0,space,&x); + if ( x < IGUANA_MAXINV ) + { + for (i=0; ibundlescount-1)) != 0 ) { - serialized = calloc(coin->chain->bundlesize,sizeof(msgB)); for (i=0; ichain->bundlesize; i++) { if ( (block= iguana_blockptr("peerhdr",coin,height + i)) != 0 ) @@ -182,32 +260,41 @@ int32_t iguana_peerhdrrequest(struct iguana_info *coin,struct iguana_peer *addr, { char str[65],str2[65]; printf("iguana_peerhdrrequest blockhash.%d error (%s) vs (%s)\n",height+i,bits256_str(str,checkhash2),bits256_str(str2,block->RO.hash2)); - free(serialized); return(-1); } } else printf("cant find block at ht.%d\n",height+i); } retval = iguana_queue_send(coin,addr,0,serialized,"headers",len,0,0); printf("hdrs request retval.%d len.%d\n",retval,len); - free(serialized); } //else printf("couldnt find header\n"); return(retval); } -int32_t iguana_peerinvrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max) +int32_t iguana_peergetrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *data,int32_t recvlen,int32_t getblock) { - int32_t i,type,len = 0; uint64_t x; struct iguana_bundle *bp; - x = coin->bundlescount; - len += iguana_rwvarint(1,&space[sizeof(struct iguana_msghdr) + len],&x); - for (i=0; imsgcounts.getblocks++; + else addr->msgcounts.getheaders++; + len = iguana_rwnum(0,&data[0],sizeof(uint32_t),&reqvers); + len += iguana_rwvarint32(0,&data[len],(uint32_t *)&n); + //for (i=0; i<10; i++) + // printf("%02x ",data[i]); + //printf("version.%d num blocks.%d recvlen.%d\n",reqvers,n,recvlen); + for (i=0; ibundles[i]) != 0 ) + len += iguana_rwbignum(0,&data[len],sizeof(bits256),hash2.bytes); + if ( bits256_nonz(hash2) == 0 ) + break; + if ( flag == 0 ) { - type = MSG_BLOCK; - len += iguana_rwnum(1,&space[sizeof(struct iguana_msghdr) + len],sizeof(uint32_t),&type); - len += iguana_rwbignum(1,&space[sizeof(struct iguana_msghdr) + len],sizeof(bits256),bp->hashes[0].bytes); + if ( getblock != 0 && iguana_peerblockrequest(coin,addr->blockspace,sizeof(addr->blockspace),addr,hash2,0) > 0 ) + flag = 1; + else if ( getblock == 0 && iguana_peerhdrrequest(coin,addr->blockspace,sizeof(addr->blockspace),addr,hash2) > 0 ) + flag = 1; } } + len += iguana_rwbignum(0,&data[len],sizeof(bits256),hash2.bytes); return(len); } diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 13a9c2620..c84ed02da 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -33,6 +33,7 @@ void iguana_initQs(struct iguana_info *coin) iguana_initQ(&coin->blocksQ,"blocksQ"); iguana_initQ(&coin->priorityQ,"priorityQ"); iguana_initQ(&coin->possibleQ,"possibleQ"); + iguana_initQ(&coin->msgrequestQ,"msgrequestQ"); iguana_initQ(&coin->cacheQ,"cacheQ"); iguana_initQ(&coin->recvQ,"recvQ"); for (i=0; icommand,"getblocks") == 0)) || strcmp(H->command,"block") == 0 ) { - struct iguana_txblock txdata; if ( addr != 0 ) { if ( ishost == 0 ) { + struct iguana_txblock txdata; addr->msgcounts.block++; iguana_memreset(rawmem), iguana_memreset(txmem); memset(&txdata,0,sizeof(txdata)); if ( (len= iguana_gentxarray(coin,rawmem,&txdata,&len,data,recvlen)) == recvlen ) iguana_gotblockM(coin,addr,&txdata,rawmem->ptr,H,data,recvlen); else printf("parse error block txn_count.%d, len.%d vs recvlen.%d\n",txdata.block.RO.txn_count,len,recvlen); - } - else - { - int32_t reqvers,flag = 0; - addr->msgcounts.getblocks++; - len = iguana_rwnum(0,&data[0],sizeof(uint32_t),&reqvers); - len += iguana_rwvarint32(0,&data[len],(uint32_t *)&n); - for (i=0; i<10; i++) - printf("%02x ",data[i]); - printf("version.%d num blocks.%d recvlen.%d\n",reqvers,n,recvlen); - for (i=0; iblockspace,sizeof(addr->blockspace),addr,hash2,0) > 0 ) - flag = 1; - } - len += iguana_rwbignum(0,&data[len],sizeof(bits256),hash2.bytes); - //len = recvlen; - } + } else len = iguana_peergetrequest(coin,addr,data,recvlen,1); } } - else if ( (ishost= (strcmp(H->command,"data") == 0)) || strcmp(H->command,"inv") == 0 ) + else if ( (ishost= (strcmp(H->command,"getdata") == 0)) || strcmp(H->command,"inv") == 0 ) { if ( addr != 0 ) { if ( ishost != 0 ) { addr->msgcounts.getdata++; - printf("%s SERVER getdata\n",addr->ipaddr); - intvectors = srvmsg = 'D'; - // generate intvectors data, create new type for shahdrs! - if ( (sendlen= iguana_peerinvrequest(coin,addr,addr->blockspace,sizeof(addr->blockspace))) > 0 ) - iguana_queue_send(coin,addr,0,addr->blockspace,"inv",sendlen,0,0); + iguana_peerdatarequest(coin,addr,data,recvlen); } else { @@ -612,7 +588,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc } else if ( (ishost= (strcmp(H->command,"getheaders") == 0)) || strcmp(H->command,"headers") == 0 ) { - struct iguana_msgblock msg; struct iguana_block *blocks; uint32_t n=0,nonz; + struct iguana_msgblock msg; struct iguana_block *blocks; uint32_t n=0; len = 0; if ( ishost == 0 ) { @@ -630,22 +606,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc if ( len == recvlen && addr != 0 ) addr->msgcounts.headers++; } else printf("got unexpected n.%d for headers\n",n); - } - else - { - addr->msgcounts.getheaders++; - len = iguana_rwnum(0,&data[0],sizeof(uint32_t),&tmp); - len += iguana_rwvarint32(0,&data[len],(uint32_t *)&n); - for (i=nonz=0; i 0 ) - nonz++; - } - printf("GOT HEADERS.(%s) n.%d len.%d\n",H->command,n,len); - } + } else len = iguana_peergetrequest(coin,addr,data,recvlen,0); } else if ( (ishost= (strcmp(H->command,"version") == 0)) || strcmp(H->command,"verack") == 0 ) { diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index af545a7d5..690943175 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -1551,8 +1551,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr) int32_t iguana_processrecv(struct iguana_info *coin) // single threaded { - int32_t i,newhwm = 0,hwmheight,flag = 0; //struct iguana_bundle *bp; struct iguana_block *block; - char str[2000]; + int32_t i,newhwm = 0,hwmheight,flag = 0; char str[2000]; hwmheight = coin->blocks.hwmchain.height; coin->RTramchain_busy = 1; if ( coin->balanceflush != 0 ) @@ -1578,32 +1577,19 @@ int32_t iguana_processrecv(struct iguana_info *coin) // single threaded } else { - //printf("reqblocks\n"); flag += iguana_reqblocks(coin); - //printf("bundlestats\n"); iguana_bundlestats(coin,str,IGUANA_DEFAULTLAG); } - //printf("call _iguana_chainlink\n"); - /*for (i=coin->blocks.hwmchain.height%coin->chain->bundlesize; ichain->bundlesize; i++) - { - if ( (bp= coin->current) != 0 && (block= bp->blocks[i]) != 0 ) - { - //printf("i.%d %s main.%d txvalid.%d\n",i,bits256_str(str,block->RO.hash2),block->mainchain,block->txvalid); - if ( _iguana_chainlink(coin,block) == 0 ) - iguana_blockQ("mainchain",coin,bp,-i,block->RO.hash2,1); - //iguana_realtime_update(coin); - } - }*/ if ( time(NULL) > coin->spendvectorsaved ) { for (i=0; ichain->bundlesize; i++) { if ( coin->RTdatabad != 0 || iguana_realtime_update(coin) <= 0 ) break; - //printf("call iguana_realtime_update i.%d\n",i); } } - coin->RTramchain_busy = (coin->RTgenesis == 0); + coin->RTramchain_busy = 0;//(coin->RTgenesis == 0); + flag += iguana_process_msgrequestQ(coin); iguana_jsonQ(); if ( hwmheight != coin->blocks.hwmchain.height ) flag = 1; diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 41b453be2..2ab2bb5c0 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -982,7 +982,7 @@ struct iguana_pkhash *iguana_pkhashfind(struct iguana_info *coin,struct iguana_r { if ( (bp= coin->bundles[i]) != 0 ) { - if ( 0 && bp->isRT != 0 && coin->RTramchain_busy != 0 ) + if ( coin->RTramchain_busy != 0 ) { printf("iguana_pkhashfind: unexpected access when RTramchain_busy\n"); return(0); @@ -1018,7 +1018,7 @@ char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi) uint8_t *PKbits; struct iguana_pkhash *P; uint32_t pkind,numpkinds; struct iguana_bundle *bp; struct iguana_ramchain *ramchain; cJSON *retjson; char rmdstr[41]; if ( (bp= coin->bundles[hdrsi]) != 0 ) { - if ( bp->isRT != 0 && coin->RTramchain_busy != 0 ) + if ( coin->RTramchain_busy != 0 ) { printf("iguana_bundleaddrs: unexpected access when RTramchain_busy\n"); return(0); @@ -1053,7 +1053,7 @@ int64_t iguana_pkhashbalance(struct iguana_info *coin,cJSON *array,int64_t *spen { struct iguana_unspent *U; struct iguana_utxo *U2; struct iguana_spend *S; int32_t uheight,spentheight; uint32_t pkind=0,unspentind; int64_t spent = 0,checkval,deposits = 0; struct iguana_txid *T; struct iguana_account *A2; struct iguana_ramchaindata *rdata = 0; int64_t RTspend = 0; *spentp = *nump = 0; - if ( 0 && ramchain == &coin->RTramchain && coin->RTramchain_busy != 0 ) + if ( coin->RTramchain_busy != 0 ) { printf("iguana_pkhashbalance: unexpected access when RTramchain_busy\n"); return(0); @@ -1111,7 +1111,7 @@ int64_t iguana_pkhashbalance(struct iguana_info *coin,cJSON *array,int64_t *spen int32_t iguana_pkhasharray(struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,int64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight) { int32_t i,n,m; int64_t spent,deposits,netbalance,total; uint32_t lastunspentind; struct iguana_ramchain *ramchain; - if ( 0 && coin->RTramchain_busy != 0 ) + if ( coin->RTramchain_busy != 0 ) { printf("iguana_pkhasharray: unexpected access when RTramchain_busy\n"); return(-1); @@ -1143,7 +1143,7 @@ int32_t iguana_pkhasharray(struct iguana_info *coin,cJSON *array,int32_t minconf void iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint8_t *rmdarray,int32_t numrmds) { int64_t total,sum=0; struct iguana_pkhash *P; uint8_t *addrtypes,*pubkeys; int32_t i,flag = 0; char coinaddr[64]; - if ( 0 && coin->RTramchain_busy != 0 ) + if ( coin->RTramchain_busy != 0 ) { printf("iguana_pkhasharray: unexpected access when RTramchain_busy\n"); return;