Browse Source

Merge remote-tracking branch 'jl777/master'

dev
Satinder Grewal 9 years ago
parent
commit
0ed0772798
  1. 12
      .gitignore
  2. 2
      InstantDEX/InstantDEX.c
  3. 2
      InstantDEX/exchange_trades.h
  4. 2
      InstantDEX/exchangeparse.h
  5. 2
      InstantDEX/exchanges/bitfinex.c
  6. 2
      InstantDEX/exchanges/bitstamp.c
  7. 2
      InstantDEX/exchanges/bittrex.c
  8. 2
      InstantDEX/exchanges/btc38.c
  9. 2
      InstantDEX/exchanges/btce.c
  10. 2
      InstantDEX/exchanges/coinbase.c
  11. 2
      InstantDEX/exchanges/huobi.c
  12. 2
      InstantDEX/exchanges/lakebtc.c
  13. 2
      InstantDEX/exchanges/okcoin.c
  14. 2
      InstantDEX/exchanges/poloniex.c
  15. 2
      InstantDEX/exchanges/quadriga.c
  16. 2
      InstantDEX/orderbooks.h
  17. 17
      README.md
  18. 1
      SuperNET/SuperNET.h
  19. 4
      agents/field.html
  20. 12
      agents/footer.html
  21. 19
      agents/formfooter.html
  22. 16
      agents/formheader.html
  23. 49
      agents/header.html
  24. 1
      confs/BTCD_peers.txt
  25. 2
      crypto777/Makefile
  26. 2
      crypto777/OS_nonportable.c
  27. 2
      crypto777/OS_portable.c
  28. 44
      crypto777/OS_portable.h
  29. 94
      crypto777/OS_time.c
  30. 8
      crypto777/SaM.c
  31. 31
      crypto777/bitcoind_RPC.c
  32. 57
      crypto777/cJSON.c
  33. 46
      crypto777/crypto777.sources
  34. 160
      crypto777/curve25519.c
  35. 4
      crypto777/hmac_sha512.c
  36. 18
      crypto777/iguana_OS.c
  37. 12
      crypto777/iguana_serdes.c
  38. 79
      crypto777/iguana_utils.c
  39. 17
      crypto777/inet.c
  40. 8
      crypto777/m_unix
  41. 0
      crypto777/nanosrc/CMakeLists.txt
  42. 0
      crypto777/nanosrc/README
  43. 0
      crypto777/nanosrc/aio/ctx.c
  44. 0
      crypto777/nanosrc/aio/ctx.h
  45. 0
      crypto777/nanosrc/aio/fsm.c
  46. 0
      crypto777/nanosrc/aio/fsm.h
  47. 0
      crypto777/nanosrc/aio/poller.c
  48. 0
      crypto777/nanosrc/aio/poller.h
  49. 0
      crypto777/nanosrc/aio/poller_epoll.c
  50. 0
      crypto777/nanosrc/aio/poller_epoll.h
  51. 0
      crypto777/nanosrc/aio/poller_kqueue.c
  52. 0
      crypto777/nanosrc/aio/poller_kqueue.h
  53. 0
      crypto777/nanosrc/aio/poller_poll.c
  54. 0
      crypto777/nanosrc/aio/poller_poll.h
  55. 0
      crypto777/nanosrc/aio/pool.c
  56. 0
      crypto777/nanosrc/aio/pool.h
  57. 0
      crypto777/nanosrc/aio/timer.c
  58. 0
      crypto777/nanosrc/aio/timer.h
  59. 0
      crypto777/nanosrc/aio/timerset.c
  60. 0
      crypto777/nanosrc/aio/timerset.h
  61. 0
      crypto777/nanosrc/aio/usock.c
  62. 0
      crypto777/nanosrc/aio/usock.h
  63. 68
      crypto777/nanosrc/aio/usock_posix.c
  64. 0
      crypto777/nanosrc/aio/usock_posix.c_dev
  65. 0
      crypto777/nanosrc/aio/usock_posix.h
  66. 0
      crypto777/nanosrc/aio/usock_win.c
  67. 0
      crypto777/nanosrc/aio/usock_win.h
  68. 0
      crypto777/nanosrc/aio/worker.c
  69. 0
      crypto777/nanosrc/aio/worker.h
  70. 44
      crypto777/nanosrc/aio/worker_posix.c
  71. 0
      crypto777/nanosrc/aio/worker_posix.h
  72. 0
      crypto777/nanosrc/aio/worker_win.c
  73. 0
      crypto777/nanosrc/aio/worker_win.h
  74. 0
      crypto777/nanosrc/bus.h
  75. 0
      crypto777/nanosrc/core/README
  76. 0
      crypto777/nanosrc/core/ep.c
  77. 0
      crypto777/nanosrc/core/ep.h
  78. 0
      crypto777/nanosrc/core/epbase.c
  79. 127
      crypto777/nanosrc/core/global.c
  80. 0
      crypto777/nanosrc/core/global.h
  81. 8
      crypto777/nanosrc/core/pipe.c
  82. 0
      crypto777/nanosrc/core/poll.c
  83. 8
      crypto777/nanosrc/core/sock.c
  84. 0
      crypto777/nanosrc/core/sock.h
  85. 0
      crypto777/nanosrc/core/sockbase.c
  86. 0
      crypto777/nanosrc/core/symbol.c
  87. 0
      crypto777/nanosrc/devices/device.c
  88. 0
      crypto777/nanosrc/devices/device.h
  89. 0
      crypto777/nanosrc/devices/tcpmuxd.c
  90. 0
      crypto777/nanosrc/inproc.h
  91. 0
      crypto777/nanosrc/ipc.h
  92. 5
      crypto777/nanosrc/nn.h
  93. 7
      crypto777/nanosrc/nn_config.h
  94. 0
      crypto777/nanosrc/pair.h
  95. 0
      crypto777/nanosrc/pipeline.h
  96. 0
      crypto777/nanosrc/pkgconfig.in
  97. 0
      crypto777/nanosrc/protocol.h
  98. 0
      crypto777/nanosrc/protocols/README
  99. 0
      crypto777/nanosrc/protocols/bus/bus.c
  100. 0
      crypto777/nanosrc/protocols/bus/bus.h

12
.gitignore

@ -6,3 +6,15 @@ agents/iguana
agents/libcrypto777.a
agents/iguana.exe
iguana/pnacl/Release/iguana_unstripped.pexe
iguana/pnacl/Release/iguana_unstripped.bc
*.deps
iguana/pnacl/Release/iguana_unstripped.bc---linked.pre_opt.pexe
*.stamp
*.d

2
InstantDEX/InstantDEX.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchange_trades.h

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchangeparse.h

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/bitfinex.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/bitstamp.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/bittrex.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/btc38.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/btce.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/coinbase.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/huobi.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/lakebtc.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/okcoin.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/poloniex.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/exchanges/quadriga.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
InstantDEX/orderbooks.h

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

17
README.md

@ -26,7 +26,7 @@ The above two definitions need to be changed to match the mingw install on your
##For chrome app##
You need to make sure the nacl sdk is properly installed and you are able to build the examples.
Now you will need to get the external libs, which can be built from scratch using naclports or there use the reference builds of libssl.a, libcrypto.a, libcurl.a and libz.a in the SuperNET/libs. You can just copy those over into $(NACL_SDK_ROOT)/lib/pnacl.
Now you will need to get the external libs, which can be built from scratch using naclports or there use the reference builds of libssl.a, libcrypto.a, libcurl.a and libz.a in the SuperNET/crypto777/pnacl_libs. You can just copy those over into $(NACL_SDK_ROOT)/<pepper_dir>/lib/pnacl.
#ONETIME#
@ -34,19 +34,30 @@ Now you are ready to build.
I try to make the build process as simple as possible, so there are no `autoconf`, `autoreconf`, `configure`, `cmake`, `make`, to get properly installed and running and run, etc. You do need a C compiler, like gcc.
The **first time** you need to build libcrypto777.a and to do that you need to run:
For unix: ```./m_onetime m_unix```
For osx: ```./m_onetime m_osx```
For win32: ```./m_onetime m_win32```
For win64: ```./m_onetime m_win64```
#(RE)BUILD
Once libcrypto777.a is built, you can build the agents.
For pnacl: ```./m_pnacl```
For pnacl: ```cd crypto777; make clean; make; cd ../iguana; make clean; make```
For unix: ```./m_unix```
For osx: ```./m_osx```
For win32: ```./m_win32```
For win64: ```./m_win64```
The m_(OS) is a standard I follow and should be self explanatory. within each is usually just a few lines, ie compile all the .c files and link with the standard libs.
To build just iguana, you can ```cd``` into SuperNET/iguana and do ```./m_unix``` (or ```./m_osx```, ...).
@ -54,10 +65,12 @@ To build just iguana, you can ```cd``` into SuperNET/iguana and do ```./m_unix``
```./m_clean``` will remove the files created from the building
#RUNNING#
The native versions are command line applications: agents/iguana {JSON}
The chrome app pexe requires that the chrome is launched with a command line parameter (tools/chrome.localhost) and then browse to *http://127.0.0.1:7777* to see the pexe
#SUPERUGLYGUI#
Once iguana is running, you can see the superuglyGUI at *http://127.0.0.1:7778/?method*
by submitting API calls using the forms, you will see it go to some specific URL. You can also do a programmatic GET request to ```http://127.0.0.1:7778/api/<path to apicall>```

1
SuperNET/SuperNET.h

@ -25,6 +25,7 @@
#define SUPERNET_POLLTIMEOUT 1
#define SUPERNET_APIUSLEEP (SUPERNET_POLLTIMEOUT * 10000)
#define SUPERNET_MAXAGENTS 64
#define MAX_SERVERNAME 128
#define LB_OFFSET 1
#define PUBGLOBALS_OFFSET 2

4
agents/field.html

@ -0,0 +1,4 @@
<div class="form-group">
<label for="%s">%s</label>
<textarea class="form-control" name="%s" rows="1" cols="%s" %s></textarea>
</div>

12
agents/footer.html

@ -0,0 +1,12 @@
</div>
</div>
<!-- API fileds -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body></html>

19
agents/formfooter.html

@ -0,0 +1,19 @@
</div>
<div class="col-md-6">
<div class="form-group">
<label for="broadcast">Response</label>
<figure class="highlight" for="%s" disabled="">
<pre>
<code id="%s" class="language-html" data-lang="javascript"></code>
</pre>
</figure>
</div>
</div>
</div>
<input type="submit" value="%s" class="btn btn-default">
</form>
</div>
</div>
</div>

16
agents/formheader.html

@ -0,0 +1,16 @@
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading-%s">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-%s" aria-expanded="false" aria-controls="collapse-%s">
%s %s
</a>
</h4>
</div>
<div id="collapse-%s" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-%s">
<div class="panel-body">
<form action="http://127.0.0.1:7778/api/%s/%s" oninput="%s">
<div class="row">
<div class="col-md-6">

49
agents/header.html

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>SuperNET API></title>
<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
</head>
<body>
<!-- Navigation Bar -->
<div class="navbar navbar-default" role="navigation">
<div class="container" style="min-width: 90%;">
<div class="navbar-header">
<a class="navbar-brand" href="#">SuperNET API</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="https://phabricator.supernet.org/w/" target="_blank" style="margin-left:20px;">Developer Wiki</a></li>
</ul>
</div>
</div>
</div>
<!-- Navigation Bar -->
<!-- API fileds -->
<div class="container" style="min-width: 90%">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

1
confs/BTCD_peers.txt

@ -1,3 +1,4 @@
5.9.102.210
89.248.160.237
89.248.160.238
89.248.160.239

2
crypto777/Makefile

@ -11,7 +11,7 @@ NACL_SDK_ROOT ?= $(abspath $(CURDIR))
TARGET = crypto777
EXTRA= -D__PNACL
EXTRA= -D__PNACL -O2
include $(NACL_SDK_ROOT)/tools/common.mk
CHROME_ARGS += --allow-nacl-socket-api=127.0.0.1

2
crypto777/OS_nonportable.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

2
crypto777/OS_portable.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

