From 34ebd02a7909a83ac0344c4a5d0f18a01c346087 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 12 Sep 2016 09:15:08 -0300 Subject: [PATCH] test --- basilisk/basilisk.c | 8 +++++--- basilisk/basilisk_MSG.c | 6 +++--- basilisk/basilisk_bitcoin.c | 10 ++++++---- iguana/iguana777.h | 7 +++++++ iguana/iguana_msg.c | 1 + 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 05a25bfae..b0b46f616 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -202,8 +202,10 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ if ( addr->usock >= 0 ) { s = 0; + valid = (addr->supernet != 0); if ( NUMRELAYS > 0 && basilisk_specialcmd(type) != 0 ) { + valid = 0; OS_randombytes((void *)&r2,sizeof(r2)); if ( (r2 % NUMRELAYS) >= sqrt(NUMRELAYS) ) { @@ -218,8 +220,8 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ //printf("skip non-relay.(%s)\n",addr->ipaddr); continue; } - //printf("send to other relay.(%s)\n",addr->ipaddr); valid = 1; + //printf("send to other relay.(%s)\n",addr->ipaddr); } for (s=0; sipbits ) @@ -229,7 +231,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ } if ( s == n && valid == 1 && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) ) { - printf("n.%d/fanout.%d i.%d l.%d [%s].tag%d send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",n,fanout,i,l,cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast"); + printf("n.%d/fanout.%d i.%d l.%d [%s].tag%u send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",n,fanout,i,l,cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast"); if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 ) { void *ptr; uint8_t *cipher,space[8192]; int32_t cipherlen; bits256 privkey; @@ -899,7 +901,7 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr) coin = iguana_coinfind(symbol); } if ( jobj(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS)+1); + jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1)); if ( jobj(vals,"numrequired") == 0 ) jaddnum(vals,"numrequired",sqrt(NUMRELAYS)); if ( coin != 0 ) diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index a5a09769a..fd8f9578b 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -189,7 +189,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr) free(retstr); } if ( vals != 0 && juint(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS)+2); + jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+2)); return(basilisk_standardservice("OUT",myinfo,0,hash,vals,hexstr,0)); } #include "../includes/iguana_apiundefs.h" @@ -203,7 +203,7 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t jaddnum(valsobj,"channel",channel); if ( msgid == 0 ) msgid = (uint32_t)time(NULL); - jaddnum(valsobj,"fanout",(int32_t)sqrt(NUMRELAYS)+2); + jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+2)); jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"duration",duration); jaddbits256(valsobj,"sender",myinfo->myaddr.persistent); @@ -252,7 +252,7 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t ch jaddnum(valsobj,"msgid",msgid); jaddnum(valsobj,"width",width); jaddnum(valsobj,"timeout",2500); - jaddnum(valsobj,"fanout",(int32_t)sqrt(NUMRELAYS)+1); + jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1)); jaddnum(valsobj,"minresults",1); if ( (retstr= basilisk_getmessage(myinfo,0,0,0,hash,valsobj,0)) != 0 ) { diff --git a/basilisk/basilisk_bitcoin.c b/basilisk/basilisk_bitcoin.c index 314b7ce91..f4d20f962 100755 --- a/basilisk/basilisk_bitcoin.c +++ b/basilisk/basilisk_bitcoin.c @@ -423,7 +423,7 @@ void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myi void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj) { - struct basilisk_item *ptr; cJSON *infojson; int32_t numsent; + struct basilisk_item *ptr; cJSON *infojson; int32_t numsent,fanout; if ( RELAYID >= 0 ) return(0); if ( coin->VALIDATENODE != 0 || coin->FULLNODE != 0 ) @@ -432,7 +432,9 @@ void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,s Lptr->retstr = jprint(infojson,1); return(Lptr); } - ptr = basilisk_issueremote(myinfo,0,&numsent,"INF",coin->symbol,1,valsobj,juint(valsobj,"fanout"),juint(valsobj,"minresults"),basilisktag,timeoutmillis,0,0,0,0,BASILISK_DEFAULTDIFF); + if ( (fanout= juint(valsobj,"fanout")) < 5 ) + fanout = 5; + ptr = basilisk_issueremote(myinfo,0,&numsent,"INF",coin->symbol,1,valsobj,fanout,juint(valsobj,"minresults"),basilisktag,timeoutmillis,0,0,0,0,BASILISK_DEFAULTDIFF); return(ptr); } @@ -816,7 +818,7 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr) coin = iguana_coinfind(symbol); } if ( jobj(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS)+1); + jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1)); if ( coin != 0 ) { if ( (basilisktag= juint(vals,"basilisktag")) == 0 ) @@ -844,7 +846,7 @@ HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr) if ( jobj(vals,"numrequired") == 0 ) jaddnum(vals,"numrequired",NUMRELAYS); if ( jobj(vals,"fanout") == 0 ) - jaddnum(vals,"fanout",(int32_t)sqrt(NUMRELAYS)); + jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1)); if ( coin != 0 ) { //if ( juint(vals,"burn") == 0 ) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index bc8d632f5..4b01c3e76 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -97,4 +97,11 @@ struct supernet_info #include "../includes/iguana_globals.h" #include "../gecko/gecko.h" +#ifndef MAX +#define MAX(a,b) ((a) >= (b) ? (a) : (b)) +#endif +#ifndef MIN +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#endif + #endif diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index bafc947ad..6f0e4b988 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -336,6 +336,7 @@ void iguana_gotversion(struct supernet_info *myinfo,struct iguana_info *coin,str addr->dead = 1; } //else coin->longestchain = vers->nStartingHeight; } + iguana_send_version(coin,addr,coin->myservices); iguana_queue_send(addr,0,serialized,"getaddr",0); }