Browse Source

transition

release/v0.1
jl777 9 years ago
parent
commit
8728780565
  1. 4
      SuperNET/Makefile
  2. 469
      SuperNET/SuperNET.c
  3. 4
      SuperNET/SuperNET.h
  4. 2
      SuperNET/m_osx
  5. 2
      SuperNET/m_unix
  6. 127
      SuperNET/main.c
  7. 18
      crypto777/Makefile
  8. 14
      crypto777/OS_time.c
  9. 1328
      crypto777/ccgi.c
  10. 11
      crypto777/crypto777.sources
  11. 1
      crypto777/inet.c
  12. 3
      crypto777/m_win32
  13. 6
      crypto777/mingw
  14. 2
      crypto777/mingw32
  15. 3
      crypto777/mingw64
  16. 837
      deprecated/obsolete.h
  17. 13
      iguana/Makefile
  18. 507
      iguana/SuperNET.c
  19. 91
      iguana/SuperNET.h
  20. 10
      iguana/iguana.sources
  21. 7
      iguana/iguana777.c
  22. 15
      iguana/iguana777.h
  23. 7
      iguana/iguana_bitmap.c
  24. 1
      iguana/iguana_chains.c
  25. 783
      iguana/iguana_html.c
  26. 2
      iguana/iguana_init.c
  27. 557
      iguana/iguana_json.c
  28. 2
      iguana/iguana_msg.c
  29. 4
      iguana/iguana_peers.c
  30. 179
      iguana/iguana_rpc.c
  31. 4
      iguana/iguana_wallet.c
  32. 789
      iguana/main.c
  33. 3
      iguana/mingw32
  34. 5
      iguana/mingw64
  35. 64
      includes/ccgi.h
  36. 2
      m_unix
  37. 2
      mingw.path
  38. 2
      mingw.path64
  39. 10
      pangea/main.c
  40. BIN
      win/libcurl.a
  41. BIN
      win/libcurldll.a

4
SuperNET/Makefile

@ -8,12 +8,12 @@
VALID_TOOLCHAINS := pnacl newlib glibc clang-newlib mac
NACL_SDK_ROOT ?= $(abspath $(CURDIR))
TARGET = SuperNET
EXTRA= -D__PNACL
include $(NACL_SDK_ROOT)/tools/common.mk
include SuperNET.sources
CHROME_ARGS += --allow-nacl-socket-api=127.0.0.1
@ -23,7 +23,7 @@ LIBS = crypto777 nanomsg curl ssl crypto z glibc-compat nacl_spawn ppapi nacl_i
CFLAGS = -Wall -D__PNACL -fno-strict-aliasing $(EXTRA)
LFLAGS = libs
SOURCES = main.c SuperNET.c
SOURCES = $(SOURCES)
# Build rules generated by macros from common.mk:

469
SuperNET/SuperNET.c

@ -14,6 +14,139 @@
******************************************************************************/
#include "SuperNET.h"
#define IGUANA_FORMS "[ \
\
{\"disp\":\"simple explorer\",\"agent\":\"ramchain\",\"method\":\"explore\",\"fields\":[{\"skip\":1,\"field\":\"search\",\"cols\":65,\"rows\":1}]}, \
{\"disp\":\"block height\",\"agent\":\"ramchain\",\"method\":\"block\",\"fields\":[{\"field\":\"height\",\"cols\":10,\"rows\":1}]}, \
{\"disp\":\"block hash\",\"agent\":\"ramchain\",\"method\":\"block\",\"fields\":[{\"field\":\"hash\",\"cols\":65,\"rows\":1}]}, \
{\"disp\":\"txid\",\"agent\":\"ramchain\",\"method\":\"txid\",\"fields\":[{\"skip\":1,\"field\":\"hash\",\"cols\":65,\"rows\":1}]}, \
{\"disp\":\"status\",\"agent\":\"ramchain\",\"method\":\"status\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":1,\"rows\":1}]}, \
{\"disp\":\"bundleinfo\",\"agent\":\"ramchain\",\"method\":\"bundleinfo\",\"fields\":[{\"skip\":1,\"field\":\"height\",\"cols\":12,\"rows\":1}]}, \
\
{\"disp\":\"addcoin\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":8,\"rows\":1}]}, \
{\"disp\":\"pausecoin\",\"agent\":\"iguana\",\"method\":\"pausecoin\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":1,\"rows\":1}]}, \
{\"disp\":\"startcoin\",\"agent\":\"iguana\",\"method\":\"startcoin\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":1,\"rows\":1}]}, \
{\"disp\":\"addnode\",\"agent\":\"iguana\",\"method\":\"addnode\",\"fields\":[{\"skip\":1,\"field\":\"ipaddr\",\"cols\":32,\"rows\":1}]}, \
{\"disp\":\"maxpeers\",\"agent\":\"iguana\",\"method\":\"maxpeers\",\"fields\":[{\"skip\":1,\"field\":\"max\",\"cols\":8,\"rows\":1}]}, \
{\"disp\":\"peers\",\"agent\":\"iguana\",\"method\":\"peers\",\"fields\":[{\"field\":\"coin\",\"cols\":16,\"rows\":1}]}, \
{\"disp\":\"nodestatus\",\"agent\":\"iguana\",\"method\":\"nodestatus\",\"fields\":[{\"skip\":1,\"field\":\"ipaddr\",\"cols\":32,\"rows\":1}]}, \
\
{\"disp\":\"rates\",\"agent\":\"PAX\",\"method\":\"rates\",\"fields\":[{\"skip\":1,\"field\":\"peg\",\"cols\":16,\"rows\":1}]},\
{\"disp\":\"prices\",\"agent\":\"PAX\",\"method\":\"prices\",\"fields\":[{\"skip\":1,\"field\":\"peg\",\"cols\":16,\"rows\":1}]},\
{\"agent\":\"PAX\",\"method\":\"lock\",\"fields\":[{\"skip\":1,\"field\":\"peg\",\"cols\":16,\"rows\":1},{\"skip\":1,\"field\":\"lockdays\",\"cols\":6,\"rows\":1},{\"skip\":1,\"field\":\"units\",\"cols\":12,\"rows\":1}]}, \
{\"agent\":\"PAX\",\"method\":\"redeem\",\"fields\":[{\"skip\":1,\"field\":\"txid\",\"cols\":65,\"rows\":1},{\"skip\":1,\"field\":\"dest\",\"cols\":65,\"rows\":1}]},\
{\"disp\":\"balance\",\"agent\":\"PAX\",\"method\":\"balance\",\"fields\":[{\"skip\":1,\"field\":\"address\",\"cols\":44,\"rows\":1}]},\
{\"agent\":\"PAX\",\"method\":\"rollover\",\"fields\":[{\"skip\":1,\"field\":\"txid\",\"cols\":16,\"rows\":1},{\"skip\":1,\"field\":\"newpeg\",\"cols\":16,\"rows\":1},{\"skip\":1,\"field\":\"newlockdays\",\"cols\":6,\"rows\":1}]},\
{\"agent\":\"PAX\",\"method\":\"swap\",\"fields\":[{\"skip\":1,\"field\":\"txid\",\"cols\":16,\"rows\":1},{\"skip\":1,\"field\":\"othertxid\",\"cols\":16,\"rows\":1}]},\
{\"agent\":\"PAX\",\"method\":\"bet\",\"fields\":[{\"skip\":1,\"field\":\"peg\",\"cols\":16,\"rows\":1},{\"skip\":1,\"field\":\"price\",\"cols\":16,\"rows\":1},{\"skip\":1,\"field\":\"amount\",\"cols\":16,\"rows\":1}]},\
\
{\"agent\":\"InstantDEX\",\"method\":\"placebid\",\"fields\":[{\"skip\":1,\"field\":\"base\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"rel\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"exchange\",\"cols\":16,\"rows\":1},{\"field\":\"price\",\"cols\":16,\"rows\":1},{\"field\":\"volume\",\"cols\":16,\"rows\":1}]}, \
{\"agent\":\"InstantDEX\",\"method\":\"placeask\",\"fields\":[{\"skip\":1,\"field\":\"base\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"rel\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"exchange\",\"cols\":16,\"rows\":1},{\"field\":\"price\",\"cols\":16,\"rows\":1},{\"field\":\"volume\",\"cols\":16,\"rows\":1}]}, \
{\"agent\":\"InstantDEX\",\"method\":\"orderbook\",\"fields\":[{\"skip\":1,\"field\":\"base\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"rel\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"exchange\",\"cols\":16,\"rows\":1}]}, \
{\"disp\":\"orderstatus\",\"agent\":\"InstantDEX\",\"method\":\"orderstatus\",\"fields\":[{\"skip\":1,\"field\":\"orderid\",\"cols\":32,\"rows\":1}]}, \
{\"disp\":\"cancelorder\",\"agent\":\"InstantDEX\",\"method\":\"cancelorder\",\"fields\":[{\"skip\":1,\"field\":\"orderid\",\"cols\":32,\"rows\":1}]}, \
{\"disp\":\"balance\",\"agent\":\"InstantDEX\",\"method\":\"balance\",\"fields\":[{\"skip\":1,\"field\":\"exchange\",\"cols\":16,\"rows\":1}]}, \
{\"newline\":0,\"disp\":\"allorderbooks\",\"agent\":\"InstantDEX\",\"method\":\"allorderbooks\",\"fields\":[{\"skip\":1,\"field\":\"allorderbooks\",\"cols\":1,\"rows\":1}]}, \
{\"newline\":0,\"disp\":\"openorders\",\"agent\":\"InstantDEX\",\"method\":\"openorders\",\"fields\":[{\"skip\":1,\"field\":\"openorders\",\"cols\":1,\"rows\":1}]}, \
{\"newline\":0,\"disp\":\"tradehistory\",\"agent\":\"InstantDEX\",\"method\":\"tradehistory\",\"fields\":[{\"skip\":1,\"field\":\"tradehistory\",\"cols\":1,\"rows\":1}]}, \
{\"disp\":\"allexchanges\",\"agent\":\"InstantDEX\",\"method\":\"allexchanges\",\"fields\":[{\"skip\":1,\"field\":\"allexchanges\",\"cols\":1,\"rows\":1}]}, \
\
{\"agent\":\"pangea\",\"method\":\"bet\",\"fields\":[{\"skip\":1,\"field\":\"tableid\",\"cols\":24,\"rows\":1},{\"skip\":1,\"field\":\"amount\",\"cols\":24,\"rows\":1}]}, \
{\"disp\":\"call\",\"agent\":\"pangea\",\"method\":\"call\",\"fields\":[{\"skip\":1,\"field\":\"tableid\",\"cols\":1,\"rows\":1}]}, \
{\"disp\":\"fold\",\"agent\":\"pangea\",\"method\":\"fold\",\"fields\":[{\"skip\":1,\"field\":\"tableid\",\"cols\":1,\"rows\":1}]}, \
{\"disp\":\"status\",\"agent\":\"pangea\",\"method\":\"status\",\"fields\":[{\"skip\":1,\"field\":\"tableid\",\"cols\":1,\"rows\":1}]}, \
{\"disp\":\"hand history\",\"agent\":\"pangea\",\"method\":\"handhistory\",\"fields\":[{\"skip\":1,\"field\":\"tableid\",\"cols\":1,\"rows\":1}]}, \
{\"disp\":\"history\",\"agent\":\"pangea\",\"method\":\"history\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":1,\"rows\":1}]}, \
{\"disp\":\"follow\",\"agent\":\"pangea\",\"method\":\"follow\",\"fields\":[{\"skip\":1,\"field\":\"tableid\",\"cols\":24,\"rows\":1}]}, \
{\"disp\":\"lobby\",\"agent\":\"pangea\",\"method\":\"lobby\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":8,\"rows\":1}]}, \
{\"disp\":\"join\",\"agent\":\"pangea\",\"method\":\"join\",\"fields\":[{\"skip\":1,\"field\":\"tableid\",\"cols\":24,\"rows\":1}]}, \
{\"agent\":\"pangea\",\"method\":\"buyin\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"tableid\",\"cols\":24,\"rows\":1},{\"skip\":1,\"field\":\"amount\",\"cols\":12,\"rows\":1}]}, \
{\"agent\":\"pangea\",\"method\":\"newtournament\",\"fields\":[{\"field\":\"mintables\",\"cols\":8,\"rows\":1},{\"field\":\"maxtables\",\"cols\":4,\"rows\":1},{\"field\":\"starttime\",\"cols\":16,\"rows\":1},{\"field\":\"prizefund\",\"cols\":12,\"rows\":1},{\"field\":\"coin\",\"cols\":12,\"rows\":1}]}, \
{\"agent\":\"pangea\",\"method\":\"newtable\",\"fields\":[{\"field\":\"minplayers\",\"cols\":4,\"rows\":1},{\"field\":\"maxplayers\",\"cols\":4,\"rows\":1},{\"field\":\"rake\",\"cols\":4,\"rows\":1},{\"field\":\"bigblind\",\"cols\":12,\"rows\":1},{\"field\":\"ante\",\"cols\":12,\"rows\":1},{\"field\":\"minbuyin\",\"cols\":12,\"rows\":1},{\"field\":\"maxbuyin\",\"cols\":12,\"rows\":1}]}, \
{\"disp\":\"leave\",\"agent\":\"pangea\",\"method\":\"leave\",\"fields\":[{\"skip\":1,\"field\":\"tableid\",\"cols\":8,\"rows\":1}]}, \
\
{\"agent\":\"jumblr\",\"method\":\"send\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"amount\",\"cols\":13,\"rows\":1},{\"skip\":1,\"field\":\"address\",\"cols\":8,\"rows\":1}]}, \
{\"agent\":\"jumblr\",\"method\":\"invoice\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"amount\",\"cols\":13,\"rows\":1},{\"skip\":1,\"field\":\"address\",\"cols\":8,\"rows\":1}]}, \
{\"agent\":\"jumblr\",\"method\":\"shuffle\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"amount\",\"cols\":13,\"rows\":1}]}, \
{\"agent\":\"jumblr\",\"method\":\"balance\",\"fields\":[{\"skip\":1,\"field\":\"coin\",\"cols\":8,\"rows\":1},{\"skip\":1,\"field\":\"address\",\"cols\":13,\"rows\":1}]}, \
\
{\"newline\":0,\"disp\":\"InstantDEX\",\"agent\":\"iguana\",\"method\":\"setagent\",\"fields\":[{\"field\":\"InstantDEX\",\"cols\":1,\"rows\":1}]}, \
{\"newline\":0,\"disp\":\"PAX\",\"agent\":\"iguana\",\"method\":\"setagent\",\"fields\":[{\"field\":\"PAX\",\"cols\":1,\"rows\":1}]}, \
{\"newline\":0,\"disp\":\"pangea\",\"agent\":\"iguana\",\"method\":\"setagent\",\"fields\":[{\"field\":\"pangea\",\"cols\":1,\"rows\":1}]}, \
{\"newline\":0,\"disp\":\"jumblr\",\"agent\":\"iguana\",\"method\":\"setagent\",\"fields\":[{\"field\":\"jumblr\",\"cols\":1,\"rows\":1}]}, \
{\"disp\":\"ramchain\",\"agent\":\"iguana\",\"method\":\"setagent\",\"fields\":[{\"field\":\"ramchain\",\"cols\":1,\"rows\":1}]}, \
{\"newline\":0,\"disp\":\"iguana\",\"agent\":\"iguana\",\"method\":\"setagent\",\"fields\":[{\"field\":\"iguana\",\"cols\":1,\"rows\":1}]}, \
\
{\"agent\":\"hash\",\"method\":\"NXT\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":100,\"rows\":1}]}, \
{\"agent\":\"hash\",\"method\":\"curve25519\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"rmd160_sha256\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"sha256_sha256\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"base64_encode\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"base64_decode\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"crc32\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"sha512\",\"fields\":[{\"skip\":1,\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"sha384\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"sha256\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"sha224\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"rmd320\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"rmd256\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"rmd160\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"rmd128\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"sha1\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"md2\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"md4\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"md5\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"tiger\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"whirlpool\",\"fields\":[{\"skip\":1,\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_sha512\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_sha384\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_sha256\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_sha224\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_rmd320\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_rmd256\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_rmd160\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_rmd128\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_sha1\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_md2\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_md4\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_md5\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_tiger\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}, \
{\"agent\":\"hash\",\"method\":\"hmac_whirlpool\",\"fields\":[{\"skip\":1,\"field\":\"password\",\"cols\":32,\"rows\":1},{\"field\":\"message\",\"cols\":64,\"rows\":3}]}\
]"
char *HTMLheader =
"<!DOCTYPE HTML> \
<html style=\"overflow-y:scroll;-webkit-user-select: text\"> \
<head> \
<meta http-equiv=\"Pragma\" content=\"no-cache\"> \
<meta http-equiv=\"Expires\" content=\"-1\"> \
<title>iguana</title> \
<script src=\"jquery-2.1.4.min.js\" type=\"text/javascript\"></script> \
<link rel=\"stylesheet\" href=\"css/bootstrap.css\" type=\"text/css\"> \
\
</head> \
<body data-custom-load=\"true\" data-name=\"iguana\" data-tools=\"pnacl newlib glibc clang-newlib mac\" data-configs=\"Debug Release\" data-path=\"{tc}/{config}\">";
// <a href="./iguana/link?field=val">Link</a>
char *HTMLfooter =
"<script type=\"text/javascript\" src=\"js/util.js\"></script> \
\
<script type=\"text/javascript\" src=\"common.js\"></script> \
<script type=\"text/javascript\" src=\"example.js\"></script> \
\
<script src=\"js/bootstrap.js\" type=\"text/javascript\"></script> \
<script src=\"js/api.js\" type=\"text/javascript\" charset=\"utf-8\"></script> \
<script src=\"js/methods.js\" type=\"text/javascript\" charset=\"utf-8\"></script> \
<script src=\"js/sites.js\" type=\"text/javascript\" charset=\"utf-8\"></script> \
<script src=\"js/settings.js\" type=\"text/javascript\" charset=\"utf-8\"></script> \
<script src=\"js/jay.min.js\"></script> \
<script src=\"js/jay.ext.js\"></script> \
\
</body> \
</html>";
#define HTML_EMIT(str) if ( (str) != 0 && (str)[0] != 0 ) strcpy(&retbuf[size],str), size += (int32_t)strlen(str)
/*
struct endpoint find_epbits(struct relay_info *list,uint32_t ipbits,uint16_t port,int32_t type)
@ -265,3 +398,339 @@ void SuperNET_init(struct supernet_info *myinfo,char *jsonstr)
init_SUPERNET_pullsock(myinfo,10,10);
}*/
int32_t Supernet_lineparse(char *key,int32_t keymax,char *value,int32_t valuemax,char *src)
{
int32_t a,b,c,n = 0;
key[0] = value[0] = 0;
while ( (c= src[n]) == ' ' || c == '\t' || c == '\n' || c == '\t' )
n++;
while ( (c= src[n]) != ':' && c != 0 )
{
*key++ = c;
if ( ++n >= keymax-1 )
{
*key = 0;
printf("lineparse overflow key.(%s)\n",src);
return(-1);
}
}
*key = 0;
if ( src[n] != ':' )
return(n);
n++;
while ( (c= src[n]) == ' ' || c == '\t' )
n++;
while ( (c= src[n]) != 0 && c != '\r' && c != '\n' )
{
if ( c == '%' && (a= src[n+1]) != 0 && (b= src[n+2]) != 0 )
c = ((unhex(a) << 4) | unhex(b)), n += 2;
*value++ = c;
n++;
if ( n >= valuemax-1 )
{
*value = 0;
printf("lineparse overflow.(%s)\n",src);
return(-1);
}
}
*value = 0;
if ( src[n] != 0 )
{
n++;
while ( (c= src[n]) == '\r' || c == '\n' )
n++;
}
return(n);
}
cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr)
{
int32_t i,n,totallen,datalen,len = 0; cJSON *json,*array; char key[8192],*data;
json = cJSON_CreateObject();
array = cJSON_CreateArray();
totallen = (int32_t)strlen(urlstr);
while ( 1 )
{
for (i=len; urlstr[i]!=0; i++)
if ( urlstr[i] == '\r' || urlstr[i] == '\n' )
break;
if ( i == len && (urlstr[len] == '\r' || urlstr[len] == '\n') )
{
len++;
continue;
}
urlstr[i] = 0;
if ( (n= Supernet_lineparse(key,sizeof(key),value,bufsize,&urlstr[len])) > 0 )
{
if ( value[0] != 0 )
jaddstr(json,key,value);
else jaddistr(array,key);
len += (n + 1);
if ( strcmp(key,"Content-Length") == 0 && (datalen= atoi(value)) > 0 )
{
data = &urlstr[totallen - datalen];
data[-1] = 0;
//printf("post.(%s) (%c)\n",data,data[0]);
jaddstr(json,"POST",data);
}
} else break;
}
jadd(json,"lines",array);
return(json);
}
char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsize,int32_t *postflagp,char *urlstr,char *remoteaddr)
{
cJSON *tokens,*argjson,*json = 0; char urlmethod[16],*data,url[1024],*retstr,*token = 0; int32_t i,j,n;
//printf("rpcparse.(%s)\n",urlstr);
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
urlmethod[i] = urlstr[i];
urlmethod[i++] = 0;
n = i;
//printf("URLMETHOD.(%s)\n",urlmethod);
*postflagp = (strcmp(urlmethod,"POST") == 0);
for (i=0; i<sizeof(url)-1&&urlstr[n+i]!=0&&urlstr[n+i]!=' '; i++)
url[i] = urlstr[n+i];
url[i++] = 0;
n += i;
//printf("URL.(%s)\n",url);
tokens = cJSON_CreateArray();
j = 0;
if ( url[0] != '/' )
token = url;
for (i=0; url[i]!=0; i++)
{
if ( url[i] == '/' )
{
url[i] = 0;
if ( token != 0 )
jaddistr(tokens,token);
token = &url[i+1];
continue;
}
}
if ( token != 0 )
jaddistr(tokens,token);
if ( (json= SuperNET_urlconv(retbuf,bufsize,urlstr+n)) != 0 )
{
jadd(json,"tokens",tokens);
jaddstr(json,"urlmethod",urlmethod);
if ( (data= jstr(json,"POST")) == 0 || (argjson= cJSON_Parse(data)) == 0 )
{
argjson = cJSON_CreateObject();
if ( (n= cJSON_GetArraySize(tokens)) > 0 )
{
jaddstr(argjson,"agent",jstri(tokens,0));
if ( n > 1 )
jaddstr(argjson,"method",jstri(tokens,1));
for (i=2; i<n; i++)
{
if ( i == n-1 )
jaddstr(argjson,"data",jstri(tokens,i));
else
{
jaddstr(argjson,jstri(tokens,i),jstri(tokens,i+1));
i++;
}
}
}
}
retstr = SuperNET_JSON(myinfo,argjson,remoteaddr);
printf("(%s) -> (%s) postflag.%d (%s)\n",urlstr,cJSON_Print(json),*postflagp,jprint(argjson,0));
return(retstr);
}
return(clonestr("{\"error\":\"couldnt process packet\"}"));
}
#ifdef notyet
int32_t iguana_htmlgen(char *retbuf,int32_t bufsize,char *result,char *error,cJSON *json,char *tabname,char *origjsonstr)
{
char *url = "http://127.0.0.1:7778";
int i,j,m,size = 0,n,rows,cols; cJSON *array,*obj,*array2,*item,*tmp;
char formheader[512],formfooter[512],clickname[512],buf[512],fieldbuf[512],fieldindex[2],postjson[8192];
char *disp,*fieldname,*button,*agent,*method,*str;
bufsize--;
HTML_EMIT("<html> <head></head> <body> <p id=\"RTstats\"></p> ");
sprintf(buf,"<canvas id=\"canvas\" width=\"%d\" height=\"%d\"></canvas><script>var Width = %d; var Height = %d;",IGUANA_WIDTH,IGUANA_HEIGHT,IGUANA_WIDTH,IGUANA_HEIGHT);
HTML_EMIT(buf);
HTML_EMIT("var RTparsed = 0; var RTcount = 0; var RTpending = 0; var RTwidth; var RTheight; var RTamplitude; var RTname; var RTjson;");
sprintf(buf,"setInterval(iguana_poll,%d);",IGUANS_JSMILLIS);
HTML_EMIT(buf);
HTML_EMIT("\
\
function process_bitmap(bitmapjson) \
{\
var red,green,blue,n,m; var bitmap = JSON.parse(bitmapjson); \
var canvas = document.getElementById(\"canvas\"); \
var ctx = canvas.getContext(\"2d\"); \
var image = ctx.getImageData(0,0,Width,Height); \
RTamplitude = bitmap.amplitude / 255; \
RTname = bitmap.status; \
RTjson = bitmapjson; RTwidth = bitmap.width; RTheight = bitmap.height; \
red = 0; blue = 0; green = 0; n = 0; m = 0;\
for (y=0; y<Height; y++)\
{\
for (x=0; x<Width; x++)\
{\
image.data[m++] = bitmap.pixels[n++]; image.data[m++] = bitmap.pixels[n++]; image.data[m++] = bitmap.pixels[n++]; image.data[m++] = 255; \
}\
}\
ctx.putImageData(image,0,0);\
RTcount++;\
RTparsed = 1;\
}\
\
function bitmap_handler() \
{ \
if ( this.status == 200 && this.responseText != null ) \
{ \
process_bitmap(this.responseText); \
if ( RTpending > 0 ) \
RTpending--; \
} \
} \
\
function httpGet()\
{\
var client;\
if (window.XMLHttpRequest)\
client = new XMLHttpRequest();\
else client = new ActiveXObject(\"Microsoft.XMLHTTP\");\
client.onload = bitmap_handler;\
client.open(\"GET\",\"http://127.0.0.1:7778/api/bitmap\");\
client.send();\
}\
\
function iguana_poll( )\
{ \
var y,x,m,red,green,blue; \
document.getElementById(\"RTstats\").innerHTML = RTcount + ' ' + RTname;\
if ( RTpending == 0 )\
{\
httpGet();\
RTpending++;\
}\
} </script><br>");
//sprintf(buf,"<br> COIN: <textarea cols=\"8\" rows=\"1\" name=\"COIN_NAME\"/>name</textarea>");
//HTML_EMIT(buf);
//HTML_EMIT(" Agent: "); HTML_EMIT(Default_agent);
HTML_EMIT("<br><br/>");
HTML_EMIT(origjsonstr); HTML_EMIT(" -> ");
HTML_EMIT("<textarea cols=\"150\" rows=\"10\" name=\"jsonresult\"/>");
tmp = cJSON_Parse(result), str = cJSON_Print(tmp), free_json(tmp);
HTML_EMIT(str); free(str);
HTML_EMIT(error);
HTML_EMIT("</textarea>");
formheader[0] = formfooter[0] = 0;
if ( (array= jarray(&n,json,"forms")) != 0 )
{
for (i=0; i<n; i++)
{
item = jitem(array,i);
//printf("FORM[%d] of %d %s\n",i,n,jprint(item,0));
// {"forms":[{"name":"block","agent":"ramchain","fields":[{"disp":"height of block","field":"height","cols":10,"rows":1},{"disp":"blockhash","field":"hash","cols":65,"rows":1}]}]}
if ( (method= jstr(item,"method")) == 0 )
method = "missing";
sprintf(clickname,"%s%d_%s",tabname,i,method);
if ( (button= jstr(item,"button")) == 0 )
button = method;
if ( (agent= jstr(item,"agent")) == 0 )
agent = "iguana";
if ( strncmp(Default_agent,"ALL",3) != 0 && strcmp(method,"setagent") != 0 && strncmp(Default_agent,agent,strlen(agent)) != 0 )
{
//printf("Default_agent.%s vs agent.(%s)\n",Default_agent,agent);
continue;
}
sprintf(buf,"<script> function click_%s()\n{\n",clickname);
HTML_EMIT(buf);
sprintf(postjson,"%s/%s",agent,method);
//printf("form.%s button.%s [%s]\n",formname,button,postjson);
if ( (array2= jarray(&m,item,"fields")) != 0 )
{
//sprintf(buf,"COIN = document.COIN_NAME.value;\n");
//sprintf(postjson+strlen(postjson),"/%s/' + %s + '","coin","COIN");
for (j=0; j<m; j++)
{
obj = jitem(array2,j);
//printf("item[%d] -> (%s)\n",j,jprint(obj,0));
sprintf(fieldindex,"%c",'A'+j);
if ( (fieldname= jstr(obj,"field")) != 0 )
{
sprintf(buf,"%s = document.%s.%s.value;\n",fieldindex,clickname,fieldname);
HTML_EMIT(buf);
//sprintf(postjson+strlen(postjson),",\"%s\":\"' + %s + '\"",fieldname,fieldindex);
if ( juint(obj,"skip") == 0 )
sprintf(postjson+strlen(postjson),"/%s/' + %s + '",fieldname,fieldindex);
else sprintf(postjson+strlen(postjson),"/' + %s + '",fieldindex);
}
}
//strcat(postjson,"}");
sprintf(&retbuf[size],"location.href = '%s/%s';\n}</script>\r\n",url,postjson), size += strlen(&retbuf[size]);
sprintf(formheader,"<form name=\"%s\" action=\"%s\" method=\"POST\" onsubmit=\"return submitForm(this);\"><table>",clickname,url);
HTML_EMIT(formheader);
disp = jstr(item,"disp");
for (j=0; j<m; j++)
{
obj = jitem(array2,j);
rows = juint(obj,"rows");
cols = juint(obj,"cols");
if ( (fieldname= jstr(obj,"field")) == 0 )
sprintf(fieldbuf,"%s_%c",clickname,'A'+j), fieldname = fieldbuf;
if ( rows == 0 && cols == 0 )
sprintf(buf,"<input type=\"text\" name=\"%s\"/>",fieldname);
else sprintf(buf,"<textarea cols=\"%d\" rows=\"%d\" name=\"%s\"/ %s></textarea>",cols,rows,fieldname,cols == 1 ? "hidden" : "");
str = disp==0?jstr(obj,"disp"):disp;
sprintf(&retbuf[size],"<td>%s</td> <td> %s </td>\r\n",str!=0?str:fieldname,buf), size += strlen(&retbuf[size]);
}
sprintf(formfooter,"<td colspan=\"2\"> <input type=\"button\" value=\"%s\" onclick=\"click_%s()\" /></td> </tr>\n</table></form>",button,clickname);
HTML_EMIT(formfooter);
}
}
}
HTML_EMIT("<br><br/>"); HTML_EMIT("</body></html>"); HTML_EMIT("<br><br/>");
return((int32_t)strlen(retbuf));
}
#undef HTML_EMIT
char *SuperNET_htmlresponse(char *retbuf,int32_t bufsize,int32_t *remainsp,int32_t localaccess,char *retstr,int32_t freeflag)
{
static char *html = "<html> <head></head> <body> %s </body> </html>";
char *result=0,*error=0; int32_t n; cJSON *json,*formsjson;
retbuf[0] = 0;
/*if ( localaccess == 0 )
sprintf(retbuf+strlen(retbuf),"Access-Control-Allow-Origin: *\r\n");
else sprintf(retbuf+strlen(retbuf),"Access-Control-Allow-Origin: null\r\n");
sprintf(retbuf+strlen(retbuf),"Access-Control-Allow-Credentials: true\r\n");
sprintf(retbuf+strlen(retbuf),"Access-Control-Allow-Headers: Authorization, Content-Type\r\n");
sprintf(retbuf+strlen(retbuf),"Access-Control-Allow-Methods: GET, POST\r\n");
sprintf(retbuf+strlen(retbuf),"Cache-Control: no-cache, no-store, must-revalidate\r\n");
sprintf(retbuf+strlen(retbuf),"Content-type: text/html\r\n");
sprintf(retbuf+strlen(retbuf),"Content-Length: %8d\r\n\r\n",n);*/
sprintf(retbuf+strlen(retbuf),"<!DOCTYPE HTML>\n\r");
n = (int32_t)strlen(retbuf);
formsjson = cJSON_Parse(IGUANA_FORMS);
if ( (json= cJSON_Parse(retstr)) == 0 )
json = cJSON_CreateObject();
jadd(json,"forms",formsjson);
error = jstr(json,"error");
result = jstr(json,"result");
//printf("process.(%s)\n",jprint(formsjson,0));
n = iguana_htmlgen(&retbuf[n],bufsize-n,result,error,json,"iguana",Currentjsonstr);
free_json(json);
if ( n == 0 )
{
n = (int32_t)(strlen(html) + strlen(retstr) + 1);
sprintf(retbuf+strlen(retbuf),html,retstr);
}
if ( freeflag != 0 )
free(retstr);
if ( n > bufsize )
{
printf("htmlresponse overflowed buffer[%d] with %d\n",bufsize,n);
exit(-1);
}
*remainsp = n;
return(retbuf);
}
#endif

