Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
7ac536a474
  1. 36
      basilisk/basilisk.c
  2. 26
      basilisk/basilisk_MSG.c
  3. 2
      iguana/main.c

36
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) 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] = static basilisk_servicefunc *basilisk_services[][2] =
{ {
{ (void *)"OUT", &basilisk_respond_OUT }, // send MSG to hash/id/num { (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 *)"VAL", &basilisk_respond_value },
{ (void *)"BAL", &basilisk_respond_balances }, { (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; return;
symbol = "BTCD"; symbol = "BTCD";
if ( senderipbits == 0 ) if ( senderipbits == 0 )
@ -613,6 +632,8 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
else expand_ipbits(remoteaddr,senderipbits); else expand_ipbits(remoteaddr,senderipbits);
if ( (valsobj= cJSON_Parse((char *)data)) != 0 ) if ( (valsobj= cJSON_Parse((char *)data)) != 0 )
{ {
if ( origcmd[0] != 0 )
jaddstr(valsobj,"origcmd",origcmd);
//printf("MSGVALS.(%s)\n",(char *)data); //printf("MSGVALS.(%s)\n",(char *)data);
if ( jobj(valsobj,"coin") != 0 ) if ( jobj(valsobj,"coin") != 0 )
coin = iguana_coinfind(jstr(valsobj,"coin")); 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 ) if ( flag == 0 )
return; 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 ) if ( myinfo->RELAYID >= 0 )//0 && strcmp(CMD,"RID") != 0 && strcmp(CMD,"MSG") != 0 )
printf("MSGPROCESS %s.(%s) tag.%d\n",CMD,(char *)data,basilisktag); printf("MSGPROCESS %s.(%s) tag.%d\n",CMD,(char *)data,basilisktag);
myinfo->basilisk_busy = 1; myinfo->basilisk_busy = 1;

26
basilisk/basilisk_MSG.c

@ -132,11 +132,33 @@ int32_t basilisk_messagekey(uint8_t *key,bits256 hash,cJSON *valsobj)
return(keylen); 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) 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); 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)); //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)); return(basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1));
} }

2
iguana/main.c

@ -526,7 +526,7 @@ void iguana_appletests(struct supernet_info *myinfo)
bitcoin_sharedsecret(myinfo->ctx,hash2,pubkey,33); bitcoin_sharedsecret(myinfo->ctx,hash2,pubkey,33);
printf("secp256k1 elapsed %.3f for %d iterations\n",OS_milliseconds() - startmillis,i); printf("secp256k1 elapsed %.3f for %d iterations\n",OS_milliseconds() - startmillis,i);
getchar();**/ 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); 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 ) 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 )

Loading…
Cancel
Save