Browse Source

Merge pull request #576 from jl777/dev

many barterDEX improvements
beta
jl777 7 years ago
committed by GitHub
parent
commit
6d02b551f1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 251
      .gitignore
  2. BIN
      OSlibs/android/lib/libcrypto.so
  3. BIN
      OSlibs/android/lib/libcurl.a
  4. BIN
      OSlibs/android/lib/libssl.so
  5. BIN
      OSlibs/ios/lib/libcrypto.a
  6. BIN
      OSlibs/ios/lib/libcurl.a
  7. BIN
      OSlibs/ios/lib/libssl.a
  8. BIN
      OSlibs/js/libnanomsg.a
  9. BIN
      OSlibs/js/libnanomsg.so
  10. BIN
      OSlibs/linux/x86_64/libnanomsg-static.a
  11. BIN
      OSlibs/osx/libcrypto.a
  12. BIN
      OSlibs/osx/libcurl.a
  13. BIN
      OSlibs/osx/libgmp.a
  14. BIN
      OSlibs/osx/libsecp256k1.a
  15. BIN
      OSlibs/osx/libssl.a
  16. BIN
      OSlibs/win/libcrypto-1_1.dll
  17. BIN
      OSlibs/win/libcrypto.a
  18. BIN
      OSlibs/win/libcurl.a
  19. BIN
      OSlibs/win/libcurl.dll
  20. BIN
      OSlibs/win/libcurldll.a
  21. BIN
      OSlibs/win/libpthreadGC2.a
  22. BIN
      OSlibs/win/libpthreadGC2_64.a
  23. BIN
      OSlibs/win/libsecp256k1.a
  24. BIN
      OSlibs/win/libssl-1_1.dll
  25. BIN
      OSlibs/win/libssl.a
  26. BIN
      OSlibs/win/nanomsg.dll
  27. BIN
      OSlibs/win/pthreadGC2.dll
  28. BIN
      OSlibs/win/pthreadGC2_64.dll
  29. BIN
      OSlibs/win/release/nanomsg.dll
  30. BIN
      OSlibs/win/release/pthreadvc2.dll
  31. BIN
      OSlibs/win/x64/libcurl.dll
  32. BIN
      OSlibs/win/x64/libpthreadGC2.a
  33. BIN
      OSlibs/win/x64/nanomsg.dll
  34. BIN
      OSlibs/win/x64/pthread_lib.lib
  35. BIN
      OSlibs/win/x64/release/libcurl.dll
  36. BIN
      OSlibs/win/x64/release/nanomsg.dll
  37. 20
      README.md
  38. 5
      crypto777/inet.c
  39. BIN
      crypto777/pnacl_libs/libcrypto.a
  40. BIN
      crypto777/pnacl_libs/libcurl.a
  41. BIN
      crypto777/pnacl_libs/libnanomsg.a
  42. BIN
      crypto777/pnacl_libs/libssl.a
  43. BIN
      crypto777/pnacl_libs/libz.a
  44. 20490
      deprecated/obsolete.h
  45. BIN
      iguana/Kashi/json_extracta
  46. 23
      iguana/client
  47. BIN
      iguana/dexscripts.win32/curl.exe
  48. 4
      iguana/exchanges/LP_NXT.c
  49. 4
      iguana/exchanges/LP_cache.c
  50. 3
      iguana/exchanges/LP_coins.c
  51. 34
      iguana/exchanges/LP_commands.c
  52. 25
      iguana/exchanges/LP_include.h
  53. 13
      iguana/exchanges/LP_instantdex.c
  54. 4
      iguana/exchanges/LP_mmjson.c
  55. 130
      iguana/exchanges/LP_nativeDEX.c
  56. 414
      iguana/exchanges/LP_network.c
  57. 305
      iguana/exchanges/LP_ordermatch.c
  58. 103
      iguana/exchanges/LP_peers.c
  59. 3
      iguana/exchanges/LP_prices.c
  60. 3
      iguana/exchanges/LP_privkey.c
  61. 30
      iguana/exchanges/LP_remember.c
  62. 2
      iguana/exchanges/LP_rpc.c
  63. 18
      iguana/exchanges/LP_signatures.c
  64. 6
      iguana/exchanges/LP_socket.c
  65. 2
      iguana/exchanges/LP_statemachine.c
  66. 8
      iguana/exchanges/LP_stats.c
  67. 19
      iguana/exchanges/LP_swap.c
  68. 89
      iguana/exchanges/LP_transaction.c
  69. 72
      iguana/exchanges/LP_utxo.c
  70. 2
      iguana/exchanges/beertest
  71. 2
      iguana/exchanges/coins
  72. 69
      iguana/exchanges/mm.c
  73. 4
      iguana/exchanges/prices/autoprice
  74. 4
      iguana/exchanges/reset_mutex
  75. 48
      iguana/exchanges/stats.c
  76. BIN
      iguana/pthreadvc2.dll
  77. BIN
      pthreadVC2.lib
  78. BIN
      pthreadvc2.dll

251
.gitignore

@ -229,259 +229,10 @@ iguana/confs/630929d976025fafde221c7358eb5805f4359bad3c6b8bd50ad3f6e0a9b5ce78
iguana/confs/5f3283a017c31e52443d61cb43944e2157f7c03eb12d701ebf4a35a695688e1f
iguana/DB/SWAPS/1313603851-3952777544
iguana/DB/SWAPS/1923456555-3815385469
iguana/DB/SWAPS/897416195-4050269921
iguana/DB/SWAPS/2465996447-4202128826
iguana/DB/SWAPS/3078036996-3700749298
iguana/DB/SWAPS/1061498231-3266306388
iguana/DB/SWAPS/1060082251-3390546616
iguana/SVM/rawfeatures/BTCD_BTC
iguana/DB/SWAPS/1032184933-1028220623
iguana/DB/SWAPS/771249356-2746947221
iguana/DB/SWAPS/2311778512-3235676199
iguana/DB/SWAPS/3385048746-2109923340
iguana/DB/SWAPS/1739581643-2099619754
iguana/DB/SWAPS/2247429570-1367058185
iguana/DB/SWAPS/3178831915-912907861
iguana/DB/SWAPS/445514331-1083446761
iguana/DB/SWAPS/2510768478-2766365035
iguana/DB/SWAPS/2072817844-2263105627
iguana/DB/SWAPS/230888617-1894645930
iguana/DB/SWAPS/3606847984-2574036327
iguana/DB/SWAPS/2384443255-1263480722
iguana/DB/SWAPS/845549832-3630913950
iguana/DB/SWAPS/2050938501-203733478
iguana/DB/SWAPS/3434672913-3981690962
iguana/DB/SWAPS/2840127595-1174059534
iguana/DB/SWAPS/2448551545-1211445977
*.alicepayment
*.myfee
iguana/DB/SWAPS/1313312572-123661666
iguana/DB/SWAPS/3408402932-4088991610
iguana/DB/SWAPS/3772541120-2007204891
iguana/DB/SWAPS/784303571-1929722462
iguana/DB/SWAPS/3221116355-3522779294
iguana/DB/SWAPS/1703578312-1139459191
iguana/DB/SWAPS/1192374491-1050242469
iguana/DB/SWAPS/4244307493-1619487751
iguana/DB/SWAPS/3213119432-553439289
iguana/DB/SWAPS/3854521391-612984356
iguana/DB/SWAPS/3611231334-1171171579
iguana/DB/SWAPS/1505015888-2633757068
iguana/DB/SWAPS/3430299677-3087427598
iguana/DB/SWAPS/2275651697-591036515
iguana/DB/SWAPS/2180638961-896149751
iguana/DB/SWAPS/2349180798-2344225091
iguana/DB/SWAPS/1395238080-4120976642
iguana/DB/SWAPS/1914406677-1452353494
iguana/DB/SWAPS/3193054754-2514575257
iguana/DB/SWAPS/3004995589-1950720855
iguana/3193054754-2514575257
iguana/DB/SWAPS/2912654530-2125064238
iguana/DB/SWAPS/3448271011-3628813832
iguana/DB/SWAPS/3448271011-3628813832
iguana/DB/SWAPS/403615495-1237768524
iguana/DB/SWAPS/3448271011-3628813832
iguana/DB/SWAPS/403615495-1237768524
iguana/DB/SWAPS/3448271011-3628813832
iguana/DB/SWAPS/246664144-1570119145
iguana/DB/SWAPS/171316098-410428064
iguana/DB/SWAPS/178665381-1950467641
iguana/DB/SWAPS/4126499968-376410338
iguana/DB/SWAPS/1518259123-2214130634
iguana/DB/SWAPS/152114847-907489057
iguana/DB/SWAPS/61119357-1960547076
iguana/DB/SWAPS/26534791-3105729230
*.finished
iguana/DB/SWAPS/2279906047-2580050792
iguana/DB/SWAPS/1672096208-4211948211
iguana/DB/SWAPS/3062665554-3128383014
iguana/DB/SWAPS/2668150969-2698996317
iguana/DB/SWAPS/3462690702-2419919594
iguana/DB/SWAPS/543051861-1532200070
iguana/DB/SWAPS/442294237-2721246052
iguana/DB/SWAPS/1247864366-3828803132
iguana/DB/SWAPS/2910626293-1439062588
iguana/DB/SWAPS/3893087081-2278083649
iguana/DB/SWAPS/2990527454-48620696
iguana/DB/SWAPS/217534954-2300638414
iguana/DB/SWAPS/2780026367-3028893038
iguana/DB/SWAPS/467080987-1442519493
iguana/DB/SWAPS/1504818827-1454232932
iguana/DB/SWAPS/4093850898-2949785771
iguana/DB/SWAPS.old/1247864366-3828803132
iguana/DB/SWAPS.old/.tmpmarker
iguana/DB/SWAPS/2723832060-1788071166
iguana/DB/SWAPS/3210648667-2626363704
iguana/DB/SWAPS/415703857-2769362858
iguana/3193054754-2514575257
iguana/DB/SWAPS/2723832060-1788071166
iguana/DB/SWAPS/3213598586-2281632307
iguana/DB/SWAPS/2686675855-3655454671
iguana/DB/SWAPS/1878868608-154367763
iguana/DB/SWAPS/1306454711-1938980379
iguana/DB/SWAPS/912783809-2523701920
iguana/DB/SWAPS/1238069553-2363573428
iguana/DB/SWAPS/2895470622-2170247626
iguana/confs/ed476386688e486f359ce67e44ce4268a875125527e122ea9126ebc54f473d31
iguana/confs/f6e8e8ab82ed33b2de063d6820dcaefb99b95cf1aef6527b8f27e1e5b1fe882d
iguana/e
iguana/a
iguana/t
iguana/stats
iguana/DEXstats
iguana/DEXstats.dSYM/Contents/Info.plist
iguana/DEXstats.dSYM/Contents/Resources/DWARF/DEXstats
iguana/confs/dc54d862abd6809d9fd200759538014248f18a5a69e7bc22c0a1f2111a896157
iguana/confs/589983f94d17d8e0dc6fbf3fce34b20efc81183c0ab0158cf81a60f03711e15c
iguana/confs/67201409eb7644e398c8090ac6e3ccf4b69d186b8478aa8488211e9b474dd245
iguana/confs/982dfa0e535a6e856cca3cd919af03f50050408fcfed1cd71bb4aa1e2e69070f
iguana/confs/aa45c35599c9c75a9788fa9740ce8713cc457919e6f6f7d8d8115da5193f5722
iguana/confs/ab828d4425655df6bf409f0e23be49ae4a19b2c974008385b18a7a9c79b0314c
iguana/confs/b29fa937dd00ed7dd73ff4eef8b49bd3103ebddaee9fae05f44ffed42c5a4611
iguana/confs/LTC_hdrs.txt
iguana/confs/LTC_oldhdrs.txt
iguana/DB/LTC_peers.dat
iguana/debug.log
iguana/DB/LTC/.tmpmarker
iguana/DB/purgeable/LTC/.tmpmarker
iguana/DB/SWAPS/654629381-1010651560
iguana/DB/SWAPS/1780095668-2225891679
iguana/DB/SWAPS/3085356347-2346291696
iguana/DB/SWAPS/1819165332-1507632737
iguana/DB/SWAPS/283982730-556239841
iguana/marketmaker.dSYM/Contents/Resources/DWARF/marketmaker
iguana/marketmaker.dSYM/Contents/Info.plist
iguana/client
iguana/marketmaker.dSYM/Contents/Resources/DWARF/marketmaker
iguana/confs/97f18454bb61e9eb7a827cfbefe42fbf7ae2832dc74c4812bdaef8bcf5c10474
iguana/DB/PRICES/.tmpmarker

BIN
OSlibs/android/lib/libcrypto.so

Binary file not shown.

BIN
OSlibs/android/lib/libcurl.a

Binary file not shown.

BIN
OSlibs/android/lib/libssl.so

Binary file not shown.

BIN
OSlibs/ios/lib/libcrypto.a

Binary file not shown.

BIN
OSlibs/ios/lib/libcurl.a

Binary file not shown.

BIN
OSlibs/ios/lib/libssl.a

Binary file not shown.

BIN
OSlibs/js/libnanomsg.a

Binary file not shown.

BIN
OSlibs/js/libnanomsg.so

Binary file not shown.

BIN
OSlibs/linux/x86_64/libnanomsg-static.a

Binary file not shown.

BIN
OSlibs/osx/libcrypto.a

Binary file not shown.

BIN
OSlibs/osx/libcurl.a

Binary file not shown.

BIN
OSlibs/osx/libgmp.a

Binary file not shown.

BIN
OSlibs/osx/libsecp256k1.a

Binary file not shown.

BIN
OSlibs/osx/libssl.a

Binary file not shown.

BIN
OSlibs/win/libcrypto-1_1.dll

Binary file not shown.

BIN
OSlibs/win/libcrypto.a

Binary file not shown.

BIN
OSlibs/win/libcurl.a

Binary file not shown.

BIN
OSlibs/win/libcurl.dll

Binary file not shown.

BIN
OSlibs/win/libcurldll.a

Binary file not shown.

BIN
OSlibs/win/libpthreadGC2.a

Binary file not shown.

BIN
OSlibs/win/libpthreadGC2_64.a

Binary file not shown.

BIN
OSlibs/win/libsecp256k1.a

Binary file not shown.

BIN
OSlibs/win/libssl-1_1.dll

Binary file not shown.

BIN
OSlibs/win/libssl.a

Binary file not shown.

BIN
OSlibs/win/nanomsg.dll

Binary file not shown.

BIN
OSlibs/win/pthreadGC2.dll

Binary file not shown.

BIN
OSlibs/win/pthreadGC2_64.dll

Binary file not shown.

BIN
OSlibs/win/release/nanomsg.dll

Binary file not shown.

BIN
OSlibs/win/release/pthreadvc2.dll

Binary file not shown.

BIN
OSlibs/win/x64/libcurl.dll

Binary file not shown.

BIN
OSlibs/win/x64/libpthreadGC2.a

Binary file not shown.

BIN
OSlibs/win/x64/nanomsg.dll

Binary file not shown.

BIN
OSlibs/win/x64/pthread_lib.lib

Binary file not shown.

BIN
OSlibs/win/x64/release/libcurl.dll

Binary file not shown.

BIN
OSlibs/win/x64/release/nanomsg.dll

Binary file not shown.

20
README.md

@ -1,4 +1,4 @@
#SuperNET Client "iguana"
# SuperNET Client "iguana"
OS | Build Status
-------------|------
@ -22,7 +22,7 @@ iguana: most efficient bitcoin core implementation that can simultaneously be fu
komodo: this is the top secret project I cant talk about publicly yet
> #TL;DR#
> # TL;DR
>
> ```sudo apt-get update; sudo apt-get install git libcurl4-openssl-dev build-essential libnanomsg-dev; git clone https://github.com/jl777/SuperNET; cd SuperNET; ./m_onetime m_unix;```
>
@ -40,14 +40,14 @@ TOOL_DIR := /usr/local/gcc-4.8.0-qt-4.8.4-for-mingw32/win32-gcc/bin
MINGW := i586-mingw32
The above two definitions need to be changed to match the mingw install on your system. m_win32 and m_win64 just invokes the makefile in mingw32 and mingw64
##For chrome app##
## 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 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.
##For android##
## For android
You have to build a native libnanomsg for android. This section is work in progress. Contact ca333@protonmail.ch for assistance on building latest iguana for android.
#ONETIME#
# ONETIME
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.
@ -82,12 +82,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#
# 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#
# 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>```
@ -134,9 +134,9 @@ on OSX mksquashfs is not native, you will need to install fuse: https://osxfuse.
A Note on Installation from pebwindkraft at bitco.in
=======================
Though I had xcode installed, aclocal didn’t work. I installed homebrew, and then:
# brew install autoconf
# brew install automake
# brew install gmp
`brew install autoconf`
`brew install automake`
`brew install gmp`
2.) libsecp256
it complained, that libsecp256 was not there in includes, so I linked it.

5
crypto777/inet.c