4
SuperNET/SuperNET.h

@ -20,7 +20,7 @@
#include "../includes/cJSON.h"
#include "../includes/nanomsg/nn.h"
#define SUPERNET_PORT 7774
#define SUPERNET_PORT 7778
#define SUPERNET_NETWORKTIMEOUT 10000
#define SUPERNET_POLLTIMEOUT 1
#define SUPERNET_APIUSLEEP (SUPERNET_POLLTIMEOUT * 10000)
@ -83,6 +83,8 @@ struct endpoint calc_epbits(char *transport,uint32_t ipbits,uint16_t port,int32_
int32_t badass_servers(char servers[][MAX_SERVERNAME],int32_t max,int32_t port);
int32_t crackfoo_servers(char servers[][MAX_SERVERNAME],int32_t max,int32_t port);
void SuperNET_init();
char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *argjson,char *remoteaddr);
char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsize,int32_t *postflagp,char *urlstr,char *remoteaddr);
extern int32_t PULLsock;
extern struct relay_info RELAYS;

2
SuperNET/m_osx

@ -1 +1 @@
gcc -o ../agents/SuperNET -O2 *.c ../agents/libcrypto777.a -lssl -lcrypto -lpthread -lm
gcc -o ../agents/SuperNET -O2 *.c ../agents/libcrypto777.a -lnanomsg -lssl -lcrypto -lpthread -lm

2
SuperNET/m_unix

@ -1 +1 @@
gcc -o ../agents/SuperNET -O2 *.c ../agents/libcrypto777.a -lssl -lcrypto -lpthread -lm
gcc -o ../agents/SuperNET -O2 *.c ../agents/libcrypto777.a -lnanomsg -lssl -lcrypto -lpthread -lm

127
SuperNET/main.c

@ -162,11 +162,6 @@ int32_t SuperNET_msgvalidate(struct supernet_msghdr *msg)
return(msglen);
}
char *SuperNET_JSON(struct supernet_info *myinfo,char *jsonstr)
{
return(clonestr("{\"error\":\"SuperNET is just a stub for now\"}"));
}
int32_t nn_settimeouts(int32_t sock,int32_t sendtimeout,int32_t recvtimeout)
{
int32_t retrymillis,maxmillis;
@ -215,25 +210,10 @@ int32_t nn_createsocket(struct supernet_info *myinfo,char *endpoint,int32_t bind
bits256 SuperNET_OPRETURN(struct supernet_info *myinfo,char *symbol,double fee,uint8_t *buf,int32_t len)
{
bits256 txid;
printf("send OPRETURN\n");
return(txid);
}
/*int32_t SuperNET_OPRETURN(uint8_t *data,char *announce)
{
static char *protocols[][2] = { {"pangea","GEA"}, {"peggy","PAX"} };
int32_t i;
for (i=0; i<sizeof(protocols)/sizeof(*protocols); i++)
{
if ( strcmp(protocols[i][0],announce) == 0 )
{
data[0] = SCRIPT_OPRETURN;
memcpy(&data[1],protocols[i][1],3);
return(4);
}
}
return(0);
}*/
bits256 SuperNET_agentannounce(struct supernet_info *myinfo,struct supernet_agent *agent,cJSON *network)
{
static bits256 zero;
@ -425,6 +405,99 @@ int32_t SuperNET_send(struct supernet_info *myinfo,struct supernet_agent *agent,
return(len);
}
char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *argjson,char *remoteaddr)
{
char *agent,*method;
if ( (agent= jstr(argjson,"agent")) == 0 || (method= jstr(argjson,"method")) == 0 )
return(clonestr("{\"error\":\"need both agent and method\"}"));
}
void SuperNET_rpcloop(void *args)
{
struct supernet_info *myinfo = args;
int32_t recvlen,bindsock,postflag,sock,remains,numsent,len; socklen_t clilen;
char remoteaddr[64],jsonbuf[8192],*buf,*retstr,*space;//,*retbuf; ,n,i,m
struct sockaddr_in cli_addr; uint32_t ipbits,i; uint16_t port;
int32_t size = 1024 * 1024 * 2;
port = SUPERNET_PORT;
bindsock = SuperNET_socket(1,"127.0.0.1",port);
printf("SuperNET_rpcloop 127.0.0.1:%d bind sock.%d\n",port,bindsock);
space = calloc(1,size);
while ( bindsock >= 0 )
{
clilen = sizeof(cli_addr);
//printf("ACCEPT (%s:%d) on sock.%d\n","127.0.0.1",port,bindsock);
sock = accept(bindsock,(struct sockaddr *)&cli_addr,&clilen);
if ( sock < 0 )
{
//printf("iguana_rpcloop ERROR on accept usock.%d\n",sock);
continue;
}
memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits));
expand_ipbits(remoteaddr,ipbits);
memset(jsonbuf,0,sizeof(jsonbuf));
remains = (int32_t)(sizeof(jsonbuf) - 1);
buf = jsonbuf;
recvlen = 0;
retstr = 0;
while ( remains > 0 )
{
if ( (len= (int32_t)recv(sock,buf,remains,0)) < 0 )
{
if ( errno == EAGAIN )
{
printf("EAGAIN for len %d, remains.%d\n",len,remains);
usleep(10000);
}
break;
}
else
{
if ( len > 0 )
{
remains -= len;
recvlen += len;
buf = &buf[len];
retstr = SuperNET_rpcparse(myinfo,space,size,&postflag,jsonbuf,remoteaddr);
break;
} else usleep(10000);
}
}
if ( retstr != 0 )
{
i = 0;
if ( postflag == 0 )
{
//retstr = SuperNET_htmlresponse(space,size,&remains,1,retstr,1);
}
else remains = (int32_t)strlen(retstr);
printf("RETBUF.(%s)\n",retstr);
while ( remains > 0 )
{
if ( (numsent= (int32_t)send(sock,&retstr[i],remains,MSG_NOSIGNAL)) < 0 )
{
if ( errno != EAGAIN && errno != EWOULDBLOCK )
{
//printf("%s: %s numsent.%d vs remains.%d len.%d errno.%d (%s) usock.%d\n",retstr,ipaddr,numsent,remains,recvlen,errno,strerror(errno),sock);
break;
}
}
else if ( remains > 0 )
{
remains -= numsent;
i += numsent;
if ( remains > 0 )
printf("iguana sent.%d remains.%d of len.%d\n",numsent,remains,recvlen);
}
}
if ( retstr != space )
free(retstr);
}
//printf("done response sock.%d\n",sock);
closesocket(sock);
}
}
int32_t SuperNET_msgrecv(struct supernet_info *myinfo,struct supernet_agent *agent,uint8_t *_buf,int32_t maxlen)
{
int32_t len,recvlen; void *buf = _buf; struct supernet_msghdr H;
@ -647,7 +720,7 @@ void SuperNET_loop(struct supernet_info *myinfo)
void SuperNET_main(void *arg)
{
struct supernet_info MYINFO; cJSON *json,*array; uint16_t port; int32_t i,n = 0;
struct supernet_info MYINFO; int32_t i;//cJSON *json,*array; uint16_t port;,n = 0;
memset(&MYINFO,0,sizeof(MYINFO));
if ( 1 )
{
@ -658,8 +731,8 @@ void SuperNET_main(void *arg)
if ( MYINFO.POLLTIMEOUT == 0 )
MYINFO.POLLTIMEOUT = SUPERNET_POLLTIMEOUT;
}
if ( arg == 0 || (json= cJSON_Parse(arg)) == 0 )
SuperNET_acceptport(&MYINFO,MYINFO.port);
/*if ( arg == 0 || (json= cJSON_Parse(arg)) == 0 )
SuperNET_acceptport(&MYINFO,MYINFO.acceptport);
else
{
if ( (array= jarray(&n,json,"accept")) != 0 )
@ -669,9 +742,9 @@ void SuperNET_main(void *arg)
SuperNET_acceptport(&MYINFO,port);
}
free_json(json);
}
sleep(3);
printf("start SuperNET_loop on port.%u\n",MYINFO.port);
}*/
printf("start SuperNET_loop on port.%u\n",SUPERNET_PORT);
OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)SuperNET_rpcloop,&MYINFO);
for (i=0; i<sizeof(MYINFO.agents)/sizeof(*MYINFO.agents); i++)
MYINFO.agents[i].sock = -1;
SuperNET_loop(&MYINFO);

18
crypto777/Makefile

@ -14,27 +14,17 @@ TARGET = crypto777
EXTRA= -D__PNACL
include $(NACL_SDK_ROOT)/tools/common.mk
CHROME_ARGS += --allow-nacl-socket-api=127.0.0.1
DEPS = nacl_io
LIBS =
CFLAGS = -Wall -D__PNACL -fno-strict-aliasing $(EXTRA)
CFLAGS = -Wall -D__PNACL -fno-strict-aliasing $(EXTRA) -I../includes
LFLAGS = libs
SOURCES = cJSON.c ramcoder.c iguana_serdes.c iguana_OS.c OS_portable.c OS_time.c OS_nonportable.c hmac_sha512.c SaM.c bitcoind_RPC.c inet.c iguana_utils.c curve25519.c curve25519-donna.c jpeg/jaricom.c jpeg/jcapimin.c jpeg/jcapistd.c jpeg/jcarith.c jpeg/jccoefct.c jpeg/jccolor.c \
jpeg/jcdctmgr.c jpeg/jchuff.c jpeg/jcinit.c jpeg/jcmainct.c jpeg/jcmarker.c jpeg/jcmaster.c \
jpeg/jcomapi.c jpeg/jcparam.c jpeg/jcprepct.c jpeg/jcsample.c jpeg/jctrans.c jpeg/jdapimin.c \
jpeg/jdapistd.c jpeg/jdarith.c jpeg/jdatadst.c jpeg/jdatasrc.c jpeg/jdcoefct.c jpeg/jdcolor.c \
jpeg/jddctmgr.c jpeg/jdhuff.c jpeg/jdinput.c jpeg/jdmainct.c jpeg/jdmarker.c jpeg/jdmaster.c \
jpeg/jdmerge.c jpeg/jdpostct.c jpeg/jdsample.c jpeg/jdtrans.c jpeg/jerror.c jpeg/jfdctflt.c \
jpeg/jfdctfst.c jpeg/jfdctint.c jpeg/jidctflt.c jpeg/jidctfst.c jpeg/jidctint.c jpeg/jquant1.c \
jpeg/jquant2.c jpeg/jutils.c jpeg/jmemmgr.c jpeg/jmemnobs.c
include crypto777.sources
# Build rules generated by macros from common.mk:
$(foreach dep,$(DEPS),$(eval $(call DEPEND_RULE,$(dep))))
$(foreach src,$(SOURCES),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS))))
$(foreach src,$(CRYPTO777_SRCS),$(eval $(call COMPILE_RULE,$(src),$(CFLAGS))))
$(eval $(call LIB_RULE,$(TARGET),$(SOURCES)))
$(eval $(call LIB_RULE,$(TARGET),$(CRYPTO777_SRCS)))

14
crypto777/OS_time.c

@ -624,7 +624,19 @@ int main(int argc, const char * argv[])
printf("(%s) time.%s date.%s %ld start.%ld %s %u %u\n",tai_str(str3,t),taitime_str(str,ct),str2,(long)tai2utime(t),(long)tai2utime(start),utime_str(str4,t),tai2utc(t),(uint32_t)time(NULL));
}
// insert code here...
printf("Hello, World!\n");
{
char str[65]; struct tai t; double startmillis; int32_t datenum,seconds; uint64_t i,checkval,timestamp,now = (uint32_t)time(NULL);
startmillis = OS_milliseconds();
for (i=0; i<1000000; i++)
{
timestamp = now - (rand() % 100000000LL); // range -100000000LL to +500000000LL
datenum = OS_conv_unixtime(&t,&seconds,timestamp); // gmtime -> datenum + number of seconds
checkval = OS_conv_datenum(datenum,seconds/3600,(seconds/60)%60,seconds%60); // datenum+H:M:S -> unix time
if ( checkval != timestamp )
printf("%s i.%lld timestamp.%-12llu -> (%d:%06d) -> checkval.%-12llu diff.[%lld]\n",tai_str(str,t),(long long)i,(long long)timestamp,datenum,seconds,(long long)checkval,(long long)(timestamp-checkval));
}
printf("million tai compares in %.3f microseconds per encode/decode\n",1000. * (OS_milliseconds()-startmillis)/i);
}
return 0;
}
#endif

1328
crypto777/ccgi.c

File diff suppressed because it is too large

11
crypto777/crypto777.sources

@ -0,0 +1,11 @@
JPEG_SRCS := ../crypto777/jpeg/jaricom.c ../crypto777/jpeg/jcapimin.c ../crypto777/jpeg/jcapistd.c ../crypto777/jpeg/jcarith.c ../crypto777/jpeg/jccoefct.c ../crypto777/jpeg/jccolor.c \
../crypto777/jpeg/jcdctmgr.c ../crypto777/jpeg/jchuff.c ../crypto777/jpeg/jcinit.c ../crypto777/jpeg/jcmainct.c ../crypto777/jpeg/jcmarker.c ../crypto777/jpeg/jcmaster.c \
../crypto777/jpeg/jcomapi.c ../crypto777/jpeg/jcparam.c ../crypto777/jpeg/jcprepct.c ../crypto777/jpeg/jcsample.c ../crypto777/jpeg/jctrans.c ../crypto777/jpeg/jdapimin.c \
../crypto777/jpeg/jdapistd.c ../crypto777/jpeg/jdarith.c ../crypto777/jpeg/jdatadst.c ../crypto777/jpeg/jdatasrc.c ../crypto777/jpeg/jdcoefct.c ../crypto777/jpeg/jdcolor.c \
../crypto777/jpeg/jddctmgr.c ../crypto777/jpeg/jdhuff.c ../crypto777/jpeg/jdinput.c ../crypto777/jpeg/jdmainct.c ../crypto777/jpeg/jdmarker.c ../crypto777/jpeg/jdmaster.c \
../crypto777/jpeg/jdmerge.c ../crypto777/jpeg/jdpostct.c ../crypto777/jpeg/jdsample.c ../crypto777/jpeg/jdtrans.c ../crypto777/jpeg/jerror.c ../crypto777/jpeg/jfdctflt.c \
../crypto777/jpeg/jfdctfst.c ../crypto777/jpeg/jfdctint.c ../crypto777/jpeg/jidctflt.c ../crypto777/jpeg/jidctfst.c ../crypto777/jpeg/jidctint.c ../crypto777/jpeg/jquant1.c \
../crypto777/jpeg/jquant2.c ../crypto777/jpeg/jutils.c ../crypto777/jpeg/jmemmgr.c ../crypto777/jpeg/jmemnobs.c
CRYPTO777_SRCS := ../crypto777/ccgi.c ../crypto777/cJSON.c ../crypto777/iguana_utils.c ../crypto777/OS_nonportable.c ../crypto777/curve25519-donna.c ../crypto777/inet.c ../crypto777/OS_portable.c ../crypto777/curve25519.c ../crypto777/libgfshare.c ../crypto777/OS_time.c ../crypto777/hmac_sha512.c ../crypto777/ramcoder.c ../crypto777/SaM.c ../crypto777/iguana_OS.c ../crypto777/iguana_serdes.c $(JPEG_SRCS)

1
crypto777/inet.c

@ -19,6 +19,7 @@
#ifndef crypto777_inet_h
#define crypto777_inet_h
#include "OS_portable.h"
#include <netinet/in.h>
#ifdef _WIN32
#include <windows.h>

3
crypto777/m_win32