44
crypto777/OS_portable.h

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@ -49,11 +49,32 @@
#include "../includes/uthash.h"
#include "../includes/curve25519.h"
#include "../includes/cJSON.h"
#include "../includes/tweetnacl.h"
#ifndef MAP_FILE
#define MAP_FILE 0
#endif
struct huffstream { uint8_t *ptr,*buf; uint32_t bitoffset,maski,endpos; uint32_t allocsize:31,allocated:1; };
typedef struct huffstream HUFF;
struct ramcoder
{
uint32_t cumulativeProb;
uint16_t lower,upper,code,underflowBits,lastsymbol,upper_lastsymbol,counter;
uint64_t *histo;
uint16_t ranges[];
};
#define hrewind(hp) hseek(hp,0,SEEK_SET)
int32_t ramcoder_decoder(struct ramcoder *coder,int32_t updateprobs,uint8_t *buf,int32_t maxlen,HUFF *hp,bits256 *seed);
int32_t ramcoder_encoder(struct ramcoder *coder,int32_t updateprobs,uint8_t *buf,int32_t len,HUFF *hp,uint64_t *histo,bits256 *seed);
//int32_t init_ramcoder(struct ramcoder *coder,HUFF *hp,bits256 *seed);
int32_t ramcoder_decompress(uint8_t *data,int32_t maxlen,uint8_t *bits,uint32_t numbits,bits256 seed);
int32_t ramcoder_compress(uint8_t *bits,int32_t maxlen,uint8_t *data,int32_t datalen,bits256 seed);
uint64_t hconv_bitlen(uint64_t bitlen);
void _init_HUFF(HUFF *hp,int32_t allocsize,void *buf);
#define SCRIPT_OPRETURN 0x6a
#define GENESIS_ACCT "1739068987193023818" // NXT-MRCC-2YLS-8M54-3CMAJ
#define GENESIS_PUBKEYSTR "1259ec21d31a30898d7cd1609f80d9668b4778e3d97e941044b39f0c44d2e51b"
@ -119,7 +140,9 @@ int32_t taidate_mjd(struct taidate cd);
uint64_t tai2utime(struct tai t);
struct tai taitime2tai(struct taitime ct);
char *tai_str(char *str,struct tai t);
char *utc_str(char *str,struct tai t);
char *utc_str(char *str,uint32_t utc);
double tai_diff(struct tai reftai,struct tai cmptai);
uint32_t OS_conv_utime(char *utime);
//int32_t msync(void *addr,size_t len,int32_t flags);
@ -148,7 +171,6 @@ void *OS_portable_mapfile(char *fname,long *filesizep,int32_t enablewrite);
int32_t OS_portable_syncmap(struct OS_mappedptr *mp,long len);
void *OS_portable_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);
int32_t is_DST(int32_t datenum);
int32_t extract_datenum(int32_t *yearp,int32_t *monthp,int32_t *dayp,int32_t datenum);
int32_t expand_datenum(char *date,int32_t datenum);
@ -177,8 +199,8 @@ int32_t OS_openmap(struct OS_mappedptr *mp);
void *OS_mappedptr(void **ptrp,struct OS_mappedptr *mp,uint64_t allocsize,int32_t rwflag,char *fname);
void *OS_filealloc(struct OS_mappedptr *M,char *fname,struct OS_memspace *mem,long size);
void *OS_mapfile(char *fname,long *filesizep,int32_t enablewrite);
void *OS_loadfile(char *fname,char **bufp,int64_t *lenp,int64_t *allocsizep);
void *OS_filestr(int64_t *allocsizep,char *fname);
void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep);
void *OS_filestr(long *allocsizep,char *fname);
int32_t OS_syncmap(struct OS_mappedptr *mp,long len);
void *OS_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize);
@ -205,7 +227,6 @@ void *iguana_meminit(struct OS_memspace *mem,char *name,void *ptr,int64_t totals
void *iguana_memalloc(struct OS_memspace *mem,long size,int32_t clearflag);
int64_t iguana_memfree(struct OS_memspace *mem,void *ptr,int32_t size);
// generic functions
int32_t unhex(char c);
void touppercase(char *str);
@ -221,6 +242,9 @@ int32_t is_hexstr(char *str,int32_t n);
int32_t decode_hex(unsigned char *bytes,int32_t n,char *hex);
void reverse_hexstr(char *str);
int32_t init_hexbytes_noT(char *hexbytes,uint8_t *message,long len);
uint16_t parse_ipaddr(char *ipaddr,char *ip_port);
int32_t bitweight(uint64_t x);
unsigned char _decode_hex(char *hex);
long _stripwhite(char *buf,int accept);
int32_t is_DST(int32_t datenum);
@ -278,6 +302,8 @@ void calc_NXTaddr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len);
void calc_curve25519_str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len);
void calc_base64_encodestr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len);
void calc_base64_decodestr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len);
void calc_hexstr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len);
void calc_unhexstr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len);
uint64_t calc_ipbits(char *ip_port);
void expand_ipbits(char *ipaddr,uint64_t ipbits);
@ -308,8 +334,12 @@ bits256 bits256_add(bits256 a,bits256 b);
int32_t bits256_cmp(bits256 a,bits256 b);
bits256 bits256_lshift(bits256 x);
bits256 bits256_from_compact(uint32_t c);
bits256 bits256_conv(char *hexstr);
int32_t btc_priv2pub(uint8_t pubkey[33],uint8_t privkey[32]);
extern char *Iguana_validcommands[];
extern bits256 GENESIS_PUBKEY,GENESIS_PRIVKEY;
extern char NXTAPIURL[];
#endif

94
crypto777/OS_time.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@ -17,6 +17,7 @@
#include "OS_portable.h"
#define DISABLE_LEAPS
#define TAI_PACK 8
#define TAI_UTC_DIFF ((uint64_t)4611686018427387914ULL)
@ -145,29 +146,22 @@ struct taidate taidate_frommjd(int32_t day,int32_t *pwday,int32_t *pyday)
struct taitime tai2time(struct tai t,int32_t *pwday,int32_t *pyday)
{
uint64_t u,tmp; int32_t leap,s; double diff; struct taitime ct;
uint64_t u; int32_t leap,s; struct taitime ct;
memset(&ct,0,sizeof(ct));
ct.millis = fmod(t.millis,999.999999);
//if ( First_TAI.x != 0 && t.x > First_TAI.x )
// t.x = (t.millis / 1000.) + First_TAI.x;
leap = leapsecs_sub(&t);
u = t.x;
u += (58486 + 60); // was off by a minute
u += 58486; // was off by a minute (or 3?)
s = u % 86400ULL;
memset(&ct,0,sizeof(ct));
ct.second = (s % 60) + leap; s /= 60;
ct.minute = s % 60; s /= 60;
ct.hour = s;
u /= 86400ULL;
ct.date = taidate_frommjd((int32_t)(u - 53375995543064ULL),pwday,pyday);
ct.offset = 0;
if ( First_TAI.x != 0 && t.x > First_TAI.x )
{
tmp = (t.x - First_TAI.x);
diff = (t.millis - First_TAI.millis);
if ( diff < tmp*1000 )
tmp = 0, printf("TAI diff %f vs tmp.%lld\n",diff,(long long)tmp);
else tmp = diff * 1000000000.;
//printf("tmp.%llu \n",(long long)tmp);
tmp %= (uint64_t)1000000000000;
ct.millis = ((double)tmp / 1000000000.);
}
// printf("origt.x %llu t.x %llu %3.3f -> %02d:%02d:%02d %3.3f\n",(long long)origt.x,(long long)t.x,t.millis,ct.second,ct.minute,ct.second,ct.millis);
//printf("TAI millis: %lld -1st.%lld %f - %f -> %f | %f\n",(long long)t.x,(long long)First_TAI.x,t.millis,First_TAI.millis,t.millis-First_TAI.millis,ct.millis);
return(ct);
}
@ -354,11 +348,13 @@ struct tai tai_now()
{
struct tai t; uint64_t now = time(NULL);
t.x = TAI_UTC_DIFF + now;
t.millis = OS_milliseconds();
t.millis = OS_milliseconds() - First_TAI.millis;
if ( First_TAI.x == 0 )
{
First_TAI = t, First_utc = (uint32_t)now;
#ifndef DISABLE_LEAPS
UTC_ADJUST = -36;
#endif
printf("TAINOW.%llu %03.3f UTC.%u vs %u [diff %d]\n",(long long)t.x,t.millis,First_utc,tai2utc(t),UTC_ADJUST);
}
return(t);
@ -366,19 +362,23 @@ struct tai tai_now()
struct tai leapsecs_add(struct tai t,int32_t hit)
{
#ifndef DISABLE_LEAPS
int32_t i; uint64_t u;
u = t.x;
if ( t.x > leaptais[sizeof(leaptais)/sizeof(*leaptais)-1].x )
u += (sizeof(leaptais)/sizeof(*leaptais) - 1);
else
if ( t.x > leaptais[(sizeof(leaptais)/sizeof(*leaptais)) - 1].x )
u += (sizeof(leaptais)/sizeof(*leaptais));//, printf("add leap.%ld\n",(sizeof(leaptais)/sizeof(*leaptais)));
else
{
for (i=0; i<sizeof(leaptais)/sizeof(*leaptais); i++)
{
for (i=0; i<sizeof(leaptais)/sizeof(*leaptais); i++)
{
if ( u < leaptais[i].x ) break;
if ( !hit || (u > leaptais[i].x) ) ++u;
}
if ( u < leaptais[i].x )
break;
if ( hit == 0 || u > leaptais[i].x )
u++;
}
}
t.x = u;
#endif
return(t);
}
@ -393,6 +393,17 @@ struct tai taitime2tai(struct taitime ct)
return(leapsecs_add(t,ct.second == 60));
}
double tai_diff(struct tai reftai,struct tai cmptai)
{
double diff;
//char str[111],str2[111]; printf("start [%f %f] %s vs %s\n",reftai.millis,cmptai.millis,tai_str(str,reftai),tai_str(str2,cmptai));
reftai = taitime2tai(tai2time(reftai,0,0));
cmptai = taitime2tai(tai2time(cmptai,0,0));
diff = (cmptai.x - reftai.x) * 1000. + (cmptai.millis - reftai.millis);
//printf("%s vs %s -> diff [%d] %f [%llu - %llu]\n\n",tai_str(str,reftai),tai_str(str2,cmptai),(int32_t)(cmptai.x - reftai.x),diff,(long long)cmptai.x,(long long)reftai.x);
return(diff);
}
struct tai taidate_scan(char *s,int32_t numleaps)
{
int32_t z,c,sign = 1; char *t = s; struct taidate cd; struct tai st;
@ -415,6 +426,7 @@ struct tai taidate_scan(char *s,int32_t numleaps)
int32_t leapsecs_sub(struct tai *lt)
{
#ifndef DISABLE_LEAPS
char out[101],x[TAI_PACK]; double packerr;
int32_t weekday,yearday,i,j,s; uint64_t u; struct tai t,t2; struct taitime ct2;
if ( leaptais[0].x == 0 )
@ -462,6 +474,7 @@ int32_t leapsecs_sub(struct tai *lt)
}
lt->x = u - s;
}
#endif
return(0);
}
@ -473,10 +486,20 @@ char *tai_str(char *str,struct tai t)
return(str);
}
char *utc_str(char *str,struct tai t)
/*char *utc_str(char *str,struct tai t)
{
t.x += UTC_ADJUST;
return(tai_str(str,t));
}*/
char *utc_str(char *str,uint32_t utc)
{
struct taitime ct; struct tai t;
t = utc2tai(utc);
t.x += UTC_ADJUST;
ct = tai2time(t,0,0);
sprintf(str,"%d-%02d-%02dT%02d:%02d:%02dZ",ct.date.year,ct.date.month,ct.date.day,ct.hour,ct.minute,ct.second);
return(str);
}
double OS_milliseconds()
@ -506,7 +529,8 @@ uint64_t OS_conv_datenum(int32_t datenum,int32_t hour,int32_t minute,int32_t sec
{
ct = taitime_set(taidate_set(year,month,day),hour,minute,second);
t = taitime2tai(ct);
return(tai2utime(t)+788250398LL - 4294967296LL);
//char str[65]; printf("conv.(y%d m%d d%d %d:%d:%d) %s\n",year,month,day,hour,minute,second,tai_str(str,t));
return(tai2utc(t));//tai2utime(t)+788250398LL - 4294967296LL);
}
return(0);
}
@ -565,6 +589,7 @@ int32_t conv_date(int32_t *secondsp,char *date)
*secondsp = (3600*hour + 60*min + sec);
else printf("ERROR: seconds.%d %d %d %d, len.%d\n",*secondsp,hour,min,sec,len);
}
//printf("(%s) -> Y.%d M.%d D.%d %d:%d:%d\n",date,year,month,day,hour,min,sec);
sprintf(origdate,"%d-%02d-%02d",year,month,day); //2015-07-25T22:34:31Z
if ( strcmp(tmpdate,origdate) != 0 )
{
@ -574,6 +599,13 @@ int32_t conv_date(int32_t *secondsp,char *date)
return((year * 10000) + (month * 100) + day);
}
uint32_t OS_conv_utime(char *utime)
{
int32_t datenum,seconds;
datenum = conv_date(&seconds,utime);
return((uint32_t)OS_conv_datenum(datenum,seconds/3600,(seconds%3600)/60,seconds%60));
}
int32_t expand_datenum(char *date,int32_t datenum)
{
int32_t year,month,day; date[0] = 0;
@ -637,6 +669,16 @@ int main(int argc, const char * argv[])
}
printf("million tai compares in %.3f microseconds per encode/decode\n",1000. * (OS_milliseconds()-startmillis)/i);
}
/* struct tai t = tai_now(); double diff,lastdiff = 0.;
for (i=0; i<1000000; i++)
{
diff = tai_diff(t,tai_now());
if ( diff < lastdiff )
printf("embargo.x %f %llu.%3.3f %llu.%3.3f\n",tai_diff(t,tai_now()),(long long)t.x,t.millis,(long long)tai_now().x,tai_now().millis);
lastdiff = diff;
//usleep(100000);
} getchar();
*/
return 0;
}
#endif

8
crypto777/SaM.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@ -229,15 +229,15 @@ int32_t _SaM_test(char *msg,TRIT *testvector,int32_t n,TRIT *checkvals)
return(errs);
}
int32_t bitweight(uint64_t x)
/*int32_t bitweight(uint64_t x)
{
int i,wt = 0;
for (i=0; i<64; i++)
if ( (1LL << i) & x )
wt++;
return(wt);
}
}*/
int32_t bitweight(uint64_t x);
#define SETBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] |= (1 << ((bitoffset) & 7)))
#define GETBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] & (1 << ((bitoffset) & 7)))
#define CLEARBIT(bits,bitoffset) (((uint8_t *)bits)[(bitoffset) >> 3] &= ~(1 << ((bitoffset) & 7)))

