Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
f0151518ed
  1. 44
      deprecated/obsolete.h
  2. 335
      iguana/SuperNET.c
  3. 18
      iguana/SuperNET.h
  4. 9
      iguana/iguana777.h
  5. 52
      iguana/iguana_json.c
  6. 15
      iguana/iguana_msg.c
  7. 13
      iguana/iguana_peers.c
  8. 49
      iguana/iguana_rpc.c
  9. 274
      iguana/main.c

44
deprecated/obsolete.h

@ -11956,6 +11956,25 @@ void iguana_dedicatedrecv(void *arg)
}
return(clonestr("{\"error\":\"cant find hash function\"}"));
}*/
/*cJSON *SuperNET_transportencode(struct supernet_info *myinfo,bits256 destpub,cJSON *json,char *destip)
{
char str[65]; uint64_t r;
if ( j64bits(json,"tag") == 0 )
{
OS_randombytes((uint8_t *)&r,sizeof(r));
jadd64bits(json,"tag",r);
}
jdelete(json,"yourip");
jaddstr(json,"yourip",destip);
jdelete(json,"mypub");
jaddstr(json,"mypub",bits256_str(str,myinfo->myaddr.pubkey));
jdelete(json,"myip");
jaddstr(json,"myip",myinfo->ipaddr);
return(json);
}*/
void ramcoder_test(void *data,int64_t datalen)
{
static double totalin,totalout;
@ -11967,4 +11986,29 @@ void iguana_dedicatedrecv(void *arg)
printf("datalen.%d -> numbits.%d %d %.3f\n",(int32_t)datalen,complen,complen>>3,(double)totalin/totalout);
free(buf);
}
/*if ( (msgjson= cJSON_Parse(message)) != 0 )
{
if ( (agent= jstr(msgjson,"agent")) != 0 && strcmp(agent,"SuperNET")) != 0 )
{
safecopy(agentstr,agent,sizeof(agentstr)-1);
jdelete(msgjson,"agent");
jaddstr(msgjson,"agent","SuperNET");
jaddstr(msgjson,"destagent",agentstr);
}
if ( (method= jstr(msgjson,"method")) != 0 && strcmp(agent,"SuperNET")) != 0 )
{
safecopy(methodstr,method,sizeof(methodstr)-1);
jdelete(msgjson,"method");
jaddstr(msgjson,"method","DHTsend");
jaddstr(msgjson,"destmethod",methodstr);
}
msgstr = jprint(msgjson,1);
msglen = (int32_t)strlen(msgstr);
hexstr = calloc(1,msglen*2+1);
flag = 1;
init_hexbytes_noT(hexstr,msgstr,msglen);
}
if ( flag != 0 )
free(hexstr);*/
#endif

335
iguana/SuperNET.c