@ -1,2 +1 @@
echo do equivalent of: gcc -c -O2 *.c jpeg/*.c jpeg/win/*.c
echo do equivalent of: rm ../agents/libcrypto777.a; ar rcu ../agents/libcrypto777.a *.o
make -f mingw32

6
crypto777/mingw

@ -0,0 +1,6 @@
include crypto777.sources
all:
$(TOOL_DIR)/$(MINGW)-gcc -D __MINGW -c $(CRYPTO777_SRCS)
$(TOOL_DIR)/$(MINGW)-ar rcu *.o ../agents/libcrypto777.a

2
crypto777/mingw32

@ -0,0 +1,2 @@
include ../mingw.path
include mingw

3
crypto777/mingw64

@ -0,0 +1,3 @@
include ../mingw.path
include mingw

837
deprecated/obsolete.h

@ -10184,5 +10184,840 @@ void iguana_dedicatedrecv(void *arg)
} else retjsonstr = clonestr("{\"error\":\"cant parse generic JSON\"}");
return(retjsonstr);
}*/
char *iguana_remoteparser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json)
{
int32_t i,n,remains,numsent; char *jsonstr = 0,*retstr = 0; uint8_t hdr[128];
if ( agent->sock < 0 )
agent->sock = iguana_socket(0,agent->hostname,agent->port);
if ( agent->sock >= 0 )
{
i = 0;
jsonstr = jprint(json,0);
n = (int32_t)strlen(jsonstr) + 1;
remains = n;
//printf("RETBUF.(%s)\n",retbuf);
while ( remains > 0 )
{
if ( (numsent= (int32_t)send(agent->sock,&jsonstr[i],remains,MSG_NOSIGNAL)) < 0 )
{
if ( errno != EAGAIN && errno != EWOULDBLOCK )
{
printf("%s: %s numsent.%d vs remains.%d of %d errno.%d (%s) usock.%d\n",jsonstr,agent->name,numsent,remains,n,errno,strerror(errno),agent->sock);
break;
}
}
else if ( remains > 0 )
{
remains -= numsent;
i += numsent;
if ( remains > 0 )
printf("iguana sent.%d remains.%d of len.%d\n",numsent,remains,n);
}
}
if ( (n= (int32_t)recv(agent->sock,hdr,sizeof(hdr),0)) >= 0 )
{
remains = (hdr[0] + ((int32_t)hdr[1] << 8) + ((int32_t)hdr[2] << 16));
retstr = mycalloc('p',1,remains + 1);
i = 0;
while ( remains > 0 )
{
if ( (n= (int32_t)recv(agent->sock,&retstr[i],remains,0)) < 0 )
{
if ( errno == EAGAIN )
{
printf("EAGAIN for len %d, remains.%d\n",n,remains);
usleep(10000);
}
break;
}
else
{
if ( n > 0 )
{
remains -= n;
i += n;
} else usleep(10000);
}
}
}
free(jsonstr);
}
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"null return\"}");
return(retstr);
}
struct iguana_agent *Agents[16];
cJSON *iguana_agentinfojson(struct iguana_agent *agent)
{
cJSON *json= cJSON_CreateObject();
jaddstr(json,"name",agent->name);
jadd(json,"methods",agent->methods);
if ( agent->port != 0 )
jaddnum(json,"port",agent->port);
else jaddstr(json,"type","builtin");
return(json);
}
char *iguana_addagent(char *name,char *(*parsefunc)(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json),char *hostname,cJSON *methods,uint16_t port,char *pubkeystr,char *privkeystr)
{
int32_t i; struct iguana_agent *agent; char retbuf[8192];
for (i=0; i<sizeof(Agents)/sizeof(*Agents); i++)
{
if ( (agent= Agents[i]) != 0 && strcmp(agent->name,name) == 0 )
{
if ( pubkeystr != 0 && privkeystr != 0 && strlen(pubkeystr) == 64 && strlen(privkeystr) == 64 )
{
decode_hex(agent->pubkey.bytes,sizeof(bits256),pubkeystr);
decode_hex(agent->privkey.bytes,sizeof(bits256),privkeystr);
}
if ( port != 0 && agent->port == 0 )
{
if ( agent->sock >= 0 )
close(agent->sock);
agent->port = port;
strcpy(agent->hostname,hostname);
agent->sock = iguana_socket(0,agent->hostname,port);
printf("set (%s) port.%d for %s -> sock.%d\n",hostname,port,agent->name,agent->sock);
}
if ( agent->port > 0 && agent->sock < 0 && agent->hostname[0] != 0 && (agent->sock= iguana_socket(0,agent->hostname,agent->port)) < 0 )
return(clonestr("{\"result\":\"existing agent couldnt connect to remote agent\"}"));
else return(clonestr("{\"result\":\"agent already there\"}"));
}
}
for (i=0; i<sizeof(Agents)/sizeof(*Agents); i++)
{
if ( Agents[i] == 0 )
{
agent = mycalloc('G',1,sizeof(*Agents[i]));
Agents[i] = agent;
strncpy(agent->name,name,sizeof(agent->name)-1);
strncpy(agent->hostname,hostname,sizeof(agent->hostname)-1);
agent->methods = methods, agent->nummethods = cJSON_GetArraySize(methods);
agent->sock = -1;
agent->port = port;
agent->parsefunc = (void *)parsefunc;
if ( pubkeystr != 0 && privkeystr != 0 && strlen(pubkeystr) == 64 && strlen(privkeystr) == 64 )
{
decode_hex(agent->pubkey.bytes,sizeof(bits256),pubkeystr);
decode_hex(agent->privkey.bytes,sizeof(bits256),privkeystr);
}
if ( port > 0 )
{
if ( (agent->sock= iguana_socket(0,hostname,port)) < 0 )
return(clonestr("{\"result\":\"agent added, but couldnt connect to remote agent\"}"));
}
sprintf(retbuf,"{\"result\":\"agent added\",\"name\"\"%s\",\"methods\":%s,\"hostname\":\"%s\",\"port\":%u,\"sock\":%d}",agent->name,jprint(agent->methods,0),agent->hostname,agent->port,agent->sock);
return(clonestr(retbuf));
}
}
return(clonestr("{\"error\":\"no more agent slots available\"}"));
}
else if ( strcmp(method,"addagent") == 0 )
{
char *hostname = "127.0.0.1",*name; uint16_t port;
if ( (name= jstr(json,"name")) != 0 && (methods= jarray(&n,json,"methods")) != 0 )
{
if ( (port= juint(json,"port")) != 0 )
{
if ( (hostname= jstr(json,"host")) == 0 )
{
if ( (hostname= jstr(json,"ipaddr")) == 0 )
hostname = "127.0.0.1";
}
if ( hostname == 0 )
return(clonestr("{\"error\":\"no host specified for remote agent\"}"));
}
else if ( strcmp(name,"pangea") != 0 && strcmp(name,"InstantDEX") != 0 && strcmp(name,"jumblr") != 0 )
return(clonestr("{\"error\":\"no port specified for remote agent\"}"));
return(iguana_addagent(name,iguana_remoteparser,hostname,methods,port,jstr(json,"pubkey"),jstr(json,"privkey")));
} else return(clonestr("{\"error\":\"cant addagent without name and methods\"}"));
}
if ( (retstr= iguana_addagent("ramchain",ramchain_parser,"127.0.0.1",cJSON_Parse("[\"block\", \"tx\", \"txs\", \"rawtx\", \"balance\", \"totalreceived\", \"totalsent\", \"utxo\", \"status\"]"),0,0,0)) != 0 )
printf("%s\n",retstr), free(retstr);
/*void iguana_issuejsonstrM(void *arg)
{
cJSON *json; int32_t fd; char *retjsonstr,*jsonstr = arg;
retjsonstr = iguana_JSON(jsonstr);
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( (fd= juint(json,"retdest")) > 0 )
{
send(fd,jsonstr,(int32_t)strlen(jsonstr)+1,MSG_NOSIGNAL);
}
free_json(json);
return;
}
printf("%s\n",retjsonstr);
free(retjsonstr);//,strlen(retjsonstr)+1);
free(jsonstr);//,strlen(jsonstr)+1);
}*/
int32_t iguana_rpctestvector(struct iguana_info *coin,char *checkstr,char *jsonstr,int32_t maxlen,int32_t testi)
{
int32_t len,checklen;
sprintf(jsonstr,"{\"rpc.%s testvector.%d\"}",coin->symbol,testi);
sprintf(checkstr,"{\"rpc.%s testvector.%d checkstr should have all info needed to verify the rpc request\"}",coin->symbol,testi);
len = (int32_t)strlen(jsonstr);
checklen = (int32_t)strlen(checkstr);
if ( len > maxlen || checklen > maxlen )
printf("iguana_rpctestvector: i was bad and overflowed buffer len.%d checklen.%d\n",len,checklen), exit(-1);
if ( checklen > len )
len = checklen;
return(len);
}
int32_t iguana_rpctestcheck(struct iguana_info *coin,char *jsonstr,char *retjsonstr)
{
if ( (rand() % 100) == 0 ) // 1% failure rate
return(-1);
else return(0);
}
int32_t iguana_rpctest(struct iguana_info *coin)
{
/* static int32_t testi,good,bad;
char *retjsonstr,jsonstr[4096],checkstr[sizeof(jsonstr)]; // should be big enough
//if ( (rand() % 1000) < 999 ) // if no test active, just return 0
return(0);
if ( iguana_rpctestvector(coin,checkstr,jsonstr,sizeof(jsonstr),testi++) > 0 )
{
retjsonstr = iguana_rpc(coin,jsonstr);
if ( iguana_rpctestcheck(coin,jsonstr,retjsonstr) < 0 )
bad++, printf("rpctestcheck.%s error: (%s) -> (%s) | good.%d bad.%d %.2f%%\n",coin->symbol,jsonstr,retjsonstr,good,bad,100.*(double)good/(good+bad));
else good++;
free(retjsonstr);
return(1); // indicates was active
}*/
return(0);
}
char *iguana_agentjson(char *name,struct iguana_info *coin,char *method,cJSON *json,char *remoteaddr)
{
cJSON *retjson = 0,*array,*methods,*obj; int32_t i,n,j; struct iguana_agent *agent;
if ( strcmp(name,"SuperNET") != 0 )
{
for (i=0; i<sizeof(Agents)/sizeof(*Agents); i++)
{
if ( (agent= Agents[i]) != 0 && strcmp(agent->name,name) == 0 )
{
if ( agent->parsefunc != 0 )
{
for (j=0; j<agent->nummethods; j++)
{
if ( (obj= jitem(agent->methods,j)) != 0 )
{
if ( strcmp(method,jstr(obj,0)) == 0 )
return((*agent->parsefunc)(agent,method,json,remoteaddr));
}
}
return(clonestr("{\"result\":\"agent doesnt have method\"}"));
} else return(clonestr("{\"result\":\"agent doesnt have parsefunc\"}"));
}
}
}
else if ( remoteaddr == 0 || strcmp(remoteaddr,"127.0.0.1") != 0 ) // public api
{
char *coinstr; int32_t j,k,l,r,rr; struct iguana_peer *addr;
array = 0;
if ( strcmp(method,"getpeers") == 0 )
{
if ( (coinstr= jstr(json,"coin")) != 0 )
{
if ( (array= iguana_peersjson(iguana_coinfind(coinstr),1)) == 0 )
return(clonestr("{\"error\":\"coin not found\"}"));
}
else
{
n = 0;
array = cJSON_CreateArray();
r = rand();
for (i=0; i<IGUANA_MAXCOINS; i++)
{
j = (r + i) % IGUANA_MAXCOINS;
if ( (coin= Coins[j]) != 0 )
{
rr = rand();
for (k=0; k<IGUANA_MAXPEERS; k++)
{
l = (rr + k) % IGUANA_MAXPEERS;
addr = &coin->peers.active[l];
if ( addr->usock >= 0 && addr->supernet != 0 )
{
jaddistr(array,addr->ipaddr);
if ( ++n >= 64 )
break;
}
}
}
}
}
if ( array != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"agent","SuperNET");
jaddstr(retjson,"method","mypeers");
jaddstr(retjson,"result","peers found");
jadd(retjson,"peers",array);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"no peers found\"}"));
}
else if ( strcmp(method,"mypeers") == 0 )
{
printf("mypeers from %s\n",remoteaddr!=0?remoteaddr:"local");
}
}
else // local api
{
if ( strcmp(method,"list") == 0 )
{
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
{
if ( Coins[i] != 0 && Coins[i]->symbol[0] != 0 )
jaddistr(array,Coins[i]->symbol);
}
jadd(retjson,"coins",array);
array = cJSON_CreateArray();
for (i=0; i<sizeof(Agents)/sizeof(*Agents); i++)
{
if ( Agents[i] != 0 && Agents[i]->name[0] != 0 )
jaddi(array,iguana_agentinfojson(Agents[i]));
}
jadd(retjson,"agents",array);
return(jprint(retjson,1));
}
else if ( strcmp(method,"peers") == 0 )
{
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
{
if ( Coins[i] != 0 && Coins[i]->symbol[0] != 0 )
jaddi(array,iguana_peersjson(Coins[i],0));
}
jadd(retjson,"allpeers",array);
return(jprint(retjson,1));
}
}
return(clonestr("{\"result\":\"stub processed generic json\"}"));
}
char *iguana_jsonstr(struct iguana_info *coin,char *jsonstr,char *remoteaddr)
{
cJSON *json; char *retjsonstr,*methodstr,*agentstr;
//printf("iguana_jsonstr.(%s)\n",jsonstr);
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( (methodstr= jstr(json,"method")) != 0 )
{
if ( (agentstr= jstr(json,"agent")) == 0 || strcmp(agentstr,"iguana") == 0 )
retjsonstr = iguana_coinjson(coin,methodstr,json);
else retjsonstr = iguana_agentjson(agentstr,coin,methodstr,json,remoteaddr);
} else retjsonstr = clonestr("{\"error\":\"no method in JSON\"}");
free_json(json);
} else retjsonstr = clonestr("{\"error\":\"cant parse JSON\"}");
printf("iguana_jsonstr.(%s)\n",retjsonstr);
return(retjsonstr);
}
char *iguana_htmlget(char *space,int32_t max,int32_t *jsonflagp,char *path,char *remoteaddr,int32_t localaccess)
{
char *iguana_coinjson(struct iguana_info *coin,char *method,cJSON *json);
struct iguana_info *coin = 0; cJSON *json; bits256 hash2; int32_t height,i;
char buf[64],jsonstr[1024],coinstr[64],*retstr;
for (i=0; path[i]!=0; i++)
if ( path[i] == ' ' )
break;
path[i] = 0;
if ( path[strlen(path)-1] == '/' )
path[strlen(path)-1] = 0;
if ( strncmp(path,"/api",strlen("/api")) == 0 )
{
*jsonflagp = 1;
path += strlen("/api");
} else *jsonflagp = 0;
iguana_coinset(coinstr,path);
if ( coinstr[0] != 0 )
coin = iguana_coinfind(coinstr);
else coin = 0;
if ( strncmp(path,"/bitmap",strlen("/bitmap")) == 0 )
{
path += strlen("/bitmap");
*jsonflagp = 2;
iguana_bitmap(space,max,path);
return(space);
}
//printf("GETCHECK.(%s)\n",path);
if ( strncmp(path,"/ramchain/",strlen("/ramchain/")) == 0 )
{
path += strlen("/ramchain/");
if ( strncmp(path,"block/",strlen("block/")) == 0 )
{
path += strlen("block/");
if ( strncmp(path,"height/",strlen("height/")) == 0 )
{
height = atoi(path + strlen("height/"));
sprintf(Currentjsonstr,"{\"agent\":\"ramchain\",\"method\":\"block\",\"coin\":\"%s\",\"height\":%d,\"txids\":1}",coinstr,height);
return(iguana_ramchain_glue(coin,"block",Currentjsonstr));
}
else if ( strncmp(path,"hash/",strlen("hash/")) == 0 )
{
decode_hex(hash2.bytes,sizeof(hash2),path + strlen("hash/"));
char str[65]; printf("ramchain blockhash.%s\n",bits256_str(str,hash2));
sprintf(Currentjsonstr,"{\"agent\":\"ramchain\",\"method\":\"block\",\"coin\":\"%s\",\"hash\":\"%s\",\"txids\":1}",coinstr,str);
return(iguana_ramchain_glue(coin,"block",Currentjsonstr));
}
}
else if ( strncmp(path,"txid/",strlen("txid/")) == 0 )
{
decode_hex(hash2.bytes,sizeof(hash2),path + strlen("txid/"));
char str[65]; bits256_str(str,hash2);
sprintf(Currentjsonstr,"{\"agent\":\"ramchain\",\"method\":\"tx\",\"coin\":\"%s\",\"txid\":\"%s\"}",coinstr,str);
return(iguana_ramchain_glue(coin,"tx",Currentjsonstr));
}
else if ( strncmp(path,"explore/",strlen("explore/")) == 0 )
{
path += strlen("explore/");
if ( coin != 0 )
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"explore\",\"coin\":\"%s\",\"search\":\"%s\"}",coinstr,path);
} else sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"explore\",\"search\":\"%s\"}",path);
return(iguana_ramchain_glue(coin,"explore",Currentjsonstr));
}
else if ( strncmp(path,"bundleinfo/",strlen("bundleinfo/")) == 0 )
{
path += strlen("bundleinfo/");
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"bundleinfo\",\"coin\":\"%s\",\"height\":%d}",coinstr,atoi(path));
}
else
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"%s\",\"coin\":\"%s\"}",path,coinstr);
return(iguana_ramchain_glue(coin,path,Currentjsonstr));
}
}
else if ( strncmp(path,"/hash/",strlen("/hash/")) == 0 )
{
path += strlen("/hash/");
return(iguana_hashparse(path));
}
else if ( strncmp(path,"/iguana/",strlen("/iguana/")) == 0 )
{
strcpy(Currentjsonstr,path);
path += strlen("/iguana/");
if ( strncmp(path,"setagent/",strlen("setagent/")) == 0 )
{
path += strlen("setagent/");
if ( strncmp(path,"ramchain",strlen("ramchain")) == 0 || strncmp(path,"iguana",strlen("iguana")) == 0 || strncmp(path,"InstantDEX",strlen("InstantDEX")) == 0 || strncmp(path,"pangea",strlen("pangea")) == 0 || strncmp(path,"PAX",strlen("PAX")) == 0 || strncmp(path,"ALL",strlen("ALL")) == 0 || strncmp(path,"jumblr",strlen("jumblr")) == 0 )
{
if ( strncmp(Default_agent,path,strlen(path)) == 0 )
{
strcpy(Default_agent,"ALL");
return(clonestr("{\"result\":\"ALL agents selected\"}"));
}
strcpy(Default_agent,path);
if ( Default_agent[strlen(Default_agent)-1] == '/' )
Default_agent[strlen(Default_agent)-1] = 0;
sprintf(buf,"{\"result\":\"agent selected\",\"name\":\"%s\"}",path);
return(clonestr(buf));
}
return(clonestr("{\"error\":\"invalid agent specified\"}"));
}
else
{
if ( strncmp(path,"peers/",strlen("peers/")) == 0 )
{
path += strlen("peers/");
if ( coin != 0 )
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"peers\",\"coin\":\"%s\"}",coinstr);
} else sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"peers\"}");
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"peers",json);
free_json(json);
return(retstr);
}
else if ( coin != 0 )
{
if ( strncmp(path,"addnode/",strlen("addnode/")) == 0 )
{
path += strlen("addnode/");
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"addnode\",\"coin\":\"%s\",\"ipaddr\":\"%s\"}",coinstr,path);
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"addnode",json);
free_json(json);
return(retstr);
}
else if ( strncmp(path,"nodestatus/",strlen("nodestatus/")) == 0 )
{
path += strlen("nodestatus/");
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"nodestatus\",\"coin\":\"%s\",\"ipaddr\":\"%s\"}",coinstr,path);
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"nodestatus",json);
free_json(json);
return(retstr);
}
else if ( strncmp(path,"addcoin",strlen("addcoin")) == 0 )
{
path += strlen("addcoin");
iguana_coinset(buf,path);
if ( (coin= iguana_coinadd(buf)) != 0 )
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"addcoin\",\"coin\":\"%s\"}",buf);
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"addcoin",json);
free_json(json);
}
else retstr = clonestr("{\"error\":\"cant create coin\"}");
return(retstr);
}
else if ( strncmp(path,"startcoin",strlen("startcoin")) == 0 )
{
path += strlen("startcoin");
iguana_coinset(buf,path);
if ( (coin= iguana_coinfind(buf)) != 0 )
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"startcoin\",\"coin\":\"%s\"}",buf);
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"startcoin",json);
free_json(json);
}
else retstr = clonestr("{\"error\":\"cant create coin\"}");
return(retstr);
}
else if ( strncmp(path,"pausecoin",strlen("pausecoin")) == 0 )
{
path += strlen("pausecoin");
iguana_coinset(buf,path);
if ( (coin= iguana_coinfind(buf)) != 0 )
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"pausecoin\",\"coin\":\"%s\"}",buf);
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"pausecoin",json);
free_json(json);
}
else retstr = clonestr("{\"error\":\"cant create coin\"}");
return(retstr);
}
else if ( strncmp(path,"maxpeers/",strlen("maxpeers/")) == 0 )
{
path += strlen("maxpeers/");
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"maxpeers\",\"coin\":\"%s\",\"max\":%d}",coinstr,atoi(path));
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"maxpeers",json);
free_json(json);
return(retstr);
}
return(clonestr("{\"result\":\"iguana method not found\"}"));
}
return(clonestr("{\"result\":\"iguana method needs coin\"}"));
}
}
else if ( strncmp(path,"/InstantDEX/",strlen("/InstantDEX/")) == 0 )
{
double price,volume; char base[16],rel[16],exchange[16];
path += strlen("/InstantDEX/");
jsonstr[0] = 0;
if ( strncmp(path,"placebid/",strlen("placebid/")) == 0 )
{
path += strlen("placebid/");
if ( iguana_InstantDEX(jsonstr,path,"placebid") == 0 )
return(clonestr("{\"error\":\"error with placebid parameters\"}"));
}
else if ( strncmp(path,"placeask/",strlen("placeask/")) == 0 )
{
path += strlen("placeask/");
if ( iguana_InstantDEX(jsonstr,path,"placeask") == 0 )
return(clonestr("{\"error\":\"error with placeask parameters\"}"));
}
else if ( strncmp(path,"orderbook/",strlen("orderbook/")) == 0 )
{
path += strlen("orderbook/");
iguana_parsebidask(base,rel,exchange,&price,&volume,path);
if ( exchange[0] == 0 )
strcpy(exchange,"active");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"orderbook\",\"base\":\"%s\",\"rel\":\"%s\",\"exchange\":\"%s\",\"allfields\":1}",base,rel,exchange);
}
else if ( strncmp(path,"orderstatus/",strlen("orderstatus/")) == 0 )
{
path += strlen("orderstatus/");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"orderstatus\",\"orderid\":\"%s\"}",path);
}
else if ( strncmp(path,"cancelorder/",strlen("cancelorder/")) == 0 )
{
path += strlen("cancelorder/");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"cancelorder\",\"orderid\":\"%s\"}",path);
}
else if ( strncmp(path,"balance/",strlen("balance/")) == 0 )
{
path += strlen("balance/");
iguana_parsebidask(base,rel,exchange,&price,&volume,path);
if ( path[0] != ' ' && path[0] != '/' )
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"balance\",\"exchange\":\"%s\"}",path);
else sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"balance\"}");
}
else if ( strncmp(path,"openorders",strlen("openorders")) == 0 )
{
path += strlen("openorders");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"openorders\"}");
}
else if ( strncmp(path,"tradehistory",strlen("tradehistory")) == 0 )
{
path += strlen("tradehistory");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"tradehistory\"}");
}
else if ( strncmp(path,"allorderbooks",strlen("allorderbooks")) == 0 )
{
path += strlen("allorderbooks");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"allorderbooks\"}");
}
else if ( strncmp(path,"allexchanges",strlen("allexchanges")) == 0 )
{
path += strlen("allexchanges");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"allexchanges\"}");
}
if ( jsonstr[0] != 0 )
{
strcpy(Currentjsonstr,jsonstr);
return(clonestr(jsonstr));
//return(InstantDEX(jsonstr,remoteaddr,localaccess));
}
return(clonestr("{\"error\":\"unrecognized InstantDEX API call\"}"));
}
else if ( strncmp(path,"/pangea/",strlen("/pangea/")) == 0 )
{
path += strlen("/pangea/");
}
else if ( strncmp(path,"/jumblr/",strlen("/jumblr/")) == 0 )
{
path += strlen("/jumblr/");
}
else printf("no match to (%s)\n",path);
return(0);
}
char *iguana_rpcparse(char *retbuf,int32_t bufsize,int32_t *postflagp,char *jsonstr)
{
cJSON *json = 0; int32_t i,n,localaccess,datalen,postflag = 0;
char *key,*reststr,*str,*retstr,remoteaddr[65],porturl[65],*data = 0,*value,*agent = "SuperNET";
//printf("rpcparse.(%s)\n",jsonstr);
localaccess = 1;
if ( (str= strstr("Referer: ",jsonstr)) != 0 )
{
for (i=0; str[i]!=' '&&str[i]!=0&&str[i]!='\n'&&str[i]!='\r'; i++)
remoteaddr[i] = str[i];
remoteaddr[i] = 0;
} else strcpy(remoteaddr,"127.0.0.1"); // need to verify this
*postflagp = 0;
if ( strncmp("POST",jsonstr,4) == 0 )
jsonstr += 6, *postflagp = postflag = 1;
else if ( strncmp("GET",jsonstr,3) == 0 )
{
jsonstr += 4;
str = 0;
sprintf(porturl,"Referer: http://127.0.0.1:%u",IGUANA_RPCPORT);
if ( (str= iguana_htmlget(retbuf,bufsize,postflagp,jsonstr,remoteaddr,localaccess)) == 0 && (reststr= strstr(jsonstr,porturl)) != 0 )
{
reststr += strlen(porturl);
str = iguana_htmlget(retbuf,bufsize,postflagp,reststr,remoteaddr,localaccess);
}
if ( str != 0 )
{
if ( *postflagp == 0 )
{
json = cJSON_CreateObject();
jaddstr(json,"result",str);
if ( str != retbuf )
free(str);
str = cJSON_Print(json);
free_json(json);
}
return(str);
}
jsonstr++;
}
else return(0);
n = (int32_t)strlen(jsonstr);
for (i=0; i<n; i++)
if ( jsonstr[i] == '?' )
break;
if ( i == n )
{
//printf("no url\n");
return(0);
}
if ( i > 0 )
{
jsonstr[i] = 0;
agent = jsonstr;
jsonstr += i;
}
jsonstr++;
json = cJSON_CreateObject();
jaddstr(json,"agent",agent);
while ( 1 )
{
n = (int32_t)strlen(jsonstr);
key = jsonstr;
value = 0;
for (i=0; i<n; i++)
{
if ( jsonstr[i] == ' ' || jsonstr[i] == '&' )
break;
else if ( jsonstr[i] == '=' )
{
if ( value != 0 )
{
printf("parse error.(%s)\n",jsonstr);
free_json(json);
return(0);
}
jsonstr[i] = 0;
value = &jsonstr[++i];
}
}
if ( value == 0 )
value = "";
jsonstr += i;
if ( jsonstr[0] == ' ' )
{
jsonstr[0] = 0;
jsonstr++;
if ( key != 0 && key[0] != 0 )
jaddstr(json,key,value);
//printf("{%s:%s}\n",key,value);
break;
}
jsonstr[0] = 0;
jsonstr++;
if ( key != 0 && key[0] != 0 )
jaddstr(json,key,value);
//printf("{%s:%s}\n",key,value);
if ( i == 0 )
break;
}
n = (int32_t)strlen(jsonstr);
datalen = 0;
if ( postflag != 0 )
{
for (i=0; i<n; i++)
{
//printf("(%d) ",jsonstr[i]);
if ( jsonstr[i] == '\n' || jsonstr[i] == '\r' )
{
//printf("[%s] cmp.%d\n",jsonstr+i+1,strncmp(jsonstr+i+1,"Content-Length:",strlen("Content-Length:")));
if ( strncmp(jsonstr+i+1,"Content-Length:",strlen("Content-Length:")) == 0 )
{
datalen = (int32_t)atoi(jsonstr + i + 1 + strlen("Content-Length:") + 1);
data = &jsonstr[n - datalen];
//printf("post.(%s) (%c)\n",data,data[0]);
//iguana_urldecode(data);
}
}
}
}
retstr = iguana_rpc(agent,json,data,datalen,remoteaddr);
free_json(json);
return(retstr);
//printf("post.%d json.(%s) data[%d] %s\n",postflag,jprint(json,0),datalen,data!=0?data:"");
//return(json);
}
char *iguana_rpc(char *agent,cJSON *json,char *data,int32_t datalen,char *remoteaddr)
{
//printf("agent.(%s) json.(%s) data[%d] %s\n",agent,jprint(json,0),datalen,data!=0?data:"");
if ( data == 0 )
return(iguana_JSON(0,jprint(json,0),remoteaddr));
else return(iguana_JSON(0,data,remoteaddr));
}
void iguana_urldecode(char *str)
{
int32_t a,b,c; char *dest = str;
while ( (c= *str) != 0 )
{
if ( c == '%' && (a= str[1]) != 0 && (b= str[2]) != 0 )
*dest++ = (unhex(a)<<4) | unhex(b);
else *dest++ = c;
}
*dest = 0;
}
char *iguana_parsebidask(char *base,char *rel,char *exchange,double *pricep,double *volumep,char *line)
{
int32_t i;
for (i=0; i<16&&line[i]!='/'&&line[i]!=0; i++)
base[i] = line[i];
base[i] = 0;
touppercase(base);
line += (i + 1);
for (i=0; i<16&&line[i]!='/'&&line[i]!=0; i++)
rel[i] = line[i];
rel[i] = 0;
touppercase(rel);
line += (i + 1);
for (i=0; i<16&&line[i]!='/'&&line[i]!=0; i++)
exchange[i] = line[i];
exchange[i] = 0;
line += (i + 1);
if ( strncmp(line,"price/",strlen("price/")) == 0 )
{
line += strlen("price/");
*pricep = atof(line);
if ( (line= strstr(line,"volume/")) != 0 )
{
line += strlen("volume/");
*volumep = atof(line);
for (i=0; i<16&&line[i]!=0; i++)
if ( line[i] == '/' )
{
i++;
break;
}
return(line+i);
}
}
return(0);
}
char *iguana_InstantDEX(char *jsonstr,char *path,char *method)
{
char *str,base[64],rel[64],exchange[64]; double price,volume;
if ( (str= iguana_parsebidask(base,rel,exchange,&price,&volume,path)) != 0 )
{
if ( price > 0. && volume > 0. )
{
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"%s\",\"base\":\"%s\",\"rel\":\"%s\",\"exchange\":\"%s\",\"price\":\%0.8f,\"volume\":%0.8f}",method,base,rel,exchange,price,volume);
return(jsonstr);
}
else return(0);
}
return(0);
}
void iguana_coinset(char *buf,char *path)
{
int32_t i;
if ( path[0] == '/' )
path++;
for (i=0; i<8&&path[i]!=0&&path[i]!=' '&&path[i]!='/'; i++)
buf[i] = path[i];
buf[i] = 0;
touppercase(buf);
}
char *iguana_ramchain_glue(struct iguana_info *coin,char *method,char *jsonstr)
{
cJSON *json; char *retstr;
json = cJSON_Parse(jsonstr);
retstr = ramchain_parser(0,method,json);
free_json(json);
return(retstr);
}
#endif

13
iguana/Makefile

@ -10,14 +10,11 @@ VALID_TOOLCHAINS := pnacl newlib glibc clang-newlib mac
NACL_SDK_ROOT ?= $(abspath $(CURDIR))
TARGET = iguana
TARGETI = InstantDEX
TARGETP = pangea
TARGETX = PAX
EXTRA= -D__PNACL
include $(NACL_SDK_ROOT)/tools/common.mk
include iguana.sources
CHROME_ARGS += --allow-nacl-socket-api=127.0.0.1
DEPS = nacl_io
@ -26,14 +23,6 @@ LIBS = crypto777 curl ssl crypto z glibc-compat nacl_spawn ppapi nacl_io ppapi_
CFLAGS = -Wall -D__PNACL -fno-strict-aliasing $(EXTRA)
LFLAGS = libs
SOURCES = main.c iguana777.c iguana_wallet.c iguana_init.c iguana_json.c iguana_recv.c iguana_chains.c iguana_ramchain.c iguana_bitmap.c iguana_rpc.c iguana_bundles.c iguana_pubkeys.c iguana_msg.c iguana_html.c iguana_blocks.c iguana_peers.c
SOURCESI = InstantDEX/main.c InstantDEX/InstantDEX_main.c InstantDEX/prices777.c
SOURCESP = pangea/main.c pangea/cards777.c pangea/pangea777.c pangea/pangeafunds.c pangea/poker.c pangea/tourney777.c
SOURCESX = peggy/main.c peggy/peggy777.c peggy/peggytx.c peggy/txidind777.c peggy/opreturn777.c quotes777.c
# Build rules generated by macros from common.mk:
$(foreach dep,$(DEPS),$(eval $(call DEPEND_RULE,$(dep))))

507
iguana/SuperNET.c