@ -605,7 +605,10 @@ uint16_t parse_endpoint(int32_t *ip6flagp,char *transport,char *ipbuf,char *retb
ipbits = calc_ipbits(ipaddr);
expand_ipbits(tmp,ipbits);
if ( strcmp(tmp,ipaddr) != 0 )
ipaddr = 0, sprintf(retbuf,"{\"result\":\"illegal ipaddr\",\"endpoint\":\"%s\",\"ipaddr\":\"%s\",\"checkaddr\":\"%s\"}",endpoint,ipaddr,tmp);
{
sprintf(retbuf,"{\"result\":\"illegal ipaddr\",\"endpoint\":\"%s\",\"ipaddr\":\"%s\",\"checkaddr\":\"%s\"}",endpoint,ipaddr,tmp);
ipaddr = 0;
}
}
if ( inet != 0 && ipaddr != 0 && port != 0 )
{

BIN
crypto777/pnacl_libs/libcrypto.a

Binary file not shown.

BIN
crypto777/pnacl_libs/libcurl.a

Binary file not shown.

BIN
crypto777/pnacl_libs/libnanomsg.a

Binary file not shown.

BIN
crypto777/pnacl_libs/libssl.a

Binary file not shown.

BIN
crypto777/pnacl_libs/libz.a

Binary file not shown.

20490
deprecated/obsolete.h

File diff suppressed because it is too large

BIN
iguana/Kashi/json_extracta

Binary file not shown.

23
iguana/client

@ -0,0 +1,23 @@
source randval
pkill -15 marketmaker;
git pull;
./m_mm;
#./m_mmosx;
./marketmaker "{\"client\":1,\"coins\":[{\"coin\":\"REVS\",\"active\":1, \"asset\":\"REVS\",\"rpcport\":10196},{\"coin\":\"JUMBLR\",\"active\":1, \"asset\":\"JUMBLR\",\"rpcport\":15106},
{\"active\":0,\"coin\":\"ZEC\",\"name\":\"zcash\",\"rpcport\":8232,\"taddr\":28,\"pubtype\":184,\"p2shtype\":189,\"wiftype\":128,\"txfee\":10000 },
{\"coin\":\"DOGE\", \"name\":\"dogecoin\", \"pubtype\":30, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000000},
{\"coin\":\"DGB\", \"name\":\"digibyte\", \"pubtype\":30, \"p2shtype\":5, \"wiftype\":128, \"txfee\":10000},
{\"coin\":\"MZC\", \"name\":\"mazacoin\", \"pubtype\":50, \"p2shtype\":9, \"wiftype\":224, \"txfee\":0},
{\"coin\":\"SYS\", \"name\":\"syscoin\", \"pubtype\":0, \"p2shtype\":5, \"wiftype\":128, \"txfee\":100000},
{\"coin\":\"UNO\", \"name\":\"unobtanium\", \"pubtype\":130, \"p2shtype\":30, \"wiftype\":224, \"txfee\":1000000},
{\"coin\":\"ZET\", \"name\":\"zetacoin\", \"pubtype\":80, \"p2shtype\":9, \"wiftype\":224, \"txfee\":10000},
{\"coin\":\"ZEC\", \"name\":\"zcash\", \"pubtype\":184, \"p2shtype\":189, \"wiftype\":128, \"txfee\":10000},
{\"coin\":\"BTM\", \"name\":\"bitmark\", \"pubtype\":85, \"p2shtype\":5, \"wiftype\":213, \"txfee\":0},
{\"coin\":\"CARB\", \"name\":\"carboncoin\", \"pubtype\":47, \"p2shtype\":5, \"wiftype\":175, \"txfee\":0},
{\"coin\":\"ANC\", \"name\":\"anoncoin\", \"pubtype\":23, \"p2shtype\":5, \"wiftype\":151, \"txfee\":2000000},
{\"coin\":\"FRK\", \"name\":\"franko\", \"pubtype\":35, \"p2shtype\":5, \"wiftype\":163, \"txfee\":0},
{\"coin\":\"GAME\", \"name\":\"gamecredits\", \"pubtype\":38, \"p2shtype\":5, \"wiftype\":166, \"txfee\":100000},
{\"coin\":\"LTC\", \"name\":\"litecoin\", \"rpcport\":9332, \"pubtype\":48, \"p2shtype\":5, \"wiftype\":176, \"txfee\":100000 },
{\"coin\":\"SUPERNET\",\"asset\":\"SUPERNET\",\"rpcport\":11341},{\"coin\":\"WLC\",\"asset\":\"WLC\",\"rpcport\":12167},{\"coin\":\"PANGEA\",\"asset\":\"PANGEA\",\"rpcport\":14068},{\"coin\":\"DEX\",\"asset\":\"DEX\",\"rpcport\":11890},{\"coin\":\"BET\",\"asset\":\"BET\",\"rpcport\":14250},{\"coin\":\"CRYPTO\",\"asset\":\"CRYPTO\",\"rpcport\":8516},{\"coin\":\"HODL\",\"asset\":\"HODL\",\"rpcport\":14431},{\"coin\":\"SHARK\",\"asset\":\"SHARK\",\"rpcport\":10114},{\"coin\":\"BOTS\",\"asset\":\"BOTS\",\"rpcport\":11964},{\"coin\":\"MGW\",\"asset\":\"MGW\",\"rpcport\":12386},{\"coin\":\"COQUI\",\"asset\":\"COQUI\",\"rpcport\":14276},{\"coin\":\"KV\",\"asset\":\"KV\",\"rpcport\":9747},{\"coin\":\"CEAL\",\"asset\":\"CEAL\",\"rpcport\":11116},{\"coin\":\"MESH\",\"asset\":\"MESH\",\"rpcport\":9455}
], \"userhome\":\"/${HOME#"/"}\",\"passphrase\":\"$randval\"}" &

BIN
iguana/dexscripts.win32/curl.exe

Binary file not shown.

4
iguana/exchanges/LP_NXT.c

@ -202,9 +202,7 @@ void NXTventure_liquidation()
cJSON *LP_NXT_redeems()
{
char url[1024],*retstr,*recv,*method,*msgstr,assetname[128]; uint64_t totals[2][sizeof(assetids)/sizeof(*assetids)],mult,txnum,assetid,qty; int32_t i,ind,numtx=0,past_marker=0; cJSON *item,*attach,*decjson,*array,*msgjson,*encjson,*retjson=0;
//sleep 1; fiat/supernet sendtoaddress RNZZuQYu8xJLZHuekhd96hYfoQuiCMz99T 1001.44150000 # txnum.8537615468620726612
//sleep 1; fiat/pangea sendtoaddress RWMdRaUmMZqKkEibwEhY6XS3RLCXJDWHTi 22.10910000 # txnum.2649622877615958504
uint64_t txnum_marker = calc_nxt64bits("8537615468620726612"); // 2649622877615958504"); // set to most recent processed
uint64_t txnum_marker = calc_nxt64bits("4114304329372848717"); // 8537615468620726612"); // set to most recent processed
uint64_t txnum_marker2 = calc_nxt64bits("7256847492742571143"); // dont change, end marker
char *passphrase = "";
char *account = "NXT-MRBN-8DFH-PFMK-A4DBM";

4
iguana/exchanges/LP_cache.c

@ -57,7 +57,7 @@ struct LP_transaction *LP_create_transaction(struct iguana_info *coin,bits256 tx
tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest");
LP_destaddr(tx->outpoints[i].coinaddr,vout);
//printf("from transaction init %s %s %s/v%d <- %.8f\n",coin->symbol,tx->outpoints[i].coinaddr,bits256_str(str,txid),i,dstr(tx->outpoints[i].value));
LP_address_utxoadd((uint32_t)time(NULL),"LP_create_transaction",coin,tx->outpoints[i].coinaddr,txid,i,tx->outpoints[i].value,height,-1);
LP_address_utxoadd(0,(uint32_t)time(NULL),"LP_create_transaction",coin,tx->outpoints[i].coinaddr,txid,i,tx->outpoints[i].value,height,-1);
}
for (i=0; i<numvins; i++)
{
@ -75,7 +75,7 @@ struct LP_transaction *LP_create_transaction(struct iguana_info *coin,bits256 tx
tx->outpoints[spentvout].spendtxid = txid;
tx->outpoints[spentvout].spendvini = i;
tx->outpoints[spentvout].spendheight = height > 0 ? height : 1;
LP_address_utxoadd((uint32_t)time(NULL),"LP_transactioninit iter1",coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1);
LP_address_utxoadd(0,(uint32_t)time(NULL),"LP_transactioninit iter1",coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1);
if ( 0 && strcmp(coin->symbol,"REVS") == 0 )
printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height);
}

3
iguana/exchanges/LP_coins.c

@ -214,7 +214,7 @@ uint16_t LP_userpass(char *userpass,char *symbol,char *assetname,char *confroot,
cJSON *LP_coinjson(struct iguana_info *coin,int32_t showwif)
{
struct electrum_info *ep; bits256 zero; int32_t notarized; uint64_t balance; char wifstr[128],ipaddr[64]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject();
struct electrum_info *ep; bits256 zero; int32_t notarized; uint64_t balance; char wifstr[128],ipaddr[72]; uint8_t tmptype; bits256 checkkey; cJSON *item = cJSON_CreateObject();
jaddstr(item,"coin",coin->symbol);
if ( showwif != 0 )
{
@ -342,6 +342,7 @@ struct iguana_info *LP_coinadd(struct iguana_info *cdata)
*coin = *cdata;
portable_mutex_init(&coin->txmutex);
portable_mutex_init(&coin->addrmutex);
portable_mutex_init(&coin->addressutxo_mutex);
portable_mutex_lock(&LP_coinmutex);
HASH_ADD_KEYPTR(hh,LP_coins,coin->symbol,strlen(coin->symbol),coin);
portable_mutex_unlock(&LP_coinmutex);

34
iguana/exchanges/LP_commands.c

@ -171,7 +171,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
rel = "";
if ( (coin= jstr(argjson,"coin")) == 0 )
coin = "";
if ( G.USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 ) // protected localhost
if ( G.USERPASS[0] != 0 && strcmp(remoteaddr,"127.0.0.1") == 0 && port != 0 && strcmp(method,"psock") != 0 ) // protected localhost
{
if ( G.USERPASS_COUNTER == 0 )
{
@ -643,7 +643,10 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
if ( strcmp(method,"swapstatus") == 0 )
return(LP_swapstatus_recv(argjson));
else if ( strcmp(method,"gettradestatus") == 0 )
return(LP_gettradestatus(j64bits(argjson,"aliceid"),juint(argjson,"requestid"),juint(argjson,"quoteid")));
{
retstr = clonestr("{\"error\":\"deprecated\"}");
//return(LP_gettradestatus(j64bits(argjson,"aliceid"),juint(argjson,"requestid"),juint(argjson,"quoteid")));
}
else if ( strcmp(method,"postprice") == 0 )
return(LP_postprice_recv(argjson));
else if ( strcmp(method,"uitem") == 0 )
@ -702,7 +705,7 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
else if ( strcmp(method,"tradestatus") == 0 )
{
LP_tradecommand_log(argjson);
printf("%-4d tradestatus | aliceid.%llu RT.%d %d\n",(uint32_t)time(NULL) % 3600,(long long)j64bits(argjson,"aliceid"),LP_RTcount,LP_swapscount);
//printf("%-4d tradestatus | aliceid.%llu RT.%d %d\n",(uint32_t)time(NULL) % 3600,(long long)j64bits(argjson,"aliceid"),LP_RTcount,LP_swapscount);
retstr = clonestr("{\"result\":\"success\"}");
}
else if ( strcmp(method,"wantnotify") == 0 )
@ -749,16 +752,21 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\
{
if ( strcmp(method,"psock") == 0 )
{
if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 )
{
if ( LP_mypeer != 0 )
myipaddr = LP_mypeer->ipaddr;
else printf("LP_psock dont have actual ipaddr?\n");
}
if ( jint(argjson,"ispaired") != 0 )
return(LP_psock(myipaddr,jint(argjson,"ispaired")));
else return(clonestr("{\"error\":\"you are running an obsolete version, update\"}"));
}
int32_t psock;
if ( myipaddr == 0 || myipaddr[0] == 0 || strcmp(myipaddr,"127.0.0.1") == 0 )
{
if ( LP_mypeer != 0 )
myipaddr = LP_mypeer->ipaddr;
else printf("LP_psock dont have actual ipaddr?\n");
}
if ( jint(argjson,"ispaired") != 0 )
{
retstr = LP_psock(&psock,myipaddr,1,jint(argjson,"cmdchannel"),jbits256(argjson,"pubkey"));
//printf("LP_commands.(%s)\n",retstr);
return(retstr);
}
else return(clonestr("{\"error\":\"you are running an obsolete version, update\"}"));
}
}
else
{

25
iguana/exchanges/LP_include.h

@ -25,6 +25,8 @@
#define LP_TECHSUPPORT 0
#endif
#define LP_DONT_CMDCHANNEL
#ifdef FROMGUI
#define printf dontprintf
@ -52,10 +54,11 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping
#endif
//#define LP_STRICTPEERS
//#define LP_DISABLE_DISTCOMBINE
#define LP_MAXVINS 64
#define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL)
#define LP_AUTOTRADE_TIMEOUT 30
#define LP_AUTOTRADE_TIMEOUT 180
#define LP_RESERVETIME 600 //(LP_AUTOTRADE_TIMEOUT * 2)
#define ELECTRUM_TIMEOUT 13
#define LP_ELECTRUM_KEEPALIVE 60
@ -297,10 +300,10 @@ struct LP_transaction
struct iguana_info
{
UT_hash_handle hh;
portable_mutex_t txmutex,addrmutex; struct LP_transaction *transactions; struct LP_address *addresses;
portable_mutex_t txmutex,addrmutex,addressutxo_mutex; struct LP_transaction *transactions; struct LP_address *addresses;
uint64_t txfee;
int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport;
uint32_t txversion,dPoWtime,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
int32_t numutxos,notarized,longestchain,firstrefht,firstscanht,lastscanht,height; uint16_t busport,did_addrutxo_reset;
uint32_t txversion,dPoWtime,lastresetutxo,loadedcache,electrumlist,lastunspent,importedprivkey,lastpushtime,lastutxosync,addr_listunspent_requested,lastutxos,updaterate,counter,inactive,lastmempool,lastgetinfo,ratetime,heighttime,lastmonitor,obooktime;
uint8_t pubtype,p2shtype,isPoS,wiftype,wiftaddr,taddr,noimportprivkey_flag,userconfirms,isassetchain,maxconfirms;
char symbol[128],smartaddr[64],userpass[1024],serverport[128],instantdex_address[64];
// portfolio
@ -360,9 +363,10 @@ struct LP_address
struct LP_peerinfo
{
UT_hash_handle hh;
bits256 pubkey;
uint64_t ip_port;
uint32_t recvtime,numrecv,ipbits,errortime,errors,numpeers,needping,lasttime,connected,lastutxos,lastpeers,diduquery,good,sessionid;
int32_t pushsock,subsock,isLP;
int32_t pushsock,subsock,isLP,pairsock;
uint16_t port,netid;
char ipaddr[64];
};
@ -430,7 +434,7 @@ struct LP_pubkey_info
struct LP_pubswap *bobswaps,*aliceswaps;
int64_t dynamictrust,unconfcredits;
uint32_t timestamp,numerrors,lasttime,slowresponse;
int32_t istrusted;
int32_t istrusted,pairsock;
uint8_t rmd160[20],sig[65],pubsecp[33],siglen;
};
@ -477,7 +481,7 @@ int32_t LP_forward(void *ctx,char *myipaddr,int32_t pubsock,bits256 pubkey,char
struct LP_peerinfo *LP_peerfind(uint32_t ipbits,uint16_t port);
uint64_t LP_value_extract(cJSON *obj,int32_t addinterest);
int32_t LP_swap_getcoinaddr(char *symbol,char *coinaddr,bits256 txid,int32_t vout);
char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen);
char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,int32_t stats_JSONonly);
int64_t LP_kmdvalue(char *symbol,int64_t satoshis);
int64_t LP_komodo_interest(bits256 txid,int64_t value);
void LP_availableset(bits256 txid,int32_t vout);
@ -485,7 +489,7 @@ int32_t LP_iseligible(uint64_t *valp,uint64_t *val2p,int32_t iambob,char *symbol
int32_t LP_pullsock_check(void *ctx,char **retstrp,char *myipaddr,int32_t pubsock,int32_t pullsock);
int64_t LP_listunspent_parseitem(struct iguana_info *coin,bits256 *txidp,int32_t *voutp,int32_t *heightp,cJSON *item);
void LP_unspents_cache(char *symbol,char *addr,char *arraystr,int32_t updatedflag);
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired);
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired,int32_t cmdchannel,char *ipaddr);
//void LP_utxo_clientpublish(struct LP_utxoinfo *utxo);
//int32_t LP_coinbus(uint16_t coin_busport);
int32_t LP_nanomsg_recvs(void *ctx);
@ -533,7 +537,7 @@ int32_t LP_numpeers();
double LP_CMCbtcprice(double *price_usdp,char *symbol);
char *basilisk_swapentry(uint32_t requestid,uint32_t quoteid,int32_t forceflag);
int64_t LP_KMDvalue(struct iguana_info *coin,int64_t balance);
int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight);
int32_t LP_address_utxoadd(int32_t skipsearch,uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight);
void LP_smartutxos_push(struct iguana_info *coin);
void LP_cacheptrs_init(struct iguana_info *coin);
cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrumret);
@ -543,9 +547,10 @@ int32_t LP_listunspent_both(char *symbol,char *coinaddr,int32_t fullflag);
uint16_t LP_randpeer(char *destip);
void LP_tradebot_pauseall();
void LP_portfolio_reset();
struct LP_pubkey_info *LP_pubkeyadd(bits256 pubkey);
uint32_t LP_atomic_locktime(char *base,char *rel);
struct LP_pubkey_info *LP_pubkeyfind(bits256 pubkey);
char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired);
char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired,int32_t cmdchannel);
char *LP_unspents_filestr(char *symbol,char *addr);
cJSON *bitcoin_data2json(char *symbol,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,int32_t height,bits256 *txidp,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,uint8_t *serialized,int32_t len,cJSON *vins,int32_t suppress_pubkeys,int32_t zcash);
//int32_t LP_butxo_findeither(bits256 txid,int32_t vout);

13
iguana/exchanges/LP_instantdex.c

@ -597,11 +597,14 @@ cJSON *LP_swapstats_item(struct LP_swapstats *sp,int32_t iambob)
}
if ( flag != 0 )
{
reqjson = cJSON_CreateObject();
jaddstr(reqjson,"method","gettradestatus");
jadd64bits(reqjson,"aliceid",sp->aliceid);
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(0,"","",zero,jprint(reqjson,1));
if ( 0 )
{
reqjson = cJSON_CreateObject();
jaddstr(reqjson,"method","gettradestatus");
jadd64bits(reqjson,"aliceid",sp->aliceid);
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(0,"","",zero,jprint(reqjson,1));
}
if ( (swapstr= basilisk_swapentry(sp->Q.R.requestid,sp->Q.R.quoteid,0)) != 0 )
{
if ( (swapjson= cJSON_Parse(swapstr)) != 0 )

4
iguana/exchanges/LP_mmjson.c

@ -516,7 +516,9 @@ int32_t MMJSON_encodeval(uint8_t *linebuf,int32_t k,int32_t ind,char *v,uint32_t
}
if ( v[j] == 0 )
{
printf("unexpected missing string value.(%s)\n",v);
static uint32_t counter;
if ( counter++ < 3 )
printf("unexpected missing string value.(%s)\n",v);
//ind = mmadd(v);
//printf("%s.<%s>.%d ",s,v,ind);
//linebuf[k++] = ind;

130
iguana/exchanges/LP_nativeDEX.c

@ -85,7 +85,7 @@ void LP_millistats_update(struct LP_millistats *mp)
}
#include "LP_include.h"
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex,LP_inusemutex,LP_cJSONmutex,LP_logmutex,LP_statslogmutex,LP_tradesmutex;
portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex,LP_inusemutex,LP_cJSONmutex,LP_logmutex,LP_statslogmutex,LP_tradesmutex,LP_commandQmutex;
int32_t LP_canbind;
char *Broadcaststr,*Reserved_msgs[2][1000];
int32_t num_Reserved_msgs[2],max_Reserved_msgs[2];
@ -192,21 +192,21 @@ char *blocktrail_listtransactions(char *symbol,char *coinaddr,int32_t num,int32_
#include "LP_messages.c"
#include "LP_commands.c"
char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen)
char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen,int32_t stats_JSONonly)
{
char *retstr=0; cJSON *retjson; bits256 zero;
if ( jobj(argjson,"result") != 0 || jobj(argjson,"error") != 0 )
return(0);
if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 )
if ( stats_JSONonly != 0 || LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 )
{
if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 )
if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",stats_JSONonly)) != 0 )
{
//printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr);
//if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 &&
//LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0);
}
}
else if ( LP_statslog_parse() > 0 )
else if ( LP_statslog_parse() > 0 && 0 )
{
memset(zero.bytes,0,sizeof(zero));
if ( (retjson= LP_statslog_disp(2000000000,2000000000,"",zero,0,0))) // pending swaps
@ -303,7 +303,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
if ( jsonstr != 0 && argjson != 0 )
{
len = (int32_t)strlen(jsonstr) + 1;
if ( (method= jstr(argjson,"method")) != 0 && strcmp(method,"broadcast") == 0 )
if ( (method= jstr(argjson,"method")) != 0 && strcmp(method,"gettradestatus") != 0 && strcmp(method,"psock") != 0 && strcmp(method,"broadcast") == 0 )
{
bits256 zero; cJSON *reqjson; char *cipherstr; int32_t cipherlen; uint8_t cipher[LP_ENCRYPTED_MAXSIZE];
if ( (reqjson= LP_dereference(argjson,"broadcast")) != 0 )
@ -331,9 +331,10 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
}
else
{
if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 )
{
}
LP_queuecommand(0,jsonstr,pubsock,0);
//if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 )
//{
//}
}
}
if ( argjson != 0 )
@ -349,7 +350,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock,
int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,char *remoteaddr,int32_t maxdepth)
{
static char *line;
int32_t recvlen=1,msglen,nonz = 0; cJSON *argjson,*recvjson; void *ptr,*msg; char methodstr[64],*decodestr,*retstr,*str; struct nn_pollfd pfd;
int32_t recvlen=1,msglen,nonz = 0; cJSON *recvjson; void *ptr,*msg; char methodstr[64],*decodestr,*retstr,*str; struct nn_pollfd pfd;
if ( line == 0 )
line = calloc(1,1024*1024);
if ( sock >= 0 )
@ -407,12 +408,14 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
{
if ( (retstr= LP_process_message(ctx,typestr,myipaddr,pubsock,msg,msglen,sock)) != 0 )
free(retstr);
if ( Broadcaststr != 0 )
{
//printf("self broadcast.(%s)\n",Broadcaststr);
str = Broadcaststr;
Broadcaststr = 0;
if ( (argjson= cJSON_Parse(str)) != 0 )
LP_queuecommand(0,str,pubsock,0);
/*if ( (argjson= cJSON_Parse(str)) != 0 )
{
//portable_mutex_lock(&LP_commandmutex);
if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 )
@ -422,7 +425,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int
}
//portable_mutex_unlock(&LP_commandmutex);
free_json(argjson);
}
}*/
free(str);
}
}
@ -551,6 +554,11 @@ void LP_coinsloop(void *_coins)
memset(&zero,0,sizeof(zero));
if ( coin->inactive != 0 )
continue;
if ( coin->did_addrutxo_reset == 0 )
{
LP_address_utxo_reset(coin);
coin->did_addrutxo_reset = 1;
}
if ( coin->longestchain == 1 ) // special init value
coin->longestchain = LP_getheight(&notarized,coin);
if ( (ep= coin->electrum) != 0 )
@ -891,7 +899,8 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint
{
printf("default seed nodes for netid.%d\n",netid);
OS_randombytes((void *)&r,sizeof(r));
for (j=0; j<sizeof(default_LPnodes)/sizeof(*default_LPnodes)&&j<5; j++)
r = 0;
for (j=0; j<sizeof(default_LPnodes)/sizeof(*default_LPnodes); j++)
{
i = (r + j) % (sizeof(default_LPnodes)/sizeof(*default_LPnodes));
LP_addpeer(mypeer,pubsock,default_LPnodes[i],myport,pushport,subport,0,G.LP_sessionid,netid);
@ -1093,11 +1102,24 @@ void LP_reserved_msgs(void *ignore)
{
nonz = 0;
LP_millistats_update(&LP_reserved_msgs_stats);
if ( num_Reserved_msgs[0] > 0 || num_Reserved_msgs[1] > 0 )
if ( num_Reserved_msgs[1] > 0 )
{
nonz++;
portable_mutex_lock(&LP_reservedmutex);
if ( num_Reserved_msgs[1] > 0 )
{
num_Reserved_msgs[1]--;
//printf("PRIORITY BROADCAST.(%s)\n",Reserved_msgs[1][num_Reserved_msgs[1]]);
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[1][num_Reserved_msgs[1]]);
Reserved_msgs[1][num_Reserved_msgs[1]] = 0;
}
portable_mutex_unlock(&LP_reservedmutex);
}
else if ( num_Reserved_msgs[0] > 0 )
{
nonz++;
flag = 0;
if ( LP_mypubsock >= 0 )
if ( flag == 0 && LP_mypubsock >= 0 )
{
memset(&pfd,0,sizeof(pfd));
pfd.fd = LP_mypubsock;
@ -1108,36 +1130,59 @@ void LP_reserved_msgs(void *ignore)
if ( flag == 1 )
{
portable_mutex_lock(&LP_reservedmutex);
if ( num_Reserved_msgs[1] > 0 )
{
num_Reserved_msgs[1]--;
//printf("PRIORITY BROADCAST.(%s)\n",Reserved_msgs[1][num_Reserved_msgs[1]]);
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[1][num_Reserved_msgs[1]]);
Reserved_msgs[1][num_Reserved_msgs[1]] = 0;
}
else if ( num_Reserved_msgs[0] > 0 )
{
num_Reserved_msgs[0]--;
//printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]);
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[0][num_Reserved_msgs[0]]);
Reserved_msgs[0][num_Reserved_msgs[0]] = 0;
}
num_Reserved_msgs[0]--;
//printf("BROADCAST.(%s)\n",Reserved_msgs[0][num_Reserved_msgs[0]]);
LP_broadcast_message(LP_mypubsock,"","",zero,Reserved_msgs[0][num_Reserved_msgs[0]]);
Reserved_msgs[0][num_Reserved_msgs[0]] = 0;
portable_mutex_unlock(&LP_reservedmutex);
}
}
if ( ignore == 0 )
break;
if ( nonz != 0 )
usleep(1000);
else usleep(5000);
if ( nonz == 0 )
usleep(5000);
}
}
int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,char *msg)
{
int32_t n = 0;
struct LP_pubkey_info *pubp; uint32_t timestamp; char *method; cJSON *argjson; int32_t skip,sentbytes,n = 0;
skip = 0;
if ( (argjson= cJSON_Parse(msg)) != 0 )
{
if ( (method= jstr(argjson,"method")) != 0 )
{
if ( strcmp(method,"gettradestatus") == 0 || strcmp(method,"wantnotify") == 0 || strcmp(method,"getdPoW") == 0 )
skip = 1;
}
if ( (timestamp= juint(argjson,"timestamp")) != 0 && time(NULL) > timestamp+60 )
skip = 1;
free_json(argjson);
}
if ( skip != 0 )
return(-1);
if ( strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 )
return(-1);
if ( priority > 0 && bits256_nonz(pubkey) != 0 )
{
if ( (pubp= LP_pubkeyfind(pubkey)) != 0 )
{
if ( pubp->pairsock >= 0 )
{
if ( (sentbytes= nn_send(pubp->pairsock,msg,(int32_t)strlen(msg)+1,0)) < 0 )
{
//pubp->pairsock = -1;
//LP_peer_pairsock(pubkey);
//printf("mark cmdchannel %d closed sentbytes.%d\n",pubp->pairsock,sentbytes);
}
else
{
printf("sent %d bytes to cmdchannel.%d\n",sentbytes,pubp->pairsock);
return(sentbytes);
}
}
}
}
portable_mutex_lock(&LP_reservedmutex);
if ( num_Reserved_msgs[priority] < sizeof(Reserved_msgs[priority])/sizeof(*Reserved_msgs[priority]) )
{
@ -1147,7 +1192,7 @@ int32_t LP_reserved_msg(int32_t priority,char *base,char *rel,bits256 pubkey,cha
if ( num_Reserved_msgs[priority] > max_Reserved_msgs[priority] )
{
max_Reserved_msgs[priority] = num_Reserved_msgs[priority];
if ( (max_Reserved_msgs[priority] % 100) == 0 )
//if ( (max_Reserved_msgs[priority] % 100) == 0 )
printf("New priority.%d max_Reserved_msgs.%d\n",priority,max_Reserved_msgs[priority]);
}
portable_mutex_unlock(&LP_reservedmutex);
@ -1234,6 +1279,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
portable_mutex_init(&LP_logmutex);
portable_mutex_init(&LP_statslogmutex);
portable_mutex_init(&LP_tradesmutex);
portable_mutex_init(&LP_commandQmutex);
myipaddr = clonestr("127.0.0.1");
#ifndef _WIN32
#ifndef FROM_JS
@ -1267,8 +1313,10 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
valid++;
if ( valid > 0 )
{
timeout = 1;
timeout = 100;
nn_setsockopt(LP_mypubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
//timeout = 10;
//nn_setsockopt(LP_mypubsock,NN_SOL_SOCKET,NN_MAXTTL,&timeout,sizeof(timeout));
}
else
{
@ -1307,7 +1355,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("got %s, initpeers. LP_mypubsock.%d pullsock.%d RPC_port.%u mypullport.%d mypubport.%d pushaddr.%s\n",myipaddr,LP_mypubsock,LP_mypullsock,RPC_port,mypullport,mypubport,pushaddr);
LP_passphrase_init(passphrase,jstr(argjson,"gui"),juint(argjson,"netid"),jstr(argjson,"seednode"));
#ifndef FROM_JS
if ( IAMLP != 0 && OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 )
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_psockloop,(void *)myipaddr) != 0 )
{
printf("error launching LP_psockloop for (%s)\n",myipaddr);
exit(-1);
@ -1372,6 +1420,11 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
printf("error launching LP_swapsloop for ctx.%p\n",ctx);
exit(-1);
}
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_commandQ_loop,ctx) != 0 )
{
printf("error launching LP_commandQ_loop for ctx.%p\n",ctx);
exit(-1);
}
int32_t nonz,didremote=0;
LP_statslog_parse();
bitcoind_RPC_inittime = 0;
@ -1439,7 +1492,10 @@ char *barterDEX(char *argstr)
printf("barterDEX.(%s)\n",argstr);
if ( (argjson= cJSON_Parse(argstr)) != 0 )
{
retstr = LP_command_process(ctx,LP_myipaddr,LP_mypubsock,argjson,(uint8_t *)argstr,(int32_t)strlen(argstr));
LP_queuecommand(&retstr,argstr,LP_mypubsock);
//retstr = LP_command_process(ctx,LP_myipaddr,LP_mypubsock,argjson,(uint8_t *)argstr,(int32_t)strlen(argstr));
while ( retstr == 0 )
usleep(50000);
free_json(argjson);
} else retstr = clonestr("{\"error\":\"couldnt parse request\"}");
return(retstr);

414
iguana/exchanges/LP_network.c

@ -21,12 +21,12 @@
struct psock
{
uint32_t lasttime,lastping,errors;
int32_t publicsock,sendsock,ispaired;
int32_t publicsock,sendsock,ispaired,cmdchannel;
uint16_t publicport,sendport;
char sendaddr[128],publicaddr[128];
} *PSOCKS;
uint16_t Numpsocks,Psockport = MIN_PSOCK_PORT;
uint16_t Numpsocks,Psockport = MIN_PSOCK_PORT,Pcmdport = MAX_PSOCK_PORT;
#ifdef FROM_JS
@ -299,16 +299,18 @@ void LP_queuesend(uint32_t crc32,int32_t pubsock,char *base,char *rel,uint8_t *m
void LP_broadcast_finish(int32_t pubsock,char *base,char *rel,uint8_t *msg,cJSON *argjson,uint32_t crc32)
{
int32_t msglen;
int32_t msglen; char *method;
if ( (method= jstr(argjson,"method")) == 0 )
return;
msg = (void *)jprint(argjson,0);
msglen = (int32_t)strlen((char *)msg) + 1;
if ( crc32 == 0 )
crc32 = calc_crc32(0,&msg[2],msglen - 2);
//printf("crc32.%x IAMLP.%d pubsock.%d\n",crc32,G.LP_IAMLP,pubsock);
#ifdef FROM_MARKETMAKER
if ( G.LP_IAMLP == 0 || pubsock < 0 )
if ( (G.LP_IAMLP == 0 || pubsock < 0) && strcmp(method,"psock") != 0 )
#else
if ( IAMLP == 0 || pubsock < 0 )
if ( (IAMLP == 0 || pubsock < 0 && strcmp(method,"psock") != 0 )
#endif
{
free(msg);
@ -412,10 +414,87 @@ uint32_t LP_swapsend(int32_t pairsock,struct basilisk_swap *swap,uint32_t msgbit
return(nextbits);
}
void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to work
struct LP_queuedcommand
{
struct LP_queuedcommand *next,*prev;
char **retstrp;
int32_t responsesock,msglen,stats_JSONonly;
char msg[];
} *LP_commandQ;
void LP_commandQ_loop(void *ctx)
{
struct LP_queuedcommand *ptr,*tmp; int32_t size,nonz; char *retstr; cJSON *argjson;
while ( LP_STOP_RECEIVED == 0 )
{
nonz = 0;
DL_FOREACH_SAFE(LP_commandQ,ptr,tmp)
{
nonz++;
portable_mutex_lock(&LP_commandQmutex);
DL_DELETE(LP_commandQ,ptr);
portable_mutex_unlock(&LP_commandQmutex);
if ( (argjson= cJSON_Parse(ptr->msg)) != 0 )
{
if ( (retstr= LP_command_process(ctx,"127.0.0.1",ptr->responsesock,argjson,(uint8_t *)ptr->msg,ptr->msglen,ptr->stats_JSONonly)) != 0 )
{
//printf("processed.(%s)\n",retstr);
if ( ptr->responsesock >= 0 && (size= nn_send(ptr->responsesock,retstr,(int32_t)strlen(retstr)+1,0)) <= 0 )
printf("error sending result\n");
if ( ptr->retstrp != 0 )
(*ptr->retstrp) = retstr;
else free(retstr);
}
else if ( ptr->retstrp != 0 )
(*ptr->retstrp) = clonestr("{\"error\":\"timeout\"}");
free_json(argjson);
}
free(ptr);
}
if ( nonz == 0 )
usleep(50000);
}
}
void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats_JSONonly)
{
struct LP_queuedcommand *ptr; int32_t msglen;
msglen = (int32_t)strlen(buf) + 1;
portable_mutex_lock(&LP_commandQmutex);
ptr = calloc(1,sizeof(*ptr) + msglen);
if ( (ptr->retstrp= retstrp) != 0 )
*retstrp = 0;
ptr->responsesock = responsesock;
ptr->msglen = msglen;
ptr->stats_JSONonly = stats_JSONonly;
memcpy(ptr->msg,buf,msglen);
DL_APPEND(LP_commandQ,ptr);
portable_mutex_unlock(&LP_commandQmutex);
}
void mynn_close(int32_t sock)
{
struct nn_pollfd pfd; int32_t n; void *buf;
if ( sock >= 0 )
{
while ( (n= nn_recv(sock,&buf,NN_MSG,0)) > 0 )
printf("got n.%d bytes from nn_close(%d)\n",n,sock);
pfd.fd = sock;
pfd.events = POLLOUT;
while ( nn_poll(&pfd,1,100) > 0 )
{
printf("cant send to nn_close(%d)\n",sock);
sleep(1);
}
if ( IAMLP != 0 )
nn_close(sock);
}
}
void LP_psockloop(void *_ptr)
{
static struct nn_pollfd *pfds;
int32_t i,n,nonz,iter,retval,sentbytes,size=0,sendsock = -1; uint32_t now; struct psock *ptr=0; void *buf=0; char keepalive[512];
int32_t nexti=0,j,i,n,nonz,iter,retval,sentbytes,size=0,sendsock = -1; uint32_t now; struct psock *ptr=0; void *buf=0; char keepalive[512];
strcpy(LP_psockloop_stats.name,"LP_psockloop");
LP_psockloop_stats.threshold = 1000.;
while ( LP_STOP_RECEIVED == 0 )
@ -445,14 +524,16 @@ void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to w
pfds = calloc(MAX_PSOCK_PORT,sizeof(*pfds));
portable_mutex_lock(&LP_psockmutex);
memset(pfds,0,sizeof(*pfds) * ((Numpsocks*2 <= MAX_PSOCK_PORT) ? Numpsocks*2 : MAX_PSOCK_PORT));
for (iter=0; iter<2; iter++)
for (iter=j=0; iter<2; iter++)
{
for (i=n=0; i<Numpsocks; i++)
for (j=n=0; j<Numpsocks; j++)
{
i = (j + nexti) % Numpsocks;
ptr = &PSOCKS[i];
if ( iter == 0 )
{
pfds[n].fd = ptr->publicsock;
//printf("check sock.%d\n",ptr->publicsock);
pfds[n].events = POLLIN;
}
else
@ -460,16 +541,20 @@ void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to w
if ( pfds[n].fd != ptr->publicsock )
{
printf("unexpected fd.%d mismatched publicsock.%d\n",pfds[n].fd,ptr->publicsock);
nexti = i+1;
break;
}
else if ( (pfds[n].revents & POLLIN) != 0 )
{
//printf("publicsock.%d %s has pollin\n",ptr->publicsock,ptr->publicaddr);
//printf("cmd.%d publicsock.%d %s has pollin\n",ptr->cmdchannel,ptr->publicsock,ptr->publicaddr);
buf = 0;
if ( (size= nn_recv(ptr->publicsock,&buf,NN_MSG,0)) > 0 )
{
ptr->lasttime = now;
sendsock = ptr->sendsock;
if ( ptr->cmdchannel == 0 )
sendsock = ptr->sendsock;
else LP_queuecommand(0,(char *)buf,ptr->publicsock,0);
nexti = i+1;
break;
}
else if ( buf != 0 )
@ -481,105 +566,104 @@ void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to w
}
}
n++;
if ( iter == 0 )
{
pfds[n].fd = ptr->sendsock;
pfds[n].events = POLLIN;
}
else
if ( ptr->sendsock > 0 )
{
if ( pfds[n].fd != ptr->sendsock )
if ( iter == 0 )
{
printf("unexpected fd.%d mismatched sendsock.%d\n",pfds[n].fd,ptr->sendsock);
break;
pfds[n].fd = ptr->sendsock;
pfds[n].events = POLLIN;
}
else if ( (pfds[n].revents & POLLIN) != 0 )
else
{
if ( (size= nn_recv(ptr->sendsock,&buf,NN_MSG,0)) > 0 )
if ( pfds[n].fd != ptr->sendsock )
{
//printf("%s paired has pollin (%s)\n",ptr->sendaddr,(char *)buf);
ptr->lasttime = now;
if ( ptr->ispaired != 0 )
{
sendsock = ptr->publicsock;
break;
}
printf("unexpected fd.%d mismatched sendsock.%d\n",pfds[n].fd,ptr->sendsock);
nexti = i+1;
break;
}
if ( buf != 0 )
else if ( (pfds[n].revents & POLLIN) != 0 )
{
nn_freemsg(buf);
buf = 0;
size = 0;
if ( (size= nn_recv(ptr->sendsock,&buf,NN_MSG,0)) > 0 )
{
//printf("%s paired has pollin (%s)\n",ptr->sendaddr,(char *)buf);
ptr->lasttime = now;
if ( ptr->ispaired != 0 )
{
sendsock = ptr->publicsock;
nexti = i+1;
break;
}
}
if ( buf != 0 )
{
nn_freemsg(buf);
buf = 0;
size = 0;
}
}
}
n++;
}
n++;
}
if ( iter == 0 )
{
if ( (retval= nn_poll(pfds,n,1)) <= 0 )
{
if ( retval != 0 )
printf("nn_poll retval.%d\n",retval);
//if ( retval != 0 )
// printf("nn_poll retval.%d\n",retval);
break;
} else printf("num pfds.%d retval.%d\n",n,retval);
} // else printf("num pfds.%d retval.%d\n",n,retval);
}
}
//free(pfds);
//printf("sendsock.%d Numpsocks.%d\n",sendsock,Numpsocks);
if ( sendsock < 0 )
{
usleep(30000);
for (i=nonz=0; i<Numpsocks; i++)
{
if ( i < Numpsocks )
{
ptr = &PSOCKS[i];
if ( now > ptr->lasttime+PSOCK_KEEPALIVE )
if ( ptr->cmdchannel == 0 && now > ptr->lasttime+PSOCK_KEEPALIVE )
{
printf("PSOCKS[%d] of %d (%u %u) lag.%d IDLETIMEOUT\n",i,Numpsocks,ptr->publicport,ptr->sendport,now - ptr->lasttime);
if ( ptr->sendsock != ptr->publicsock && ptr->sendsock >= 0 )
mynn_close(ptr->sendsock), ptr->sendsock = -1;
if ( ptr->publicsock >= 0 )
nn_close(ptr->publicsock);
if ( ptr->sendsock >= 0 )
nn_close(ptr->sendsock);
//portable_mutex_lock(&LP_psockmutex);
if ( Numpsocks > 1 )
{
PSOCKS[i] = PSOCKS[--Numpsocks];
memset(&PSOCKS[Numpsocks],0,sizeof(*ptr));
} else Numpsocks = 0;
//portable_mutex_unlock(&LP_psockmutex);
break;
mynn_close(ptr->publicsock), ptr->publicsock = -1;
nonz++;
}
else if ( now > ptr->lastping+PSOCK_KEEPALIVE/2 && ptr->errors < 3 )
}
}
if ( nonz > 0 )
{
n = Numpsocks;
for (i=0; i<n; i++)
{
ptr = &PSOCKS[i];
if ( ptr->sendsock < 0 && ptr->publicsock < 0 )
{
ptr->lastping = now;
if ( 0 )
{
sendsock = ptr->sendsock;
sprintf(keepalive,"{\"method\":\"keepalive\",\"endpoint\":\"%s\"}",ptr->sendaddr);
size = (int32_t)strlen(keepalive) + 1;
buf = keepalive;
printf("send keepalive.(%s)\n",keepalive);
}
break;
for (j=i; j<n-1; j++)
PSOCKS[j] = PSOCKS[j+1];
n--;
}
}
printf("PSOCKS purge nonz.%d n.%d vs Numpsocks.%d\n",nonz,n,Numpsocks);
Numpsocks = n;
}
if ( nonz == 0 && i == Numpsocks )
usleep(100000);
}
portable_mutex_unlock(&LP_psockmutex);
} else usleep(100000);
}
}
void LP_psockadd(int32_t ispaired,int32_t publicsock,uint16_t recvport,int32_t sendsock,uint16_t sendport,char *subaddr,char *publicaddr)
void LP_psockadd(int32_t ispaired,int32_t publicsock,uint16_t recvport,int32_t sendsock,uint16_t sendport,char *subaddr,char *publicaddr,int32_t cmdchannel)
{
struct psock *ptr;
portable_mutex_lock(&LP_psockmutex);
PSOCKS = realloc(PSOCKS,sizeof(*PSOCKS) * (Numpsocks + 1));
ptr = &PSOCKS[Numpsocks++];
ptr->ispaired = ispaired;
ptr->cmdchannel = cmdchannel;
ptr->publicsock = publicsock;
ptr->publicport = recvport;
ptr->sendsock = sendsock;
@ -609,62 +693,126 @@ int32_t LP_psockmark(char *publicaddr)
return(retval);
}
char *LP_psock(char *myipaddr,int32_t ispaired)
char *_LP_psock_create(int32_t *pullsockp,int32_t *pubsockp,char *ipaddr,uint16_t publicport,uint16_t subport,int32_t ispaired,int32_t cmdchannel,bits256 pubkey)
{
char pushaddr[128],subaddr[128]; uint16_t i,publicport,subport,maxiters=100; int32_t timeout,pullsock=-1,pubsock=-1; cJSON *retjson=0;
retjson = cJSON_CreateObject();
publicport = Psockport++;
subport = Psockport++;
for (i=0; i<maxiters; i++,publicport+=2,subport+=2)
int32_t i,pullsock,bindflag=(IAMLP != 0),pubsock,arg; struct LP_pubkey_info *pubp; char pushaddr[128],subaddr[128]; cJSON *retjson = 0;
pullsock = pubsock = -1;
*pullsockp = *pubsockp = -1;
if ( IAMLP != 0 && bits256_nonz(pubkey) != 0 )
{
char str[65];
if ( (pubp= LP_pubkeyadd(pubkey)) != 0 )
{
if ( pubp->pairsock >= 0 )
{
printf("%s already has pairsock.%d\n",bits256_str(str,pubkey),pubp->pairsock);
portable_mutex_lock(&LP_psockmutex);
for (i=0; i<Numpsocks; i++)
if ( PSOCKS[i].publicsock == pubp->pairsock )
{
//PSOCKS[i].lasttime = (uint32_t)time(NULL) - PSOCK_KEEPALIVE - 1;
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"LPipaddr",ipaddr);
jaddstr(retjson,"connectaddr",PSOCKS[i].sendaddr);
jaddnum(retjson,"connectport",PSOCKS[i].sendport);
jaddnum(retjson,"ispaired",PSOCKS[i].ispaired);
jaddnum(retjson,"cmdchannel",PSOCKS[i].cmdchannel);
jaddstr(retjson,"publicaddr",PSOCKS[i].publicaddr);
jaddnum(retjson,"publicport",PSOCKS[i].publicport);
//printf("cmd.%d publicaddr.(%s) for subaddr.(%s), pullsock.%d pubsock.%d\n",cmdchannel,pushaddr,subaddr,pullsock,pubsock);
*pullsockp = pullsock;
*pubsockp = pubsock;
portable_mutex_unlock(&LP_psockmutex);
return(jprint(retjson,1));
}
portable_mutex_unlock(&LP_psockmutex);
}
//printf("pairsock for %s <- %d\n",bits256_str(str,pubkey),pullsock);
//pubp->pairsock = pullsock;
}
}
nanomsg_transportname(bindflag,pushaddr,ipaddr,publicport);
nanomsg_transportname(bindflag,subaddr,ipaddr,subport);
if ( (pullsock= nn_socket(AF_SP,ispaired!=0?NN_PAIR:NN_PULL)) >= 0 && (cmdchannel != 0 ||(pubsock= nn_socket(AF_SP,ispaired!=0?NN_PAIR:NN_PAIR)) >= 0) )
{
if ( nn_bind(pullsock,pushaddr) >= 0 && (cmdchannel != 0 || nn_bind(pubsock,subaddr) >= 0) )
{
arg = 100;
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_SNDTIMEO,&arg,sizeof(arg));
if ( pubsock >= 0 )
nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&arg,sizeof(arg));
arg = 1;
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&arg,sizeof(arg));
if ( pubsock >= 0 )
nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_RCVTIMEO,&arg,sizeof(arg));
//arg = 2;
//nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_MAXTTL,&arg,sizeof(arg));
//if ( pubsock >= 0 )
// nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_MAXTTL,&arg,sizeof(arg));
nanomsg_transportname(0,pushaddr,ipaddr,publicport);
nanomsg_transportname(0,subaddr,ipaddr,subport);
LP_psockadd(ispaired,pullsock,publicport,pubsock,subport,subaddr,pushaddr,cmdchannel);
retjson = cJSON_CreateObject();
jaddstr(retjson,"result","success");
jaddstr(retjson,"LPipaddr",ipaddr);
jaddstr(retjson,"connectaddr",subaddr);
jaddnum(retjson,"connectport",subport);
jaddnum(retjson,"ispaired",ispaired);
jaddnum(retjson,"cmdchannel",cmdchannel);
jaddstr(retjson,"publicaddr",pushaddr);
jaddnum(retjson,"publicport",publicport);
//printf("cmd.%d publicaddr.(%s) for subaddr.(%s), pullsock.%d pubsock.%d\n",cmdchannel,pushaddr,subaddr,pullsock,pubsock);
*pullsockp = pullsock;
*pubsockp = pubsock;
return(jprint(retjson,1));
} //else printf("bind error on %s or %s\n",pushaddr,subaddr);
if ( pullsock >= 0 )
nn_close(pullsock);
if ( pubsock >= 0 )
nn_close(pubsock);
}
return(0);
}
char *LP_psock(int32_t *pullsockp,char *ipaddr,int32_t ispaired,int32_t cmdchannel,bits256 pubkey)
{
char *retstr=0; uint16_t i,publicport,subport,maxport; int32_t pubsock=-1;
*pullsockp = -1;
//printf("LP_psock ipaddr.%s ispaird.%d cmdchannel.%d\n",ipaddr,ispaired,cmdchannel);
if ( cmdchannel == 0 )
{
maxport = MAX_PSOCK_PORT;
publicport = Psockport++;
subport = Psockport++;
}
else
{
if ( cmdchannel != 0 && bits256_nonz(pubkey) == 0 )
return(clonestr("{\"error\",\"cant do pairsock for null pubkey\"}"));
maxport = 65534;
publicport = subport = Pcmdport++;
}
for (i=0; i<maxport; i++)
{
if ( publicport < MIN_PSOCK_PORT )
publicport = MIN_PSOCK_PORT+1;
if ( subport <= publicport )
if ( cmdchannel == 0 && subport <= publicport )
subport = publicport + 1;
pullsock = pubsock = -1;
nanomsg_transportname(1,pushaddr,myipaddr,publicport);
nanomsg_transportname(1,subaddr,myipaddr,subport);
if ( (pullsock= nn_socket(AF_SP,ispaired!=0?NN_PAIR:NN_PULL)) >= 0 && (pubsock= nn_socket(AF_SP,ispaired!=0?NN_PAIR:NN_PAIR)) >= 0 )
if ( (retstr= _LP_psock_create(pullsockp,&pubsock,ipaddr,publicport,subport,ispaired,cmdchannel,pubkey)) != 0 )
{
if ( nn_bind(pullsock,pushaddr) >= 0 && nn_bind(pubsock,subaddr) >= 0 )
{
timeout = 1;
nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
if ( ispaired != 0 )
{
//maxsize = 1024 * 1024;
//nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize));
}
//if ( ispaired != 0 )
{
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
nn_setsockopt(pubsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
}
nanomsg_transportname(0,pushaddr,myipaddr,publicport);
nanomsg_transportname(0,subaddr,myipaddr,subport);
LP_psockadd(ispaired,pullsock,publicport,pubsock,subport,subaddr,pushaddr);
jaddstr(retjson,"result","success");
jaddstr(retjson,"LPipaddr",myipaddr);
jaddstr(retjson,"connectaddr",subaddr);
jaddnum(retjson,"connectport",subport);
jaddnum(retjson,"ispaired",ispaired);
jaddstr(retjson,"publicaddr",pushaddr);
jaddnum(retjson,"publicport",publicport);
printf("i.%d publicaddr.(%s) for subaddr.(%s), pullsock.%d pubsock.%d\n",i,pushaddr,subaddr,pullsock,pubsock);
break;
} else printf("bind error on %s or %s\n",pushaddr,subaddr);
if ( pullsock >= 0 )
nn_close(pullsock);
if ( pubsock >= 0 )
nn_close(pubsock);
//printf("LP_psock returns.(%s)\n",retstr);
return(retstr);
}
if ( cmdchannel == 0 )
publicport+=2, subport+=2;
else publicport++, subport++;
}
if ( Psockport > MAX_PSOCK_PORT )
if ( Psockport >= MAX_PSOCK_PORT )
Psockport = MIN_PSOCK_PORT;
if ( i == maxiters )
jaddstr(retjson,"error","cant find psock ports");
return(jprint(retjson,1));
if ( Pcmdport >= 65534 )
Pcmdport = MAX_PSOCK_PORT;
return(clonestr("{\"error\",\"cant find psock ports\"}"));
}
/*
@ -678,51 +826,50 @@ char *LP_psock(char *myipaddr,int32_t ispaired)
*/
char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired)
char *issue_LP_psock(char *destip,uint16_t destport,int32_t ispaired,int32_t cmdchannel)
{
char url[512],*retstr;
sprintf(url,"http://%s:%u/api/stats/psock?ispaired=%d",destip,destport-1,ispaired);
char str[65],url[512],*retstr;
sprintf(url,"http://%s:%u/api/stats/psock?ispaired=%d&cmdchannel=%d&pubkey=%s",destip,destport-1,ispaired,cmdchannel,bits256_str(str,G.LP_mypub25519));
//return(LP_issue_curl("psock",destip,destport,url));
retstr = issue_curlt(url,LP_HTTP_TIMEOUT*3);
printf("issue_LP_psock got (%s) from %s\n",retstr,destip);
retstr = issue_curlt(url,LP_HTTP_TIMEOUT*10);
printf("issue_LP_psock got (%s) from %s\n",retstr,url); // this is needed?!
return(retstr);
}
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired)
uint16_t LP_psock_get(char *connectaddr,char *publicaddr,int32_t ispaired,int32_t cmdchannel,char *ipaddr)
{
uint16_t publicport = 0; char *retstr,*addr; cJSON *retjson; struct LP_peerinfo *peer,*tmp;
connectaddr[0] = publicaddr[0] = 0;
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
if ( ipaddr != 0 && strcmp(ipaddr,peer->ipaddr) != 0 )
continue;
connectaddr[0] = publicaddr[0] = 0;
if ( peer->errors < LP_MAXPEER_ERRORS && (retstr= issue_LP_psock(peer->ipaddr,peer->port,ispaired)) != 0 )
if ( peer->errors < LP_MAXPEER_ERRORS && (retstr= issue_LP_psock(peer->ipaddr,peer->port,ispaired,cmdchannel)) != 0 )
{
if ( (retjson= cJSON_Parse(retstr)) != 0 )
{
printf("from %s:%u (%s)\n",peer->ipaddr,peer->port,retstr);
//printf("from %s:%u (%s)\n",peer->ipaddr,peer->port,retstr);
if ( (addr= jstr(retjson,"publicaddr")) != 0 )
safecopy(publicaddr,addr,128);
if ( (addr= jstr(retjson,"connectaddr")) != 0 )
safecopy(connectaddr,addr,128);
//if ( (addr= jstr(retjson,"connectaddr2")) != 0 )
// safecopy(connectaddr2,addr,128);
if ( publicaddr[0] != 0 && connectaddr[0] != 0 )
publicport = juint(retjson,"publicport");
free_json(retjson);
}
printf("got.(%s) connect.%s public.%s\n",retstr,connectaddr,publicaddr);
//printf("got.(%s) connect.%s public.%s publicport.%u\n",retstr,connectaddr,publicaddr,publicport);
free(retstr);
} else printf("error psock from %s:%u\n",peer->ipaddr,peer->port);
if ( publicport != 0 )
break;
return(publicport);
} //else printf("error psock from %s:%u\n",peer->ipaddr,peer->port);
}
return(publicport);
return(0);
}
int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char *myipaddr,uint16_t mypullport,int32_t ispaired)
{
int32_t nntype,pullsock,timeout; char bindaddr[128],connectaddr[128];
*mypullportp = mypullport;
//connectaddr2[0] = 0;
if ( ispaired == 0 )
{
if ( LP_canbind != 0 )
@ -733,7 +880,6 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char
{
nanomsg_transportname(0,publicaddr,myipaddr,mypullport);
nanomsg_transportname(1,bindaddr,myipaddr,mypullport);
//nanomsg_transportname2(1,bindaddr2,myipaddr,mypullport);
}
else
{
@ -745,7 +891,7 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char
}
while ( *mypullportp == 0 )
{
if ( (*mypullportp= LP_psock_get(connectaddr,publicaddr,ispaired)) != 0 )
if ( (*mypullportp= LP_psock_get(connectaddr,publicaddr,ispaired,0,0)) != 0 )
break;
sleep(10);
printf("try to get publicaddr again\n");
@ -764,8 +910,6 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char
}
else
{
//if ( connectaddr2[0] != 0 && nn_connect(pullsock,connectaddr2) > 0 )
// printf("%s ",connectaddr2);
printf("nntype.%d NN_PAIR.%d connect to %s connectsock.%d\n",nntype,NN_PAIR,connectaddr,pullsock);
}
}
@ -776,14 +920,10 @@ int32_t LP_initpublicaddr(void *ctx,uint16_t *mypullportp,char *publicaddr,char
printf("bind to %s error for %s: %s\n",bindaddr,publicaddr,nn_strerror(nn_errno()));
exit(-1);
}
//if ( nn_bind(pullsock,bindaddr2) >= 0 )
// printf("bound to %s\n",bindaddr2);
}
timeout = 1;
timeout = 100;
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
//maxsize = 2 * 1024 * 1024;
//nn_setsockopt(pullsock,NN_SOL_SOCKET,NN_RCVBUF,&maxsize,sizeof(maxsize));
if ( nntype == NN_SUB )
nn_setsockopt(pullsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0);
}

305
iguana/exchanges/LP_ordermatch.c

@ -230,7 +230,7 @@ int32_t LP_nanobind(void *ctx,char *pairstr)
printf("error creating utxo->pair\n");
else
{
for (i=0; i<10; i++)
for (i=0; i<10000; i++)
{
r = (10000 + (LP_rand() % 50000)) & 0xffff;
if ( LP_fixed_pairport != 0 )
@ -242,12 +242,15 @@ int32_t LP_nanobind(void *ctx,char *pairstr)
//timeout = 1;
//nn_setsockopt(pairsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
//nn_setsockopt(pairsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
printf("nanobind %s to %d\n",pairstr,pairsock);
//printf("nanobind %s to %d\n",pairstr,pairsock);
return(pairsock);
} else printf("error binding to %s for %s\n",bindaddr,pairstr);
} // else printf("error binding to %s for %s\n",bindaddr,pairstr);
if ( LP_fixed_pairport != 0 )
break;
}
printf("%d ports all used\n",i);
nn_close(pairsock);
pairsock = -1;
}
} else pairsock = LP_initpublicaddr(ctx,&mypullport,pairstr,"127.0.0.1",0,1);
return(pairsock);
@ -411,7 +414,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
{
up = utxos[mini];
utxos[mini] = 0;
printf("found mini.%d %.8f for targetval %.8f -> targetval2 %.8f, ratio %.2f\n",mini,dstr(up->U.value),dstr(targetval),dstr(targetval2),(double)up->U.value/targetval);
//printf("found mini.%d %.8f for targetval %.8f -> targetval2 %.8f, ratio %.2f\n",mini,dstr(up->U.value),dstr(targetval),dstr(targetval2),(double)up->U.value/targetval);
if ( (double)up->U.value/targetval < ratio-1 )
{
@ -430,7 +433,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
LP_butxo_set(butxo,iambob,coin,up,up2,targetval);
return(butxo);
} else printf("cant find utxos[mini %d]\n",mini);
} else printf("cant find targetval2 %.8f\n",dstr(targetval2));
} //else printf("cant find targetval2 %.8f\n",dstr(targetval2));
} else printf("failed ratio test %.8f\n",(double)up->U.value/targetval);
} else if ( targetval != 0 && mini >= 0 )
printf("targetval %.8f mini.%d\n",dstr(targetval),mini);
@ -444,7 +447,7 @@ struct LP_utxoinfo *LP_address_myutxopair(struct LP_utxoinfo *butxo,int32_t iamb
int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double price,struct LP_quoteinfo *qp)
{
char pairstr[512],otheraddr[64]; cJSON *reqjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; struct basilisk_swap *swap; struct iguana_info *coin,*kmdcoin;
char pairstr[512],otheraddr[64]; cJSON *reqjson; bits256 privkey; int32_t pair=-1,retval = -1,DEXselector = 0; int64_t dtrust; struct basilisk_swap *swap; struct iguana_info *coin,*kmdcoin;
qp->quotetime = (uint32_t)time(NULL);
if ( (coin= LP_coinfind(qp->srccoin)) == 0 )
{
@ -455,12 +458,13 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 )
{
LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector);
if ( LP_pendingswap(qp->R.requestid,qp->R.quoteid) > 0 )
/*if ( LP_pendingswap(qp->R.requestid,qp->R.quoteid) > 0 )
{
printf("requestid.%u quoteid.%u is already in progres\n",qp->R.requestid,qp->R.quoteid);
return(-1);
}
if ( (swap= LP_swapinit(1,0,privkey,&qp->R,qp,LP_dynamictrust(qp->othercredits,qp->desthash,LP_kmdvalue(qp->destcoin,qp->destsatoshis)) > 0)) == 0 )
}*/
dtrust = LP_dynamictrust(qp->othercredits,qp->desthash,LP_kmdvalue(qp->destcoin,qp->destsatoshis));
if ( (swap= LP_swapinit(1,0,privkey,&qp->R,qp,dtrust > 0)) == 0 )
{
printf("cant initialize swap\n");
return(-1);
@ -468,8 +472,6 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
if ( (pair= LP_nanobind(ctx,pairstr)) >= 0 )
{
swap->N.pair = pair;
//utxo->S.swap = swap;
//swap->utxo = utxo;
if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)LP_bobloop,(void *)swap) == 0 )
{
reqjson = LP_quotejson(qp);
@ -477,14 +479,16 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
jaddstr(reqjson,"pair",pairstr);
if ( (kmdcoin= LP_coinfind("KMD")) != 0 )
jadd(reqjson,"proof",LP_instantdex_txids(0,kmdcoin->smartaddr));
char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,qp->desthash));
//char str[65]; printf("BOB pubsock.%d binds to %d (%s)\n",pubsock,pair,bits256_str(str,qp->desthash));
bits256 zero;
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,base,rel,zero,jprint(reqjson,0));
sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
sleep(1);
LP_reserved_msg(0,base,rel,zero,jprint(reqjson,0));
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
if ( 0 )
{
LP_reserved_msg(1,base,rel,zero,jprint(reqjson,0));
LP_reserved_msg(0,base,rel,zero,jprint(reqjson,0));
}
free_json(reqjson);
LP_importaddress(qp->destcoin,qp->destaddr);
LP_otheraddress(qp->srccoin,otheraddr,qp->destcoin,qp->destaddr);
@ -512,6 +516,7 @@ char *LP_trade(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo *q
qp->aliceid = LP_aliceid_calc(qp->desttxid,qp->destvout,qp->feetxid,qp->feevout);
if ( (qp->tradeid= tradeid) == 0 )
qp->tradeid = LP_rand();
qp->srchash = destpubkey;
LP_query(ctx,myipaddr,mypubsock,"request",qp);
LP_Alicequery = *qp, LP_Alicemaxprice = maxprice, Alice_expiration = qp->timestamp + timeout, LP_Alicedestpubkey = destpubkey;
char str[65]; printf("LP_trade %s/%s %.8f vol %.8f dest.(%s) maxprice %.8f\n",qp->srccoin,qp->destcoin,dstr(qp->satoshis),dstr(qp->destsatoshis),bits256_str(str,LP_Alicedestpubkey),maxprice);
@ -571,13 +576,13 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
printf("CONNECTED numpending.%d tradeid.%u requestid.%u quoteid.%u pairstr.%s\n",G.LP_pendingswaps,qp->tradeid,qp->R.requestid,qp->R.quoteid,pairstr!=0?pairstr:"");
LP_requestinit(&qp->R,qp->srchash,qp->desthash,qp->srccoin,qp->satoshis-qp->txfee,qp->destcoin,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector);
//printf("calculated requestid.%u quoteid.%u\n",qp->R.requestid,qp->R.quoteid);
if ( LP_pendingswap(qp->R.requestid,qp->R.quoteid) > 0 )
/*if ( LP_pendingswap(qp->R.requestid,qp->R.quoteid) > 0 )
{
printf("requestid.%u quoteid.%u is already in progres\n",qp->R.requestid,qp->R.quoteid);
retjson = cJSON_CreateObject();
jaddstr(retjson,"error","swap already in progress");
return(jprint(retjson,1));
}
}*/
/*if ( LP_quotecmp(1,qp,&LP_Alicereserved) == 0 )
{
printf("mismatched between reserved and connected\n");
@ -662,7 +667,7 @@ char *LP_connectedalice(struct LP_quoteinfo *qp,char *pairstr) // alice
LP_aliceid(qp->tradeid,qp->aliceid,"error10",qp->R.requestid,qp->R.quoteid);
printf("connect error %s\n",nn_strerror(nn_errno()));
}
printf("connected result.(%s)\n",jprint(retjson,0));
//printf("connected result.(%s)\n",jprint(retjson,0));
if ( jobj(retjson,"error") != 0 )
{
LP_availableset(qp->desttxid,qp->vout);
@ -702,7 +707,7 @@ int32_t LP_validSPV(char *symbol,char *coinaddr,bits256 txid,int32_t vout)
if ( vout < tx->numvouts && tx->height > 0 )
{
printf("added missing utxo for SPV checking\n");
LP_address_utxoadd((uint32_t)time(NULL),"LP_validSPV",coin,coinaddr,txid,vout,tx->outpoints[vout].value,tx->height,-1);
LP_address_utxoadd(0,(uint32_t)time(NULL),"LP_validSPV",coin,coinaddr,txid,vout,tx->outpoints[vout].value,tx->height,-1);
}
}
}
@ -767,7 +772,7 @@ void LP_reserved(void *ctx,char *myipaddr,int32_t mypubsock,struct LP_quoteinfo
qp->tradeid = LP_Alicequery.tradeid;
LP_Alicereserved = *qp;
LP_alicequery_clear();
printf("send CONNECT\n");
//printf("send CONNECT\n");
LP_query(ctx,myipaddr,mypubsock,"connect",qp);
} else printf("LP_reserved %llu price %.8f vs maxprice %.8f\n",(long long)qp->aliceid,price,maxprice);
} //else printf("probably a timeout, reject reserved due to not eligible.%d or mismatched quote price %.8f vs maxprice %.8f\n",LP_alice_eligible(qp->quotetime),price,maxprice);
@ -833,10 +838,9 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
double price,qprice,myprice,bestprice,range,bid,ask; struct iguana_info *coin; struct LP_utxoinfo A,B,*autxo,*butxo; cJSON *reqjson; char str[65]; struct LP_address_utxo *utxos[1000]; int32_t r,counter,max = (int32_t)(sizeof(utxos)/sizeof(*utxos));
*newqp = *qp;
qp = newqp;
//printf("bob %s received REQUEST.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
if ( (coin= LP_coinfind(qp->srccoin)) == 0 )
return(0);
//if ( strcmp(qp->srccoin,"GRS") == 0 || strcmp(qp->destcoin,"GRS") == 0 )
// printf("LP_trades_gotrequest %s/%s myprice %.8f\n",qp->srccoin,qp->destcoin,LP_trades_bobprice(&bid,&ask,qp));
if ( (myprice= LP_trades_bobprice(&bid,&ask,qp)) == 0. )
return(0);
autxo = &A;
@ -855,8 +859,6 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
memset(&qp->txid2,0,sizeof(qp->txid2));
qp->vout = qp->vout2 = -1;
} else return(0);
//if ( strcmp(qp->srccoin,"GRS") == 0 || strcmp(qp->destcoin,"GRS") == 0 )
// printf("LP_trades_gotrequest qprice %.8f vs myprice %.8f\n",qprice,myprice);
if ( qprice > myprice )
{
r = (LP_rand() % 100);
@ -864,7 +866,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
price = myprice + (r * range) / 100.;
bestprice = LP_bob_competition(&counter,qp->aliceid,price,0);
printf("%llu >>>>>>> qprice %.8f r.%d range %.8f -> %.8f, bestprice %.8f counter.%d\n",(long long)qp->aliceid,qprice,r,range,price,bestprice,counter);
if ( counter > 3 && price >= bestprice+SMALLVAL ) // skip if late or bad price
if ( counter > 3 && price > bestprice+SMALLVAL ) // skip if late or bad price
return(0);
} else return(0);
//LP_RTmetrics_update(qp->srccoin,qp->destcoin);
@ -873,7 +875,9 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
printf("request from blacklisted %s, ignore\n",bits256_str(str,qp->desthash));
return(0);
}
LP_address_utxo_reset(coin);
//printf("LP_address_utxo_reset.%s\n",coin->symbol);
//LP_address_utxo_reset(coin);
//printf("done LP_address_utxo_reset.%s\n",coin->symbol);
if ( (butxo= LP_address_myutxopair(butxo,1,utxos,max,LP_coinfind(qp->srccoin),qp->coinaddr,qp->txfee,dstr(qp->destsatoshis),price,qp->desttxfee)) != 0 )
{
strcpy(qp->gui,G.gui);
@ -888,13 +892,11 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
}
else
{
printf("cant find utxopair aliceid.%llu %s/%s %.8f -> relvol %.8f\n",(long long)qp->aliceid,qp->srccoin,qp->destcoin,dstr(LP_basesatoshis(dstr(qp->destsatoshis),price,qp->txfee,qp->desttxfee)),dstr(qp->destsatoshis));
//printf("cant find utxopair aliceid.%llu %s/%s %.8f -> relvol %.8f\n",(long long)qp->aliceid,qp->srccoin,qp->destcoin,dstr(LP_basesatoshis(dstr(qp->destsatoshis),price,qp->txfee,qp->desttxfee)),dstr(qp->destsatoshis));
return(0);
}
if ( (qprice= LP_trades_pricevalidate(qp,coin,myprice)) < 0. )
return(0);
//if ( strcmp(qp->srccoin,"GRS") == 0 || strcmp(qp->destcoin,"GRS") == 0 )
// printf("final checks\n");
if ( LP_allocated(qp->txid,qp->vout) == 0 && LP_allocated(qp->txid2,qp->vout2) == 0 )
{
reqjson = LP_quotejson(qp);
@ -905,16 +907,12 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
jaddnum(reqjson,"quotetime",qp->quotetime);
jaddnum(reqjson,"pending",qp->timestamp + LP_RESERVETIME);
jaddstr(reqjson,"method","reserved");
//LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
bits256 zero;
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
if ( 0 )//if ( IAMLP == 0 )
{
sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
}
//LP_reserved_msg(0,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
free_json(reqjson);
//printf("Send RESERVED id.%llu\n",(long long)qp->aliceid);
return(qp);
} else printf("request processing selected ineligible utxos?\n");
return(0);
@ -923,7 +921,7 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
struct LP_quoteinfo *LP_trades_gotreserved(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp)
{
char *retstr;
char str[65]; printf("alice %s received RESERVED.(%llu) %.8f\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid,(double)qp->destsatoshis/(qp->satoshis+1));
//char str[65]; printf("alice %s received RESERVED.(%llu) %.8f\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid,(double)qp->destsatoshis/(qp->satoshis+1));
*newqp = *qp;
qp = newqp;
if ( LP_trades_alicevalidate(ctx,qp) > 0. )
@ -939,6 +937,7 @@ struct LP_quoteinfo *LP_trades_gotreserved(void *ctx,struct LP_quoteinfo *qp,str
struct LP_quoteinfo *LP_trades_gotconnect(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp,char *pairstr)
{
double myprice,qprice,bid,ask; struct iguana_info *coin;
char str[65]; printf("bob %s received CONNECT.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
*newqp = *qp;
qp = newqp;
if ( (coin= LP_coinfind(qp->srccoin)) == 0 )
@ -958,7 +957,7 @@ struct LP_quoteinfo *LP_trades_gotconnect(void *ctx,struct LP_quoteinfo *qp,stru
struct LP_quoteinfo *LP_trades_gotconnected(void *ctx,struct LP_quoteinfo *qp,struct LP_quoteinfo *newqp,char *pairstr)
{
char *retstr;
char str[65]; printf("alice %s received CONNECTED.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
//char str[65]; printf("alice %s received CONNECTED.(%llu)\n",bits256_str(str,G.LP_mypub25519),(long long)qp->aliceid);
*newqp = *qp;
qp = newqp;
if ( LP_trades_alicevalidate(ctx,qp) > 0. )
@ -1012,12 +1011,64 @@ void LP_tradesloop(void *ctx)
{
struct LP_trade *qtp,*tp,*tmp; struct LP_quoteinfo *qp,Q; uint32_t now; int32_t timeout,funcid,flag,nonz; struct iguana_info *coin; struct LP_pubkey_info *pubp;
strcpy(LP_tradesloop_stats.name,"LP_tradesloop");
LP_tradesloop_stats.threshold = 10000;
LP_tradesloop_stats.threshold = 30000;
sleep(5);
while ( LP_STOP_RECEIVED == 0 )
{
LP_millistats_update(&LP_tradesloop_stats);
nonz = 0;
HASH_ITER(hh,LP_trades,tp,tmp)
{
if ( tp->negotiationdone != 0 )
continue;
timeout = LP_AUTOTRADE_TIMEOUT;
if ( (coin= LP_coinfind(tp->Q.srccoin)) != 0 && coin->electrum != 0 )
timeout += LP_AUTOTRADE_TIMEOUT * .5;
if ( (coin= LP_coinfind(tp->Q.destcoin)) != 0 && coin->electrum != 0 )
timeout += LP_AUTOTRADE_TIMEOUT * .5;
now = (uint32_t)time(NULL);
if ( now > tp->lastprocessed )
{
if ( tp->iambob == 0 )
{
if ( tp->bestprice > 0. )
{
if ( tp->connectsent == 0 )
{
LP_Alicemaxprice = tp->bestprice;
LP_reserved(ctx,LP_myipaddr,LP_mypubsock,&tp->Qs[LP_CONNECT]); // send LP_CONNECT
tp->connectsent = now;
//printf("send LP_connect aliceid.%llu %.8f\n",(long long)tp->aliceid,tp->bestprice);
}
else if ( now < tp->firstprocessed+timeout && ((tp->firstprocessed - now) % 20) == 19 )
{
//LP_Alicemaxprice = tp->bestprice;
//LP_reserved(ctx,LP_myipaddr,LP_mypubsock,&tp->Qs[LP_CONNECT]); // send LP_CONNECT
//printf("mark slow LP_connect aliceid.%llu %.8f\n",(long long)tp->aliceid,tp->bestprice);
if ( (pubp= LP_pubkeyfind(tp->Qs[LP_CONNECT].srchash)) != 0 )
pubp->slowresponse++;
}
}
}
}
}
now = (uint32_t)time(NULL);
HASH_ITER(hh,LP_trades,tp,tmp)
{
timeout = LP_AUTOTRADE_TIMEOUT;
if ( (coin= LP_coinfind(tp->Q.srccoin)) != 0 && coin->electrum != 0 )
timeout += LP_AUTOTRADE_TIMEOUT * .5;
if ( (coin= LP_coinfind(tp->Q.destcoin)) != 0 && coin->electrum != 0 )
timeout += LP_AUTOTRADE_TIMEOUT * .5;
if ( now > tp->firstprocessed+timeout*10 )
{
//printf("purge swap aliceid.%llu\n",(long long)tp->aliceid);
portable_mutex_lock(&LP_tradesmutex);
HASH_DELETE(hh,LP_trades,tp);
portable_mutex_unlock(&LP_tradesmutex);
free(tp);
}
}
DL_FOREACH_SAFE(LP_tradesQ,qtp,tmp)
{
now = (uint32_t)time(NULL);
@ -1029,106 +1080,83 @@ void LP_tradesloop(void *ctx)
HASH_FIND(hh,LP_trades,&qtp->aliceid,sizeof(qtp->aliceid),tp);
if ( tp == 0 )
{
tp = qtp;
HASH_ADD(hh,LP_trades,aliceid,sizeof(tp->aliceid),tp);
portable_mutex_unlock(&LP_tradesmutex);
if ( tp->iambob != 0 && funcid == LP_REQUEST ) // bob maybe sends LP_RESERVED
{
if ( (qp= LP_trades_gotrequest(ctx,&Q,&tp->Qs[LP_REQUEST],tp->pairstr)) != 0 )
tp->Qs[LP_RESERVED] = Q;
}
else if ( tp->iambob == 0 && funcid == LP_RESERVED ) // alice maybe sends LP_CONNECT
{
LP_trades_bestpricecheck(ctx,tp);
}
nonz++;
tp->firstprocessed = tp->lastprocessed = (uint32_t)time(NULL);
//printf("iambob.%d funcid.%d vs %d\n",tp->iambob,funcid,LP_REQUEST);
continue;
}
portable_mutex_unlock(&LP_tradesmutex);
tp->Q = qtp->Q;
if ( qtp->iambob == tp->iambob && qtp->pairstr[0] != 0 )
safecopy(tp->pairstr,qtp->pairstr,sizeof(tp->pairstr));
//printf("finished dequeue %p funcid.%d aliceid.%llu iambob.%d\n",qtp,funcid,(long long)qtp->aliceid,qtp->iambob);
free(qtp);
if ( tp->negotiationdone != 0 )
continue;
flag = 0;
if ( qtp->iambob == tp->iambob )
{
if ( tp->iambob == 0 )
if ( now > Q.timestamp+LP_AUTOTRADE_TIMEOUT*2 ) // eat expired
free(qtp);
else
{
if ( funcid == LP_RESERVED )
tp = qtp;
HASH_ADD(hh,LP_trades,aliceid,sizeof(tp->aliceid),tp);
portable_mutex_unlock(&LP_tradesmutex);
if ( tp->iambob != 0 && funcid == LP_REQUEST ) // bob maybe sends LP_RESERVED
{
if ( tp->connectsent == 0 )
flag = LP_trades_bestpricecheck(ctx,tp);
if ( (qp= LP_trades_gotrequest(ctx,&Q,&tp->Qs[LP_REQUEST],tp->pairstr)) != 0 )
tp->Qs[LP_RESERVED] = Q;
}
else if ( funcid == LP_CONNECTED && tp->connectsent != 0 && tp->negotiationdone == 0 ) // alice all done
else if ( tp->iambob == 0 && funcid == LP_RESERVED ) // alice maybe sends LP_CONNECT
{
LP_trades_bestpricecheck(ctx,tp);
}
else if ( tp->iambob == 0 && funcid == LP_CONNECTED )
{
flag = 1;
tp->negotiationdone = now;
//printf("alice sets negotiationdone.%u\n",now);
LP_trades_gotconnected(ctx,&tp->Q,&tp->Qs[LP_CONNECTED],tp->pairstr);
}
}
else
{
nonz++;
tp->firstprocessed = tp->lastprocessed = (uint32_t)time(NULL);
if ( funcid == LP_CONNECT && tp->negotiationdone == 0 ) // bob all done
{
flag = 1;
tp->negotiationdone = now;
//printf("bob sets negotiationdone.%u\n",now);
LP_trades_gotconnect(ctx,&tp->Q,&tp->Qs[LP_CONNECT],tp->pairstr);
}
}
if ( flag != 0 )
continue;
}
portable_mutex_unlock(&LP_tradesmutex);
tp->Q = qtp->Q;
if ( qtp->iambob == tp->iambob && qtp->pairstr[0] != 0 )
safecopy(tp->pairstr,qtp->pairstr,sizeof(tp->pairstr));
//printf("finished dequeue %p funcid.%d aliceid.%llu iambob.%d/%d done.%u\n",qtp,funcid,(long long)qtp->aliceid,qtp->iambob,tp->iambob,tp->negotiationdone);
free(qtp);
flag = 0;
if ( tp->iambob == 0 )
{
if ( funcid == LP_RESERVED )
{
tp->lastprocessed = (uint32_t)time(NULL);
nonz++;
if ( tp->connectsent == 0 )
flag = LP_trades_bestpricecheck(ctx,tp);
}
else if ( funcid == LP_CONNECTED && tp->negotiationdone == 0 ) // alice all done tp->connectsent != 0 &&
{
flag = 1;
tp->negotiationdone = now;
LP_trades_gotconnected(ctx,&tp->Q,&tp->Qs[LP_CONNECTED],tp->pairstr);
}
}
}
HASH_ITER(hh,LP_trades,tp,tmp)
{
if ( tp->negotiationdone != 0 )
continue;
timeout = LP_AUTOTRADE_TIMEOUT;
if ( (coin= LP_coinfind(tp->Q.srccoin)) != 0 && coin->electrum != 0 )
timeout += LP_AUTOTRADE_TIMEOUT * .5;
if ( (coin= LP_coinfind(tp->Q.destcoin)) != 0 && coin->electrum != 0 )
timeout += LP_AUTOTRADE_TIMEOUT * .5;
now = (uint32_t)time(NULL);
if ( now > tp->lastprocessed )
else
{
if ( tp->iambob == 0 )
if ( funcid == LP_REQUEST ) // bob maybe sends LP_RESERVED
{
if ( tp->bestprice > 0. )
if ( (qp= LP_trades_gotrequest(ctx,&Q,&tp->Qs[LP_REQUEST],tp->pairstr)) != 0 )
{
if ( tp->connectsent == 0 )
{
LP_Alicemaxprice = tp->bestprice;
LP_reserved(ctx,LP_myipaddr,LP_mypubsock,&tp->Qs[LP_CONNECT]); // send LP_CONNECT
tp->connectsent = now;
//printf("send LP_connect aliceid.%llu %.8f\n",(long long)tp->aliceid,tp->bestprice);
}
else if ( now < tp->firstprocessed+timeout && ((tp->firstprocessed - now) % 10) == 9 )
{
LP_Alicemaxprice = tp->bestprice;
LP_reserved(ctx,LP_myipaddr,LP_mypubsock,&tp->Qs[LP_CONNECT]); // send LP_CONNECT
printf("repeat LP_connect aliceid.%llu %.8f\n",(long long)tp->aliceid,tp->bestprice);
if ( (pubp= LP_pubkeyfind(tp->Qs[LP_CONNECT].srchash)) != 0 )
pubp->slowresponse++;
}
tp->Qs[LP_RESERVED] = Q;
flag = 1;
}
}
else if ( now > tp->firstprocessed+timeout*10 )
else if ( funcid == LP_CONNECT && tp->negotiationdone == 0 ) // bob all done
{
//printf("purge swap aliceid.%llu\n",(long long)tp->aliceid);
portable_mutex_lock(&LP_tradesmutex);
HASH_DELETE(hh,LP_trades,tp);
portable_mutex_unlock(&LP_tradesmutex);
free(tp);
flag = 1;
tp->negotiationdone = now;
//printf("bob sets negotiationdone.%u\n",now);
LP_trades_gotconnect(ctx,&tp->Q,&tp->Qs[LP_CONNECT],tp->pairstr);
}
}
if ( flag != 0 )
{
tp->lastprocessed = (uint32_t)time(NULL);
nonz++;
}
}
if ( nonz == 0 )
sleep(1);
@ -1161,14 +1189,19 @@ void LP_tradecommandQ(struct LP_quoteinfo *qp,char *pairstr,int32_t funcid)
int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,uint8_t *data,int32_t datalen)
{
int32_t Qtrades = 1;
char *method,str[65]; int32_t num,DEXselector = 0; uint64_t aliceid; double qprice,bestprice,price,bid,ask; cJSON *proof; struct iguana_info *coin; struct LP_quoteinfo Q,Q2; int32_t counter,retval=-1;
char *method,str[65]; int32_t i,num,DEXselector = 0; uint64_t aliceid; double qprice,bestprice,price,bid,ask; cJSON *proof; uint64_t rq; struct iguana_info *coin; struct LP_quoteinfo Q,Q2; int32_t counter,retval=-1;
if ( (method= jstr(argjson,"method")) != 0 && (strcmp(method,"reserved") == 0 ||strcmp(method,"connected") == 0 || strcmp(method,"request") == 0 || strcmp(method,"connect") == 0) )
{
LP_quoteparse(&Q,argjson);
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector);
LP_tradecommand_log(argjson);
rq = ((uint64_t)Q.R.requestid << 32) | Q.R.quoteid;
if ( Q.timestamp > 0 && time(NULL) > Q.timestamp + LP_AUTOTRADE_TIMEOUT*20 ) // eat expired packets, some old timestamps floating about?
{
printf("aliceid.%llu is expired by %d\n",(long long)Q.aliceid,(uint32_t)time(NULL) - (Q.timestamp + LP_AUTOTRADE_TIMEOUT*20));
return(1);
}
printf("%-4d (%-10u %10u) %12s id.%-20llu %5s/%-5s %12.8f -> %12.8f (%11.8f) | RT.%d %d n%d\n",(uint32_t)time(NULL) % 3600,Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,LP_RTcount,LP_swapscount,G.netid);
//LP_autoprices_update(method,Q.srccoin,dstr(Q.satoshis),Q.destcoin,dstr(Q.destsatoshis));
retval = 1;
aliceid = j64bits(argjson,"aliceid");
qprice = jdouble(argjson,"price");
@ -1176,7 +1209,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
{
bestprice = LP_bob_competition(&counter,aliceid,qprice,1);
//printf("%s lag %ld: aliceid.%llu price %.8f -> bestprice %.8f Alice max %.8f\n",jprint(argjson,0),Q.quotetime - (time(NULL)-20),(long long)aliceid,qprice,bestprice,LP_Alicemaxprice);
if ( 0 )
if ( 1 )
{
if ( LP_Alicemaxprice == 0. )
return(retval);
@ -1189,7 +1222,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
} else printf("got reserved response from destpubkey %s\n",bits256_str(str,Q.srchash));
}
}
if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 )
if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 ) // alice
{
if ( Qtrades == 0 )
{
@ -1205,9 +1238,19 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
else if ( strcmp(method,"connected") == 0 )
{
bestprice = LP_bob_competition(&counter,aliceid,qprice,1000);
if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 )
if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 ) // alice
{
//printf("CONNECTED.(%s)\n",jprint(argjson,0));
static uint64_t rqs[1024];
for (i=0; i<sizeof(rqs)/sizeof(*rqs); i++)
if ( rq == rqs[i] )
return(retval);
for (i=0; i<sizeof(rqs)/sizeof(*rqs); i++)
if ( rqs[i] == 0 )
break;
if ( i == sizeof(rqs)/sizeof(*rqs) )
i = (rand() % (sizeof(rqs)/sizeof(*rqs)));
rqs[i] = rq;
//printf("CONNECTED.(%s)\n",jprint(argjson,0));
if ( (proof= jarray(&num,argjson,"proof")) != 0 && num > 0 )
Q.othercredits = LP_instantdex_proofcheck(Q.srccoin,Q.coinaddr,proof,num);
if ( Qtrades == 0 )
@ -1231,21 +1274,29 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,
printf("{\"error\":\"GAME can only be alice coin\"}\n");
return(retval);
}
if ( strcmp(method,"request") == 0 )
if ( strcmp(method,"request") == 0 ) // bob
{
bestprice = LP_bob_competition(&counter,aliceid,qprice,-1);
//if ( strcmp(Q.srccoin,"GRS") == 0 || strcmp(Q.destcoin,"GRS") == 0 )
// printf("%s lag %ld: aliceid.%llu price %.8f -> bestprice %.8f\n",jprint(argjson,0),Q.quotetime - (time(NULL)-20),(long long)aliceid,qprice,bestprice);
if ( Qtrades == 0 )
if ( Qtrades == 0 )//|| (bits256_cmp(Q.srchash,G.LP_mypub25519) == 0 && bits256_cmp(G.LP_mypub25519,Q.desthash) != 0) )
LP_trades_gotrequest(ctx,&Q,&Q2,jstr(argjson,"pair"));
else LP_tradecommandQ(&Q,jstr(argjson,"pair"),LP_REQUEST);
}
else if ( strcmp(method,"connect") == 0 )
{
LP_bob_competition(&counter,aliceid,qprice,1000);
if ( bits256_cmp(G.LP_mypub25519,Q.srchash) == 0 && bits256_cmp(G.LP_mypub25519,Q.desthash) != 0 )
if ( bits256_cmp(G.LP_mypub25519,Q.srchash) == 0 && bits256_cmp(G.LP_mypub25519,Q.desthash) != 0 ) // bob
{
printf("CONNECT.(%s)\n",jprint(argjson,0));
static uint64_t rqs[1024];
for (i=0; i<sizeof(rqs)/sizeof(*rqs); i++)
if ( rq == rqs[i] )
return(retval);
for (i=0; i<sizeof(rqs)/sizeof(*rqs); i++)
if ( rqs[i] == 0 )
break;
if ( i == sizeof(rqs)/sizeof(*rqs) )
i = (rand() % (sizeof(rqs)/sizeof(*rqs)));
rqs[i] = rq;
//printf("CONNECT.(%s)\n",jprint(argjson,0));
if ( (proof= jarray(&num,argjson,"proof")) != 0 && num > 0 )
Q.othercredits = LP_instantdex_proofcheck(Q.destcoin,Q.destaddr,proof,num);
if ( Qtrades == 0 )

103
iguana/exchanges/LP_peers.c

@ -56,6 +56,61 @@ char *LP_peers()
return(jprint(peersjson,1));
}
void LP_cmdchannel(struct LP_peerinfo *peer)
{
char *hellostr = "{\"method\":\"hello\"}";
char connectaddr[128],publicaddr[128],*retstr; int32_t pairsock=-1,pubsock,sentbytes=-2; uint16_t cmdport;
#ifdef LP_DONT_CMDCHANNEL
return;
#endif
if ( bits256_nonz(G.LP_mypub25519) == 0 || strcmp(G.USERPASS,"1d8b27b21efabcd96571cd56f91a40fb9aa4cc623d273c63bf9223dc6f8cd81f") == 0 )
return;
if ( (cmdport= LP_psock_get(connectaddr,publicaddr,1,1,peer->ipaddr)) != 0 )
{
if ( (retstr= _LP_psock_create(&pairsock,&pubsock,peer->ipaddr,cmdport,cmdport,1,1,G.LP_mypub25519)) != 0 )
{
if ( nn_connect(pairsock,connectaddr) < 0 )
printf("error connecting cmdchannel with %s\n",connectaddr);
else
{
peer->pairsock = pairsock;
sentbytes = nn_send(peer->pairsock,hellostr,(int32_t)strlen(hellostr)+1,0);
printf("cmdchannel %d created %s sent.%d\n",peer->pairsock,retstr,sentbytes);
}
free(retstr);
}
} else printf("error getting cmdchannel with %s\n",peer->ipaddr);
}
void LP_cmdchannels()
{
struct LP_peerinfo *peer,*tmp;
if ( IAMLP == 0 )
{
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
if ( peer->pairsock < 0 )
LP_cmdchannel(peer);
}
}
}
void LP_peer_pairsock(bits256 pubkey)
{
struct LP_peerinfo *peer,*tmp;
if ( IAMLP == 0 )
{
HASH_ITER(hh,LP_peerinfos,peer,tmp)
{
if ( bits256_cmp(pubkey,peer->pubkey) == 0 )
{
peer->pairsock = -1;
break;
}
}
}
}
struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char *ipaddr,uint16_t port,uint16_t pushport,uint16_t subport,int32_t isLP,uint32_t sessionid,uint16_t netid)
{
uint32_t ipbits; int32_t valid,pushsock,subsock,timeout; char checkip[64],pushaddr[64],subaddr[64]; struct LP_peerinfo *peer = 0;
@ -79,6 +134,8 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
if ( (peer->isLP= isLP) != 0 )
LP_numactive_LP++;
}
if ( IAMLP == 0 && peer->pairsock < 0 )
LP_cmdchannel(peer);
/*if ( numpeers > peer->numpeers )
peer->numpeers = numpeers;
if ( numutxos > peer->numutxos )
@ -86,10 +143,11 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
if ( peer->sessionid == 0 )
peer->sessionid = sessionid;*/
}
else if ( IAMLP != 0 || LP_numactive_LP < 3 )
else if ( IAMLP != 0 || LP_numactive_LP < 10 )
{
//printf("addpeer (%s:%u) pushport.%u subport.%u\n",ipaddr,port,pushport,subport);
peer = calloc(1,sizeof(*peer));
peer->pairsock = -1;
if ( strcmp(peer->ipaddr,LP_myipaddr) == 0 )
peer->sessionid = G.LP_sessionid;
else peer->sessionid = sessionid;
@ -105,33 +163,27 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
if ( pushport != 0 && subport != 0 && (pushsock= nn_socket(AF_SP,NN_PUSH)) >= 0 )
{
nanomsg_transportname(0,pushaddr,peer->ipaddr,pushport);
//nanomsg_transportname2(0,pushaddr2,peer->ipaddr,pushport);
valid = 0;
if ( nn_connect(pushsock,pushaddr) >= 0 )
valid++;
//if ( nn_connect(pushsock,pushaddr2) >= 0 )
// valid++;
if ( valid > 0 )
{
timeout = 1;
//timeout = 10;
//nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_MAXTTL,&timeout,sizeof(timeout));
timeout = 100;
nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDTIMEO,&timeout,sizeof(timeout));
//maxsize = 2 * 1024 * 1024;
//nn_setsockopt(pushsock,NN_SOL_SOCKET,NN_SNDBUF,&maxsize,sizeof(maxsize));
printf("connected to push.(%s) pushsock.%d valid.%d | ",pushaddr,pushsock,valid);
peer->connected = (uint32_t)time(NULL);
peer->pushsock = pushsock;
if ( (subsock= nn_socket(AF_SP,NN_SUB)) >= 0 )
{
timeout = 1;
timeout = 100;
nn_setsockopt(subsock,NN_SOL_SOCKET,NN_RCVTIMEO,&timeout,sizeof(timeout));
nn_setsockopt(subsock,NN_SUB,NN_SUB_SUBSCRIBE,"",0);
nanomsg_transportname(0,subaddr,peer->ipaddr,subport);
//nanomsg_transportname2(0,subaddr2,peer->ipaddr,subport);
valid = 0;
if ( nn_connect(subsock,subaddr) >= 0 )
valid++;
//if ( nn_connect(subsock,subaddr2) >= 0 )
// valid++;
if ( valid > 0 )
{
peer->subsock = subsock;
@ -163,24 +215,8 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
printf("_LPaddpeer %s -> numpeers.%d mypubsock.%d other.(%d)\n",ipaddr,mypeer->numpeers,mypubsock,isLP);
} else peer->numpeers = 1; // will become mypeer
portable_mutex_unlock(&LP_peermutex);
/*if ( IAMLP != 0 && mypubsock >= 0 )
{
//struct iguana_info *coin,*ctmp; char busaddr[64]; //
//memset(zero.bytes,0,sizeof(zero));
//LP_send(mypubsock,msg,(int32_t)strlen(msg)+1,1);
//LP_reserved_msg(0,"","",zero,jprint(LP_peerjson(peer),1));
if ( 0 )
{
HASH_ITER(hh,LP_coins,coin,ctmp)
{
if ( coin->bussock >= 0 )
{
nanomsg_transportname(0,busaddr,peer->ipaddr,coin->busport);
nn_connect(coin->bussock,busaddr);
}
}
}
}*/
if ( IAMLP == 0 && peer->pairsock < 0 )
LP_cmdchannel(peer);
} else printf("%s invalid pushsock.%d or subsock.%d\n",peer->ipaddr,peer->pushsock,peer->subsock);
}
} else printf("LP_addpeer: checkip.(%s) vs (%s)\n",checkip,ipaddr);
@ -233,13 +269,18 @@ void LP_closepeers()
return(bussock);
}*/
void LP_peer_recv(char *ipaddr,int32_t ismine)
void LP_peer_recv(char *ipaddr,int32_t ismine,struct LP_pubkey_info *pubp)
{
struct LP_peerinfo *peer;
if ( (peer= LP_peerfind((uint32_t)calc_ipbits(ipaddr),RPC_port)) != 0 )
{
peer->numrecv++;
//if ( ismine != 0 )
if ( ismine != 0 && bits256_cmp(G.LP_mypub25519,pubp->pubkey) != 0 && (bits256_nonz(peer->pubkey) == 0 || pubp->pairsock < 0) )
{
peer->pubkey = pubp->pubkey;
pubp->pairsock = peer->pairsock;
char str[65]; printf("set pubkey for %s <- %s, pairsock.%d\n",ipaddr,bits256_str(str,pubp->pubkey),pubp->pairsock);
}
peer->recvtime = (uint32_t)time(NULL);
}
}

