Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
91d9767f1b
  1. 10
      basilisk/basilisk.c
  2. 27
      basilisk/basilisk_CMD.c
  3. 2
      iguana/SuperNET.h

10
basilisk/basilisk.c

@ -101,7 +101,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
else if ( fanout > BASILISK_MAXFANOUT ) else if ( fanout > BASILISK_MAXFANOUT )
fanout = BASILISK_MAXFANOUT; fanout = BASILISK_MAXFANOUT;
if ( type == 0 ) if ( type == 0 )
type = ""; type = "BTCD";
if ( strlen(type) > 3 ) if ( strlen(type) > 3 )
{ {
printf("basilisk_sendcmd illegal type(%s)\n",type); printf("basilisk_sendcmd illegal type(%s)\n",type);
@ -309,7 +309,7 @@ struct basilisk_item *basilisk_requestservice(struct basilisk_item *Lptr,struct
timeoutmillis = BASILISK_TIMEOUT; timeoutmillis = BASILISK_TIMEOUT;
encryptflag = jint(valsobj,"encrypt"); encryptflag = jint(valsobj,"encrypt");
delaymillis = jint(valsobj,"delay"); delaymillis = jint(valsobj,"delay");
return(basilisk_issueremote(myinfo,&numsent,CMD,"",valsobj,1,minresults,basilisktag,timeoutmillis,0,0,encryptflag,delaymillis)); return(basilisk_issueremote(myinfo,&numsent,CMD,"BTCD",valsobj,1,minresults,basilisktag,timeoutmillis,0,0,encryptflag,delaymillis));
} }
void basilisk_sendback(struct supernet_info *myinfo,char *symbol,char *remoteaddr,uint32_t basilisktag,char *retstr) void basilisk_sendback(struct supernet_info *myinfo,char *symbol,char *remoteaddr,uint32_t basilisktag,char *retstr)
@ -383,9 +383,9 @@ char *basilisk_standardservice(char *CMD,basilisk_requestfunc *func,struct super
if ( blockflag != 0 ) if ( blockflag != 0 )
{ {
ptr->vals = jduplicate(vals); ptr->vals = jduplicate(vals);
strcpy(ptr->symbol,""); strcpy(ptr->symbol,"BTCD");
strcpy(ptr->CMD,CMD); strcpy(ptr->CMD,CMD);
return(basilisk_block(myinfo,CMD,"",0,&Lptr,ptr)); return(basilisk_block(myinfo,CMD,"BTCD",0,&Lptr,ptr));
} }
else if ( ptr->numsent > 0 ) else if ( ptr->numsent > 0 )
{ {
@ -777,7 +777,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender
data += sizeof(pubkey), datalen -= sizeof(pubkey); data += sizeof(pubkey), datalen -= sizeof(pubkey);
} else data = 0, datalen = 0; } else data = 0, datalen = 0;
if ( (symbol= jstr(valsobj,"coin")) == 0 ) if ( (symbol= jstr(valsobj,"coin")) == 0 )
symbol = ""; symbol = "BTCD";
timeoutmillis = jint(valsobj,"timeout"); timeoutmillis = jint(valsobj,"timeout");
if ( (numrequired= jint(valsobj,"numrequired")) == 0 ) if ( (numrequired= jint(valsobj,"numrequired")) == 0 )
numrequired = 1; numrequired = 1;

27
basilisk/basilisk_CMD.c

@ -33,7 +33,7 @@ void basilisk_request_goodbye(struct supernet_info *myinfo)
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 prevhash,int32_t from_basilisk) 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 prevhash,int32_t from_basilisk)
{ {
bits256 hash,cathash; struct category_info *cat,*prevcat=0; char *category; char str[65]; bits256 hash,cathash; struct category_info *rootcat,*cat,*prevcat=0; char *category; char str[65];
printf("from.(%s) SET.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen); printf("from.(%s) SET.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen);
if ( datalen <= 0 || (category= jstr(valsobj,"category")) == 0 ) if ( datalen <= 0 || (category= jstr(valsobj,"category")) == 0 )
return(0); return(0);
@ -47,11 +47,17 @@ char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,struct ig
printf("basilisk_respond_publish: cant find prevhash.%s\n",bits256_str(str,prevhash)); printf("basilisk_respond_publish: cant find prevhash.%s\n",bits256_str(str,prevhash));
} }
} else memset(prevhash.bytes,0,sizeof(prevhash)); } else memset(prevhash.bytes,0,sizeof(prevhash));
if ( (cat= category_find(cathash,hash)) == 0 ) if ( (rootcat= category_find(cathash,GENESIS_PUBKEY)) == 0 )
printf("error finding category.(%s)\n",category);
else if ( (cat= category_find(cathash,hash)) == 0 )
printf("error finding just added category\n"); printf("error finding just added category\n");
else
{
rootcat->lasthash = hash;
cat->prevhash = prevhash; cat->prevhash = prevhash;
if ( prevcat != 0 ) if ( prevcat != 0 )
prevcat->next = cat; prevcat->next = cat;
}
return(0); return(0);
} }
@ -63,19 +69,32 @@ struct basilisk_item *basilisk_request_setfield(struct basilisk_item *Lptr,struc
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 prevhash,int32_t from_basilisk) 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 prevhash,int32_t from_basilisk)
{ {
bits256 cathash; struct category_info *cat; char *category,*hexstr; cJSON *retjson; bits256 cathash; struct category_info *cat; char *category,*hexstr; cJSON *retjson;
printf("from.(%s) GET.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen);
if ( (category= jstr(valsobj,"category")) == 0 ) if ( (category= jstr(valsobj,"category")) == 0 )
return(0); return(0);
vcalc_sha256(0,cathash.bytes,(uint8_t *)category,(int32_t)strlen(category)); vcalc_sha256(0,cathash.bytes,(uint8_t *)category,(int32_t)strlen(category));
char str[65]; printf("from.(%s) GET.(%s) datalen.%d %s\n",remoteaddr,jprint(valsobj,0),datalen,bits256_str(str,cathash));
retjson = cJSON_CreateObject();
if ( bits256_nonz(prevhash) == 0 || bits256_cmp(GENESIS_PUBKEY,prevhash) == 0 )
{
if ( (cat= category_find(cathash,GENESIS_PUBKEY)) == 0 )
jaddstr(retjson,"error","cant find category");
else
{
jaddbits256(retjson,"genesis",cat->hash);
jaddbits256(retjson,"last",cat->lasthash);
}
}
else
{
if ( (cat= category_find(cathash,prevhash)) == 0 ) if ( (cat= category_find(cathash,prevhash)) == 0 )
printf("error finding just added category\n"); printf("error finding just added category\n");
retjson = cJSON_CreateObject();
if ( cat->datalen > 0 ) if ( cat->datalen > 0 )
{ {
hexstr = calloc(1,(cat->datalen << 1) + 1); hexstr = calloc(1,(cat->datalen << 1) + 1);
init_hexbytes_noT(hexstr,cat->data,cat->datalen); init_hexbytes_noT(hexstr,cat->data,cat->datalen);
jaddstr(retjson,"data",hexstr); jaddstr(retjson,"data",hexstr);
} }
}
return(jprint(retjson,1)); return(jprint(retjson,1));
} }

2
iguana/SuperNET.h

@ -130,7 +130,7 @@ struct category_info
{ {
UT_hash_handle hh; queue_t Q; UT_hash_handle hh; queue_t Q;
char *(*processfunc)(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t datalen,char *remoteaddr); char *(*processfunc)(struct supernet_info *myinfo,struct category_info *cat,void *data,int32_t datalen,char *remoteaddr);
struct category_chain *catchain; bits256 hash,prevhash; void *info; struct category_info *sub,*next; struct category_chain *catchain; bits256 hash,prevhash,lasthash; void *info; struct category_info *sub,*next;
int32_t datalen; uint8_t data[]; int32_t datalen; uint8_t data[];
}; };

Loading…
Cancel
Save