@ -0,0 +1,507 @@
/******************************************************************************
* 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 "../crypto777/OS_portable.h"
#include "SuperNET.h"
void SuperNET_rpcloop(void *args)
{
struct supernet_info *myinfo = args;
int32_t recvlen,bindsock,postflag,sock,remains,jsonflag,numsent,len; socklen_t clilen;
char remoteaddr[64],jsonbuf[8192],*buf,*retstr,*space;//,*retbuf; ,n,i,m
struct sockaddr_in cli_addr; uint32_t ipbits,i; uint16_t port;
int32_t size = 1024 * 1024 * 2;
port = SUPERNET_PORT;
bindsock = iguana_socket(1,"127.0.0.1",port);
printf("SuperNET_rpcloop 127.0.0.1:%d bind sock.%d\n",port,bindsock);
space = calloc(1,size);
while ( bindsock >= 0 )
{
clilen = sizeof(cli_addr);
//printf("ACCEPT (%s:%d) on sock.%d\n","127.0.0.1",port,bindsock);
sock = accept(bindsock,(struct sockaddr *)&cli_addr,&clilen);
if ( sock < 0 )
{
//printf("iguana_rpcloop ERROR on accept usock.%d\n",sock);
continue;
}
memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits));
expand_ipbits(remoteaddr,ipbits);
memset(jsonbuf,0,sizeof(jsonbuf));
remains = (int32_t)(sizeof(jsonbuf) - 1);
buf = jsonbuf;
recvlen = 0;
retstr = 0;
while ( remains > 0 )
{
if ( (len= (int32_t)recv(sock,buf,remains,0)) < 0 )
{
if ( errno == EAGAIN )
{
printf("EAGAIN for len %d, remains.%d\n",len,remains);
usleep(10000);
}
break;
}
else
{
if ( len > 0 )
{
remains -= len;
recvlen += len;
buf = &buf[len];
retstr = SuperNET_rpcparse(myinfo,space,size,&jsonflag,&postflag,jsonbuf,remoteaddr);
break;
} else usleep(10000);
}
}
if ( retstr != 0 )
{
i = 0;
if ( postflag == 0 && jsonflag == 0 )
retstr = SuperNET_htmlresponse(space,size,&remains,1,retstr,1);
else remains = (int32_t)strlen(retstr);
printf("RETBUF.(%s)\n",retstr);
while ( remains > 0 )
{
if ( (numsent= (int32_t)send(sock,&retstr[i],remains,MSG_NOSIGNAL)) < 0 )
{
if ( errno != EAGAIN && errno != EWOULDBLOCK )
{
//printf("%s: %s numsent.%d vs remains.%d len.%d errno.%d (%s) usock.%d\n",retstr,ipaddr,numsent,remains,recvlen,errno,strerror(errno),sock);
break;
}
}
else if ( remains > 0 )
{
remains -= numsent;
i += numsent;
if ( remains > 0 )
printf("iguana sent.%d remains.%d of len.%d\n",numsent,remains,recvlen);
}
}
if ( retstr != space )
free(retstr);
}
//printf("done response sock.%d\n",sock);
closesocket(sock);
}
}
/*
struct endpoint find_epbits(struct relay_info *list,uint32_t ipbits,uint16_t port,int32_t type)
{
int32_t i; struct endpoint epbits;
memset(&epbits,0,sizeof(epbits));
if ( list != 0 && list->num > 0 )
{
if ( type >= 0 )
type = nn_portoffset(type);
for (i=0; i<list->num&&i<(int32_t)(sizeof(list->connections)/sizeof(*list->connections)); i++)
if ( list->connections[i].ipbits == ipbits && (port == 0 || port == list->connections[i].port) && (type < 0 || type == list->connections[i].nn) )
return(list->connections[i]);
}
return(epbits);
}
int32_t add_relay(struct relay_info *list,struct endpoint epbits)
{
list->connections[list->num % (sizeof(list->connections)/sizeof(*list->connections))] = epbits, list->num++;
if ( list->num > (sizeof(list->connections)/sizeof(*list->connections)) )
printf("add_relay warning num.%d > %ld\n",list->num,(long)(sizeof(list->connections)/sizeof(*list->connections)));
return(list->num);
}
int32_t nn_add_lbservers(struct supernet_info *myinfo,uint16_t port,uint16_t globalport,uint16_t relaysport,int32_t priority,int32_t sock,char servers[][MAX_SERVERNAME],int32_t num)
{
int32_t i; char endpoint[512],pubendpoint[512]; struct endpoint epbits; uint32_t ipbits;
if ( num > 0 && servers != 0 && nn_setsockopt(sock,NN_SOL_SOCKET,NN_SNDPRIO,&priority,sizeof(priority)) >= 0 )
{
for (i=0; i<num; i++)
{
if ( (ipbits= (uint32_t)calc_ipbits(servers[i])) == 0 )
{
printf("null ipbits.(%s)\n",servers[i]);
continue;
}
//printf("epbits.%llx ipbits.%x %s\n",*(long long *)&epbits,(uint32_t)ipbits,endpoint);
if ( ismyaddress(servers[i],myinfo) == 0 )
{
epbits = calc_epbits("tcp",ipbits,port,NN_REP);
expand_epbits(endpoint,epbits);
if ( nn_connect(sock,endpoint) >= 0 )
{
printf("+R%s ",endpoint);
add_relay(&myinfo->active,epbits);
}
if ( myinfo->subclient >= 0 )
{
if ( myinfo->iamrelay != 0 )
{
epbits = calc_epbits("tcp",ipbits,relaysport,NN_PUB);
expand_epbits(pubendpoint,epbits);
if ( nn_connect(myinfo->subclient,pubendpoint) >= 0 )
printf("+P%s ",pubendpoint);
}
epbits = calc_epbits("tcp",ipbits,globalport,NN_PUB);
expand_epbits(pubendpoint,epbits);
if ( nn_connect(myinfo->subclient,pubendpoint) >= 0 )
printf("+P%s ",pubendpoint);
}
}
}
printf("added priority.%d\n",priority);
priority++;
} else printf("error setting priority.%d (%s)\n",priority,nn_errstr());
return(priority);
}
int32_t _lb_socket(struct supernet_info *myinfo,uint16_t port,uint16_t globalport,uint16_t relaysport,int32_t maxmillis,char servers[][MAX_SERVERNAME],int32_t num,char backups[][MAX_SERVERNAME],int32_t numbacks,char failsafes[][MAX_SERVERNAME],int32_t numfailsafes)
{
int32_t lbsock,timeout,retrymillis,priority = 1;
if ( (lbsock= nn_socket(AF_SP,NN_REQ)) >= 0 )
{
retrymillis = (maxmillis / 30) + 1;
printf("!!!!!!!!!!!! lbsock.%d !!!!!!!!!!!\n",lbsock);
if ( nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_RECONNECT_IVL,&retrymillis,sizeof(retrymillis)) < 0 )
printf("error setting NN_REQ NN_RECONNECT_IVL_MAX socket %s\n",nn_errstr());
else if ( nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_RECONNECT_IVL_MAX,&maxmillis,sizeof(maxmillis)) < 0 )
fprintf(stderr,"error setting NN_REQ NN_RECONNECT_IVL_MAX socket %s\n",nn_errstr());
timeout = SUPERNET_NETWORKTIMEOUT;
if ( 1 && nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout)) < 0 )
printf("error setting NN_SOL_SOCKET NN_RCVTIMEO socket %s\n",nn_errstr());
timeout = 100;
if ( 1 && nn_setsockopt(lbsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout)) < 0 )
printf("error setting NN_SOL_SOCKET NN_SNDTIMEO socket %s\n",nn_errstr());
if ( num > 0 )
priority = nn_add_lbservers(myinfo,port,globalport,relaysport,priority,lbsock,servers,num);
if ( numbacks > 0 )
priority = nn_add_lbservers(myinfo,port,globalport,relaysport,priority,lbsock,backups,numbacks);
if ( numfailsafes > 0 )
priority = nn_add_lbservers(myinfo,port,globalport,relaysport,priority,lbsock,failsafes,numfailsafes);
} else printf("error getting req socket %s\n",nn_errstr());
//printf("myinfo->lb.num %d\n",myinfo->lb.num);
return(lbsock);
}
int32_t nn_lbsocket(struct supernet_info *myinfo,int32_t maxmillis,int32_t port,uint16_t globalport,uint16_t relaysport)
{
char Cservers[32][MAX_SERVERNAME],Bservers[32][MAX_SERVERNAME],failsafes[4][MAX_SERVERNAME];
int32_t n,m,lbsock,numfailsafes = 0;
printf("redo lbsocket()\n"), exit(-1);
//strcpy(failsafes[numfailsafes++],"5.9.56.103");
//strcpy(failsafes[numfailsafes++],"5.9.102.210");
// n = crackfoo_servers(Cservers,sizeof(Cservers)/sizeof(*Cservers),port);
// m = badass_servers(Bservers,sizeof(Bservers)/sizeof(*Bservers),port);
lbsock = _lb_socket(myinfo,port,globalport,relaysport,maxmillis,Bservers,m,Cservers,n*0,failsafes,numfailsafes);
return(lbsock);
}
void add_standard_fields(char *request)
{
cJSON *json; uint64_t tag;
if ( (json= cJSON_Parse(request)) != 0 )
{
if ( get_API_nxt64bits(cJSON_GetObjectItem(json,"NXT")) == 0 )
{
randombytes((void *)&tag,sizeof(tag));
sprintf(request + strlen(request) - 1,",\"NXT\":\"%s\",\"tag\":\"%llu\"}",myinfo->NXTADDR,(long long)tag);
if ( myinfo->iamrelay != 0 && (myinfo->hostname[0] != 0 || myinfo->ipaddr[0] != 0) )
sprintf(request + strlen(request) - 1,",\"iamrelay\":\"%s\"}",myinfo->hostname[0]!=0?myinfo->hostname:myinfo->myipaddr);
}
free_json(json);
}
}
char *nn_loadbalanced(struct supernet_info *myinfo,uint8_t *data,int32_t len)
{
char *msg,*jsonstr = 0;
int32_t sendlen,i,lbsock,recvlen = 0;
if ( (lbsock= myinfo->lbclient) < 0 )
return(clonestr("{\"error\":\"invalid load balanced socket\"}"));
for (i=0; i<10; i++)
if ( (nn_socket_status(lbsock,1) & NN_POLLOUT) != 0 )
break;
if ( myinfo->Debuglevel > 2 )
printf("sock.%d NN_LBSEND.(%s)\n",lbsock,data);
//fprintf(stderr,"send to network\n");
if ( (sendlen= nn_send(lbsock,data,len,0)) == len )
{
for (i=0; i<10; i++)
if ( (nn_socket_status(lbsock,1) & NN_POLLIN) != 0 )
break;
if ( (recvlen= nn_recv(lbsock,&msg,NN_MSG,0)) > 0 )
{
if ( myinfo->Debuglevel > 2 )
printf("LBRECV.(%s)\n",msg);
jsonstr = clonestr((char *)msg);
nn_freemsg(msg);
}
else
{
printf("nn_loadbalanced got recvlen.%d %s\n",recvlen,nn_errstr());
jsonstr = clonestr("{\"error\":\"lb recv error, probably timeout\"}");
}
} else printf("got sendlen.%d instead of %d %s\n",sendlen,len,nn_errstr()), jsonstr = clonestr("{\"error\":\"lb send error\"}");
return(jsonstr);
}
cJSON *relay_json(struct relay_info *list)
{
cJSON *json,*array; char endpoint[512]; int32_t i;
if ( list == 0 || list->num == 0 )
return(0);
array = cJSON_CreateArray();
for (i=0; i<list->num&&i<(int32_t)(sizeof(list->connections)/sizeof(*list->connections)); i++)
{
expand_epbits(endpoint,list->connections[i]);
jaddistr(array,endpoint);
}
json = cJSON_CreateObject();
jadd(json,"endpoints",array);
//cJSON_AddItemToObject(json,"type",cJSON_CreateString(nn_typestr(list->mytype)));
//cJSON_AddItemToObject(json,"dest",cJSON_CreateString(nn_typestr(list->desttype)));
jaddnum(json,"total",list->num);
return(json);
}
char *relays_jsonstr(struct supernet_info *myinfo,char *jsonstr,cJSON *argjson)
{
cJSON *json;
if ( myinfo->iamrelay != 0 && myinfo->ipaddr[0] != 0 )
{
json = cJSON_CreateObject();
jaddstr(json,"relay",myinfo->ipaddr);
if ( myinfo->active.num > 0 )
jadd(json,"relays",relay_json(&myinfo->active));
return(jprint(json,1));
}
else return(clonestr("{\"error\":\"get relay list from relay\"}"));
}
int32_t init_SUPERNET_pullsock(struct supernet_info *myinfo,int32_t sendtimeout,int32_t recvtimeout)
{
char bindaddr[64],*transportstr; int32_t iter;
myinfo->pullsock = -1;
if ( (myinfo->pullsock= nn_socket(AF_SP,NN_PULL)) < 0 )
{
printf("error creating pullsock %s\n",nn_strerror(nn_errno()));
return(-1);
}
printf("got pullsock.%d\n",myinfo->pullsock);
if ( nn_settimeouts(myinfo->pullsock,sendtimeout,recvtimeout) < 0 )
{
printf("error settime pullsock timeouts %s\n",nn_strerror(nn_errno()));
return(-1);
}
printf("PULLsock.%d\n",myinfo->pullsock);
for (iter=0; iter<2; iter++)
{
transportstr = (iter == 0) ? "ipc" : "inproc";
sprintf(bindaddr,"%s://SuperNET.agents",transportstr);
if ( nn_bind(myinfo->pullsock,bindaddr) < 0 )
{
printf("error binding pullsock to (%s) %s\n",bindaddr,nn_strerror(nn_errno()));
return(-1);
}
}
return(0);
}
void busdata_init(struct supernet_info *myinfo,int32_t sendtimeout,int32_t recvtimeout,int32_t firstiter)
{
char endpoint[512]; int32_t i;
myinfo->servicesock = myinfo->pubglobal = myinfo->pubrelays = myinfo->lbserver = -1;
endpoint[0] = 0;
if ( (myinfo->subclient= nn_createsocket(myinfo,endpoint,0,"NN_SUB",NN_SUB,0,sendtimeout,recvtimeout)) >= 0 )
{
myinfo->pfd[myinfo->numservers++].fd = myinfo->subclient, printf("numservers.%d\n",myinfo->numservers);
nn_setsockopt(myinfo->subclient,NN_SUB,NN_SUB_SUBSCRIBE,"",0);
} else printf("error creating subclient\n");
myinfo->lbclient = nn_lbsocket(myinfo,SUPERNET_NETWORKTIMEOUT,SUPERNET_PORT + LB_OFFSET,myinfo->port + PUBGLOBALS_OFFSET,myinfo->port + PUBRELAYS_OFFSET);
printf("LBclient.%d port.%d\n",myinfo->lbclient,SUPERNET_PORT + LB_OFFSET);
sprintf(endpoint,"%s://%s:%u",myinfo->transport,myinfo->ipaddr,myinfo->serviceport);
if ( (myinfo->servicesock= nn_createsocket(myinfo,endpoint,1,"NN_REP",NN_REP,myinfo->serviceport,sendtimeout,recvtimeout)) >= 0 )
myinfo->pfd[myinfo->numservers++].fd = myinfo->servicesock, printf("numservers.%d\n",myinfo->numservers);
else printf("error creating servicesock\n");
for (i=0; i<myinfo->numservers; i++)
myinfo->pfd[i].events = NN_POLLIN | NN_POLLOUT;
printf("myinfo->iamrelay %d, numservers.%d ipaddr.(%s://%s) port.%d serviceport.%d\n",myinfo->iamrelay,myinfo->numservers,myinfo->transport,myinfo->ipaddr,myinfo->port,myinfo->serviceport);
}
void SuperNET_init(struct supernet_info *myinfo,char *jsonstr)
{
char *str;
if ( jsonstr != 0 && (str= SuperNET_JSON(myinfo,jsonstr)) != 0 )
free(str);
busdata_init(myinfo,10,1,0);
init_SUPERNET_pullsock(myinfo,10,10);
}*/
int32_t Supernet_lineparse(char *key,int32_t keymax,char *value,int32_t valuemax,char *src)
{
int32_t a,b,c,n = 0;
key[0] = value[0] = 0;
while ( (c= src[n]) == ' ' || c == '\t' || c == '\n' || c == '\t' )
n++;
while ( (c= src[n]) != ':' && c != 0 )
{
*key++ = c;
if ( ++n >= keymax-1 )
{
*key = 0;
printf("lineparse overflow key.(%s)\n",src);
return(-1);
}
}
*key = 0;
if ( src[n] != ':' )
return(n);
n++;
while ( (c= src[n]) == ' ' || c == '\t' )
n++;
while ( (c= src[n]) != 0 && c != '\r' && c != '\n' )
{
if ( c == '%' && (a= src[n+1]) != 0 && (b= src[n+2]) != 0 )
c = ((unhex(a) << 4) | unhex(b)), n += 2;
*value++ = c;
n++;
if ( n >= valuemax-1 )
{
*value = 0;
printf("lineparse overflow.(%s)\n",src);
return(-1);
}
}
*value = 0;
if ( src[n] != 0 )
{
n++;
while ( (c= src[n]) == '\r' || c == '\n' )
n++;
}
return(n);
}
cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr)
{
int32_t i,n,totallen,datalen,len = 0; cJSON *json,*array; char key[8192],*data;
json = cJSON_CreateObject();
array = cJSON_CreateArray();
totallen = (int32_t)strlen(urlstr);
while ( 1 )
{
for (i=len; urlstr[i]!=0; i++)
if ( urlstr[i] == '\r' || urlstr[i] == '\n' )
break;
if ( i == len && (urlstr[len] == '\r' || urlstr[len] == '\n') )
{
len++;
continue;
}
urlstr[i] = 0;
if ( (n= Supernet_lineparse(key,sizeof(key),value,bufsize,&urlstr[len])) > 0 )
{
if ( value[0] != 0 )
jaddstr(json,key,value);
else jaddistr(array,key);
len += (n + 1);
if ( strcmp(key,"Content-Length") == 0 && (datalen= atoi(value)) > 0 )
{
data = &urlstr[totallen - datalen];
data[-1] = 0;
//printf("post.(%s) (%c)\n",data,data[0]);
jaddstr(json,"POST",data);
}
} else break;
}
jadd(json,"lines",array);
return(json);
}
char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr)
{
cJSON *tokens,*argjson,*json = 0; char urlmethod[16],*data,url[1024],*retstr,*token = 0; int32_t i,j,n;
//printf("rpcparse.(%s)\n",urlstr);
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
urlmethod[i] = urlstr[i];
urlmethod[i++] = 0;
n = i;
//printf("URLMETHOD.(%s)\n",urlmethod);
*postflagp = (strcmp(urlmethod,"POST") == 0);
for (i=0; i<sizeof(url)-1&&urlstr[n+i]!=0&&urlstr[n+i]!=' '; i++)
url[i] = urlstr[n+i];
url[i++] = 0;
n += i;
//printf("URL.(%s)\n",url);
tokens = cJSON_CreateArray();
j = i = 0;
if ( strncmp(&url[i],"/api",strlen("/url")) == 0 )
{
*jsonflagp = 1;
i += strlen("/api");
} else *jsonflagp = 0;
if ( strncmp(&url[i],"/bitmap",strlen("/bitmap")) == 0 )
{
i += strlen("/bitmap");
*jsonflagp = 2;
iguana_bitmap(retbuf,bufsize,&url[i]);
return(retbuf);
}
if ( url[i] != '/' )
token = url;
for (; url[i]!=0; i++)
{
if ( url[i] == '/' )
{
url[i] = 0;
if ( token != 0 )
jaddistr(tokens,token);
token = &url[i+1];
continue;
}
}
if ( token != 0 )
jaddistr(tokens,token);
if ( (json= SuperNET_urlconv(retbuf,bufsize,urlstr+n)) != 0 )
{
jadd(json,"tokens",tokens);
jaddstr(json,"urlmethod",urlmethod);
if ( (data= jstr(json,"POST")) == 0 || (argjson= cJSON_Parse(data)) == 0 )
{
argjson = cJSON_CreateObject();
if ( (n= cJSON_GetArraySize(tokens)) > 0 )
{
jaddstr(argjson,"agent",jstri(tokens,0));
if ( n > 1 )
jaddstr(argjson,"method",jstri(tokens,1));
for (i=2; i<n; i++)
{
if ( i == n-1 )
jaddstr(argjson,"data",jstri(tokens,i));
else
{
jaddstr(argjson,jstri(tokens,i),jstri(tokens,i+1));
i++;
}
}
}
}
retstr = SuperNET_JSON(myinfo,argjson,remoteaddr);
printf("(%s) -> (%s) postflag.%d (%s)\n",urlstr,cJSON_Print(json),*postflagp,jprint(argjson,0));
return(retstr);
}
return(clonestr("{\"error\":\"couldnt process packet\"}"));
}

91
iguana/SuperNET.h

@ -0,0 +1,91 @@
/******************************************************************************
* 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. *
* *
******************************************************************************/
#ifndef INCLUDED_SUPERNET_H
#define INCLUDED_SUPERNET_H
#include "../crypto777/OS_portable.h"
#include "../includes/cJSON.h"
#include "../includes/nanomsg/nn.h"
#define SUPERNET_PORT 7778
#define SUPERNET_NETWORKTIMEOUT 10000
#define SUPERNET_POLLTIMEOUT 1
#define SUPERNET_APIUSLEEP (SUPERNET_POLLTIMEOUT * 10000)
#define SUPERNET_MAXAGENTS 64
#define NXT_TOKEN_LEN 160
#define nn_errstr() nn_strerror(nn_errno())
/*#define LB_OFFSET 1
#define PUBGLOBALS_OFFSET 2
#define PUBRELAYS_OFFSET 3
#define MAX_SERVERNAME 128
struct relayargs
{
char name[16],endpoint[MAX_SERVERNAME];
int32_t sock,type,bindflag,sendtimeout,recvtimeout;
};
struct relay_info { int32_t sock,num,mytype,desttype; struct endpoint connections[1 << CONNECTION_NUMBITS]; };*/
#define CONNECTION_NUMBITS 10
struct endpoint { queue_t nnrecvQ; int32_t nnsock,nnind; uint64_t ipbits:32,port:16,transport:2,nn:4,directind:CONNECTION_NUMBITS; };
struct direct_connection { char handler[16]; struct endpoint epbits; int32_t sock; };
struct supernet_msghdr { uint8_t type,serlen[3]; char command[16]; uint8_t hdrdata[44]; uint8_t data[]; };
struct supernet_agent
{
struct queueitem DL; queue_t recvQ; uint64_t totalrecv,totalsent;
int32_t (*recvfunc)(void *myinfo,struct supernet_agent *,struct supernet_msghdr *msg,uint8_t *data,int32_t datalen);
cJSON *networks;
char name[9],ipaddr[64],reppoint[64],pubpoint[64]; int32_t reqsock,repsock,pubsock,subsock;
uint32_t ipbits,dead; int32_t num,sock; uint16_t port,pubport,repport;
};
struct supernet_info
{
char ipaddr[64],transport[8]; int32_t APISLEEP; int32_t iamrelay; uint64_t my64bits; uint64_t ipbits;
int32_t Debuglevel,readyflag,dead,POLLTIMEOUT;
//int32_t pullsock,subclient,lbclient,lbserver,servicesock,pubglobal,pubrelays,numservers;
bits256 privkey,pubkey;
uint16_t port,serviceport,acceptport;
struct nn_pollfd pfd[SUPERNET_MAXAGENTS]; //struct relay_info active;
struct supernet_agent agents[SUPERNET_MAXAGENTS]; queue_t acceptQ; int32_t numagents;
};
struct supernet_endpoint
{
char name[64]; struct endpoint ep;
int32_t (*nnrecvfunc)(struct supernet_info *,struct supernet_endpoint *,int32_t ind,uint8_t *msg,int32_t nnlen);
queue_t nnrecvQ;
int32_t nnsock,num; struct endpoint eps[];
};
void expand_epbits(char *endpoint,struct endpoint epbits);
struct endpoint calc_epbits(char *transport,uint32_t ipbits,uint16_t port,int32_t type);
void SuperNET_init();
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);
#endif

10
iguana/iguana.sources

@ -1,9 +1 @@
SOURCES := iguana_wallet.c iguana_pubkeys.c iguana_recv.c iguana_bundles.c iguana_msg.c iguana_rpc.c iguana777.c iguana_chains.c iguana_peers.c iguana_accept.c iguana_html.c iguana_bitmap.c iguana_init.c iguana_ramchain.c iguana_blocks.c iguana_json.c ../crypto777/cJSON.c ../crypto777/iguana_utils.c ../crypto777/OS_nonportable.c ../crypto777/curve25519-donna.c ../crypto777/inet.c ../crypto777/OS_portable.c ../crypto777/curve25519.c ../crypto777/libgfshare.c ../crypto777/OS_time.c ../crypto777/hmac_sha512.c ../crypto777/ramcoder.c ../crypto777/SaM.c ../crypto777/iguana_OS.c ../crypto777/iguana_serdes.c ../crypto777/jpeg/jaricom.c ../crypto777/jpeg/jcapimin.c ../crypto777/jpeg/jcapistd.c ../crypto777/jpeg/jcarith.c ../crypto777/jpeg/jccoefct.c ../crypto777/jpeg/jccolor.c \
../crypto777/jpeg/jcdctmgr.c ../crypto777/jpeg/jchuff.c ../crypto777/jpeg/jcinit.c ../crypto777/jpeg/jcmainct.c ../crypto777/jpeg/jcmarker.c ../crypto777/jpeg/jcmaster.c \
../crypto777/jpeg/jcomapi.c ../crypto777/jpeg/jcparam.c ../crypto777/jpeg/jcprepct.c ../crypto777/jpeg/jcsample.c ../crypto777/jpeg/jctrans.c ../crypto777/jpeg/jdapimin.c \
../crypto777/jpeg/jdapistd.c ../crypto777/jpeg/jdarith.c ../crypto777/jpeg/jdatadst.c ../crypto777/jpeg/jdatasrc.c ../crypto777/jpeg/jdcoefct.c ../crypto777/jpeg/jdcolor.c \
../crypto777/jpeg/jddctmgr.c ../crypto777/jpeg/jdhuff.c ../crypto777/jpeg/jdinput.c ../crypto777/jpeg/jdmainct.c ../crypto777/jpeg/jdmarker.c ../crypto777/jpeg/jdmaster.c \
../crypto777/jpeg/jdmerge.c ../crypto777/jpeg/jdpostct.c ../crypto777/jpeg/jdsample.c ../crypto777/jpeg/jdtrans.c ../crypto777/jpeg/jerror.c ../crypto777/jpeg/jfdctflt.c \
../crypto777/jpeg/jfdctfst.c ../crypto777/jpeg/jfdctint.c ../crypto777/jpeg/jidctflt.c ../crypto777/jpeg/jidctfst.c ../crypto777/jpeg/jidctint.c ../crypto777/jpeg/jquant1.c \
../crypto777/jpeg/jquant2.c ../crypto777/jpeg/jutils.c ../crypto777/jpeg/jmemmgr.c ../crypto777/jpeg/jmemnobs.c main.c
SOURCES := iguana_wallet.c iguana_html.c iguana_pubkeys.c iguana_recv.c iguana_bundles.c iguana_msg.c iguana_rpc.c iguana777.c iguana_chains.c iguana_peers.c iguana_accept.c iguana_bitmap.c iguana_init.c iguana_ramchain.c iguana_blocks.c iguana_json.c $(CRYPTO777_SRCS) main.c

7
iguana/iguana777.c

@ -284,7 +284,7 @@ int32_t iguana_helpertask(FILE *fp,struct OS_memspace *mem,struct OS_memspace *m
void iguana_helper(void *arg)
{
FILE *fp = 0; char fname[512],name[64],*helpername = 0; cJSON *argjson=0; int32_t i,flag;
FILE *fp = 0; char fname[512],name[64],*helpername = 0; cJSON *argjson=0; int32_t flag;
struct iguana_helper *ptr; struct iguana_info *coin; struct OS_memspace MEM,*MEMB;
if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 )
helpername = jstr(argjson,"name");
@ -302,6 +302,7 @@ void iguana_helper(void *arg)
MEMB = mycalloc('b',IGUANA_MAXBUNDLESIZE,sizeof(*MEMB));
while ( 1 )
{
iguana_jsonQ();
flag = 0;
if ( (ptr= queue_dequeue(&helperQ,0)) != 0 )
{
@ -316,11 +317,11 @@ void iguana_helper(void *arg)
}
if ( flag == 0 )
{
for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
/*for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
{
if ( (coin= Coins[i]) != 0 && coin->launched != 0 )
flag += iguana_rpctest(coin);
}
}*/
if ( flag == 0 )
usleep(10000);
}

15
iguana/iguana777.h

@ -132,7 +132,7 @@ extern int32_t IGUANA_NUMHELPERS;
#define IGUANA_ALLOC_MULT 1.1
#define IGUANA_ALLOC_INCR 1000
#define IGUANA_JSONTIMEOUT 10000
#define IGUANA_JSONTIMEOUT 1000
#define IGUANA_MAPRECVDATA 1
#define IGUANA_MAPTXIDITEMS 2
@ -432,7 +432,7 @@ struct iguana_info
struct iguana_bitmap screen;
//struct pollfd fds[IGUANA_MAXPEERS]; struct iguana_peer bindaddr; int32_t numsocks;
struct OS_memspace TXMEM;
queue_t acceptQ,bundlesQ,hdrsQ,blocksQ,priorityQ,possibleQ,jsonQ,finishedQ,TerminateQ,cacheQ;
queue_t acceptQ,bundlesQ,hdrsQ,blocksQ,priorityQ,possibleQ,TerminateQ,cacheQ;
double parsemillis,avetime; uint32_t Launched[8],Terminated[8];
portable_mutex_t peers_mutex,blocks_mutex;
struct iguana_bundle *bundles[IGUANA_MAXBUNDLES];
@ -477,7 +477,7 @@ int32_t iguana_rwblock(int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct
int32_t iguana_serialize_block(bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block);
void iguana_blockconv(struct iguana_block *dest,struct iguana_msgblock *msg,bits256 hash2,int32_t height);
//void iguana_freetx(struct iguana_msgtx *tx,int32_t n);
int32_t iguana_parser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t datalen);
int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t datalen);
// send message
int32_t iguana_validatehdr(struct iguana_msghdr *H);
@ -559,7 +559,7 @@ double dxblend(double *destp,double val,double decay);
// json
int32_t iguana_processjsonQ(struct iguana_info *coin); // reentrant, can be called during any idletime
char *iguana_JSON(struct iguana_info *coin,char *jsonstr,char *remoteaddr);
char *iguana_JSON(char *jsonstr);
char *SuperNET_p2p(struct iguana_info *coin,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen);
char *mbstr(char *str,double);
@ -670,11 +670,14 @@ int32_t iguana_send_supernet(struct iguana_info *coin,struct iguana_peer *addr,c
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);
int32_t iguana_waccountswitch(struct iguana_info *coin,struct iguana_waddress *waddr,char *coinaddr);
struct iguana_waddress *iguana_waddressfind(struct iguana_info *coin,char *coinaddr);
int32_t iguana_waccountswitch(struct iguana_info *coin,char *account,struct iguana_waccount *oldwaddr,int32_t oldind,char *coinaddr);
struct iguana_waddress *iguana_waddresscalc(struct iguana_info *coin,struct iguana_waddress *addr,bits256 privkey);
struct iguana_waccount *iguana_waddressfind(struct iguana_info *coin,int32_t *indp,char *coinaddr);
char *iguana_coinjson(struct iguana_info *coin,char *method,cJSON *json);
cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly);
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();
#endif

7
iguana/iguana_bitmap.c