3
iguana/exchanges/LP_prices.c

@ -304,6 +304,7 @@ struct LP_pubkey_info *LP_pubkeyadd(bits256 pubkey)
{
pubp = calloc(1,sizeof(*pubp));
pubp->pubkey = pubkey;
pubp->pairsock = -1;
if ( bits256_cmp(G.LP_mypub25519,pubkey) == 0 )
{
memcpy(pubp->rmd160,G.LP_myrmd160,sizeof(pubp->rmd160));
@ -853,7 +854,7 @@ char *LP_orderbook(char *base,char *rel,int32_t duration)
suppress_prefetch = 1;
duration = LP_ORDERBOOK_DURATION;
}
LP_pubkeys_query();
//LP_pubkeys_query();
baseid = basepp->ind;
relid = relpp->ind;
now = (uint32_t)time(NULL);

3
iguana/exchanges/LP_privkey.c

@ -317,7 +317,7 @@ bits256 LP_privkeycalc(void *ctx,uint8_t *pubkey33,bits256 *pubkeyp,struct iguan
printf("userpass.(%s)\n",bits256_str(G.USERPASS,userpub));
}
}
if ( coin->importedprivkey == 0 && coin->electrum == 0 && coin->userpass[0] != 0 && LP_getheight(&notarized,coin) > 0 )
if ( strcmp(coin->smartaddr,"RPZVpjptzfZnFZZoLnuSbfLexjtkhe6uvn") != 0 && coin->importedprivkey == 0 && coin->electrum == 0 && coin->userpass[0] != 0 && LP_getheight(&notarized,coin) > 0 )
{
memset(zero.bytes,0,sizeof(zero));
LP_listunspent_issue(coin->symbol,coin->smartaddr,0,zero,zero);
@ -417,6 +417,7 @@ int32_t LP_passphrase_init(char *passphrase,char *gui,uint16_t netid,char *seedn
LP_priceinfos_clear();
G.USERPASS_COUNTER = counter;
G.initializing = 0;
//LP_cmdchannels();
return(0);
}

30
iguana/exchanges/LP_remember.c

@ -235,7 +235,7 @@ bits256 basilisk_swap_privbob_extract(char *symbol,bits256 spendtxid,int32_t vin
privkey.bytes[31 - i] = script[siglen+2+i];
else privkey.bytes[i] = script[siglen+2+i];
}
char str[65]; printf("extracted privbob.(%s)\n",bits256_str(str,privkey));
//char str[65]; printf("extracted privbob.(%s)\n",bits256_str(str,privkey));
}
return(privkey);
}
@ -794,7 +794,7 @@ int32_t LP_swap_load(struct LP_swap_remember *rswap,int32_t forceflag)
{
if ( (sentobj= LP_gettx(symbol,txid,1)) == 0 )
{
char str2[65]; printf("%s %s ready to broadcast\n",symbol,bits256_str(str2,txid));
char str2[65]; printf("%s %s ready to broadcast %s r%u q%u\n",symbol,bits256_str(str2,txid),txnames[i],rswap->requestid,rswap->quoteid);
}
else
{
@ -1027,7 +1027,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
for (j=0; j<32; j++)
rev.bytes[j] = rswap.myprivs[0].bytes[31 - j];
if ( (rswap.txbytes[BASILISK_ALICESPEND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"alicespend",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_ALICESPEND],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]);
{
//printf("alicespend.(%s)\n",rswap.txbytes[BASILISK_ALICESPEND]);
}
}
LP_txbytes_update("alicespend",rswap.bobcoin,rswap.txbytes[BASILISK_ALICESPEND],&rswap.txids[BASILISK_ALICESPEND],&rswap.paymentspent,&rswap.sentflags[BASILISK_ALICESPEND]);
}
@ -1104,7 +1106,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
if ( bits256_nonz(rswap.privAm) != 0 && bits256_nonz(rswap.privBn) != 0 )
{
if ( (rswap.txbytes[BASILISK_BOBSPEND]= basilisk_swap_Aspend("bobspend",rswap.alicecoin,rswap.Atxfee,alice->wiftaddr,alice->taddr,alice->pubtype,alice->p2shtype,alice->isPoS,alice->wiftype,ctx,rswap.privAm,rswap.privBn,rswap.txids[BASILISK_ALICEPAYMENT],0,rswap.pubkey33,rswap.expiration,&rswap.values[BASILISK_BOBSPEND],rswap.alicepaymentaddr,alice->zcash)) != 0 )
printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]);
{
//printf("bobspend.(%s)\n",rswap.txbytes[BASILISK_BOBSPEND]);
}
}
LP_txbytes_update("bobspend",rswap.alicecoin,rswap.txbytes[BASILISK_BOBSPEND],&rswap.txids[BASILISK_BOBSPEND],&rswap.Apaymentspent,&rswap.sentflags[BASILISK_BOBSPEND]);
}
@ -1128,16 +1132,18 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
len = basilisk_swapuserdata(userdata,zero,1,rswap.myprivs[1],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_BOBRECLAIM]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[1],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBPAYMENT],0,0,rswap.pubkey33,0,claimtime,&rswap.values[BASILISK_BOBRECLAIM],0,0,rswap.bobpaymentaddr,1,bob->zcash)) != 0 )
{
int32_t z;
for (z=0; z<20; z++)
printf("%02x",rswap.secretAm[z]);
printf(" secretAm, myprivs[1].(%s) bobreclaim.(%s)\n",bits256_str(str,rswap.myprivs[1]),rswap.txbytes[BASILISK_BOBRECLAIM]);
//int32_t z;
//for (z=0; z<20; z++)
// printf("%02x",rswap.secretAm[z]);
//printf(" secretAm, myprivs[1].(%s) bobreclaim.(%s)\n",bits256_str(str,rswap.myprivs[1]),rswap.txbytes[BASILISK_BOBRECLAIM]);
}
}
LP_txbytes_update("bobreclaim",rswap.bobcoin,rswap.txbytes[BASILISK_BOBRECLAIM],&rswap.txids[BASILISK_BOBRECLAIM],&rswap.paymentspent,&rswap.sentflags[BASILISK_BOBRECLAIM]);
}
else if ( flag == 0 )
printf("bobpayment: now.%u < expiration %u\n",(uint32_t)time(NULL),rswap.expiration);
{
//printf("bobpayment: now.%u < expiration %u\n",(uint32_t)time(NULL),rswap.expiration);
}
}
if ( rswap.sentflags[BASILISK_BOBREFUND] == 0 && rswap.sentflags[BASILISK_BOBDEPOSIT] != 0 && bits256_nonz(rswap.txids[BASILISK_BOBDEPOSIT]) != 0 && bits256_nonz(rswap.depositspent) == 0 )
{
@ -1150,7 +1156,7 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
}
if ( bits256_nonz(rswap.Apaymentspent) != 0 || time(NULL) > rswap.expiration+777 )
{
printf("do the refund! paymentspent.%s now.%u vs expiration.%u\n",bits256_str(str,rswap.paymentspent),(uint32_t)time(NULL),rswap.expiration);
//printf("do the refund! paymentspent.%s now.%u vs expiration.%u\n",bits256_str(str,rswap.paymentspent),(uint32_t)time(NULL),rswap.expiration);
//if ( txbytes[BASILISK_BOBREFUND] == 0 )
{
revcalc_rmd160_sha256(rswap.secretBn,rswap.privBn);
@ -1158,7 +1164,9 @@ cJSON *basilisk_remember(int64_t *KMDtotals,int64_t *BTCtotals,uint32_t requesti
redeemlen = basilisk_swap_bobredeemscript(1,&secretstart,redeemscript,rswap.dlocktime,rswap.pubA0,rswap.pubB0,rswap.pubB1,rswap.privAm,rswap.privBn,rswap.secretAm,rswap.secretAm256,rswap.secretBn,rswap.secretBn256);
len = basilisk_swapuserdata(userdata,rswap.privBn,0,rswap.myprivs[0],redeemscript,redeemlen);
if ( (rswap.txbytes[BASILISK_BOBREFUND]= basilisk_swap_bobtxspend(&signedtxid,rswap.Btxfee,"bobrefund",rswap.bobcoin,bob->wiftaddr,bob->taddr,bob->pubtype,bob->p2shtype,bob->isPoS,bob->wiftype,ctx,rswap.myprivs[0],0,redeemscript,redeemlen,userdata,len,rswap.txids[BASILISK_BOBDEPOSIT],0,0,rswap.pubkey33,1,rswap.expiration,&rswap.values[BASILISK_BOBREFUND],0,0,rswap.bobdepositaddr,1,bob->zcash)) != 0 )
printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,rswap.pubB1),rswap.txbytes[BASILISK_BOBREFUND]);
{
//printf("pubB1.(%s) bobrefund.(%s)\n",bits256_str(str,rswap.pubB1),rswap.txbytes[BASILISK_BOBREFUND]);
}
}
LP_txbytes_update("bobrefund",rswap.bobcoin,rswap.txbytes[BASILISK_BOBREFUND],&rswap.txids[BASILISK_BOBREFUND],&rswap.depositspent,&rswap.sentflags[BASILISK_BOBREFUND]);
}

