From 7ac536a4742e8e738b21e9194fdce716c0f74ac3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 28 Aug 2016 09:31:03 -0300 Subject: [PATCH] test --- basilisk/basilisk.c | 36 +++++++++++++++++++++++------------- basilisk/basilisk_MSG.c | 26 ++++++++++++++++++++++++-- iguana/main.c | 2 +- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 6619020ca..021b3f437 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -568,7 +568,7 @@ void basilisk_wait(struct supernet_info *myinfo,struct iguana_info *coin) void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t senderipbits,char *type,uint32_t basilisktag,uint8_t *data,int32_t datalen) { - 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; + cJSON *valsobj; char *symbol,*retstr=0,remoteaddr[64],CMD[4],cmd[4],origcmd[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 *)"OUT", &basilisk_respond_OUT }, // send MSG to hash/id/num @@ -605,7 +605,26 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende { (void *)"VAL", &basilisk_respond_value }, { (void *)"BAL", &basilisk_respond_balances }, }; - if ( myinfo->RELAYID >= 0 && basilisk_specialcmd(type) == 0 ) + 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 ) + from_basilisk = 1; + else from_basilisk = 0; + origdata = data; + origlen = datalen; + for (i=0; i<3; i++) + { + CMD[i] = toupper((int32_t)CMD[i]); + cmd[i] = tolower((int32_t)CMD[i]); + } + origcmd[0] = 0; + if ( myinfo->RELAYID >= 0 ) + { + if ( basilisk_specialcmd(CMD) == 0 ) + return; + else if ( strcmp(CMD,"OUT") != 0 && strcmp(CMD,"MSG") != 0 ) + strcpy(origcmd,CMD); + } + else if ( strcmp(CMD,"OUT") == 0 || strcmp(CMD,"MSG") == 0 ) return; symbol = "BTCD"; if ( senderipbits == 0 ) @@ -613,6 +632,8 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende else expand_ipbits(remoteaddr,senderipbits); if ( (valsobj= cJSON_Parse((char *)data)) != 0 ) { + if ( origcmd[0] != 0 ) + jaddstr(valsobj,"origcmd",origcmd); //printf("MSGVALS.(%s)\n",(char *)data); if ( jobj(valsobj,"coin") != 0 ) coin = iguana_coinfind(jstr(valsobj,"coin")); @@ -647,17 +668,6 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende } if ( flag == 0 ) return; - 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 ) - from_basilisk = 1; - else from_basilisk = 0; - origdata = data; - origlen = datalen; - for (i=0; i<3; i++) - { - CMD[i] = toupper((int32_t)CMD[i]); - cmd[i] = tolower((int32_t)CMD[i]); - } if ( myinfo->RELAYID >= 0 )//0 && strcmp(CMD,"RID") != 0 && strcmp(CMD,"MSG") != 0 ) printf("MSGPROCESS %s.(%s) tag.%d\n",CMD,(char *)data,basilisktag); myinfo->basilisk_busy = 1; diff --git a/basilisk/basilisk_MSG.c b/basilisk/basilisk_MSG.c index 8274b016e..0aab47ec5 100755 --- a/basilisk/basilisk_MSG.c +++ b/basilisk/basilisk_MSG.c @@ -132,11 +132,33 @@ int32_t basilisk_messagekey(uint8_t *key,bits256 hash,cJSON *valsobj) return(keylen); } +uint32_t basilisk_msgid(struct supernet_info *myinfo,uint32_t channel,bits256 hash,uint8_t *data,int32_t datalen) +{ + bits256 msghash; int32_t msgid = 0; + vcalc_sha256(0,msghash.bytes,data,datalen); + if ( bits256_nonz(hash) == 0 ) // broadcast + { + // find msghash and return its ind, or allocate new one + } + else + { + // check against most recent small n for hash, return ind or allocate new one + } + return(msgid); +} + char *basilisk_respond_OUT(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) { - int32_t keylen; uint8_t key[64]; + int32_t keylen; uint8_t key[64]; char *origcmd; uint32_t channel,msgid; + if ( (origcmd= jstr(valsobj,"origcmd")) != 0 && strlen(origcmd) == 3 ) + { + channel = origcmd[0] + ((uint32_t)origcmd[1] << 8) + ((uint32_t)origcmd[2] << 16); + msgid = basilisk_msgid(myinfo,channel,hash,data,datalen); + jaddnum(valsobj,"channel",channel); + jaddnum(valsobj,"msgid",msgid); + } else origcmd = ""; keylen = basilisk_messagekey(key,hash,valsobj); - printf("OUT keylen.%d datalen.%d\n",keylen,datalen); + printf("OUT orig.(%s) keylen.%d datalen.%d\n",origcmd,keylen,datalen); //char str[65]; printf("add message.[%d] channel.%u msgid.%x %s\n",datalen,juint(valsobj,"channel"),juint(valsobj,"msgid"),bits256_str(str,hash)); return(basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1)); } diff --git a/iguana/main.c b/iguana/main.c index 5e651ce39..ecfd66608 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -526,7 +526,7 @@ void iguana_appletests(struct supernet_info *myinfo) bitcoin_sharedsecret(myinfo->ctx,hash2,pubkey,33); printf("secp256k1 elapsed %.3f for %d iterations\n",OS_milliseconds() - startmillis,i); getchar();**/ - if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"protover\":70002,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":4,\"endpend\":1,\"services\":129,\"maxpeers\":8,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 ) + if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"protover\":70002,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":512,\"endpend\":512,\"services\":129,\"maxpeers\":8,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 ) { free(str); if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"portp2p\":8333,\"RELAY\":0,\"VALIDATE\":0,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":1,\"endpend\":1,\"services\":128,\"maxpeers\":8,\"newcoin\":\"BTC\",\"active\":0,\"numhelpers\":1,\"poll\":100}"),0,myinfo->rpcport)) != 0 )