@ -0,0 +1,335 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#include "iguana777.h"
int32_t SuperNET_delaymillis(struct supernet_info *myinfo,int32_t maxdelay)
{
maxdelay += myinfo->maxdelay;
if ( maxdelay > SUPERNET_MAXDELAY )
maxdelay = SUPERNET_MAXDELAY;
return(rand() % maxdelay);
}
void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag)
{
uint64_t ipbits; struct iguana_peer *addr;
//printf("got %s remotepeer.(%s) supernet.%d\n",symbol,ipaddr,supernetflag);
if ( supernetflag != 0 )
{
ipbits = calc_ipbits(ipaddr);
if ( (addr= iguana_peerslot(coin,ipbits)) != 0 )
{
printf("launch startconnection to supernet peer.(%s)\n",ipaddr);
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
return;
}
}
iguana_possible_peer(coin,ipaddr);
}
int32_t SuperNET_confirmip(struct supernet_info *myinfo,uint32_t ipbits)
{
int32_t i,j,total = 0; uint32_t x;
for (i=0; i<IGUANA_MAXCOINS; i++)
{
if ( Coins[i] != 0 )
{
for (j=0; j<IGUANA_MAXPEERS; j++)
{
if ( (x= Coins[i]->peers.active[j].myipbits) != 0 )
{
if ( x == ipbits )
total++;
else total--;
}
}
}
}
return(total);
}
void SuperNET_myipaddr(struct supernet_info *myinfo,struct iguana_peer *addr,char *myipaddr,char *remoteaddr)
{
uint32_t myipbits = (uint32_t)calc_ipbits(myipaddr);
if ( addr->myipbits == 0 )
addr->myipbits = myipbits;
else if ( addr->myipbits != myipbits )
{
printf("%s: myipaddr conflict %x != %x?\n",addr->ipaddr,addr->myipbits,myipbits);
addr->myipbits = 0;
}
if ( addr->myipbits != 0 && myinfo->myaddr.myipbits == 0 )
myinfo->myaddr.myipbits = addr->myipbits;
if ( addr->myipbits == myinfo->myaddr.myipbits )
{
myinfo->myaddr.confirmed++;
if ( myinfo->myaddr.selfipbits == 0 || myinfo->ipaddr[0] == 0 )
{
if ( (myinfo->myaddr.totalconfirmed= SuperNET_confirmip(myinfo,addr->myipbits)) > 3 )
myinfo->myaddr.selfipbits = addr->myipbits;
}
}
else myinfo->myaddr.confirmed--;
if ( myinfo->myaddr.selfipbits == myinfo->myaddr.myipbits )
{
expand_ipbits(myinfo->ipaddr,myinfo->myaddr.selfipbits);
vcalc_sha256(0,myinfo->myaddr.iphash.bytes,(uint8_t *)&myinfo->myaddr.selfipbits,sizeof(myinfo->myaddr.selfipbits));
}
}
int32_t SuperNET_json2bits(struct supernet_info *myinfo,uint8_t *serialized,int32_t maxsize,char *destip,bits256 destpub,cJSON *json)
{
uint32_t ipbits; uint64_t tag; char *hexmsg; int32_t n,len = 0;
if ( (tag= j64bits(json,"tag")) == 0 )
OS_randombytes((uint8_t *)&tag,sizeof(tag));
ipbits = (uint32_t)calc_ipbits(destip);
len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),&ipbits);
ipbits = (uint32_t)calc_ipbits(myinfo->ipaddr);
len += iguana_rwnum(1,&serialized[len],sizeof(uint32_t),&ipbits);
len += iguana_rwbignum(1,&serialized[len],sizeof(myinfo->myaddr.pubkey),myinfo->myaddr.pubkey.bytes);
len += iguana_rwnum(1,&serialized[len],sizeof(tag),&tag);
if ( (hexmsg= jstr(json,"message")) != 0 )
{
n = (int32_t)strlen(hexmsg);
if ( (n & 1) == 0 && is_hexstr(hexmsg,n) > 0 )
{
n >>= 1;
decode_hex(&serialized[len],n,hexmsg);
} else return(-1);
}
return(len);
}
cJSON *SuperNET_bits2json(struct supernet_info *myinfo,bits256 prevpub,uint8_t *serialized,int32_t datalen)
{
char destip[64],myipaddr[64],str[65],*hexmsg; uint64_t tag; int32_t len = 0;
uint32_t destipbits,myipbits; bits256 senderpub; cJSON *json = cJSON_CreateObject();
len += iguana_rwnum(0,&serialized[len],sizeof(uint32_t),&destipbits);
len += iguana_rwnum(0,&serialized[len],sizeof(uint32_t),&myipbits);
len += iguana_rwbignum(0,&serialized[len],sizeof(bits256),senderpub.bytes);
len += iguana_rwnum(0,&serialized[len],sizeof(tag),&tag);
expand_ipbits(destip,destipbits), jaddstr(json,"yourip",destip);
expand_ipbits(myipaddr,myipbits), jaddstr(json,"myip",myipaddr);
jaddstr(json,"mypub",bits256_str(str,senderpub));
jadd64bits(json,"tag",tag);
if ( len < datalen )
{
hexmsg = malloc(((datalen - len)<<1) + 1);
init_hexbytes_noT(hexmsg,&serialized[len],datalen - len);
jaddstr(json,"message",hexmsg);
free(hexmsg);
}
return(json);
}
int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,char *jsonstr,int32_t delaymillis)
{
int32_t datalen,qlen = -1; uint8_t *serialized; cJSON *json;
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
serialized = malloc(sizeof(struct iguana_msghdr) + IGUANA_MAXPACKETSIZE);
datalen = SuperNET_json2bits(SuperNET_MYINFO(0),&serialized[sizeof(struct iguana_msghdr)],IGUANA_MAXPACKETSIZE,addr->ipaddr,addr->pubkey,json);
printf("SUPERSEND.(%s) -> (%s) delaymillis.%d\n",jsonstr,addr->ipaddr,delaymillis);
qlen = iguana_queue_send(coin,addr,delaymillis,serialized,"SuperNET",datalen,0,1);
free(serialized);
}
return(qlen);
}
char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexmsg,int32_t maxdelay)
{
static int lastpurge; static uint64_t Packetcache[1024];
bits256 packethash; char retbuf[512]; int32_t i,j,datalen,firstz,iter,n = 0; char *jsonstr=0;
struct iguana_peer *addr; cJSON *json;
if ( myinfo == 0 )
return(clonestr("{\"error\":\"no supernet_info\"}"));
datalen = (int32_t)strlen(hexmsg) + 1;
json = cJSON_CreateObject();
jaddstr(json,"message",hexmsg);
jsonstr = jprint(json,1);
vcalc_sha256(0,packethash.bytes,(void *)hexmsg,datalen);
firstz = -1;
for (i=0; i<sizeof(Packetcache)/sizeof(*Packetcache); i++)
{
if ( Packetcache[i] == 0 )
{
Packetcache[i] = packethash.txid;
printf("add.%llx packetcache(%s)\n",(long long)packethash.txid,hexmsg);
break;
}
else if ( Packetcache[i] == packethash.txid )
{
printf("SuperNET_DHTsend reject repeated packet.%llx (%s)\n",(long long)packethash.txid,hexmsg);
return(clonestr("{\"error\":\"duplicate packet rejected\"}"));
}
}
if ( i == sizeof(Packetcache)/sizeof(*Packetcache) )
{
printf("purge slot[%d]\n",lastpurge);
Packetcache[lastpurge++] = packethash.txid;
if ( lastpurge >= sizeof(Packetcache)/sizeof(*Packetcache) )
lastpurge = 0;
}
for (iter=0; iter<2; iter++)
{
for (i=0; i<IGUANA_MAXCOINS; i++)
{
if ( Coins[i] != 0 )
{
for (j=0; j<IGUANA_MAXPEERS; j++)
{
addr = &Coins[i]->peers.active[j];
if ( addr->usock >= 0 )
{
if ( iter == 0 && memcmp(addr->iphash.bytes,routehash.bytes,sizeof(addr->iphash)) == 0 )
{
iguana_send_supernet(Coins[i],addr,jsonstr,maxdelay==0?0:rand()%maxdelay);
return(clonestr("{\"result\":\"packet sent directly to destip\"}"));
}
else if ( iter == 1 )
{
char str[65],str2[65]; printf("%s vs %s -> %d\n",bits256_str(str,packethash),bits256_str(str2,addr->iphash),bits256_cmp(addr->iphash,packethash));
if ( bits256_cmp(addr->iphash,packethash) < 0 )
{
iguana_send_supernet(Coins[i],addr,jsonstr,maxdelay==0?0:rand()%maxdelay);
n++;
}
}
}
}
}
}
}
if ( jsonstr != 0 )
free(jsonstr);
if ( n > 0 )
sprintf(retbuf,"{\"result\":\"packet forwarded to superDHT\",\"branches\":%d}",n);
else sprintf(retbuf,"{\"error\":\"no nodes to forward packet to\"}");
return(clonestr(retbuf));
}
char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 destpub,char *hexmsg,int32_t maxdelay)
{
uint32_t destipbits; bits256 routehash; char *retstr; cJSON *msgjson = cJSON_CreateObject();
if ( destip == 0 || destip[0] == 0 || strncmp(destip,"127.0.0.1",strlen("127.0.0.1")) == 0 )
{
routehash = destpub;
jaddbits256(msgjson,"destpub",destpub);
}
else
{
destipbits = (uint32_t)calc_ipbits(destip);
vcalc_sha256(0,routehash.bytes,(uint8_t *)&destipbits,sizeof(destipbits));
jaddstr(msgjson,"destip",destip);
}
retstr = SuperNET_DHTsend(myinfo,routehash,hexmsg,maxdelay);
return(retstr);
}
char *SuperNET_forward(struct supernet_info *myinfo,char *hexmsg,uint32_t destipbits,bits256 destpub,int32_t maxdelay)
{
bits256 routehash;
if ( destipbits != 0 )
vcalc_sha256(0,routehash.bytes,(uint8_t *)&destipbits,sizeof(destipbits));
else routehash = destpub;
return(SuperNET_DHTsend(myinfo,routehash,hexmsg,maxdelay));
}
int32_t SuperNET_destination(struct supernet_info *myinfo,uint32_t *destipbitsp,bits256 *destpubp,int32_t *maxdelayp,cJSON *json)
{
char *destip; int32_t destflag = SUPERNET_FORWARD;
if ( (destip= jstr(json,"destip")) != 0 )
*destipbitsp = (uint32_t)calc_ipbits(destip);
*maxdelayp = juint(json,"delay");
*destpubp = jbits256(json,"destpub");
if ( *destipbitsp == myinfo->myaddr.selfipbits )
destflag = SUPERNET_ISMINE;
else if ( memcmp(destpubp,myinfo->myaddr.pubkey.bytes,sizeof(*destpubp)) == 0 )
destflag = SUPERNET_ISMINE;
// check for encrypted packets
return(destflag);
}
char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
{
int32_t destflag,maxdelay; bits256 destpub; uint32_t destipbits; cJSON *retjson;
char *forwardstr=0,*retstr=0,*agent,*method,*message,*jsonstr=0;
if ( remoteaddr != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 )
remoteaddr = 0;
destflag = SuperNET_destination(myinfo,&destipbits,&destpub,&maxdelay,json);
if ( (destflag & SUPERNET_FORWARD) != 0 )
{
if ( (message= jstr(json,"message")) == 0 )
{
jsonstr = jprint(json,0);
message = jsonstr;
}
forwardstr = SuperNET_forward(myinfo,message,destipbits,destpub,maxdelay);
}
if ( (destflag & SUPERNET_ISMINE) && (agent= jstr(json,"agent")) != 0 && (method= jstr(json,"method")) != 0 )
{
if ( (retstr= SuperNET_processJSON(myinfo,json,remoteaddr)) != 0 )
{
//printf("retstr.(%s)\n",retstr);
if ( remoteaddr != 0 && (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( jobj(retjson,"result") != 0 || jobj(retjson,"error") != 0 || jobj(retjson,"method") == 0 )
{
//printf("it is a result, dont return\n");
free(retstr);
retstr = 0;
}
free_json(retjson);
}
} else printf("null retstr from SuperNET_JSON\n");
}
if ( retstr == 0 )
retstr = forwardstr, forwardstr = 0;
if ( forwardstr != 0 )
free(forwardstr);
if ( jsonstr != 0 )
free(jsonstr);
return(retstr);
}
char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen)
{
cJSON *json; bits256 senderpub; char *myipaddr,*method,*retstr = 0; int32_t maxdelay; struct supernet_info *myinfo;
myinfo = SuperNET_MYINFO(0);
*delaymillisp = 0;
if ( (json= SuperNET_bits2json(myinfo,addr->pubkey,data,datalen)) != 0 )
{
maxdelay = juint(json,"maxdelay");
printf("GOT >>>>>>>> SUPERNET P2P.(%s) from.%s\n",(char *)data,coin->symbol);
if ( (myipaddr= jstr(json,"yourip")) != 0 )
SuperNET_myipaddr(SuperNET_MYINFO(0),addr,myipaddr,ipaddr);
senderpub = jbits256(json,"mypub");
if ( bits256_nonz(senderpub) > 0 )
addr->pubkey = senderpub;
jaddstr(json,"fromp2p",coin->symbol);
method = jstr(json,"method");
if ( method != 0 && strcmp(method,"stop") == 0 )
{
addr->dead = (uint32_t)time(NULL);
free_json(json);
return(clonestr("{\"result\":\"peer marked as dead\"}"));
}
retstr = SuperNET_JSON(myinfo,json,ipaddr);
*delaymillisp = SuperNET_delaymillis(myinfo,maxdelay);
free_json(json);
}
return(retstr);
}

