From d70ba724378bdfc0a2d9d77717785edfb1d61fd3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 10:49:48 +0200 Subject: [PATCH 01/32] test --- iguana/dpow/dpow_network.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 8292de2c8..c7607b0df 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -364,9 +364,9 @@ void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isr np->srcvout = bp->notaries[bp->myind].src.prev_vout; np->destutxo = bp->notaries[bp->myind].dest.prev_hash; np->destvout = bp->notaries[bp->myind].dest.prev_vout; - np->bestmask = bp->notaries[bp->myind].bestmask; + np->bestmask = bp->pendingbestmask;//notaries[bp->myind].bestmask; np->recvmask = bp->notaries[bp->myind].recvmask; - if ( (np->bestk= bp->notaries[bp->myind].bestk) >= 0 ) + if ( (np->bestk= bp->pendingbestk) >= 0 )//notaries[bp->myind].bestk) >= 0 ) { if ( (np->siglens[0]= bp->notaries[bp->myind].src.siglens[bp->bestk]) > 0 ) memcpy(np->sigs[0],bp->notaries[bp->myind].src.sigs[bp->bestk],np->siglens[0]); @@ -685,7 +685,7 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru { if ( bp->pendingbestk != bp->bestk || bp->pendingbestmask != bp->bestmask ) { - //printf("new PENDING BESTK (%d %llx) state.%d\n",bp->bestk,(long long)bp->bestmask,bp->state); + printf("new PENDING BESTK (%d %llx) state.%d\n",bp->bestk,(long long)bp->bestmask,bp->state); bp->pendingbestk = bp->bestk; bp->pendingbestmask = bp->bestmask; dpow_signedtxgen(myinfo,dp,bp->destcoin,bp,bp->bestk,bp->bestmask,bp->myind,DPOW_SIGBTCCHANNEL,1,0); @@ -715,7 +715,7 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d } else { - if ( senderind <= 1 ) + //if ( senderind <= 1 ) printf("RECV.%d %llx (%d %llx)\n",senderind,(long long)np->recvmask,bp->bestk,(long long)np->bestmask); dpow_notarize_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); } From 11a74af2317b52639ba0ad8dd659c87de9e68418 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 10:54:07 +0200 Subject: [PATCH 02/32] test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index c7607b0df..c3e7d4f3e 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -747,7 +747,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo { extralen = dpow_paxpending(extras,&paxwdcrc); bp->paxwdcrc = bp->notaries[bp->myind].paxwdcrc = np->notarize.paxwdcrc = paxwdcrc; - dpow_bestconsensus(bp); + //dpow_bestconsensus(bp); dpow_nanoutxoset(&np->notarize,bp,0); } else From 203f04e7aea89d5e1ab4accc360ec25bc41275be Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 11:10:17 +0200 Subject: [PATCH 03/32] test --- iguana/dpow/dpow_network.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index c3e7d4f3e..7216b926d 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -716,7 +716,7 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d else { //if ( senderind <= 1 ) - printf("RECV.%d %llx (%d %llx)\n",senderind,(long long)np->recvmask,bp->bestk,(long long)np->bestmask); + // printf("RECV.%d %llx (%d %llx)\n",senderind,(long long)np->recvmask,bp->bestk,(long long)np->bestmask); dpow_notarize_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); @@ -727,8 +727,8 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo struct dpow_nanomsghdr *np; int32_t i,size,extralen=0,sentbytes = 0; uint32_t crc32,paxwdcrc; uint8_t extras[10000]; if ( bp->myind < 0 ) return; - if ( time(NULL) < myinfo->nanoinit+5 ) - return; + //if ( time(NULL) < myinfo->nanoinit+5 ) + // return; crc32 = calc_crc32(0,data,datalen); //dp->crcs[firstz] = crc32; size = (int32_t)(sizeof(*np) + datalen); @@ -873,7 +873,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } if ( np != 0 ) nn_freemsg(np), np = 0; - if ( size == 0 || n++ > 100 ) + if ( size == 0 || n++ > 10000 ) break; } portable_mutex_unlock(&myinfo->dpowmutex); @@ -891,7 +891,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } if ( dexp != 0 ) nn_freemsg(dexp), dexp = 0; - if ( size == 0 || n++ > 100 ) + if ( size == 0 || n++ > 1000 ) break; } n = 0; From 1f6de80ea8d4d606df0f21c163fea5c205385c27 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 11:19:11 +0200 Subject: [PATCH 04/32] test --- basilisk/basilisk.c | 2 +- iguana/dpow/dpow_network.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index f5d1818b1..3440001d6 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -892,7 +892,7 @@ void basilisks_loop(void *arg) iguana_dPoWupdate(myinfo,dp); if ( (counter % myinfo->numdpows) != 0 ) iguana_dPoWupdate(myinfo,&myinfo->DPOWS[0]); - endmilli = startmilli + 200; + endmilli = startmilli + 10; } } else if ( myinfo->IAMLP != 0 ) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 7216b926d..495a63826 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -873,7 +873,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } if ( np != 0 ) nn_freemsg(np), np = 0; - if ( size == 0 || n++ > 10000 ) + //if ( size == 0 || n++ > 10000 ) break; } portable_mutex_unlock(&myinfo->dpowmutex); From 3971f243dc0ef35b8db6d5940c02336c0bb4eaed Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 11:46:08 +0200 Subject: [PATCH 05/32] test --- iguana/dpow/dpow_network.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 495a63826..844f879fe 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -364,9 +364,15 @@ void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isr np->srcvout = bp->notaries[bp->myind].src.prev_vout; np->destutxo = bp->notaries[bp->myind].dest.prev_hash; np->destvout = bp->notaries[bp->myind].dest.prev_vout; - np->bestmask = bp->pendingbestmask;//notaries[bp->myind].bestmask; - np->recvmask = bp->notaries[bp->myind].recvmask; - if ( (np->bestk= bp->pendingbestk) >= 0 )//notaries[bp->myind].bestk) >= 0 ) + if ( (np->recvmask= bp->recvmask) == 0 ) + np->recvmask = bp->notaries[bp->myind].recvmask; + if ( (np->bestmask= bp->pendingbestmask) == 0 ) + { + if ( (np->bestmask= bp->notaries[bp->myind].bestmask) == 0 ) + np->bestmask = bp->bestmask, np->bestk = bp->bestk; + else np->bestk = bp->notaries[bp->myind].bestk; + } else np->bestk = bp->pendingbestk; + if ( np->bestk >= 0 ) { if ( (np->siglens[0]= bp->notaries[bp->myind].src.siglens[bp->bestk]) > 0 ) memcpy(np->sigs[0],bp->notaries[bp->myind].src.sigs[bp->bestk],np->siglens[0]); @@ -873,16 +879,13 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } if ( np != 0 ) nn_freemsg(np), np = 0; - //if ( size == 0 || n++ > 10000 ) + //if ( size == 0 || nun > 10000 ) break; } portable_mutex_unlock(&myinfo->dpowmutex); - if ( 0 && n != 0 ) - printf("nanoupdates.%d\n",n); n = 0; while ( (size= nn_recv(myinfo->dexsock,&dexp,NN_MSG,0)) >= 0 ) { - num++; if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { printf("FROM BUS.%08x -> pub\n",dexp->crc32); @@ -894,12 +897,10 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) if ( size == 0 || n++ > 1000 ) break; } - n = 0; - if ( num == 0 ) + if ( n == 0 ) { while ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) >= 0 ) { - num++; if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { nn_send(myinfo->dexsock,dexp,size,0); From fda37056a6b13be2c64c4b06f200407cad1cf57d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 12:07:16 +0200 Subject: [PATCH 06/32] test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 844f879fe..4021cfddb 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -187,7 +187,7 @@ struct dpow_nanoutxo uint64_t bestmask,recvmask; uint32_t pendingcrcs[2],paxwdcrc; uint16_t srcvout,destvout; - uint8_t sigs[2][DPOW_MAXSIGLEN],siglens[2],bestk,pad; + uint8_t sigs[2][DPOW_MAXSIGLEN],siglens[2],pad; int8_t bestk; } PACKED; struct dpow_nanomsghdr From ba6ae0c9df0fe46761d9a197471317c7402ad678 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 12:08:06 +0200 Subject: [PATCH 07/32] test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 4021cfddb..6983ab333 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -781,7 +781,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo sentbytes = nn_send(myinfo->dpowsock,np,size,0); portable_mutex_unlock(&myinfo->dpowmutex); free(np); - printf("NANOSEND ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx)\n",np->height,np->channel,size,np->notarize.paxwdcrc,datalen,np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask); + printf("NANOSEND ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",np->height,np->channel,size,np->notarize.paxwdcrc,datalen,np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); } void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *ipbits,int32_t numipbits,int32_t fromid,uint32_t senderipbits) From 96ed4171ee429fd1068fe82fc19526aa2def67db Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 12:33:57 +0200 Subject: [PATCH 08/32] test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 6983ab333..e01edce52 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -722,7 +722,7 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d else { //if ( senderind <= 1 ) - // printf("RECV.%d %llx (%d %llx)\n",senderind,(long long)np->recvmask,bp->bestk,(long long)np->bestmask); + printf("RECV.%d %llx (%d %llx)\n",senderind,(long long)np->recvmask,np->bestk,(long long)np->bestmask); dpow_notarize_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); From 371d9c64951089a23396a96b147acb3fa1dec922 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 12:37:42 +0200 Subject: [PATCH 09/32] test --- iguana/dpow/dpow_network.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index e01edce52..996190e72 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -721,9 +721,8 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d } else { - //if ( senderind <= 1 ) - printf("RECV.%d %llx (%d %llx)\n",senderind,(long long)np->recvmask,np->bestk,(long long)np->bestmask); dpow_notarize_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); + printf("RECV.%d %llx (%d %llx)\n",senderind,(long long)np->recvmask,np->bestk,(long long)np->bestmask); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); } @@ -868,7 +867,6 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) dpow_nanoutxoget(myinfo,dp,bp,&np->notarize,0,np->senderind); else dpow_nanoutxoget(myinfo,dp,bp,&np->ratify,1,np->senderind); dpow_datahandler(myinfo,dp,bp,np->senderind,np->channel,np->height,np->packet,np->datalen); - dex_reqsend(myinfo,np->packet,np->datalen); } } //dp->crcs[firstz] = crc32; From 28859465d3d8959fb8d40c02578d46e7a182f687 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 12:38:47 +0200 Subject: [PATCH 10/32] test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 996190e72..09ed72825 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -722,7 +722,7 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d else { dpow_notarize_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); - printf("RECV.%d %llx (%d %llx)\n",senderind,(long long)np->recvmask,np->bestk,(long long)np->bestmask); + printf("RECV.%d %llx (%d %llx) %llx/%llx\n",senderind,(long long)np->recvmask,np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); } From 971f40e4801e13613ad6a135eae787e61cbe36b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 12:52:23 +0200 Subject: [PATCH 11/32] test --- iguana/dpow/dpow_network.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 09ed72825..1cc068553 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -767,7 +767,6 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo np->ratify.pendingcrcs[i] = bp->pendingcrcs[i]; for (i=0; i<32; i++) np->srchash.bytes[i] = dp->minerkey33[i+1]; - //np->srchash = srchash; np->desthash = desthash; np->channel = channel; np->height = msgbits; @@ -861,18 +860,21 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) dpow_ipbitsadd(myinfo,dp,np->ipbits,np->numipbits,np->senderind,np->myipbits); if ( (bp= dpow_heightfind(myinfo,dp,np->height)) != 0 && bp->state != 0xffffffff && bp->myind >= 0 ) { - if ( np->senderind >= 0 && np->senderind < bp->numnotaries && memcmp(bp-> notaries[np->senderind].pubkey+1,np->srchash.bytes,32) == 0 && bits256_nonz(np->srchash) != 0 ) + if ( np->senderind >= 0 && np->senderind < bp->numnotaries ) { - if ( bp->isratify == 0 ) - dpow_nanoutxoget(myinfo,dp,bp,&np->notarize,0,np->senderind); - else dpow_nanoutxoget(myinfo,dp,bp,&np->ratify,1,np->senderind); - dpow_datahandler(myinfo,dp,bp,np->senderind,np->channel,np->height,np->packet,np->datalen); + if ( memcmp(bp->notaries[np->senderind].pubkey+1,np->srchash.bytes,32) == 0 && bits256_nonz(np->srchash) != 0 ) + { + if ( bp->isratify == 0 ) + dpow_nanoutxoget(myinfo,dp,bp,&np->notarize,0,np->senderind); + else dpow_nanoutxoget(myinfo,dp,bp,&np->ratify,1,np->senderind); + dpow_datahandler(myinfo,dp,bp,np->senderind,np->channel,np->height,np->packet,np->datalen); + } else printf("wrong senderind.%d\n",np->senderind); } } //dp->crcs[firstz] = crc32; } - } - } //else printf("ignore np->datalen.%d %d (size %d - %ld)\n",np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np)); + } else printf("crc error %x vs %x or no dp.%p\n",crc32,np->crc32,dp); + } else printf("ignore np->datalen.%d %d (size %d - %ld)\n",np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np)); } } if ( np != 0 ) From d184cc81638c28c1f41c63baf8cb4744816da5d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 12:53:31 +0200 Subject: [PATCH 12/32] test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 1cc068553..3ff4febaa 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -879,7 +879,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } if ( np != 0 ) nn_freemsg(np), np = 0; - //if ( size == 0 || nun > 10000 ) + if ( size == 0 || num > 100 ) break; } portable_mutex_unlock(&myinfo->dpowmutex); From fba7fe2498cb139c7a245f6e9a8694e4b7abbbc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 12:56:01 +0200 Subject: [PATCH 13/32] test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 3ff4febaa..de81334cf 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -879,7 +879,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } if ( np != 0 ) nn_freemsg(np), np = 0; - if ( size == 0 || num > 100 ) + //if ( size == 0 || num > 100 ) break; } portable_mutex_unlock(&myinfo->dpowmutex); From 34b90aeeb18b57480fa809903b5d6ce896ecd0c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 12:56:59 +0200 Subject: [PATCH 14/32] test --- iguana/dpow/dpow_network.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index de81334cf..acf9f285d 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -830,7 +830,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) if ( time(NULL) < myinfo->nanoinit+5 ) return; portable_mutex_lock(&myinfo->dpowmutex); - while ( (size= nn_recv(myinfo->dpowsock,&np,NN_MSG,0)) >= 0 ) + if ( (size= nn_recv(myinfo->dpowsock,&np,NN_MSG,0)) >= 0 ) { num++; if ( size >= 0 ) @@ -879,12 +879,10 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } if ( np != 0 ) nn_freemsg(np), np = 0; - //if ( size == 0 || num > 100 ) - break; } portable_mutex_unlock(&myinfo->dpowmutex); n = 0; - while ( (size= nn_recv(myinfo->dexsock,&dexp,NN_MSG,0)) >= 0 ) + if ( (size= nn_recv(myinfo->dexsock,&dexp,NN_MSG,0)) >= 0 ) { if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { @@ -894,29 +892,22 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } if ( dexp != 0 ) nn_freemsg(dexp), dexp = 0; - if ( size == 0 || n++ > 1000 ) - break; } - if ( n == 0 ) + if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) >= 0 ) { - while ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) >= 0 ) + if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { - if ( dex_packetcheck(myinfo,dexp,size) == 0 ) + nn_send(myinfo->dexsock,dexp,size,0); + if ( (m= myinfo->numdpowipbits) > 0 ) { - nn_send(myinfo->dexsock,dexp,size,0); - if ( (m= myinfo->numdpowipbits) > 0 ) - { - r = myinfo->dpowipbits[rand() % m]; - nn_send(myinfo->repsock,&r,sizeof(r),0); - printf("REP.%08x -> dexbus, rep.%08x",dexp->crc32,r); - } - dex_packet(myinfo,dexp,size); + r = myinfo->dpowipbits[rand() % m]; + nn_send(myinfo->repsock,&r,sizeof(r),0); + printf("REP.%08x -> dexbus, rep.%08x",dexp->crc32,r); } - if ( dexp != 0 ) - nn_freemsg(dexp), dexp = 0; - if ( size == 0 || n++ > 100 ) - break; + dex_packet(myinfo,dexp,size); } + if ( dexp != 0 ) + nn_freemsg(dexp), dexp = 0; } } #else From 196aeeb669a371981ba1b920a33976364d6f93e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 13:03:43 +0200 Subject: [PATCH 15/32] test --- iguana/dpow/dpow_network.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index acf9f285d..546622a3c 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -187,7 +187,7 @@ struct dpow_nanoutxo uint64_t bestmask,recvmask; uint32_t pendingcrcs[2],paxwdcrc; uint16_t srcvout,destvout; - uint8_t sigs[2][DPOW_MAXSIGLEN],siglens[2],pad; int8_t bestk; + uint8_t sigs[2][DPOW_MAXSIGLEN],siglens[2],pad,bestk; } PACKED; struct dpow_nanomsghdr @@ -372,7 +372,7 @@ void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isr np->bestmask = bp->bestmask, np->bestk = bp->bestk; else np->bestk = bp->notaries[bp->myind].bestk; } else np->bestk = bp->pendingbestk; - if ( np->bestk >= 0 ) + if ( (int8_t)np->bestk >= 0 ) { if ( (np->siglens[0]= bp->notaries[bp->myind].src.siglens[bp->bestk]) > 0 ) memcpy(np->sigs[0],bp->notaries[bp->myind].src.sigs[bp->bestk],np->siglens[0]); @@ -717,12 +717,12 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d { if ( isratify != 0 ) { - dpow_ratify_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->pendingcrcs); + dpow_ratify_update(myinfo,dp,bp,senderind,(int8_t)np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->pendingcrcs); } else { - dpow_notarize_update(myinfo,dp,bp,senderind,np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); - printf("RECV.%d %llx (%d %llx) %llx/%llx\n",senderind,(long long)np->recvmask,np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); + dpow_notarize_update(myinfo,dp,bp,senderind,(int8_t)np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); + printf("RECV.%d %llx (%d %llx) %llx/%llx\n",senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); } From 3904477077f377f47e559aa0fe5252b8beb92bdb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 13:08:52 +0200 Subject: [PATCH 16/32] test --- iguana/dpow/dpow_fsm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index 1a3c7b07a..fac6fae56 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -439,6 +439,7 @@ void dpow_statemachinestart(void *ptr) if ( bp->state != 0xffffffff ) { dpow_send(myinfo,dp,bp,srchash,bp->hashmsg,0,bp->height,(void *)"ping",0); + dpow_nanomsg_update(myinfo); } if ( 0 && dp->cancelratify != 0 && bp->isratify != 0 ) { From ca675e32060e6cc8133b9e6626d86b59d52f0466 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 13:17:57 +0200 Subject: [PATCH 17/32] test --- iguana/dpow/dpow_network.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 546622a3c..a683421df 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -873,13 +873,13 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } //dp->crcs[firstz] = crc32; } - } else printf("crc error %x vs %x or no dp.%p\n",crc32,np->crc32,dp); + } else printf("crc error %x vs %x or no dp.%p [%s]\n",crc32,np->crc32,dp,np->symbol); } else printf("ignore np->datalen.%d %d (size %d - %ld)\n",np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np)); - } - } + } else printf("wrong version\n"); + } else printf("illegal size.%d\n",size); if ( np != 0 ) nn_freemsg(np), np = 0; - } + } else printf("no packets\n"); portable_mutex_unlock(&myinfo->dpowmutex); n = 0; if ( (size= nn_recv(myinfo->dexsock,&dexp,NN_MSG,0)) >= 0 ) From 0637b8c48472c8c6c95eff05e1a43767c481b1f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 13:20:25 +0200 Subject: [PATCH 18/32] test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index a683421df..0d5e11952 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -875,7 +875,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } } else printf("crc error %x vs %x or no dp.%p [%s]\n",crc32,np->crc32,dp,np->symbol); } else printf("ignore np->datalen.%d %d (size %d - %ld)\n",np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np)); - } else printf("wrong version\n"); + } else printf("wrong version %02x %02x\n",np->version0,np->version1); } else printf("illegal size.%d\n",size); if ( np != 0 ) nn_freemsg(np), np = 0; From c24a1d7c7044dce59c9de0330cbc1fa949d00180 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 15:00:54 +0200 Subject: [PATCH 19/32] test --- iguana/dpow/dpow_network.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 0d5e11952..911916b6f 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -873,9 +873,9 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } //dp->crcs[firstz] = crc32; } - } else printf("crc error %x vs %x or no dp.%p [%s]\n",crc32,np->crc32,dp,np->symbol); - } else printf("ignore np->datalen.%d %d (size %d - %ld)\n",np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np)); - } else printf("wrong version %02x %02x\n",np->version0,np->version1); + } else printf("crc error from.%d %x vs %x or no dp.%p [%s]\n",np->senderind,crc32,np->crc32,dp,np->symbol); + } else printf("ignore.%d np->datalen.%d %d (size %d - %ld)\n",np->senderind,np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np)); + } else printf("wrong version from.%d %02x %02x size.%d [%s]\n",np->senderind,np->version0,np->version1,size,np->symbol); } else printf("illegal size.%d\n",size); if ( np != 0 ) nn_freemsg(np), np = 0; From e05b1c6474c81be54dd659a682c61362c85d08a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Dec 2016 15:16:05 +0200 Subject: [PATCH 20/32] test --- iguana/dpow/dpow_network.c | 17 ++++++++++------- iguana/iguana_notary.c | 6 ++++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 911916b6f..e036382db 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -242,7 +242,7 @@ int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *i else dp->numipbits = n; //for (i=0; inumdpowipbits,dp!=0?dp->numipbits:-1,iter); + printf("addnotary.[%d] (%s) retval.%d (total %d %d) iter.%d\n",n,ipaddr,retval,myinfo->numdpowipbits,dp!=0?dp->numipbits:-1,iter); } if ( dp == 0 ) break; @@ -604,8 +604,8 @@ void dpow_bestconsensus(struct dpow_block *bp) { bp->bestmask = masks[besti]; bp->bestk = bestks[besti]; - bp->recvmask = recvmask; } + bp->recvmask = recvmask; if ( bp->bestmask == 0 )//|| (time(NULL) / 180) != bp->lastepoch ) { bp->bestmask = dpow_notarybestk(bp->recvmask,bp,&bp->bestk); @@ -779,7 +779,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo sentbytes = nn_send(myinfo->dpowsock,np,size,0); portable_mutex_unlock(&myinfo->dpowmutex); free(np); - printf("NANOSEND ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",np->height,np->channel,size,np->notarize.paxwdcrc,datalen,np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); + printf("NANOSEND ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); } void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *ipbits,int32_t numipbits,int32_t fromid,uint32_t senderipbits) @@ -824,11 +824,11 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t * //printf("recv numips.(%d %d)\n",myinfo->numdpowipbits,dp->numipbits); } -void dpow_nanomsg_update(struct supernet_info *myinfo) +int32_t dpow_nanomsg_update(struct supernet_info *myinfo) { int32_t i,n=0,num=0,size,firstz = -1; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; if ( time(NULL) < myinfo->nanoinit+5 ) - return; + return(-1); portable_mutex_lock(&myinfo->dpowmutex); if ( (size= nn_recv(myinfo->dpowsock,&np,NN_MSG,0)) >= 0 ) { @@ -874,7 +874,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) //dp->crcs[firstz] = crc32; } } else printf("crc error from.%d %x vs %x or no dp.%p [%s]\n",np->senderind,crc32,np->crc32,dp,np->symbol); - } else printf("ignore.%d np->datalen.%d %d (size %d - %ld)\n",np->senderind,np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np)); + } else printf("ignore.%d np->datalen.%d %d (size %d - %ld) [%s]\n",np->senderind,np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np),np->symbol); } else printf("wrong version from.%d %02x %02x size.%d [%s]\n",np->senderind,np->version0,np->version1,size,np->symbol); } else printf("illegal size.%d\n",size); if ( np != 0 ) @@ -884,6 +884,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) n = 0; if ( (size= nn_recv(myinfo->dexsock,&dexp,NN_MSG,0)) >= 0 ) { + num++; if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { printf("FROM BUS.%08x -> pub\n",dexp->crc32); @@ -895,6 +896,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) } if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) >= 0 ) { + num++; if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { nn_send(myinfo->dexsock,dexp,size,0); @@ -909,6 +911,7 @@ void dpow_nanomsg_update(struct supernet_info *myinfo) if ( dexp != 0 ) nn_freemsg(dexp), dexp = 0; } + return(num); } #else @@ -919,7 +922,7 @@ uint32_t dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow return(0); } -void dpow_nanomsg_update(struct supernet_info *myinfo) { } +int32_t dpow_nanomsg_update(struct supernet_info *myinfo) { return(0); } #endif diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index d7734d11e..4afc005d7 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -142,8 +142,10 @@ void dpow_destupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t h void iguana_dPoWupdate(struct supernet_info *myinfo,struct dpow_info *dp) { - int32_t height; uint32_t blocktime; bits256 blockhash; struct iguana_info *src,*dest; - dpow_nanomsg_update(myinfo); + int32_t i,height; uint32_t blocktime; bits256 blockhash; struct iguana_info *src,*dest; + for (i=0; i<100; i++) + if ( dpow_nanomsg_update(myinfo) <= 0 ) + break; src = iguana_coinfind(dp->symbol); dest = iguana_coinfind(dp->dest); //fprintf(stderr,"dp.%p dPoWupdate (%s -> %s)\n",dp,dp!=0?dp->symbol:"",dp!=0?dp->dest:""); From 9c5bb011b7e30d2b237aba1f1bd510f344e7cd85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 13:26:59 +0200 Subject: [PATCH 21/32] test --- iguana/dpow/dpow_network.c | 3 ++- iguana/dpow/dpow_tx.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index e036382db..36cd50ddf 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -604,6 +604,7 @@ void dpow_bestconsensus(struct dpow_block *bp) { bp->bestmask = masks[besti]; bp->bestk = bestks[besti]; + printf("set best to (%d %llx) recv.%llx\n",bp->bestk,(long long)bp->bestmask,(long long)recvmask); } bp->recvmask = recvmask; if ( bp->bestmask == 0 )//|| (time(NULL) / 180) != bp->lastepoch ) @@ -657,7 +658,7 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru dpow_bestconsensus(bp); //bp->recvmask |= (1LL << senderind) | (1LL << bp->myind); //bp->bestmask = dpow_maskmin(bp->recvmask,bp,&bp->bestk); - if ( bp->paxwdcrc != 0 ) + //if ( bp->paxwdcrc != 0 ) bp->notaries[bp->myind].paxwdcrc = bp->paxwdcrc; if ( bp->bestk >= 0 ) bp->notaries[bp->myind].bestk = bp->bestk; diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index 8e71a65ff..ccc1f736d 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -110,7 +110,7 @@ uint64_t dpow_notarybestk(uint64_t refmask,struct dpow_block *bp,int8_t *lastkp) k = (j + (bp->height/DPOW_CHECKPOINTFREQ)) % bp->numnotaries; //if ( bp->require0 != 0 && k == 0 ) // continue; - if ( bits256_nonz(bp->notaries[k].src.prev_hash) != 0 && bits256_nonz(bp->notaries[k].dest.prev_hash) != 0 ) + if ( bits256_nonz(bp->notaries[k].src.prev_hash) != 0 && bits256_nonz(bp->notaries[k].dest.prev_hash) != 0 && bp->paxwdcrc == bp->notaries[k].paxwdcrc ) { mask |= (1LL << k); if ( ++m == bp->minsigs )//-bp->require0 ) From 2ff8411b10786a6ef743de1c4df7c1888700844b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 13:52:03 +0200 Subject: [PATCH 22/32] test --- iguana/dpow/dpow_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 36cd50ddf..a3a27ef4b 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -685,7 +685,7 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru } } if ( bp->notaries[i].paxwdcrc != 0 ) - printf("%d.(%x %d %llx) ",i,bp->notaries[i].paxwdcrc,bp->notaries[i].bestk,(long long)bp->notaries[i].bestmask); + printf("%d.(%x %d %llx r%llx) ",i,bp->notaries[i].paxwdcrc,bp->notaries[i].bestk,(long long)bp->notaries[i].bestmask,(long long)bp->notaries[i].recvmask); } printf("recv.%llx best.(%d %llx) m.%d p.%d:%d b.%d\n",(long long)bp->recvmask,bp->bestk,(long long)bp->bestmask,matches,paxmatches,paxbestmatches,bestmatches); if ( bestmatches >= bp->minsigs && paxbestmatches >= bp->minsigs ) From ba31e081034334f97a9265740652ac044b11158b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 13:53:52 +0200 Subject: [PATCH 23/32] test --- iguana/dpow/dpow_network.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index a3a27ef4b..16d7c9725 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -360,6 +360,7 @@ void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isr } else { + dpow_bestconsensus(bp); np->srcutxo = bp->notaries[bp->myind].src.prev_hash; np->srcvout = bp->notaries[bp->myind].src.prev_vout; np->destutxo = bp->notaries[bp->myind].dest.prev_hash; @@ -723,7 +724,7 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d else { dpow_notarize_update(myinfo,dp,bp,senderind,(int8_t)np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); - printf("RECV.%d %llx (%d %llx) %llx/%llx\n",senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); + printf("RECV.%d r%llx (%d %llx) %llx/%llx\n",senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); } From d5569f6c8c46a607377dd1eba5f32640d3ad1848 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 13:54:31 +0200 Subject: [PATCH 24/32] test --- iguana/dpow/dpow_network.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 16d7c9725..a3c9efca5 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -875,9 +875,9 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) } //dp->crcs[firstz] = crc32; } - } else printf("crc error from.%d %x vs %x or no dp.%p [%s]\n",np->senderind,crc32,np->crc32,dp,np->symbol); - } else printf("ignore.%d np->datalen.%d %d (size %d - %ld) [%s]\n",np->senderind,np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np),np->symbol); - } else printf("wrong version from.%d %02x %02x size.%d [%s]\n",np->senderind,np->version0,np->version1,size,np->symbol); + } //else printf("crc error from.%d %x vs %x or no dp.%p [%s]\n",np->senderind,crc32,np->crc32,dp,np->symbol); + } //else printf("ignore.%d np->datalen.%d %d (size %d - %ld) [%s]\n",np->senderind,np->datalen,(int32_t)(size-sizeof(*np)),size,sizeof(*np),np->symbol); + } //else printf("wrong version from.%d %02x %02x size.%d [%s]\n",np->senderind,np->version0,np->version1,size,np->symbol); } else printf("illegal size.%d\n",size); if ( np != 0 ) nn_freemsg(np), np = 0; From 023057cbc237bf8bacee23debb9b10fae95ef316 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 13:55:15 +0200 Subject: [PATCH 25/32] test --- iguana/dpow/dpow_network.c | 118 ++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index a3c9efca5..2bd8eddeb 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -335,6 +335,65 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) dpow_addnotary(myinfo,0,ipaddr); } +void dpow_bestconsensus(struct dpow_block *bp) +{ + int8_t bestks[64]; int32_t counts[64],i,j,numcrcs=0,numdiff,besti,best,bestmatches = 0,matches = 0; uint64_t masks[64],matchesmask,recvmask; uint32_t crcval=0; char srcaddr[64],destaddr[64]; + memset(masks,0,sizeof(masks)); + memset(bestks,0xff,sizeof(bestks)); + memset(counts,0,sizeof(counts)); + recvmask = 0; + for (numdiff=i=0; inumnotaries; i++) + { + if ( bits256_nonz(bp->notaries[i].src.prev_hash) != 0 && bits256_nonz(bp->notaries[i].dest.prev_hash) != 0 ) + recvmask |= (1LL << i); + if ( bp->notaries[i].bestk < 0 || bp->notaries[i].bestmask == 0 ) + continue; + //if ( bp->require0 != 0 && (bp->notaries[i].bestmask & 1) == 0 ) + // continue; + for (j=0; jnotaries[i].bestk == bestks[j] && bp->notaries[i].bestmask == masks[j] ) + { + counts[j]++; + break; + } + if ( j == numdiff && bp->notaries[i].bestk >= 0 && bp->notaries[i].bestmask != 0 ) + { + masks[numdiff] = bp->notaries[i].bestmask; + bestks[numdiff] = bp->notaries[i].bestk; + counts[numdiff]++; + //printf("j.%d numdiff.%d (%d %llx).%d\n",j,numdiff,bp->notaries[i].bestk,(long long)bp->notaries[i].bestmask,counts[numdiff]); + numdiff++; + } + } + besti = -1, best = 0; + for (i=0; i best ) + { + best = counts[i]; + besti = i; + } + } + if ( besti >= 0 && bestks[besti] >= 0 && masks[besti] != 0 && (recvmask & masks[besti]) == masks[besti] ) + { + bp->bestmask = masks[besti]; + bp->bestk = bestks[besti]; + printf("set best to (%d %llx) recv.%llx\n",bp->bestk,(long long)bp->bestmask,(long long)recvmask); + } + bp->recvmask = recvmask; + if ( bp->bestmask == 0 )//|| (time(NULL) / 180) != bp->lastepoch ) + { + bp->bestmask = dpow_notarybestk(bp->recvmask,bp,&bp->bestk); + if ( 0 && (time(NULL) / 180) != bp->lastepoch ) + { + bp->lastepoch = (uint32_t)(time(NULL) / 180); + printf("epoch %u\n",bp->lastepoch % bp->numnotaries); + sleep(1 + (rand() % 3)); + } + } +} + void dpow_nanoutxoset(struct dpow_nanoutxo *np,struct dpow_block *bp,int32_t isratify) { int32_t i; @@ -561,65 +620,6 @@ void dpow_ratify_update(struct supernet_info *myinfo,struct dpow_info *dp,struct } } -void dpow_bestconsensus(struct dpow_block *bp) -{ - int8_t bestks[64]; int32_t counts[64],i,j,numcrcs=0,numdiff,besti,best,bestmatches = 0,matches = 0; uint64_t masks[64],matchesmask,recvmask; uint32_t crcval=0; char srcaddr[64],destaddr[64]; - memset(masks,0,sizeof(masks)); - memset(bestks,0xff,sizeof(bestks)); - memset(counts,0,sizeof(counts)); - recvmask = 0; - for (numdiff=i=0; inumnotaries; i++) - { - if ( bits256_nonz(bp->notaries[i].src.prev_hash) != 0 && bits256_nonz(bp->notaries[i].dest.prev_hash) != 0 ) - recvmask |= (1LL << i); - if ( bp->notaries[i].bestk < 0 || bp->notaries[i].bestmask == 0 ) - continue; - //if ( bp->require0 != 0 && (bp->notaries[i].bestmask & 1) == 0 ) - // continue; - for (j=0; jnotaries[i].bestk == bestks[j] && bp->notaries[i].bestmask == masks[j] ) - { - counts[j]++; - break; - } - if ( j == numdiff && bp->notaries[i].bestk >= 0 && bp->notaries[i].bestmask != 0 ) - { - masks[numdiff] = bp->notaries[i].bestmask; - bestks[numdiff] = bp->notaries[i].bestk; - counts[numdiff]++; - //printf("j.%d numdiff.%d (%d %llx).%d\n",j,numdiff,bp->notaries[i].bestk,(long long)bp->notaries[i].bestmask,counts[numdiff]); - numdiff++; - } - } - besti = -1, best = 0; - for (i=0; i best ) - { - best = counts[i]; - besti = i; - } - } - if ( besti >= 0 && bestks[besti] >= 0 && masks[besti] != 0 && (recvmask & masks[besti]) == masks[besti] ) - { - bp->bestmask = masks[besti]; - bp->bestk = bestks[besti]; - printf("set best to (%d %llx) recv.%llx\n",bp->bestk,(long long)bp->bestmask,(long long)recvmask); - } - bp->recvmask = recvmask; - if ( bp->bestmask == 0 )//|| (time(NULL) / 180) != bp->lastepoch ) - { - bp->bestmask = dpow_notarybestk(bp->recvmask,bp,&bp->bestk); - if ( 0 && (time(NULL) / 180) != bp->lastepoch ) - { - bp->lastepoch = (uint32_t)(time(NULL) / 180); - printf("epoch %u\n",bp->lastepoch % bp->numnotaries); - sleep(1 + (rand() % 3)); - } - } -} - void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,uint8_t senderind,int8_t bestk,uint64_t bestmask,uint64_t recvmask,bits256 srcutxo,uint16_t srcvout,bits256 destutxo,uint16_t destvout,uint8_t siglens[2],uint8_t sigs[2][DPOW_MAXSIGLEN],uint32_t paxwdcrc) { int32_t i,bestmatches = 0,matches = 0,paxmatches = 0,paxbestmatches = 0; From 474ecc08d66ec6d20970f04fa1c2bd85971c3674 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 14:32:03 +0200 Subject: [PATCH 26/32] test --- iguana/dpow/dpow_network.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 2bd8eddeb..e906a3615 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -724,7 +724,7 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d else { dpow_notarize_update(myinfo,dp,bp,senderind,(int8_t)np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); - printf("RECV.%d r%llx (%d %llx) %llx/%llx\n",senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); + printf("lag.[%d] RECV.%d r%llx (%d %llx) %llx/%llx\n",(int32_t)(time(NULL)-np->channel),senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); } @@ -770,18 +770,30 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo for (i=0; i<32; i++) np->srchash.bytes[i] = dp->minerkey33[i+1]; np->desthash = desthash; - np->channel = channel; + if ( (np->channel= channel) == 0 ) + np->channel = (uint32_t)time(NULL); np->height = msgbits; np->myipbits = myinfo->myaddr.myipbits; strcpy(np->symbol,dp->symbol); np->version0 = DPOW_VERSION & 0xff; np->version1 = (DPOW_VERSION >> 8) & 0xff; memcpy(np->packet,data,datalen); + sentbytes = -1; portable_mutex_lock(&myinfo->dpowmutex); - sentbytes = nn_send(myinfo->dpowsock,np,size,0); + for (i=0; i<100; i++) + { + struct nn_pollfd pfd; + pfd.fd = myinfo->dpowsock; + pfd.events = NN_POLLOUT; + if ( nn_poll(&pfd,1,100) > 0 ) + { + sentbytes = nn_send(myinfo->dpowsock,np,size,0); + break; + } + } portable_mutex_unlock(&myinfo->dpowmutex); free(np); - printf("NANOSEND ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); + printf("%d NANOSEND.%s ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",i,sentbytes,np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); } void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *ipbits,int32_t numipbits,int32_t fromid,uint32_t senderipbits) From 18f419b52c9a32b404b759e059f11c83ae666179 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 14:33:25 +0200 Subject: [PATCH 27/32] test --- iguana/dpow/dpow_network.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index e906a3615..a1ddb563c 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -270,6 +270,7 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) } else { + printf("NN_BIND to %s\n",str); if ( myinfo->dexsock < 0 && (myinfo->dexsock= nn_socket(AF_SP,NN_BUS)) >= 0 ) { if ( nn_bind(myinfo->dexsock,nanomsg_tcpname(str,myinfo->ipaddr,DEX_SOCK)) < 0 ) From 1cbbdf121eaeb164b1fb2f9b2ccb67782770ba68 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 14:36:35 +0200 Subject: [PATCH 28/32] test --- iguana/dpow/dpow_network.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index a1ddb563c..88060ad6d 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -233,6 +233,7 @@ int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *i if ( iter == 0 && strcmp(ipaddr,myinfo->ipaddr) != 0 ) { retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(str,ipaddr,DPOW_SOCK)); + printf("NN_CONNECT to (%s)\n",str); retval = nn_connect(myinfo->dexsock,nanomsg_tcpname(str,ipaddr,DEX_SOCK)); } n++; @@ -242,7 +243,7 @@ int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *i else dp->numipbits = n; //for (i=0; inumdpowipbits,dp!=0?dp->numipbits:-1,iter); + //printf("addnotary.[%d] (%s) retval.%d (total %d %d) iter.%d\n",n,ipaddr,retval,myinfo->numdpowipbits,dp!=0?dp->numipbits:-1,iter); } if ( dp == 0 ) break; @@ -716,7 +717,7 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru } } -void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,struct dpow_nanoutxo *np,int32_t isratify,int8_t senderind) +void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_block *bp,struct dpow_nanoutxo *np,int32_t isratify,int8_t senderind,uint32_t channel) { if ( isratify != 0 ) { @@ -725,7 +726,7 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d else { dpow_notarize_update(myinfo,dp,bp,senderind,(int8_t)np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); - printf("lag.[%d] RECV.%d r%llx (%d %llx) %llx/%llx\n",(int32_t)(time(NULL)-np->channel),senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); + printf("lag.[%d] RECV.%d r%llx (%d %llx) %llx/%llx\n",(int32_t)(time(NULL)-channel),senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); } @@ -794,7 +795,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo } portable_mutex_unlock(&myinfo->dpowmutex); free(np); - printf("%d NANOSEND.%s ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",i,sentbytes,np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); + printf("%d NANOSEND.%d ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",i,sentbytes,np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); } void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *ipbits,int32_t numipbits,int32_t fromid,uint32_t senderipbits) @@ -880,8 +881,8 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) if ( memcmp(bp->notaries[np->senderind].pubkey+1,np->srchash.bytes,32) == 0 && bits256_nonz(np->srchash) != 0 ) { if ( bp->isratify == 0 ) - dpow_nanoutxoget(myinfo,dp,bp,&np->notarize,0,np->senderind); - else dpow_nanoutxoget(myinfo,dp,bp,&np->ratify,1,np->senderind); + dpow_nanoutxoget(myinfo,dp,bp,&np->notarize,0,np->senderind,np->channel); + else dpow_nanoutxoget(myinfo,dp,bp,&np->ratify,1,np->senderind,np->channel); dpow_datahandler(myinfo,dp,bp,np->senderind,np->channel,np->height,np->packet,np->datalen); } else printf("wrong senderind.%d\n",np->senderind); } From 0479c42f668f18ba18f1972a9fb84d8e2f49cd4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 15:08:05 +0200 Subject: [PATCH 29/32] test --- iguana/dpow/dpow_network.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 88060ad6d..b157681f4 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -234,7 +234,7 @@ int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *i { retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(str,ipaddr,DPOW_SOCK)); printf("NN_CONNECT to (%s)\n",str); - retval = nn_connect(myinfo->dexsock,nanomsg_tcpname(str,ipaddr,DEX_SOCK)); + //retval = nn_connect(myinfo->dexsock,nanomsg_tcpname(str,ipaddr,DEX_SOCK)); } n++; qsort(ptr,n,sizeof(uint32_t),_increasing_ipbits); @@ -272,7 +272,7 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) else { printf("NN_BIND to %s\n",str); - if ( myinfo->dexsock < 0 && (myinfo->dexsock= nn_socket(AF_SP,NN_BUS)) >= 0 ) + /*if ( myinfo->dexsock < 0 && (myinfo->dexsock= nn_socket(AF_SP,NN_BUS)) >= 0 ) { if ( nn_bind(myinfo->dexsock,nanomsg_tcpname(str,myinfo->ipaddr,DEX_SOCK)) < 0 ) { @@ -314,14 +314,10 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) } else { - myinfo->dpowipbits[0] = (uint32_t)calc_ipbits(myinfo->ipaddr); - myinfo->numdpowipbits = 1; timeout = 1000; - nn_setsockopt(myinfo->dpowsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(myinfo->dexsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); nn_setsockopt(myinfo->repsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); maxsize = 1024 * 1024; - printf("RCVBUF.%d\n",nn_setsockopt(myinfo->dpowsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); printf("RCVBUF.%d\n",nn_setsockopt(myinfo->dexsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); printf("RCVBUF.%d\n",nn_setsockopt(myinfo->repsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); printf("DEXINIT dpow.%d dex.%d rep.%d\n",myinfo->dpowsock,myinfo->dexsock,myinfo->repsock); @@ -331,7 +327,13 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) } } } - } + }*/ + myinfo->dpowipbits[0] = (uint32_t)calc_ipbits(myinfo->ipaddr); + myinfo->numdpowipbits = 1; + timeout = 1000; + nn_setsockopt(myinfo->dpowsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); + maxsize = 1024 * 1024; + printf("RCVBUF.%d\n",nn_setsockopt(myinfo->dpowsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); } } dpow_addnotary(myinfo,0,ipaddr); From d6e560d0bb3693a44dc373ec89ea046545ab2fd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 15:18:25 +0200 Subject: [PATCH 30/32] test --- iguana/dpow/dpow_network.c | 59 ++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index b157681f4..ff1ea8690 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -335,7 +335,7 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) maxsize = 1024 * 1024; printf("RCVBUF.%d\n",nn_setsockopt(myinfo->dpowsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); } - } + } else printf("error creating nanosocket\n"); dpow_addnotary(myinfo,0,ipaddr); } @@ -845,10 +845,18 @@ void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t * int32_t dpow_nanomsg_update(struct supernet_info *myinfo) { int32_t i,n=0,num=0,size,firstz = -1; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; - if ( time(NULL) < myinfo->nanoinit+5 ) + if ( time(NULL) < myinfo->nanoinit+5 || myinfo->dpowsock < 0 ) return(-1); portable_mutex_lock(&myinfo->dpowmutex); - if ( (size= nn_recv(myinfo->dpowsock,&np,NN_MSG,0)) >= 0 ) + for (i=0; i<100; i++) + { + struct nn_pollfd pfd; + pfd.fd = myinfo->dpowsock; + pfd.events = NN_POLLIN; + if ( nn_poll(&pfd,1,100) > 0 ) + break; + } + if ( i < 100 && (size= nn_recv(myinfo->dpowsock,&np,NN_MSG,0)) >= 0 ) { num++; if ( size >= 0 ) @@ -900,34 +908,37 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) } else printf("no packets\n"); portable_mutex_unlock(&myinfo->dpowmutex); n = 0; - if ( (size= nn_recv(myinfo->dexsock,&dexp,NN_MSG,0)) >= 0 ) + if ( myinfo->dexsock >= 0 ) { - num++; - if ( dex_packetcheck(myinfo,dexp,size) == 0 ) + if ( (size= nn_recv(myinfo->dexsock,&dexp,NN_MSG,0)) >= 0 ) { - printf("FROM BUS.%08x -> pub\n",dexp->crc32); - nn_send(myinfo->pubsock,dexp,size,0); - dex_packet(myinfo,dexp,size); + num++; + if ( dex_packetcheck(myinfo,dexp,size) == 0 ) + { + printf("FROM BUS.%08x -> pub\n",dexp->crc32); + nn_send(myinfo->pubsock,dexp,size,0); + dex_packet(myinfo,dexp,size); + } + if ( dexp != 0 ) + nn_freemsg(dexp), dexp = 0; } - if ( dexp != 0 ) - nn_freemsg(dexp), dexp = 0; - } - if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) >= 0 ) - { - num++; - if ( dex_packetcheck(myinfo,dexp,size) == 0 ) + if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) >= 0 ) { - nn_send(myinfo->dexsock,dexp,size,0); - if ( (m= myinfo->numdpowipbits) > 0 ) + num++; + if ( dex_packetcheck(myinfo,dexp,size) == 0 ) { - r = myinfo->dpowipbits[rand() % m]; - nn_send(myinfo->repsock,&r,sizeof(r),0); - printf("REP.%08x -> dexbus, rep.%08x",dexp->crc32,r); + nn_send(myinfo->dexsock,dexp,size,0); + if ( (m= myinfo->numdpowipbits) > 0 ) + { + r = myinfo->dpowipbits[rand() % m]; + nn_send(myinfo->repsock,&r,sizeof(r),0); + printf("REP.%08x -> dexbus, rep.%08x",dexp->crc32,r); + } + dex_packet(myinfo,dexp,size); } - dex_packet(myinfo,dexp,size); + if ( dexp != 0 ) + nn_freemsg(dexp), dexp = 0; } - if ( dexp != 0 ) - nn_freemsg(dexp), dexp = 0; } return(num); } From e6498ec0d5acefb37d3145fafd3ee01d7d10cd84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 15:22:50 +0200 Subject: [PATCH 31/32] test --- iguana/dpow/dpow_network.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index ff1ea8690..36c1ba6b8 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -208,7 +208,7 @@ void dpow_sigscheck(struct supernet_info *myinfo,struct dpow_info *dp,struct dpo int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *ipaddr) { char str[512]; uint32_t ipbits,*ptr; int32_t i,iter,n,retval = -1; - if ( myinfo->dpowsock >= 0 ) + if ( myinfo->dpowsock >= 0 && myinfo->dexsock >= 0 ) { portable_mutex_lock(&myinfo->notarymutex); ipbits = (uint32_t)calc_ipbits(ipaddr); @@ -234,7 +234,7 @@ int32_t dpow_addnotary(struct supernet_info *myinfo,struct dpow_info *dp,char *i { retval = nn_connect(myinfo->dpowsock,nanomsg_tcpname(str,ipaddr,DPOW_SOCK)); printf("NN_CONNECT to (%s)\n",str); - //retval = nn_connect(myinfo->dexsock,nanomsg_tcpname(str,ipaddr,DEX_SOCK)); + retval = nn_connect(myinfo->dexsock,nanomsg_tcpname(str,ipaddr,DEX_SOCK)); } n++; qsort(ptr,n,sizeof(uint32_t),_increasing_ipbits); @@ -272,7 +272,7 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) else { printf("NN_BIND to %s\n",str); - /*if ( myinfo->dexsock < 0 && (myinfo->dexsock= nn_socket(AF_SP,NN_BUS)) >= 0 ) + if ( myinfo->dexsock < 0 && (myinfo->dexsock= nn_socket(AF_SP,NN_BUS)) >= 0 ) { if ( nn_bind(myinfo->dexsock,nanomsg_tcpname(str,myinfo->ipaddr,DEX_SOCK)) < 0 ) { @@ -321,19 +321,19 @@ void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) printf("RCVBUF.%d\n",nn_setsockopt(myinfo->dexsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); printf("RCVBUF.%d\n",nn_setsockopt(myinfo->repsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); printf("DEXINIT dpow.%d dex.%d rep.%d\n",myinfo->dpowsock,myinfo->dexsock,myinfo->repsock); - myinfo->nanoinit = (uint32_t)time(NULL); } } } } } - }*/ + } myinfo->dpowipbits[0] = (uint32_t)calc_ipbits(myinfo->ipaddr); myinfo->numdpowipbits = 1; timeout = 1000; nn_setsockopt(myinfo->dpowsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); maxsize = 1024 * 1024; printf("RCVBUF.%d\n",nn_setsockopt(myinfo->dpowsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize))); + myinfo->nanoinit = (uint32_t)time(NULL); } } else printf("error creating nanosocket\n"); dpow_addnotary(myinfo,0,ipaddr); @@ -783,7 +783,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo np->version1 = (DPOW_VERSION >> 8) & 0xff; memcpy(np->packet,data,datalen); sentbytes = -1; - portable_mutex_lock(&myinfo->dpowmutex); + //portable_mutex_lock(&myinfo->dpowmutex); for (i=0; i<100; i++) { struct nn_pollfd pfd; @@ -795,7 +795,7 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo break; } } - portable_mutex_unlock(&myinfo->dpowmutex); + //portable_mutex_unlock(&myinfo->dpowmutex); free(np); printf("%d NANOSEND.%d ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",i,sentbytes,np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); } @@ -847,7 +847,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) int32_t i,n=0,num=0,size,firstz = -1; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; if ( time(NULL) < myinfo->nanoinit+5 || myinfo->dpowsock < 0 ) return(-1); - portable_mutex_lock(&myinfo->dpowmutex); + //portable_mutex_lock(&myinfo->dpowmutex); for (i=0; i<100; i++) { struct nn_pollfd pfd; @@ -906,7 +906,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) if ( np != 0 ) nn_freemsg(np), np = 0; } else printf("no packets\n"); - portable_mutex_unlock(&myinfo->dpowmutex); + //portable_mutex_unlock(&myinfo->dpowmutex); n = 0; if ( myinfo->dexsock >= 0 ) { From 312aa1e294e3e6ef6b7e63cb43ff9e383ade6708 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 20 Dec 2016 15:24:55 +0200 Subject: [PATCH 32/32] test --- iguana/dpow/dpow_network.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/iguana/dpow/dpow_network.c b/iguana/dpow/dpow_network.c index 36c1ba6b8..37788ae27 100755 --- a/iguana/dpow/dpow_network.c +++ b/iguana/dpow/dpow_network.c @@ -689,10 +689,11 @@ void dpow_notarize_update(struct supernet_info *myinfo,struct dpow_info *dp,stru } } } - if ( bp->notaries[i].paxwdcrc != 0 ) + if ( bp->myind <= 2 && bp->notaries[i].paxwdcrc != 0 ) printf("%d.(%x %d %llx r%llx) ",i,bp->notaries[i].paxwdcrc,bp->notaries[i].bestk,(long long)bp->notaries[i].bestmask,(long long)bp->notaries[i].recvmask); } - printf("recv.%llx best.(%d %llx) m.%d p.%d:%d b.%d\n",(long long)bp->recvmask,bp->bestk,(long long)bp->bestmask,matches,paxmatches,paxbestmatches,bestmatches); + if ( bp->myind <= 2 ) + printf("recv.%llx best.(%d %llx) m.%d p.%d:%d b.%d\n",(long long)bp->recvmask,bp->bestk,(long long)bp->bestmask,matches,paxmatches,paxbestmatches,bestmatches); if ( bestmatches >= bp->minsigs && paxbestmatches >= bp->minsigs ) { if ( bp->pendingbestk != bp->bestk || bp->pendingbestmask != bp->bestmask ) @@ -728,7 +729,8 @@ void dpow_nanoutxoget(struct supernet_info *myinfo,struct dpow_info *dp,struct d else { dpow_notarize_update(myinfo,dp,bp,senderind,(int8_t)np->bestk,np->bestmask,np->recvmask,np->srcutxo,np->srcvout,np->destutxo,np->destvout,np->siglens,np->sigs,np->paxwdcrc); - printf("lag.[%d] RECV.%d r%llx (%d %llx) %llx/%llx\n",(int32_t)(time(NULL)-channel),senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); + if ( bp->myind <= 2 ) + printf("lag.[%d] RECV.%d r%llx (%d %llx) %llx/%llx\n",(int32_t)(time(NULL)-channel),senderind,(long long)np->recvmask,(int8_t)np->bestk,(long long)np->bestmask,(long long)np->srcutxo.txid,(long long)np->destutxo.txid); } //dpow_bestmask_update(myinfo,dp,bp,nn_senderind,nn_bestk,nn_bestmask,nn_recvmask); } @@ -797,7 +799,8 @@ void dpow_send(struct supernet_info *myinfo,struct dpow_info *dp,struct dpow_blo } //portable_mutex_unlock(&myinfo->dpowmutex); free(np); - printf("%d NANOSEND.%d ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",i,sentbytes,np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); + if ( bp->myind <= 2 ) + printf("%d NANOSEND.%d ht.%d channel.%08x (%d) pax.%08x datalen.%d (%d %llx) (%d %llx) recv.%llx\n",i,sentbytes,np->height,np->channel,size,np->notarize.paxwdcrc,datalen,(int8_t)np->notarize.bestk,(long long)np->notarize.bestmask,bp->notaries[bp->myind].bestk,(long long)bp->notaries[bp->myind].bestmask,(long long)bp->recvmask); } void dpow_ipbitsadd(struct supernet_info *myinfo,struct dpow_info *dp,uint32_t *ipbits,int32_t numipbits,int32_t fromid,uint32_t senderipbits)