@ -123,7 +123,7 @@ void gen_jpegfile(char *fname,int32_t quality,uint8_t *bitmap,int32_t width,int3
int row_stride; /* physical row width in image buffer */
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
if ((outfile = fopen(fname, "wb")) == NULL)
if ( (outfile= fopen(fname,"wb")) == NULL)
{
fprintf(stderr, "can't open %s\n", fname);
exit(1);
@ -1131,11 +1131,10 @@ void iguana_bitmap(char *space,int32_t max,char *name)
//sprintf(space,"Content-type: text/standard\r\n");
//sprintf(space+strlen(space),"Content-Length: %ld\r\n\r\n",strlen(buf));
//strcpy(space,buf);
//printf("bitmap.[%s]\n",space);
printf("bitmap.[%s]\n",space);
}
else
{
sprintf(space,"{\"name\":\"%s\",\"status\":\"%s\",\"amplitude\":%u,\"width\":%d,\"height\":%d,\"pixels\":[",name,coin!=0?coin->statusstr:"no coin",rect->amplitude,rect->width,rect->height), len = (int32_t)strlen(space);
ptr = rect->data;
h = rect->height, w = rect->width;
for (y=0; y<h; y++)
@ -1150,6 +1149,8 @@ void iguana_bitmap(char *space,int32_t max,char *name)
}
}
space[len-1] = ']', space[len++] = '}', space[len++] = 0;
if ( cJSON_Parse(space) == 0 )
printf("ERROR PARSING BITMAP\n");
//if ( (rand() % 100) == 0 )
{
sprintf(fname,"%s.jpg",name);

1
iguana/iguana_chains.c

@ -100,6 +100,7 @@ struct iguana_chain *iguana_chainfind(char *name)
continue;
if ( strcmp(name,chain->symbol) == 0 )
{
printf("found.(%s)\n",name);
iguana_chaininit(chain,strcmp(chain->symbol,"BTC") == 0);
return(chain);
}

783
iguana/iguana_html.c

@ -14,7 +14,7 @@
******************************************************************************/
#include "iguana777.h"
#include "../includes/cJSON.h"
#include "SuperNET.h"
char Default_agent[64] = { "ALL" };
#define IGUANA_FORMS "[ \
@ -152,552 +152,6 @@ char *HTMLfooter =
#define HTML_EMIT(str) if ( (str) != 0 && (str)[0] != 0 ) strcpy(&retbuf[size],str), size += (int32_t)strlen(str)
char Prevjsonstr[1024],Currentjsonstr[1024];
char *iguana_rpc(char *agent,cJSON *json,char *data,int32_t datalen,char *remoteaddr)
{
//printf("agent.(%s) json.(%s) data[%d] %s\n",agent,jprint(json,0),datalen,data!=0?data:"");
if ( data == 0 )
return(iguana_JSON(0,jprint(json,0),remoteaddr));
else return(iguana_JSON(0,data,remoteaddr));
}
void iguana_urldecode(char *str)
{
int32_t a,b,c; char *dest = str;
while ( (c= *str) != 0 )
{
if ( c == '%' && (a= str[1]) != 0 && (b= str[2]) != 0 )
*dest++ = (unhex(a)<<4) | unhex(b);
else *dest++ = c;
}
*dest = 0;
}
char *iguana_parsebidask(char *base,char *rel,char *exchange,double *pricep,double *volumep,char *line)
{
int32_t i;
for (i=0; i<16&&line[i]!='/'&&line[i]!=0; i++)
base[i] = line[i];
base[i] = 0;
touppercase(base);
line += (i + 1);
for (i=0; i<16&&line[i]!='/'&&line[i]!=0; i++)
rel[i] = line[i];
rel[i] = 0;
touppercase(rel);
line += (i + 1);
for (i=0; i<16&&line[i]!='/'&&line[i]!=0; i++)
exchange[i] = line[i];
exchange[i] = 0;
line += (i + 1);
if ( strncmp(line,"price/",strlen("price/")) == 0 )
{
line += strlen("price/");
*pricep = atof(line);
if ( (line= strstr(line,"volume/")) != 0 )
{
line += strlen("volume/");
*volumep = atof(line);
for (i=0; i<16&&line[i]!=0; i++)
if ( line[i] == '/' )
{
i++;
break;
}
return(line+i);
}
}
return(0);
}
char *iguana_InstantDEX(char *jsonstr,char *path,char *method)
{
char *str,base[64],rel[64],exchange[64]; double price,volume;
if ( (str= iguana_parsebidask(base,rel,exchange,&price,&volume,path)) != 0 )
{
if ( price > 0. && volume > 0. )
{
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"%s\",\"base\":\"%s\",\"rel\":\"%s\",\"exchange\":\"%s\",\"price\":\%0.8f,\"volume\":%0.8f}",method,base,rel,exchange,price,volume);
return(jsonstr);
}
else return(0);
}
return(0);
}
void iguana_coinset(char *buf,char *path)
{
int32_t i;
if ( path[0] == '/' )
path++;
for (i=0; i<8&&path[i]!=0&&path[i]!=' '&&path[i]!='/'; i++)
buf[i] = path[i];
buf[i] = 0;
touppercase(buf);
}
char *iguana_ramchain_glue(struct iguana_info *coin,char *method,char *jsonstr)
{
char *ramchain_parser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json);
cJSON *json; char *retstr;
json = cJSON_Parse(jsonstr);
retstr = ramchain_parser(0,coin,method,json);
free_json(json);
return(retstr);
}
char *iguana_hashparse(char *path)
{
int32_t i,j,len,iter,n; uint8_t databuf[512];
char hexstr[1025],password[512],hashname[512],*name,*msg; cJSON *json;
typedef void (*hashfunc)(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len);
typedef char *(*hmacfunc)(char *dest,char *key,int32_t key_size,char *message);
struct hashfunc_entry { char *name; hashfunc hashfunc; };
struct hmacfunc_entry { char *name; hmacfunc hmacfunc; };
struct hashfunc_entry hashes[] = { {"NXT",calc_NXTaddr}, {"curve25519",calc_curve25519_str }, {"base64_encode",calc_base64_encodestr}, {"base64_decode",calc_base64_decodestr}, {"crc32",calc_crc32str}, {"rmd160_sha256",rmd160ofsha256}, {"sha256_sha256",sha256_sha256}, {"sha256",vcalc_sha256}, {"sha512",calc_sha512}, {"sha384",calc_sha384}, {"sha224",calc_sha224}, {"rmd160",calc_rmd160}, {"rmd256",calc_rmd256}, {"rmd320",calc_rmd320}, {"rmd128",calc_rmd128}, {"sha1",calc_sha1}, {"md5",calc_md5str}, {"tiger",calc_tiger}, {"whirlpool",calc_whirlpool} };
struct hmacfunc_entry hmacs[] = { {"hmac_sha256",hmac_sha256_str}, {"hmac_sha512",hmac_sha512_str}, {"hmac_sha384",hmac_sha384_str}, {"hmac_sha224",hmac_sha224_str}, {"hmac_rmd160",hmac_rmd160_str}, {"hmac_rmd256",hmac_rmd256_str}, {"hmac_rmd320",hmac_rmd320_str}, {"hmac_rmd128",hmac_rmd128_str}, {"hmac_sha1",hmac_sha1_str}, {"hmac_md5",hmac_md5_str}, {"hmac_tiger",hmac_tiger_str}, {"hmac_whirlpool",hmac_whirlpool_str} };
n = (int32_t)sizeof(hashes)/sizeof(*hashes);
for (j=0; j<sizeof(hashname)&&path[j]!=0&&path[j]!='/'; j++)
hashname[j] = path[j];
hashname[j] = 0;
printf("ITER0 set hashname.(%s)\n",hashname);
path += j;
path++;
msg = path;
for (j=0; path[j]!='/'&&path[j]!=0&&path[j]!=' '; j++)
;
path[j] = 0;
if ( path[j] != 0 )
j++;
for (j=0; j<sizeof(password)&&path[j]!=0&&path[j]!='/'; j++)
password[j] = path[j];
password[j] = 0;
printf("msg.(%s) password.(%s)\n",msg,password);
for (iter=0; iter<2; iter++)
{
for (i=0; i<n; i++)
{
name = (iter == 0) ? hashes[i].name : hmacs[i].name;
printf("iter.%d i.%d (%s) vs (%s) %d\n",iter,i,name,hashname,strcmp(hashname,name) == 0);
if ( strcmp(hashname,name) == 0 )
{
json = cJSON_CreateObject();
len = (int32_t)strlen(path);
if ( iter == 0 )
(*hashes[i].hashfunc)(hexstr,databuf,(uint8_t *)msg,len);
else (*hmacs[i].hmacfunc)(hexstr,password,j,msg);
jaddstr(json,"result","hash calculated");
jaddstr(json,"message",msg);
jaddstr(json,name,hexstr);
return(jprint(json,1));
}
}
n = (int32_t)sizeof(hmacs)/sizeof(*hmacs);
}
return(clonestr("{\"error\":\"cant find hash function\"}"));
}
char *iguana_htmlget(char *space,int32_t max,int32_t *jsonflagp,char *path,char *remoteaddr,int32_t localaccess)
{
struct iguana_info *coin = 0; cJSON *json; bits256 hash2; int32_t height,i;
char buf[64],jsonstr[1024],coinstr[64],*retstr;
for (i=0; path[i]!=0; i++)
if ( path[i] == ' ' )
break;
path[i] = 0;
if ( path[strlen(path)-1] == '/' )
path[strlen(path)-1] = 0;
if ( strncmp(path,"/api",strlen("/api")) == 0 )
{
*jsonflagp = 1;
path += strlen("/api");
} else *jsonflagp = 0;
iguana_coinset(coinstr,path);
if ( coinstr[0] != 0 )
coin = iguana_coinfind(coinstr);
else coin = 0;
if ( strncmp(path,"/bitmap",strlen("/bitmap")) == 0 )
{
path += strlen("/bitmap");
*jsonflagp = 2;
iguana_bitmap(space,max,path);
return(space);
}
//printf("GETCHECK.(%s)\n",path);
if ( strncmp(path,"/ramchain/",strlen("/ramchain/")) == 0 )
{
path += strlen("/ramchain/");
if ( strncmp(path,"block/",strlen("block/")) == 0 )
{
path += strlen("block/");
if ( strncmp(path,"height/",strlen("height/")) == 0 )
{
height = atoi(path + strlen("height/"));
sprintf(Currentjsonstr,"{\"agent\":\"ramchain\",\"method\":\"block\",\"coin\":\"%s\",\"height\":%d,\"txids\":1}",coinstr,height);
return(iguana_ramchain_glue(coin,"block",Currentjsonstr));
}
else if ( strncmp(path,"hash/",strlen("hash/")) == 0 )
{
decode_hex(hash2.bytes,sizeof(hash2),path + strlen("hash/"));
char str[65]; printf("ramchain blockhash.%s\n",bits256_str(str,hash2));
sprintf(Currentjsonstr,"{\"agent\":\"ramchain\",\"method\":\"block\",\"coin\":\"%s\",\"hash\":\"%s\",\"txids\":1}",coinstr,str);
return(iguana_ramchain_glue(coin,"block",Currentjsonstr));
}
}
else if ( strncmp(path,"txid/",strlen("txid/")) == 0 )
{
decode_hex(hash2.bytes,sizeof(hash2),path + strlen("txid/"));
char str[65]; bits256_str(str,hash2);
sprintf(Currentjsonstr,"{\"agent\":\"ramchain\",\"method\":\"tx\",\"coin\":\"%s\",\"txid\":\"%s\"}",coinstr,str);
return(iguana_ramchain_glue(coin,"tx",Currentjsonstr));
}
else if ( strncmp(path,"explore/",strlen("explore/")) == 0 )
{
path += strlen("explore/");
if ( coin != 0 )
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"explore\",\"coin\":\"%s\",\"search\":\"%s\"}",coinstr,path);
} else sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"explore\",\"search\":\"%s\"}",path);
return(iguana_ramchain_glue(coin,"explore",Currentjsonstr));
}
else if ( strncmp(path,"bundleinfo/",strlen("bundleinfo/")) == 0 )
{
path += strlen("bundleinfo/");
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"bundleinfo\",\"coin\":\"%s\",\"height\":%d}",coinstr,atoi(path));
}
else
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"%s\",\"coin\":\"%s\"}",path,coinstr);
return(iguana_ramchain_glue(coin,path,Currentjsonstr));
}
}
else if ( strncmp(path,"/hash/",strlen("/hash/")) == 0 )
{
path += strlen("/hash/");
return(iguana_hashparse(path));
}
else if ( strncmp(path,"/iguana/",strlen("/iguana/")) == 0 )
{
strcpy(Currentjsonstr,path);
path += strlen("/iguana/");
if ( strncmp(path,"setagent/",strlen("setagent/")) == 0 )
{
path += strlen("setagent/");
if ( strncmp(path,"ramchain",strlen("ramchain")) == 0 || strncmp(path,"iguana",strlen("iguana")) == 0 || strncmp(path,"InstantDEX",strlen("InstantDEX")) == 0 || strncmp(path,"pangea",strlen("pangea")) == 0 || strncmp(path,"PAX",strlen("PAX")) == 0 || strncmp(path,"ALL",strlen("ALL")) == 0 || strncmp(path,"jumblr",strlen("jumblr")) == 0 )
{
if ( strncmp(Default_agent,path,strlen(path)) == 0 )
{
strcpy(Default_agent,"ALL");
return(clonestr("{\"result\":\"ALL agents selected\"}"));
}
strcpy(Default_agent,path);
if ( Default_agent[strlen(Default_agent)-1] == '/' )
Default_agent[strlen(Default_agent)-1] = 0;
sprintf(buf,"{\"result\":\"agent selected\",\"name\":\"%s\"}",path);
return(clonestr(buf));
}
return(clonestr("{\"error\":\"invalid agent specified\"}"));
}
else
{
if ( strncmp(path,"peers/",strlen("peers/")) == 0 )
{
path += strlen("peers/");
if ( coin != 0 )
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"peers\",\"coin\":\"%s\"}",coinstr);
} else sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"peers\"}");
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"peers",json);
free_json(json);
return(retstr);
}
else if ( coin != 0 )
{
if ( strncmp(path,"addnode/",strlen("addnode/")) == 0 )
{
path += strlen("addnode/");
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"addnode\",\"coin\":\"%s\",\"ipaddr\":\"%s\"}",coinstr,path);
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"addnode",json);
free_json(json);
return(retstr);
}
else if ( strncmp(path,"nodestatus/",strlen("nodestatus/")) == 0 )
{
path += strlen("nodestatus/");
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"nodestatus\",\"coin\":\"%s\",\"ipaddr\":\"%s\"}",coinstr,path);
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"nodestatus",json);
free_json(json);
return(retstr);
}
else if ( strncmp(path,"addcoin",strlen("addcoin")) == 0 )
{
path += strlen("addcoin");
iguana_coinset(buf,path);
if ( (coin= iguana_coinadd(buf)) != 0 )
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"addcoin\",\"coin\":\"%s\"}",buf);
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"addcoin",json);
free_json(json);
}
else retstr = clonestr("{\"error\":\"cant create coin\"}");
return(retstr);
}
else if ( strncmp(path,"startcoin",strlen("startcoin")) == 0 )
{
path += strlen("startcoin");
iguana_coinset(buf,path);
if ( (coin= iguana_coinfind(buf)) != 0 )
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"startcoin\",\"coin\":\"%s\"}",buf);
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"startcoin",json);
free_json(json);
}
else retstr = clonestr("{\"error\":\"cant create coin\"}");
return(retstr);
}
else if ( strncmp(path,"pausecoin",strlen("pausecoin")) == 0 )
{
path += strlen("pausecoin");
iguana_coinset(buf,path);
if ( (coin= iguana_coinfind(buf)) != 0 )
{
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"pausecoin\",\"coin\":\"%s\"}",buf);
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"pausecoin",json);
free_json(json);
}
else retstr = clonestr("{\"error\":\"cant create coin\"}");
return(retstr);
}
else if ( strncmp(path,"maxpeers/",strlen("maxpeers/")) == 0 )
{
path += strlen("maxpeers/");
sprintf(Currentjsonstr,"{\"agent\":\"iguana\",\"method\":\"maxpeers\",\"coin\":\"%s\",\"max\":%d}",coinstr,atoi(path));
json = cJSON_Parse(Currentjsonstr);
retstr = iguana_coinjson(coin,"maxpeers",json);
free_json(json);
return(retstr);
}
return(clonestr("{\"result\":\"iguana method not found\"}"));
}
return(clonestr("{\"result\":\"iguana method needs coin\"}"));
}
}
else if ( strncmp(path,"/InstantDEX/",strlen("/InstantDEX/")) == 0 )
{
double price,volume; char base[16],rel[16],exchange[16];
path += strlen("/InstantDEX/");
jsonstr[0] = 0;
if ( strncmp(path,"placebid/",strlen("placebid/")) == 0 )
{
path += strlen("placebid/");
if ( iguana_InstantDEX(jsonstr,path,"placebid") == 0 )
return(clonestr("{\"error\":\"error with placebid parameters\"}"));
}
else if ( strncmp(path,"placeask/",strlen("placeask/")) == 0 )
{
path += strlen("placeask/");
if ( iguana_InstantDEX(jsonstr,path,"placeask") == 0 )
return(clonestr("{\"error\":\"error with placeask parameters\"}"));
}
else if ( strncmp(path,"orderbook/",strlen("orderbook/")) == 0 )
{
path += strlen("orderbook/");
iguana_parsebidask(base,rel,exchange,&price,&volume,path);
if ( exchange[0] == 0 )
strcpy(exchange,"active");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"orderbook\",\"base\":\"%s\",\"rel\":\"%s\",\"exchange\":\"%s\",\"allfields\":1}",base,rel,exchange);
}
else if ( strncmp(path,"orderstatus/",strlen("orderstatus/")) == 0 )
{
path += strlen("orderstatus/");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"orderstatus\",\"orderid\":\"%s\"}",path);
}
else if ( strncmp(path,"cancelorder/",strlen("cancelorder/")) == 0 )
{
path += strlen("cancelorder/");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"cancelorder\",\"orderid\":\"%s\"}",path);
}
else if ( strncmp(path,"balance/",strlen("balance/")) == 0 )
{
path += strlen("balance/");
iguana_parsebidask(base,rel,exchange,&price,&volume,path);
if ( path[0] != ' ' && path[0] != '/' )
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"balance\",\"exchange\":\"%s\"}",path);
else sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"balance\"}");
}
else if ( strncmp(path,"openorders",strlen("openorders")) == 0 )
{
path += strlen("openorders");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"openorders\"}");
}
else if ( strncmp(path,"tradehistory",strlen("tradehistory")) == 0 )
{
path += strlen("tradehistory");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"tradehistory\"}");
}
else if ( strncmp(path,"allorderbooks",strlen("allorderbooks")) == 0 )
{
path += strlen("allorderbooks");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"allorderbooks\"}");
}
else if ( strncmp(path,"allexchanges",strlen("allexchanges")) == 0 )
{
path += strlen("allexchanges");
sprintf(jsonstr,"{\"agent\":\"InstantDEX\",\"method\":\"allexchanges\"}");
}
if ( jsonstr[0] != 0 )
{
strcpy(Currentjsonstr,jsonstr);
return(clonestr(jsonstr));
//return(InstantDEX(jsonstr,remoteaddr,localaccess));
}
return(clonestr("{\"error\":\"unrecognized InstantDEX API call\"}"));
}
else if ( strncmp(path,"/pangea/",strlen("/pangea/")) == 0 )
{
path += strlen("/pangea/");
}
else if ( strncmp(path,"/jumblr/",strlen("/jumblr/")) == 0 )
{
path += strlen("/jumblr/");
}
else printf("no match to (%s)\n",path);
return(0);
}
char *iguana_rpcparse(char *retbuf,int32_t bufsize,int32_t *postflagp,char *jsonstr)
{
cJSON *json = 0; int32_t i,n,localaccess,datalen,postflag = 0;
char *key,*reststr,*str,*retstr,remoteaddr[65],porturl[65],*data = 0,*value,*agent = "SuperNET";
//printf("rpcparse.(%s)\n",jsonstr);
localaccess = 1;
if ( (str= strstr("Referer: ",jsonstr)) != 0 )
{
for (i=0; str[i]!=' '&&str[i]!=0&&str[i]!='\n'&&str[i]!='\r'; i++)
remoteaddr[i] = str[i];
remoteaddr[i] = 0;
} else strcpy(remoteaddr,"127.0.0.1"); // need to verify this
*postflagp = 0;
if ( strncmp("POST",jsonstr,4) == 0 )
jsonstr += 6, *postflagp = postflag = 1;
else if ( strncmp("GET",jsonstr,3) == 0 )
{
jsonstr += 4;
str = 0;
sprintf(porturl,"Referer: http://127.0.0.1:%u",IGUANA_RPCPORT);
if ( (str= iguana_htmlget(retbuf,bufsize,postflagp,jsonstr,remoteaddr,localaccess)) == 0 && (reststr= strstr(jsonstr,porturl)) != 0 )
{
reststr += strlen(porturl);
str = iguana_htmlget(retbuf,bufsize,postflagp,reststr,remoteaddr,localaccess);
}
if ( str != 0 )
{
if ( *postflagp == 0 )
{
json = cJSON_CreateObject();
jaddstr(json,"result",str);
if ( str != retbuf )
free(str);
str = cJSON_Print(json);
free_json(json);
}
return(str);
}
jsonstr++;
}
else return(0);
n = (int32_t)strlen(jsonstr);
for (i=0; i<n; i++)
if ( jsonstr[i] == '?' )
break;
if ( i == n )
{
//printf("no url\n");
return(0);
}
if ( i > 0 )
{
jsonstr[i] = 0;
agent = jsonstr;
jsonstr += i;
}
jsonstr++;
json = cJSON_CreateObject();
jaddstr(json,"agent",agent);
while ( 1 )
{
n = (int32_t)strlen(jsonstr);
key = jsonstr;
value = 0;
for (i=0; i<n; i++)
{
if ( jsonstr[i] == ' ' || jsonstr[i] == '&' )
break;
else if ( jsonstr[i] == '=' )
{
if ( value != 0 )
{
printf("parse error.(%s)\n",jsonstr);
free_json(json);
return(0);
}
jsonstr[i] = 0;
value = &jsonstr[++i];
}
}
if ( value == 0 )
value = "";
jsonstr += i;
if ( jsonstr[0] == ' ' )
{
jsonstr[0] = 0;
jsonstr++;
if ( key != 0 && key[0] != 0 )
jaddstr(json,key,value);
//printf("{%s:%s}\n",key,value);
break;
}
jsonstr[0] = 0;
jsonstr++;
if ( key != 0 && key[0] != 0 )
jaddstr(json,key,value);
//printf("{%s:%s}\n",key,value);
if ( i == 0 )
break;
}
n = (int32_t)strlen(jsonstr);
datalen = 0;
if ( postflag != 0 )
{
for (i=0; i<n; i++)
{
//printf("(%d) ",jsonstr[i]);
if ( jsonstr[i] == '\n' || jsonstr[i] == '\r' )
{
//printf("[%s] cmp.%d\n",jsonstr+i+1,strncmp(jsonstr+i+1,"Content-Length:",strlen("Content-Length:")));
if ( strncmp(jsonstr+i+1,"Content-Length:",strlen("Content-Length:")) == 0 )
{
datalen = (int32_t)atoi(jsonstr + i + 1 + strlen("Content-Length:") + 1);
data = &jsonstr[n - datalen];
//printf("post.(%s) (%c)\n",data,data[0]);
//iguana_urldecode(data);
}
}
}
}
retstr = iguana_rpc(agent,json,data,datalen,remoteaddr);
free_json(json);
return(retstr);
//printf("post.%d json.(%s) data[%d] %s\n",postflag,jprint(json,0),datalen,data!=0?data:"");
//return(json);
}
int32_t iguana_htmlgen(char *retbuf,int32_t bufsize,char *result,char *error,cJSON *json,char *tabname,char *origjsonstr)
{
char *url = "http://127.0.0.1:7778";
@ -705,7 +159,7 @@ int32_t iguana_htmlgen(char *retbuf,int32_t bufsize,char *result,char *error,cJS
char formheader[512],formfooter[512],clickname[512],buf[512],fieldbuf[512],fieldindex[2],postjson[8192];
char *disp,*fieldname,*button,*agent,*method,*str;
bufsize--;
HTML_EMIT("<html> <head></head> <body> <p id=\"RTstats\"></p> ");
HTML_EMIT("<html> <head><title>SuperUGLY GUI></title></head> <body> <p id=\"RTstats\"></p> ");
sprintf(buf,"<canvas id=\"canvas\" width=\"%d\" height=\"%d\"></canvas><script>var Width = %d; var Height = %d;",IGUANA_WIDTH,IGUANA_HEIGHT,IGUANA_WIDTH,IGUANA_HEIGHT);
HTML_EMIT(buf);
HTML_EMIT("var RTparsed = 0; var RTcount = 0; var RTpending = 0; var RTwidth; var RTheight; var RTamplitude; var RTname; var RTjson;");
@ -727,7 +181,10 @@ function process_bitmap(bitmapjson) \
{\
for (x=0; x<Width; x++)\
{\
image.data[m++] = bitmap.pixels[n++]; image.data[m++] = bitmap.pixels[n++]; image.data[m++] = bitmap.pixels[n++]; image.data[m++] = 255; \
image.data[m++] = bitmap.pixels[n++]; \
image.data[m++] = bitmap.pixels[n++]; \
image.data[m++] = bitmap.pixels[n++]; \
image.data[m++] = 255; \
}\
}\
ctx.putImageData(image,0,0);\
@ -737,10 +194,12 @@ function process_bitmap(bitmapjson) \
\
function bitmap_handler() \
{ \
if ( this.status == 200 && this.responseText != null ) { \
if ( this.status == 200 && this.responseText != null ) \
{ \
process_bitmap(this.responseText); \
if ( RTpending > 0 ) RTpending--; \
} \
if ( RTpending > 0 )\
RTpending--; \
} \
} \
\
function httpGet()\
@ -751,7 +210,7 @@ function httpGet()\
else\
client = new ActiveXObject(\"Microsoft.XMLHTTP\");\
client.onload = bitmap_handler;\
client.open(\"GET\",\"http://127.0.0.1:7778/api/bitmap\");\
client.open(\"GET\",\"http://127.0.0.1:7778/api/bitmap/BTCD\");\
client.send();\
}\
\
@ -765,22 +224,9 @@ function iguana_poll( )\
RTpending++;\
}\
} </script><br>");
//sprintf(buf,"<br> COIN: <textarea cols=\"8\" rows=\"1\" name=\"COIN_NAME\"/>name</textarea>");
//HTML_EMIT(buf);
if ( 0 )
{
sprintf(formfooter,"\t<input type=\"button\" value=\"%s\" onclick=\"click_%s()\" /></form>","InstantDEX","iguana49_setagent"); HTML_EMIT(formfooter);
sprintf(formfooter,"\t<input type=\"button\" value=\"%s\" onclick=\"click_%s()\" /></form>","PAX","iguana50_setagent"); HTML_EMIT(formfooter);
sprintf(formfooter,"\t<input type=\"button\" value=\"%s\" onclick=\"click_%s()\" /></form>","pangea","iguana51_setagent"); HTML_EMIT(formfooter);
sprintf(formfooter,"\t<input type=\"button\" value=\"%s\" onclick=\"click_%s()\" /></form>","jumblr","iguana52_setagent"); HTML_EMIT(formfooter);
sprintf(formfooter,"\t<input type=\"button\" value=\"%s\" onclick=\"click_%s()\" /></form>","ramchain","iguana53_setagent"); HTML_EMIT(formfooter);
sprintf(formfooter,"\t<input type=\"button\" value=\"%s\" onclick=\"click_%s()\" /></form>","iguana","iguana54_setagent"); HTML_EMIT(formfooter);
}
HTML_EMIT(" Agent: "); HTML_EMIT(Default_agent);
HTML_EMIT("<br><br/>");
HTML_EMIT(origjsonstr); HTML_EMIT(" -> ");
HTML_EMIT("<textarea cols=\"150\" rows=\"10\" name=\"jsonresult\"/>");
HTML_EMIT("<textarea cols=\"150\" rows=\"10\" name=\"jsonresult\">");
tmp = cJSON_Parse(result), str = cJSON_Print(tmp), free_json(tmp);
HTML_EMIT(str); free(str);
HTML_EMIT(error);
@ -823,7 +269,7 @@ function iguana_poll( )\
sprintf(buf,"%s = document.%s.%s.value;\n",fieldindex,clickname,fieldname);
HTML_EMIT(buf);
//sprintf(postjson+strlen(postjson),",\"%s\":\"' + %s + '\"",fieldname,fieldindex);
if ( juint(obj,"skip") == 0 )
if ( 1 || juint(obj,"skip") == 0 )
sprintf(postjson+strlen(postjson),"/%s/' + %s + '",fieldname,fieldindex);
else sprintf(postjson+strlen(postjson),"/' + %s + '",fieldindex);
}
@ -842,9 +288,9 @@ function iguana_poll( )\
sprintf(fieldbuf,"%s_%c",clickname,'A'+j), fieldname = fieldbuf;
if ( rows == 0 && cols == 0 )
sprintf(buf,"<input type=\"text\" name=\"%s\"/>",fieldname);
else sprintf(buf,"<textarea cols=\"%d\" rows=\"%d\" name=\"%s\"/ %s></textarea>",cols,rows,fieldname,cols == 1 ? "hidden" : "");
else sprintf(buf,"<textarea cols=\"%d\" rows=\"%d\" name=\"%s\" %s></textarea>",cols,rows,fieldname,cols == 1 ? "hidden" : "");
str = disp==0?jstr(obj,"disp"):disp;
sprintf(&retbuf[size],"<td>%s</td> <td> %s </td>\r\n",str!=0?str:fieldname,buf), size += strlen(&retbuf[size]);
sprintf(&retbuf[size],"<td>%s %s </td>\r\n",str!=0?str:fieldname,buf), size += strlen(&retbuf[size]);
}
sprintf(formfooter,"<td colspan=\"2\"> <input type=\"button\" value=\"%s\" onclick=\"click_%s()\" /></td> </tr>\n</table></form>",button,clickname);
HTML_EMIT(formfooter);
@ -858,7 +304,7 @@ function iguana_poll( )\
char *iguana_htmlresponse(char *retbuf,int32_t bufsize,int32_t *remainsp,int32_t localaccess,char *retstr,int32_t freeflag)
{
static char *html = "<html> <head></head> <body> %s </body> </html>";
//static char *html = "<html> <head></head> <body> %s </body> </html>";
char *result=0,*error=0; int32_t n; cJSON *json,*formsjson;
retbuf[0] = 0;
/*if ( localaccess == 0 )
@ -873,7 +319,7 @@ char *iguana_htmlresponse(char *retbuf,int32_t bufsize,int32_t *remainsp,int32_t
sprintf(retbuf+strlen(retbuf),"<!DOCTYPE HTML>\n\r");
n = (int32_t)strlen(retbuf);
formsjson = cJSON_Parse(IGUANA_FORMS);
if ( (json= cJSON_Parse(retstr)) == 0 )
if ( retstr == 0 || (json= cJSON_Parse(retstr)) == 0 )
json = cJSON_CreateObject();
jadd(json,"forms",formsjson);
error = jstr(json,"error");
@ -881,11 +327,11 @@ char *iguana_htmlresponse(char *retbuf,int32_t bufsize,int32_t *remainsp,int32_t
//printf("process.(%s)\n",jprint(formsjson,0));
n = iguana_htmlgen(&retbuf[n],bufsize-n,result,error,json,"iguana",Currentjsonstr);
free_json(json);
if ( n == 0 )
/*if ( n == 0 )
{
n = (int32_t)(strlen(html) + strlen(retstr) + 1);
sprintf(retbuf+strlen(retbuf),html,retstr);
}
}*/
if ( freeflag != 0 )
free(retstr);
if ( n > bufsize )
@ -897,10 +343,180 @@ char *iguana_htmlresponse(char *retbuf,int32_t bufsize,int32_t *remainsp,int32_t
return(retbuf);
}
int32_t Supernet_lineparse(char *key,int32_t keymax,char *value,int32_t valuemax,char *src)
{
int32_t a,b,c,n = 0;
key[0] = value[0] = 0;
while ( (c= src[n]) == ' ' || c == '\t' || c == '\n' || c == '\t' )
n++;
while ( (c= src[n]) != ':' && c != 0 )
{
*key++ = c;
if ( ++n >= keymax-1 )
{
*key = 0;
printf("lineparse overflow key.(%s)\n",src);
return(-1);
}
}
*key = 0;
if ( src[n] != ':' )
return(n);
n++;
while ( (c= src[n]) == ' ' || c == '\t' )
n++;
while ( (c= src[n]) != 0 && c != '\r' && c != '\n' )
{
if ( c == '%' && (a= src[n+1]) != 0 && (b= src[n+2]) != 0 )
c = ((unhex(a) << 4) | unhex(b)), n += 2;
*value++ = c;
n++;
if ( n >= valuemax-1 )
{
*value = 0;
printf("lineparse overflow.(%s)\n",src);
return(-1);
}
}
*value = 0;
if ( src[n] != 0 )
{
n++;
while ( (c= src[n]) == '\r' || c == '\n' )
n++;
}
return(n);
}
cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr)
{
int32_t i,n,totallen,datalen,len = 0; cJSON *json,*array; char key[8192],*data;
json = cJSON_CreateObject();
array = cJSON_CreateArray();
totallen = (int32_t)strlen(urlstr);
while ( 1 )
{
for (i=len; urlstr[i]!=0; i++)
if ( urlstr[i] == '\r' || urlstr[i] == '\n' )
break;
if ( i == len && (urlstr[len] == '\r' || urlstr[len] == '\n') )
{
len++;
continue;
}
urlstr[i] = 0;
if ( (n= Supernet_lineparse(key,sizeof(key),value,bufsize,&urlstr[len])) > 0 )
{
if ( value[0] != 0 )
jaddstr(json,key,value);
else jaddistr(array,key);
len += (n + 1);
if ( strcmp(key,"Content-Length") == 0 && (datalen= atoi(value)) > 0 )
{
data = &urlstr[totallen - datalen];
data[-1] = 0;
//printf("post.(%s) (%c)\n",data,data[0]);
jaddstr(json,"POST",data);
}
} else break;
}
jadd(json,"lines",array);
return(json);
}
char *SuperNET_rpcparse(struct supernet_info *myinfo,char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr)
{
cJSON *tokens,*argjson,*json = 0; char urlmethod[16],*data,url[1024],*retstr,*token = 0; int32_t i,j,n;
//printf("rpcparse.(%s)\n",urlstr);
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
urlmethod[i] = urlstr[i];
urlmethod[i++] = 0;
n = i;
//printf("URLMETHOD.(%s)\n",urlmethod);
*postflagp = (strcmp(urlmethod,"POST") == 0);
for (i=0; i<sizeof(url)-1&&urlstr[n+i]!=0&&urlstr[n+i]!=' '; i++)
url[i] = urlstr[n+i];
url[i++] = 0;
n += i;
j = i = 0;
if ( strncmp(&url[i],"/api",strlen("/url")) == 0 )
{
*jsonflagp = 1;
i += strlen("/api");
} else *jsonflagp = 0;
if ( strncmp(&url[i],"/bitmap",strlen("/bitmap")) == 0 )
{
i += strlen("/bitmap");
*jsonflagp = 2;
if ( url[i] == '/' )
i++;
iguana_bitmap(retbuf,bufsize,&url[i]);
return(retbuf);
}
printf("URL.(%s)\n",url);
if ( strcmp(url,"/favicon.ico") == 0 )
{
*jsonflagp = -1;
return(0);
}
if ( url[i] != '/' )
token = url;
tokens = cJSON_CreateArray();
for (; url[i]!=0; i++)
{
if ( url[i] == '/' )
{
url[i] = 0;
if ( token != 0 )
jaddistr(tokens,token);
token = &url[i+1];
continue;
}
}
if ( token != 0 )
jaddistr(tokens,token);
if ( (json= SuperNET_urlconv(retbuf,bufsize,urlstr+n)) != 0 )
{
jadd(json,"tokens",tokens);
jaddstr(json,"urlmethod",urlmethod);
if ( (data= jstr(json,"POST")) == 0 || (argjson= cJSON_Parse(data)) == 0 )
{
argjson = cJSON_CreateObject();
if ( (n= cJSON_GetArraySize(tokens)) > 0 )
{
jaddstr(argjson,"agent",jstri(tokens,0));
if ( n > 1 )
jaddstr(argjson,"method",jstri(tokens,1));
for (i=2; i<n; i++)
{
if ( i == n-1 )
jaddstr(argjson,"data",jstri(tokens,i));
else
{
jaddstr(argjson,jstri(tokens,i),jstri(tokens,i+1));
i++;
}
}
}
}
if ( jstr(argjson,"agent") == 0 || jstr(argjson,"method") == 0 )
{
free_json(argjson);
return(0);
}
retstr = SuperNET_JSON(myinfo,argjson,remoteaddr);
free_json(argjson);
//printf("(%s) -> (%s) postflag.%d (%s)\n",urlstr,cJSON_Print(json),*postflagp,retstr);
return(retstr);
}
return(clonestr("{\"error\":\"couldnt process packet\"}"));
}
void iguana_rpcloop(void *args)
{
int32_t recvlen,bindsock,postflag,sock,remains,numsent,len; socklen_t clilen;
char ipaddr[64],jsonbuf[8192],*buf,*retstr,*space;//,*retbuf; ,n,i,m
struct supernet_info *myinfo = args;
int32_t recvlen,bindsock,postflag,sock,remains,numsent,jsonflag,len; socklen_t clilen;
char remoteaddr[64],jsonbuf[8192],*buf,*retstr,*space;//,*retbuf; ,n,i,m
struct sockaddr_in cli_addr; uint32_t ipbits,i,size = IGUANA_WIDTH*IGUANA_HEIGHT*16 + 512; uint16_t port;
port = IGUANA_RPCPORT;
bindsock = iguana_socket(1,"127.0.0.1",port);
@ -917,7 +533,7 @@ void iguana_rpcloop(void *args)
continue;
}
memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits));
expand_ipbits(ipaddr,ipbits);
expand_ipbits(remoteaddr,ipbits);
//printf("RPC.%d for %x (%s)\n",sock,ipbits,ipaddr);
//printf("%p got.(%s) from %s | usock.%d ready.%u dead.%u\n",addr,H.command,addr->ipaddr,addr->usock,addr->ready,addr->dead);
memset(jsonbuf,0,sizeof(jsonbuf));
@ -943,18 +559,23 @@ void iguana_rpcloop(void *args)
remains -= len;
recvlen += len;
buf = &buf[len];
retstr = SuperNET_rpcparse(myinfo,space,size,&jsonflag,&postflag,jsonbuf,remoteaddr);
break;
} else usleep(10000);
//printf("got.(%s) %d remains.%d of total.%d\n",jsonbuf,recvlen,remains,len);
retstr = iguana_rpcparse(space,size,&postflag,jsonbuf);
//retstr = iguana_rpcparse(space,size,&postflag,jsonbuf);
break;
}
}
if ( retstr == 0 )
retstr = iguana_htmlresponse(space,size,&remains,1,retstr,retstr != space);
if ( retstr != 0 )
{
i = 0;
if ( postflag == 0 )
retstr = iguana_htmlresponse(space,size,&remains,1,retstr,1);
if ( 0 && postflag == 0 )
retstr = iguana_htmlresponse(space,size,&remains,1,retstr,retstr != space);
else remains = (int32_t)strlen(retstr);
//printf("POSTFLAG.%d\n",postflag);
//printf("RETBUF.(%s)\n",retstr);
while ( remains > 0 )
{
@ -981,6 +602,6 @@ void iguana_rpcloop(void *args)
strcpy(Prevjsonstr,Currentjsonstr);
Currentjsonstr[0] = 0;
//printf("done response sock.%d\n",sock);
close(sock);
closesocket(sock);
}
}