18
iguana/SuperNET.h

@ -32,6 +32,10 @@
#define MAX_SERVERNAME 128
#define SUPERNET_MAXRECVBUF (1024 * 1024 * 16)
#define SUPERNET_FORWARD 2
#define SUPERNET_ISMINE 1
#define SUPERNET_MAXDELAY (1000 * 3600)
/*#define LB_OFFSET 1
#define PUBGLOBALS_OFFSET 2
#define PUBRELAYS_OFFSET 3
@ -81,7 +85,7 @@ struct supernet_info
bits256 privkey;
uint8_t *recvbuf[6];
struct supernet_address myaddr;
int32_t LBsock,PUBsock,reqsock,subsock,networktimeout;
int32_t LBsock,PUBsock,reqsock,subsock,networktimeout,maxdelay;
uint16_t LBport,PUBport,reqport,subport;
struct nn_pollfd pfd[SUPERNET_MAXAGENTS]; //struct relay_info active;
struct supernet_agent agents[SUPERNET_MAXAGENTS]; queue_t acceptQ; int32_t numagents;
@ -98,14 +102,16 @@ struct supernet_endpoint
void expand_epbits(char *endpoint,struct endpoint epbits);
struct endpoint calc_epbits(char *transport,uint32_t ipbits,uint16_t port,int32_t type);
struct supernet_info *SuperNET_MYINFO(char *passphrase);
void SuperNET_init(void *args);
char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr);
char *pangea_parser(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr);
char *ramchain_parser(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr);
char *iguana_parser(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr);
char *InstantDEX_parser(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr);
char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,void *data,int32_t datalen,int32_t maxdelay);
char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remoteaddr);
char *SuperNET_DHTencode(struct supernet_info *myinfo,char *destip,bits256 destpub,char *hexmsg,int32_t maxdelay);
char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSON *json,char *remoteaddr);
char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr);
char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,char *hexmessage,int32_t maxdelay);
#endif

9
iguana/iguana777.h

@ -353,7 +353,7 @@ struct iguana_peer
{
struct queueitem DL;
queue_t sendQ;
bits256 iphash;
bits256 iphash,pubkey;
struct iguana_msgaddress A;
char ipaddr[64],lastcommand[16],coinstr[16],symbol[16];
uint64_t pingnonce,totalsent,totalrecv,ipbits; double pingtime,sendmillis,pingsum,getdatamillis;
@ -671,7 +671,7 @@ struct iguana_info *iguana_coinfind(const char *symbol);
struct iguana_info *iguana_coinadd(const char *symbol);
struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana_bundle *bp);
int32_t iguana_sendblockreq(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe);
int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,void *data,long datalen,int32_t delay);
int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,char *jsonstr,int32_t delay);
struct iguana_waccount *iguana_waccountfind(struct iguana_info *coin,char *account);
struct iguana_waccount *iguana_waccountadd(struct iguana_info *coin,char *walletaccount,struct iguana_waddress *waddr);
@ -684,16 +684,15 @@ int32_t btc_priv2wip(char *wipstr,uint8_t privkey[32],uint8_t addrtype);
int32_t btc_pub2rmd(uint8_t rmd160[20],uint8_t pubkey[33]);
int32_t iguana_launchcoin(char *symbol,cJSON *json);
int32_t iguana_jsonQ();
int32_t is_bitcoinrpc(char *method);
int32_t is_bitcoinrpc(char *method,char *remoteaddr);
char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr);
cJSON *iguana_pubkeyjson(struct iguana_info *coin,char *pubkeystr);
void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit);
int32_t iguana_bundleiters(struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit);
void ramcoder_test(void *data,int64_t len);
void SuperNET_init(void *args);
char *SuperNET_parser(struct supernet_info *myinfo,char *agent,char *method,cJSON *json,char *remoteaddr);
void iguana_exit();
int32_t iguana_pendingaccept(struct iguana_info *coin);
char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t tag,int32_t maxmillis,char *remoteaddr);
extern queue_t bundlesQ;

52
iguana/iguana_json.c

@ -385,55 +385,11 @@ void SuperNET_parsepeers(struct supernet_info *myinfo,cJSON *array,int32_t n,int
TWOSTRINGS_AND_HASH_AND_INT(SuperNET,DHT,message,destip,destpub,maxdelay)
{
bits256 routehash; uint32_t destipbits = 0; long datalen;
char *retstr,*data,*hexstr; cJSON *msgjson;
if ( is_hexstr(message,(int32_t)strlen(message)) <= 0 )
if ( remoteaddr != 0 )
return(clonestr("{\"error\":\"cant remote DHT\"}"));
else if ( is_hexstr(message,(int32_t)strlen(message)) <= 0 )
return(clonestr("{\"error\":\"message must be in hex\"}"));
else hexstr = message;
msgjson = cJSON_CreateObject();
jaddstr(msgjson,"agent","SuperNET");
jaddstr(msgjson,"method","DHT");
if ( destip == 0 || destip[0] == 0 || strncmp(destip,"127.0.0.1",strlen("127.0.0.1")) == 0 )
{
routehash = destpub;
jaddbits256(msgjson,"destpub",destpub);
}
else
{
destipbits = (uint32_t)calc_ipbits(destip);
vcalc_sha256(0,routehash.bytes,(uint8_t *)&destipbits,sizeof(destipbits));
jaddstr(msgjson,"destip",destip);
}
jaddstr(msgjson,"message",message);
data = jprint(msgjson,1);
datalen = strlen(data)+1;
retstr = SuperNET_DHTsend(myinfo,routehash,data,(int32_t)datalen,maxdelay);
free(data);
return(retstr);
/*if ( (msgjson= cJSON_Parse(message)) != 0 )
{
if ( (agent= jstr(msgjson,"agent")) != 0 && strcmp(agent,"SuperNET")) != 0 )
{
safecopy(agentstr,agent,sizeof(agentstr)-1);
jdelete(msgjson,"agent");
jaddstr(msgjson,"agent","SuperNET");
jaddstr(msgjson,"destagent",agentstr);
}
if ( (method= jstr(msgjson,"method")) != 0 && strcmp(agent,"SuperNET")) != 0 )
{
safecopy(methodstr,method,sizeof(methodstr)-1);
jdelete(msgjson,"method");
jaddstr(msgjson,"method","DHTsend");
jaddstr(msgjson,"destmethod",methodstr);
}
msgstr = jprint(msgjson,1);
msglen = (int32_t)strlen(msgstr);
hexstr = calloc(1,msglen*2+1);
flag = 1;
init_hexbytes_noT(hexstr,msgstr,msglen);
}
if ( flag != 0 )
free(hexstr);*/
return(SuperNET_DHTencode(myinfo,destip,destpub,message,maxdelay));
}
ZERO_ARGS(SuperNET,stop)

