diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 62cc3e8d1..93d50bc9f 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -16,7 +16,7 @@ #include "../iguana/iguana777.h" typedef char *basilisk_coinfunc(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen); -typedef char *basilisk_servicefunc(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey); +typedef char *basilisk_servicefunc(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk); typedef struct basilisk_item *basilisk_requestfunc(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen); char *basilisk_finish(struct basilisk_item *ptr,int32_t besti,char *errstr) @@ -56,9 +56,46 @@ struct basilisk_item *basilisk_itemcreate(struct supernet_info *myinfo,char *CMD return(ptr); } +/*int32_t basilisk_sendPUB(struct supernet_info *myinfo,uint32_t basilisktag,uint8_t *data,int32_t datalen) // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag) +{ + int32_t i,j,r,r2,s,k,val,l,n=0; uint32_t *alreadysent; struct iguana_info *coin; struct iguana_peer *addr; + alreadysent = calloc(IGUANA_MAXPEERS * IGUANA_MAXCOINS,sizeof(*alreadysent)); + r = rand(), r2 = rand(); + for (k=0; kpeers.active[i]) != 0 && addr->ipbits != 0 && addr->usock >= 0 && addr->basilisk != 0 ) + { + for (s=0; sipbits ) + break; + if ( s == n ) + { + printf("pub (%s) addr->supernet.%u to (%s).%d\n",(char *)&data[4],addr->supernet,addr->ipaddr,addr->A.port); + if ( (val= iguana_queue_send(addr,0,&data[-sizeof(struct iguana_msghdr)],"SuperNETpub",datalen)) >= datalen ) + { + alreadysent[n++] = (uint32_t)addr->ipbits; + if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS ) + break; + } + } + } + } + if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS ) + break; + } + free(alreadysent); + return(n); +}*/ + int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *type,uint32_t basilisktag,int32_t encryptflag,int32_t delaymillis,uint8_t *data,int32_t datalen,int32_t fanout) // data must be offset by sizeof(iguana_msghdr)+sizeof(basilisktag) { - int32_t i,j,r,r2,k,l,val,n=0,offset,havepubkey=0,retval = -1; char cmd[12]; struct iguana_info *coin; struct iguana_peer *addr; bits256 pubkey; + int32_t i,j,r,r2,k,l,s,val,n=0,offset,havepubkey=0,retval = -1; char cmd[12]; struct iguana_info *coin; struct iguana_peer *addr; bits256 pubkey; uint32_t *alreadysent; if ( fanout <= 0 ) fanout = BASILISK_MINFANOUT; else if ( fanout > BASILISK_MAXFANOUT ) @@ -91,6 +128,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ return(0); } } + alreadysent = calloc(IGUANA_MAXPEERS * IGUANA_MAXCOINS,sizeof(*alreadysent)); iguana_rwnum(1,&data[-sizeof(basilisktag)],sizeof(basilisktag),&basilisktag); data -= sizeof(basilisktag), datalen += sizeof(basilisktag); memset(cmd,0,sizeof(cmd)); @@ -109,7 +147,10 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ i = (l + r) % IGUANA_MAXPEERS; if ( (addr= &coin->peers.active[i]) != 0 && addr->usock >= 0 ) { - if ( addr->supernet != 0 && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) ) + for (s=0; sipbits ) + break; + if ( s == n && addr->supernet != 0 && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) ) { printf("[%s] send %s.(%s) addr->supernet.%u to (%s).%d destip.%s\n",cmd,type,(char *)&data[4],addr->supernet,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast"); if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 ) @@ -129,16 +170,26 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ { cmd[6] = 'E', cmd[7] = 'T'; if ( (val= iguana_queue_send(addr,delaymillis,&data[-sizeof(struct iguana_msghdr)],cmd,datalen)) >= datalen ) - n++; + { + alreadysent[n++] = (uint32_t)addr->ipbits; + if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS ) + break; + } } if ( destipaddr != 0 || (fanout > 0 && n >= fanout) ) + { + free(alreadysent); return(val); + } else if ( val > retval ) retval = val; } } } + if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS ) + break; } + free(alreadysent); return(n); } @@ -664,7 +715,7 @@ HASH_ARRAY_STRING(basilisk,VPNlogout,pubkey,vals,hexstr) void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t senderipbits,char *type,uint32_t basilisktag,uint8_t *data,int32_t datalen,bits256 pubkey) { - cJSON *valsobj; char *symbol,*retstr=0,remoteaddr[64],CMD[4],cmd[4]; int32_t origlen,basilisk_request,i,timeoutmillis,numrequired,jsonlen; uint8_t *origdata; struct iguana_info *coin=0; + cJSON *valsobj; char *symbol,*retstr=0,remoteaddr[64],CMD[4],cmd[4]; int32_t origlen,from_basilisk,i,timeoutmillis,numrequired,jsonlen; uint8_t *origdata; struct iguana_info *coin=0; static basilisk_servicefunc *basilisk_services[][2] = { { (void *)"RUN", &basilisk_respond_dispatch }, // higher level protocol handler, pass through @@ -697,8 +748,8 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender }; strncpy(CMD,type,3), CMD[3] = cmd[3] = 0; if ( isupper((int32_t)CMD[0]) != 0 && isupper((int32_t)CMD[1]) != 0 && isupper((int32_t)CMD[2]) != 0 ) - basilisk_request = 1; - else basilisk_request = 0; + from_basilisk = 1; + else from_basilisk = 0; origdata = data; origlen = datalen; for (i=0; i<3; i++) @@ -732,11 +783,11 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender { if ( myinfo->IAMRELAY != 0 ) // iguana node { - if ( basilisk_request != 0 ) - basilisk_sendcmd(myinfo,0,cmd,rand(),0,0,origdata,origlen,-1); - if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,pubkey)) != 0 ) + if ( from_basilisk != 0 ) + basilisk_sendcmd(myinfo,0,cmd,rand(),0,0,origdata,origlen,-1); // to other iguanas + if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,pubkey,from_basilisk)) != 0 ) { - if ( basilisk_request != 0 ) + if ( from_basilisk != 0 ) basilisk_sendback(myinfo,symbol,remoteaddr,basilisktag,retstr); if ( retstr != 0 ) free(retstr); @@ -761,6 +812,10 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender { if ( strcmp(type,"RET") == 0 ) retstr = _basilisk_result(myinfo,coin,addr,remoteaddr,basilisktag,valsobj,data,datalen); + else if ( strcmp(type,"ADD") == 0 ) + { + printf("new relay ADD.(%s) datalen.%d\n",jprint(valsobj,0),datalen); + } else printf("basilisk node doenst handle.(%s)\n",type); } } else printf("basilisk_msgprocess no coin\n"); diff --git a/basilisk/basilisk_CMD.c b/basilisk/basilisk_CMD.c index 21b1f429d..197e27dfa 100755 --- a/basilisk/basilisk_CMD.c +++ b/basilisk/basilisk_CMD.c @@ -15,7 +15,7 @@ #include "../iguana/iguana777.h" -char *basilisk_respond_goodbye(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_goodbye(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { printf("(%s) sends goodbye\n",remoteaddr); addr->dead = (uint32_t)time(NULL); @@ -31,11 +31,28 @@ void basilisk_request_goodbye(struct supernet_info *myinfo) free_json(valsobj); } -char *basilisk_respond_publish(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_publish(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) { - char *retstr=0; + bits256 hash,cathash; struct category_info *cat,*prevcat=0; char *category; char str[65]; printf("from.(%s) PUB.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen); - return(retstr); + if ( datalen <= 0 || (category= jstr(valsobj,"cat")) == 0 ) + return(0); + vcalc_sha256(0,cathash.bytes,(uint8_t *)category,(int32_t)strlen(category)); + vcalc_sha256(0,hash.bytes,data,datalen); + category_subscribe(myinfo,cathash,hash,data,datalen); + if ( bits256_cmp(prevhash,GENESIS_PUBKEY) != 0 && bits256_nonz(prevhash) != 0 ) + { + if ( (prevcat= category_find(cathash,prevhash)) == 0 ) + { + printf("basilisk_respond_publish: cant find prevhash.%s\n",bits256_str(str,prevhash)); + } + } else memset(prevhash.bytes,0,sizeof(prevhash)); + if ( (cat= category_find(cathash,hash)) == 0 ) + printf("error finding just added category\n"); + cat->prevhash = prevhash; + if ( prevcat != 0 ) + prevcat->next = cat; + return(0); } struct basilisk_item *basilisk_request_publish(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen) @@ -43,17 +60,35 @@ struct basilisk_item *basilisk_request_publish(struct basilisk_item *Lptr,struct return(basilisk_requestservice(Lptr,myinfo,"PUB",0,valsobj,pubkey)); } -char *basilisk_respond_subscribe(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_subscribe(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk) { - char *retstr=0; - return(retstr); + bits256 cathash; struct category_info *cat; char *category,*hexstr; cJSON *retjson; + printf("from.(%s) SUB.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen); + if ( (category= jstr(valsobj,"cat")) == 0 ) + return(0); + vcalc_sha256(0,cathash.bytes,(uint8_t *)category,(int32_t)strlen(category)); + if ( (cat= category_find(cathash,prevhash)) == 0 ) + printf("error finding just added category\n"); + retjson = cJSON_CreateObject(); + if ( cat->datalen > 0 ) + { + hexstr = calloc(1,(cat->datalen << 1) + 1); + init_hexbytes_noT(hexstr,cat->data,cat->datalen); + jaddstr(retjson,"data",hexstr); + } + return(jprint(retjson,1)); } -struct basilisk_item *basilisk_request_subscribe(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen) + +struct basilisk_item *basilisk_request_subscribe(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 prevhash,cJSON *valsobj,uint8_t *data,int32_t datalen) { - return(basilisk_requestservice(Lptr,myinfo,"SUB",0,valsobj,pubkey)); + bits256 cathash; char *category; + if ( datalen <= 0 || (category= jstr(valsobj,"cat")) == 0 ) + return(0); + vcalc_sha256(0,cathash.bytes,(uint8_t *)category,(int32_t)strlen(category)); + return(basilisk_requestservice(Lptr,myinfo,"SUB",0,valsobj,prevhash)); } -char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; printf("from.(%s) SET.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen); @@ -65,7 +100,7 @@ struct basilisk_item *basilisk_request_setfield(struct basilisk_item *Lptr,struc return(basilisk_requestservice(Lptr,myinfo,"SET",0,valsobj,pubkey)); } -char *basilisk_respond_getfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_getfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; printf("from.(%s) GET.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen); @@ -77,7 +112,7 @@ struct basilisk_item *basilisk_request_getfield(struct basilisk_item *Lptr,struc return(basilisk_requestservice(Lptr,myinfo,"GET",0,valsobj,pubkey)); } -char *basilisk_respond_dispatch(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_dispatch(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; return(retstr); @@ -88,7 +123,7 @@ struct basilisk_item *basilisk_request_dispatch(struct basilisk_item *Lptr,struc return(basilisk_requestservice(Lptr,myinfo,"RUN",0,valsobj,pubkey)); } -char *basilisk_respond_addrelay(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_addrelay(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; return(retstr); @@ -99,7 +134,7 @@ struct basilisk_item *basilisk_request_addrelay(struct basilisk_item *Lptr,struc return(basilisk_requestservice(Lptr,myinfo,"ADD",0,valsobj,pubkey)); } -char *basilisk_respond_forward(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_forward(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; return(retstr); @@ -110,7 +145,7 @@ struct basilisk_item *basilisk_request_forward(struct basilisk_item *Lptr,struct return(basilisk_requestservice(Lptr,myinfo,"HOP",0,valsobj,pubkey)); } -char *basilisk_respond_mailbox(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_mailbox(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; return(retstr); @@ -121,7 +156,7 @@ struct basilisk_item *basilisk_request_mailbox(struct basilisk_item *Lptr,struct return(basilisk_requestservice(Lptr,myinfo,"BOX",0,valsobj,pubkey)); } -char *basilisk_respond_VPNcreate(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_VPNcreate(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; return(retstr); @@ -132,7 +167,7 @@ struct basilisk_item *basilisk_request_VPNcreate(struct basilisk_item *Lptr,stru return(basilisk_requestservice(Lptr,myinfo,"HUB",0,valsobj,pubkey)); } -char *basilisk_respond_VPNjoin(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_VPNjoin(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; return(retstr); @@ -143,7 +178,7 @@ struct basilisk_item *basilisk_request_VPNjoin(struct basilisk_item *Lptr,struct return(basilisk_requestservice(Lptr,myinfo,"ARC",0,valsobj,pubkey)); } -char *basilisk_respond_VPNlogout(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_VPNlogout(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; return(retstr); @@ -154,7 +189,7 @@ struct basilisk_item *basilisk_request_VPNlogout(struct basilisk_item *Lptr,stru return(basilisk_requestservice(Lptr,myinfo,"END",0,valsobj,pubkey)); } -char *basilisk_respond_VPNbroadcast(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_VPNbroadcast(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; return(retstr); @@ -165,7 +200,7 @@ struct basilisk_item *basilisk_request_VPNbroadcast(struct basilisk_item *Lptr,s return(basilisk_requestservice(Lptr,myinfo,"SAY",0,valsobj,pubkey)); } -char *basilisk_respond_VPNreceive(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_VPNreceive(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; return(retstr); @@ -176,7 +211,7 @@ struct basilisk_item *basilisk_request_VPNreceive(struct basilisk_item *Lptr,str return(basilisk_requestservice(Lptr,myinfo,"EAR",0,valsobj,pubkey)); } -char *basilisk_respond_VPNmessage(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey) +char *basilisk_respond_VPNmessage(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk) { char *retstr=0; return(retstr); diff --git a/iguana/SuperNET.c b/iguana/SuperNET.c index 18f980b3c..0f7210deb 100755 --- a/iguana/SuperNET.c +++ b/iguana/SuperNET.c @@ -1281,7 +1281,7 @@ TWO_STRINGS(SuperNET,subscribe,category,subcategory) if ( remoteaddr != 0 ) return(clonestr("{\"error\":\"no remote\"}")); categoryhash = calc_categoryhashes(&subhash,category,subcategory); - if ( category_subscribe(myinfo,categoryhash,subhash) != 0 ) + if ( category_subscribe(myinfo,categoryhash,subhash,0,0) != 0 ) return(clonestr("{\"result\":\"subscribed\"}")); else return(clonestr("{\"error\":\"couldnt subscribe\"}")); } diff --git a/iguana/SuperNET.h b/iguana/SuperNET.h index dd8ef38c2..c5fa950e7 100755 --- a/iguana/SuperNET.h +++ b/iguana/SuperNET.h @@ -130,9 +130,10 @@ struct category_info { UT_hash_handle hh; queue_t Q; char *(*processfunc)(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t datalen,char *remoteaddr); - struct category_chain *catchain; - bits256 hash; void *info; struct category_info *sub; + struct category_chain *catchain; bits256 hash,prevhash; void *info; struct category_info *sub,*next; + int32_t datalen; uint8_t data[]; }; + extern struct category_info *Categories; struct category_msg { struct queueitem DL; struct tai t; uint64_t remoteipbits; int32_t len; uint8_t msg[]; }; @@ -169,7 +170,7 @@ void SuperNET_hex2str(char *str,uint8_t *hex,int32_t len); void SuperNET_hexmsgadd(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr); int32_t SuperNET_hexmsgfind(struct supernet_info *myinfo,bits256 category,bits256 subhash,char *hexmsg,int32_t addflag); void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,char *hexmsg,struct tai now,char *remoteaddr); -void *category_subscribe(struct supernet_info *myinfo,bits256 category,bits256 subhash); +void *category_subscribe(struct supernet_info *myinfo,bits256 category,bits256 subhash,uint8_t *data,int32_t datalen); struct category_msg *category_gethexmsg(struct supernet_info *myinfo,struct category_info **catptrp,bits256 categoryhash,bits256 subhash); char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr); queue_t *category_Q(struct category_info **catptrp,bits256 categoryhash,bits256 subhash); diff --git a/iguana/SuperNET_category.c b/iguana/SuperNET_category.c index fef1491ca..d5b525436 100755 --- a/iguana/SuperNET_category.c +++ b/iguana/SuperNET_category.c @@ -23,8 +23,6 @@ #include "../includes/curve25519.h" #include "../includes/cJSON.h" - - bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory) { bits256 categoryhash; @@ -126,14 +124,16 @@ void category_posthexmsg(struct supernet_info *myinfo,bits256 categoryhash,bits2 // char str[65]; printf("no subscription for category.(%s) %llx\n",bits256_str(str,categoryhash),(long long)subhash.txid); } -void *category_subscribe(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash) +void *category_subscribe(struct supernet_info *myinfo,bits256 categoryhash,bits256 subhash,uint8_t *data,int32_t datalen) { struct category_info *cat,*sub; bits256 hash; HASH_FIND(hh,Categories,categoryhash.bytes,sizeof(categoryhash),cat); if ( cat == 0 ) { - cat = mycalloc('c',1,sizeof(*cat)); + cat = mycalloc('c',1,sizeof(*cat) + datalen); cat->hash = hash = categoryhash; + if ( (cat->datalen= datalen) > 0 ) + memcpy(cat->data,data,datalen); char str[65]; printf("ADD cat.(%s)\n",bits256_str(str,categoryhash)); HASH_ADD(hh,Categories,hash,sizeof(hash),cat); } @@ -142,9 +142,11 @@ void *category_subscribe(struct supernet_info *myinfo,bits256 categoryhash,bits2 HASH_FIND(hh,cat->sub,subhash.bytes,sizeof(subhash),sub); if ( sub == 0 ) { - sub = mycalloc('c',1,sizeof(*sub)); + sub = mycalloc('c',1,sizeof(*sub) + datalen); sub->hash = hash = subhash; - char str[65],str2[65]; printf("subadd.(%s) -> (%s)\n",bits256_str(str,hash),bits256_str(str2,categoryhash)); + if ( (sub->datalen= datalen) > 0 ) + memcpy(sub->data,data,datalen); + char str[65],str2[65]; printf("subadd.(%s) -> (%s) datalen.%d\n",bits256_str(str,subhash),bits256_str(str2,categoryhash),datalen); HASH_ADD(hh,cat->sub,hash,sizeof(hash),sub); } } @@ -204,18 +206,22 @@ char *SuperNET_categorymulticast(struct supernet_info *myinfo,int32_t surveyflag void category_init(struct supernet_info *myinfo) { - bits256 pangeahash,instantdexhash; - category_subscribe(myinfo,GENESIS_PUBKEY,GENESIS_PUBKEY); + bits256 pangeahash,instantdexhash,baseliskhash; + category_subscribe(myinfo,GENESIS_PUBKEY,GENESIS_PUBKEY,0,0); pangeahash = calc_categoryhashes(0,"pangea",0); myinfo->pangea_category = pangeahash; - category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY); + category_subscribe(myinfo,pangeahash,GENESIS_PUBKEY,0,0); category_processfunc(pangeahash,GENESIS_PUBKEY,pangea_hexmsg); category_chain_functions(myinfo,pangeahash,GENESIS_PUBKEY,sizeof(bits256),sizeof(bits256),0,0,0,0,0,0); instantdexhash = calc_categoryhashes(0,"InstantDEX",0); myinfo->instantdex_category = instantdexhash; - category_subscribe(myinfo,instantdexhash,GENESIS_PUBKEY); + category_subscribe(myinfo,instantdexhash,GENESIS_PUBKEY,0,0); category_processfunc(instantdexhash,GENESIS_PUBKEY,InstantDEX_hexmsg); category_processfunc(instantdexhash,myinfo->myaddr.persistent,InstantDEX_hexmsg); - + + baseliskhash = calc_categoryhashes(0,"baselisk",0); + myinfo->basilisk_category = baseliskhash; + category_subscribe(myinfo,baseliskhash,GENESIS_PUBKEY,0,0); + basilisks_init(myinfo); } \ No newline at end of file diff --git a/iguana/iguana_msg.c b/iguana/iguana_msg.c index be6bc984a..2c4c054e7 100755 --- a/iguana/iguana_msg.c +++ b/iguana/iguana_msg.c @@ -263,7 +263,7 @@ void iguana_gotversion(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_queue_send(addr,0,serialized,"verack",0); //iguana_send_ping(coin,addr); } - else if ( addr->supernet == 0 && addr->basilisk == 0 )//|| (addr->basilisk != 0 && myinfo->IAMRELAY == 0) ) + else if ( 0 && addr->supernet == 0 && addr->basilisk == 0 )//|| (addr->basilisk != 0 && myinfo->IAMRELAY == 0) ) addr->dead = (uint32_t)time(NULL); //if ( addr->supernet != 0 || addr->basilisk != 0 ) printf("height.%d nServices.%lld nonce.%llu %srelay node.(%s) supernet.%d basilisk.%d\n",vers->nStartingHeight,(long long)vers->nServices,(long long)vers->nonce,addr->relayflag==0?"non-":"",addr->ipaddr,addr->supernet,addr->basilisk); @@ -289,7 +289,7 @@ int32_t iguana_send_version(struct iguana_info *coin,struct iguana_peer *addr,ui if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 ) sprintf(msg.strSubVer,"/iguana 0.00/"); else sprintf(msg.strSubVer,"/basilisk 0.00/"); - printf("SEND.(%s) -> (%s)\n",msg.strSubVer,addr->ipaddr); + //printf("SEND.(%s) -> (%s)\n",msg.strSubVer,addr->ipaddr); //sprintf(msg.strSubVer,"/Satoshi:0.10.0/"); msg.nStartingHeight = coin->blocks.hwmchain.height; iguana_gotdata(coin,addr,msg.nStartingHeight); diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index f17781e72..bd5e4b1a1 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -709,7 +709,7 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi HASH_DELETE(hh,wacct->waddr,waddr); if ( waddr->unspents != 0 ) free(waddr->unspents); - printf("%p free %s\n",waddr,waddr->coinaddr); + //printf("walletiterate: %p free %s\n",waddr,waddr->coinaddr); myfree(waddr,sizeof(*waddr) + waddr->scriptlen); } } diff --git a/iguana/pangea_api.c b/iguana/pangea_api.c index f33203b1a..dc9c57071 100755 --- a/iguana/pangea_api.c +++ b/iguana/pangea_api.c @@ -196,7 +196,7 @@ struct table_info *pangea_table(struct supernet_info *myinfo,bits256 tablehash,i } if ( tp != 0 ) { - category_subscribe(SuperNET_MYINFO(0),myinfo->pangea_category,tablehash); + category_subscribe(SuperNET_MYINFO(0),myinfo->pangea_category,tablehash,0,0); if ( category_infoset(myinfo->pangea_category,tablehash,tp) == 0 ) printf("error: couldnt set table.(%s)\n",bits256_str(str,tablehash)), tp = 0; //else tp->G.allocsize = allocsize; @@ -220,8 +220,8 @@ struct player_info *pangea_playerfind(struct supernet_info *myinfo,struct table_ char *pangea_jsondatacmd(struct supernet_info *myinfo,bits256 tablehash,struct pangea_msghdr *pm,cJSON *json,char *cmdstr,char *ipaddr) { cJSON *argjson; char *reqstr,hexstr[8192]; uint64_t nxt64bits; struct table_info *tp; int32_t i,datalen; - category_subscribe(myinfo,myinfo->pangea_category,GENESIS_PUBKEY); - category_subscribe(myinfo,myinfo->pangea_category,tablehash); + category_subscribe(myinfo,myinfo->pangea_category,GENESIS_PUBKEY,0,0); + category_subscribe(myinfo,myinfo->pangea_category,tablehash,0,0); argjson = json != 0 ? jduplicate(json) : cJSON_CreateObject(); jaddstr(argjson,"cmd",cmdstr); if ( myinfo->ipaddr[0] == 0 || strncmp(myinfo->ipaddr,"127.0.0.1",strlen("127.0.0.1")) == 0 ) @@ -808,7 +808,7 @@ ZERO_ARGS(pangea,lobby) //cJSON *retjson,*argjson; char *retstr,*result; uint8_t *buf; int32_t flag,len; struct pangea_msghdr *pm; if ( remoteaddr != 0 ) return(clonestr("{\"error\":\"no remote\"}")); - category_subscribe(myinfo,myinfo->pangea_category,GENESIS_PUBKEY); + category_subscribe(myinfo,myinfo->pangea_category,GENESIS_PUBKEY,0,0); pangea_update(myinfo); return(jprint(pangea_lobbyjson(myinfo),1)); }