2
iguana/iguana_init.c

@ -32,8 +32,6 @@ void iguana_initQs(struct iguana_info *coin)
iguana_initQ(&coin->blocksQ,"blocksQ");
iguana_initQ(&coin->priorityQ,"priorityQ");
iguana_initQ(&coin->possibleQ,"possibleQ");
iguana_initQ(&coin->jsonQ,"jsonQ");
iguana_initQ(&coin->finishedQ,"finishedQ");
iguana_initQ(&coin->cacheQ,"cacheQ");
iguana_initQ(&coin->TerminateQ,"TerminateQ");
for (i=0; i<IGUANA_MAXPEERS; i++)

557
iguana/iguana_json.c

@ -14,16 +14,7 @@
******************************************************************************/
#include "iguana777.h"
struct iguana_agent *Agents[16];
char *pangea_parser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json);
char *InstantDEX_parser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json);
char *jumblr_parser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json);
char *ramchain_parser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json);
int32_t iguana_launchcoin(char *symbol,cJSON *json);
struct iguana_jsonitem { struct queueitem DL; uint32_t fallback,expired,allocsize; char **retjsonstrp; char remoteaddr[64]; char jsonstr[]; };
#include "SuperNET.h"
cJSON *iguana_peerjson(struct iguana_info *coin,struct iguana_peer *addr)
{
@ -95,267 +86,6 @@ cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly)
else return(array);
}
cJSON *iguana_agentinfojson(struct iguana_agent *agent)
{
cJSON *json= cJSON_CreateObject();
jaddstr(json,"name",agent->name);
jadd(json,"methods",agent->methods);
if ( agent->port != 0 )
jaddnum(json,"port",agent->port);
else jaddstr(json,"type","builtin");
return(json);
}
char *iguana_remoteparser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json)
{
int32_t i,n,remains,numsent; char *jsonstr = 0,*retstr = 0; uint8_t hdr[128];
if ( agent->sock < 0 )
agent->sock = iguana_socket(0,agent->hostname,agent->port);
if ( agent->sock >= 0 )
{
i = 0;
jsonstr = jprint(json,0);
n = (int32_t)strlen(jsonstr) + 1;
remains = n;
//printf("RETBUF.(%s)\n",retbuf);
while ( remains > 0 )
{
if ( (numsent= (int32_t)send(agent->sock,&jsonstr[i],remains,MSG_NOSIGNAL)) < 0 )
{
if ( errno != EAGAIN && errno != EWOULDBLOCK )
{
printf("%s: %s numsent.%d vs remains.%d of %d errno.%d (%s) usock.%d\n",jsonstr,agent->name,numsent,remains,n,errno,strerror(errno),agent->sock);
break;
}
}
else if ( remains > 0 )
{
remains -= numsent;
i += numsent;
if ( remains > 0 )
printf("iguana sent.%d remains.%d of len.%d\n",numsent,remains,n);
}
}
if ( (n= (int32_t)recv(agent->sock,hdr,sizeof(hdr),0)) >= 0 )
{
remains = (hdr[0] + ((int32_t)hdr[1] << 8) + ((int32_t)hdr[2] << 16));
retstr = mycalloc('p',1,remains + 1);
i = 0;
while ( remains > 0 )
{
if ( (n= (int32_t)recv(agent->sock,&retstr[i],remains,0)) < 0 )
{
if ( errno == EAGAIN )
{
printf("EAGAIN for len %d, remains.%d\n",n,remains);
usleep(10000);
}
break;
}
else
{
if ( n > 0 )
{
remains -= n;
i += n;
} else usleep(10000);
}
}
}
free(jsonstr);
}
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"null return\"}");
return(retstr);
}
char *iguana_addagent(char *name,char *(*parsefunc)(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json),char *hostname,cJSON *methods,uint16_t port,char *pubkeystr,char *privkeystr)
{
int32_t i; struct iguana_agent *agent; char retbuf[8192];
for (i=0; i<sizeof(Agents)/sizeof(*Agents); i++)
{
if ( (agent= Agents[i]) != 0 && strcmp(agent->name,name) == 0 )
{
if ( pubkeystr != 0 && privkeystr != 0 && strlen(pubkeystr) == 64 && strlen(privkeystr) == 64 )
{
decode_hex(agent->pubkey.bytes,sizeof(bits256),pubkeystr);
decode_hex(agent->privkey.bytes,sizeof(bits256),privkeystr);
}
if ( port != 0 && agent->port == 0 )
{
if ( agent->sock >= 0 )
close(agent->sock);
agent->port = port;
strcpy(agent->hostname,hostname);
agent->sock = iguana_socket(0,agent->hostname,port);
printf("set (%s) port.%d for %s -> sock.%d\n",hostname,port,agent->name,agent->sock);
}
if ( agent->port > 0 && agent->sock < 0 && agent->hostname[0] != 0 && (agent->sock= iguana_socket(0,agent->hostname,agent->port)) < 0 )
return(clonestr("{\"result\":\"existing agent couldnt connect to remote agent\"}"));
else return(clonestr("{\"result\":\"agent already there\"}"));
}
}
for (i=0; i<sizeof(Agents)/sizeof(*Agents); i++)
{
if ( Agents[i] == 0 )
{
agent = mycalloc('G',1,sizeof(*Agents[i]));
Agents[i] = agent;
strncpy(agent->name,name,sizeof(agent->name)-1);
strncpy(agent->hostname,hostname,sizeof(agent->hostname)-1);
agent->methods = methods, agent->nummethods = cJSON_GetArraySize(methods);
agent->sock = -1;
agent->port = port;
agent->parsefunc = (void *)parsefunc;
if ( pubkeystr != 0 && privkeystr != 0 && strlen(pubkeystr) == 64 && strlen(privkeystr) == 64 )
{
decode_hex(agent->pubkey.bytes,sizeof(bits256),pubkeystr);
decode_hex(agent->privkey.bytes,sizeof(bits256),privkeystr);
}
if ( port > 0 )
{
if ( (agent->sock= iguana_socket(0,hostname,port)) < 0 )
return(clonestr("{\"result\":\"agent added, but couldnt connect to remote agent\"}"));
}
sprintf(retbuf,"{\"result\":\"agent added\",\"name\"\"%s\",\"methods\":%s,\"hostname\":\"%s\",\"port\":%u,\"sock\":%d}",agent->name,jprint(agent->methods,0),agent->hostname,agent->port,agent->sock);
return(clonestr(retbuf));
}
}
return(clonestr("{\"error\":\"no more agent slots available\"}"));
}
char *iguana_agentjson(char *name,struct iguana_info *coin,char *method,cJSON *json,char *remoteaddr)
{
cJSON *retjson = 0,*array,*methods,*obj; int32_t i,n,j; struct iguana_agent *agent;
if ( strcmp(name,"SuperNET") != 0 )
{
for (i=0; i<sizeof(Agents)/sizeof(*Agents); i++)
{
if ( (agent= Agents[i]) != 0 && strcmp(agent->name,name) == 0 )
{
if ( agent->parsefunc != 0 )
{
for (j=0; j<agent->nummethods; j++)
{
if ( (obj= jitem(agent->methods,j)) != 0 )
{
if ( strcmp(method,jstr(obj,0)) == 0 )
return((*agent->parsefunc)(agent,method,json,remoteaddr));
}
}
return(clonestr("{\"result\":\"agent doesnt have method\"}"));
} else return(clonestr("{\"result\":\"agent doesnt have parsefunc\"}"));
}
}
}
else if ( remoteaddr == 0 || strcmp(remoteaddr,"127.0.0.1") != 0 ) // public api
{
char *coinstr; int32_t j,k,l,r,rr; struct iguana_peer *addr;
array = 0;
if ( strcmp(method,"getpeers") == 0 )
{
if ( (coinstr= jstr(json,"coin")) != 0 )
{
if ( (array= iguana_peersjson(iguana_coinfind(coinstr),1)) == 0 )
return(clonestr("{\"error\":\"coin not found\"}"));
}
else
{
n = 0;
array = cJSON_CreateArray();
r = rand();
for (i=0; i<IGUANA_MAXCOINS; i++)
{
j = (r + i) % IGUANA_MAXCOINS;
if ( (coin= Coins[j]) != 0 )
{
rr = rand();
for (k=0; k<IGUANA_MAXPEERS; k++)
{
l = (rr + k) % IGUANA_MAXPEERS;
addr = &coin->peers.active[l];
if ( addr->usock >= 0 && addr->supernet != 0 )
{
jaddistr(array,addr->ipaddr);
if ( ++n >= 64 )
break;
}
}
}
}
}
if ( array != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"agent","SuperNET");
jaddstr(retjson,"method","mypeers");
jaddstr(retjson,"result","peers found");
jadd(retjson,"peers",array);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"no peers found\"}"));
}
else if ( strcmp(method,"mypeers") == 0 )
{
printf("mypeers from %s\n",remoteaddr!=0?remoteaddr:"local");
}
}
else // local api
{
if ( strcmp(method,"list") == 0 )
{
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
{
if ( Coins[i] != 0 && Coins[i]->symbol[0] != 0 )
jaddistr(array,Coins[i]->symbol);
}
jadd(retjson,"coins",array);
array = cJSON_CreateArray();
for (i=0; i<sizeof(Agents)/sizeof(*Agents); i++)
{
if ( Agents[i] != 0 && Agents[i]->name[0] != 0 )
jaddi(array,iguana_agentinfojson(Agents[i]));
}
jadd(retjson,"agents",array);
return(jprint(retjson,1));
}
else if ( strcmp(method,"peers") == 0 )
{
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
{
if ( Coins[i] != 0 && Coins[i]->symbol[0] != 0 )
jaddi(array,iguana_peersjson(Coins[i],0));
}
jadd(retjson,"allpeers",array);
return(jprint(retjson,1));
}
else if ( strcmp(method,"addagent") == 0 )
{
char *hostname = "127.0.0.1",*name; uint16_t port;
if ( (name= jstr(json,"name")) != 0 && (methods= jarray(&n,json,"methods")) != 0 )
{
if ( (port= juint(json,"port")) != 0 )
{
if ( (hostname= jstr(json,"host")) == 0 )
{
if ( (hostname= jstr(json,"ipaddr")) == 0 )
hostname = "127.0.0.1";
}
if ( hostname == 0 )
return(clonestr("{\"error\":\"no host specified for remote agent\"}"));
}
else if ( strcmp(name,"pangea") != 0 && strcmp(name,"InstantDEX") != 0 && strcmp(name,"jumblr") != 0 )
return(clonestr("{\"error\":\"no port specified for remote agent\"}"));
return(iguana_addagent(name,iguana_remoteparser,hostname,methods,port,jstr(json,"pubkey"),jstr(json,"privkey")));
} else return(clonestr("{\"error\":\"cant addagent without name and methods\"}"));
}
}
return(clonestr("{\"result\":\"stub processed generic json\"}"));
}
char *iguana_coinjson(struct iguana_info *coin,char *method,cJSON *json)
{
int32_t i,max,retval; struct iguana_peer *addr; char *ipaddr; cJSON *retjson = 0;
@ -422,244 +152,101 @@ char *iguana_coinjson(struct iguana_info *coin,char *method,cJSON *json)
return(clonestr("{\"error\":\"unhandled request\"}"));
}
char *iguana_jsonstr(struct iguana_info *coin,char *jsonstr,char *remoteaddr)
char *iguana_parser(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr)
{
cJSON *json; char *retjsonstr,*methodstr,*agentstr;
//printf("iguana_jsonstr.(%s)\n",jsonstr);
if ( (json= cJSON_Parse(jsonstr)) != 0 )
char *coinstr,SYM[16]; int32_t j,k,l,r,rr; struct iguana_peer *addr;
cJSON *retjson = 0,*array; int32_t i,n; struct iguana_info *coin; char *symbol;
printf("remoteaddr.(%s)\n",remoteaddr!=0?remoteaddr:"local");
if ( remoteaddr == 0 || remoteaddr[0] == 0 || strcmp(remoteaddr,"127.0.0.1") == 0 ) // local (private) api
{
if ( (methodstr= jstr(json,"method")) != 0 )
{
if ( (agentstr= jstr(json,"agent")) == 0 || strcmp(agentstr,"iguana") == 0 )
retjsonstr = iguana_coinjson(coin,methodstr,json);
else retjsonstr = iguana_agentjson(agentstr,coin,methodstr,json,remoteaddr);
} else retjsonstr = clonestr("{\"error\":\"no method in JSON\"}");
free_json(json);
} else retjsonstr = clonestr("{\"error\":\"cant parse JSON\"}");
printf("iguana_jsonstr.(%s)\n",retjsonstr);
return(retjsonstr);
}
int32_t iguana_processjsonQ(struct iguana_info *coin) // reentrant, can be called during any idletime
{
struct iguana_jsonitem *ptr;
if ( (ptr= queue_dequeue(&coin->finishedQ,0)) != 0 )
{
if ( ptr->expired != 0 )
{
*ptr->retjsonstrp = clonestr("{\"error\":\"request timeout\"}");
printf("garbage collection: expired.(%s)\n",ptr->jsonstr);
myfree(ptr,ptr->allocsize);
} else queue_enqueue("finishedQ",&coin->finishedQ,&ptr->DL,0);
}
if ( (ptr= queue_dequeue(&coin->jsonQ,0)) != 0 )
{
//printf("process.(%s)\n",ptr->jsonstr);
if ( (*ptr->retjsonstrp= iguana_jsonstr(ptr->fallback==0?coin:0,ptr->jsonstr,ptr->remoteaddr)) == 0 )
*ptr->retjsonstrp = clonestr("{\"error\":\"null return from iguana_jsonstr\"}");
queue_enqueue("finishedQ",&coin->finishedQ,&ptr->DL,0);
return(1);
}
return(0);
}
char *iguana_blockingjsonstr(struct iguana_info *coin,char *jsonstr,uint64_t tag,int32_t maxmillis,char *remoteaddr)
{
struct iguana_jsonitem *ptr; char *retjsonstr = 0; int32_t fallback = 0,len,allocsize; double expiration = OS_milliseconds() + maxmillis;
if ( coin == 0 )
coin = iguana_coinfind("BTCD"), fallback = 1;
if ( coin != 0 )
{
//printf("blocking case.(%s)\n",jsonstr);
len = (int32_t)strlen(jsonstr);
allocsize = sizeof(*ptr) + len + 1;
ptr = mycalloc('J',1,allocsize);
ptr->allocsize = allocsize;
ptr->fallback = fallback;
ptr->retjsonstrp = &retjsonstr;
safecopy(ptr->remoteaddr,remoteaddr,sizeof(ptr->remoteaddr));
memcpy(ptr->jsonstr,jsonstr,len+1);
queue_enqueue("jsonQ",&coin->jsonQ,&ptr->DL,0);
while ( OS_milliseconds() < expiration )
if ( strcmp(method,"list") == 0 )
{
usleep(100);
if ( retjsonstr != 0 )
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
{
//printf("blocking retjsonstr.(%s)\n",retjsonstr);
queue_delete(&coin->finishedQ,&ptr->DL,allocsize,1);
return(retjsonstr);
if ( Coins[i] != 0 && Coins[i]->symbol[0] != 0 )
jaddistr(array,Coins[i]->symbol);
}
usleep(1000);
}
printf("(%s) expired\n",jsonstr);
ptr->expired = (uint32_t)time(NULL);
return(clonestr("{\"error\":\"iguana jsonstr expired\"}"));
}
return(clonestr("{\"error\":\"iguana blockingjsonstr cant get coin_info\"}"));
}
char *iguana_JSON(struct iguana_info *coin,char *jsonstr,char *remoteaddr)
{
cJSON *json,*retjson; uint64_t tag; uint32_t timeout; int32_t retval,localaccess = 0;
char *method,*retjsonstr,*symbol,*retstr = 0;
if ( remoteaddr == 0 || strcmp(remoteaddr,"127.0.0.1") == 0 ) // || strcmp(remoteaddr,myipaddr) == 0 )
localaccess = 1;
printf("iguana_JSON.(%s) from %s\n",jsonstr,localaccess==0?remoteaddr:"local access");
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( localaccess != 0 && (method= jstr(json,"method")) != 0 && strcmp(method,"addcoin") == 0 )
{
if ( (retval= iguana_launchcoin(jstr(json,"coin"),json)) > 0 )
return(clonestr("{\"result\":\"launched coin\"}"));
else if ( retval == 0 ) return(clonestr("{\"result\":\"coin already launched\"}"));
else return(clonestr("{\"error\":\"error launching coin\"}"));
}
if ( (tag= j64bits(json,"tag")) == 0 )
OS_randombytes((uint8_t *)&tag,sizeof(tag));
if ( (symbol= jstr(json,"coin")) != 0 )
{
coin = iguana_coinfind(symbol);
if ( coin != 0 && localaccess != 0 && coin->launched == 0 )
iguana_launchcoin(symbol,json);
jadd(retjson,"coins",array);
return(jprint(retjson,1));
}
if ( (timeout= juint(json,"timeout")) == 0 )
timeout = IGUANA_JSONTIMEOUT;
if ( (retjsonstr= iguana_blockingjsonstr(coin,jsonstr,tag,timeout,remoteaddr)) != 0 )
else if ( strcmp(method,"allpeers") == 0 )
{
//printf("retjsonstr.(%s)\n",retjsonstr);
if ( (retjson= cJSON_Parse(retjsonstr)) == 0 )
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
{
retjson = cJSON_Parse("{\"error\":\"cant parse retjsonstr\"}");
if ( Coins[i] != 0 && Coins[i]->symbol[0] != 0 )
jaddi(array,iguana_peersjson(Coins[i],0));
}
jdelete(retjson,"tag");
jadd64bits(retjson,"tag",tag);
retstr = jprint(retjson,1);
//printf("retstr.(%s) retjsonstr.%p retjson.%p\n",retstr,retjsonstr,retjson);
free(retjsonstr);//,strlen(retjsonstr)+1);
jadd(retjson,"allpeers",array);
return(jprint(retjson,1));
}
free_json(json);
} else retstr = clonestr("{\"error\":\"cant parse JSON\"}");
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"null return\"}");
return(retstr);
}
char *SuperNET_p2p(struct iguana_info *coin,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen)
{
cJSON *json,*retjson; char *retstr = 0;
if ( (json= cJSON_Parse((char *)data)) != 0 )
{
printf("GOT >>>>>>>> SUPERNET P2P.(%s)\n",(char *)data);
if ( (retstr = iguana_JSON(coin,(char *)data,ipaddr)) != 0 )
else
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
if ( (symbol= jstr(json,"coin")) != 0 && strlen(symbol) < sizeof(SYM)-1 )
{
if ( jobj(retjson,"result") != 0 || jobj(retjson,"error") != 0 || jobj(retjson,"method") == 0 )
strcpy(SYM,symbol);
touppercase(SYM);
if ( (coin= iguana_coinfind(SYM)) == 0 )
{
free(retstr);
retstr = 0;
if ( strcmp(method,"addcoin") == 0 )
coin = iguana_coinadd(SYM);
}
free_json(retjson);
if ( coin != 0 )
return(iguana_coinjson(coin,method,json));
else return(clonestr("{\"error\":\"cant get coin info\"}"));
}
}
free_json(json);
}
return(retstr);
}
/*void iguana_issuejsonstrM(void *arg)
{
cJSON *json; int32_t fd; char *retjsonstr,*jsonstr = arg;
retjsonstr = iguana_JSON(jsonstr);
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( (fd= juint(json,"retdest")) > 0 )
{
send(fd,jsonstr,(int32_t)strlen(jsonstr)+1,MSG_NOSIGNAL);
}
free_json(json);
return;
}
printf("%s\n",retjsonstr);
free(retjsonstr);//,strlen(retjsonstr)+1);
free(jsonstr);//,strlen(jsonstr)+1);
}*/
void iguana_main(void *arg)
{
char helperstr[64],*helperargs,*coinargs=0,*retstr,*secret,*jsonstr = arg;
int32_t i,len,flag; cJSON *json; uint8_t secretbuf[512];
// portable_OS_init()?
mycalloc(0,0,0);
array = 0;
if ( strcmp(method,"getpeers") == 0 )
{
char str[65]; struct tai t; double startmillis; int32_t datenum,seconds; uint64_t i,checkval,timestamp,now = (uint32_t)time(NULL);
startmillis = OS_milliseconds();
for (i=0; i<1000000; i++)
if ( (coinstr= jstr(json,"coin")) != 0 )
{
timestamp = now - (rand() % 100000000LL); // range -100000000LL to +500000000LL
datenum = OS_conv_unixtime(&t,&seconds,timestamp); // gmtime -> datenum + number of seconds
checkval = OS_conv_datenum(datenum,seconds/3600,(seconds/60)%60,seconds%60); // datenum+H:M:S -> unix time
if ( checkval != timestamp )
printf("%s i.%lld timestamp.%-12llu -> (%d:%06d) -> checkval.%-12llu diff.[%lld]\n",tai_str(str,t),(long long)i,(long long)timestamp,datenum,seconds,(long long)checkval,(long long)(timestamp-checkval));
if ( (array= iguana_peersjson(iguana_coinfind(coinstr),1)) == 0 )
return(clonestr("{\"error\":\"coin not found\"}"));
}
printf("million tai compares in %.3f microseconds per encode/decode\n",1000. * (OS_milliseconds()-startmillis)/i);
}
if ( (retstr= iguana_addagent("ramchain",ramchain_parser,"127.0.0.1",cJSON_Parse("[\"block\", \"tx\", \"txs\", \"rawtx\", \"balance\", \"totalreceived\", \"totalsent\", \"utxo\", \"status\"]"),0,0,0)) != 0 )
printf("%s\n",retstr), free(retstr);
if ( (retstr= iguana_addagent("pangea",pangea_parser,"127.0.0.1",cJSON_Parse("[\"test\"]"),0,0,0)) != 0 )
printf("%s\n",retstr), free(retstr);
if ( (retstr= iguana_addagent("InstantDEX",InstantDEX_parser,"127.0.0.1",cJSON_Parse("[\"test\"]"),0,0,0)) != 0 )
printf("%s\n",retstr), free(retstr);
if ( (retstr= iguana_addagent("jumblr",jumblr_parser,"127.0.0.1",cJSON_Parse("[\"test\"]"),0,0,0)) != 0 )
printf("%s\n",retstr), free(retstr);
iguana_initQ(&helperQ,"helperQ");
OS_ensure_directory("confs");
OS_ensure_directory("DB");
OS_ensure_directory("tmp");
if ( jsonstr != 0 && (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( jobj(json,"numhelpers") != 0 )
IGUANA_NUMHELPERS = juint(json,"numhelpers");
if ( (secret= jstr(json,"secret")) != 0 )
else
{
len = (int32_t)strlen(secret);
if ( is_hexstr(secret,0) != 0 && len <= (sizeof(secretbuf)<<1) )
n = 0;
array = cJSON_CreateArray();
r = rand();
for (i=0; i<IGUANA_MAXCOINS; i++)
{
len >>= 1;
decode_hex(secretbuf,len,secret);
} else vcalc_sha256(0,secretbuf,(void *)secret,len), len = sizeof(bits256);
j = (r + i) % IGUANA_MAXCOINS;
if ( (coin= Coins[j]) != 0 )
{
rr = rand();
for (k=0; k<IGUANA_MAXPEERS; k++)
{
l = (rr + k) % IGUANA_MAXPEERS;
addr = &coin->peers.active[l];
if ( addr->usock >= 0 && addr->supernet != 0 )
{
jaddistr(array,addr->ipaddr);
if ( ++n >= 64 )
break;
}
}
}
}
}
if ( jobj(json,"coins") != 0 )
coinargs = jsonstr;
}
if ( IGUANA_NUMHELPERS == 0 )
IGUANA_NUMHELPERS = 1;
for (i=0; i<IGUANA_NUMHELPERS; i++)
{
sprintf(helperstr,"{\"name\":\"helper.%d\"}",i);
helperargs = clonestr(helperstr);
iguana_launch(iguana_coinadd("BTCD"),"iguana_helper",iguana_helper,helperargs,IGUANA_PERMTHREAD);
}
iguana_launch(iguana_coinadd("BTCD"),"rpcloop",iguana_rpcloop,iguana_coinadd("BTCD"),IGUANA_PERMTHREAD);
if ( coinargs != 0 )
iguana_launch(iguana_coinadd("BTCD"),"iguana_coins",iguana_coins,coinargs,IGUANA_PERMTHREAD);
else if ( 1 )
{
#ifdef __APPLE__
sleep(1);
iguana_JSON(iguana_coinfind("BTCD"),"{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":16,\"coin\":\"BTCD\",\"active\":1}",0);
#endif
if ( array != 0 )
{
retjson = cJSON_CreateObject();
jaddstr(retjson,"agent","SuperNET");
jaddstr(retjson,"method","mypeers");
jaddstr(retjson,"result","peers found");
jadd(retjson,"peers",array);
return(jprint(retjson,1));
} else return(clonestr("{\"error\":\"no peers found\"}"));
}
if ( arg != 0 )
iguana_JSON(0,arg,0);
//init_InstantDEX();
while ( 1 )
else if ( strcmp(method,"mypeers") == 0 )
{
flag = 0;
for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
if ( Coins[i] != 0 && Coins[i]->symbol[0] != 0 )
flag += iguana_processjsonQ(Coins[i]);
if ( flag == 0 )
usleep(100000);
printf("mypeers from %s\n",remoteaddr!=0?remoteaddr:"local");
}
return(clonestr("{\"result\":\"stub processed generic json\"}"));
}

