From 900a651c807b57bf709ce3970e82f9cbf62adf9f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 14 Oct 2016 10:19:34 -0300 Subject: [PATCH] test --- README.md | 1 + iguana/dPoW.h | 7 +++-- iguana/iguana_notary.c | 68 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fa810da44..4145b8496 100755 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ the idea is to issue a curl command into a /tmp/file and then use jsoncmp to ver ##### ../agents/iguana notary 0.Have iguana installed at http://wiki.supernet.org/wiki/How_To_Install_Iguana_on_Linux also install nanomsg: sudo apt-get install libnanomsg-dev +ports 7774 and 7775 will be used cd Supernet/iguana --> diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 07a56963c..da701c244 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -34,7 +34,7 @@ struct dpow_entry uint64_t masks[DPOW_MAXRELAYS],recvmask; int32_t prev_vout,height; int8_t bestk; - uint8_t pubkey[33],siglens[DPOW_MAXRELAYS],sigs[DPOW_MAXRELAYS][76]; + uint8_t pubkey[33],siglens[DPOW_MAXRELAYS],sigs[DPOW_MAXRELAYS][0x100]; }; struct dpow_sigentry @@ -42,7 +42,7 @@ struct dpow_sigentry bits256 beacon; uint64_t mask; int32_t refcount; - uint8_t senderind,lastk,siglen,sig[80],senderpub[33]; + uint8_t senderind,lastk,siglen,sig[0x100],senderpub[33]; }; struct komodo_notaries @@ -64,7 +64,7 @@ struct dpow_block uint32_t state,timestamp,waiting,sigcrcs[2],txidcrcs[2],utxocrcs[2]; int32_t height,numnotaries,completed; int8_t bestk; - char signedtx[32768],rawtx[32768]; + char signedtx[32768];//,rawtx[32768]; }; struct dpow_info @@ -74,6 +74,7 @@ struct dpow_info struct dpow_hashheight approved[DPOW_FIFOSIZE],notarized[DPOW_FIFOSIZE]; bits256 srctx[DPOW_MAXTX],desttx[DPOW_MAXTX]; uint32_t destupdated,srcconfirms,numdesttx,numsrctx,lastsplit; + int32_t sock; struct dpow_block **srcblocks,**destblocks; }; diff --git a/iguana/iguana_notary.c b/iguana/iguana_notary.c index 709d92078..0a1bf3375 100755 --- a/iguana/iguana_notary.c +++ b/iguana/iguana_notary.c @@ -28,17 +28,80 @@ #if ISNOTARYNODE +struct dpow_nanomsghdr +{ + bits256 srchash,desthash; + uint32_t channel,height,size,crc32; + uint8_t packet[]; +}; + +char *nanomsg_tcpname(char *str,char *ipaddr) +{ + sprintf(str,"tcp://%s:7774",ipaddr); + return(str); +} + void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) { - + char str[512]; int32_t timeout; + if ( myinfo->DPOW.sock < 0 && (myinfo->DPOW.sock= nn_socket(AF_SP,NN_BUS)) >= 0 ) + { + if ( nn_bind(myinfo->DPOW.sock,nanomsg_tcpname(str,myinfo->ipaddr)) < 0 ) + { + printf("error binding to (%s)\n",nanomsg_tcpname(str,myinfo->ipaddr)); + nn_close(myinfo->DPOW.sock); + myinfo->DPOW.sock = -1; + } + timeout = 100; + nn_setsockopt(myinfo->DPOW.sock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)); + } + if ( myinfo->DPOW.sock >= 0 && strcmp(ipaddr,myinfo->ipaddr) != 0 ) + nn_connect(myinfo->DPOW.sock,ipaddr); } uint32_t dpow_send(struct supernet_info *myinfo,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t crcs[2]) { - return(basilisk_channelsend(myinfo,srchash,desthash,channel,msgbits,data,datalen,120)); + struct dpow_nanomsghdr *np; int32_t size,sentbytes; + size = (int32_t)(sizeof(*np) + datalen); + np = malloc(size); + np->size = size; + np->crc32 = calc_crc32(0,data,datalen); + np->srchash = srchash; + np->desthash = desthash; + np->channel = channel; + np->height = msgbits; + memcpy(np->packet,data,datalen); + sentbytes = nn_send(myinfo->DPOW.sock,np,size,0); + free(np); + return(sentbytes); + //return(basilisk_channelsend(myinfo,srchash,desthash,channel,msgbits,data,datalen,120)); //return(basilisk_crcsend(myinfo,1,bp->sendbuf,sizeof(bp->sendbuf),srchash,desthash,channel,msgbits,data,datalen,crcs)); } +void dpow_nanomsg_update(struct supernet_info *myinfo) +{ + int32_t size; struct dpow_nanomsghdr *np; + while ( (size= nn_recv(myinfo->DPOW.sock,&np,NN_MSG,0)) >= 0 ) + { + if ( size >= 0 ) + { + printf("NANORECV ht.%d channel.%08x (%d) crc32.%08x\n",np->height,np->channel,size,np->crc32); + if ( np != 0 ) + nn_freemsg(np); + } + } +} +#else + +void dpow_nanomsginit(struct supernet_info *myinfo,char *ipaddr) { } + +uint32_t dpow_send(struct supernet_info *myinfo,struct dpow_block *bp,bits256 srchash,bits256 desthash,uint32_t channel,uint32_t msgbits,uint8_t *data,int32_t datalen,uint32_t crcs[2]) +{ + return(0); +} + +void dpow_nanomsg_update(struct supernet_info *myinfo) { } + #endif #define CHECKSIG 0xac @@ -1315,6 +1378,7 @@ void dpow_destupdate(struct supernet_info *myinfo,struct dpow_info *dp,int32_t h void iguana_dPoWupdate(struct supernet_info *myinfo) { int32_t height; char str[65]; uint32_t blocktime; bits256 blockhash; struct iguana_info *src,*dest; struct dpow_info *dp = &myinfo->DPOW; + dpow_nanomsg_update(myinfo); src = iguana_coinfind(dp->symbol); dest = iguana_coinfind(dp->dest); if ( src != 0 && dest != 0 )