|
@ -52,7 +52,7 @@ int32_t signed_nn_send(void *ctx,bits256 privkey,int32_t sock,void *packet,int32 |
|
|
} |
|
|
} |
|
|
return(-1); |
|
|
return(-1); |
|
|
} |
|
|
} |
|
|
|
|
|
//dex* api
|
|
|
int32_t signed_nn_recv(void **freeptrp,void *ctx,struct dpow_entry *notaries,int32_t n,int32_t sock,void *packetp) |
|
|
int32_t signed_nn_recv(void **freeptrp,void *ctx,struct dpow_entry *notaries,int32_t n,int32_t sock,void *packetp) |
|
|
{ |
|
|
{ |
|
|
int32_t i,recvbytes; uint8_t pubkey33[33]; bits256 packethash; struct signed_nnpacket *sigpacket=0; |
|
|
int32_t i,recvbytes; uint8_t pubkey33[33]; bits256 packethash; struct signed_nnpacket *sigpacket=0; |
|
@ -243,7 +243,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3 |
|
|
pfd.events = NN_POLLOUT; |
|
|
pfd.events = NN_POLLOUT; |
|
|
if ( nn_poll(&pfd,1,100) > 0 ) |
|
|
if ( nn_poll(&pfd,1,100) > 0 ) |
|
|
{ |
|
|
{ |
|
|
sentbytes = signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->reqsock,dexp,size); |
|
|
sentbytes = nn_send(myinfo->reqsock,dexp,size,0); |
|
|
//printf(" sent.%d:%d datalen.%d\n",sentbytes,size,datalen);
|
|
|
//printf(" sent.%d:%d datalen.%d\n",sentbytes,size,datalen);
|
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
@ -253,12 +253,12 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3 |
|
|
// printf("%02x",((uint8_t *)data)[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->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->reqsock,&retptr)) >= 0 ) |
|
|
{ |
|
|
{ |
|
|
//printf("req returned.[%d]\n",recvbytes);
|
|
|
printf("req returned.[%d]\n",recvbytes); |
|
|
portable_mutex_lock(&myinfo->dexmutex); |
|
|
portable_mutex_lock(&myinfo->dexmutex); |
|
|
ipbits = 0; |
|
|
ipbits = 0; |
|
|
if ( strcmp(handler,"DEX") == 0 ) |
|
|
if ( strcmp(handler,"DEX") == 0 ) |
|
|
ipbits = *retptr; |
|
|
ipbits = *retptr; |
|
|
else |
|
|
else if ( retptr != 0 ) |
|
|
{ |
|
|
{ |
|
|
retstr = clonestr((char *)retptr); |
|
|
retstr = clonestr((char *)retptr); |
|
|
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|
|
if ( (retjson= cJSON_Parse(retstr)) != 0 ) |
|
@ -288,7 +288,7 @@ char *_dex_reqsend(struct supernet_info *myinfo,char *handler,uint8_t *data,int3 |
|
|
printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str); |
|
|
printf("%d: subscribe connect (%s)\n",myinfo->numdexipbits,str); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
nn_connect(myinfo->reqsock,nanomsg_tcpname(0,str,ipaddr,REP_SOCK)); |
|
|
//nn_connect(myinfo->reqsock,nanomsg_tcpname(0,str,ipaddr,REP_SOCK));
|
|
|
printf("%d: req connect (%s)\n",myinfo->numdexipbits,str); |
|
|
printf("%d: req connect (%s)\n",myinfo->numdexipbits,str); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -693,7 +693,7 @@ int32_t dex_subsock_poll(struct supernet_info *myinfo) |
|
|
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->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->subsock,&dexp)) >= 0 ) |
|
|
{ |
|
|
{ |
|
|
//printf("SUBSOCK.%08x recv.%d datalen.%d\n",dexp->crc32,size,dexp->datalen);
|
|
|
//printf("SUBSOCK.%08x recv.%d datalen.%d\n",dexp->crc32,size,dexp->datalen);
|
|
|
if ( dex_packetcheck(myinfo,dexp,size) == 0 ) |
|
|
if ( dexp != 0 && dex_packetcheck(myinfo,dexp,size) == 0 ) |
|
|
{ |
|
|
{ |
|
|
//printf("SUBSOCK.%08x ",dexp->crc32);
|
|
|
//printf("SUBSOCK.%08x ",dexp->crc32);
|
|
|
dex_packet(myinfo,dexp,size); |
|
|
dex_packet(myinfo,dexp,size); |
|
@ -1564,7 +1564,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
} |
|
|
} |
|
|
if ( myinfo->repsock >= 0 ) // from clients
|
|
|
if ( myinfo->repsock >= 0 ) // from clients
|
|
|
{ |
|
|
{ |
|
|
if ( (size= signed_nn_recv(&freeptr,myinfo->ctx,myinfo->notaries,myinfo->numnotaries,myinfo->repsock,&dexp)) > 0 ) |
|
|
if ( (size= nn_recv(myinfo->repsock,&dexp,NN_MSG,0)) > 0 ) |
|
|
{ |
|
|
{ |
|
|
num++; |
|
|
num++; |
|
|
//fprintf(stderr,"%d ",size);
|
|
|
//fprintf(stderr,"%d ",size);
|
|
@ -1572,6 +1572,7 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 ) |
|
|
if ( (retstr= dex_response(&broadcastflag,myinfo,dexp)) != 0 ) |
|
|
{ |
|
|
{ |
|
|
signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1); |
|
|
signed_nn_send(myinfo->ctx,myinfo->persistent_priv,myinfo->repsock,retstr,(int32_t)strlen(retstr)+1); |
|
|
|
|
|
//printf("send back[%ld]\n",strlen(retstr)+1);
|
|
|
free(retstr); |
|
|
free(retstr); |
|
|
if ( broadcastflag != 0 ) |
|
|
if ( broadcastflag != 0 ) |
|
|
{ |
|
|
{ |
|
@ -1596,8 +1597,10 @@ int32_t dpow_nanomsg_update(struct supernet_info *myinfo) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
//printf("GOT DEX rep PACKET.%d\n",size);
|
|
|
//printf("GOT DEX rep PACKET.%d\n",size);
|
|
|
if ( freeptr != 0 ) |
|
|
//if ( freeptr != 0 )
|
|
|
nn_freemsg(freeptr), dexp = 0, freeptr = 0; |
|
|
// nn_freemsg(freeptr), dexp = 0, freeptr = 0;
|
|
|
|
|
|
if ( dexp != 0 ) |
|
|
|
|
|
nn_freemsg(dexp), dexp = 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
portable_mutex_unlock(&myinfo->dpowmutex); |
|
|
portable_mutex_unlock(&myinfo->dpowmutex); |
|
|