|
|
@ -1888,7 +1888,7 @@ 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,broadcastflag,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; void *freeptr; |
|
|
|
int32_t i,n,num,num2,flags=0,size,iter,broadcastflag,firstz = -1; char *retstr; uint32_t crc32,r,m; struct dpow_nanomsghdr *np=0; struct dpow_info *dp; struct dpow_block *bp; struct dex_nanomsghdr *dexp = 0; void *freeptr; |
|
|
|
if ( time(NULL) < myinfo->nanoinit+5 || (myinfo->dpowsock < 0 && myinfo->dexsock < 0 && myinfo->repsock < 0) ) |
|
|
|
return(-1); |
|
|
|
if ( myinfo->IAMNOTARY != 0 && myinfo->numnotaries <= 0 ) |
|
|
@ -1897,16 +1897,10 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
|
printf("INIT with %d notaries\n",myinfo->numnotaries); |
|
|
|
} |
|
|
|
portable_mutex_lock(&myinfo->dpowmutex); |
|
|
|
/*for (i=0; i<100; i++)
|
|
|
|
num = num2 = n = 0; |
|
|
|
for (iter=0; iter<1000; iter++) |
|
|
|
{ |
|
|
|
struct nn_pollfd pfd; |
|
|
|
pfd.fd = myinfo->dpowsock; |
|
|
|
pfd.events = NN_POLLIN; |
|
|
|
if ( nn_poll(&pfd,1,100) > 0 ) |
|
|
|
break; |
|
|
|
usleep(1000); |
|
|
|
}*/ |
|
|
|
while ( (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) >= 0 && num < 1000 ) |
|
|
|
if ( (flags & 1) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) >= 0 ) |
|
|
|
{ |
|
|
|
num++; |
|
|
|
if ( size > 0 ) |
|
|
@ -1953,14 +1947,13 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
|
} //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 ( freeptr != 0 ) |
|
|
|
nn_freemsg(freeptr), np = 0, freeptr = 0; |
|
|
|
} //else printf("no packets\n");
|
|
|
|
n = 0; |
|
|
|
} else flag |= 1; |
|
|
|
if ( myinfo->dexsock >= 0 ) // from servers
|
|
|
|
{ |
|
|
|
while ( (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 && n < 1000 ) |
|
|
|
if ( (flags & 2) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 ) |
|
|
|
{ |
|
|
|
//fprintf(stderr,"%d ",size);
|
|
|
|
n++; |
|
|
@ -1973,14 +1966,13 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
|
//printf("GOT DEX bus PACKET.%d\n",size);
|
|
|
|
if ( freeptr != 0 ) |
|
|
|
nn_freemsg(freeptr), dexp = 0, freeptr = 0; |
|
|
|
} |
|
|
|
} else flags |= 2; |
|
|
|
} |
|
|
|
if ( myinfo->repsock >= 0 ) // from clients
|
|
|
|
{ |
|
|
|
num = 0; |
|
|
|
while ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 ) |
|
|
|
if ( (flags & 4) == 0 && (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 ) |
|
|
|
{ |
|
|
|
num++; |
|
|
|
num2++; |
|
|
|
printf("REP got %d crc.%08x\n",size,calc_crc32(0,(void *)dexp,size)); |
|
|
|
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 ) |
|
|
|
{ |
|
|
@ -2014,10 +2006,11 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
|
// nn_freemsg(freeptr), dexp = 0, freeptr = 0;
|
|
|
|
if ( dexp != 0 ) |
|
|
|
nn_freemsg(dexp), dexp = 0; |
|
|
|
if ( num > 1000 ) |
|
|
|
break; |
|
|
|
//if ( num > 1000 )
|
|
|
|
// break;
|
|
|
|
} else flags |= 4; |
|
|
|
printf("num.%d n.%d num2.%d rep packets\n",num,n,num2); |
|
|
|
} |
|
|
|
printf("num.%d rep packets\n",num); |
|
|
|
} |
|
|
|
portable_mutex_unlock(&myinfo->dpowmutex); |
|
|
|
return(num); |
|
|
|