31
crypto777/bitcoind_RPC.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@ -18,6 +18,7 @@
#include <curl/curl.h>
#include <curl/easy.h>
#define issue_curl(cmdstr) bitcoind_RPC(0,"curl",cmdstr,0,0,0)
// return data from the server
struct return_string {
@ -339,3 +340,31 @@ void curlhandle_free(void *curlhandle)
{
curl_easy_cleanup(curlhandle);
}
bits256 issue_getpubkey(int32_t *haspubkeyp,char *acct)
{
cJSON *json; bits256 pubkey; char cmd[4096],*jsonstr; struct destbuf pubkeystr;
sprintf(cmd,"%s?requestType=getAccountPublicKey&account=%s",NXTAPIURL,acct);
jsonstr = issue_curl(cmd);
pubkeystr.buf[0] = 0;
if ( haspubkeyp != 0 )
*haspubkeyp = 0;
memset(&pubkey,0,sizeof(pubkey));
if ( jsonstr != 0 )
{
printf("PUBKEYRPC.(%s)\n",jsonstr);
if ( (json = cJSON_Parse(jsonstr)) != 0 )
{
copy_cJSON(&pubkeystr,cJSON_GetObjectItem(json,"publicKey"));
free_json(json);
if ( strlen(pubkeystr.buf) == sizeof(pubkey)*2 )
{
if ( haspubkeyp != 0 )
*haspubkeyp = 1;
decode_hex(pubkey.bytes,sizeof(pubkey),pubkeystr.buf);
}
}
free(jsonstr);
}
return(pubkey);
}

57
crypto777/cJSON.c

@ -62,7 +62,7 @@ static char* cJSON_strdup(const char* str)
char* copy;
len = strlen(str) + 1;
if (!(copy = (char*)cJSON_malloc(len))) return 0;
if (!(copy = (char*)cJSON_malloc(len+1))) return 0;
memcpy(copy,str,len);
return copy;
}
@ -137,7 +137,7 @@ static char *print_number(cJSON *item)
}
else
{
str = (char *)cJSON_malloc(64); /* This is a nice tradeoff. */
str = (char *)cJSON_malloc(66); /* This is a nice tradeoff. */
if ( str != 0 )
{
if ( fabs(floor(d) - d) <= DBL_EPSILON && fabs(d) < 1.0e60 )
@ -170,15 +170,20 @@ static const char *parse_string(cJSON *item,const char *str)
const char *ptr=str+1;char *ptr2;char *out;int32_t len=0;unsigned uc,uc2;
if (*str!='\"') {ep=str;return 0;} /* not a string! */
while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; // Skip escaped quotes
out=(char*)cJSON_malloc(len+1); /* This is how long we need for the string, roughly. */
out=(char*)cJSON_malloc(len+2); /* This is how long we need for the string, roughly. */
if (!out) return 0;
ptr=str+1;ptr2=out;
while (*ptr!='\"' && *ptr)
{
if (*ptr!='\\') *ptr2++=*ptr++;
if (*ptr!='\\')
{
if ( *ptr == '%' && is_hexstr((char *)&ptr[1],2) && isprint(_decode_hex((char *)&ptr[1])) != 0 )
*ptr2++ = _decode_hex((char *)&ptr[1]), ptr += 3;
else *ptr2++ = *ptr++;
}
else
{
ptr++;
@ -189,16 +194,16 @@ static const char *parse_string(cJSON *item,const char *str)
case 'n': *ptr2++='\n'; break;
case 'r': *ptr2++='\r'; break;
case 't': *ptr2++='\t'; break;
case 'u': /* transcode utf16 to utf8. */
uc=parse_hex4(ptr+1);ptr+=4; /* get the unicode char. */
case 'u': // transcode utf16 to utf8
uc=parse_hex4(ptr+1);ptr+=4; // get the unicode char
if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; /* check for invalid. */
if ((uc>=0xDC00 && uc<=0xDFFF) || uc==0) break; // check for invalid
if (uc>=0xD800 && uc<=0xDBFF) /* UTF16 surrogate pairs. */
if (uc>=0xD800 && uc<=0xDBFF) // UTF16 surrogate pairs
{
if (ptr[1]!='\\' || ptr[2]!='u') break; /* missing second-half of surrogate. */
if (ptr[1]!='\\' || ptr[2]!='u') break; // missing second-half of surrogate.
uc2=parse_hex4(ptr+3);ptr+=6;
if (uc2<0xDC00 || uc2>0xDFFF) break; /* invalid second-half of surrogate. */
if (uc2<0xDC00 || uc2>0xDFFF) break; // invalid second-half of surrogate
uc=0x10000 + (((uc&0x3FF)<<10) | (uc2&0x3FF));
}
@ -232,7 +237,7 @@ static char *print_string_ptr(const char *str)
if (!str) return cJSON_strdup("");
ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;}
out=(char*)cJSON_malloc(len+3);
out=(char*)cJSON_malloc(len+3+1);
if (!out) return 0;
ptr2=out;ptr=str;
@ -376,12 +381,12 @@ static char *print_array(cJSON *item,int32_t depth,int32_t fmt)
/* Explicitly handle numentries==0 */
if (!numentries)
{
out=(char*)cJSON_malloc(3);
out=(char*)cJSON_malloc(3+1);
if (out) strcpy(out,"[]");
return out;
}
/* Allocate an array to hold the values for each */
entries=(char**)cJSON_malloc(numentries*sizeof(char*));
entries=(char**)cJSON_malloc((1+numentries)*sizeof(char*));
if (!entries) return 0;
memset(entries,0,numentries*sizeof(char*));
/* Retrieve all the results: */
@ -395,7 +400,7 @@ static char *print_array(cJSON *item,int32_t depth,int32_t fmt)
}
/* If we didn't fail, try to malloc the output string */
if (!fail) out=(char*)cJSON_malloc(len);
if (!fail) out=(char*)cJSON_malloc(len+1);
/* If that fails, we fail. */
if (!out) fail=1;
@ -469,7 +474,7 @@ static char *print_object(cJSON *item,int32_t depth,int32_t fmt)
/* Explicitly handle empty object case */
if (!numentries)
{
out=(char*)cJSON_malloc(fmt?depth+4:3);
out=(char*)cJSON_malloc(fmt?depth+4+1:3+1);
if (!out) return 0;
ptr=out;*ptr++='{';
if (fmt) {*ptr++='\n';for (i=0;i<depth-1;i++) *ptr++='\t';}
@ -495,7 +500,7 @@ static char *print_object(cJSON *item,int32_t depth,int32_t fmt)
}
/* Try to allocate the output string */
if (!fail) out=(char*)cJSON_malloc(len);
if (!fail) out=(char*)cJSON_malloc(len+1);
if (!out) fail=1;
/* Handle failure */
@ -526,7 +531,7 @@ static char *print_object(cJSON *item,int32_t depth,int32_t fmt)
}
/* Get Array size/item / object item. */
int32_t cJSON_GetArraySize(cJSON *array) {cJSON *c=array->child;int32_t i=0;while(c)i++,c=c->next;return i;}
int32_t cJSON_GetArraySize(cJSON *array) {cJSON *c; if ( array == 0 ) return(0); c=array->child;int32_t i=0;while(c)i++,c=c->next;return i;}
cJSON *cJSON_GetArrayItem(cJSON *array,int32_t item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;}
cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;}
@ -616,7 +621,7 @@ void cJSON_Minify(char *json)
// the following written by jl777
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@ -798,15 +803,15 @@ char *cJSON_str(cJSON *json)
return(0);
}
void jadd(cJSON *json,char *field,cJSON *item) { cJSON_AddItemToObject(json,field,item); }
void jaddstr(cJSON *json,char *field,char *str) { cJSON_AddItemToObject(json,field,cJSON_CreateString(str)); }
void jaddnum(cJSON *json,char *field,double num) { cJSON_AddItemToObject(json,field,cJSON_CreateNumber(num)); }
void jadd(cJSON *json,char *field,cJSON *item) { if ( json != 0 )cJSON_AddItemToObject(json,field,item); }
void jaddstr(cJSON *json,char *field,char *str) { if ( json != 0 && str != 0 ) cJSON_AddItemToObject(json,field,cJSON_CreateString(str)); }
void jaddnum(cJSON *json,char *field,double num) { if ( json != 0 )cJSON_AddItemToObject(json,field,cJSON_CreateNumber(num)); }
void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddstr(json,field,numstr); }
void jaddi(cJSON *json,cJSON *item) { cJSON_AddItemToArray(json,item); }
void jaddistr(cJSON *json,char *str) { cJSON_AddItemToArray(json,cJSON_CreateString(str)); }
void jaddinum(cJSON *json,double num) { cJSON_AddItemToArray(json,cJSON_CreateNumber(num)); }
void jaddi(cJSON *json,cJSON *item) { if ( json != 0 ) cJSON_AddItemToArray(json,item); }
void jaddistr(cJSON *json,char *str) { if ( json != 0 ) cJSON_AddItemToArray(json,cJSON_CreateString(str)); }
void jaddinum(cJSON *json,double num) { if ( json != 0 ) cJSON_AddItemToArray(json,cJSON_CreateNumber(num)); }
void jaddi64bits(cJSON *json,uint64_t nxt64bits) { char numstr[64]; sprintf(numstr,"%llu",(long long)nxt64bits), jaddistr(json,numstr); }
char *jstr(cJSON *json,char *field) { if ( field == 0 ) return(cJSON_str(json)); return(cJSON_str(cJSON_GetObjectItem(json,field))); }
char *jstr(cJSON *json,char *field) { if ( json == 0 ) return(0); if ( field == 0 ) return(cJSON_str(json)); return(cJSON_str(cJSON_GetObjectItem(json,field))); }
char *jstri(cJSON *json,int32_t i) { return(cJSON_str(cJSON_GetArrayItem(json,i))); }
char *jprint(cJSON *json,int32_t freeflag) { char *str; if ( json == 0 ) return(clonestr("{}")); str = cJSON_Print(json), _stripwhite(str,' '); if ( freeflag != 0 ) free_json(json); return(str); }

46
crypto777/crypto777.sources

@ -1,4 +1,46 @@
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
NANOSRC = ../crypto777/nanosrc
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)
NANOMSG_CORE = $(NANOSRC)/core/global.c $(NANOSRC)/core/ep.c $(NANOSRC)/core/epbase.c $(NANOSRC)/core/pipe.c $(NANOSRC)/core/poll.c $(NANOSRC)/core/sock.c $(NANOSRC)/core/sockbase.c $(NANOSRC)/core/symbol.c
NANOMSG_DEVICES = $(NANOSRC)/devices/device.c $(NANOSRC)/devices/tcpmuxd.c
NANOMSG_AIO = $(NANOSRC)/aio/ctx.c $(NANOSRC)/aio/fsm.c $(NANOSRC)/aio/poller.c $(NANOSRC)/aio/pool.c $(NANOSRC)/aio/timer.c $(NANOSRC)/aio/usock.c $(NANOSRC)/aio/timerset.c $(NANOSRC)/aio/worker.c
NANOMSG_UTILS = $(NANOSRC)/utils/alloc.c $(NANOSRC)/utils/atomic.c $(NANOSRC)/utils/chunk.c $(NANOSRC)/utils/chunkref.c $(NANOSRC)/utils/clock.c $(NANOSRC)/utils/closefd.c $(NANOSRC)/utils/efd.c $(NANOSRC)/utils/err.c $(NANOSRC)/utils/glock.c $(NANOSRC)/utils/hash.c $(NANOSRC)/utils/list.c $(NANOSRC)/utils/msg.c $(NANOSRC)/utils/mutex.c $(NANOSRC)/utils/queue.c $(NANOSRC)/utils/random.c $(NANOSRC)/utils/sem.c $(NANOSRC)/utils/sleep.c $(NANOSRC)/utils/stopwatch.c $(NANOSRC)/utils/thread.c $(NANOSRC)/utils/wire.c
PROTOCOLS_UTILS = $(NANOSRC)/protocols/utils/dist.c $(NANOSRC)/protocols/utils/excl.c $(NANOSRC)/protocols/utils/fq.c $(NANOSRC)/protocols/utils/lb.c $(NANOSRC)/protocols/utils/priolist.c
PROTOCOLS_BUS = $(NANOSRC)/protocols/bus/bus.c $(NANOSRC)/protocols/bus/xbus.c
PROTOCOLS_PIPELINE = $(NANOSRC)/protocols/pipeline/push.c $(NANOSRC)/protocols/pipeline/pull.c $(NANOSRC)/protocols/pipeline/xpull.c $(NANOSRC)/protocols/pipeline/xpush.c
PROTOCOLS_PUBSUB = $(NANOSRC)/protocols/pubsub/pub.c $(NANOSRC)/protocols/pubsub/sub.c $(NANOSRC)/protocols/pubsub/trie.c $(NANOSRC)/protocols/pubsub/xpub.c $(NANOSRC)/protocols/pubsub/xsub.c
PROTOCOLS_PAIR = $(NANOSRC)/protocols/pair/pair.c $(NANOSRC)/protocols/pair/xpair.c
PROTOCOLS_REQREP = $(NANOSRC)/protocols/reqrep/req.c $(NANOSRC)/protocols/reqrep/rep.c $(NANOSRC)/protocols/reqrep/task.c $(NANOSRC)/protocols/reqrep/xrep.c $(NANOSRC)/protocols/reqrep/xreq.c
PROTOCOLS_SURVEY = $(NANOSRC)/protocols/survey/respondent.c $(NANOSRC)/protocols/survey/surveyor.c $(NANOSRC)/protocols/survey/xrespondent.c $(NANOSRC)/protocols/survey/xsurveyor.c
TRANSPORTS_UTILS = $(NANOSRC)/transports/utils/backoff.c $(NANOSRC)/transports/utils/dns.c $(NANOSRC)/transports/utils/iface.c $(NANOSRC)/transports/utils/literal.c $(NANOSRC)/transports/utils/port.c $(NANOSRC)/transports/utils/streamhdr.c $(NANOSRC)/transports/utils/base64.c
TRANSPORTS_IPC = $(NANOSRC)/transports/ipc/aipc.c $(NANOSRC)/transports/ipc/bipc.c $(NANOSRC)/transports/ipc/cipc.c $(NANOSRC)/transports/ipc/ipc.c $(NANOSRC)/transports/ipc/sipc.c
TRANSPORTS_TCP = $(NANOSRC)/transports/tcp/atcp.c $(NANOSRC)/transports/tcp/btcp.c $(NANOSRC)/transports/tcp/ctcp.c $(NANOSRC)/transports/tcp/stcp.c $(NANOSRC)/transports/tcp/tcp.c
TRANSPORTS_INPROC = $(NANOSRC)/transports/inproc/binproc.c $(NANOSRC)/transports/inproc/cinproc.c $(NANOSRC)/transports/inproc/inproc.c $(NANOSRC)/transports/inproc/ins.c $(NANOSRC)/transports/inproc/msgqueue.c $(NANOSRC)/transports/inproc/sinproc.c
TRANSPORTS_WS = $(NANOSRC)/transports/ws/aws.c $(NANOSRC)/transports/ws/bws.c $(NANOSRC)/transports/ws/cws.c $(NANOSRC)/transports/ws/sws.c $(NANOSRC)/transports/ws/ws.c $(NANOSRC)/transports/ws/ws_handshake.c $(NANOSRC)/transports/ws/sha1.c
TRANSPORTS_TCPMUX = $(NANOSRC)/transports/tcpmux/atcpmux.c $(NANOSRC)/transports/tcpmux/btcpmux.c $(NANOSRC)/transports/tcpmux/ctcpmux.c $(NANOSRC)/transports/tcpmux/stcpmux.c $(NANOSRC)/transports/tcpmux/tcpmux.c
NANOMSG_PROTOCOLS = $(PROTOCOLS_UTILS) $(PROTOCOLS_PUBSUB) $(PROTOCOLS_PAIR) $(PROTOCOLS_REQREP) $(PROTOCOLS_BUS) $(PROTOCOLS_PIPELINE) $(PROTOCOLS_SURVEY)
NANOMSG_TRANSPORTS = $(TRANSPORTS_UTILS) $(TRANSPORTS_TCP) $(TRANSPORTS_IPC) $(TRANSPORTS_INPROC)
NANOMSG = $(NANOMSG_CORE) $(NANOMSG_AIO) $(NANOMSG_UTILS) $(NANOMSG_DEVICES) $(NANOMSG_TRANSPORTS) $(NANOMSG_PROTOCOLS)
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/tweetnacl.c ../crypto777/bitcoind_RPC.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) # $(NANOMSG)

