|
|
@ -140,12 +140,23 @@ int32_t signed_nn_send(struct supernet_info *myinfo,void *ctx,bits256 privkey,in |
|
|
|
return(-1); |
|
|
|
} |
|
|
|
|
|
|
|
int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_t n,int32_t sock,void *packetp) |
|
|
|
int32_t signed_nn_recv(void **freeptrp,struct supernet_info *myinfo,uint8_t notaries[64][33],int32_t n,int32_t sock,void *packetp) |
|
|
|
{ |
|
|
|
int32_t i,recvbytes; uint8_t pubkey33[33],pubkey0[33]; bits256 packethash; struct signed_nnpacket *sigpacket=0; |
|
|
|
*(void **)packetp = 0; |
|
|
|
*freeptrp = 0; |
|
|
|
if ( (recvbytes= nn_recv(sock,&sigpacket,NN_MSG,0)) > 0 ) |
|
|
|
for (i=0; i<100; i++) |
|
|
|
{ |
|
|
|
struct nn_pollfd pfd; |
|
|
|
pfd.fd = myinfo->reqsock; |
|
|
|
pfd.events = NN_POLLIN; |
|
|
|
if ( nn_poll(&pfd,1,100) > 0 ) |
|
|
|
break; |
|
|
|
usleep(1000); |
|
|
|
} |
|
|
|
if ( i == 100 ) |
|
|
|
recvbytes = 0; |
|
|
|
else if ( (recvbytes= nn_recv(sock,&sigpacket,NN_MSG,0)) > 0 ) |
|
|
|
{ |
|
|
|
//for (i=0; i<recvbytes; i++)
|
|
|
|
// printf("%02x",((uint8_t *)sigpacket)[i]);
|
|
|
@ -156,7 +167,7 @@ int32_t signed_nn_recv(void **freeptrp,void *ctx,uint8_t notaries[64][33],int32_ |
|
|
|
vcalc_sha256(0,packethash.bytes,(void *)&sigpacket->nonce,(int32_t)(sigpacket->packetlen+sizeof(sigpacket->nonce)+sizeof(sigpacket->packetlen))); |
|
|
|
if ( bits256_cmp(packethash,sigpacket->packethash) == 0 && sigpacket->packethash.bytes[0] == 0 ) |
|
|
|
{ |
|
|
|
if ( bitcoin_recoververify(ctx,"nnrecv",sigpacket->sig64,sigpacket->packethash,pubkey33,33) == 0 ) |
|
|
|
if ( bitcoin_recoververify(myinfo->ctx,"nnrecv",sigpacket->sig64,sigpacket->packethash,pubkey33,33) == 0 ) |
|
|
|
{ |
|
|
|
char *notary0 = "03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828"; |
|
|
|
// expand to official notaries
|
|
|
@ -474,7 +485,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *key,int32 |
|
|
|
} |
|
|
|
//for (i=0; i<datalen; i++)
|
|
|
|
// printf("%02x",((uint8_t *)data)[i]);
|
|
|
|
if ( (recvbytes= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->reqsock,&retptr)) >= 0 ) |
|
|
|
if ( (recvbytes= signed_nn_recv(&freeptr,myinfo,myinfo->notaries,myinfo->numnotaries,myinfo->reqsock,&retptr)) >= 0 ) |
|
|
|
{ |
|
|
|
//printf("req returned.[%d]\n",recvbytes);
|
|
|
|
portable_mutex_lock(&myinfo->dexmutex); |
|
|
@ -819,7 +830,7 @@ char *dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int32 |
|
|
|
{ |
|
|
|
if ( (retstrs[j]= _dex_reqsend(myinfo,handler,0,0,data,datalen)) != 0 ) |
|
|
|
{ |
|
|
|
//printf("j.%d of max.%d M.%d (%s)\n",j,max,M,retstrs[j]);
|
|
|
|
printf("j.%d of max.%d M.%d (%s)\n",j,max,M,retstrs[j]); |
|
|
|
if ( strncmp(retstrs[j],"{\"error\":\"null return\"}",strlen("{\"error\":\"null return\"}")) != 0 && strncmp(retstrs[j],"[]",strlen("[]")) != 0 && strcmp("0",retstrs[j]) != 0 ) |
|
|
|
{ |
|
|
|
if ( ++j == M ) |
|
|
@ -1265,7 +1276,7 @@ int32_t dex_subsock_poll(struct supernet_info *myinfo) |
|
|
|
int32_t size= -1; struct dex_nanomsghdr *dexp; void *freeptr; |
|
|
|
//return(0);
|
|
|
|
//fprintf(stderr,"subsock.%d\n",myinfo->subsock);
|
|
|
|
if ( myinfo->subsock >= 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->subsock,&dexp)) >= 0 ) |
|
|
|
if ( myinfo->subsock >= 0 && (size= signed_nn_recv(&freeptr,myinfo,myinfo->notaries,myinfo->numnotaries,myinfo->subsock,&dexp)) >= 0 ) |
|
|
|
{ |
|
|
|
if ( dexp != 0 ) |
|
|
|
{ |
|
|
@ -2071,7 +2082,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
|
for (iter=0; iter<100; iter++) |
|
|
|
{ |
|
|
|
freeptr = 0; |
|
|
|
if ( (flags & 1) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) > 0 ) |
|
|
|
if ( (flags & 1) == 0 && (size= signed_nn_recv(&freeptr,myinfo,myinfo->notaries,myinfo->numnotaries,myinfo->dpowsock,&np)) > 0 ) |
|
|
|
{ |
|
|
|
num++; |
|
|
|
if ( size > 0 ) |
|
|
@ -2125,7 +2136,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
|
if ( myinfo->dexsock >= 0 ) // from servers
|
|
|
|
{ |
|
|
|
freeptr = 0; |
|
|
|
if ( (flags & 2) == 0 && (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 ) |
|
|
|
if ( (flags & 2) == 0 && (size= signed_nn_recv(&freeptr,myinfo,myinfo->notaries,myinfo->numnotaries,myinfo->dexsock,&dexp)) > 0 ) |
|
|
|
{ |
|
|
|
//fprintf(stderr,"%d ",size);
|
|
|
|
n++; |
|
|
|