2
iguana/exchanges/LP_rpc.c

@ -735,7 +735,7 @@ char *LP_signrawtx(char *symbol,bits256 *signedtxidp,int32_t *completedp,cJSON *
printf("incomplete signing %s (%s)\n",rawtx,jprint(vins,0));
if ( signedtx != 0 )
free(signedtx), signedtx = 0;
} else printf("basilisk_swap_bobtxspend %s -> %s\n",rawtx,bits256_str(str,*signedtxidp));
} // else printf("basilisk_swap_bobtxspend %s -> %s\n",rawtx,bits256_str(str,*signedtxidp));
if ( signedtx == 0 )
{
retjson = cJSON_CreateObject();

18
iguana/exchanges/LP_signatures.c

@ -547,7 +547,7 @@ void LP_notify_pubkeys(void *ctx,int32_t pubsock)
} else printf("no LPipaddr\n");
}
jaddnum(reqjson,"session",G.LP_sessionid);
LP_reserved_msg(0,"","",zero,jprint(reqjson,1));
LP_reserved_msg(1,"","",zero,jprint(reqjson,1));
}
char *LP_notify_recv(cJSON *argjson)
@ -561,7 +561,7 @@ char *LP_notify_recv(cJSON *argjson)
if ( (ipaddr= jstr(argjson,"isLP")) != 0 )
{
//printf("notify got isLP %s %d\n",ipaddr,jint(argjson,"ismine"));
LP_peer_recv(ipaddr,jint(argjson,"ismine"));
LP_peer_recv(ipaddr,jint(argjson,"ismine"),pubp);
if ( IAMLP != 0 && G.LP_IAMLP == 0 && strcmp(ipaddr,LP_myipaddr) == 0 )
{
if ( bits256_cmp(pub,G.LP_mypub25519) != 0 )
@ -626,7 +626,7 @@ printf("LP_uitem_recv deprecated\n");
{
//char str[65]; printf("uitem %s %s %s/v%d %.8f ht.%d\n",symbol,coinaddr,bits256_str(str,txid),vout,dstr(value),height);
if ( strcmp(coin->smartaddr,coinaddr) != 0 )
LP_address_utxoadd((uint32_t)time(NULL),"LP_uitem_recv",coin,coinaddr,txid,vout,value,height,-1);
LP_address_utxoadd(0,(uint32_t)time(NULL),"LP_uitem_recv",coin,coinaddr,txid,vout,value,height,-1);
//else printf("ignore external uitem %s %s\n",symbol,coin->smartaddr);
}
return(clonestr("{\"result\":\"success\"}"));
@ -671,19 +671,13 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_
jadd(reqjson,"proof",LP_instantdex_txids(0,coin->smartaddr));
}
msg = jprint(reqjson,1);
printf("QUERY.(%s)\n",msg);
//printf("QUERY.(%s)\n",msg);
//if ( bits256_nonz(qp->srchash) == 0 || strcmp(method,"request") != 0 )
{
memset(&zero,0,sizeof(zero));
if ( bits256_nonz(qp->srchash) != 0 )
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->srchash,clonestr(msg));
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg));
//if ( strcmp(method,"request") == 0 )
if ( 0 )
{
sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg));
sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg));
}
free(msg);
/*portable_mutex_lock(&LP_reservedmutex);
if ( num_Reserved_msgs[1] < sizeof(Reserved_msgs[1])/sizeof(*Reserved_msgs[1])-2 )

6
iguana/exchanges/LP_socket.c

@ -303,7 +303,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep
else
{
//printf("external unspent has no gettxout\n");
flag += LP_address_utxoadd((uint32_t)time(NULL),"electrum process",coin,coinaddr,txid,v,value,0,1);
flag += LP_address_utxoadd(0,(uint32_t)time(NULL),"electrum process",coin,coinaddr,txid,v,value,0,1);
}
}
else
@ -348,7 +348,7 @@ int32_t electrum_process_array(struct iguana_info *coin,struct electrum_info *ep
if ( tx->height > 0 )
{
//printf("from electrum_process_array\n");
flag += LP_address_utxoadd((uint32_t)time(NULL),"electrum process2",coin,coinaddr,txid,v,value,tx->height,-1);
flag += LP_address_utxoadd(0,(uint32_t)time(NULL),"electrum process2",coin,coinaddr,txid,v,value,tx->height,-1);
}
//printf("v.%d numvouts.%d %.8f (%s)\n",v,tx->numvouts,dstr(tx->outpoints[jint(item,"tx_pos")].value),jprint(item,0));
} //else printf("cant find tx\n");
@ -551,7 +551,7 @@ cJSON *electrum_address_gethistory(char *symbol,struct electrum_info *ep,cJSON *
if ( tx->height > 0 && tx->height != height )
printf("update %s height.%d <- %d\n",bits256_str(str,txid),tx->height,height);
tx->height = height;
LP_address_utxoadd((uint32_t)time(NULL),"electrum history",coin,addr,txid,0,0,height,-1);
LP_address_utxoadd(0,(uint32_t)time(NULL),"electrum history",coin,addr,txid,0,0,height,-1);
}
}
}

2
iguana/exchanges/LP_statemachine.c

@ -2491,7 +2491,7 @@ void basilisk_swaploop(void *_utxo)
{
uint8_t *data; uint32_t expiration,savestatebits=0,saveotherbits=0; uint32_t channel; int32_t iters,retval=0,j,datalen,maxlen; struct basilisk_swap *swap; struct LP_utxoinfo *utxo = _utxo;
swap = utxo->swap;
fprintf(stderr,"start swap iambob.%d\n",swap->I.iambob);
//fprintf(stderr,"start swap iambob.%d\n",swap->I.iambob);
maxlen = 1024*1024 + sizeof(*swap);
data = malloc(maxlen);
expiration = (uint32_t)time(NULL) + 300;

8
iguana/exchanges/LP_stats.c

@ -471,7 +471,7 @@ int32_t LP_statslog_parsequote(char *method,cJSON *lineobj)
flag = 1;
break;
}
if ( counter++ < 10 )
if ( counter++ < 1 )
printf("error after delayed match\n");
}
}
@ -727,7 +727,7 @@ int32_t LP_stats_dispiter(cJSON *array,struct LP_swapstats *sp,uint32_t starttim
cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256 refpubkey,char *refbase,char *refrel)
{
static int32_t rval;
cJSON *retjson,*array,*item,*reqjson; struct LP_pubkey_info *pubp,*ptmp; bits256 zero; uint32_t now; struct LP_swapstats *sp,*tmp; int32_t i,n,numtrades[LP_MAXPRICEINFOS]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS];
cJSON *retjson,*array,*item; struct LP_pubkey_info *pubp,*ptmp; uint32_t now; struct LP_swapstats *sp,*tmp; int32_t i,n,numtrades[LP_MAXPRICEINFOS]; uint64_t basevols[LP_MAXPRICEINFOS],relvols[LP_MAXPRICEINFOS];
if ( rval == 0 )
rval = (LP_rand() % 300) + 60;
if ( starttime > endtime )
@ -754,14 +754,14 @@ cJSON *LP_statslog_disp(uint32_t starttime,uint32_t endtime,char *refgui,bits256
else
{
LP_RTcount++;
if ( now > sp->lasttime+rval )
/*if ( now > sp->lasttime+rval )
{
reqjson = cJSON_CreateObject();
jaddstr(reqjson,"method","gettradestatus");
jadd64bits(reqjson,"aliceid",sp->aliceid);
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(0,"","",zero,jprint(reqjson,1));
}
}*/
}
}
HASH_ITER(hh,LP_swapstats,sp,tmp)

