From 4f6fa87d6d0f8203f4997581bcc6bc5e22ee18e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 26 Jun 2016 07:34:43 -0300 Subject: [PATCH] test --- basilisk/basilisk.c | 116 ++++++++++++++++++++++------------------ basilisk/basilisk.h | 2 +- basilisk/basilisk_CMD.c | 3 +- 3 files changed, 68 insertions(+), 53 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 21bc468d3..95a2a9de8 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -517,56 +517,6 @@ void basilisk_result(struct supernet_info *myinfo,char *remoteaddr,uint32_t basi } else printf("null vals.(%s) or no hexmsg.%p\n",jprint(vals,0),vals); } -void basilisks_loop(void *arg) -{ - struct iguana_info *virt,*tmpcoin,*btcd; struct basilisk_item *tmp,*pending; int32_t iter,maxmillis,flag=0; struct supernet_info *myinfo = arg; - iter = 0; - while ( 1 ) - { - portable_mutex_lock(&myinfo->basilisk_mutex); - HASH_ITER(hh,myinfo->basilisks.issued,pending,tmp) - { - if ( pending != 0 && (pending->finished != 0 || OS_milliseconds() > pending->expiration+60) ) - { - HASH_DELETE(hh,myinfo->basilisks.issued,pending); - free(pending); - } - } - portable_mutex_unlock(&myinfo->basilisk_mutex); - //if ( myinfo->allcoins_numvirts > 0 ) - if ( (btcd= iguana_coinfind("BTCD")) != 0 ) - { - maxmillis = (10000 / (myinfo->allcoins_numvirts + 1)) + 1; - //portable_mutex_lock(&myinfo->allcoins_mutex); - HASH_ITER(hh,myinfo->allcoins,virt,tmpcoin) - { - if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 ) - { - gecko_iteration(myinfo,btcd,virt,maxmillis), flag++; - } - } - //portable_mutex_unlock(&myinfo->allcoins_mutex); - } - - //fprintf(stderr,"i "); - //for (i=0; iRELAYNODE == 0 && coin->VALIDATENODE == 0 && coin->active != 0 && coin->chain->userpass[0] != 0 && coin->MAXPEERS == 1 ) - // basilisk_bitcoinscan(coin,blockspace,&RAWMEM); - if ( flag == 0 ) - usleep(1000000); - } -} - -void basilisks_init(struct supernet_info *myinfo) -{ - //iguana_initQ(&myinfo->basilisks.submitQ,"submitQ"); - //iguana_initQ(&myinfo->basilisks.resultsQ,"resultsQ"); - portable_mutex_init(&myinfo->allcoins_mutex); - portable_mutex_init(&myinfo->basilisk_mutex); - portable_mutex_init(&myinfo->gecko_mutex); - myinfo->basilisks.launched = iguana_launch(iguana_coinfind("BTCD"),"basilisks_loop",basilisks_loop,myinfo,IGUANA_PERMTHREAD); -} - void basilisk_wait(struct supernet_info *myinfo,struct iguana_info *coin) { if ( coin != 0 ) @@ -586,7 +536,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende cJSON *valsobj; char *symbol,*retstr=0,remoteaddr[64],CMD[4],cmd[4]; int32_t height,origlen,from_basilisk,i,timeoutmillis,flag,numrequired,jsonlen; uint8_t *origdata; struct iguana_info *coin=0; bits256 hash; struct iguana_peer *addr = _addr; static basilisk_servicefunc *basilisk_services[][2] = { - { (void *)"RUN", &basilisk_respond_dispatch }, // higher level protocol handler, pass through + { (void *)"PIN", &basilisk_respond_ping }, { (void *)"BYE", &basilisk_respond_goodbye }, // disconnect // gecko chains @@ -711,4 +661,68 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende myinfo->basilisk_busy = 0; } +void basilisks_loop(void *arg) +{ + struct iguana_info *virt,*tmpcoin,*btcd; struct basilisk_item *tmp,*pending; int32_t iter,maxmillis,flag=0; struct supernet_info *myinfo = arg; + iter = 0; + while ( 1 ) + { + portable_mutex_lock(&myinfo->basilisk_mutex); + HASH_ITER(hh,myinfo->basilisks.issued,pending,tmp) + { + if ( pending != 0 && (pending->finished != 0 || OS_milliseconds() > pending->expiration+60) ) + { + HASH_DELETE(hh,myinfo->basilisks.issued,pending); + free(pending); + } + } + portable_mutex_unlock(&myinfo->basilisk_mutex); + //if ( myinfo->allcoins_numvirts > 0 ) + if ( (btcd= iguana_coinfind("BTCD")) != 0 ) + { + maxmillis = (10000 / (myinfo->allcoins_numvirts + 1)) + 1; + //portable_mutex_lock(&myinfo->allcoins_mutex); + HASH_ITER(hh,myinfo->allcoins,virt,tmpcoin) + { + if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 ) + { + gecko_iteration(myinfo,btcd,virt,maxmillis), flag++; + } + } + //portable_mutex_unlock(&myinfo->allcoins_mutex); + } + if ( myinfo->RELAYID >= 0 ) + { + struct basilisk_relay *rp; int32_t i,j,datalen=0; uint8_t data[1024]; + for (i=0; inumrelays; i++) + { + rp = &myinfo->relays[i]; + if ( rp->addr != 0 && rp->addr->usock >= 0 ) + { + data[datalen++] = myinfo->numrelays; + for (j=0; jnumrelays; j++) + data[datalen++] = myinfo->relays[j].status; + if ( iguana_queue_send(rp->addr,0,&data[sizeof(struct iguana_msghdr)],"SuperNET",datalen) != datalen ) + printf("error sending %d to (%s)\n",datalen,rp->addr->ipaddr); + else printf("sent %d to (%s)\n",datalen,rp->addr->ipaddr); + } + } + } + //fprintf(stderr,"i "); + //for (i=0; iRELAYNODE == 0 && coin->VALIDATENODE == 0 && coin->active != 0 && coin->chain->userpass[0] != 0 && coin->MAXPEERS == 1 ) + // basilisk_bitcoinscan(coin,blockspace,&RAWMEM); + if ( flag == 0 ) + usleep(1000000); + } +} +void basilisks_init(struct supernet_info *myinfo) +{ + //iguana_initQ(&myinfo->basilisks.submitQ,"submitQ"); + //iguana_initQ(&myinfo->basilisks.resultsQ,"resultsQ"); + portable_mutex_init(&myinfo->allcoins_mutex); + portable_mutex_init(&myinfo->basilisk_mutex); + portable_mutex_init(&myinfo->gecko_mutex); + myinfo->basilisks.launched = iguana_launch(iguana_coinfind("BTCD"),"basilisks_loop",basilisks_loop,myinfo,IGUANA_PERMTHREAD); +} diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index 0bb37ee7b..faba883fb 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -48,7 +48,7 @@ struct basilisk_info struct basilisk_relay { bits256 pubkey; uint32_t ipbits; struct iguana_peer *addr; - uint8_t pubkey33[33]; + uint8_t status,pubkey33[33]; }; void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t senderipbits,char *type,uint32_t basilisktag,uint8_t *data,int32_t datalen); diff --git a/basilisk/basilisk_CMD.c b/basilisk/basilisk_CMD.c index 252a27c2b..a2adad31d 100755 --- a/basilisk/basilisk_CMD.c +++ b/basilisk/basilisk_CMD.c @@ -103,9 +103,10 @@ char *basilisk_respond_instantdex(struct supernet_info *myinfo,char *CMD,void *a return(retstr); } -char *basilisk_respond_dispatch(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) +char *basilisk_respond_ping(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk) { char *retstr=0; + printf("PING got %d from (%s)\n",datalen,remoteaddr!=0?remoteaddr:""); return(retstr); }