Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
6556f5cf80
  1. 24
      basilisk/basilisk.c
  2. 1
      basilisk/basilisk.h
  3. 3
      basilisk/basilisk_CMD.c
  4. 10
      iguana/iguana_msg.c

24
basilisk/basilisk.c

@ -80,15 +80,14 @@ uint8_t *get_dataptr(int32_t hdroffset,uint8_t **ptrp,int32_t *datalenp,uint8_t
uint8_t *basilisk_jsondata(int32_t extraoffset,uint8_t **ptrp,uint8_t *space,int32_t spacesize,int32_t *datalenp,char *symbol,cJSON *sendjson,uint32_t basilisktag) uint8_t *basilisk_jsondata(int32_t extraoffset,uint8_t **ptrp,uint8_t *space,int32_t spacesize,int32_t *datalenp,char *symbol,cJSON *sendjson,uint32_t basilisktag)
{ {
char *sendstr,*hexstr; uint8_t *data; int32_t datalen,hexlen=0; char *sendstr,*hexstr=0; uint8_t *data,hexspace[8192],*allocptr=0,*hexdata; int32_t datalen,hexlen=0;
if ( jobj(sendjson,"coin") == 0 ) if ( jobj(sendjson,"coin") == 0 )
jaddstr(sendjson,"coin",symbol); jaddstr(sendjson,"coin",symbol);
if ( (hexstr= jstr(sendjson,"data")) != 0 ) if ( (hexstr= jstr(sendjson,"data")) != 0 )
{ {
if ( (hexlen= is_hexstr(hexstr,0)) > 0 ) hexdata = get_dataptr(0,&allocptr,&hexlen,hexspace,sizeof(hexspace),hexstr);
hexlen >>= 1; printf("delete data.%s from sendjson\n",hexstr);
jdelete(sendjson,"data"); jdelete(sendjson,"data");
printf("delete data.[%d] from sendjson\n",hexlen);
} }
*ptrp = 0; *ptrp = 0;
sendstr = jprint(sendjson,0); sendstr = jprint(sendjson,0);
@ -106,10 +105,12 @@ uint8_t *basilisk_jsondata(int32_t extraoffset,uint8_t **ptrp,uint8_t *space,int
free(sendstr); free(sendstr);
if ( hexlen > 0 ) if ( hexlen > 0 )
{ {
decode_hex(&data[datalen],hexlen,hexstr); memcpy(&data[datalen],hexdata,hexlen);
datalen += hexlen; datalen += hexlen;
} }
*datalenp = datalen; *datalenp = datalen;
if ( allocptr != 0 )
free(allocptr);
return(data); return(data);
} }
@ -209,7 +210,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
//printf("%s s.%d vs n.%d\n",addr->ipaddr,s,n); //printf("%s s.%d vs n.%d\n",addr->ipaddr,s,n);
if ( s == n && (addr->supernet != 0 || addr->basilisk != 0) && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) ) if ( s == n && (addr->supernet != 0 || addr->basilisk != 0) && (destipaddr == 0 || strcmp(addr->ipaddr,destipaddr) == 0) )
{ {
printf("[%s].tag%d send %s.(%s) addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",cmd,*(uint32_t *)data,type,(char *)&data[4],addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast"); printf("[%s].tag%d send %s.(%s) [%x] datalen.%d addr->supernet.%u basilisk.%u to (%s).%d destip.%s\n",cmd,*(uint32_t *)data,type,(char *)&data[4],*(int32_t *)&data[datalen-4],datalen,addr->supernet,addr->basilisk,addr->ipaddr,addr->A.port,destipaddr!=0?destipaddr:"broadcast");
if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 ) if ( encryptflag != 0 && bits256_nonz(addr->pubkey) != 0 )
{ {
void *ptr; uint8_t *cipher,space[8192]; int32_t cipherlen; bits256 privkey; void *ptr; uint8_t *cipher,space[8192]; int32_t cipherlen; bits256 privkey;
@ -277,7 +278,9 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t
ipbits = (uint32_t)calc_ipbits(senderip); ipbits = (uint32_t)calc_ipbits(senderip);
else ipbits = 0; else ipbits = 0;
len += iguana_rwnum(0,data,sizeof(basilisktag),&basilisktag); len += iguana_rwnum(0,data,sizeof(basilisktag),&basilisktag);
//printf("received.%d basilisk_p2p.(%s) from %s tag.%d\n",datalen,type,senderip!=0?senderip:"?",basilisktag); int32_t i; for (i=0; i<datalen-len; i++)
printf("%02x",data[len+i]);
printf(" ->received.%d basilisk_p2p.(%s) from %s tag.%d\n",datalen,type,senderip!=0?senderip:"?",basilisktag);
basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len); basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len);
if ( ptr != 0 ) if ( ptr != 0 )
free(ptr); free(ptr);
@ -1076,8 +1079,11 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
if ( datalen > jsonlen ) if ( datalen > jsonlen )
{ {
data += jsonlen, datalen -= jsonlen; data += jsonlen, datalen -= jsonlen;
if ( *data++ != 0 ) for (i=0; i<datalen; i++)
data += sizeof(hash), datalen -= sizeof(hash); printf("%02x",data[i]);
printf(" <-> got datalen.%d\n",datalen);
//if ( *data++ != 0 )
// data += sizeof(hash), datalen -= sizeof(hash);
} else data = 0, datalen = 0; } else data = 0, datalen = 0;
if ( coin == 0 ) if ( coin == 0 )
coin = iguana_coinfind("BTCD"); coin = iguana_coinfind("BTCD");

1
basilisk/basilisk.h

@ -64,6 +64,7 @@ uint8_t *get_dataptr(int32_t hdroffset,uint8_t **ptrp,int32_t *datalenp,uint8_t
char *basilisk_addhexstr(char **ptrp,cJSON *valsobj,char *strbuf,int32_t strsize,uint8_t *data,int32_t datalen); char *basilisk_addhexstr(char **ptrp,cJSON *valsobj,char *strbuf,int32_t strsize,uint8_t *data,int32_t datalen);
char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,bits256 hash,cJSON *valsobj,char *hexstr,int32_t blockflag); // client side char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,bits256 hash,cJSON *valsobj,char *hexstr,int32_t blockflag); // client side
char *basilisk_respond_mempool(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_mempool(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_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint32_t ipbits,bits256 pubkey);
void basilisk_request_goodbye(struct supernet_info *myinfo); void basilisk_request_goodbye(struct supernet_info *myinfo);
int32_t basilisk_update(char *symbol,uint32_t reftimestamp); int32_t basilisk_update(char *symbol,uint32_t reftimestamp);

3
basilisk/basilisk_CMD.c

@ -33,6 +33,7 @@ struct iguana_peer *basilisk_ensurerelay(struct iguana_info *btcd,uint32_t ipbit
char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint32_t ipbits,bits256 pubkey) char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint32_t ipbits,bits256 pubkey)
{ {
int32_t i; struct basilisk_relay *rp; struct iguana_info *btcd; int32_t i; struct basilisk_relay *rp; struct iguana_info *btcd;
printf("addrelay.%x\n",ipbits);
if ( (btcd= iguana_coinfind("BTCD")) == 0 || ipbits == 0 ) if ( (btcd= iguana_coinfind("BTCD")) == 0 || ipbits == 0 )
return(clonestr("{\"error\":\"add relay needs BTCD and ipbits\"}")); return(clonestr("{\"error\":\"add relay needs BTCD and ipbits\"}"));
for (i=0; i<myinfo->numrelays; i++) for (i=0; i<myinfo->numrelays; i++)
@ -95,6 +96,7 @@ char *basilisk_respond_relays(struct supernet_info *myinfo,char *CMD,void *_addr
for (i=len=0; i<n; i++) for (i=len=0; i<n; i++)
{ {
len += iguana_rwnum(0,(void *)&data[len],sizeof(uint32_t),&ipbits); len += iguana_rwnum(0,(void *)&data[len],sizeof(uint32_t),&ipbits);
printf("(%d %x) ",i,ipbits);
if ( (retstr= basilisk_addrelay_info(myinfo,0,ipbits,GENESIS_PUBKEY)) != 0 ) if ( (retstr= basilisk_addrelay_info(myinfo,0,ipbits,GENESIS_PUBKEY)) != 0 )
free(retstr); free(retstr);
} }
@ -121,7 +123,6 @@ int32_t basilisk_relays_send(struct supernet_info *myinfo,struct iguana_peer *ad
init_hexbytes_noT(strbuf,sig,siglen); init_hexbytes_noT(strbuf,sig,siglen);
jaddstr(vals,"sig",strbuf); jaddstr(vals,"sig",strbuf);
} }
init_hexbytes_noT(hexstr,serialized,len);
if ( (retstr= basilisk_standardservice("RLY",myinfo,hash,vals,hexstr,0)) != 0 ) if ( (retstr= basilisk_standardservice("RLY",myinfo,hash,vals,hexstr,0)) != 0 )
free(retstr); free(retstr);
free_json(vals); free_json(vals);

10
iguana/iguana_msg.c

@ -308,12 +308,16 @@ int32_t iguana_rwmsgalert(struct iguana_info *coin,int32_t rwflag,uint8_t *seria
return(len); return(len);
}*/ }*/
void iguana_gotversion(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msgversion *vers) void iguana_gotversion(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msgversion *vers)
{ {
uint8_t serialized[sizeof(struct iguana_msghdr)]; uint8_t serialized[sizeof(struct iguana_msghdr)]; char *retstr;
//printf("gotversion from %s: starting height.%d services.%llx proto.%d (%s)\n",addr->ipaddr,vers->nStartingHeight,(long long)vers->nServices,vers->nVersion,vers->strSubVer); //printf("gotversion from %s: starting height.%d services.%llx proto.%d (%s)\n",addr->ipaddr,vers->nStartingHeight,(long long)vers->nServices,vers->nVersion,vers->strSubVer);
if ( strncmp(vers->strSubVer,"/iguana",strlen("/iguana")) == 0 ) if ( strncmp(vers->strSubVer,"/iguana",strlen("/iguana")) == 0 )
{
addr->supernet = 1, addr->basilisk = 0; addr->supernet = 1, addr->basilisk = 0;
if ( (retstr= basilisk_addrelay_info(myinfo,0,(uint32_t)addr->ipbits,GENESIS_PUBKEY)) != 0 )
free(retstr);
}
else if ( strncmp(vers->strSubVer,"/basilisk",strlen("/basilisk")) == 0 ) else if ( strncmp(vers->strSubVer,"/basilisk",strlen("/basilisk")) == 0 )
addr->basilisk = 1, addr->supernet = 0; addr->basilisk = 1, addr->supernet = 0;
if ( (vers->nServices & NODE_NETWORK) != 0 ) if ( (vers->nServices & NODE_NETWORK) != 0 )
@ -944,7 +948,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
struct iguana_msgversion recvmv; struct iguana_msgversion recvmv;
len = iguana_rwversion(0,data,&recvmv,addr->ipaddr,recvlen); len = iguana_rwversion(0,data,&recvmv,addr->ipaddr,recvlen);
if ( len <= recvlen ) if ( len <= recvlen )
iguana_gotversion(coin,addr,&recvmv); iguana_gotversion(myinfo,coin,addr,&recvmv);
addr->msgcounts.version++; addr->msgcounts.version++;
} }
else else

Loading…
Cancel
Save