2
iguana/iguana_msg.c

@ -422,7 +422,7 @@ int32_t iguana_send_hashes(struct iguana_info *coin,char *command,struct iguana_
return(retval);
}
int32_t iguana_parser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen)
int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen)
{
uint8_t serialized[512]; char *retstr;
int32_t i,retval,delay,srvmsg,bloom,intvectors,len= -100; uint64_t nonce,x; uint32_t type; bits256 hash2;

4
iguana/iguana_peers.c

@ -480,7 +480,7 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig
iguana_meminit(&addr->HASHMEM,"HASHPTRS",0,256,0);//IGUANA_MAXPACKETSIZE*16,0);
//printf("Init %s memory %p %p %p\n",addr->ipaddr,addr->RAWMEM.ptr,addr->TXDATA.ptr,addr->HASHMEM.ptr);
}
if ( iguana_parser(coin,addr,&addr->RAWMEM,&addr->TXDATA,&addr->HASHMEM,H,buf,len) < 0 || addr->dead != 0 )
if ( iguana_msgparser(coin,addr,&addr->RAWMEM,&addr->TXDATA,&addr->HASHMEM,H,buf,len) < 0 || addr->dead != 0 )
{
printf("%p addr->dead.%d or parser break at %u\n",&addr->dead,addr->dead,(uint32_t)time(NULL));
addr->dead = (uint32_t)time(NULL);
@ -706,7 +706,7 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
free_queueitem(ipaddr);
return((uint32_t)time(NULL));
}
else if ( coin->peers.active[i].ipaddr != 0 )
else if ( coin->peers.active[i].ipaddr[0] != 0 )
n++;
}
if ( n >= coin->MAXPEERS-(coin->MAXPEERS>>3)-1 )

179
iguana/iguana_rpc.c

@ -14,60 +14,7 @@
******************************************************************************/
#include "iguana777.h"
int32_t iguana_rpctestvector(struct iguana_info *coin,char *checkstr,char *jsonstr,int32_t maxlen,int32_t testi)
{
int32_t len,checklen;
sprintf(jsonstr,"{\"rpc.%s testvector.%d\"}",coin->symbol,testi);
sprintf(checkstr,"{\"rpc.%s testvector.%d checkstr should have all info needed to verify the rpc request\"}",coin->symbol,testi);
len = (int32_t)strlen(jsonstr);
checklen = (int32_t)strlen(checkstr);
if ( len > maxlen || checklen > maxlen )
printf("iguana_rpctestvector: i was bad and overflowed buffer len.%d checklen.%d\n",len,checklen), exit(-1);
if ( checklen > len )
len = checklen;
return(len);
}
int32_t iguana_rpctestcheck(struct iguana_info *coin,char *jsonstr,char *retjsonstr)
{
if ( (rand() % 100) == 0 ) // 1% failure rate
return(-1);
else return(0);
}
int32_t iguana_rpctest(struct iguana_info *coin)
{
/* static int32_t testi,good,bad;
char *retjsonstr,jsonstr[4096],checkstr[sizeof(jsonstr)]; // should be big enough
//if ( (rand() % 1000) < 999 ) // if no test active, just return 0
return(0);
if ( iguana_rpctestvector(coin,checkstr,jsonstr,sizeof(jsonstr),testi++) > 0 )
{
retjsonstr = iguana_rpc(coin,jsonstr);
if ( iguana_rpctestcheck(coin,jsonstr,retjsonstr) < 0 )
bad++, printf("rpctestcheck.%s error: (%s) -> (%s) | good.%d bad.%d %.2f%%\n",coin->symbol,jsonstr,retjsonstr,good,bad,100.*(double)good/(good+bad));
else good++;
free(retjsonstr);
return(1); // indicates was active
}*/
return(0);
}
char *pangea_parser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json)
{
return(clonestr("{\"error\":\"pangea API is not yet\"}"));
}
char *InstantDEX_parser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json)
{
return(clonestr("{\"error\":\"InstantDEX API is not yet\"}"));
}
char *jumblr_parser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json)
{
return(clonestr("{\"error\":\"jumblr API is not yet\"}"));
}
#include "SuperNET.h"
struct iguana_txid *iguana_blocktx(struct iguana_info *coin,struct iguana_txid *tx,struct iguana_block *block,int32_t i)
{
@ -441,9 +388,9 @@ char *iguana_jsoncheck(char *retstr,int32_t freeflag)
return(0);
}
char *ramchain_parser(struct iguana_agent *agent,struct iguana_info *coin,char *method,cJSON *json)
char *ramchain_parser(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr)
{
char *symbol,*str,*retstr; int32_t height; cJSON *argjson,*obj;
char *symbol,*str,*retstr; int32_t height; cJSON *argjson,*obj; struct iguana_info *coin = 0;
/*{"agent":"ramchain","method":"block","coin":"BTCD","hash":"<sha256hash>"}
{"agent":"ramchain","method":"block","coin":"BTCD","height":345600}
{"agent":"ramchain","method":"tx","coin":"BTCD","txid":"<sha txid>"}
@ -506,8 +453,8 @@ char *ramchain_parser(struct iguana_agent *agent,struct iguana_info *coin,char *
return(ramchain_coinparser(coin,method,json));
}
/*
#define RPCARGS struct iguana_info *coin,struct iguana_wallet *wallet,cJSON *params[],int32_t n,char *origstr,char *remoteaddr
#define RPCARGS struct supernet_info *myinfo,struct iguana_info *coin,cJSON *params[],int32_t n,cJSON *json,char *remoteaddr
// MAP bitcoin RPC to SuperNET JSONstr
// MAP REST to SuperNET JSONstr
@ -524,15 +471,17 @@ static char *stop(RPCARGS)
static char *sendalert(RPCARGS)
{
return(0);
}
static char *SuperNET(RPCARGS)
{
return(iguana_JSON(coin,origstr,remoteaddr));
return(SuperNET_JSON(myinfo,json,remoteaddr));
}
static char *getrawmempool(RPCARGS)
{
return(0);
}
// peers
@ -558,10 +507,11 @@ static char *getpeerinfo(RPCARGS)
static char *addnode(RPCARGS)
{
// addnode <node> <add/remove/onetry> version 0.8 Attempts add or remove <node> from the addnode list or try a connection to <node> once. N
return(0);
}
// address and pubkeys
int32_t iguana_waddresscalc(struct iguana_info *coin,struct iguana_waddress *addr,bits256 privkey)
struct iguana_waddress *iguana_waddresscalc(struct iguana_info *coin,struct iguana_waddress *addr,bits256 privkey)
{
memset(addr,0,sizeof(*addr));
addr->privkey = privkey;
@ -569,9 +519,15 @@ int32_t iguana_waddresscalc(struct iguana_info *coin,struct iguana_waddress *add
{
addr->wiptype = coin->chain->wipval;
addr->type = coin->chain->pubval;
return(0);
return(addr);
}
return(-1);
return(0);
}
int32_t iguana_addressvalidate(struct iguana_info *coin,char *coinaddr)
{
// verify checksum bytes
return(0);
}
static char *validateretstr(struct iguana_info *coin,char *coinaddr)
@ -611,6 +567,7 @@ static char *validatepubkey(RPCARGS)
static char *createmultisig(RPCARGS)
{
return(0);
}
// blockchain
@ -637,43 +594,53 @@ static char *getblockcount(RPCARGS)
static char *getblock(RPCARGS)
{
return(0);
}
static char *getblockhash(RPCARGS)
{
return(0);
}
static char *gettransaction(RPCARGS)
{
return(0);
}
static char *listtransactions(RPCARGS)
{
return(0);
}
static char *getreceivedbyaddress(RPCARGS)
{
return(0);
}
static char *listreceivedbyaddress(RPCARGS)
{
return(0);
}
static char *listsinceblock(RPCARGS)
{
return(0);
}
// waccount and waddress funcs
static char *getreceivedbyaccount(RPCARGS)
{
return(0);
}
static char *listreceivedbyaccount(RPCARGS)
{
return(0);
}
static char *addmultisigaddress(RPCARGS)
{
return(0);
}
static char *getnewaddress(RPCARGS)
@ -712,13 +679,14 @@ static char *makekeypair(RPCARGS)
static char *getaccountaddress(RPCARGS)
{
struct iguana_waddress *waddr,addr; char str[67]; char *account,*coinaddr; cJSON *retjson;
if ( params[0] != 0 && (coinaddr= jstr(params[0],0)) != 0 )
struct iguana_waccount *wacct; struct iguana_waddress *waddr=0,addr; char str[67]; char *account; cJSON *retjson;
if ( params[0] != 0 && (account= jstr(params[0],0)) != 0 )
{
if ( (waddr= iguana_waccountfind(coin,account)) == 0 )
if ( (wacct= iguana_waccountfind(coin,account)) == 0 )
{
if ( (waddr= iguana_waddresscalc(coin,&addr,rand256(1))) == 0 )
return(clonestr("{\"error\":\"cant generate address\"}"));
iguana_waccountswitch(coin,account,0,-1,addr.coinaddr);
}
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",waddr->coinaddr);
@ -736,17 +704,17 @@ static char *getaccountaddress(RPCARGS)
static char *setaccount(RPCARGS)
{
struct iguana_waddress *waddr,addr; char *account,*coinaddr;
struct iguana_waccount *wacct; struct iguana_waddress *waddr=0,addr; int32_t ind=-1; char *account,*coinaddr;
if ( params[0] != 0 && (coinaddr= jstr(params[0],0)) != 0 && params[1] != 0 && (account= jstr(params[1],0)) != 0 )
{
if ( iguana_addressvalidate(coin,coinaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
if ( (waddr= iguana_waddressfind(coin,coinaddr)) == 0 )
if ( (wacct= iguana_waddressfind(coin,&ind,coinaddr)) == 0 )
{
if ( (waddr= iguana_waddresscalc(coin,&addr,rand256(1))) == 0 )
return(clonestr("{\"error\":\"cant generate address\"}"));
}
iguana_waccountswitch(coin,waddr,coinaddr);
iguana_waccountswitch(coin,account,wacct,ind,coinaddr);
return(clonestr("{\"result\":\"account set\"}"));
}
return(clonestr("{\"error\":\"need address and account\"}"));
@ -754,15 +722,15 @@ static char *setaccount(RPCARGS)
static char *getaccount(RPCARGS)
{
struct iguana_waddress *waddr,addr; char *account,*coinaddr; cJSON *retjson;
struct iguana_waccount *wacct; char *coinaddr; cJSON *retjson; int32_t ind;
if ( params[0] != 0 && (coinaddr= jstr(params[0],0)) != 0 )
{
if ( iguana_addressvalidate(coin,coinaddr) < 0 )
return(clonestr("{\"error\":\"invalid coin address\"}"));
if ( (waddr= iguana_waccountfind(coin,account)) == 0 )
if ( (wacct= iguana_waddressfind(coin,&ind,coinaddr)) == 0 )
return(clonestr("{\"result\":\"no account for address\"}"));
retjson = cJSON_CreateObject();
jaddstr(retjson,"result",waddr->account);
jaddstr(retjson,"result",wacct->account);
return(jprint(retjson,1));
}
return(clonestr("{\"error\":\"need address\"}"));
@ -770,11 +738,11 @@ static char *getaccount(RPCARGS)
static char *getaddressesbyaccount(RPCARGS)
{
struct iguana_waccount *subset; char *account; cJSON *retjson,*array;
struct iguana_waccount *subset; struct iguana_waddress *waddr,*tmp; char *account; cJSON *retjson,*array;
retjson = cJSON_CreateObject();
array = cJSON_CreateArray();
if ( params[0] != 0 && (account= jstr(params[0],0)) != 0 )
{
array = cJSON_CreateArray();
if ( (subset= iguana_waccountfind(coin,account)) != 0 )
{
HASH_ITER(hh,subset->waddrs,waddr,tmp)
@ -789,91 +757,116 @@ static char *getaddressesbyaccount(RPCARGS)
static char *listaddressgroupings(RPCARGS)
{
return(0);
}
static char *getbalance(RPCARGS)
{
return(0);
}
// wallet
static char *listaccounts(RPCARGS)
{
return(0);
}
static char *dumpprivkey(RPCARGS)
{
return(0);
}
static char *importprivkey(RPCARGS)
{
return(0);
}
static char *dumpwallet(RPCARGS)
{
return(0);
}
static char *importwallet(RPCARGS)
{
return(0);
}
static char *walletpassphrase(RPCARGS)
{
return(0);
}
static char *walletpassphrasechange(RPCARGS)
{
return(0);
}
static char *walletlock(RPCARGS)
{
return(0);
}
static char *encryptwallet(RPCARGS)
{
return(0);
}
static char *checkwallet(RPCARGS)
{
return(0);
}
static char *repairwallet(RPCARGS)
{
return(0);
}
static char *backupwallet(RPCARGS)
{
return(0);
}
// messages
static char *signmessage(RPCARGS)
{
return(0);
}
static char *verifymessage(RPCARGS)
{
return(0);
}
// unspents
static char *listunspent(RPCARGS)
{
return(0);
}
static char *lockunspent(RPCARGS)
{
return(0);
}
static char *listlockunspent(RPCARGS)
{
return(0);
}
static char *gettxout(RPCARGS)
{
return(0);
}
static char *gettxoutsetinfo(RPCARGS)
{
return(0);
}
// payments
static char *sendtoaddress(RPCARGS)
{
struct iguana_waddress *waddr,addr; char *account,*coinaddr,*comment=0,*comment2=0; double amount = -1.;
char *coinaddr,*comment=0,*comment2=0; double amount = -1.;
//sendtoaddress <bitcoinaddress> <amount> [comment] [comment-to] <amount> is a real and is rounded to 8 decimal places. Returns the transaction ID <txid> if successful. Y
if ( params[0] != 0 && (coinaddr= jstr(params[0],0)) != 0 && params[1] != 0 && is_cJSON_Number(params[1]) != 0 )
{
@ -882,60 +875,74 @@ static char *sendtoaddress(RPCARGS)
amount = jdouble(params[1],0);
comment = jstr(params[2],0);
comment2 = jstr(params[3],0);
printf("need to generate send %.8f to %s [%s] [%s]\n",dstr(amount),coinaddr,comment!=0?comment:"",comment2!=0comment2:"");
printf("need to generate send %.8f to %s [%s] [%s]\n",dstr(amount),coinaddr,comment!=0?comment:"",comment2!=0?comment2:"");
}
return(clonestr("{\"error\":\"need address and amount\"}"));
}
static char *move(RPCARGS)
static char *movecmd(RPCARGS)
{
return(0);
}
static char *sendfrom(RPCARGS)
{
return(0);
}
static char *sendmany(RPCARGS)
{
return(0);
}
static char *settxfee(RPCARGS)
{
return(0);
}
// rawtransaction
static char *getrawtransaction(RPCARGS)
{
return(0);
}
static char *createrawtransaction(RPCARGS)
{
return(0);
}
static char *decoderawtransaction(RPCARGS)
{
return(0);
}
static char *decodescript(RPCARGS)
{
return(0);
}
static char *signrawtransaction(RPCARGS)
{
return(0);
}
static char *sendrawtransaction(RPCARGS)
{
return(0);
}
static char *resendtx(RPCARGS)
{
return(0);
}
static char *getrawchangeaddress(RPCARGS)
{
return(0);
}
#define true 1
#define false 0
struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,flag1; } RPCcalls[] =
{
{ "help", &help, true, true },
@ -996,13 +1003,14 @@ struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,flag1; }
{ "makekeypair", &makekeypair, false, true},
{ "sendalert", &sendalert, false, false},
//
{ "addnode", &addnode, false, false},
{ "createmultisig", &createmultisig, false, false},
{ "addnode", &addnode, false, false},
{ "getrawmempool", &getrawmempool, false, false},
{ "getrawchangeaddress", &getrawchangeaddress, false, false},
{ "listlockunspent", &listlockunspent, false, false},
{ "lockunspent", &lockunspent, false, false},
{ "gettxout", &gettxout, false, false},
{ "gettxoutsetinfo", &gettxoutsetinfo, false, false}]
{ "gettxoutsetinfo", &gettxoutsetinfo, false, false}
#ifdef PEGGY
//{ "peggytx", &peggytx, true, false },
//{ "peggypayments", &peggypayments, true, false },
@ -1024,38 +1032,38 @@ struct RPC_info { char *name; char *(*rpcfunc)(RPCARGS); int32_t flag0,flag1; }
// { "reservebalance", &reservebalance, false, true},
};
char *iguana_bitcoinrpc(struct iguana_info *coin,struct iguana_wallet *wallet,char *method,cJSON *params,int32_t n,char *origstr,char *remoteaddr)
char *iguana_bitcoinrpc(struct supernet_info *myinfo,struct iguana_info *coin,char *method,cJSON *params[16],int32_t n,cJSON *json,char *remoteaddr)
{
int32_t i;
for (i=0; i<sizeof(RPCcalls)/sizeof(*RPCcalls); i++)
{
if ( strcmp(RPCcalls[i].name,method) == 0 )
return((*RPCcalls[i].rpcfunc)(coin,wallet,params,n,origstr,remoteaddr));
return((*RPCcalls[i].rpcfunc)(myinfo,coin,params,n,json,remoteaddr));
}
return(clonestr("{\"error\":\"invalid coin address\"}"));
}
char *iguana_bitcoinRPC(struct iguana_info *coin,struct supernet_info *myinfo,char *jsonstr,char *remoteaddr)
{
cJSON *json,*obj0,*params[16]; char *method; int32_t n; char *retstr = 0;
cJSON *json,*params[16],*array; char *method; int32_t i,n; char *retstr = 0;
memset(params,0,sizeof(params));
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( (method= jstr(json,"method")) != 0 )
{
if ( (params= jarray(&n,json,"params")) == 0 )
if ( (array= jarray(&n,json,"params")) == 0 )
{
n = 1;
params[0] = jobj(json,"params");
}
else
{
params[0] = jitem(params,0);
params[0] = jitem(array,0);
if ( n > 1 )
for (i=1; i<n; i++)
params[i] = jitem(params,i);
params[i] = jitem(array,i);
}
retstr = iguana_bitcoin(coin,myinfo,method,params,n,jsonstr,remoteaddr);
retstr = iguana_bitcoinrpc(myinfo,coin,method,params,n,json,remoteaddr);
}
free_json(json);
}
@ -1063,4 +1071,3 @@ char *iguana_bitcoinRPC(struct iguana_info *coin,struct supernet_info *myinfo,ch
retstr = clonestr("{\"error\":\"cant parse jsonstr\"}");
return(retstr);
}
*/

4
iguana/iguana_wallet.c

@ -42,14 +42,14 @@ struct iguana_waccount *iguana_waccountadd(struct iguana_info *coin,char *wallet
return(acct);
}
int32_t iguana_waccountswitch(struct iguana_info *coin,struct iguana_waddress *waddr,char *coinaddr)
int32_t iguana_waccountswitch(struct iguana_info *coin,char *account,struct iguana_waccount *oldwaddr,int32_t oldind,char *coinaddr)
{
// what if coinaddr is already in an account?
//printf("change %s walletaccount.(%s) (%s) <- %s\n",coin->symbol,waddr->account,waddr->coinaddr,coinaddr);
return(0);
}
struct iguana_waddress *iguana_waddressfind(struct iguana_info *coin,char *coinaddr)
struct iguana_waccount *iguana_waddressfind(struct iguana_info *coin,int32_t *indp,char *coinaddr)
{
return(0);
}

789
iguana/main.c

@ -22,6 +22,7 @@
#include "../pnacl_main.h"
#include "iguana777.h"
#include "SuperNET.h"
// ALL globals must be here!
struct iguana_info *Coins[IGUANA_MAXCOINS];
@ -29,7 +30,7 @@ int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel;
uint32_t prices777_NXTBLOCK,MAX_DEPTH = 100;
char NXTAPIURL[256],IGUANA_NXTADDR[256],IGUANA_NXTACCTSECRET[256];
uint64_t IGUANA_MY64BITS;
queue_t helperQ;
queue_t helperQ,jsonQ,finishedQ;
static int32_t initflag;
#ifdef __linux__
int32_t IGUANA_NUMHELPERS = 4;
@ -37,626 +38,284 @@ int32_t IGUANA_NUMHELPERS = 4;
int32_t IGUANA_NUMHELPERS = 1;
#endif
#ifdef oldway
void *iguana(void *arg)
char *hash_parser(struct supernet_info *myinfo,char *hashname,cJSON *json,char *remoteaddr)
{
if ( arg == 0 )
#ifdef __linux__
arg = 0;//"{\"coins\":[{\"name\":\"BTCD\",\"maxpeers\":128,\"initialheight\":400000,\"services\":1,\"peers\":[\"127.0.0.1\"]}]}";
//arg = "{\"coins\":[{\"name\":\"BTCD\",\"services\":1,\"maxrecvcache\":64,\"peers\":[\"127.0.0.1\",\"107.170.13.184\",\"108.58.252.82\",\"207.182.151.130\",\"70.106.255.189\"]}]}";
#else
arg = 0;//"{\"coins\":[{\"name\":\"BTCD\",\"maxpeers\":128,\"initialheight\":400000,\"services\":1,\"peers\":[\"127.0.0.1\"]}]}";
#endif
PostMessage("iguana start.(%s)\n",(char *)arg);
while ( initflag == 0 )
sleep(1);
iguana_main(arg);
return(0);
}
#ifdef __PNACL
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/select.h>
#include <sys/stat.h>
#include "includes/ppapi/c/ppb.h"
#include "includes/ppapi/c/ppb_var.h"
#include "includes/ppapi/c/ppb_instance.h"
#include "includes/ppapi/c/ppb_messaging.h"
#include "includes/ppapi/c/ppb_var_array.h"
#include "includes/ppapi/c/ppb_var_dictionary.h"
#include "includes/ppapi/c/pp_errors.h"
#include "includes/ppapi/c/ppp_messaging.h"
#include "includes/ppapi/c/ppp_instance.h"
typedef int (*PSMainFunc_t)(int argc, char *argv[]);
#if defined(WIN32)
#define va_copy(d, s) ((d) = (s))
#endif
#ifndef __PNACL
int32_t PSGetInstanceId()
{
return(4);
}
#endif
typedef int (*HandleFunc)(struct PP_Var params,struct PP_Var* out_var,const char** error);
typedef struct { const char* name; HandleFunc function; } FuncNameMapping;
static PP_Instance g_instance = 0;
static PPB_GetInterface g_get_browser_interface = NULL;
static PPB_Messaging* g_ppb_messaging = NULL;
PPB_Var* g_ppb_var = NULL;
PPB_VarArray* g_ppb_var_array = NULL;
PPB_VarDictionary* g_ppb_var_dictionary = NULL;
int Handle_iguana(struct PP_Var params,struct PP_Var *output,const char **out_error);
static FuncNameMapping g_function_map[] = { { "iguana", Handle_iguana }, { NULL, NULL } };
struct PP_Var CStrToVar(const char* str) { return g_ppb_var->VarFromUtf8(str, (int32_t)strlen(str)); }
char *VprintfToNewString(const char* format, va_list args)
{
va_list args_copy; int length; char *buffer; int result;
va_copy(args_copy, args);
length = vsnprintf(NULL, 0, format, args);
buffer = (char*)malloc(length + 1); // +1 for NULL-terminator.
result = vsnprintf(&buffer[0], length + 1, format, args_copy);
if ( result != length )
int32_t i,len,iter,n; uint8_t databuf[512];
char hexstr[1025],*password,*name,*msg;
typedef void (*hashfunc)(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len);
typedef char *(*hmacfunc)(char *dest,char *key,int32_t key_size,char *message);
struct hashfunc_entry { char *name; hashfunc hashfunc; };
struct hmacfunc_entry { char *name; hmacfunc hmacfunc; };
struct hashfunc_entry hashes[] = { {"NXT",calc_NXTaddr}, {"curve25519",calc_curve25519_str }, {"base64_encode",calc_base64_encodestr}, {"base64_decode",calc_base64_decodestr}, {"crc32",calc_crc32str}, {"rmd160_sha256",rmd160ofsha256}, {"sha256_sha256",sha256_sha256}, {"sha256",vcalc_sha256}, {"sha512",calc_sha512}, {"sha384",calc_sha384}, {"sha224",calc_sha224}, {"rmd160",calc_rmd160}, {"rmd256",calc_rmd256}, {"rmd320",calc_rmd320}, {"rmd128",calc_rmd128}, {"sha1",calc_sha1}, {"md5",calc_md5str}, {"tiger",calc_tiger}, {"whirlpool",calc_whirlpool} };
struct hmacfunc_entry hmacs[] = { {"hmac_sha256",hmac_sha256_str}, {"hmac_sha512",hmac_sha512_str}, {"hmac_sha384",hmac_sha384_str}, {"hmac_sha224",hmac_sha224_str}, {"hmac_rmd160",hmac_rmd160_str}, {"hmac_rmd256",hmac_rmd256_str}, {"hmac_rmd320",hmac_rmd320_str}, {"hmac_rmd128",hmac_rmd128_str}, {"hmac_sha1",hmac_sha1_str}, {"hmac_md5",hmac_md5_str}, {"hmac_tiger",hmac_tiger_str}, {"hmac_whirlpool",hmac_whirlpool_str} };
if ( (msg= jstr(json,"message")) == 0 )
return(clonestr("{\"error\":\"no message to hash\"}"));
password = jstr(json,"password");
n = (int32_t)sizeof(hashes)/sizeof(*hashes);
printf("msg.(%s) password.(%s)\n",msg,password!=0?password:"");
for (iter=0; iter<2; iter++)
{
assert(0);
return NULL;
for (i=0; i<n; i++)
{
name = (iter == 0) ? hashes[i].name : hmacs[i].name;
printf("iter.%d i.%d (%s) vs (%s) %d\n",iter,i,name,hashname,strcmp(hashname,name) == 0);
if ( strcmp(hashname,name) == 0 )
{
json = cJSON_CreateObject();
len = (int32_t)strlen(msg);
if ( iter == 0 )
(*hashes[i].hashfunc)(hexstr,databuf,(uint8_t *)msg,len);
else (*hmacs[i].hmacfunc)(hexstr,password,(int32_t)strlen(password),msg);
jaddstr(json,"result","hash calculated");
jaddstr(json,"message",msg);
jaddstr(json,name,hexstr);
return(jprint(json,1));
}
}
n = (int32_t)sizeof(hmacs)/sizeof(*hmacs);
}
return buffer;
return(clonestr("{\"error\":\"cant find hash function\"}"));
}
char *PrintfToNewString(const char *format, ...)
char *InstantDEX_parser(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr)
{
va_list args; char *result;
va_start(args, format);
result = VprintfToNewString(format, args);
va_end(args);
return result;
return(clonestr("{\"error\":\"InstantDEX API is not yet\"}"));
}
struct PP_Var VprintfToVar(const char* format, va_list args)
char *jumblr_parser(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr)
{
struct PP_Var var; char *string = VprintfToNewString(format, args);
var = g_ppb_var->VarFromUtf8(string, (int32_t)strlen(string));
free(string);
return var;
return(clonestr("{\"error\":\"jumblr API is not yet\"}"));
}
static const char *VarToCStr(struct PP_Var var)
char *pangea_parser(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr)
{
uint32_t length; char *new_str; const char *str = g_ppb_var->VarToUtf8(var, &length);
if ( str == NULL )
return NULL;
new_str = (char*)malloc(length + 1);
memcpy(new_str, str, length); // str is NOT NULL-terminated. Copy using memcpy.
new_str[length] = 0;
return new_str;
return(clonestr("{\"error\":\"jumblr API is not yet\"}"));
}
struct PP_Var GetDictVar(struct PP_Var dict, const char* key)
char *SuperNET_jsonstr(struct supernet_info *myinfo,char *jsonstr,char *remoteaddr)
{
struct PP_Var key_var = CStrToVar(key);
struct PP_Var value = g_ppb_var_dictionary->Get(dict, key_var);
g_ppb_var->Release(key_var);
return value;
cJSON *json; char *agent,*method;
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
if ( (agent= jstr(json,"agent")) != 0 && (method= jstr(json,"method")) != 0 )
{
if ( strcmp(agent,"iguana") == 0 )
return(iguana_parser(myinfo,method,json,remoteaddr));
else if ( strcmp(agent,"ramchain") == 0 )
return(ramchain_parser(myinfo,method,json,remoteaddr));
else if ( strcmp(agent,"InstantDEX") == 0 )
return(InstantDEX_parser(myinfo,method,json,remoteaddr));
else if ( strcmp(agent,"pangea") == 0 )
return(pangea_parser(myinfo,method,json,remoteaddr));
else if ( strcmp(agent,"jumblr") == 0 )
return(jumblr_parser(myinfo,method,json,remoteaddr));
else if ( strcmp(agent,"hash") == 0 )
return(hash_parser(myinfo,method,json,remoteaddr));
}
return(clonestr("{\"error\":\"need both agent and method\"}"));
}
return(clonestr("{\"error\":\"couldnt parse SuperNET_JSON\"}"));
}
void PostMessage(const char* format, ...)
{
va_list args;
va_start(args, format);
#ifdef __PNACL
struct PP_Var var;
var = VprintfToVar(format, args);
g_ppb_messaging->PostMessage(g_instance, var);
g_ppb_var->Release(var);
#else
printf(format,args);
#endif
va_end(args);
}
struct iguana_jsonitem { struct queueitem DL; struct supernet_info *myinfo; uint32_t fallback,expired,allocsize; char **retjsonstrp; char remoteaddr[64]; char jsonstr[]; };
/**
* Given a message from JavaScript, parse it for functions and parameters.
*
* The format of the message is:
* {
* "cmd": <function name>,
* "args": [<arg0>, <arg1>, ...]
* }
*
* @param[in] message The message to parse.
* @param[out] out_function The function name.
* @param[out] out_params A PP_Var array.
* @return 0 if successful, otherwise 1.
*/
static int ParseMessage(struct PP_Var message,const char **out_function,struct PP_Var *out_params)
int32_t iguana_jsonQ()
{
if ( message.type != PP_VARTYPE_DICTIONARY )
return(1);
struct PP_Var cmd_value = GetDictVar(message, "cmd");
*out_function = VarToCStr(cmd_value);
g_ppb_var->Release(cmd_value);
*out_params = GetDictVar(message, "args");
PostMessage("Parse.(%s) cmd.(%s)\n",*out_function,VarToCStr(*out_params));
if ( cmd_value.type != PP_VARTYPE_STRING )
return(1);
if ( out_params->type != PP_VARTYPE_ARRAY )
struct iguana_jsonitem *ptr;
if ( (ptr= queue_dequeue(&finishedQ,0)) != 0 )
{
if ( ptr->expired != 0 )
{
*ptr->retjsonstrp = clonestr("{\"error\":\"request timeout\"}");
printf("garbage collection: expired.(%s)\n",ptr->jsonstr);
myfree(ptr,ptr->allocsize);
} else queue_enqueue("finishedQ",&finishedQ,&ptr->DL,0);
}
if ( (ptr= queue_dequeue(&jsonQ,0)) != 0 )
{
printf("process.(%s)\n",ptr->jsonstr);
if ( (*ptr->retjsonstrp= SuperNET_jsonstr(ptr->myinfo,ptr->jsonstr,ptr->remoteaddr)) == 0 )
*ptr->retjsonstrp = clonestr("{\"error\":\"null return from iguana_jsonstr\"}");
printf("finished.(%s)\n",ptr->jsonstr);
queue_enqueue("finishedQ",&finishedQ,&ptr->DL,0);
return(1);
}
return(0);
}
static HandleFunc GetFunctionByName(const char* function_name)
char *iguana_blockingjsonstr(struct supernet_info *myinfo,char *jsonstr,uint64_t tag,int32_t maxmillis,char *remoteaddr)
{
FuncNameMapping* map_iter = g_function_map;
for (; map_iter->name; ++map_iter)
struct iguana_jsonitem *ptr; char *retjsonstr = 0; int32_t len,allocsize; double expiration;
expiration = OS_milliseconds() + maxmillis;
//printf("blocking case.(%s)\n",jsonstr);
len = (int32_t)strlen(jsonstr);
allocsize = sizeof(*ptr) + len + 1;
ptr = mycalloc('J',1,allocsize);
ptr->allocsize = allocsize;
ptr->myinfo = myinfo;
ptr->retjsonstrp = &retjsonstr;
safecopy(ptr->remoteaddr,remoteaddr,sizeof(ptr->remoteaddr));
memcpy(ptr->jsonstr,jsonstr,len+1);
queue_enqueue("jsonQ",&jsonQ,&ptr->DL,0);
while ( OS_milliseconds() < expiration )
{
if (strcmp(map_iter->name, function_name) == 0)
return map_iter->function;
usleep(100);
if ( retjsonstr != 0 )
{
printf("blocking retjsonstr.(%s)\n",retjsonstr);
queue_delete(&finishedQ,&ptr->DL,allocsize,1);
return(retjsonstr);
}
usleep(1000);
}
return NULL;
//printf("(%s) expired\n",jsonstr);
ptr->expired = (uint32_t)time(NULL);
return(clonestr("{\"error\":\"iguana jsonstr expired\"}"));
}
/**
* Handle as message from JavaScript on the worker thread.
*
* @param[in] message The message to parse and handle.
*/
static void HandleMessage(struct PP_Var message)
char *SuperNET_JSON(struct supernet_info *myinfo,cJSON *json,char *remoteaddr)
{
const char *function_name,*error; struct PP_Var params,result_var;
if ( ParseMessage(message, &function_name, &params) != 0 )
cJSON *retjson; uint64_t tag; uint32_t timeout; char *jsonstr; char *retjsonstr,*retstr = 0;
if ( json != 0 )
{
PostMessage("Error: Unable to parse message");
return;
}
HandleFunc function = GetFunctionByName(function_name);
if ( function == 0 )
{
PostMessage("Error: Unknown function \"%s\"", function_name); // Function name wasn't found.
return;
}
// Function name was found, call it.
int result = (*function)(params, &result_var, &error);
if ( result != 0 )
{
if ( error != NULL )
/*if ( localaccess != 0 && (method= jstr(json,"method")) != 0 && strcmp(method,"addcoin") == 0 )
{
PostMessage("Error: \"%s\" failed: %s.", function_name, error);
free((void*)error);
if ( (retval= iguana_launchcoin(jstr(json,"coin"),json)) > 0 )
return(clonestr("{\"result\":\"launched coin\"}"));
else if ( retval == 0 ) return(clonestr("{\"result\":\"coin already launched\"}"));
else return(clonestr("{\"error\":\"error launching coin\"}"));
}*/
if ( (tag= j64bits(json,"tag")) == 0 )
OS_randombytes((uint8_t *)&tag,sizeof(tag));
/*if ( (symbol= jstr(json,"coin")) != 0 )
{
coin = iguana_coinfind(symbol);
if ( coin != 0 && localaccess != 0 && coin->launched == 0 )
iguana_launchcoin(symbol,json);
}*/
if ( (timeout= juint(json,"timeout")) == 0 )
timeout = IGUANA_JSONTIMEOUT;
jsonstr = jprint(json,0);
if ( (retjsonstr= iguana_blockingjsonstr(myinfo,jsonstr,tag,timeout,remoteaddr)) != 0 )
{
//printf("retjsonstr.(%s)\n",retjsonstr);
if ( (retjson= cJSON_Parse(retjsonstr)) == 0 )
retjson = cJSON_Parse("{\"error\":\"cant parse retjsonstr\"}");
jdelete(retjson,"tag");
jadd64bits(retjson,"tag",tag);
retstr = jprint(retjson,1);
//printf("retstr.(%s) retjsonstr.%p retjson.%p\n",retstr,retjsonstr,retjson);
free(retjsonstr);//,strlen(retjsonstr)+1);
}
else PostMessage("Error: \"%s\" failed.", function_name);
return;
}
// Function returned an output dictionary. Send it to JavaScript.
g_ppb_messaging->PostMessage(g_instance, result_var);
g_ppb_var->Release(result_var);
free(jsonstr);
} else retstr = clonestr("{\"error\":\"cant parse JSON\"}");
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"null return\"}");
return(retstr);
}
#define MAX_QUEUE_SIZE 256
// A mutex that guards |g_queue|.
static pthread_mutex_t g_queue_mutex;
// A condition variable that is signalled when |g_queue| is not empty.
static pthread_cond_t g_queue_not_empty_cond;
/** A circular queue of messages from JavaScript to be handled.
*
* If g_queue_start < g_queue_end:
* all elements in the range [g_queue_start, g_queue_end) are valid.
* If g_queue_start > g_queue_end:
* all elements in the ranges [0, g_queue_end) and
* [g_queue_start, MAX_QUEUE_SIZE) are valid.
* If g_queue_start == g_queue_end, and g_queue_size > 0:
* all elements in the g_queue are valid.
* If g_queue_start == g_queue_end, and g_queue_size == 0:
* No elements are valid. */
static struct PP_Var g_queue[MAX_QUEUE_SIZE];
static int g_queue_start = 0; // The index of the head of the queue
static int g_queue_end = 0; // The index of the tail of the queue, non-inclusive.
static int g_queue_size = 0;
// NOTE: this function assumes g_queue_mutex lock is held. @return non-zero if the queue is empty
static int IsQueueEmpty() { return g_queue_size == 0; }
// NOTE: this function assumes g_queue_mutex lock is held. @return non-zero if the queue is full
static int IsQueueFull() { return g_queue_size == MAX_QUEUE_SIZE; }
void InitializeMessageQueue()
char *iguana_JSON(char *jsonstr)
{
pthread_mutex_init(&g_queue_mutex, NULL);
pthread_cond_init(&g_queue_not_empty_cond, NULL);
}
int EnqueueMessage(struct PP_Var message)
{
pthread_mutex_lock(&g_queue_mutex);
// We shouldn't block the main thread waiting for the queue to not be full, so just drop the message.
if ( IsQueueFull() != 0)
char *retstr=0; cJSON *json;
if ( (json= cJSON_Parse(jsonstr)) != 0 )
{
PostMessage("EnqueueMessage: full Q, drop message\n");
pthread_mutex_unlock(&g_queue_mutex);
return(0);
retstr = SuperNET_JSON(0,json,"127.0.0.1");
free_json(json);
}
g_queue[g_queue_end] = message;
g_queue_end = (g_queue_end + 1) % MAX_QUEUE_SIZE;
g_queue_size++;
pthread_cond_signal(&g_queue_not_empty_cond);
pthread_mutex_unlock(&g_queue_mutex);
return 1;
}
struct PP_Var DequeueMessage()
{
struct PP_Var message;
pthread_mutex_lock(&g_queue_mutex);
while ( IsQueueEmpty() != 0 )
pthread_cond_wait(&g_queue_not_empty_cond, &g_queue_mutex);
message = g_queue[g_queue_start];
g_queue_start = (g_queue_start + 1) % MAX_QUEUE_SIZE;
g_queue_size--;
pthread_mutex_unlock(&g_queue_mutex);
return(message);
if ( retstr == 0 )
retstr = clonestr("{\"error\":\"cant parse jsonstr from pnacl\"}");
return(retstr);
}
/**
* A worker thread that handles messages from JavaScript.
* @param[in] user_data Unused.
* @return unused.
*/
void *HandleMessageThread(void *user_data)
char *SuperNET_p2p(struct iguana_info *coin,int32_t *delaymillisp,char *ipaddr,uint8_t *data,int32_t datalen)
{
while ( 1 )
cJSON *json,*retjson; char *agent,*method,*retstr = 0;
if ( (json= cJSON_Parse((char *)data)) != 0 )
{
struct PP_Var message = DequeueMessage();
HandleMessage(message);
g_ppb_var->Release(message);
printf("GOT >>>>>>>> SUPERNET P2P.(%s) from.%s\n",(char *)data,coin->symbol);
if ( (agent= jstr(json,"agent")) != 0 && (method= jstr(json,"method")) != 0 )
{
jaddstr(json,"fromp2p",coin->symbol);
if ( (retstr= SuperNET_JSON(0,json,ipaddr)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
if ( jobj(retjson,"result") != 0 || jobj(retjson,"error") != 0 || jobj(retjson,"method") == 0 )
{
free(retstr);
retstr = 0;
}
free_json(retjson);
}
}
}
free_json(json);
}
return(retstr);
}
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#undef mount
#undef umount
static PP_Bool Instance_DidCreate(PP_Instance instance,uint32_t argc,const char* argn[],const char* argv[])
{
int nacl_io_init_ppapi(PP_Instance instance, PPB_GetInterface get_interface);
static pthread_t g_handle_message_thread;
static pthread_t iguana_thread;
int64_t allocsize;
g_instance = instance;
// By default, nacl_io mounts / to pass through to the original NaCl
// filesystem (which doesn't do much). Let's remount it to a memfs
// filesystem.
InitializeMessageQueue();
pthread_create(&g_handle_message_thread, NULL, &HandleMessageThread, NULL);
pthread_create(&iguana_thread,NULL,&iguana,OS_filestr(&allocsize,"iguana.conf"));
nacl_io_init_ppapi(instance,g_get_browser_interface);
umount("/");
mount("", "/memfs", "memfs", 0, "");
mount("", /* source */
"/", /* target */
"html5fs", /* filesystemtype */
0, /* mountflags */
"type=PERSISTENT,expected_size=10000000000"); /* data */
mount("", /* source. Use relative URL */
"/http", /* target */
"httpfs", /* filesystemtype */
0, /* mountflags */
""); /* data */
PostMessage("finished DidCreate\n");
initflag = 1;
return PP_TRUE;
}
static void Instance_DidDestroy(PP_Instance instance) { }
static void Instance_DidChangeView(PP_Instance instance,PP_Resource view_resource) { }
static void Instance_DidChangeFocus(PP_Instance instance, PP_Bool has_focus) { }
static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance,PP_Resource url_loader)
{
// NaCl modules do not need to handle the document load function.
return PP_FALSE;
}
static void Messaging_HandleMessage(PP_Instance instance,struct PP_Var message)
void iguana_main(void *arg)
{
if ( message.type != PP_VARTYPE_DICTIONARY ) // Special case for jspipe input handling
{
PostMessage("Got unexpected message type: %d\n", message.type);
return;
}
struct PP_Var pipe_var = CStrToVar("pipe");
struct PP_Var pipe_name = g_ppb_var_dictionary->Get(message, pipe_var);
g_ppb_var->Release(pipe_var);
if ( pipe_name.type == PP_VARTYPE_STRING ) // Special case for jspipe input handling
struct supernet_info MYINFO; char helperstr[64],*helperargs,*coinargs=0,*secret,*jsonstr = arg;
int32_t i,len,flag; cJSON *json; uint8_t secretbuf[512];
mycalloc(0,0,0);
iguana_initQ(&helperQ,"helperQ");
OS_ensure_directory("confs");
OS_ensure_directory("DB");
OS_ensure_directory("tmp");
memset(&MYINFO,0,sizeof(MYINFO));
if ( jsonstr != 0 && (json= cJSON_Parse(jsonstr)) != 0 )
{
char file_name[PATH_MAX];
snprintf(file_name, PATH_MAX, "/dev/%s", VarToCStr(pipe_name));
int fd = open(file_name, O_RDONLY);
g_ppb_var->Release(pipe_name);
if ( fd < 0 )
if ( jobj(json,"numhelpers") != 0 )
IGUANA_NUMHELPERS = juint(json,"numhelpers");
if ( (secret= jstr(json,"secret")) != 0 )
{
PostMessage("Warning: opening %s failed.", file_name);
goto done;
len = (int32_t)strlen(secret);
if ( is_hexstr(secret,0) != 0 && len == 128 )
{
len >>= 1;
decode_hex(secretbuf,len,secret);
} else vcalc_sha256(0,secretbuf,(void *)secret,len), len = sizeof(bits256);
memcpy(MYINFO.privkey.bytes,secretbuf,sizeof(MYINFO.privkey));
}
//if ( ioctl(fd, NACL_IOC_HANDLEMESSAGE, &message) != 0 )
// PostMessage("Error: ioctl on %s failed: %s", file_name, strerror(errno));
close(fd);
goto done;
if ( jobj(json,"coins") != 0 )
coinargs = jsonstr;
}
g_ppb_var->AddRef(message);
if ( !EnqueueMessage(message) )
if ( IGUANA_NUMHELPERS == 0 )
IGUANA_NUMHELPERS = 1;
for (i=0; i<IGUANA_NUMHELPERS; i++)
{
g_ppb_var->Release(message);
PostMessage("Warning: dropped message because the queue was full.");
sprintf(helperstr,"{\"name\":\"helper.%d\"}",i);
helperargs = clonestr(helperstr);
iguana_launch(iguana_coinadd("BTCD"),"iguana_helper",iguana_helper,helperargs,IGUANA_PERMTHREAD);
}
done:
g_ppb_var->Release(pipe_name);
}
#define GET_INTERFACE(var, type, name) \
var = (type*)(get_browser(name)); \
if (!var) { \
printf("Unable to get interface " name "\n"); \
return PP_ERROR_FAILED; \
}
//PP_EXPORT
int32_t PPP_InitializeModule(PP_Module a_module_id,PPB_GetInterface get_browser)
{
g_get_browser_interface = get_browser;
GET_INTERFACE(g_ppb_messaging, PPB_Messaging, PPB_MESSAGING_INTERFACE);
GET_INTERFACE(g_ppb_var, PPB_Var, PPB_VAR_INTERFACE);
GET_INTERFACE(g_ppb_var_array, PPB_VarArray, PPB_VAR_ARRAY_INTERFACE);
GET_INTERFACE(g_ppb_var_dictionary, PPB_VarDictionary, PPB_VAR_DICTIONARY_INTERFACE);
return PP_OK;
}
//PP_EXPORT
const void *PPP_GetInterface(const char* interface_name)
{
if ( strcmp(interface_name,PPP_INSTANCE_INTERFACE) == 0 )
iguana_launch(iguana_coinadd("BTCD"),"rpcloop",iguana_rpcloop,iguana_coinadd("BTCD"),IGUANA_PERMTHREAD);
if ( coinargs != 0 )
iguana_launch(iguana_coinadd("BTCD"),"iguana_coins",iguana_coins,coinargs,IGUANA_PERMTHREAD);
else if ( 1 )
{
static PPP_Instance instance_interface =
#ifdef __APPLE__
sleep(1);
char *str;
if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":16,\"coin\":\"BTCD\",\"active\":1}"),0)) != 0 )
{
&Instance_DidCreate,
&Instance_DidDestroy,
&Instance_DidChangeView,
&Instance_DidChangeFocus,
&Instance_HandleDocumentLoad,
};
return &instance_interface;
}
else if ( strcmp(interface_name, PPP_MESSAGING_INTERFACE) == 0 )
{
static PPP_Messaging messaging_interface = { &Messaging_HandleMessage };
return &messaging_interface;
}
return NULL;
}
//PP_EXPORT
void PPP_ShutdownModule() { }
#define CHECK_PARAM_COUNT(name, expected) \
if (GetNumParams(params) != expected) { \
*out_error = PrintfToNewString(#name " takes " #expected " parameters." \
" Got %d", GetNumParams(params)); \
return 1; \
}
#define PARAM_STRING(index, var) \
char* var; \
uint32_t var##_len; \
if (GetParamString(params, index, &var, &var##_len, out_error)) { \
return 1; \
}
#define CREATE_RESPONSE(name) CreateResponse(output, #name, out_error)
#define RESPONSE_STRING(var) AppendResponseString(output, var, out_error)
#define RESPONSE_INT(var) AppendResponseInt(output, var, out_error)
#define MAX_PARAMS 4
static char* g_ParamStrings[MAX_PARAMS];
/**
* Get the number of parameters.
* @param[in] params The parameter array.
* @return uint32_t The number of parameters in the array.
*/
static uint32_t GetNumParams(struct PP_Var params) {
return g_ppb_var_array->GetLength(params);
}
/**
* Create a response PP_Var to send back to JavaScript.
* @param[out] response_var The response PP_Var.
* @param[in] cmd The name of the function that is being executed.
* @param[out] out_error An error message, if this call failed.
*/
static void CreateResponse(struct PP_Var* response_var,
const char* cmd,
const char** out_error) {
PP_Bool result;
struct PP_Var dict_var = g_ppb_var_dictionary->Create();
struct PP_Var cmd_key = CStrToVar("cmd");
struct PP_Var cmd_value = CStrToVar(cmd);
result = g_ppb_var_dictionary->Set(dict_var, cmd_key, cmd_value);
g_ppb_var->Release(cmd_key);
g_ppb_var->Release(cmd_value);
if (!result) {
g_ppb_var->Release(dict_var);
*out_error =
PrintfToNewString("Unable to set \"cmd\" key in result dictionary");
return;
}
struct PP_Var args_key = CStrToVar("args");
struct PP_Var args_value = g_ppb_var_array->Create();
result = g_ppb_var_dictionary->Set(dict_var, args_key, args_value);
g_ppb_var->Release(args_key);
g_ppb_var->Release(args_value);
if (!result) {
g_ppb_var->Release(dict_var);
*out_error =
PrintfToNewString("Unable to set \"args\" key in result dictionary");
return;
}
*response_var = dict_var;
}
/**
* Append a PP_Var to the response dictionary.
* @param[in,out] response_var The response PP_var.
* @param[in] value The value to add to the response args.
* @param[out] out_error An error message, if this call failed.
*/
static void AppendResponseVar(struct PP_Var* response_var,
struct PP_Var value,
const char** out_error) {
struct PP_Var args_value = GetDictVar(*response_var, "args");
uint32_t args_length = g_ppb_var_array->GetLength(args_value);
PP_Bool result = g_ppb_var_array->Set(args_value, args_length, value);
if (!result) {
// Release the dictionary that was there before.
g_ppb_var->Release(*response_var);
// Return an error message instead.
*response_var = PP_MakeUndefined();
*out_error = PrintfToNewString("Unable to append value to result");
return;
}
}
/**
* Append a string to the response dictionary.
* @param[in,out] response_var The response PP_var.
* @param[in] value The value to add to the response args.
* @param[out] out_error An error message, if this call failed.
*/
static void AppendResponseString(struct PP_Var* response_var,
const char* value,
const char** out_error) {
struct PP_Var value_var = CStrToVar(value);
AppendResponseVar(response_var, value_var, out_error);
g_ppb_var->Release(value_var);
}
/**
* Get a parameter at |index| as a string.
* @param[in] params The parameter array.
* @param[in] index The index in |params| to get.
* @param[out] out_string The output string.
* @param[out] out_string_len The length of the output string.
* @param[out] out_error An error message, if this operation failed.
* @return int 0 if successful, otherwise 1.
*/
static int GetParamString(struct PP_Var params,
uint32_t index,
char** out_string,
uint32_t* out_string_len,
const char** out_error) {
if (index >= MAX_PARAMS) {
*out_error = PrintfToNewString("Param index %u >= MAX_PARAMS (%d)",
index, MAX_PARAMS);
return 1;
}
struct PP_Var value = g_ppb_var_array->Get(params, index);
if (value.type != PP_VARTYPE_STRING) {
*out_error =
PrintfToNewString("Expected param at index %d to be a string not.%d", index,value.type);
return 1;
printf("got.(%s)\n",str);
free(str);
}
#endif
}
uint32_t length;
const char* var_str = g_ppb_var->VarToUtf8(value, &length);
char* string = (char*)malloc(length + 1);
memcpy(string, var_str, length);
string[length] = 0;
/* Put the allocated string in g_ParamStrings. This keeps us from leaking
* each parameter string, without having to do manual cleanup in every
* Handle* function below.
*/
free(g_ParamStrings[index]);
g_ParamStrings[index] = string;
*out_string = string;
*out_string_len = length;
return 0;
}
int Handle_iguana(struct PP_Var params,struct PP_Var *output,const char **out_error)
{
char *iguana_JSON(char *);
char *retstr;
PostMessage("inside Handle_iguana\n");
CHECK_PARAM_COUNT(iguana, 1);
PARAM_STRING(0,jsonstr);
retstr = iguana_JSON(jsonstr);
CREATE_RESPONSE(iguana);
RESPONSE_STRING(retstr);
return 0;
}
int example_main()
{
PostMessage("Started example main.\n");
//g_pInputEvent = (PPB_InputEvent*) PSGetInterface(PPB_INPUT_EVENT_INTERFACE);
//g_pKeyboardInput = (PPB_KeyboardInputEvent*)PSGetInterface(PPB_KEYBOARD_INPUT_EVENT_INTERFACE);
//g_pMouseInput = (PPB_MouseInputEvent*) PSGetInterface(PPB_MOUSE_INPUT_EVENT_INTERFACE);
//g_pTouchInput = (PPB_TouchInputEvent*) PSGetInterface(PPB_TOUCH_INPUT_EVENT_INTERFACE);
//PSEventSetFilter(PSE_ALL);
if ( arg != 0 )
SuperNET_JSON(&MYINFO,cJSON_Parse(arg),0);
//init_InstantDEX();
while ( 1 )
{
sleep(777);
/* Process all waiting events without blocking
PSEvent* event;
while ((event = PSEventTryAcquire()) != NULL) {
ProcessEvent(event);
PSEventRelease(event);
}*/
//flag = 0;
//for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
// if ( Coins[i] != 0 && Coins[i]->symbol[0] != 0 )
// flag += iguana_processjsonQ(Coins[i]);
flag = iguana_jsonQ();
if ( flag == 0 )
usleep(100000);
}
return 0;
}
PSMainFunc_t PSUserMainGet()
{
return(example_main);
}
#else
int main(int argc, const char * argv[])
{
char *jsonstr;
if ( argc < 2 )
jsonstr = 0;
else jsonstr = (char *)argv[1];
initflag = 1;
printf("main\n");
iguana(jsonstr);
return 0;
}
#endif
#endif

