Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
b8ce7833c9
  1. 1
      basilisk/basilisk.h
  2. 30
      basilisk/basilisk_CMD.c
  3. 10
      iguana/main.c

1
basilisk/basilisk.h

@ -135,5 +135,6 @@ void basilisk_seqresult(struct supernet_info *myinfo,char *retstr);
struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj); struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj);
void basilisk_alicepayment(struct supernet_info *myinfo,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn); void basilisk_alicepayment(struct supernet_info *myinfo,struct iguana_info *coin,struct basilisk_rawtx *alicepayment,bits256 pubAm,bits256 pubBn);
void basilisk_rawtx_setparms(char *name,struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,struct iguana_info *coin,int32_t numconfirms,int32_t vintype,uint64_t satoshis,int32_t vouttype,uint8_t *pubkey33); void basilisk_rawtx_setparms(char *name,struct supernet_info *myinfo,struct basilisk_swap *swap,struct basilisk_rawtx *rawtx,struct iguana_info *coin,int32_t numconfirms,int32_t vintype,uint64_t satoshis,int32_t vouttype,uint8_t *pubkey33);
void basilisk_setmyid(struct supernet_info *myinfo);
#endif #endif

30
basilisk/basilisk_CMD.c

@ -18,6 +18,8 @@
struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *btcd,uint32_t ipbits) struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *btcd,uint32_t ipbits)
{ {
struct iguana_peer *addr; int32_t i; struct iguana_peer *addr; int32_t i;
if ( btcd == 0 )
return(0);
if ( (addr= iguana_peerfindipbits(btcd,ipbits,0)) == 0 ) if ( (addr= iguana_peerfindipbits(btcd,ipbits,0)) == 0 )
{ {
if ( (addr= iguana_peerslot(btcd,ipbits,0)) != 0 ) if ( (addr= iguana_peerslot(btcd,ipbits,0)) != 0 )
@ -31,7 +33,6 @@ struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct igu
myinfo->RELAYID = i; myinfo->RELAYID = i;
break; break;
} }
iguana_launch(btcd,"addrelay",iguana_startconnection,addr,IGUANA_CONNTHREAD); iguana_launch(btcd,"addrelay",iguana_startconnection,addr,IGUANA_CONNTHREAD);
} else printf("error getting peerslot\n"); } else printf("error getting peerslot\n");
} else addr->isrelay = 1; } else addr->isrelay = 1;
@ -61,12 +62,21 @@ void basilisk_relay_remap(struct supernet_info *myinfo,struct basilisk_relay *rp
rp->reported[myinfo->relays[i].relayid] = tmp[myinfo->relays[i].oldrelayid]; rp->reported[myinfo->relays[i].relayid] = tmp[myinfo->relays[i].oldrelayid];
} }
void basilisk_setmyid(struct supernet_info *myinfo)
{
int32_t i; char ipaddr[64]; struct iguana_info *btcd = iguana_coinfind("BTCD");
for (i=0; i<myinfo->numrelays; i++)
{
expand_ipbits(ipaddr,myinfo->relays[i].ipbits);
if ( myinfo->myaddr.myipbits == myinfo->relays[i].ipbits )
myinfo->RELAYID = i;
basilisk_ensurerelay(myinfo,btcd,myinfo->relays[i].ipbits);
}
}
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;
//return(clonestr("{\"error\":\"addrelay info disabled\"}"));
if ( (btcd= iguana_coinfind("BTCD")) == 0 || ipbits == 0 )
return(clonestr("{\"error\":\"add relay needs BTCD and ipbits\"}"));
for (i=0; i<myinfo->numrelays; i++) for (i=0; i<myinfo->numrelays; i++)
{ {
rp = &myinfo->relays[i]; rp = &myinfo->relays[i];
@ -88,19 +98,13 @@ char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint
rp = &myinfo->relays[i]; rp = &myinfo->relays[i];
rp->ipbits = ipbits; rp->ipbits = ipbits;
rp->relayid = myinfo->numrelays; rp->relayid = myinfo->numrelays;
basilisk_ensurerelay(myinfo,btcd,rp->ipbits); basilisk_ensurerelay(myinfo,iguana_coinfind("BTCD"),rp->ipbits);
if ( myinfo->numrelays < sizeof(myinfo->relays)/sizeof(*myinfo->relays) ) if ( myinfo->numrelays < sizeof(myinfo->relays)/sizeof(*myinfo->relays) )
myinfo->numrelays++; myinfo->numrelays++;
qsort(myinfo->relays,myinfo->numrelays,sizeof(myinfo->relays[0]),_decreasing_ipbits); qsort(myinfo->relays,myinfo->numrelays,sizeof(myinfo->relays[0]),_decreasing_ipbits);
for (i=0; i<myinfo->numrelays; i++) for (i=0; i<myinfo->numrelays; i++)
{
char ipaddr[64];
expand_ipbits(ipaddr,myinfo->relays[i].ipbits);
if ( myinfo->myaddr.myipbits == myinfo->relays[i].ipbits )
myinfo->RELAYID = i;
myinfo->relays[i].relayid = i; myinfo->relays[i].relayid = i;
printf("%s ",ipaddr); basilisk_setmyid(myinfo);
}
printf("sorted MYRELAYID.%d\n",myinfo->RELAYID); printf("sorted MYRELAYID.%d\n",myinfo->RELAYID);
for (i=0; i<myinfo->numrelays; i++) for (i=0; i<myinfo->numrelays; i++)
basilisk_relay_remap(myinfo,&myinfo->relays[i]); basilisk_relay_remap(myinfo,&myinfo->relays[i]);

10
iguana/main.c

@ -1293,7 +1293,7 @@ STRING_ARG(SuperNET,priv2wif,priv)
STRING_ARG(SuperNET,myipaddr,ipaddr) STRING_ARG(SuperNET,myipaddr,ipaddr)
{ {
int32_t i; cJSON *retjson = cJSON_CreateObject(); cJSON *retjson = cJSON_CreateObject();
myinfo->RELAYID = -1; myinfo->RELAYID = -1;
if ( myinfo->ipaddr[0] == 0 ) if ( myinfo->ipaddr[0] == 0 )
{ {
@ -1301,12 +1301,7 @@ STRING_ARG(SuperNET,myipaddr,ipaddr)
{ {
strcpy(myinfo->ipaddr,ipaddr); strcpy(myinfo->ipaddr,ipaddr);
myinfo->myaddr.myipbits = (uint32_t)calc_ipbits(ipaddr); myinfo->myaddr.myipbits = (uint32_t)calc_ipbits(ipaddr);
for (i=0; i<myinfo->numrelays; i++) basilisk_setmyid(myinfo);
if ( myinfo->relays[i].ipbits == myinfo->myaddr.myipbits )
{
myinfo->RELAYID = i;
break;
}
} }
} }
jaddstr(retjson,"result",myinfo->ipaddr); jaddstr(retjson,"result",myinfo->ipaddr);
@ -1324,6 +1319,7 @@ STRING_ARG(SuperNET,setmyipaddr,ipaddr)
if ( is_ipaddr(ipaddr) != 0 ) if ( is_ipaddr(ipaddr) != 0 )
{ {
strcpy(myinfo->ipaddr,ipaddr); strcpy(myinfo->ipaddr,ipaddr);
basilisk_setmyid(myinfo);
jaddstr(retjson,"result",myinfo->ipaddr); jaddstr(retjson,"result",myinfo->ipaddr);
} else jaddstr(retjson,"error","illegal ipaddr"); } else jaddstr(retjson,"error","illegal ipaddr");
return(jprint(retjson,1)); return(jprint(retjson,1));

Loading…
Cancel
Save