15
iguana/iguana_msg.c

@ -163,7 +163,7 @@ int32_t iguana_send_version(struct iguana_info *coin,struct iguana_peer *addr,ui
void iguana_gotverack(struct iguana_info *coin,struct iguana_peer *addr)
{
uint8_t serialized[sizeof(struct iguana_msghdr)]; char *msg = "{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}";
uint8_t serialized[sizeof(struct iguana_msghdr)];
if ( addr != 0 )
{
printf("gotverack from %s\n",addr->ipaddr);
@ -172,7 +172,7 @@ void iguana_gotverack(struct iguana_info *coin,struct iguana_peer *addr)
if ( addr->supernet != 0 )
{
printf("send getpeers to %s\n",addr->ipaddr);
iguana_send_supernet(coin,addr,msg,strlen(msg)+1,0);
iguana_send_supernet(coin,addr,"{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}",0);
}
}
}
@ -192,7 +192,6 @@ void iguana_gotaddr(struct iguana_info *coin,struct iguana_peer *addr,struct igu
void iguana_gotping(struct iguana_info *coin,struct iguana_peer *addr,uint64_t nonce,uint8_t *data)
{
int32_t len; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(nonce)];
char *msg = "{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}";
len = iguana_rwnum(1,&serialized[sizeof(struct iguana_msghdr)],sizeof(uint64_t),&nonce);
if ( memcmp(data,&serialized[sizeof(struct iguana_msghdr)],sizeof(nonce)) != 0 )
printf("ping ser error %llx != %llx\n",(long long)nonce,*(long long *)data);
@ -200,14 +199,13 @@ void iguana_gotping(struct iguana_info *coin,struct iguana_peer *addr,uint64_t n
if ( addr->supernet != 0 )
{
printf("send getpeers to %s\n",addr->ipaddr);
iguana_send_supernet(coin,addr,msg,strlen(msg)+1,0);
iguana_send_supernet(coin,addr,"{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}",0);
}
}
int32_t iguana_send_ping(struct iguana_info *coin,struct iguana_peer *addr)
{
int32_t len; uint64_t nonce; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(nonce)];
char *msg = "{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}";
if ( (nonce= addr->pingnonce) == 0 )
{
OS_randombytes((uint8_t *)&nonce,sizeof(nonce));
@ -217,7 +215,7 @@ int32_t iguana_send_ping(struct iguana_info *coin,struct iguana_peer *addr)
printf("pingnonce.%llx\n",(long long)nonce);
len = iguana_rwnum(1,&serialized[sizeof(struct iguana_msghdr)],sizeof(uint64_t),&nonce);
if ( addr->supernet != 0 )
iguana_send_supernet(coin,addr,msg,strlen(msg)+1,(rand() % 10000));
iguana_send_supernet(coin,addr,"{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}",0);
return(iguana_queue_send(coin,addr,0,serialized,"ping",len,0,0));
}
@ -431,8 +429,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
strcpy(addr->lastcommand,H->command);
}
retval = 0;
//usleep(1000);
printf("iguana_msgparser %s parse.(%s)\n",addr->ipaddr,H->command);
//printf("iguana_msgparser %s parse.(%s)\n",addr->ipaddr,H->command);
if ( strcmp(H->command,"SuperNET") == 0 )
{
addr->supernet = 1;
@ -440,7 +437,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
len = recvlen;
if ( (retstr= SuperNET_p2p(coin,addr,&delay,addr->ipaddr,data,recvlen)) != 0 )
{
iguana_send_supernet(coin,addr,retstr,strlen(retstr)+1,delay);
iguana_send_supernet(coin,addr,retstr,delay);
free(retstr);
}
printf("GOT.(%s) [%s] len.%d from %s -> (%s)\n",H->command,data,recvlen,addr->ipaddr,retstr==0?"null":retstr);

13
iguana/iguana_peers.c

@ -888,7 +888,7 @@ int64_t iguana_peerallocated(struct iguana_info *coin,struct iguana_peer *addr)
void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr)
{
static uint32_t lastping;
char *msg; struct pollfd fds; uint8_t *buf,serialized[64]; struct iguana_bundlereq *req;
struct pollfd fds; uint8_t *buf,serialized[64]; struct iguana_bundlereq *req;
uint32_t ipbits; int32_t bufsize,flag,run,timeout = coin->polltimeout == 0 ? 10 : coin->polltimeout;
#ifdef IGUANA_PEERALLOC
int32_t i; int64_t remaining; struct OS_memspace *mem[sizeof(addr->SEROUT)/sizeof(*addr->SEROUT)];
@ -912,8 +912,6 @@ void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr)
bufsize = IGUANA_MAXPACKETSIZE;
buf = mycalloc('r',1,bufsize);
printf("send version myservices.%llu to (%s)\n",(long long)coin->myservices,addr->ipaddr);
//if ( addr->supernet != 0 )
// iguana_send_supernet(coin,addr,"{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}",0);
iguana_send_version(coin,addr,coin->myservices);
sleep(1+(rand()%5));
iguana_queue_send(coin,addr,0,serialized,"getaddr",0,0,0);
@ -985,11 +983,9 @@ void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr)
}
if ( flag != 0 )
run = 0;
else if ( addr->supernet != 0 && time(NULL) > lastping+60 )
else if ( addr->supernet != 0 && time(NULL) > lastping+600 )
{
printf("send getpeers\n");
msg = "{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}";
iguana_send_supernet(coin,addr,msg,strlen(msg)+1,0);
iguana_send_supernet(coin,addr,"{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}",0);
lastping = (uint32_t)time(NULL);
}
if ( coin->isRT != 0 && addr->rank > coin->MAXPEERS && (rand() % 100) == 0 )
@ -1093,9 +1089,8 @@ void iguana_peersloop(void *ptr)
}
if ( flag == 0 )
{
char *msg = "{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}";
if ( time(NULL) > lastping+1 )
iguana_send_supernet(coin,addr,msg,strlen(msg)+1,0);
iguana_send_supernet(coin,addr,"{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}",0);
usleep(1000);
}
}

