jl777 8 years ago
parent
commit
5b93246555
  1. 2
      basilisk/basilisk.c
  2. 4
      basilisk/basilisk.h
  3. 57
      basilisk/basilisk_MSG.c
  4. 6
      basilisk/basilisk_ping.c
  5. 2
      iguana/iguana777.h
  6. 10
      iguana/iguana_rpc.c
  7. 1
      iguana/main.c

2
basilisk/basilisk.c

@ -806,7 +806,7 @@ void basilisk_requests_poll(struct supernet_info *myinfo)
memset(&issueR,0,sizeof(issueR)); memset(&issueR,0,sizeof(issueR));
if ( (retstr= InstantDEX_incoming(myinfo,0,0,0,0)) != 0 ) if ( (retstr= InstantDEX_incoming(myinfo,0,0,0,0)) != 0 )
{ {
printf("poll.(%s)\n",retstr); //printf("poll.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 ) if ( (retjson= cJSON_Parse(retstr)) != 0 )
{ {
if ( (outerarray= jarray(&n,retjson,"responses")) != 0 ) if ( (outerarray= jarray(&n,retjson,"responses")) != 0 )

4
basilisk/basilisk.h

@ -85,8 +85,8 @@ struct basilisk_item
struct basilisk_message struct basilisk_message
{ {
struct queueitem DL; UT_hash_handle hh; struct queueitem DL; UT_hash_handle hh;
uint32_t datalen,expiration,duration; uint32_t expiration,duration,datalen;
uint8_t key[BASILISK_KEYSIZE],keylen; uint8_t keylen,broadcast,key[BASILISK_KEYSIZE];
uint8_t data[]; uint8_t data[];
}; };

57
basilisk/basilisk_MSG.c

@ -17,7 +17,7 @@
char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration) char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen,uint8_t *data,int32_t datalen,int32_t sendping,uint32_t duration)
{ {
struct basilisk_message *msg; int32_t i; struct basilisk_message *msg; int32_t i; bits256 desthash;
HASH_FIND(hh,myinfo->messagetable,key,keylen,msg); HASH_FIND(hh,myinfo->messagetable,key,keylen,msg);
if ( msg == 0 && keylen == BASILISK_KEYSIZE ) if ( msg == 0 && keylen == BASILISK_KEYSIZE )
{ {
@ -26,6 +26,11 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3
duration = BASILISK_MSGDURATION; duration = BASILISK_MSGDURATION;
else if ( duration > INSTANTDEX_LOCKTIME*2 ) else if ( duration > INSTANTDEX_LOCKTIME*2 )
duration = INSTANTDEX_LOCKTIME*2; duration = INSTANTDEX_LOCKTIME*2;
memcpy(desthash.bytes,&key[BASILISK_KEYSIZE - sizeof(desthash)],sizeof(desthash));
if ( bits256_nonz(desthash) == 0 )
msg->broadcast = 1;
if ( bits256_nonz(desthash) == 0 )
msg->broadcast = 1;
msg->duration = duration; msg->duration = duration;
msg->expiration = (uint32_t)time(NULL) + duration; msg->expiration = (uint32_t)time(NULL) + duration;
msg->keylen = keylen; msg->keylen = keylen;
@ -47,13 +52,9 @@ char *basilisk_respond_addmessage(struct supernet_info *myinfo,uint8_t *key,int3
} else return(0); } else return(0);
} }
cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen) cJSON *basilisk_msgjson(struct basilisk_message *msg,uint8_t *key,int32_t keylen)
{ {
cJSON *msgjson=0; struct basilisk_message *msg; char *ptr = 0,strbuf[32768],keystr[BASILISK_KEYSIZE*2+1]; cJSON *msgjson=0; char *ptr = 0,strbuf[32768],keystr[BASILISK_KEYSIZE*2+1];
portable_mutex_lock(&myinfo->messagemutex);
HASH_FIND(hh,myinfo->messagetable,key,keylen,msg);
if ( msg != 0 )
{
msgjson = cJSON_CreateObject(); msgjson = cJSON_CreateObject();
if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),msg->data,msg->datalen) != 0 ) if ( basilisk_addhexstr(&ptr,msgjson,strbuf,sizeof(strbuf),msg->data,msg->datalen) != 0 )
{ {
@ -68,7 +69,16 @@ cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int
free_json(msgjson); free_json(msgjson);
msgjson = 0; msgjson = 0;
} }
} return(msgjson);
}
cJSON *basilisk_respond_getmessage(struct supernet_info *myinfo,uint8_t *key,int32_t keylen)
{
cJSON *msgjson = 0; struct basilisk_message *msg;
portable_mutex_lock(&myinfo->messagemutex);
HASH_FIND(hh,myinfo->messagetable,key,keylen,msg);
if ( msg != 0 )
msgjson = basilisk_msgjson(msg,key,keylen);
portable_mutex_unlock(&myinfo->messagemutex); portable_mutex_unlock(&myinfo->messagemutex);
return(msgjson); return(msgjson);
} }
@ -87,26 +97,42 @@ int32_t basilisk_messagekey(uint8_t *key,uint32_t channel,uint32_t msgid,bits256
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,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 senderhash; int32_t keylen,duration; uint8_t key[BASILISK_KEYSIZE]; bits256 senderhash; char *retstr;
senderhash = jbits256(valsobj,"sender"); senderhash = jbits256(valsobj,"sender");
duration = juint(valsobj,"duration"); duration = juint(valsobj,"duration");
keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,hash); keylen = basilisk_messagekey(key,juint(valsobj,"channel"),juint(valsobj,"msgid"),senderhash,hash);
if( bits256_nonz(senderhash) == 0 && bits256_nonz(hash) == 0 && duration > BASILISK_MSGDURATION ) retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,1,duration);
if ( bits256_nonz(hash) == 0 )
{
if ( duration > BASILISK_MSGDURATION )
duration = BASILISK_MSGDURATION; duration = BASILISK_MSGDURATION;
}
// printf("OUT keylen.%d datalen.%d\n",keylen,datalen); // printf("OUT keylen.%d datalen.%d\n",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,duration)); return(retstr);
}
int32_t basilisk_msgcmp(struct basilisk_message *msg,int32_t width,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash)
{
return(-1);
} }
char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth) char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_t msgid,bits256 srchash,bits256 desthash,int32_t origwidth)
{ {
uint8_t key[BASILISK_KEYSIZE]; int32_t i,keylen,width; cJSON *item,*retjson,*array; bits256 zero; struct basilisk_message *msg,*tmpmsg; uint8_t key[BASILISK_KEYSIZE]; int32_t i,keylen,width; cJSON *item,*retjson,*array; bits256 zero;
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
array = cJSON_CreateArray(); array = cJSON_CreateArray();
portable_mutex_lock(&myinfo->messagemutex);
portable_mutex_unlock(&myinfo->messagemutex);
if ( (width= origwidth) > 3600 ) if ( (width= origwidth) > 3600 )
width = 3600; width = 3600;
else if ( width < 1 ) else if ( width < 1 )
width = 1; width = 1;
HASH_ITER(hh,myinfo->messagetable,msg,tmpmsg)
{
if ( msg->broadcast != 0 && basilisk_msgcmp(msg,width,channel,msgid,zero,zero) == 0 )
jaddi(array,basilisk_msgjson(msg,msg->key,msg->keylen));
}
//printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid); //printf("iterate_MSG width.%d channel.%d msgid.%d src.%llx -> %llx\n",origwidth,channel,msgid,(long long)srchash.txid,(long long)desthash.txid);
for (i=0; i<width; i++) for (i=0; i<width; i++)
{ {
@ -124,13 +150,10 @@ char *basilisk_iterate_MSG(struct supernet_info *myinfo,uint32_t channel,uint32_
if ( bits256_nonz(desthash) != 0 ) if ( bits256_nonz(desthash) != 0 )
{ {
keylen = basilisk_messagekey(key,channel,msgid,srchash,zero); keylen = basilisk_messagekey(key,channel,msgid,srchash,zero);
//int32_t j; for (j=0; j<keylen; j++)
// printf("%02x",key[j]);
//printf(" <- key\n");
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0)); jaddi(array,item);//, printf("gotmsg2.(%s)\n",jprint(item,0));
} }
if ( bits256_nonz(srchash) != 0 || bits256_nonz(desthash) != 0 ) if ( bits256_nonz(srchash) != 0 && bits256_nonz(desthash) != 0 )
{ {
keylen = basilisk_messagekey(key,channel,msgid,zero,zero); keylen = basilisk_messagekey(key,channel,msgid,zero,zero);
if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 ) if ( (item= basilisk_respond_getmessage(myinfo,key,keylen)) != 0 )
@ -187,7 +210,9 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
{ {
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"sender"),hash); keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"sender"),hash);
if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 ) if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 )
{
retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration")); retstr = basilisk_respond_addmessage(myinfo,key,keylen,data,datalen,0,juint(vals,"duration"));
}
if ( ptr != 0 ) if ( ptr != 0 )
free(ptr); free(ptr);
if ( retstr != 0 ) if ( retstr != 0 )

