From 93d3c10c891ff090bebd55db2f7d391056c4049b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Jan 2016 02:35:54 -0300 Subject: [PATCH] test --- iguana/SuperNET.c | 14 ++++++-------- iguana/SuperNET.h | 4 ++-- iguana/SuperNET_category.c | 14 ++++++++++++-- iguana/SuperNET_hexmsg.c | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/iguana/SuperNET.c b/iguana/SuperNET.c index 4296988ff..6ba558cef 100644 --- a/iguana/SuperNET.c +++ b/iguana/SuperNET.c @@ -464,7 +464,7 @@ char *SuperNET_DHTsend(struct supernet_info *myinfo,uint32_t destipbits,bits256 if ( plaintext != 0 ) jaddnum(json,"plaintext",plaintext!=0); jsonstr = jprint(json,1); - if ( SuperNET_hexmsguniq(myinfo,destpub,hexmsg,1) < 0 ) + if ( SuperNET_hexmsgfind(myinfo,destpub,hexmsg,1) < 0 ) { char str[65]; printf("duplicate hex.(%s) for %s\n",hexmsg,bits256_str(str,destpub)); return(clonestr("{\"error\":\"duplicate packet rejected\"}")); @@ -565,16 +565,16 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr) if ( hexmsg != 0 ) { //printf("check.(%s)\n",hexmsg); - if ( SuperNET_hexmsguniq(myinfo,destpub,hexmsg,0) >= 0 ) + if ( SuperNET_hexmsgfind(myinfo,destpub,hexmsg,0) < 0 ) { SuperNET_hexmsgadd(myinfo,destpub,hexmsg,tai_now()); forwardstr = SuperNET_forward(myinfo,hexmsg,destipbits,destpub,maxdelay,juint(json,"broadcast"),juint(json,"plaintext")!=0); } } } - if ( (destflag & SUPERNET_ISMINE) && (agent= jstr(json,"agent")) != 0 && (method= jstr(json,"method")) != 0 ) + if ( (destflag & SUPERNET_ISMINE) != 0 && (agent= jstr(json,"agent")) != 0 && (method= jstr(json,"method")) != 0 ) { - if ( SuperNET_hexmsguniq(myinfo,destpub,hexmsg,0) >= 0 ) + if ( hexmsg != 0 && SuperNET_hexmsgfind(myinfo,destpub,hexmsg,0) < 0 ) SuperNET_hexmsgadd(myinfo,destpub,hexmsg,tai_now()); if ( (retstr= SuperNET_processJSON(myinfo,json,remoteaddr)) != 0 ) { @@ -669,8 +669,6 @@ char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *de //printf("p2pret.(%s)\n",retstr); *delaymillisp = SuperNET_delaymillis(myinfo,maxdelay); senderpub = jbits256(json,"mypub"); - //if ( memcmp(senderpub.bytes,addr->pubkey.bytes,sizeof(senderpub)) != 0 ) - // addr->pubkey = senderpub; addr->othervalid = (int32_t)jdouble(json,"ov"); addr->pubkey = senderpub; free_json(json); @@ -1007,13 +1005,13 @@ THREE_STRINGS(SuperNET,announce,category,subcategory,message) { bits256 categoryhash; vcalc_sha256(0,categoryhash.bytes,(uint8_t *)category,(int32_t)strlen(category)); - return(SuperNET_categorymulticast(myinfo,0,categoryhash,subcategory,message,juint(json,"maxdelay"),juint(json,"plaintext"))); + return(SuperNET_categorymulticast(myinfo,0,categoryhash,subcategory,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext"))); } THREE_STRINGS(SuperNET,survey,category,subcategory,message) { bits256 categoryhash; vcalc_sha256(0,categoryhash.bytes,(uint8_t *)category,(int32_t)strlen(category)); - return(SuperNET_categorymulticast(myinfo,1,categoryhash,subcategory,message,juint(json,"maxdelay"),juint(json,"plaintext"))); + return(SuperNET_categorymulticast(myinfo,1,categoryhash,subcategory,message,juint(json,"maxdelay"),juint(json,"broadcast"),juint(json,"plaintext"))); } #include "../includes/iguana_apiundefs.h" diff --git a/iguana/SuperNET.h b/iguana/SuperNET.h index 664def6bd..3ee1bdd43 100644 --- a/iguana/SuperNET.h +++ b/iguana/SuperNET.h @@ -127,9 +127,9 @@ int32_t SuperNET_decrypt(bits256 *senderpubp,uint64_t *senderbitsp,uint32_t *tim int32_t SuperNET_str2hex(uint8_t *hex,char *str); void SuperNET_hex2str(char *str,uint8_t *hex,int32_t len); void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 destpub,char *hexmsg,struct tai now); -int32_t SuperNET_hexmsguniq(struct supernet_info *myinfo,bits256 dest,char *hexmsg,int32_t addflag); +int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 dest,char *hexmsg,int32_t addflag); -char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag,bits256 categoryhash,char *subcategory,char *message,int32_t maxdelay,int32_t plaintext); +char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag,bits256 categoryhash,char *subcategory,char *message,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext); #endif diff --git a/iguana/SuperNET_category.c b/iguana/SuperNET_category.c index ccd9d48c4..af3721405 100644 --- a/iguana/SuperNET_category.c +++ b/iguana/SuperNET_category.c @@ -32,9 +32,18 @@ int32_t category_maxdelay(struct supernet_info *myinfo,bits256 categoryhash,int3 return(maxdelay); } -char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag,bits256 categoryhash,char *subcategory,char *message,int32_t maxdelay,int32_t plaintext) +int32_t category_broadcast(struct supernet_info *myinfo,bits256 categoryhash,int32_t broadcastflag) { - char *hexmsg,*retstr; int32_t len,broadcastflag=1; + if ( broadcastflag < 1 ) + broadcastflag = 1; + else if ( broadcastflag > SUPERNET_MAXHOPS ) + broadcastflag = SUPERNET_MAXHOPS; + return(broadcastflag); +} + +char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag,bits256 categoryhash,char *subcategory,char *message,int32_t maxdelay,int32_t broadcastflag,int32_t plaintext) +{ + char *hexmsg,*retstr; int32_t len; len = (int32_t)strlen(message); if ( is_hexstr(message,len) == 0 ) { @@ -42,6 +51,7 @@ char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag init_hexbytes_noT(hexmsg,(uint8_t *)message,len+1); } else hexmsg = message; plaintext = category_plaintext(myinfo,categoryhash,plaintext); + broadcastflag = category_broadcast(myinfo,categoryhash,broadcastflag); maxdelay = category_maxdelay(myinfo,categoryhash,maxdelay); retstr = SuperNET_DHTsend(myinfo,0,categoryhash,hexmsg,maxdelay,broadcastflag,plaintext); if ( hexmsg != message) diff --git a/iguana/SuperNET_hexmsg.c b/iguana/SuperNET_hexmsg.c index 6ed1c014c..3aca4a865 100644 --- a/iguana/SuperNET_hexmsg.c +++ b/iguana/SuperNET_hexmsg.c @@ -15,7 +15,7 @@ #include "iguana777.h" -int32_t SuperNET_hexmsguniq(struct supernet_info *myinfo,bits256 dest,char *hexmsg,int32_t addflag) +int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 dest,char *hexmsg,int32_t addflag) { static int lastpurge; static uint64_t Packetcache[1024]; bits256 packethash; int32_t i,datalen;