19
iguana/exchanges/LP_swap.c

@ -479,7 +479,7 @@ int32_t LP_waitfor(int32_t pairsock,struct basilisk_swap *swap,int32_t timeout,i
} // else printf("error nn_recv\n");
}
}
printf("waitfor timedout\n");
printf("waitfor timedout aliceid.%llu requestid.%u quoteid.%u\n",(long long)swap->aliceid,swap->I.req.requestid,swap->I.req.quoteid);
return(retval);
}
@ -625,7 +625,7 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
if ( recvlen != datalen+rawtx->I.redeemlen+75 )
printf("RECVLEN %d != %d + %d\n",recvlen,datalen,rawtx->I.redeemlen);
txid = bits256_calctxid(coin->symbol,data,datalen);
char str[65]; printf("rawtx.%s txid %s\n",rawtx->name,bits256_str(str,txid));
//char str[65]; printf("rawtx.%s txid %s\n",rawtx->name,bits256_str(str,txid));
if ( bits256_cmp(txid,rawtx->I.actualtxid) != 0 && bits256_nonz(rawtx->I.actualtxid) == 0 )
rawtx->I.actualtxid = txid;
if ( (txobj= bitcoin_data2json(coin->symbol,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,height,&rawtx->I.signedtxid,&rawtx->msgtx,rawtx->extraspace,sizeof(rawtx->extraspace),data,datalen,0,suppress_pubkeys,coin->zcash)) != 0 )
@ -659,9 +659,8 @@ int32_t LP_rawtx_spendscript(struct basilisk_swap *swap,int32_t height,struct ba
retval = 0;
if ( rawtx == &swap->otherfee )
{
char str[65];
LP_swap_coinaddr(coin,rawtx->p2shaddr,0,data,datalen,0);
printf("got %s txid.%s (%s) -> %s\n",rawtx->name,bits256_str(str,rawtx->I.signedtxid),jprint(txobj,0),rawtx->p2shaddr);
//printf("got %s txid.%s (%s) -> %s\n",rawtx->name,bits256_str(str,rawtx->I.signedtxid),jprint(txobj,0),rawtx->p2shaddr);
} else bitcoin_address(coin->symbol,rawtx->p2shaddr,coin->taddr,coin->p2shtype,rawtx->spendscript,hexlen);
}
} else printf("%s satoshis %.8f ERROR.(%s) txfees.[%.8f %.8f: %.8f] amount.%.8f -> %.8f\n",rawtx->name,dstr(j64bits(vout,"satoshis")),jprint(txobj,0),dstr(swap->I.Atxfee),dstr(swap->I.Btxfee),dstr(txfee),dstr(rawtx->I.amount),dstr(rawtx->I.amount)-dstr(txfee));
@ -996,8 +995,8 @@ int32_t instantdex_pubkeyargs(struct basilisk_swap *swap,int32_t numpubs,bits256
}
n++;
}
if ( n > 2 || m > 2 )
printf("n.%d m.%d len.%d numpubs.%d\n",n,m,len,swap->I.numpubs);
//if ( n > 2 || m > 2 )
// printf("n.%d m.%d len.%d numpubs.%d\n",n,m,len,swap->I.numpubs);
return(n);
}
@ -1007,7 +1006,7 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx *
numconfirms = 0;
#endif
strcpy(rawtx->name,name);
printf("set coin.%s %s -> %s\n",coin->symbol,coin->smartaddr,name);
//printf("set coin.%s %s -> %s\n",coin->symbol,coin->smartaddr,name);
strcpy(rawtx->symbol,coin->symbol);
rawtx->I.numconfirms = numconfirms;
if ( (rawtx->I.amount= satoshis) < LP_MIN_TXFEE )
@ -1030,8 +1029,8 @@ void basilisk_rawtx_setparms(char *name,uint32_t quoteid,struct basilisk_rawtx *
if ( rawtx->I.vouttype <= 1 && rawtx->I.destaddr[0] != 0 )
{
rawtx->I.spendlen = bitcoin_standardspend(rawtx->spendscript,0,rawtx->I.rmd160);
printf("%s spendlen.%d %s <- %.8f\n",name,rawtx->I.spendlen,rawtx->I.destaddr,dstr(rawtx->I.amount));
} else printf("%s vouttype.%d destaddr.(%s)\n",name,rawtx->I.vouttype,rawtx->I.destaddr);
//printf("%s spendlen.%d %s <- %.8f\n",name,rawtx->I.spendlen,rawtx->I.destaddr,dstr(rawtx->I.amount));
} //else printf("%s vouttype.%d destaddr.(%s)\n",name,rawtx->I.vouttype,rawtx->I.destaddr);
}
struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256 pubkey25519,struct basilisk_swap *swap,int32_t optionduration,uint32_t statebits,struct LP_quoteinfo *qp,int32_t dynamictrust)
@ -1191,7 +1190,7 @@ struct basilisk_swap *bitcoin_swapinit(bits256 privkey,uint8_t *pubkey33,bits256
swap->myfee.utxotxid = qp->feetxid, swap->myfee.utxovout = qp->feevout;
LP_mark_spent(swap->I.alicestr,qp->feetxid,qp->feevout);
}
char str[65],str2[65],str3[65]; printf("IAMBOB.%d %s %s %s [%s %s]\n",swap->I.iambob,bits256_str(str,qp->txid),bits256_str(str2,qp->txid2),bits256_str(str3,qp->feetxid),swap->I.bobstr,swap->I.alicestr);
//char str[65],str2[65],str3[65]; printf("IAMBOB.%d %s %s %s [%s %s]\n",swap->I.iambob,bits256_str(str,qp->txid),bits256_str(str2,qp->txid2),bits256_str(str3,qp->feetxid),swap->I.bobstr,swap->I.alicestr);
return(swap);
}