49
iguana/iguana_rpc.c

@ -469,15 +469,15 @@ static char *getrawchangeaddress(RPCARGS)
#define true 1
#define false 0
struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,flag1; } RPCcalls[] =
struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,remoteflag; } RPCcalls[] =
{
{ "help", &help, true, true },
{ "help", &help, true, false },
{ "stop", &stop, true, true },
{ "getbestblockhash", &getbestblockhash, true, false },
{ "getblockcount", &getblockcount, true, false },
{ "getconnectioncount", &getconnectioncount, true, false },
{ "getpeerinfo", &getpeerinfo, true, false },
{ "getinfo", &getinfo, true, false },
{ "getbestblockhash", &getbestblockhash, true, true },
{ "getblockcount", &getblockcount, true, true },
{ "getconnectioncount", &getconnectioncount, true, true },
{ "getpeerinfo", &getpeerinfo, true, true },
{ "getinfo", &getinfo, true, true },
{ "getnewaddress", &getnewaddress, true, false },
{ "getnewpubkey", &makekeypair, true, false },
{ "getaccountaddress", &getaccountaddress, true, false },
@ -494,16 +494,16 @@ struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,flag1; }
{ "walletpassphrasechange", &walletpassphrasechange, false, false },
{ "walletlock", &walletlock, true, false },
{ "encryptwallet", &encryptwallet, false, false },
{ "validateaddress", &validateaddress, true, false },
{ "validatepubkey", &validatepubkey, true, false },
{ "validateaddress", &validateaddress, true, true },
{ "validatepubkey", &validatepubkey, true, true },
{ "getbalance", &getbalance, false, false },
{ "move", &movecmd, false, false },
{ "sendfrom", &sendfrom, false, false },
{ "sendmany", &sendmany, false, false },
{ "addmultisigaddress", &addmultisigaddress, false, false },
{ "getblock", &getblock, false, false },
{ "getblockhash", &getblockhash, false, false },
{ "gettransaction", &gettransaction, false, false },
{ "getblock", &getblock, false, true },
{ "getblockhash", &getblockhash, false, true },
{ "gettransaction", &gettransaction, false, true },
{ "listtransactions", &listtransactions, false, false },
{ "listaddressgroupings", &listaddressgroupings, false, false },
{ "signmessage", &signmessage, false, false },
@ -512,30 +512,30 @@ struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,flag1; }
{ "settxfee", &settxfee, false, false },
{ "listsinceblock", &listsinceblock, false, false },
{ "dumpprivkey", &dumpprivkey, false, false },
{ "SuperNET", &SuperNET, false, false },
{ "SuperNET", &SuperNET, false, true },
{ "dumpwallet", &dumpwallet, true, false },
{ "importwallet", &importwallet, false, false },
{ "importprivkey", &importprivkey, false, false },
{ "listunspent", &listunspent, false, false },
{ "getrawtransaction", &getrawtransaction, false, false },
{ "createrawtransaction", &createrawtransaction, false, false },
{ "decoderawtransaction", &decoderawtransaction, false, false },
{ "decodescript", &decodescript, false, false },
{ "decoderawtransaction", &decoderawtransaction, false, true },
{ "decodescript", &decodescript, false, true },
{ "signrawtransaction", &signrawtransaction, false, false },
{ "sendrawtransaction", &sendrawtransaction, false, false },
{ "checkwallet", &checkwallet, false, true},
{ "repairwallet", &repairwallet, false, true},
{ "makekeypair", &makekeypair, false, true},
{ "sendrawtransaction", &sendrawtransaction, false, true },
{ "checkwallet", &checkwallet, false, false },
{ "repairwallet", &repairwallet, false, false },
{ "makekeypair", &makekeypair, false, false },
{ "sendalert", &sendalert, false, false },
//
{ "createmultisig", &createmultisig, false, false },
{ "addnode", &addnode, false, false },
{ "getrawmempool", &getrawmempool, false, false},
{ "getrawmempool", &getrawmempool, false, true },
{ "getrawchangeaddress", &getrawchangeaddress, false, false },
{ "listlockunspent", &listlockunspent, false, false },
{ "lockunspent", &lockunspent, false, false },
{ "gettxout", &gettxout, false, false},
{ "gettxoutsetinfo", &gettxoutsetinfo, false, false},
{ "gettxout", &gettxout, false, true },
{ "gettxoutsetinfo", &gettxoutsetinfo, false, true },
{ "vanitygen", &vanitygen, false, false }
#ifdef PEGGY
//{ "peggytx", &peggytx, true, false },
@ -559,14 +559,17 @@ struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,flag1; }
// { "reservebalance", &reservebalance, false, true},
};
int32_t is_bitcoinrpc(char *method)
int32_t is_bitcoinrpc(char *method,char *remoteaddr)
{
int32_t i;
for (i=0; i<sizeof(RPCcalls)/sizeof(*RPCcalls); i++)
{
if ( strcmp(RPCcalls[i].name,method) == 0 )
{
if ( RPCcalls[i].remoteflag != 0 || (RPCcalls[i].remoteflag == 0 && (remoteaddr == 0 || remoteaddr[0] == 0 || strcmp(remoteaddr,"127.0.0.1") == 0)) )
return(i);
}
}
return(-1);
}