6
basilisk/basilisk_ping.c

@ -107,7 +107,7 @@ int32_t basilisk_ping_genvirts(struct supernet_info *myinfo,uint8_t *data,int32_
int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipbits,uint8_t *data,int32_t datalen) int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipbits,uint8_t *data,int32_t datalen)
{ {
int32_t i,msglen,len=0; uint8_t num,keylen,*msg,*key; uint32_t duration; int32_t i,msglen,len=0; uint8_t num,keylen,*message,*key; uint32_t duration;
if ( (num= data[len++]) > 0 ) if ( (num= data[len++]) > 0 )
{ {
//printf("processMSG num.%d datalen.%d\n",num,datalen); //printf("processMSG num.%d datalen.%d\n",num,datalen);
@ -127,14 +127,14 @@ int32_t basilisk_ping_processMSG(struct supernet_info *myinfo,uint32_t senderipb
} }
len += iguana_rwnum(0,&data[len],sizeof(msglen),&msglen); len += iguana_rwnum(0,&data[len],sizeof(msglen),&msglen);
len += iguana_rwnum(0,&data[len],sizeof(duration),&duration); len += iguana_rwnum(0,&data[len],sizeof(duration),&duration);
msg = &data[len], len += msglen; message = &data[len], len += msglen;
if ( msglen <= 0 || len > datalen ) if ( msglen <= 0 || len > datalen )
{ {
printf("illegal msglen.%d or len.%d > %d\n",msglen,len,datalen); printf("illegal msglen.%d or len.%d > %d\n",msglen,len,datalen);
return(0); return(0);
} }
//printf("i.%d: keylen.%d msglen.%d\n",i,keylen,msglen); //printf("i.%d: keylen.%d msglen.%d\n",i,keylen,msglen);
basilisk_respond_addmessage(myinfo,key,keylen,msg,msglen,0,duration); basilisk_respond_addmessage(myinfo,key,keylen,message,msglen,0,duration);
} }
} }
return(len); return(len);