89
iguana/exchanges/LP_transaction.c

@ -744,7 +744,7 @@ void test_validate(struct iguana_info *coin,char *signedtx)
char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,char *symbol,uint8_t wiftaddr,uint8_t taddr,uint8_t pubtype,uint8_t p2shtype,uint8_t isPoS,uint8_t wiftype,void *ctx,bits256 privkey,bits256 *privkey2p,uint8_t *redeemscript,int32_t redeemlen,uint8_t *userdata,int32_t userdatalen,bits256 utxotxid,int32_t utxovout,char *destaddr,uint8_t *pubkey33,int32_t finalseqid,uint32_t expiration,int64_t *destamountp,uint64_t satoshis,char *changeaddr,char *vinaddr,int32_t suppress_pubkeys,int32_t zcash)
{
char *rawtxbytes=0,*signedtx=0,str[65],tmpaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*obj,*vouts,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[8]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin;
char *rawtxbytes=0,*signedtx=0,tmpaddr[64],hexstr[999],wifstr[128],_destaddr[64]; uint8_t spendscript[512],addrtype,rmd160[20]; cJSON *txobj,*vins,*obj,*vouts,*item,*privkeys; int32_t completed,spendlen,n,ignore_cltverr=1; struct vin_info V[8]; uint32_t timestamp,locktime = 0,sequenceid = 0xffffffff * finalseqid; bits256 txid; uint64_t value=0,change = 0; struct iguana_msgtx msgtx; struct iguana_info *coin;
LP_mark_spent(symbol,utxotxid,utxovout);
*destamountp = 0;
memset(signedtxidp,0,sizeof(*signedtxidp));
@ -771,7 +771,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
} else printf("cant gettx\n");
if ( value == 0 )
{
printf("basilisk_swap_bobtxspend.%s %s utxo.(%s).v%d already spent or doesnt exist\n",name,symbol,bits256_str(str,utxotxid),utxovout);
//printf("basilisk_swap_bobtxspend.%s %s utxo.(%s).v%d already spent or doesnt exist\n",name,symbol,bits256_str(str,utxotxid),utxovout);
return(0);
}
#endif
@ -790,7 +790,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
else if ( value == satoshis && (double)txfee/value < 0.25 )
{
satoshis = value - txfee;
printf("txfee allocation from value %.8f identical to satoshis: %.8f txfee %.8f\n",dstr(value),dstr(satoshis),dstr(txfee));
//printf("txfee allocation from value %.8f identical to satoshis: %.8f txfee %.8f\n",dstr(value),dstr(satoshis),dstr(txfee));
}
else
{
@ -800,7 +800,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
}
if ( value > satoshis+txfee )
change = value - (satoshis + txfee);
printf("utxo %.8f, destamount %.8f change %.8f txfee %.8f\n",dstr(value),dstr(satoshis),dstr(change),dstr(txfee));
//printf("utxo %.8f, destamount %.8f change %.8f txfee %.8f\n",dstr(value),dstr(satoshis),dstr(change),dstr(txfee));
} else if ( value > txfee )
satoshis = value - txfee;
else
@ -904,7 +904,7 @@ char *basilisk_swap_bobtxspend(bits256 *signedtxidp,uint64_t txfee,char *name,ch
printf("incomplete signing suppress.%d %s (%s)\n",suppress_pubkeys,name,jprint(vins,0));
if ( signedtx != 0 )
free(signedtx), signedtx = 0;
} else printf("basilisk_swap_bobtxspend %s -> %s\n",name,bits256_str(str,*signedtxidp));
} // else printf("basilisk_swap_bobtxspend %s -> %s\n",name,bits256_str(str,*signedtxidp));
free(rawtxbytes);
} else printf("error making rawtx suppress.%d\n",suppress_pubkeys);
free_json(privkeys);
@ -1077,7 +1077,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_
if ( up == 0 )
{
value = LP_txvalue(0,coin->symbol,utxotxid,utxovout);
LP_address_utxoadd((uint32_t)time(NULL),"withdraw",coin,coin->smartaddr,utxotxid,utxovout,value,1,-1);
LP_address_utxoadd(0,(uint32_t)time(NULL),"withdraw",coin,coin->smartaddr,utxotxid,utxovout,value,1,-1);
//printf("added after not finding\n");
}
if ( (up= LP_address_utxofind(coin,coin->smartaddr,utxotxid,utxovout)) != 0 )
@ -1085,7 +1085,13 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_
else
{
printf("couldnt add address_utxo after not finding\n");
return(0);
sleep(1);
value = LP_txvalue(0,coin->symbol,utxotxid,utxovout);
LP_address_utxoadd(0,(uint32_t)time(NULL),"withdraw",coin,coin->smartaddr,utxotxid,utxovout,value,1,-1);
if ( (up= LP_address_utxofind(coin,coin->smartaddr,utxotxid,utxovout)) != 0 )
preselected[numpre++] = up;
else printf("second couldnt add address_utxo after not finding\n");
//return(0);
}
}
if ( dustcombine >= 1 && min0 != 0 && min0->U.value < LP_DUSTCOMBINE_THRESHOLD && (coin->electrum == 0 || min0->SPV > 0) )
@ -1211,6 +1217,9 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
else if ( coin->numutxos >= LP_MAXDESIRED_UTXOS )
dustcombine = 2;
else dustcombine = 1;
#ifdef LP_DISABLE_DISTCOMBINE
dustcombine = 0;
#endif
amount = txfee;
for (i=0; i<numvouts; i++)
{
@ -1228,7 +1237,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
return(0);
}
amount += value;
printf("vout.%d %.8f -> total %.8f\n",i,dstr(value),dstr(amount));
//printf("vout.%d %.8f -> total %.8f\n",i,dstr(value),dstr(amount));
}
else
{
@ -1271,7 +1280,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf
txobj = bitcoin_txcreate(coin->symbol,coin->isPoS,locktime,coin->txversion,timestamp);
jdelete(txobj,"vin");
jadd(txobj,"vin",jduplicate(vins));
printf("change %.8f = total %.8f - amount %.8f, adjust %.8f numvouts.%d\n",dstr(change),dstr(total),dstr(amount),dstr(adjust),numvouts);
//printf("change %.8f = total %.8f - amount %.8f, adjust %.8f numvouts.%d\n",dstr(change),dstr(total),dstr(amount),dstr(adjust),numvouts);
for (i=0; i<numvouts; i++)
{
item = jitem(outputs,i);
@ -1371,7 +1380,7 @@ char *LP_withdraw(struct iguana_info *coin,cJSON *argjson)
printf("incomplete signing withdraw (%s)\n",jprint(vins,0));
if ( signedtx != 0 )
free(signedtx), signedtx = 0;
} else printf("LP_withdraw.%s %s -> %s\n",coin->symbol,jprint(argjson,0),bits256_str(str,signedtxid));
} //else printf("LP_withdraw.%s %s -> %s\n",coin->symbol,jprint(argjson,0),bits256_str(str,signedtxid));
if ( signedtx == 0 )
break;
datalen = (int32_t)strlen(signedtx) / 2;
@ -1455,7 +1464,7 @@ int32_t basilisk_rawtx_gen(void *ctx,char *str,uint32_t swapstarted,uint8_t *pub
rawtx->I.completed = 1;
rawtx->I.signedtxid = jbits256(retjson,"txid");
retval = 0;
} else printf("rawtx withdraw error? (%s)\n",retstr);
} else printf("rawtx withdraw error? (%s)\n",jprint(argjson,0));
free_json(retjson);
}
free(retstr);
@ -1807,9 +1816,9 @@ int32_t basilisk_bobscript(uint8_t *rmd160,uint8_t *redeemscript,int32_t *redeem
{
calc_rmd160_sha256(rmd160,redeemscript,n);
n = bitcoin_p2shspend(script,0,rmd160);
int32_t i; for (i=0; i<n; i++)
printf("%02x",script[i]);
printf(" <- redeem.%d bobtx dflag.%d spendscript.[%d]\n",*redeemlenp,depositflag,n);
//int32_t i; for (i=0; i<n; i++)
// printf("%02x",script[i]);
//printf(" <- redeem.%d bobtx dflag.%d spendscript.[%d]\n",*redeemlenp,depositflag,n);
}
return(n);
}
@ -1842,7 +1851,7 @@ int32_t basilisk_swapuserdata(uint8_t *userdata,bits256 privkey,int32_t ifpath,b
int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay)
{
static bits256 zero;
uint8_t userdata[512]; int32_t retval,i,len = 0; struct iguana_info *coin;
uint8_t userdata[512]; int32_t retval,len = 0; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 )
{
//printf("basilisk_bobpayment_reclaim\n");
@ -1851,9 +1860,9 @@ int32_t basilisk_bobpayment_reclaim(struct basilisk_swap *swap,int32_t delay)
swap->I.userdata_bobreclaimlen = len;
if ( (retval= basilisk_rawtx_sign(coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,swap,&swap->bobreclaim,&swap->bobpayment,swap->I.myprivs[1],0,userdata,len,1,swap->changermd160,swap->bobpayment.I.destaddr,coin->zcash)) == 0 )
{
for (i=0; i<swap->bobreclaim.I.datalen; i++)
printf("%02x",swap->bobreclaim.txbytes[i]);
printf(" <- bobreclaim\n");
//for (i=0; i<swap->bobreclaim.I.datalen; i++)
// printf("%02x",swap->bobreclaim.txbytes[i]);
//printf(" <- bobreclaim\n");
//basilisk_txlog(swap,&swap->bobreclaim,delay);
return(retval);
}
@ -1903,7 +1912,7 @@ void LP_swap_coinaddr(struct iguana_info *coin,char *coinaddr,uint64_t *valuep,u
int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,int32_t genflag)
{
int32_t j; char coinaddr[64],checkaddr[64]; struct iguana_info *coin;
char coinaddr[64],checkaddr[64]; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.bobstr)) != 0 )
{
bitcoin_address(coin->symbol,coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20);
@ -1928,13 +1937,13 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i
}
else
{
for (j=0; j<swap->bobpayment.I.datalen; j++)
/*for (j=0; j<swap->bobpayment.I.datalen; j++)
printf("%02x",swap->bobpayment.txbytes[j]);
printf(" <- bobpayment.%d\n",swap->bobpayment.I.datalen);
for (j=0; j<swap->bobpayment.I.redeemlen; j++)
printf("%02x",swap->bobpayment.redeemscript[j]);
printf(" <- redeem.%d\n",swap->bobpayment.I.redeemlen);
printf(" <- GENERATED BOB PAYMENT.%d destaddr.(%s)\n",swap->bobpayment.I.datalen,swap->bobpayment.I.destaddr);
printf(" <- GENERATED BOB PAYMENT.%d destaddr.(%s)\n",swap->bobpayment.I.datalen,swap->bobpayment.I.destaddr);*/
LP_swap_coinaddr(coin,checkaddr,0,swap->bobpayment.txbytes,swap->bobpayment.I.datalen,0);
if ( strcmp(swap->bobpayment.I.destaddr,checkaddr) != 0 )
{
@ -1965,9 +1974,9 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i
}
else
{
for (j=0; j<swap->bobdeposit.I.datalen; j++)
printf("%02x",swap->bobdeposit.txbytes[j]);
printf(" <- GENERATED BOB DEPOSIT.%d (%s)\n",swap->bobdeposit.I.datalen,swap->bobdeposit.I.destaddr);
//for (j=0; j<swap->bobdeposit.I.datalen; j++)
// printf("%02x",swap->bobdeposit.txbytes[j]);
//printf(" <- GENERATED BOB DEPOSIT.%d (%s)\n",swap->bobdeposit.I.datalen,swap->bobdeposit.I.destaddr);
LP_swap_coinaddr(coin,checkaddr,0,swap->bobdeposit.txbytes,swap->bobdeposit.I.datalen,0);
if ( strcmp(swap->bobdeposit.I.destaddr,checkaddr) != 0 )
{
@ -1975,7 +1984,7 @@ int32_t basilisk_bobscripts_set(struct basilisk_swap *swap,int32_t depositflag,i
return(-1);
}
LP_unspents_mark(coin->symbol,swap->bobdeposit.vins);
printf("bobscripts set completed\n");
//printf("bobscripts set completed\n");
return(0);
}
}
@ -2028,7 +2037,7 @@ void basilisk_alicepayment(struct basilisk_swap *swap,struct iguana_info *coin,s
int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *data,int32_t maxlen)
{
char coinaddr[64]; int32_t i,retval = -1; struct iguana_info *coin;
char coinaddr[64]; int32_t retval = -1; struct iguana_info *coin;
if ( (coin= LP_coinfind(swap->I.alicestr)) != 0 )
{
if ( swap->alicepayment.I.datalen == 0 )
@ -2041,26 +2050,26 @@ int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *d
//LP_importaddress(coin->symbol,swap->alicepayment.I.destaddr);
strcpy(swap->alicepayment.p2shaddr,swap->alicepayment.I.destaddr);
retval = 0;
for (i=0; i<swap->alicepayment.I.datalen; i++)
printf("%02x",swap->alicepayment.txbytes[i]);
printf(" ALICE PAYMENT created.(%s)\n",swap->alicepayment.I.destaddr);
//for (i=0; i<swap->alicepayment.I.datalen; i++)
// printf("%02x",swap->alicepayment.txbytes[i]);
//printf(" ALICE PAYMENT created.(%s)\n",swap->alicepayment.I.destaddr);
LP_unspents_mark(coin->symbol,swap->alicepayment.vins);
//LP_importaddress(coin->symbol,swap->alicepayment.I.destaddr);
//basilisk_txlog(swap,&swap->alicepayment,-1);
}
if ( swap->myfee.I.datalen == 0 )
{
printf("%s generate fee %.8f from.%s\n",coin->symbol,dstr(strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee),coin->smartaddr);
//printf("%s generate fee %.8f from.%s\n",coin->symbol,dstr(strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee),coin->smartaddr);
bitcoin_address(coin->symbol,coinaddr,coin->taddr,coin->pubtype,swap->changermd160,20);
if ( basilisk_rawtx_gen(swap->ctx,"myfee",swap->I.started,swap->persistent_pubkey33,swap->I.iambob,1,&swap->myfee,swap->myfee.I.locktime,swap->myfee.spendscript,swap->myfee.I.spendlen,strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee,1,0,swap->persistent_privkey,swap->changermd160,coinaddr) == 0 )
{
printf("rawtxsend %s %.8f\n",coin->symbol,dstr(strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee));
//printf("rawtxsend %s %.8f\n",coin->symbol,dstr(strcmp(coin->symbol,"BTC") == 0 ? LP_MIN_TXFEE : coin->txfee));
swap->I.statebits |= LP_swapdata_rawtxsend(pairsock,swap,0x80,data,maxlen,&swap->myfee,0x40,0);
LP_unspents_mark(swap->I.iambob!=0?coin->symbol:coin->symbol,swap->myfee.vins);
//basilisk_txlog(swap,&swap->myfee,-1);
for (i=0; i<swap->myfee.I.datalen; i++)
printf("%02x",swap->myfee.txbytes[i]);
printf(" <- fee state.%x\n",swap->I.statebits);
//for (i=0; i<swap->myfee.I.datalen; i++)
// printf("%02x",swap->myfee.txbytes[i]);
//printf(" <- fee state.%x\n",swap->I.statebits);
swap->I.statebits |= 0x40;
}
else
@ -2071,7 +2080,7 @@ int32_t basilisk_alicetxs(int32_t pairsock,struct basilisk_swap *swap,uint8_t *d
}
if ( swap->alicepayment.I.datalen != 0 && swap->alicepayment.I.spendlen > 0 && swap->myfee.I.datalen != 0 && swap->myfee.I.spendlen > 0 )
{
printf("fee sent\n");
//printf("fee sent\n");
return(0);
}
} else printf("basilisk alicetx cant find (%s)\n",swap->I.alicestr);
@ -2085,14 +2094,16 @@ int32_t LP_verify_otherfee(struct basilisk_swap *swap,uint8_t *data,int32_t data
{
if ( LP_rawtx_spendscript(swap,coin->longestchain,&swap->otherfee,0,data,datalen,0) == 0 )
{
printf("otherfee amount %.8f -> %s vs %s locktime %u vs %u\n",dstr(swap->otherfee.I.amount),swap->otherfee.p2shaddr,swap->otherfee.I.destaddr,swap->otherfee.I.locktime,swap->I.started+1);
//printf("otherfee amount %.8f -> %s vs %s locktime %u vs %u\n",dstr(swap->otherfee.I.amount),swap->otherfee.p2shaddr,swap->otherfee.I.destaddr,swap->otherfee.I.locktime,swap->I.started+1);
if ( strcmp(swap->otherfee.I.destaddr,swap->otherfee.p2shaddr) == 0 )
{
diff = swap->otherfee.I.locktime - (swap->I.started+1);
if ( diff < 0 )
diff = -diff;
if ( diff < LP_AUTOTRADE_TIMEOUT )
printf("dexfee verified\n");
{
//printf("dexfee verified\n");
}
else printf("locktime mismatch in otherfee, reject %u vs %u\n",swap->otherfee.I.locktime,swap->I.started+1);
return(0);
} else printf("destaddress mismatch in other fee, reject (%s) vs (%s)\n",swap->otherfee.I.destaddr,swap->otherfee.p2shaddr);
@ -2159,12 +2170,12 @@ int32_t LP_verify_bobdeposit(struct basilisk_swap *swap,uint8_t *data,int32_t da
retval = 0;
if ( (retval= basilisk_rawtx_sign(coin->symbol,coin->wiftaddr,coin->taddr,coin->pubtype,coin->p2shtype,coin->isPoS,coin->wiftype,swap,&swap->aliceclaim,&swap->bobdeposit,swap->I.myprivs[0],0,userdata,len,1,swap->changermd160,swap->bobdeposit.I.destaddr,coin->zcash)) == 0 )
{
int32_t i; for (i=0; i<swap->bobdeposit.I.datalen; i++)
/*int32_t i; for (i=0; i<swap->bobdeposit.I.datalen; i++)
printf("%02x",swap->bobdeposit.txbytes[i]);
printf(" <- bobdeposit\n");
for (i=0; i<swap->aliceclaim.I.datalen; i++)
printf("%02x",swap->aliceclaim.txbytes[i]);
printf(" <- aliceclaim\n");
printf(" <- aliceclaim\n");*/
//basilisk_txlog(swap,&swap->aliceclaim,swap->I.putduration+swap->I.callduration);
return(LP_waitmempool(coin->symbol,swap->bobdeposit.I.destaddr,swap->bobdeposit.I.signedtxid,0,60));
} else printf("error signing aliceclaim suppress.%d vin.(%s)\n",swap->aliceclaim.I.suppress_pubkeys,swap->bobdeposit.I.destaddr);

72
iguana/exchanges/LP_utxo.c

@ -381,7 +381,7 @@ void LP_mark_spent(char *symbol,bits256 txid,int32_t vout)
}
}
int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight)
int32_t LP_address_utxoadd(int32_t skipsearch,uint32_t timestamp,char *debug,struct iguana_info *coin,char *coinaddr,bits256 txid,int32_t vout,uint64_t value,int32_t height,int32_t spendheight)
{
struct LP_address *ap; cJSON *txobj; struct LP_transaction *tx; struct LP_address_utxo *up,*tmp; int32_t flag,retval = 0; //char str[65];
if ( coin == 0 )
@ -393,20 +393,23 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co
if ( ap != 0 )
{
flag = 0;
DL_FOREACH_SAFE(ap->utxos,up,tmp)
if ( skipsearch == 0 )
{
if ( vout == up->U.vout && bits256_cmp(up->U.txid,txid) == 0 )
DL_FOREACH_SAFE(ap->utxos,up,tmp)
{
flag = 1;
if ( height > 0 && up->U.height != height )
up->U.height = height, flag |= 2;
if ( spendheight > 0 && up->spendheight != spendheight )
up->spendheight = spendheight, flag |= 4;
if ( value != 0 && up->U.value == 0 && up->U.value != value )
up->U.value = value, flag |= 8;
//up->timestamp = timestamp;
//char str[65]; printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value));
break;
if ( vout == up->U.vout && bits256_cmp(up->U.txid,txid) == 0 )
{
flag = 1;
if ( height > 0 && up->U.height != height )
up->U.height = height, flag |= 2;
if ( spendheight > 0 && up->spendheight != spendheight )
up->spendheight = spendheight, flag |= 4;
if ( value != 0 && up->U.value == 0 && up->U.value != value )
up->U.value = value, flag |= 8;
//up->timestamp = timestamp;
//char str[65]; printf("found >>>>>>>>>> %s %s %s/v%d ht.%d %.8f\n",coin->symbol,coinaddr,bits256_str(str,txid),vout,height,dstr(value));
break;
}
}
}
if ( flag == 0 && value != 0 )
@ -447,7 +450,6 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
{
struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t i,n,m,vout,height; cJSON *array,*item,*txobj; bits256 zero; int64_t value; bits256 txid; uint32_t now;
LP_address(coin,coin->smartaddr);
//printf("call listunspent issue %s (%s)\n",coin->symbol,coin->smartaddr);
memset(zero.bytes,0,sizeof(zero));
LP_listunspent_issue(coin->symbol,coin->smartaddr,2,zero,zero);
if ( (ap= LP_addressfind(coin,coin->smartaddr)) == 0 )
@ -455,18 +457,23 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
printf("LP_address_utxo_reset: cant find address data\n");
return(0);
}
if ( IAMLP != 0 && time(NULL) < coin->lastresetutxo+10 )
return(ap);
coin->lastresetutxo = (uint32_t)time(NULL);
portable_mutex_lock(&coin->addressutxo_mutex);
if ( (array= LP_listunspent(coin->symbol,coin->smartaddr,zero,zero)) != 0 )
{
printf("reset %s ap->utxos\n",coin->symbol);
portable_mutex_lock(&coin->addrmutex);
portable_mutex_lock(&LP_gcmutex);
DL_FOREACH_SAFE(ap->utxos,up,tmp)
{
portable_mutex_lock(&coin->addrmutex);
DL_DELETE(ap->utxos,up);
portable_mutex_unlock(&coin->addrmutex);
portable_mutex_lock(&LP_gcmutex);
up->spendheight = (int32_t)time(NULL);
DL_APPEND(LP_garbage_collector2,up);
portable_mutex_unlock(&LP_gcmutex);
}
portable_mutex_unlock(&coin->addrmutex);
portable_mutex_unlock(&LP_gcmutex);
now = (uint32_t)time(NULL);
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
@ -476,12 +483,15 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
//{"tx_hash":"38d1b7c73015e1b1d6cb7fc314cae402a635b7d7ea294970ab857df8777a66f4","tx_pos":0,"height":577975,"value":238700}
item = jitem(array,i);
value = LP_listunspent_parseitem(coin,&txid,&vout,&height,item);
if ( (txobj= LP_gettxout(coin->symbol,coin->smartaddr,txid,vout)) == 0 )
continue;
else free_json(txobj);
if ( LP_numconfirms(coin->symbol,coin->smartaddr,txid,vout,0) <= 0 )
continue;
LP_address_utxoadd(now,"withdraw",coin,coin->smartaddr,txid,vout,value,height,-1);
if ( 1 )
{
if ( (txobj= LP_gettxout(coin->symbol,coin->smartaddr,txid,vout)) == 0 )
continue;
else free_json(txobj);
if ( LP_numconfirms(coin->symbol,coin->smartaddr,txid,vout,0) <= 0 )
continue;
}
LP_address_utxoadd(1,now,"withdraw",coin,coin->smartaddr,txid,vout,value,height,-1);
if ( (up= LP_address_utxofind(coin,coin->smartaddr,txid,vout)) == 0 )
printf("couldnt find just added %s/%d ht.%d %.8f\n",bits256_str(str,txid),vout,height,dstr(value));
else
@ -490,10 +500,11 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
//printf("%.8f ",dstr(value));
}
}
//printf("added %d from listunspents\n",m);
printf("added %d from %s listunspents\n",m,coin->symbol);
}
free_json(array);
}
portable_mutex_unlock(&coin->addressutxo_mutex);
return(ap);
}
@ -545,9 +556,10 @@ cJSON *LP_address_utxos(struct iguana_info *coin,char *coinaddr,int32_t electrum
}
if ( up->spendheight <= 0 && up->U.value != 0 )
{
char str[65];
if ( LP_allocated(up->U.txid,up->U.vout) != 0 )
printf("%s %s/v%d allocated\n",coin->symbol,bits256_str(str,up->U.txid),up->U.vout);
{
//printf("%s %s/v%d allocated\n",coin->symbol,bits256_str(str,up->U.txid),up->U.vout);
}
else if ( coin->electrum == 0 || up->SPV > 0 )
{
jaddi(array,LP_address_item(coin,up,electrumret));
@ -728,7 +740,7 @@ int32_t LP_unspents_array(struct iguana_info *coin,char *coinaddr,cJSON *array)
if ( errs == 0 )
{
//printf("from LP_unspents_array\n");
LP_address_utxoadd((uint32_t)time(NULL),"LP_unspents_array",coin,coinaddr,txid,v,val,height,-1);
LP_address_utxoadd(0,(uint32_t)time(NULL),"LP_unspents_array",coin,coinaddr,txid,v,val,height,-1);
count++;
}
}
@ -792,7 +804,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS
tx->outpoints[i].interest = SATOSHIDEN * jdouble(vout,"interest");
LP_destaddr(tx->outpoints[i].coinaddr,vout);
//printf("from transaction init %s %s %s/v%d <- %.8f\n",coin->symbol,tx->outpoints[i].coinaddr,bits256_str(str,txid),i,dstr(tx->outpoints[i].value));
LP_address_utxoadd((uint32_t)time(NULL),"LP_transactioninit iter0",coin,tx->outpoints[i].coinaddr,txid,i,tx->outpoints[i].value,height,-1);
LP_address_utxoadd(0,(uint32_t)time(NULL),"LP_transactioninit iter0",coin,tx->outpoints[i].coinaddr,txid,i,tx->outpoints[i].value,height,-1);
}
//printf("numvouts.%d\n",numvouts);
}
@ -814,7 +826,7 @@ cJSON *LP_transactioninit(struct iguana_info *coin,bits256 txid,int32_t iter,cJS
tx->outpoints[spentvout].spendtxid = txid;
tx->outpoints[spentvout].spendvini = i;
tx->outpoints[spentvout].spendheight = height > 0 ? height : 1;
LP_address_utxoadd((uint32_t)time(NULL),"LP_transactioninit iter1",coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1);
LP_address_utxoadd(0,(uint32_t)time(NULL),"LP_transactioninit iter1",coin,tx->outpoints[spentvout].coinaddr,spenttxid,spentvout,tx->outpoints[spentvout].value,-1,height>0?height:1);
if ( 0 && strcmp(coin->symbol,"REVS") == 0 )
printf("spend %s %s/v%d at ht.%d\n",coin->symbol,bits256_str(str,tx->txid),spentvout,height);
}