274
iguana/main.c

@ -24,8 +24,6 @@
#include "iguana777.h"
#include "SuperNET.h"
#define SUPERNET_HELPSTR "SuperNET help text here"
// ALL globals must be here!
struct iguana_info *Coins[IGUANA_MAXCOINS];
int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel;
@ -40,6 +38,32 @@ int32_t IGUANA_NUMHELPERS = 8;
#else
int32_t IGUANA_NUMHELPERS = 1;
#endif
struct iguana_jsonitem { struct queueitem DL; struct supernet_info *myinfo; uint32_t fallback,expired,allocsize; char **retjsonstrp; char remoteaddr[64]; char jsonstr[]; };
struct supernet_info *SuperNET_MYINFO(char *passphrase)
{
if ( passphrase == 0 || passphrase[0] == 0 )
return(&MYINFO);
else
{
// search saved accounts
}
return(0);
}
char *iguana_JSON(char *jsonstr)
{
char *retstr=0; cJSON *json;
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
retstr = SuperNET_JSON(0,json,"127.0.0.1");
free_json(json);
}
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"cant parse jsonstr from pnacl\"}");
return(retstr);
}
char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remoteaddr)
{
@ -49,15 +73,13 @@ char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remotead
method = jstr(json,"method");
if ( (agent= jstr(json,"agent")) != 0 && method != 0 )
return(SuperNET_parser(myinfo,agent,method,json,remoteaddr));
else if ( method != 0 && is_bitcoinrpc(method) )
else if ( method != 0 && is_bitcoinrpc(method,remoteaddr) )
return(iguana_bitcoinRPC(myinfo,method,json,remoteaddr));
return(clonestr("{\"error\":\"need both agent and method\"}"));
}
return(clonestr("{\"error\":\"couldnt parse SuperNET_JSON\"}"));
}
struct iguana_jsonitem { struct queueitem DL; struct supernet_info *myinfo; uint32_t fallback,expired,allocsize; char **retjsonstrp; char remoteaddr[64]; char jsonstr[]; };
int32_t iguana_jsonQ()
{
struct iguana_jsonitem *ptr;
@ -112,10 +134,10 @@ char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t
return(clonestr("{\"error\":\"iguana jsonstr expired\"}"));
}
char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
char *SuperNET_processJSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
{
cJSON *retjson; uint64_t tag; uint32_t timeout; char *jsonstr; char *retjsonstr,*retstr = 0;
printf("SuperNET_JSON.(%s) remoteaddr.(%s)\n",jprint(json,0),remoteaddr!=0?remoteaddr:"");
//printf("SuperNET_JSON.(%s) remoteaddr.(%s)\n",jprint(json,0),remoteaddr!=0?remoteaddr:"");
if ( json != 0 )
{
if ( (tag= j64bits(json,"tag")) == 0 )
@ -147,242 +169,6 @@ char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
return(retstr);
}
char *iguana_JSON(char *jsonstr)
{
char *retstr=0; cJSON *json;
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
retstr = SuperNET_JSON(0,json,"127.0.0.1");
free_json(json);
}
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"cant parse jsonstr from pnacl\"}");
return(retstr);
}
int32_t SuperNET_confirmip(struct supernet_info *myinfo,uint32_t ipbits)
{
int32_t i,j,total = 0; uint32_t x;
for (i=0; i<IGUANA_MAXCOINS; i++)
{
if ( Coins[i] != 0 )
{
for (j=0; j<IGUANA_MAXPEERS; j++)
{
if ( (x= Coins[i]->peers.active[j].myipbits) != 0 )
{
if ( x == ipbits )
total++;
else total--;
}
}
}
}
return(total);
}
void SuperNET_myipaddr(struct supernet_info *myinfo,struct iguana_peer *addr,char *myipaddr,char *remoteaddr)
{
uint32_t myipbits = (uint32_t)calc_ipbits(myipaddr);
if ( addr->myipbits == 0 )
addr->myipbits = myipbits;
else if ( addr->myipbits != myipbits )
{
printf("%s: myipaddr conflict %x != %x?\n",addr->ipaddr,addr->myipbits,myipbits);
addr->myipbits = 0;
}
if ( addr->myipbits != 0 && myinfo->myaddr.myipbits == 0 )
myinfo->myaddr.myipbits = addr->myipbits;
if ( addr->myipbits == myinfo->myaddr.myipbits )
{
myinfo->myaddr.confirmed++;
if ( myinfo->myaddr.selfipbits == 0 || myinfo->ipaddr[0] == 0 )
{
if ( (myinfo->myaddr.totalconfirmed= SuperNET_confirmip(myinfo,addr->myipbits)) > 3 )
myinfo->myaddr.selfipbits = addr->myipbits;
}
}
else myinfo->myaddr.confirmed--;
if ( myinfo->myaddr.selfipbits == myinfo->myaddr.myipbits )
{
expand_ipbits(myinfo->ipaddr,myinfo->myaddr.selfipbits);
vcalc_sha256(0,myinfo->myaddr.iphash.bytes,(uint8_t *)&myinfo->myaddr.selfipbits,sizeof(myinfo->myaddr.selfipbits));
}
}
void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag)
{
uint64_t ipbits; struct iguana_peer *addr;
printf("got %s remotepeer.(%s) supernet.%d\n",symbol,ipaddr,supernetflag);
if ( supernetflag != 0 )
{
ipbits = calc_ipbits(ipaddr);
if ( (addr= iguana_peerslot(coin,ipbits)) != 0 )
{
printf("launch startconnection to supernet peer.(%s)\n",ipaddr);
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
return;
}
}
iguana_possible_peer(coin,ipaddr);
}
int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,void *data,long datalen,int32_t delaymillis)
{
uint64_t r; char *jsonstr = data; int32_t flag=0,qlen = -1; uint8_t serialized[8192],*buf; cJSON *json;
if ( (json= cJSON_Parse((char *)data)) != 0 )
{
if ( j64bits(json,"tag") == 0 )
{
OS_randombytes((uint8_t *)&r,sizeof(r));
jadd64bits(json,"tag",r);
}
jdelete(json,"yourip");
jaddstr(json,"yourip",addr->ipaddr);
jsonstr = jprint(json,1);
datalen = strlen(jsonstr)+1;
flag = 1;
}
buf = serialized;
if ( datalen > sizeof(serialized)-sizeof(struct iguana_msghdr) )
buf = calloc(1,datalen+sizeof(struct iguana_msghdr));
memcpy(&buf[sizeof(struct iguana_msghdr)],jsonstr,datalen);
printf("SUPERSEND.(%s) -> (%s) delaymillis.%d\n",jsonstr,addr->ipaddr,delaymillis);
qlen = iguana_queue_send(coin,addr,delaymillis,serialized,"SuperNET",(int32_t)datalen,0,1);
if ( buf != serialized )
free(buf);
if ( flag != 0 )
free(jsonstr);
return(qlen);
}
uint64_t Packetcache[1024];
char *SuperNET_DHTsend(struct supernet_info *myinfo,bits256 routehash,void *data,int32_t datalen,int32_t maxdelay)
{
static int lastpurge;
bits256 packethash; char retbuf[512]; int32_t i,j,firstz,iter,n = 0; struct iguana_peer *addr;
if ( myinfo == 0 )
myinfo = &MYINFO;
vcalc_sha256(0,packethash.bytes,data,datalen);
firstz = -1;
for (i=0; i<sizeof(Packetcache)/sizeof(*Packetcache); i++)
{
if ( Packetcache[i] == 0 )
{
Packetcache[i] = packethash.txid;
printf("add.%llx packetcache(%s)\n",(long long)packethash.txid,(char *)data);
break;
}
else if ( Packetcache[i] == packethash.txid )
{
printf("SuperNET_DHTsend reject repeated packet.%llx (%s)\n",(long long)packethash.txid,(char *)data);
return(clonestr("{\"error\":\"duplicate packet rejected\"}"));
}
}
if ( i == sizeof(Packetcache)/sizeof(*Packetcache) )
{
printf("purge slot[%d]\n",lastpurge);
Packetcache[lastpurge++] = packethash.txid;
if ( lastpurge >= sizeof(Packetcache)/sizeof(*Packetcache) )
lastpurge = 0;
}
for (iter=0; iter<2; iter++)
{
for (i=0; i<IGUANA_MAXCOINS; i++)
{
if ( Coins[i] != 0 )
{
for (j=0; j<IGUANA_MAXPEERS; j++)
{
addr = &Coins[i]->peers.active[j];
if ( addr->usock >= 0 )
{
if ( iter == 0 && memcmp(addr->iphash.bytes,routehash.bytes,sizeof(addr->iphash)) == 0 )
{
iguana_send_supernet(Coins[i],addr,data,datalen,maxdelay==0?0:rand()%maxdelay);
return(clonestr("{\"result\":\"packet sent directly to destip\"}"));
}
else if ( iter == 1 )
{
if ( bits256_cmp(addr->iphash,myinfo->myaddr.iphash) < 0 )
{
iguana_send_supernet(Coins[i],addr,data,datalen,maxdelay==0?0:rand()%maxdelay);
n++;
}
}
}
}
}
}
}
if ( n > 0 )
sprintf(retbuf,"{\"result\":\"packet forwarded to superDHT\",\"branches\":%d}",n);
else sprintf(retbuf,"{\"error\":\"no nodes to forward packet to\"}");
return(clonestr(retbuf));
}
int32_t SuperNET_mypacket(struct supernet_info *myinfo,uint32_t destipbits,bits256 destpub)
{
if ( destipbits == myinfo->myaddr.selfipbits )
return(0);
if ( memcmp(destpub.bytes,myinfo->myaddr.pubkey.bytes,sizeof(destpub)) == 0 )
return(0);
// check for encrypted packets
return(-1);
}
char *SuperNET_p2p(struct iguana_info *coin,struct iguana_peer *addr,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen)
{
cJSON *json,*retjson; bits256 destpub,routehash; uint32_t destipbits = 0;
char *destip,*agent,*myipaddr,*method,*retstr = 0;
*delaymillisp = 0;
if ( (json= cJSON_Parse((char *)data)) != 0 )
{
printf("GOT >>>>>>>> SUPERNET P2P.(%s) from.%s\n",(char *)data,coin->symbol);
if ( (myipaddr= jstr(json,"yourip")) != 0 )
SuperNET_myipaddr(&MYINFO,addr,myipaddr,ipaddr);
if ( (destip= jstr(json,"destip")) != 0 )
destipbits = (uint32_t)calc_ipbits(destip);
destpub = jbits256(json,"destpub");
if ( SuperNET_mypacket(&MYINFO,destipbits,destpub) < 0 )
{
if ( destipbits != 0 )
vcalc_sha256(0,routehash.bytes,(uint8_t *)&destipbits,sizeof(destipbits));
else routehash = destpub;
retstr = SuperNET_DHTsend(&MYINFO,routehash,data,datalen,juint(json,"delay"));
free_json(json);
return(retstr);
}
if ( (agent= jstr(json,"agent")) != 0 && (method= jstr(json,"method")) != 0 )
{
if ( strcmp(agent,"SuperNET") == 0 && strcmp(method,"stop") == 0 )
{
addr->dead = (uint32_t)time(NULL);
free_json(json);
return(clonestr("{\"result\":\"peer marked as dead\"}"));
}
jaddstr(json,"fromp2p",coin->symbol);
if ( (retstr= SuperNET_JSON(0,json,ipaddr)) != 0 )
{
//printf("retstr.(%s)\n",retstr);
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( jobj(retjson,"result") != 0 || jobj(retjson,"error") != 0 || jobj(retjson,"method") == 0 )
{
//printf("it is a result, dont return\n");
free(retstr);
retstr = 0;
}
else *delaymillisp = (rand() % 1000);
free_json(retjson);
}
} else printf("null retstr from SuperNET_JSON\n");
}
free_json(json);
}
return(retstr);
}
void iguana_exit()
{
int32_t i,j,iter; char *stopstr = "{\"agent\":\"SuperNET\",\"method\":\"stop\"}";
@ -399,7 +185,7 @@ void iguana_exit()
{
case 0:
if ( Coins[i]->peers.active[j].usock >= 0 && Coins[i]->peers.active[j].supernet != 0 )
iguana_send_supernet(Coins[i],&Coins[i]->peers.active[j],stopstr,strlen(stopstr)+1,0);
iguana_send_supernet(Coins[i],&Coins[i]->peers.active[j],stopstr,0);
break;
case 1: Coins[i]->peers.active[j].dead = (uint32_t)time(NULL); break;
case 2:

Loading…
Cancel
Save