3
iguana/mingw32

@ -1,5 +1,4 @@
TOOL_DIR := /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin
MINGW := i586-mingw32
include ../mingw.path
LIBS := ../win/libcrypto.a ../win/libssl.a ../win/libpthreadGC2.a -lws2_32 -lgdi32
include mingw

5
iguana/mingw64

@ -1,6 +1,3 @@
TOOL_DIR := /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw64/win64-gcc/bin
MINGW := i686-mingw64
include ../mingw.path64
LIBS := ../win/libcrypto.a ../win/libs/libssl.a ../win/libpthreadGC2_64.a -lws2_64 -lgdi64
include mingw

64
includes/ccgi.h

@ -0,0 +1,64 @@
/*
* C CGI Library version 1.1
*
* Copyright 2009 Stephen C. Losen. Distributed under the terms
* of the GNU General Public License (GPL)
*/
#ifndef _CCGI_H
#define _CCGI_H
typedef struct CGI_varlist CGI_varlist;
typedef const char * const CGI_value;
char *CGI_decode_url(const char *p);
char *CGI_encode_url(const char *p, const char *keep);
char *CGI_encode_entity(const char *p);
char *CGI_encode_base64(const void *p, int len);
void *CGI_decode_base64(const char *p, int *len);
char *CGI_encode_hex(const void *p, int len);
void *CGI_decode_hex(const char *p, int *len);
char *CGI_encrypt(const void *p, int len, const char *password);
void *CGI_decrypt(const char *p, int *len, const char *password);
char *CGI_encode_query(const char *keep, ...);
char *CGI_encode_varlist(CGI_varlist *v, const char *keep);
CGI_varlist *CGI_decode_query(CGI_varlist *v, const char *query);
CGI_varlist *CGI_get_cookie(CGI_varlist *v);
CGI_varlist *CGI_get_query(CGI_varlist *v);
CGI_varlist *CGI_get_post(CGI_varlist *v, const char *template);
CGI_varlist *CGI_get_all(const char *template);
CGI_varlist *CGI_add_var(CGI_varlist *v, const char *varname,
const char *value);
void CGI_free_varlist(CGI_varlist *v);
CGI_value *CGI_lookup_all(CGI_varlist *v, const char *varname);
const char *CGI_lookup(CGI_varlist *v, const char *varname);
const char *CGI_first_name(CGI_varlist *v);
const char *CGI_next_name(CGI_varlist *v);
void CGI_prefork_server(const char *host, int port, const char *pidfile,
int maxproc, int minidle, int maxidle, int maxreq,
void (*callback)(void));
#endif

2
m_unix

@ -1,3 +1,3 @@
git pull
cd iguana; ./m_unix; cd ..
cd SuperNET; ./m_unix; cd ..
#cd SuperNET; ./m_unix; cd ..

2
mingw.path

@ -0,0 +1,2 @@
TOOL_DIR := /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin
MINGW := i586-mingw32

2
mingw.path64

@ -0,0 +1,2 @@
TOOL_DIR := /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw64/win64-gcc/bin
MINGW := i686-mingw64

10
pangea/main.c

@ -13,6 +13,7 @@
* *
******************************************************************************/
#ifdef STANDALONE
#define CHROMEAPP_NAME pangea
#define CHROMEAPP_STR "pangea"
#define CHROMEAPP_CONF "pangea.conf"
@ -33,4 +34,11 @@ void pangea_main(void *arg)
char *pangea_JSON(char *jsonstr)
{
return(clonestr("{\"error\":\"pangea is just a stub for now\"}"));
}
}
#else
char *pangea_parser(struct supernet_info *myinfo,char *method,cJSON *json)
{
return(clonestr("{\"error\":\"pangea API is not yet\"}"));
}
#endif

BIN
win/libcurl.a

Binary file not shown.

BIN
win/libcurldll.a

Binary file not shown.
Loading…
Cancel
Save