2
iguana/exchanges/beertest

@ -0,0 +1,2 @@
source userpass
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BEER\",\"rel\":\"KMD\",\"fixed\":1.28700,\"margin\":0.00001}"

2
iguana/exchanges/coins

File diff suppressed because one or more lines are too long

69
iguana/exchanges/mm.c

@ -190,6 +190,75 @@ int main(int argc, const char * argv[])
printf("done vanitygen.(%s) done %u elapsed %d\n",argv[2],(uint32_t)time(NULL),(uint32_t)time(NULL) - timestamp);
exit(0);
}
else if ( argv[1] != 0 && strcmp(argv[1],"airdropH") == 0 && argv[2] != 0 )
{
FILE *fp; double val,total = 0.; uint8_t checktype,addrtype,rmd160[21],checkrmd160[21]; char buf[256],checkaddr[64],coinaddr[64],manystrs[64][128],cmd[64*128]; int32_t n,i,num; char *flag;
if ( (fp= fopen(argv[2],"rb")) != 0 )
{
num = 0;
while ( fgets(buf,sizeof(buf),fp) > 0 )
{
if ( (n= (int32_t)strlen(buf)) > 0 )
buf[--n] = 0;
flag = 0;
for (i=0; i<n; i++)
{
if ( buf[i] == ',' )
{
buf[i] = 0;
flag = &buf[i+1];
break;
}
}
if ( flag != 0 )
{
bitcoin_addr2rmd160("HUSH",28,&addrtype,rmd160,buf);
bitcoin_address("KMD",coinaddr,0,addrtype == 184 ? 60 : 85,rmd160,20);
bitcoin_addr2rmd160("KMD",0,&checktype,checkrmd160,coinaddr);
bitcoin_address("HUSH",checkaddr,28,checktype == 60 ? 184 : 189,checkrmd160,20);
if ( memcmp(rmd160,checkrmd160,20) != 0 || strcmp(buf,checkaddr) != 0 )
{
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
printf(" vs. ");
for (i=0; i<20; i++)
printf("%02x",checkrmd160[i]);
printf(" address calc error (%s).%d -> (%s).%d -> (%s) %.8f?\n",buf,addrtype,coinaddr,checktype,checkaddr,atof(flag));
}
else
{
val = atof(flag);
sprintf(manystrs[num++],"\\\"%s\\\":%0.8f",coinaddr,val);
if ( num >= sizeof(manystrs)/sizeof(*manystrs) )
{
sprintf(cmd,"fiat/btch sendmany \\\"\\\" \"{");
for (i=0; i<num; i++)
sprintf(cmd + strlen(cmd),"%s%s",manystrs[i],i<num-1?",":"");
strcat(cmd,"}\" 0");
printf("%s\n",cmd);
num = 0;
memset(manystrs,0,sizeof(manystrs));
}
total += val;
//printf("(%s).%d (%s) <- %.8f total %.8f\n",buf,addrtype,coinaddr,val,total);
}
} else printf("parse error for (%s)\n",buf);
}
if ( num > 0 )
{
sprintf(cmd,"fiat/btch sendmany \\\"\\\" \"{");
for (i=0; i<num; i++)
sprintf(cmd + strlen(cmd),"%s%s",manystrs[i],i<num-1?",":"");
strcat(cmd,"}\" 0");
printf("%s\n",cmd);
num = 0;
memset(manystrs,0,sizeof(manystrs));
}
printf("close (%s) total %.8f\n",argv[2],total);
fclose(fp);
} else printf("couldnt open (%s)\n",argv[2]);
exit(0);
}
sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/SWAPS",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/PRICES",GLOBAL_DBDIR), OS_ensure_directory(dirname);