2
iguana/iguana777.h

@ -76,7 +76,7 @@ struct supernet_info
uint8_t persistent_pubkey33[33]; uint8_t persistent_pubkey33[33];
char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024]; char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024];
char *decryptstr; char *decryptstr;
int32_t maxdelay,IAMRELAY,IAMNOTARY,IAMLP,publicRPC,basilisk_busy,genesisresults; int32_t maxdelay,IAMRELAY,IAMNOTARY,IAMLP,publicRPC,basilisk_busy,genesisresults,remoteorigin;
uint32_t expiration,dirty,DEXactive,DEXpoll; uint32_t expiration,dirty,DEXactive,DEXpoll;
uint16_t argport,rpcport; uint16_t argport,rpcport;
struct basilisk_info basilisks; struct basilisk_info basilisks;

10
iguana/iguana_rpc.c

@ -838,6 +838,16 @@ char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsiz
cJSON *tokens,*argjson,*origargjson,*json = 0; long filesize; struct iguana_info *coin = 0; cJSON *tokens,*argjson,*origargjson,*json = 0; long filesize; struct iguana_info *coin = 0;
char symbol[64],buf[4096],urlmethod[16],*data,url[1024],furl[1024],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0; char symbol[64],buf[4096],urlmethod[16],*data,url[1024],furl[1024],*retstr,*filestr,*token = 0; int32_t i,j,n,num=0;
//printf("rpcparse.(%s)\n",urlstr); //printf("rpcparse.(%s)\n",urlstr);
if ( myinfo->remoteorigin == 0 )
{
n = (int32_t)(strlen(urlstr) - strlen("Origin: "));
for (i=0; i<n; i++)
if ( strncmp("Origin: ",&urlstr[i],strlen("Origin: ")) == 0 )
{
printf("remote Origin REJECT.(%s)\n",urlstr);
return(clonestr("{\"error\":\"remote origin not enabled\"}"));
}
}
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++) for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
urlmethod[i] = urlstr[i]; urlmethod[i] = urlstr[i];
urlmethod[i++] = 0; urlmethod[i++] = 0;

1
iguana/main.c

@ -610,6 +610,7 @@ int32_t iguana_commandline(struct supernet_info *myinfo,char *arg)
else else
{ {
IGUANA_NUMHELPERS = juint(argjson,"numhelpers"); IGUANA_NUMHELPERS = juint(argjson,"numhelpers");
myinfo->remoteorigin = juint(argjson,"remoteorigin");
free_json(argjson); free_json(argjson);
printf("Will run (%s) after initialized with %d threads\n",COMMANDLINE_ARGFILE,IGUANA_NUMHELPERS); printf("Will run (%s) after initialized with %d threads\n",COMMANDLINE_ARGFILE,IGUANA_NUMHELPERS);
} }

Loading…
Cancel
Save