160
crypto777/curve25519.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@ -184,6 +184,7 @@ bits256 fcontract(const bits320 input)
bits256 curve25519(bits256 mysecret,bits256 basepoint)
{
bits320 bp,x,z;
mysecret.bytes[0] &= 0xf8, mysecret.bytes[31] &= 0x7f, mysecret.bytes[31] |= 0x40;
bp = fexpand(basepoint);
cmult(&x,&z,mysecret,bp);
return(fcontract(fmul(x,crecip(z))));
@ -872,7 +873,7 @@ inline bits320 force_inline crecip(const bits320 z)
/* 2^255 - 21 */ return(fmul(t0, a));
}
void randombytes(unsigned char *x,long xlen);
void OS_randombytes(unsigned char *x,long xlen);
bits256 rand256(int32_t privkeyflag)
{
@ -1692,4 +1693,159 @@ uint64_t conv_NXTpassword(unsigned char *mysecret,unsigned char *mypublic,uint8_
memcpy(&addr,hash,sizeof(addr));
return(addr);
}
#include <stdio.h>
bits256 GENESIS_PUBKEY,GENESIS_PRIVKEY;
bits256 acct777_pubkey(bits256 privkey)
{
static uint8_t basepoint[32] = {9};
bits256 pubkey;
privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64;
curve25519_donna(pubkey.bytes,privkey.bytes,basepoint);
return(pubkey);
}
uint64_t acct777_nxt64bits(bits256 pubkey)
{
bits256 acct;
vcalc_sha256(0,acct.bytes,pubkey.bytes,sizeof(pubkey));
return(acct.txid);
}
bits256 acct777_msgprivkey(uint8_t *data,int32_t datalen)
{
bits256 hash;
vcalc_sha256(0,hash.bytes,data,datalen);
return(hash);
}
bits256 acct777_msgpubkey(uint8_t *data,int32_t datalen)
{
return(acct777_pubkey(acct777_msgprivkey(data,datalen)));
}
bits256 acct777_hashiter(bits256 privkey,bits256 pubkey,int32_t lockdays,uint8_t chainlen)
{
uint16_t lockseed,signlen = 0; uint8_t signbuf[16]; bits256 shared,lockhash;
lockseed = (chainlen & 0x7f) | (lockdays << 7);
signlen = 0, signbuf[signlen++] = lockseed & 0xff, signbuf[signlen++] = (lockseed >> 8) & 0xff;
privkey.bytes[0] &= 248, privkey.bytes[31] &= 127, privkey.bytes[31] |= 64;
shared = curve25519(privkey,pubkey);
vcalc_sha256cat(lockhash.bytes,shared.bytes,sizeof(shared),signbuf,signlen);
return(lockhash);
}
bits256 acct777_lockhash(bits256 pubkey,int32_t lockdays,uint8_t chainlen)
{
bits256 lockhash = GENESIS_PRIVKEY;
while ( chainlen > 0 )
lockhash = acct777_hashiter(lockhash,pubkey,lockdays,chainlen--);
return(lockhash);
}
bits256 acct777_invoicehash(bits256 *invoicehash,uint16_t lockdays,uint8_t chainlen)
{
int32_t i; bits256 lockhash,privkey;
OS_randombytes(privkey.bytes,sizeof(privkey)); // both privkey and pubkey are sensitive. pubkey allows verification, privkey proves owner
lockhash = privkey;
for (i=0; i<chainlen; i++)
lockhash = acct777_hashiter(lockhash,GENESIS_PUBKEY,chainlen - i,lockdays);
*invoicehash = lockhash;
return(privkey);
}
//char *bits256_str();
//struct acct777_sig { bits256 sigbits,pubkey; uint64_t signer64bits; uint32_t timestamp,allocsize; };
void acct777_rwsig(int32_t rwflag,uint8_t *serialized,struct acct777_sig *sig)
{
int32_t len = 0;
iguana_rwbignum(rwflag,&serialized[len],sizeof(bits256),sig->sigbits.bytes), len += sizeof(bits256);
iguana_rwbignum(rwflag,&serialized[len],sizeof(bits256),sig->pubkey.bytes),len += sizeof(bits256);
iguana_rwnum(rwflag,&serialized[len],sizeof(sig->signer64bits),&sig->signer64bits),len += sizeof(sig->signer64bits);
iguana_rwnum(rwflag,&serialized[len],sizeof(sig->timestamp),&sig->timestamp),len += sizeof(sig->timestamp);
iguana_rwnum(rwflag,&serialized[len],sizeof(sig->allocsize),&sig->allocsize),len += sizeof(sig->allocsize);
}
int32_t acct777_sigcheck(struct acct777_sig *sig)
{
#define IGUANA_GENESIS 1453075200
#define IGUANA_MAXPACKETSIZE (1024 * 1024 * 2)
#define TEN_YEARS (10 * 365 * 24 * 3600)
if ( sig->allocsize < sizeof(*sig) || sig->allocsize > IGUANA_MAXPACKETSIZE )
{
//printf("acct777_sign: invalid datalen.%d hex.%08x\n",sig->allocsize,sig->allocsize);
return(-1);
}
if ( sig->timestamp < IGUANA_GENESIS || sig->timestamp > (long)IGUANA_GENESIS+TEN_YEARS )
{
printf("acct777_sign: invalid timestamp.%u (%u %u)\n",sig->timestamp,IGUANA_GENESIS,IGUANA_GENESIS+TEN_YEARS);
return(-1);
}
return(sig->allocsize);
}
uint64_t acct777_sign(struct acct777_sig *sig,bits256 privkey,bits256 otherpubkey,uint32_t timestamp,uint8_t *serialized,int32_t datalen)
{
bits256 pubkey; bits256 shared; uint8_t buf[sizeof(*sig)];
pubkey = acct777_pubkey(privkey);
if ( memcmp(sig->pubkey.bytes,otherpubkey.bytes,sizeof(bits256)) != 0 )
{
//char str[65],str2[65];
//printf("set sig fields.(%s) != (%s)\n",bits256_str(str,sig->pubkey),bits256_str(str2,otherpubkey));
sig->pubkey = pubkey;
sig->timestamp = timestamp;
sig->allocsize = (int32_t)(datalen + sizeof(*sig));
sig->signer64bits = acct777_nxt64bits(sig->pubkey);
}
sig->sigbits = shared = curve25519(privkey,otherpubkey);
if ( acct777_sigcheck(sig) < 0 )
return(0);
memset(buf,0,sizeof(buf));
acct777_rwsig(1,buf,sig);
//int32_t i; for (i=0; i<sizeof(buf); i++)
// printf("%02x ",buf[i]);
//printf(" <<<<<<<<< SIGN.%d allocsize.%d signer.%llu t%u\n",datalen,sig->allocsize,(long long)sig->signer64bits,sig->timestamp);
//char str[65]; printf("shared.(%s) crc.%u datalen.%d\n",bits256_str(str,shared),calc_crc32(0,buf,sizeof(buf)),datalen);
vcalc_sha256cat(sig->sigbits.bytes,buf,sizeof(buf),serialized,datalen);
//printf(" calcsig.%llx pubkey.%llx signer.%llu | t%u crc.%08x len.%d shared.%llx <- %llx * %llx\n",(long long)sig->sigbits.txid,(long long)sig->pubkey.txid,(long long)sig->signer64bits,timestamp,calc_crc32(0,serialized,datalen),datalen,(long long)shared.txid,(long long)privkey.txid,(long long)otherpubkey.txid);
return(sig->signer64bits);
}
uint64_t acct777_validate(struct acct777_sig *sig,bits256 privkey,bits256 pubkey)
{
struct acct777_sig checksig; uint64_t signerbits; int32_t datalen; uint8_t *serialized;
datalen = (int32_t)(sig->allocsize - sizeof(*sig));
checksig = *sig;
serialized = (uint8_t *)((long)sig + sizeof(*sig));
//{ int32_t i; for (i=0; i<datalen; i++) printf("%02x",serialized[i]); printf(" VALIDATE.%d?\n",datalen); }
acct777_sign(&checksig,privkey,pubkey,sig->timestamp,serialized,datalen);
if ( memcmp(checksig.sigbits.bytes,sig->sigbits.bytes,sizeof(checksig.sigbits)) != 0 )
{
//char *bits256_str();
//char str[65],str2[65]; printf("sig compare error using sig->pub from %llu\n>>>>>>>> sig.(%s) vs (%s)",(long long)acct777_nxt64bits(sig->pubkey),bits256_str(str,checksig.sigbits),bits256_str(str2,sig->sigbits));
return(0);
}
signerbits = acct777_nxt64bits(sig->pubkey);
if ( signerbits == checksig.signer64bits )
return(signerbits);
else return(0);
}
uint64_t acct777_signtx(struct acct777_sig *sig,bits256 privkey,uint32_t timestamp,uint8_t *data,int32_t datalen)
{
return(acct777_sign(sig,privkey,acct777_msgpubkey(data,datalen),timestamp,data,datalen));
}
/*uint64_t acct777_swaptx(bits256 privkey,struct acct777_sig *sig,uint32_t timestamp,uint8_t *data,int32_t datalen)
{
uint64_t othernxt;
if ( (othernxt= acct777_validate(sig)) != sig->signer64bits )
return(0);
return(acct777_sign(sig,privkey,acct777_msgpubkey(data,datalen),timestamp,data,datalen));
}*/
#undef force_inline

4
crypto777/hmac_sha512.c

@ -458,7 +458,7 @@ static void hmac_sha512_final(hmac_sha512_ctx * ctx, unsigned char *mac,
memcpy(mac, mac_temp, mac_size);
}
void hmac_sha512(const unsigned char *key, unsigned int key_size,
void hmac_sha512str(const unsigned char *key, unsigned int key_size,
const unsigned char *message, unsigned int message_len,
unsigned char *mac, unsigned mac_size)
{
@ -499,7 +499,7 @@ char *hmac_sha512_str(char *dest,char *key,int32_t key_size,char *message)
{
unsigned char mac[SHA512_DIGEST_SIZE],checkbuf[SHA512_DIGEST_SIZE*2 + 1]; char dest2[SHA512_DIGEST_SIZE*2 + 1]; unsigned long size = sizeof(checkbuf);
//int i;
hmac_sha512((const unsigned char *)key,key_size,(const unsigned char *)message,(int)strlen(message),mac,SHA512_DIGEST_SIZE);
hmac_sha512str((const unsigned char *)key,key_size,(const unsigned char *)message,(int)strlen(message),mac,SHA512_DIGEST_SIZE);
//for (i=0; i<SHA512_DIGEST_SIZE; i++)
// sprintf(&dest[i*2],"%02x", mac[i]);
//dest[2 * SHA512_DIGEST_SIZE] = '\0';

18
crypto777/iguana_OS.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@ -249,13 +249,15 @@ void *queue_dequeue(queue_t *queue,int32_t offsetflag)
void *queue_delete(queue_t *queue,struct queueitem *copy,int32_t copysize,int32_t freeitem)
{
struct allocitem *ptr;
struct queueitem *item = 0;
lock_queue(queue);
if ( queue->list != 0 )
{
DL_FOREACH(queue->list,item)
{
if ( item == copy || memcmp((void *)((long)item + sizeof(struct queueitem)),(void *)((long)item + sizeof(struct queueitem)),copysize) == 0 )
ptr = (void *)((long)item - sizeof(struct allocitem));
if ( item == copy || (ptr->allocsize == copysize && memcmp((void *)((long)item + sizeof(struct queueitem)),(void *)((long)item + sizeof(struct queueitem)),copysize) == 0) )
{
DL_DELETE(queue->list,item);
portable_mutex_unlock(&queue->mutex);
@ -767,10 +769,10 @@ void *OS_filealloc(struct OS_mappedptr *M,char *fname,struct OS_memspace *mem,lo
return(M->fileptr);
}
void *OS_loadfile(char *fname,char **bufp,int64_t *lenp,int64_t *allocsizep)
void *OS_loadfile(char *fname,char **bufp,long *lenp,long *allocsizep)
{
FILE *fp;
int64_t filesize,buflen = *allocsizep;
long filesize,buflen = *allocsizep;
char *buf = *bufp;
*lenp = 0;
if ( (fp= fopen(OS_compatible_path(fname),"rb")) != 0 )
@ -803,9 +805,9 @@ void *OS_loadfile(char *fname,char **bufp,int64_t *lenp,int64_t *allocsizep)
return(buf);
}
void *OS_filestr(int64_t *allocsizep,char *fname)
void *OS_filestr(long *allocsizep,char *fname)
{
int64_t filesize = 0; char *buf = 0;
long filesize = 0; char *buf = 0;
*allocsizep = 0;
return(OS_loadfile(fname,&buf,&filesize,allocsizep));
}
@ -828,6 +830,10 @@ void *OS_tmpalloc(char *dirname,char *name,struct OS_memspace *mem,long origsize
void OS_init()
{
extern bits256 GENESIS_PUBKEY,GENESIS_PRIVKEY;
tai_now();
decode_hex(GENESIS_PUBKEY.bytes,sizeof(GENESIS_PUBKEY),GENESIS_PUBKEYSTR);
decode_hex(GENESIS_PRIVKEY.bytes,sizeof(GENESIS_PRIVKEY),GENESIS_PRIVKEYSTR);
SaM_PrepareIndices();
return(OS_portable_init());
}

12
crypto777/iguana_serdes.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@ -54,13 +54,9 @@ int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endian
int32_t iguana_validatehdr(struct iguana_msghdr *H)
{
int32_t i,len; char *validcommands[] =
{
"SuperNET", "version", "verack", "getaddr", "addr", "inv", "getdata", "notfound", "getblocks", "getheaders",
"headers", "tx", "block", "mempool", "ping", "pong", "reject", "filterload", "filteradd", "filterclear", "merkleblock", "alert"
};
for (i=0; i<sizeof(validcommands)/sizeof(*validcommands); i++)
if ( strcmp(H->command,validcommands[i]) == 0 )
int32_t i,len;
for (i=0; Iguana_validcommands[i]!=0&&Iguana_validcommands[i][0]!=0; i++)
if ( strcmp(H->command,Iguana_validcommands[i]) == 0 )
{
iguana_rwnum(0,H->serdatalen,sizeof(H->serdatalen),(uint32_t *)&len);
if ( len > IGUANA_MAXPACKETSIZE )

79
crypto777/iguana_utils.c

@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2015 The SuperNET Developers. *
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@ -33,6 +33,15 @@ char *bits256_str(char hexstr[65],bits256 x)
return(hexstr);
}
bits256 bits256_conv(char *hexstr)
{
bits256 x;
memset(&x,0,sizeof(x));
if ( strlen(hexstr) == sizeof(x)*2)
decode_hex(x.bytes,sizeof(x.bytes),hexstr);
return(x);
}
char *bits256_lstr(char hexstr[65],bits256 x)
{
bits256 revx; int32_t i;
@ -94,6 +103,15 @@ bits256 bits256_from_compact(uint32_t c)
return(x);
}
int32_t bitweight(uint64_t x)
{
int i,wt = 0;
for (i=0; i<64; i++)
if ( (1LL << i) & x )
wt++;
return(wt);
}
void calc_OP_HASH160(char hexstr[41],uint8_t hash160[20],char *pubkey)
{
uint8_t sha256[32],buf[4096]; int32_t len;
@ -280,8 +298,11 @@ int32_t decode_hex(unsigned char *bytes,int32_t n,char *hex)
}
if ( n == 0 || (hex[n*2+1] == 0 && hex[n*2] != 0) )
{
bytes[0] = unhex(hex[0]);
printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex));
if ( n > 0 )
{
bytes[0] = unhex(hex[0]);
printf("decode_hex n.%d hex[0] (%c) -> %d hex.(%s) [n*2+1: %d] [n*2: %d %c] len.%ld\n",n,hex[0],bytes[0],hex,hex[n*2+1],hex[n*2],hex[n*2],(long)strlen(hex));
}
#ifdef __APPLE__
getchar();
#endif
@ -429,6 +450,25 @@ int32_t has_backslash(char *str)
return(0);
}
static int _increasing_double(const void *a,const void *b)
{
#define double_a (*(double *)a)
#define double_b (*(double *)b)
if ( double_b > double_a )
return(-1);
else if ( double_b < double_a )
return(1);
return(0);
#undef double_a
#undef double_b
}
int32_t sortds(double *buf,uint32_t num,int32_t size)
{
qsort(buf,num,size,_increasing_double);
return(0);
}
/*int32_t iguana_sortbignum(void *buf,int32_t size,uint32_t num,int32_t structsize,int32_t dir)
{
int32_t retval = 0;
@ -584,7 +624,7 @@ int32_t nn_base64_decode (const char *in, size_t in_len,uint8_t *out, size_t out
ch = DECODEMAP [(uint32_t)in [ii]];
/* Discard invalid characters as per RFC 2045. */
// Discard invalid characters as per RFC 2045.
if (ch == 0xFF)
break;
@ -634,7 +674,7 @@ int32_t nn_base64_encode (const uint8_t *in, size_t in_len,char *out, size_t out
out [io++] = ENCODEMAP [v & 63];
}
/* Pad to a multiple of 3. */
// Pad to a multiple of 3
while (io & 3) {
if (io >= out_len)
return -ENOBUFS;
@ -648,6 +688,7 @@ int32_t nn_base64_encode (const uint8_t *in, size_t in_len,char *out, size_t out
return io;
}
/*
NXT address converter,
Ported from original javascript (nxtchg)
@ -769,6 +810,17 @@ int32_t RS_encode(char *rsaddr,uint64_t id)
return(0);
}
void calc_hexstr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
{
init_hexbytes_noT(hexstr,(void *)msg,len+1);
}
void calc_unhexstr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
{
decode_hex((void *)hexstr,len>>1,(void *)msg);
hexstr[len>>1] = 0;
}
void calc_base64_encodestr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
{
nn_base64_encode(msg,len,hexstr,64);
@ -817,8 +869,15 @@ void calc_md5str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
void calc_crc32str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
{
uint32_t crc = calc_crc32(0,msg,len);
init_hexbytes_noT(hexstr,(uint8_t *)&crc,sizeof(crc));
uint32_t crc; uint8_t serialized[sizeof(crc)];
crc = calc_crc32(0,msg,len);
//iguana_rwnum(1,serialized,sizeof(crc),&crc);
serialized[3] = (crc & 0xff), crc >>= 8;
serialized[2] = (crc & 0xff), crc >>= 8;
serialized[1] = (crc & 0xff), crc >>= 8;
serialized[0] = (crc & 0xff), crc >>= 8;
init_hexbytes_noT(hexstr,serialized,sizeof(crc));
//printf("crc.%08x vs revcrc.%08x -> %s\n",crc,*(uint32_t *)serialized,hexstr);
}
void calc_NXTaddr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
@ -830,6 +889,10 @@ void calc_NXTaddr(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
void calc_curve25519_str(char *hexstr,uint8_t *buf,uint8_t *msg,int32_t len)
{
bits256 x = curve25519(*(bits256 *)msg,curve25519_basepoint9());
bits256 x,priv,pub;
if ( len != sizeof(bits256)*2 || is_hexstr((char *)msg,64) == 0 )
conv_NXTpassword(priv.bytes,pub.bytes,msg,len);
else priv = *(bits256 *)msg;
x = curve25519(priv,curve25519_basepoint9());
init_hexbytes_noT(hexstr,x.bytes,sizeof(x));
}

17
crypto777/inet.c

@ -338,9 +338,9 @@ static int inet_pton6(char *src, unsigned char *dst) {
return 0;
}
int32_t parse_ipaddr(char *ipaddr,char *ip_port)
uint16_t parse_ipaddr(char *ipaddr,char *ip_port)
{
int32_t j,port = 0;
int32_t j; uint16_t port = 0;
if ( ip_port != 0 && ip_port[0] != 0 )
{
strcpy(ipaddr,ip_port);
@ -388,11 +388,14 @@ void expand_ipbits(char *ipaddr,uint64_t ipbits)
uint64_t calc_ipbits(char *ip_port)
{
uint64_t ipbits; char ipaddr[64];
ipbits = _calc_ipbits(ip_port);
expand_ipbits(ipaddr,ipbits);
if ( ipbits != 0 && strcmp(ipaddr,ip_port) != 0 )
printf("calc_ipbits error: (%s) -> %llx -> (%s)\n",ip_port,(long long)ipbits,ipaddr);
uint64_t ipbits = 0; char ipaddr[64];
if ( ip_port != 0 )
{
ipbits = _calc_ipbits(ip_port);
expand_ipbits(ipaddr,ipbits);
if ( ipbits != 0 && strcmp(ipaddr,ip_port) != 0 )
printf("calc_ipbits error: (%s) -> %llx -> (%s)\n",ip_port,(long long)ipbits,ipaddr);//, getchar();
}
return(ipbits);
}

8
crypto777/m_unix

@ -1,2 +1,8 @@
gcc -c -O2 *.c jpeg/*.c jpeg/unix/*.c
#DNN_DISABLE_GETADDRINFO_A=1 -DNN_USE_LITERAL_IFADDR=1 -DNN_HAVE_STDINT=1 -DNN_HAVE_MSG_CONTROL=1 -DNN_HAVE_SEMAPHORE=1 -DNN_HAVE_POLL=1 -DNN_HAVE_SOCKETPAIR=1 -DNN_USE_POLL=1
#nanosrc/core/global.c nanosrc/core/ep.c nanosrc/core/epbase.c nanosrc/core/pipe.c nanosrc/core/poll.c nanosrc/core/sock.c nanosrc/core/sockbase.c nanosrc/core/symbol.c nanosrc/devices/device.c nanosrc/devices/tcpmuxd.c nanosrc/aio/ctx.c nanosrc/aio/fsm.c nanosrc/aio/poller.c nanosrc/aio/pool.c nanosrc/aio/timer.c nanosrc/aio/usock.c nanosrc/aio/timerset.c nanosrc/aio/worker.c nanosrc/utils/alloc.c nanosrc/utils/atomic.c nanosrc/utils/chunk.c nanosrc/utils/chunkref.c nanosrc/utils/clock.c nanosrc/utils/closefd.c nanosrc/utils/efd.c nanosrc/utils/err.c nanosrc/utils/glock.c nanosrc/utils/hash.c nanosrc/utils/list.c nanosrc/utils/msg.c nanosrc/utils/mutex.c nanosrc/utils/queue.c nanosrc/utils/random.c nanosrc/utils/sem.c nanosrc/utils/sleep.c nanosrc/utils/stopwatch.c nanosrc/utils/thread.c nanosrc/utils/wire.c nanosrc/protocols/utils/dist.c nanosrc/protocols/utils/excl.c nanosrc/protocols/utils/fq.c nanosrc/protocols/utils/lb.c nanosrc/protocols/utils/priolist.c nanosrc/protocols/bus/bus.c nanosrc/protocols/bus/xbus.c nanosrc/protocols/pipeline/push.c nanosrc/protocols/pipeline/pull.c nanosrc/protocols/pipeline/xpull.c nanosrc/protocols/pipeline/xpush.c nanosrc/protocols/pubsub/pub.c nanosrc/protocols/pubsub/sub.c nanosrc/protocols/pubsub/trie.c nanosrc/protocols/pubsub/xpub.c nanosrc/protocols/pubsub/xsub.c nanosrc/protocols/pair/pair.c nanosrc/protocols/pair/xpair.c nanosrc/protocols/reqrep/req.c nanosrc/protocols/reqrep/rep.c nanosrc/protocols/reqrep/task.c nanosrc/protocols/reqrep/xrep.c nanosrc/protocols/reqrep/xreq.c nanosrc/protocols/survey/respondent.c nanosrc/protocols/survey/surveyor.c nanosrc/protocols/survey/xrespondent.c nanosrc/protocols/survey/xsurveyor.c nanosrc/transports/utils/backoff.c nanosrc/transports/utils/dns.c nanosrc/transports/utils/iface.c nanosrc/transports/utils/literal.c nanosrc/transports/utils/port.c nanosrc/transports/utils/streamhdr.c nanosrc/transports/utils/base64.c nanosrc/transports/ipc/aipc.c nanosrc/transports/ipc/bipc.c nanosrc/transports/ipc/cipc.c nanosrc/transports/ipc/ipc.c nanosrc/transports/ipc/sipc.c nanosrc/transports/tcp/atcp.c nanosrc/transports/tcp/btcp.c nanosrc/transports/tcp/ctcp.c nanosrc/transports/tcp/stcp.c nanosrc/transports/tcp/tcp.c nanosrc/transports/inproc/binproc.c nanosrc/transports/inproc/cinproc.c nanosrc/transports/inproc/inproc.c nanosrc/transports/inproc/ins.c nanosrc/transports/inproc/msgqueue.c nanosrc/transports/inproc/sinproc.c
#include crypto777.sources
#gcc -c -O2 $(CRYPTO777_SRCS)
gcc -c -O2 *.c jpeg/*.c jpeg/unix/*.c
rm -f ../agents/libcrypto777.a; ar rcu ../agents/libcrypto777.a *.o

0
nanomsg/CMakeLists.txt → crypto777/nanosrc/CMakeLists.txt

0
nanomsg/README → crypto777/nanosrc/README

0
nanomsg/aio/ctx.c → crypto777/nanosrc/aio/ctx.c

0
nanomsg/aio/ctx.h → crypto777/nanosrc/aio/ctx.h

0
nanomsg/aio/fsm.c → crypto777/nanosrc/aio/fsm.c

0
nanomsg/aio/fsm.h → crypto777/nanosrc/aio/fsm.h

0
nanomsg/aio/poller.c → crypto777/nanosrc/aio/poller.c

0
nanomsg/aio/poller.h → crypto777/nanosrc/aio/poller.h

0
nanomsg/aio/poller_epoll.c → crypto777/nanosrc/aio/poller_epoll.c

0
nanomsg/aio/poller_epoll.h → crypto777/nanosrc/aio/poller_epoll.h

0
nanomsg/aio/poller_kqueue.c → crypto777/nanosrc/aio/poller_kqueue.c

0
nanomsg/aio/poller_kqueue.h → crypto777/nanosrc/aio/poller_kqueue.h

0
nanomsg/aio/poller_poll.c → crypto777/nanosrc/aio/poller_poll.c

0
nanomsg/aio/poller_poll.h → crypto777/nanosrc/aio/poller_poll.h

0
nanomsg/aio/pool.c → crypto777/nanosrc/aio/pool.c

0
nanomsg/aio/pool.h → crypto777/nanosrc/aio/pool.h

0
nanomsg/aio/timer.c → crypto777/nanosrc/aio/timer.c

0
nanomsg/aio/timer.h → crypto777/nanosrc/aio/timer.h

0
nanomsg/aio/timerset.c → crypto777/nanosrc/aio/timerset.c

0
nanomsg/aio/timerset.h → crypto777/nanosrc/aio/timerset.h

0
nanomsg/aio/usock.c → crypto777/nanosrc/aio/usock.c

0
nanomsg/aio/usock.h → crypto777/nanosrc/aio/usock.h

68
nanomsg/aio/usock_posix.c → crypto777/nanosrc/aio/usock_posix.c

@ -167,7 +167,7 @@ int nn_usock_start (struct nn_usock *self, int domain, int type, int protocol)
s = socket (domain, type, protocol);
if (nn_slow (s < 0))
return -errno;
//PostMessage("got socket s.%d\n",s);
//PNACL_message("got socket s.%d\n",s);
nn_usock_init_from_fd (self, s);
/* Start the state machine. */
@ -290,7 +290,7 @@ int nn_usock_bind (struct nn_usock *self, const struct sockaddr *addr,
errno_assert (rc == 0);
rc = bind (self->s, addr, (socklen_t) addrlen);
//PostMessage("usock.%d -> bind rc.%d errno.%d\n",self->s,rc,errno);
//printf("usock.%d -> bind rc.%d errno.%d %s\n",self->s,rc,errno,nn_strerror(errno));
if (nn_slow (rc != 0))
return -errno;
@ -306,7 +306,7 @@ int nn_usock_listen (struct nn_usock *self, int backlog)
/* Start listening for incoming connections. */
rc = listen (self->s, backlog);
//PostMessage("usock.%d -> listen rc.%d errno.%d\n",self->s,rc,errno);
//printf("usock.%d -> listen rc.%d errno.%d %s\n",self->s,rc,errno,nn_strerror(errno));
if (nn_slow (rc != 0))
return -errno;
@ -333,7 +333,7 @@ void nn_usock_accept (struct nn_usock *self, struct nn_usock *listener)
#else
s = accept (listener->s, NULL, NULL);
#endif
//PostMessage("usock.%d -> accept errno.%d s.%d\n",self->s,errno,s);
//printf("usock.%d -> accept errno.%d s.%d %s\n",self->s,errno,s,nn_strerror(errno));
/* Immediate success. */
if (nn_fast (s >= 0)) {
@ -366,7 +366,7 @@ void nn_usock_accept (struct nn_usock *self, struct nn_usock *listener)
and allow processing other events in the meantime */
if (nn_slow (errno != EAGAIN && errno != EWOULDBLOCK && errno != ECONNABORTED && errno != listener->errnum))
{
PostMessage("listen errno.%d\n",errno);
PNACL_message("listen errno.%d\n",errno);
listener->errnum = errno;
listener->state = NN_USOCK_STATE_ACCEPTING_ERROR;
nn_fsm_raise (&listener->fsm,
@ -393,7 +393,7 @@ void nn_usock_connect (struct nn_usock *self, const struct sockaddr *addr,
/* Do the connect itself. */
rc = connect(self->s,addr,(socklen_t)addrlen);
//PostMessage("usock.%d <- connect (%llx) rc.%d errno.%d\n",self->s,*(long long *)addr,rc,errno);
//printf("usock.%d <- connect (%llx) rc.%d errno.%d %s\n",self->s,*(long long *)addr,rc,errno,nn_strerror(errno));
/* Immediate success. */
if ( nn_fast(rc == 0) )
{
@ -404,7 +404,7 @@ void nn_usock_connect (struct nn_usock *self, const struct sockaddr *addr,
if ( nn_slow(errno != EINPROGRESS) )
{
self->errnum = errno;
PostMessage("error.%d not EINPROGRESS\n",errno);
PNACL_message("error.%d not EINPROGRESS\n",errno);
nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR);
return;
}
@ -433,9 +433,9 @@ void nn_usock_send (struct nn_usock *self, const struct nn_iovec *iov,
self->out.iov [out].iov_base = iov [i].iov_base;
self->out.iov [out].iov_len = iov [i].iov_len;
out++;
//PostMessage("{%d} ",(int)iov [i].iov_len);
//PNACL_message("{%d} ",(int)iov [i].iov_len);
}
//PostMessage("iov[%d]\n",out);
//PNACL_message("iov[%d]\n",out);
self->out.hdr.msg_iovlen = out;
/* Try to send the data immediately. */
@ -472,17 +472,17 @@ void nn_usock_recv (struct nn_usock *self, void *buf, size_t len, int *fd)
rc = nn_usock_recv_raw (self, buf, &nbytes);
if (nn_slow (rc < 0)) {
errnum_assert (rc == -ECONNRESET, -rc);
//PostMessage("rc.%d vs ECONNRESET\n",rc,ECONNRESET);
//PNACL_message("rc.%d vs ECONNRESET\n",rc,ECONNRESET);
nn_fsm_action (&self->fsm, NN_USOCK_ACTION_ERROR);
return;
}
//int i;
//for (i=0; i<16&&i<nbytes; i++)
// PostMessage("%02x ",((uint8_t *)buf)[i]);
//PostMessage("nn_usock_recv nbytes.%d\n",(int)nbytes);
// PNACL_message("%02x ",((uint8_t *)buf)[i]);
//PNACL_message("nn_usock_recv nbytes.%d\n",(int)nbytes);
/* Success. */
if (nn_fast (nbytes == len)) {
//PostMessage("raise NN_USOCK_RECEIVED\n");
//PNACL_message("raise NN_USOCK_RECEIVED\n");
nn_fsm_raise (&self->fsm, &self->event_received, NN_USOCK_RECEIVED);
return;
}
@ -1021,19 +1021,19 @@ int32_t nn_getiovec_size(uint8_t *buf,int32_t maxlen,struct msghdr *hdr)
if ( nn_slow(iov->iov_len == NN_MSG) )
{
errno = EINVAL;
PostMessage("ERROR: iov->iov_len == NN_MSG\n");
PNACL_message("ERROR: iov->iov_len == NN_MSG\n");
return(-1);
}
if ( nn_slow(!iov->iov_base && iov->iov_len) )
{
errno = EFAULT;
PostMessage("ERROR: !iov->iov_base && iov->iov_len\n");
PNACL_message("ERROR: !iov->iov_base && iov->iov_len\n");
return(-1);
}
if ( maxlen > 0 && nn_slow(size + iov->iov_len > maxlen) )
{
errno = EINVAL;
PostMessage("ERROR: sz.%d + iov->iov_len.%d < maxlen.%d\n",(int32_t)size,(int32_t)iov->iov_len,maxlen);
PNACL_message("ERROR: sz.%d + iov->iov_len.%d < maxlen.%d\n",(int32_t)size,(int32_t)iov->iov_len,maxlen);
return(-1);
}
if ( iov->iov_len > 0 )
@ -1069,10 +1069,10 @@ ssize_t mysendmsg(int32_t usock,struct msghdr *hdr,int32_t flags)
if ( nn_getiovec_size(&buf[offset],veclen,hdr) == veclen )
{
nbytes = send(usock,buf,offset + veclen,0);
//PostMessage(">>>>>>>>> send.[%d %d %d %d] (n.%d v.%d c.%d)-> usock.%d nbytes.%d\n",buf[offset],buf[offset+1],buf[offset+2],buf[offset+3],(int32_t)offset+veclen,veclen,clen,usock,(int32_t)nbytes);
//PNACL_message(">>>>>>>>> send.[%d %d %d %d] (n.%d v.%d c.%d)-> usock.%d nbytes.%d\n",buf[offset],buf[offset+1],buf[offset+2],buf[offset+3],(int32_t)offset+veclen,veclen,clen,usock,(int32_t)nbytes);
if ( nbytes != offset + veclen )
{
//PostMessage("nbytes.%d != offset.%d veclen.%d errno.%d usock.%d\n",(int32_t)nbytes,(int32_t)offset,veclen,errno,usock);
//PNACL_message("nbytes.%d != offset.%d veclen.%d errno.%d usock.%d\n",(int32_t)nbytes,(int32_t)offset,veclen,errno,usock);
}
if ( nbytes >= offset )
nbytes -= offset;
@ -1080,19 +1080,19 @@ ssize_t mysendmsg(int32_t usock,struct msghdr *hdr,int32_t flags)
else
{
err = -errno;
PostMessage("mysendmsg: unexpected nn_getiovec_size error %d\n",err);
PNACL_message("mysendmsg: unexpected nn_getiovec_size error %d\n",err);
}
if ( buf != _buf )
free(buf);
if ( err != 0 )
{
PostMessage("nn_usock_send_raw errno.%d err.%d\n",errno,err);
PNACL_message("nn_usock_send_raw errno.%d err.%d\n",errno,err);
return(-errno);
}
}
else
{
PostMessage("nn_usock_send_raw errno.%d invalid iovec size\n",errno);
PNACL_message("nn_usock_send_raw errno.%d invalid iovec size\n",errno);
return(-errno);
}
return(nbytes);
@ -1104,32 +1104,32 @@ ssize_t myrecvmsg(int32_t usock,struct msghdr *hdr,int32_t flags,int32_t len)
iov = hdr->msg_iov;
/*if ( (n= (int32_t)recv(usock,lens,sizeof(lens),0)) != sizeof(lens) )
{
PostMessage("error getting veclen/clen n.%d vs %d from usock.%d\n",n,(int32_t)sizeof(lens),usock);
PNACL_message("error getting veclen/clen n.%d vs %d from usock.%d\n",n,(int32_t)sizeof(lens),usock);
return(0);
} else PostMessage("GOT %d bytes from usock.%d\n",n,usock);
} else PNACL_message("GOT %d bytes from usock.%d\n",n,usock);
offset = 0;
veclen = lens[offset++];
veclen |= ((int32_t)lens[offset++] << 8);
veclen |= ((int32_t)lens[offset++] << 16);
clen = lens[offset++];
clen |= ((int32_t)lens[offset++] << 8);
PostMessage("veclen.%d clen.%d waiting in usock.%d\n",veclen,clen,usock);
PNACL_message("veclen.%d clen.%d waiting in usock.%d\n",veclen,clen,usock);
if ( clen > 0 )
{
if ( (cbytes= (int32_t)recv(usock,hdr->msg_control,clen,0)) != clen )
{
PostMessage("myrecvmsg: unexpected cbytes.%d vs clen.%d\n",cbytes,clen);
PNACL_message("myrecvmsg: unexpected cbytes.%d vs clen.%d\n",cbytes,clen);
}
} else cbytes = 0;*/
hdr->msg_controllen = 0;
if ( (nbytes= (int32_t)recv(usock,iov->iov_base,len,0)) != len )
{
//PostMessage("myrecvmsg: partial nbytes.%d vs veclen.%d\n",(int32_t)nbytes,len);
//PNACL_message("myrecvmsg: partial nbytes.%d vs veclen.%d\n",(int32_t)nbytes,len);
}
//PostMessage("GOT nbytes.%d of len.%d from usock.%d\n",(int32_t)nbytes,len,usock);
//PNACL_message("GOT nbytes.%d of len.%d from usock.%d\n",(int32_t)nbytes,len,usock);
if ( 0 && nbytes > 0 )
{
PostMessage("got nbytes.%d from usock.%d [%d %d %d %d]\n",(int32_t)nbytes,usock,((uint8_t *)iov->iov_base)[0],((uint8_t *)iov->iov_base)[1],((uint8_t *)iov->iov_base)[2],((uint8_t *)iov->iov_base)[3]);
PNACL_message("got nbytes.%d from usock.%d [%d %d %d %d]\n",(int32_t)nbytes,usock,((uint8_t *)iov->iov_base)[0],((uint8_t *)iov->iov_base)[1],((uint8_t *)iov->iov_base)[2],((uint8_t *)iov->iov_base)[3]);
}
return(nbytes);
}
@ -1144,7 +1144,7 @@ static int nn_usock_send_raw (struct nn_usock *self, struct msghdr *hdr)
nbytes = sendmsg(self->s,hdr,MSG_NOSIGNAL);
#else
nbytes = sendmsg(self->s,hdr,0);
printf("sendmsg nbytes.%d\n",(int32_t)nbytes);
//printf("sendmsg nbytes.%d\n",(int32_t)nbytes);
#endif
#endif
/* Handle errors. */
@ -1199,13 +1199,13 @@ int32_t nn_process_cmsg(struct nn_usock *self,struct msghdr *hdr)
memcpy(&retval,(int32_t *)CMSG_DATA(cmsg),sizeof(int32_t));
if ( self->in.pfd )
{
PostMessage("CMSG set self->in.pfd (%d)\n",retval);
PNACL_message("CMSG set self->in.pfd (%d)\n",retval);
*self->in.pfd = retval;
self->in.pfd = NULL;
}
else
{
PostMessage("CMSG nn_closefd(%d)\n",retval);
PNACL_message("CMSG nn_closefd(%d)\n",retval);
nn_closefd(retval);
}
break;
@ -1286,7 +1286,7 @@ static int nn_usock_recv_raw(struct nn_usock *self, void *buf, size_t *len)
#if NN_USE_MYMSG
nbytes = myrecvmsg(self->s,&hdr,0,(int32_t)iov.iov_len);
//printf("got nbytes.%d from recvmsg errno.%d\n",(int32_t)nbytes,errno);
//printf("got nbytes.%d from recvmsg errno.%d %s\n",(int32_t)nbytes,errno,nn_strerror(errno));
#else
nbytes = recvmsg (self->s, &hdr, 0);
#endif
@ -1298,7 +1298,7 @@ static int nn_usock_recv_raw(struct nn_usock *self, void *buf, size_t *len)
nbytes = 0;
else
{
printf("errno.%d\n",errno);
printf("recvraw errno.%d %s\n",errno,nn_strerror(errno));
// If the peer closes the connection, return ECONNRESET
errno_assert(errno == ECONNRESET || errno == ENOTCONN || errno == ECONNREFUSED || errno == ETIMEDOUT || errno == EHOSTUNREACH
#if NN_USE_MYMSG
@ -1310,7 +1310,7 @@ static int nn_usock_recv_raw(struct nn_usock *self, void *buf, size_t *len)
}
} else if ( hdr.msg_controllen > 0 )
nn_process_cmsg(self,&hdr);
//PostMessage("nbytes.%d length.%d *len %d\n",(int)nbytes,(int)length,(int)*len);
//PNACL_message("nbytes.%d length.%d *len %d\n",(int)nbytes,(int)length,(int)*len);
// If the data were received directly into the place we can return straight away
if ( usebuf != 0 )

0
nanomsg/aio/usock_posix.c_dev → crypto777/nanosrc/aio/usock_posix.c_dev

0
nanomsg/aio/usock_posix.h → crypto777/nanosrc/aio/usock_posix.h

0
nanomsg/aio/usock_win.c → crypto777/nanosrc/aio/usock_win.c

0
nanomsg/aio/usock_win.h → crypto777/nanosrc/aio/usock_win.h

0
nanomsg/aio/worker.c → crypto777/nanosrc/aio/worker.c

0
nanomsg/aio/worker.h → crypto777/nanosrc/aio/worker.h

44
nanomsg/aio/worker_posix.c → crypto777/nanosrc/aio/worker_posix.c

@ -98,31 +98,33 @@ void nn_worker_task_term (struct nn_worker_task *self)
nn_queue_item_term (&self->item);
}
#include <unistd.h>
int nn_worker_init(struct nn_worker *self)
{
int32_t rc;
//PostMessage("nn_worker_init %p\n",self);
PNACL_message("nn_worker_init %p\n",self);
sleep(1);
rc = nn_efd_init(&self->efd);
//PostMessage("efd init: rc.%d\n",rc);
PNACL_message("efd init: rc.%d\n",rc);
if ( rc < 0 )
return rc;
//PostMessage("nn_mutex_init\n");
PNACL_message("nn_mutex_init\n");
nn_mutex_init(&self->sync);
//PostMessage("nn_queue_init\n");
PNACL_message("nn_queue_init\n");
nn_queue_init(&self->tasks);
//PostMessage("nn_queue_item_init\n");
PNACL_message("nn_queue_item_init\n");
nn_queue_item_init(&self->stop);
//PostMessage("nn_poller_init\n");
PNACL_message("nn_poller_init\n");
nn_poller_init(&self->poller);
//PostMessage("nn_poller_add\n");
PNACL_message("nn_poller_add\n");
nn_poller_add(&self->poller,nn_efd_getfd(&self->efd),&self->efd_hndl);
//PostMessage("nn_poller_set_in\n");
PNACL_message("nn_poller_set_in\n");
nn_poller_set_in(&self->poller, &self->efd_hndl);
//PostMessage("nn_timerset_init\n");
PNACL_message("nn_timerset_init\n");
nn_timerset_init(&self->timerset);
//PostMessage("nn_thread_init\n");
PNACL_message("nn_thread_init\n");
nn_thread_init(&self->thread,nn_worker_routine, self);
//PostMessage("finished nn_worker_init\n");
PNACL_message("finished nn_worker_init\n");
return 0;
}
@ -172,7 +174,7 @@ static void nn_worker_routine (void *arg)
struct nn_worker_task *task;
struct nn_worker_fd *fd;
struct nn_worker_timer *timer;
//PostMessage("nn_worker_routine started\n");
PNACL_message("nn_worker_routine started\n");
self = (struct nn_worker*) arg;
while ( 1 ) // Infinite loop. It will be interrupted only when the object is shut down.
{
@ -184,7 +186,7 @@ static void nn_worker_routine (void *arg)
rc = nn_timerset_event(&self->timerset, &thndl);
if ( rc == -EAGAIN )
break;
//PostMessage("nn_worker process expired user\n");
PNACL_message("nn_worker process expired user\n");
errnum_assert(rc == 0, -rc);
timer = nn_cont(thndl, struct nn_worker_timer, hndl);
nn_ctx_enter(timer->owner->ctx);
@ -196,7 +198,7 @@ static void nn_worker_routine (void *arg)
rc = nn_poller_event(&self->poller,&pevent,&phndl); // Get next poller event, such as IN or OUT
if ( nn_slow(rc == -EAGAIN) )
break;
//PostMessage("nn_worker process all events from the poller\n");
PNACL_message("nn_worker process all events from the poller\n");
if ( phndl == &self->efd_hndl ) // If there are any new incoming worker tasks, process them
{
nn_assert (pevent == NN_POLLER_IN);
@ -211,14 +213,14 @@ static void nn_worker_routine (void *arg)
item = nn_queue_pop(&tasks); // Next worker task
if ( nn_slow(!item) )
break;
//PostMessage("nn_worker next worker task\n");
PNACL_message("nn_worker next worker task\n");
if ( nn_slow(item == &self->stop) ) // If the worker thread is asked to stop, do so
{
nn_queue_term(&tasks);
return;
}
// It's a user-defined task. Notify the user that it has arrived in the worker thread
//PostMessage("nn_worker user defined task\n");
PNACL_message("nn_worker user defined task\n");
task = nn_cont(item,struct nn_worker_task,item);
nn_ctx_enter(task->owner->ctx);
nn_fsm_feed(task->owner,task->src,NN_WORKER_TASK_EXECUTE,task);
@ -227,15 +229,15 @@ static void nn_worker_routine (void *arg)
nn_queue_term (&tasks);
continue;
}
//PostMessage("nn_worker true i/o, invoke handler\n");
PNACL_message("nn_worker true i/o, invoke handler\n");
fd = nn_cont(phndl,struct nn_worker_fd,hndl); // It's a true I/O event. Invoke the handler
//PostMessage("nn_worker true i/o, fd.%p\n",fd);
PNACL_message("nn_worker true i/o, fd.%p\n",fd);
nn_ctx_enter(fd->owner->ctx);
//PostMessage("nn_worker true i/o, after nn_ctx_enter\n");
PNACL_message("nn_worker true i/o, after nn_ctx_enter\n");
nn_fsm_feed(fd->owner,fd->src,pevent,fd);
//PostMessage("nn_worker true i/o, after nn_fsm_feed leave.%p\n",fd->owner->ctx);
PNACL_message("nn_worker true i/o, after nn_fsm_feed leave.%p\n",fd->owner->ctx);
nn_ctx_leave(fd->owner->ctx);
//PostMessage("nn_worker true i/o, after nn_ctx_leave\n");
PNACL_message("nn_worker true i/o, after nn_ctx_leave\n");
}
}
}

0
nanomsg/aio/worker_posix.h → crypto777/nanosrc/aio/worker_posix.h

0
nanomsg/aio/worker_win.c → crypto777/nanosrc/aio/worker_win.c

0
nanomsg/aio/worker_win.h → crypto777/nanosrc/aio/worker_win.h

0
includes/nanomsg/bus.h → crypto777/nanosrc/bus.h

0
nanomsg/core/README → crypto777/nanosrc/core/README

0
nanomsg/core/ep.c → crypto777/nanosrc/core/ep.c

0
nanomsg/core/ep.h → crypto777/nanosrc/core/ep.h

0
nanomsg/core/epbase.c → crypto777/nanosrc/core/epbase.c

127
nanomsg/core/global.c → crypto777/nanosrc/core/global.c

@ -191,7 +191,19 @@ static void nn_global_shutdown (struct nn_fsm *self,int32_t src,int32_t type,voi
int32_t nn_errno(void) { return nn_err_errno(); }
const char *nn_strerror(int32_t errnum) { return nn_err_strerror(errnum); }
static void nn_global_add_transport (struct nn_transport *transport)
{
if (transport->init)
transport->init ();
nn_list_insert (&SELF.transports, &transport->item,nn_list_end (&SELF.transports));
}
static void nn_global_add_socktype (struct nn_socktype *socktype)
{
PNACL_message("add socktype %p -> %p\n",socktype,&SELF.socktypes);
nn_list_insert (&SELF.socktypes, &socktype->item,nn_list_end (&SELF.socktypes));
PNACL_message("added socktype %p -> %p\n",socktype,&SELF.socktypes);
}
void nn_global_init (void)
{
int32_t i,rc; char *envvar,*addr;
@ -205,15 +217,16 @@ void nn_global_init (void)
nn_assert (LOBYTE (data.wVersion) == 2 &&
HIBYTE (data.wVersion) == 2);
#endif
PNACL_message("nn_global_init\n");
nn_alloc_init(); // Initialise the memory allocation subsystem
nn_random_seed(); // Seed the pseudo-random number generator
// Allocate the global table of SP sockets.
SELF.socks = nn_alloc((sizeof (struct nn_sock*) * NN_MAX_SOCKETS) + (sizeof (uint16_t) * NN_MAX_SOCKETS), "socket table");
SELF.socks = nn_alloc((sizeof (struct nn_sock *) * NN_MAX_SOCKETS) + (sizeof (uint16_t) * NN_MAX_SOCKETS), "socket table");
alloc_assert (SELF.socks);
for (i=0; i<NN_MAX_SOCKETS; i++)
SELF.socks[i] = NULL;
SELF.nsocks = SELF.flags = 0;
//PostMessage("do getenv\n");
PNACL_message("do getenv\n");
envvar = getenv("NN_PRINT_ERRORS"); // Print connection and accepting errors to the stderr
SELF.print_errors = envvar && *envvar; // any non-empty string is true
envvar = getenv("NN_PRINT_STATISTICS"); // Print socket statistics to stderr
@ -222,53 +235,58 @@ void nn_global_init (void)
alloc_assert (SELF.unused);
for (i=0; i<NN_MAX_SOCKETS; i++)
SELF.unused [i] = NN_MAX_SOCKETS - i - 1;
//PostMessage("list init\n");
PNACL_message("list init\n");
// Initialise other parts of the global state.
nn_list_init(&SELF.transports);
nn_list_init(&SELF.socktypes);
//PostMessage("transports init\n");
sleep(1);
PNACL_message("transports init\n");
// Plug in individual transports.
nn_global_add_transport(nn_ipc);
//nn_global_add_transport(nn_ipc);
nn_global_add_transport(nn_tcp);
//#ifdef NN_ENABLE_EXTRA
nn_global_add_transport(nn_inproc);
//nn_global_add_transport(nn_inproc);
//nn_global_add_transport(nn_ws);
//nn_global_add_transport(nn_tcpmux);
//PostMessage("socktypes init\n");
sleep(1);
PNACL_message("socktypes init\n");
// Plug in individual socktypes
nn_global_add_socktype(nn_pair_socktype);
sleep(1);
PNACL_message("nn_xpair_socktype init\n");
nn_global_add_socktype(nn_xpair_socktype);
nn_global_add_socktype(nn_rep_socktype);
nn_global_add_socktype(nn_req_socktype);
nn_global_add_socktype(nn_xrep_socktype);
nn_global_add_socktype(nn_xreq_socktype);
nn_global_add_socktype(nn_respondent_socktype);
nn_global_add_socktype(nn_surveyor_socktype);
nn_global_add_socktype(nn_xrespondent_socktype);
nn_global_add_socktype(nn_xsurveyor_socktype);
//#endif
nn_global_add_socktype(nn_pub_socktype);
nn_global_add_socktype(nn_sub_socktype);
nn_global_add_socktype(nn_xpub_socktype);
nn_global_add_socktype(nn_xsub_socktype);
nn_global_add_socktype(nn_push_socktype);
nn_global_add_socktype(nn_xpush_socktype);
nn_global_add_socktype(nn_pull_socktype);
nn_global_add_socktype(nn_xpull_socktype);
nn_global_add_socktype(nn_bus_socktype);
nn_global_add_socktype(nn_xbus_socktype);
//PostMessage("do pool init\n");
PNACL_message("did nn_xpair_socktype init\n");
//nn_global_add_socktype(nn_rep_socktype);
//nn_global_add_socktype(nn_req_socktype);
//nn_global_add_socktype(nn_xrep_socktype);
//nn_global_add_socktype(nn_xreq_socktype);
//nn_global_add_socktype(nn_respondent_socktype);
//nn_global_add_socktype(nn_surveyor_socktype);
//nn_global_add_socktype(nn_xrespondent_socktype);
//nn_global_add_socktype(nn_xsurveyor_socktype);
//nn_global_add_socktype(nn_pub_socktype);
//nn_global_add_socktype(nn_sub_socktype);
//nn_global_add_socktype(nn_xpub_socktype);
//nn_global_add_socktype(nn_xsub_socktype);
//nn_global_add_socktype(nn_push_socktype);
//nn_global_add_socktype(nn_xpush_socktype);
//nn_global_add_socktype(nn_pull_socktype);
//nn_global_add_socktype(nn_xpull_socktype);
//nn_global_add_socktype(nn_bus_socktype);
//nn_global_add_socktype(nn_xbus_socktype);
sleep(1);
PNACL_message("do pool init\n");
nn_pool_init(&SELF.pool); // Start the worker threads
//PostMessage("do FSM init\n");
sleep(1);
PNACL_message("do FSM init\n");
nn_fsm_init_root(&SELF.fsm,nn_global_handler,nn_global_shutdown,&SELF.ctx); // Start FSM
SELF.state = NN_GLOBAL_STATE_IDLE;
//PostMessage("ctx init\n");
PNACL_message("ctx init\n");
nn_ctx_init(&SELF.ctx, nn_global_getpool(),NULL);
//PostMessage("timer init\n");
PNACL_message("timer init\n");
nn_timer_init(&SELF.stat_timer,NN_GLOBAL_SRC_STAT_TIMER,&SELF.fsm);
//PostMessage("do FSM start\n");
PNACL_message("do FSM start\n");
nn_fsm_start(&SELF.fsm);
//PostMessage("special sockets init\n");
PNACL_message("special sockets init\n");
// Initializing special sockets.
addr = getenv("NN_STATISTICS_SOCKET");
if ( addr != 0 )
@ -484,15 +502,15 @@ int32_t nn_global_create_socket(int32_t domain,int32_t protocol)
int nn_socket(int domain,int protocol)
{
int rc;
PNACL_message("nn_socket flags.%d\n",SELF.flags);
nn_glock_lock();
//PostMessage("nn_socket flags.%d\n",SELF.flags);
if (nn_slow (SELF.flags & NN_CTX_FLAG_ZOMBIE)) // If nn_term() was already called, return ETERM
{
nn_glock_unlock();
errno = ETERM;
return -1;
}
//PostMessage("nn_socket flags.%d\n",SELF.flags);
//PNACL_message("nn_socket flags.%d\n",SELF.flags);
nn_global_init(); // Make sure that global state is initialised
rc = nn_global_create_socket (domain, protocol);
if ( rc < 0 )
@ -503,7 +521,7 @@ int nn_socket(int domain,int protocol)
return -1;
}
nn_glock_unlock();
//PostMessage("did nn_global_init\n");
//PNACL_message("did nn_global_init\n");
return rc;
}
@ -653,7 +671,7 @@ int32_t nn_recv(int32_t s,void *buf,size_t len,int32_t flags)
int32_t nn_sendmsg(int32_t s,const struct nn_msghdr *msghdr,int32_t flags)
{
int32_t rc,i,nnmsg; size_t sz; struct nn_iovec *iov; struct nn_msg msg; void *chunk;
//PostMessage("nn_sendmsg.(%d) \n",s);
//PNACL_message("nn_sendmsg.(%d) \n",s);
NN_BASIC_CHECKS;
if ( nn_slow(!msghdr) )
{
@ -753,13 +771,13 @@ int32_t nn_recvmsg(int32_t s,struct nn_msghdr *msghdr,int32_t flags)
chunk = nn_chunkref_getchunk(&msg.body);
*(void **)(msghdr->msg_iov[0].iov_base) = chunk;
sz = nn_chunk_size(chunk);
//PostMessage("got message -> iov_base.%p sz.%d\n",msghdr->msg_iov[0].iov_base,(int32_t)sz);
//PNACL_message("got message -> iov_base.%p sz.%d\n",msghdr->msg_iov[0].iov_base,(int32_t)sz);
}
else // Copy the message content into the supplied gather array
{
data = nn_chunkref_data(&msg.body);
sz = nn_chunkref_size(&msg.body);
//PostMessage("got message -> data.%p sz.%d\n",data,(int32_t)sz);
//PNACL_message("got message -> data.%p sz.%d\n",data,(int32_t)sz);
for (i=0; i!=msghdr->msg_iovlen; i++)
{
iov = &msghdr->msg_iov[i];
@ -790,7 +808,7 @@ int32_t nn_recvmsg(int32_t s,struct nn_msghdr *msghdr,int32_t flags)
int32_t nn_sendmsg(int32_t s,const struct nn_msghdr *msghdr,int32_t flags)
{
int32_t rc,i,nnmsg; size_t sz,spsz; struct nn_iovec *iov; struct nn_msg msg; void *chunk; struct nn_cmsghdr *cmsg;
//PostMessage("nn_sendmsg.(%d) \n",s);
//PNACL_message("nn_sendmsg.(%d) \n",s);
NN_BASIC_CHECKS;
if ( nn_slow(!msghdr) )
{
@ -909,7 +927,7 @@ int32_t nn_recvmsg(int32_t s,struct nn_msghdr *msghdr,int32_t flags)
{
struct nn_msg msg; uint8_t *data; struct nn_iovec *iov; void *chunk,*ctrl; struct nn_cmsghdr *chdr;
int32_t i,rc; size_t sz,hdrssz,ctrlsz,spsz,sptotalsz;
//PostMessage("nn_recvmsg.(%d) \n",s);
//PNACL_message("nn_recvmsg.(%d) \n",s);
NN_BASIC_CHECKS;
if ( nn_slow(!msghdr) )
{
@ -921,7 +939,7 @@ int32_t nn_recvmsg(int32_t s,struct nn_msghdr *msghdr,int32_t flags)
errno = EMSGSIZE;
return -1;
}
//PostMessage("get a message from sock.%d\n",s);
//PNACL_message("get a message from sock.%d\n",s);
rc = nn_sock_recv(SELF.socks[s],&msg,flags); // Get a message
if ( nn_slow(rc < 0) )
{
@ -933,13 +951,13 @@ int32_t nn_recvmsg(int32_t s,struct nn_msghdr *msghdr,int32_t flags)
chunk = nn_chunkref_getchunk(&msg.body);
*(void **)(msghdr->msg_iov[0].iov_base) = chunk;
sz = nn_chunk_size(chunk);
//PostMessage("got message -> iov_base.%p sz.%d\n",msghdr->msg_iov[0].iov_base,(int32_t)sz);
//PNACL_message("got message -> iov_base.%p sz.%d\n",msghdr->msg_iov[0].iov_base,(int32_t)sz);
}
else // Copy the message content into the supplied gather array
{
data = nn_chunkref_data(&msg.body);
sz = nn_chunkref_size (&msg.body);
//PostMessage("got message -> data.%p sz.%d\n",data,(int32_t)sz);
//PNACL_message("got message -> data.%p sz.%d\n",data,(int32_t)sz);
for (i=0; i!=msghdr->msg_iovlen; i++)
{
iov = &msghdr->msg_iov[i];
@ -997,20 +1015,7 @@ int32_t nn_recvmsg(int32_t s,struct nn_msghdr *msghdr,int32_t flags)
}
#endif
static void nn_global_add_transport (struct nn_transport *transport)
{
if (transport->init)
transport->init ();
nn_list_insert (&SELF.transports, &transport->item,
nn_list_end (&SELF.transports));
}
static void nn_global_add_socktype (struct nn_socktype *socktype)
{
nn_list_insert (&SELF.socktypes, &socktype->item,
nn_list_end (&SELF.socktypes));
}
static void nn_global_submit_counter (int i, struct nn_sock *s,
char *name, uint64_t value)
@ -1144,7 +1149,7 @@ static void nn_global_submit_errors (int i, struct nn_sock *s,
len = snprintf (curbuf, buf_left,
" nanomsg: Endpoint %d [%s] error: %s\n",
ep->eid, nn_ep_getaddr (ep), nn_strerror (ep->last_errno));
PostMessage("%s\n",curbuf);
PNACL_message("%s\n",curbuf);
#endif
if (buf_left < len)
break;
@ -1241,7 +1246,7 @@ static int nn_global_create_ep (int s, const char *addr, int bind)
#ifdef NN_USE_MYMSG
if ( strncmp("inproc",proto,strlen("inproc")) != 0 && strncmp("ipc",proto,strlen("ipc")) != 0 && strncmp("tcp",proto,strlen("tcp")) != 0 )
{
PostMessage("only ipc, inproc and tcp transport is supported\n");
PNACL_message("only ipc, inproc and tcp transport is supported\n");
printf("only ipc, inproc and tcp transport is supported\n");
fprintf(stderr,"only ipc, inproc and tcp transport is supported\n");
exit(-1);
@ -1318,12 +1323,12 @@ static void nn_global_handler (struct nn_fsm *myself,int src, int type, NN_UNUSE
nn_timer_start (&global->stat_timer, 10000); // Start statistics collection timer
return;
default:
PostMessage("bad action %d type %d\n",src,type);
PNACL_message("bad action %d type %d\n",src,type);
nn_fsm_bad_action(global->state, src, type);
}
default:
PostMessage("bad source %d\n",src);
PNACL_message("bad source %d\n",src);
nn_fsm_bad_source(global->state, src, type);
}

0
nanomsg/core/global.h → crypto777/nanosrc/core/global.h

8
nanomsg/core/pipe.c → crypto777/nanosrc/core/pipe.c

@ -58,7 +58,7 @@ void nn_pipebase_init(struct nn_pipebase *self,const struct nn_pipebase_vfptr *v
memcpy(&self->options,&epbase->ep->options,sizeof(struct nn_ep_options));
nn_fsm_event_init(&self->in);
nn_fsm_event_init(&self->out);
//printf("pipebase_init vfptr.%p recv.%p rcvprio.%d\n",vfptr,vfptr->recv,self->options.rcvprio);
PNACL_message("pipebase_init vfptr.%p recv.%p rcvprio.%d\n",vfptr,vfptr->recv,self->options.rcvprio);
}
void nn_pipebase_term (struct nn_pipebase *self)
@ -78,7 +78,7 @@ int nn_pipebase_start (struct nn_pipebase *self)
self->instate = NN_PIPEBASE_INSTATE_ASYNC;
self->outstate = NN_PIPEBASE_OUTSTATE_IDLE;
rc = nn_sock_add(self->sock,(struct nn_pipe *)self);
//printf("nn_pipebase_start self.%p rc.%d\n",self,rc);
PNACL_message("nn_pipebase_start self.%p rc.%d\n",self,rc);
if ( nn_slow(rc < 0) )
{
self->state = NN_PIPEBASE_STATE_FAILED;
@ -98,7 +98,7 @@ void nn_pipebase_stop(struct nn_pipebase *self)
void nn_pipebase_received(struct nn_pipebase *self)
{
//printf("nn_pipebase_received\n");
PNACL_message("nn_pipebase_received\n");
if ( nn_fast(self->instate == NN_PIPEBASE_INSTATE_RECEIVING) )
{
self->instate = NN_PIPEBASE_INSTATE_RECEIVED;
@ -196,7 +196,7 @@ int nn_pipe_recv(struct nn_pipe *self,struct nn_msg *msg)
pipebase = (struct nn_pipebase*) self;
nn_assert (pipebase->instate == NN_PIPEBASE_INSTATE_IDLE);
pipebase->instate = NN_PIPEBASE_INSTATE_RECEIVING;
//printf("call pipebase recv\n");
PNACL_message("call pipebase recv\n");
rc = pipebase->vfptr->recv (pipebase,msg);
errnum_assert (rc >= 0, -rc);
if ( nn_fast(pipebase->instate == NN_PIPEBASE_INSTATE_RECEIVED) )

0
nanomsg/core/poll.c → crypto777/nanosrc/core/poll.c

8
nanomsg/core/sock.c → crypto777/nanosrc/core/sock.c

@ -489,11 +489,11 @@ int nn_sock_add_ep(struct nn_sock *self,struct nn_transport *transport,int32_t b
return rc;
}
nn_ep_start(ep);
//PostMessage("ep sock.(%s) started %s://(%s) bind.%d\n",self->socket_name,transport->name,addr,bind);
PNACL_message("ep sock.(%s) started %s://(%s) bind.%d\n",self->socket_name,transport->name,addr,bind);
eid = self->eid++; // Increase the endpoint ID for the next endpoint
nn_list_insert(&self->eps,&ep->item,nn_list_end(&self->eps)); // Add to the list of active endpoints
nn_ctx_leave (&self->ctx);
} else PostMessage("self->sock.(%s) %p already has (%s)\n",self->socket_name,self->sockbase->sock,addr);
} else PNACL_message("self->sock.(%s) %p already has (%s)\n",self->socket_name,self->sockbase->sock,addr);
return(ep->eid);
}
@ -973,12 +973,12 @@ void nn_sock_report_error(struct nn_sock *self,struct nn_ep *ep,int32_t errnum,c
if ( ep != 0 )
{
fprintf(stderr,"nanomsg: socket.%s[%s]: Error: %s\n",self->socket_name,nn_ep_getaddr(ep),nn_strerror(errnum));
PostMessage("nanomsg: socket.%s[%s]: [%s:%d] Error: %s\n",self->socket_name,nn_ep_getaddr(ep),fname,linenum,nn_strerror(errnum));
PNACL_message("nanomsg: socket.%s[%s]: [%s:%d] Error: %s\n",self->socket_name,nn_ep_getaddr(ep),fname,linenum,nn_strerror(errnum));
}
else
{
fprintf(stderr,"nanomsg: socket.%s: Error: %s\n",self->socket_name, nn_strerror(errnum));
PostMessage("nanomsg: socket.%s: [%s:%d] Error: %s\n",self->socket_name,fname,linenum,nn_strerror(errnum));
PNACL_message("nanomsg: socket.%s: [%s:%d] Error: %s\n",self->socket_name,fname,linenum,nn_strerror(errnum));
}
}

0
nanomsg/core/sock.h → crypto777/nanosrc/core/sock.h

0
nanomsg/core/sockbase.c → crypto777/nanosrc/core/sockbase.c

0
nanomsg/core/symbol.c → crypto777/nanosrc/core/symbol.c

0
nanomsg/devices/device.c → crypto777/nanosrc/devices/device.c

0
nanomsg/devices/device.h → crypto777/nanosrc/devices/device.h

0
nanomsg/devices/tcpmuxd.c → crypto777/nanosrc/devices/tcpmuxd.c

0
includes/nanomsg/inproc.h → crypto777/nanosrc/inproc.h

0
includes/nanomsg/ipc.h → crypto777/nanosrc/ipc.h

5
includes/nanomsg/nn.h → crypto777/nanosrc/nn.h

@ -391,9 +391,6 @@ NN_EXPORT int nn_tcpmuxd (int port);
}
#endif
#endif
#include "pair.h"
#include "bus.h"
#include "pubsub.h"
@ -401,3 +398,5 @@ NN_EXPORT int nn_tcpmuxd (int port);
#include "survey.h"
#include "pipeline.h"
#endif

7
includes/nanomsg/nn_config.h → crypto777/nanosrc/nn_config.h

@ -44,18 +44,18 @@
#define NN_USE_LITERAL_IFADDR 1
#define NN_HAVE_STDINT 1
#define NN_HAVE_MSG_CONTROL 1
#define NN_HAVE_MSG_CONTROL 0
//#define STANDALONE 1
#ifdef __PNACL
//#define FD_CLOEXEC 1
void PostMessage(const char* format, ...);
void PNACL_message(const char* format, ...);
#include <glibc-compat/sys/uio.h>
#include <glibc-compat/sys/un.h>
#else
//#define NN_ENABLE_EXTRA 1
#define PostMessage printf
#define PNACL_message printf
#include <sys/uio.h>
#include <sys/un.h>
#endif
@ -64,6 +64,7 @@ void PostMessage(const char* format, ...);
performance optimal make sure that this value is larger than network MTU. */
#define NN_USOCK_BATCH_SIZE (2048)
//#define NN_USOCK_BATCH_SIZE (_NN_USOCK_BATCH_SIZE - 5 - 256 - 16) // adjust for veclen/clen + sizeof(ctrl)
#define NN_USE_MYMSG 1
#if defined __PNACL || defined __APPLE__
#define NN_USE_MYMSG 1

0
includes/nanomsg/pair.h → crypto777/nanosrc/pair.h

0
includes/nanomsg/pipeline.h → crypto777/nanosrc/pipeline.h

0
nanomsg/pkgconfig.in → crypto777/nanosrc/pkgconfig.in

0
includes/nanomsg/protocol.h → crypto777/nanosrc/protocol.h

0
nanomsg/protocols/README → crypto777/nanosrc/protocols/README

0
nanomsg/protocols/bus/bus.c → crypto777/nanosrc/protocols/bus/bus.c

0
nanomsg/protocols/bus/bus.h → crypto777/nanosrc/protocols/bus/bus.h

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save