4
iguana/exchanges/prices/autoprice

@ -9,8 +9,8 @@ curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"MNZ\",\"offset\":0.0,\"refbase\":\"KMD\",\"refrel\":\"BTC\",\"factor\":15000,\"margin\":-0.2}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"HUSH\",\"rel\":\"KMD\",\"margin\":$margin,\"refbase\":\"hush\",\"refrel\":\"coinmarketcap\"}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTCH\",\"offset\":0.0,\"refbase\":\"KMD\",\"refrel\":\"HUSH\",\"factor\":1.44,\"buymargin\":0.05,\"sellmargin\":0.05}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BTCH\",\"rel\":\"KMD\",\"offset\":0.0,\"refbase\":\"HUSH\",\"refrel\":\"KMD\",\"factor\":0.7,\"buymargin\":0.05,\"sellmargin\":0.05}"
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"KMD\",\"rel\":\"BTCH\",\"offset\":0.0,\"refbase\":\"KMD\",\"refrel\":\"HUSH\",\"factor\":1.44,\"buymargin\":0.05,\"sellmargin\":0.05}"
#curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BTCH\",\"rel\":\"KMD\",\"offset\":0.0,\"refbase\":\"HUSH\",\"refrel\":\"KMD\",\"factor\":0.7,\"buymargin\":0.05,\"sellmargin\":0.05}"
curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"autoprice\",\"base\":\"BEER\",\"rel\":\"PIZZA\",\"fixed\":0.0001,\"margin\":0.00001}"

4
iguana/exchanges/reset_mutex

@ -0,0 +1,4 @@
#!/bin/sh
strace -f -o $HOME/strace.out -p `pidof marketmaker` &
sleep 2
killall strace

48
iguana/exchanges/stats.c

@ -29,6 +29,7 @@
#define STATS_DEST "/var/www/html/DEXstats.json"
#include "DEXstats.h"
char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port);
void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats_JSONonly);
extern uint32_t DOCKERFLAG;
char *stats_validmethods[] =
@ -223,7 +224,7 @@ int32_t iguana_socket(int32_t bindflag,char *hostname,uint16_t port)
return(-1);
}
}
if ( listen(sock,4096) != 0 )
if ( listen(sock,512) != 0 )
{
printf("listen(%s) port.%d failed: %s sock.%d. errno.%d\n",hostname,port,strerror(errno),sock,errno);
if ( sock >= 0 )
@ -333,7 +334,7 @@ extern void *bitcoin_ctx();
char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port)
{
static void *ctx;
cJSON *tokens,*argjson,*origargjson,*tmpjson=0,*json = 0; long filesize; char *myipaddr="127.0.0.1",symbol[64],buf[4096],*userpass=0,urlmethod[16],*data,url[8192],furl[8192],*retstr=0,*filestr,*token = 0; int32_t i,j,n,num=0;
cJSON *tokens,*argjson,*origargjson,*tmpjson=0,*json = 0; long filesize; char symbol[64],buf[4096],*userpass=0,urlmethod[16],*data,url[8192],furl[8192],*retstr=0,*filestr,*token = 0; int32_t i,j,n,num=0;
if ( ctx == 0 )
ctx = bitcoin_ctx();
for (i=0; i<sizeof(urlmethod)-1&&urlstr[i]!=0&&urlstr[i]!=' '; i++)
@ -523,7 +524,12 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
#ifdef FROM_MARKETMAKER
if ( strcmp(remoteaddr,"127.0.0.1") == 0 || LP_valid_remotemethod(argjson) > 0 )
{
if ( (retstr= stats_JSON(ctx,myipaddr,-1,argjson,remoteaddr,port)) != 0 )
//buf = jprint(argjson,0);
//LP_queuecommand(&retstr,buf,-1,1);
//free(buf);
//while ( retstr == 0 )
// usleep(10000);
if ( (retstr= stats_JSON(ctx,"127.0.0.1",-1,argjson,remoteaddr,port)) != 0 )
{
if ( (retitem= cJSON_Parse(retstr)) != 0 )
jaddi(retarray,retitem);
@ -531,6 +537,11 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
}
} else retstr = clonestr("{\"error\":\"invalid remote method\"}");
#else
//buf = jprint(argjson,0);
//LP_queuecommand(&retstr,buf,-1,1);
//free(buf);
//while ( retstr == 0 )
// usleep(10000);
if ( (retstr= stats_JSON(ctx,myipaddr,-1,argjson,remoteaddr,port)) != 0 )
{
if ( (retitem= cJSON_Parse(retstr)) != 0 )
@ -545,7 +556,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
}
else
{
cJSON *arg;
cJSON *arg; //char *buf;
if ( jstr(argjson,"agent") != 0 && strcmp(jstr(argjson,"agent"),"bitcoinrpc") != 0 && jobj(argjson,"params") != 0 )
{
arg = jobj(argjson,"params");
@ -557,9 +568,20 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
jaddstr(arg,"userpass",userpass);
#ifdef FROM_MARKETMAKER
if ( strcmp(remoteaddr,"127.0.0.1") == 0 || LP_valid_remotemethod(arg) > 0 )
retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port);
else retstr = clonestr("{\"error\":\"invalid remote method\"}");
{
//buf = jprint(arg,0);
//LP_queuecommand(&retstr,buf,-1,1);
//free(buf);
//while ( retstr == 0 )
// usleep(10000);
retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port);
} else retstr = clonestr("{\"error\":\"invalid remote method\"}");
#else
//buf = jprint(arg,0);
//LP_queuecommand(&retstr,buf,-1,1);
//free(buf);
//while ( retstr == 0 )
// usleep(10000);
retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port);
#endif
}
@ -568,6 +590,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po
free_json(json);
if ( tmpjson != 0 )
free(tmpjson);
//printf("stats_JSON rpc return.(%s)\n",retstr);
return(retstr);
}
free_json(argjson);
@ -778,7 +801,7 @@ extern int32_t IAMLP,LP_STOP_RECEIVED;
void stats_rpcloop(void *args)
{
uint16_t port; int32_t retval,sock=-1,bindsock=-1; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits; struct rpcrequest_info *req,*req2,*rtmp;
uint16_t port; int32_t retval,sock=-1,bindsock=-1; socklen_t clilen; struct sockaddr_in cli_addr; uint32_t ipbits,localhostbits; struct rpcrequest_info *req;
if ( (port= *(uint16_t *)args) == 0 )
port = 7779;
printf("Start stats_rpcloop.%u\n",port);
@ -834,14 +857,13 @@ void stats_rpcloop(void *args)
req->ipbits = ipbits;
req->port = port;
LP_rpc_processreq(req);
continue;
// this leads to cant open file errors
continue;
// this might lead to "cant open file errors"
if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 )
{
printf("error launching rpc handler on port %d, retval.%d\n",port,retval);
closesocket(sock);
sock = -1;
portable_mutex_lock(&LP_gcmutex);
LP_rpc_processreq(req);
/*portable_mutex_lock(&LP_gcmutex);
DL_FOREACH_SAFE(LP_garbage_collector,req2,rtmp)
{
DL_DELETE(LP_garbage_collector,req2);
@ -852,7 +874,7 @@ continue;
{
printf("error2 launching rpc handler on port %d, retval.%d\n",port,retval);
LP_rpc_processreq(req);
}
}*/
}
}
printf("i got killed\n");

BIN
iguana/pthreadvc2.dll

Binary file not shown.

BIN
pthreadVC2.lib

Binary file not shown.

BIN
pthreadvc2.dll

Binary file not shown.
Loading…
Cancel
Save