Compare commits

...

708 commits

Author SHA1 Message Date
Nathaniel
8b50451373
Add support for auxiliary serialization data
To supplement the new custom serialization feature, we also would like
the ability to use standard reflection-based serialization, but also to
add some extra data in on the side. This is now possible as auxiliary
serialized data. A class can define auxiliary data serializers which will
add additional data to the serialized record generated by the usual
reflection-based serializers.
2022-03-16 20:41:15 -05:00
Nathaniel
ac40f449f8
Cleanup and organization
Delete a useless and unused overload of raw::unpack

Also, make the new custom serialization bit work for unreflected types
(they still need typename reflection)
2022-03-16 18:59:36 -05:00
Nathaniel
907dc57fb6
Enable classes to customize their serialization
Add support for classes to define members to customize their
serialization from the default from reflection.
2022-03-16 15:47:17 -05:00
Nathaniel
23fd3a3a41
Adjust tcp_socket allocation 2022-03-16 13:17:32 -05:00
serkixenos
bff16bbc3d Merge branch 'latest-fc' into 'dapp-support'
# Conflicts:
#   src/crypto/openssl.cpp
2022-02-11 20:02:33 +00:00
serkixenos
86b77c6eb4 Merge branch 'bug/issue34' into 'latest-fc'
Remove OpenSSL related build warnings

See merge request PBSA/tools-libs/peerplays-fc!23
2022-02-10 19:16:44 +00:00
Pavel Baykov
8363f00715 Remove OpenSSL related build warnings 2022-02-10 19:16:44 +00:00
Nathaniel
b674c0f241
Add GitLab CI config from latest-fc 2022-02-08 17:42:19 -06:00
Nathaniel Hourt
a17b231acf
Merge pull request #1 from MichelSantos/dapp-support
Merge with latest-fc
2021-11-12 17:25:30 -06:00
Michel Santos
9ed3f6e338 Merge branch latest-fc into dapp-support 2021-11-11 15:19:50 -05:00
Nathaniel Hourt
21418ec46e
Compiler incompatibility
It broke again so poke it again. Perhaps all clang versions require `template` here? I'm not sure, haven't gotten around to testing all the different compilers on it yet.
2021-09-21 12:36:07 -05:00
Nathan Hourt
0248e20531
Add option to compile dynamic libraries
Also, fix build:
Clang 10.0.1 has incompatible rules with other compilers on whether
you must/cannot put the `template` keyword in part of the reflection
code. Add a special case to make it work all around.
2021-03-13 09:14:01 -06:00
serkixenos
4888839219
Merge pull request #17 from peerplays-network/fc/cleaner-build-log
Remove as much warnings from build log as possible
2021-01-27 13:33:51 +01:00
Nathan Hourt
472ff6bf40
Restore pre-merge websocketpp
This is just a rote copy of vendor/websocketpp from two commits
ago, ie 0e9259486c
2020-12-02 11:34:54 -06:00
Nathan Hourt
74b0201049
Merge remote-tracking branch 'ppu/latest-fc' into bts-updates 2020-12-02 10:24:46 -06:00
serkixenos
29d2f72b24 Remove as much warnings from build log as possible 2020-10-29 21:47:30 +01:00
Bobinson K B
0e9259486c Merge branch 'feature/static_variant_update' into 'latest-fc'
static variant update

See merge request PBSA/PeerplaysIO/tools-libs/peerplays-fc!19
2020-10-27 17:33:25 +00:00
Bobinson K B
d8429b8376 Merge branch 'feature/rl-editline' into 'latest-fc'
Feature/readline-editline

See merge request PBSA/PeerplaysIO/tools-libs/peerplays-fc!20
2020-10-27 17:33:01 +00:00
blockc p
5e5c6c91df Feature/readline-editline 2020-10-27 17:32:59 +00:00
pravin-battu
3f4a4468e0 static variant update 2020-10-16 12:12:57 -03:00
Nathan Hourt
2f89e0812a
Use signed_int to serialize enums 2020-09-17 21:11:28 -05:00
Nathan Hourt
747567fbdc
Revert "Removed signed_int"
This reverts commit 1dcacbafc9.
2020-09-17 12:26:06 -05:00
Nathan Hourt
69ebbf4ba4
Link boost.serialization 2020-08-21 14:45:42 -05:00
Nathan Hourt
5b3eb3a355
websocket_server default empty XFF header
For some reason, the websocket_server types have been altered to require
an X-Forwarded-For header (???) which seems utterly unnecessary. AFAICT,
it's safe to just leave it empty (BitShares does), so add a default arg
to make it do so by default.
2020-08-21 11:47:14 -05:00
Nathan Hourt
4accfdd951
Fix warnings 2020-08-21 11:42:57 -05:00
Eric Frias
fde60bdbbc
Add a fc_[diwe]dump() function, analogous to fc_[diew]log() 2020-08-20 11:31:00 -05:00
Nathan Hourt
7bf5340a74
Add hash_ctr_rng.hpp
This file was originally added in ff099209b6
2020-08-20 10:52:08 -05:00
Bobinson K B
fb27454cdf Merge branch 'ws-fc-updates' into 'latest-fc'
ws-updates

See merge request PBSA/PeerplaysIO/tools-libs/peerplays-fc!18
2020-08-12 13:00:39 +00:00
blockc p
917e4d348b ws-updates 2020-08-12 13:00:39 +00:00
Bobinson K B
8dd2fbe1b6 Merge branch 'issue-13-fix-websocket' into 'latest-fc'
Issue-13-fix (websocket shutdown)

See merge request PBSA/PeerplaysIO/tools-libs/peerplays-fc!17
2020-08-11 14:53:56 +00:00
Roshan Syed
b99585ca69 Added .gitlab-ci.yml 2020-07-09 13:11:09 +00:00
pravin-battu
c1e362a8dd websocket issue 2020-07-05 22:23:29 -03:00
blockc p
13b7cfaec7 Revert "websocket fix, issue 13"
This reverts commit 0cf6f461b6
2020-07-02 17:07:12 +00:00
pravin-battu
0cf6f461b6 websocket fix, issue 13 2020-07-02 13:34:29 -03:00
Abit
9e14f238f7
Merge pull request #206 from bitshares/github-auto-build
Add macOS to Github Autobuild
2020-07-02 17:04:17 +02:00
abitmore
4ffc77f9d6 Update boost version checks in time_test to macros 2020-07-02 09:18:11 -04:00
abitmore
82e3944ff2 Update time_test to get around a boost 1.60 issue 2020-07-02 08:47:45 -04:00
Abit
210e816897 Fix paths for macOS unit tests in github autobuild 2020-07-02 08:35:27 -04:00
Abit
d7c710edd5
Add macOS to Github Autobuild 2020-07-02 10:38:59 +02:00
Abit
a2b380d58e
Merge pull request #205 from bitshares/fix-websocket-close
Fix race condition in websocket server close
2020-06-24 15:27:28 +02:00
Abit
8b94976b79
Fix race condition in websocket server close
Note: the close() functions are not yet used in bitshares-core, but only in tests in FC.
The new code is not fully thread-safe either.
2020-06-24 12:08:55 +02:00
Abit
a876678008
Merge pull request #204 from bitshares/jmj_1256
Test to demonstrate fc::mutex and fc::thread
2020-06-22 17:07:13 +02:00
Abit
12777b8358
Merge pull request #201 from bitshares/ws-refactory
Websocket code refactory and bugfix
2020-06-22 16:27:42 +02:00
abitmore
0d9b127e34 Add missing functions to websocket_tls_server
These functions were in websocket_server class but not in websocket_tls_server class:
- get_listening_port
- stop_listening
- close
2020-06-20 13:01:22 -04:00
abitmore
aa671d61b5 Add promise to wait for closure of server socket
This may fix the issues that a websocket server may crash or hang when quitting
2020-06-20 11:36:21 -04:00
abitmore
9ae294293f Update coding style 2020-06-18 18:57:33 -04:00
Abit
6606806f31
Merge pull request #202 from bitshares/fix-tuple-size-warning
Fix Clang -Wmismatched-tags warning on tuple_size
2020-06-17 14:24:28 +02:00
abitmore
88a3b58651 Fix Clang -Wmismatched-tags warning on tuple_size 2020-06-14 21:53:47 +00:00
abitmore
4dd1319a9e Refactor destructor of websocket_server_impl 2020-05-06 13:25:23 -04:00
abitmore
c55b1fde3c Add notes 2020-05-06 13:25:23 -04:00
abitmore
b77fa2a651 Capture only required vars, update coding style
and replace an assertion with a check.
2020-05-06 12:22:07 -04:00
abitmore
04f5fae050 Refactor websocket_tls_server_impl with template
Removes unnecessary differences between websocket_server_impl and websocket_tls_server_impl.
2020-05-02 13:33:39 -04:00
abitmore
33ce80cc5f Remove unused types, wrap long lines 2020-05-02 11:36:05 -04:00
abitmore
bee73bd491 Refactor websocket_client, fix duplicate code
Fix duplicate code issue in websocket_client::connect() and
websocket_client::secure_connect(), and other minor issues
2020-05-02 11:21:50 -04:00
Abit
c00824a137
Merge pull request #134 from bitshares/jmj_844b
Log host information from websocket requests
2020-05-02 14:03:15 +02:00
abitmore
ea96a5a93b Fix websocket_client::secure_connect()
Code synced from connect(), added todo to refactor later
2020-05-02 06:35:56 -04:00
abitmore
aa54e3938c Remove unused websocket_tls_client class
The funcionality is already covered by the websocket_client class
2020-05-02 06:34:18 -04:00
abitmore
ffbda4e161 Add test cases about on_http for websocket servers 2020-05-02 05:46:21 -04:00
abitmore
c58ae55f44 Update test cases about RPC logging level 2020-05-02 04:40:28 -04:00
abitmore
c8fcefb901 Update RPC logging format 2020-05-02 04:17:44 -04:00
abitmore
3e07edf995 Remove unused header inclusion 2020-05-02 04:03:01 -04:00
abitmore
c6df78b0bb Rename a function to avoid accidental misuse 2020-05-01 20:51:47 -04:00
abitmore
8ddcc87ee1 Add todo 2020-05-01 19:43:29 -04:00
abitmore
e778cf1520 Revert to simple WS connection for clients 2020-05-01 19:11:09 -04:00
abitmore
8ffe08f891 Merge 'master' branch 2020-05-01 18:01:55 -04:00
abitmore
e50067d6ed Tweak code slightly 2020-05-01 17:57:21 -04:00
abitmore
9c506d050b Fix test cases 2020-05-01 17:46:19 -04:00
abitmore
ba394e05b3 Refactor code about logging remote host info 2020-05-01 17:35:52 -04:00
Abit
ed22e1e6d4
Merge pull request #200 from bitshares/merge-core-4.0.x-to-master
Merge changes done for bitshares-core 4.0 to master
2020-04-29 15:55:37 +02:00
Abit
26c5bfc498
Merge pull request #199 from bitshares/abitmore-patch-1
Fix static_variant_depth_test
2020-04-19 18:32:19 +02:00
Abit
377f843478
Fix static_variant_depth_test 2020-04-19 18:03:37 +02:00
Abit
bb4fdb124f
Merge pull request #197 from bitshares/improve-testing
Update run-parallel-tests.sh to support arguments
2020-04-19 17:42:59 +02:00
Abit
c72d5d31cc
Merge branch 'master' into for-core-4.0.x 2020-04-19 10:55:50 +02:00
abitmore
480b17fdcd Show more messages in Travis CI 2020-04-18 14:42:12 -04:00
abitmore
a7bb22a9d1 Show more msgs when testing with Github Actions 2020-04-18 13:19:17 -04:00
abitmore
bc60ea3fa9 Update run-parallel-tests.sh to support arguments 2020-04-18 13:15:53 -04:00
Abit
73a7f08f00
Merge pull request #143 from bitshares/jmj_bsip64
Add Hash160 algorithm
2020-04-15 17:39:39 +02:00
John Jones
c554c7e56d add impl to hash160 2020-04-15 09:52:18 -05:00
John Jones
5070d8d2fc define hash160 reset method 2020-04-15 09:20:39 -05:00
John Jones
9505342dbf improve hash160 performance 2020-04-14 11:25:00 -05:00
John Jones
dbf4b99e3e Merge remote-tracking branch 'upstream/for-core-4.0.x' into jmj_bsip64 2020-04-14 10:37:40 -05:00
Abit
23f0c6ab8e
Merge pull request #196 from bitshares/fix-static-variant-warning
Fix compiler warnings about static_variant
2020-04-06 19:31:42 +02:00
abitmore
ca3e76d226 Fix compiler warnings about static_variant 2020-04-06 15:16:12 +00:00
Abit
60d7946dbe
Merge pull request #194 from bitshares/update-variant-size-t-macos-openbsd
Update to_variant(size_t) for macOS and OpenBSD
2020-03-31 17:42:23 +02:00
Abit
907a81b434
Merge pull request #195 from bitshares/replace-int-in-static-variant
Replace int with 64-bit types in static_variant
2020-03-31 17:41:23 +02:00
Abit
3a2902e3c7
Merge pull request #193 from bitshares/fix-exception-to-string
Fix potential infinity loop in `exception::to_detail_string()`
2020-03-30 15:42:58 +02:00
abitmore
98a16ce397 Replace int with 64-bit types in static_variant 2020-03-29 20:40:51 +00:00
abitmore
34ddc2b859 Update to_variant(size_t) for macOS and OpenBSD
Fix to_variant(size_t) for OpenBSD, move implementation for macOS to cpp file
2020-03-28 17:30:42 +00:00
abitmore
cc1103fe45 Fix potential infinity loop
Fix exception::to_detail_string(...)
2020-03-28 16:05:03 +00:00
Abit
4bc1405643
Merge pull request #192 from bitshares/update-bool-pack
Update bool serialization
2020-03-28 16:54:56 +01:00
abitmore
9763d1c194 Update bool serialization
Make the logic clearer, to avoid issues on some compilers.
Thanks to @pureland and team.
2020-03-26 16:27:59 +00:00
Abit
9dbf944412
Merge pull request #190 from nathanhourt/fix-2
Fix Build
2020-03-19 00:39:22 +01:00
Abit
3f9c3f6ed2
Merge pull request #189 from nathanhourt/fix-1
Fix Build
2020-03-19 00:15:28 +01:00
Nathan Hourt
2b1980a30a
Fix Build
Definitely something strange going on here, as in my environment
the value of Boost_UNIT_TEST_FRAMEWORK_LIBRARY is
"Boost::unit_test_framework"... So this is my fix, but probably
something else should be done.

Boost 1.72.0
2020-03-17 14:49:46 -05:00
Nathan Hourt
cb06e42e80
Fix Build
This is necessary to build in my environment for both clang and g++

Clang 9.0.1
G++ 9.2.1
Boost 1.72.0
2020-03-17 14:42:13 -05:00
Abit
bbf17f8a40
Merge pull request #188 from bitshares/for-core-4.0.x
Merge 4.0.x changes to master
2020-02-24 19:10:22 +01:00
Abit
5768c6d884
Merge pull request #186 from bitshares/abitmore-patch-1
Return a user-friendly message on RPC execution error
2020-02-24 18:49:17 +01:00
Abit
52f90d6392
Merge pull request #187 from bitshares/fix-github-autobuild
Fix Github auto-build
2020-02-24 18:17:22 +01:00
Abit
142b7eb4c6 Return a user-friendly msg on RPC execution error 2020-02-24 12:11:59 -05:00
Abit
f221ca3210
Fix Github auto-build
Remove the predefined boost related environment variables.
2020-02-24 18:00:03 +01:00
Abit
3970ca178b
Merge pull request #185 from bitshares/for-core-4.0.x
Merge 4.0.x changes to master
2020-02-21 12:14:35 +01:00
Peter Conrad
463380d64a
Merge pull request #184 from pmconrad/2078_file_appender
Fixed busy-wait in delete_files
2019-12-11 07:38:39 +01:00
Peter Conrad
3b7e67a3dc Fixed busy-wait in delete_files 2019-12-10 15:41:08 +01:00
Peter Conrad
c851de8caa
Merge pull request #180 from pmconrad/2054_github_autobuild
Add GitHub autobuild
2019-11-30 09:03:55 +01:00
Peter Conrad
6e5fe1f550 Fixed badge 2019-11-29 17:45:19 +01:00
Peter Conrad
1d8b63bdb1
Merge pull request #182 from bitshares/for-core-4.0.x
bring macos build fix to master
2019-11-27 08:05:49 +01:00
Alfredo Garcia
8474e84997
Merge pull request #181 from pmconrad/2070_osx_fix
Fix for OSX build
2019-11-26 10:21:25 -03:00
Peter Conrad
56d9e4d968 Fix for OSX build 2019-11-26 08:26:16 +01:00
Peter Conrad
7981ab08f5 Added badge to README 2019-11-25 15:03:46 +01:00
Peter Conrad
005aa69c0a Attempt to fix tests 2019-11-18 17:19:19 +01:00
Peter Conrad
f7f64ee1fd Add ccache 2019-11-18 17:19:19 +01:00
Peter Conrad
540a99670b Build and run in parallel 2019-11-18 17:16:59 +01:00
Peter Conrad
453345cedf Install boost 2019-11-18 17:16:22 +01:00
Peter Conrad
0e0bc44651 Added initial workflow 2019-11-18 17:16:22 +01:00
Abit
2568867f2f
Merge pull request #178 from bitshares/abitmore-patch-1
Fix potential out-of-bounds access
2019-11-08 16:23:38 +01:00
Abit
1d028b3c15
Fix potential out-of-bounds access
Thanks to Beosin(https://github.com/Lianantech)
2019-11-08 12:13:36 +01:00
Peter Conrad
ad3c881aa2
Merge pull request #13 from bitshares/oxarbitrage-patch-2
add license mit
2019-11-07 17:44:01 +01:00
Peter Conrad
61f16df040 Replaced "regime" 2019-11-07 13:18:49 +01:00
Peter Conrad
ca43b6c6df License clarification 2019-11-06 18:39:03 +01:00
Peter Conrad
0633515d7b Fixed stacktrace license 2019-11-06 18:39:03 +01:00
Peter Conrad
8c9b8a95f5 Updated license file 2019-11-06 18:39:03 +01:00
abitmore
9c3428096a Update copyright notice 2019-11-06 18:39:03 +01:00
Peter Conrad
35b3c0336c Document licensing and history 2019-11-06 18:39:03 +01:00
oxarbitrage
2ae775bdb3 add license mit 2019-11-06 18:39:03 +01:00
Peter Conrad
e5ab69acff
Merge pull request #176 from bitshares/bloom_update
Updated bloom_filter.hpp…
2019-11-06 18:38:14 +01:00
Peter Conrad
41aaa6cb1f
Merge pull request #177 from bitshares/cmake_simplification
Get rid of most extra cmake modules
2019-11-06 15:50:18 +01:00
Peter Conrad
cdbe881996 Removed unused reflection 2019-11-06 15:49:16 +01:00
Nathan Hourt
e48941b87e
Merge pull request #175 from bitshares/nathanhourt-fix-warnings
Fix warning in zeroed_array.hpp
2019-11-05 11:06:47 -06:00
Peter Conrad
7e07bc4514 Get rid of most extra cmake modules 2019-11-04 08:21:57 +01:00
Peter Conrad
1d59bb3d47 Updated bloom_filter.hpp from c89c2912c4/bloom_filter.hpp 2019-11-04 08:18:34 +01:00
Nathan Hourt
6e22341d9f
Fix warning in zeroed_array.hpp
Only one template declaration is needed here, I think. Clang gives many, many warnings over it.
2019-11-01 15:14:46 -05:00
Peter Conrad
dd257e5c0b
Merge pull request #171 from pmconrad/obsolete_boost
Removed checks for obsolete boost version numbers
2019-09-25 07:33:19 +02:00
Peter Conrad
4bdab0bb0a Removed checks for obsolete boost version numbers 2019-09-24 17:24:38 +02:00
Abit
2f776301cd
Merge pull request #169 from bitshares/for-core-3-3
Merge 3.3.x branch to master branch
2019-09-23 17:02:18 +02:00
Peter Conrad
9593e5d3bb
Merge pull request #170 from pmconrad/node_crashes
Make for-core-3-3 branch mergable with master
2019-09-23 07:59:51 +02:00
Peter Conrad
ec77b4943c Added std::tuple_size for master compatibility 2019-09-22 10:03:29 +02:00
Peter Conrad
6d8d0307a2
Merge pull request #165 from pmconrad/node_crashes
Changes wrt recent crashes of nodes
2019-09-21 09:17:46 +02:00
Peter Conrad
ed479c8c3e Reformatting 2019-09-20 09:27:57 +02:00
Peter Conrad
afc0e00700 Added zero_initialized_array template to restore functionality of fc::array<unsigned char,N> 2019-09-20 09:27:57 +02:00
Peter Conrad
253c1d56b9 Added test for zero-initialized arrays 2019-09-20 09:27:57 +02:00
Peter Conrad
5c0b9ed4e3
Merge pull request #164 from pmconrad/1895_namespaces
Move stuff into namespaces
2019-09-19 16:15:43 +02:00
Peter Conrad
b986bab004
Merge pull request #167 from pmconrad/exception_format_fix
Exception format fix
2019-09-19 08:20:27 +02:00
Peter Conrad
2cc32d79ba Fixed assert 2019-09-18 15:12:27 +02:00
Peter Conrad
9077892d87 Log stacktrace instead of writing to stderr 2019-09-18 15:12:27 +02:00
Peter Conrad
4ce3775630 Clean up before returning 2019-09-18 15:12:27 +02:00
Peter Conrad
eb42ebb528 Add log message 2019-09-18 15:12:27 +02:00
Peter Conrad
ef52b39036 Preserve crash in debug mode 2019-09-18 15:12:27 +02:00
Peter Conrad
201b4b33f0 Print stacktrace when yielding within an exception handler 2019-09-18 15:12:27 +02:00
Peter Conrad
cd69d13348 Replaced spin_yield_lock with atomics 2019-09-18 15:12:27 +02:00
Peter Conrad
20c1688223 Removed superfluous return 2019-09-18 13:07:54 +02:00
Peter Conrad
164f1f68e6 Whitespace fixes 2019-09-18 13:07:54 +02:00
Peter Conrad
5b8a7c281c Partial revert "Changes to avoid conflict in following cherry-pick"
This reverts commit d729816b06.
2019-09-18 13:07:47 +02:00
Spartucus
3583ee6138 Fix non-void function return value
Since last catch insert exception string to `ss`, it should returns.
2019-09-18 12:59:37 +02:00
Kevin Heifner
2eb047a6f4 Add exception handling to to_string and to_detail_string 2019-09-18 12:59:37 +02:00
Peter Conrad
d729816b06 Changes to avoid conflict in following cherry-pick 2019-09-18 12:59:37 +02:00
Peter Conrad
bae416a446
Merge pull request #162 from pmconrad/1982_rotate_logs
Check + rotate logs while logging not by scheduled task
2019-09-17 17:37:04 +02:00
Peter Conrad
f052ac98fa
Merge pull request #166 from pmconrad/copy_safety
Copy safety
2019-09-17 15:59:01 +02:00
Peter Conrad
e168b6400b Avoid time calculation when not rotating 2019-09-17 13:46:02 +02:00
Peter Conrad
2b3611fa95 Delete copy constructor + copy assignment in tcp_socket 2019-09-16 14:44:55 +02:00
Peter Conrad
7b98c69c3b Delete copy constructor + copy assignment in openssl type wrappers 2019-09-16 14:38:45 +02:00
Peter Conrad
8c9f7151e1 Moved stuff into fc::test namespace 2019-09-16 12:30:32 +02:00
Peter Conrad
f4866b777e Move helper classes into fc::detail 2019-09-16 12:00:38 +02:00
Peter Conrad
f6fd6a7cf7 Avoid re-computing seconds 2019-09-15 14:18:57 +02:00
Peter Conrad
5cd9f7d631 Move log file deletion into separate task 2019-09-15 14:09:44 +02:00
Peter Conrad
2e50624b28 Check + rotate logs while logging not by scheduled task 2019-09-12 16:01:09 +02:00
Peter Conrad
869c75d070
Merge pull request #159 from pmconrad/314_windows_default_cas
Fix core #314 - Use windows default CAs for tls client connections
2019-09-06 08:09:13 +02:00
Nathan Hourt
9db1417b25
Merge pull request #160 from nathanhourt/master
Add FC_REFLECT_DERIVED_NO_TYPENAME
2019-09-02 11:52:18 -05:00
Nathan Hourt
dadfe189d4 Add FC_REFLECT_DERIVED_NO_TYPENAME
This is moved to FC from graphene/protocol/types.hpp
2019-09-02 10:02:51 -05:00
Nathan Hourt
7e69567dd0
Merge pull request #158 from nathanhourt/master
Fix build on G++ 7
2019-09-02 09:53:20 -05:00
Nathan Hourt
1699b0ac36 Fix build on updated G++ 2019-09-01 12:53:01 -05:00
Nathan Hourt
4b7bcb951d
Merge pull request #156 from nathanhourt/reflection-updates
Improve reflection system and static_variant
2019-09-01 10:33:40 -05:00
Peter Conrad
77a82903fc Fix core #314 - Use windows default CAs for tls client connections 2019-09-01 15:17:59 +02:00
Nathan Hourt
292584ca59 Add static_variant::operator==
For real this time :)
2019-08-31 12:48:52 -05:00
Nathan Hourt
94cb1858b8 Fix constexprs, unused code 2019-08-31 12:48:52 -05:00
Abit
78aaaac8e1
Merge pull request #157 from bitshares/for-core-3-3
Merge for-core-3-3 branch into master
2019-08-30 22:27:42 +02:00
Nathan Hourt
c69ea32613 Improve reflection system and static_variant
Previously, fc reflection generated visitor infrastructure capable of
visiting each field of a struct; however, this is only useful for run-
time operations on structures. No compile-time information was preserved
about the fields of a struct, making compile-time introspection of types
impossible.

Now FC reflection generates rich compile-time information about the
members of structs, including types, names, and structure, allowing
code to be written to explore types in detail at compile-time and fetch
arbitrary fields at runtime without needing to iterate over the unwanted
fields.

To make this a reality, a new `typelist` type was added to store this
compile-time information. This type is also useful within the context of
`static_variant`, as SV previously used implementation detail types in a
private namespace to provide this functionality. Now `static_variant`
uses the reusable functionality of `typelist` to operate, dramatically
reducing the amount of code dedicated to `static_variant` and also
making `static_variant` types more flexible to work with since their
infrastructure is now based on the `typelist` public interface.
2019-08-30 14:21:36 -05:00
Nathan Hourt
5278a125df
Merge pull request #154 from nathanhourt/sv_overloads
Replace improper static_variant operator overloads with comparators
2019-08-30 14:19:06 -05:00
Peter Conrad
7a4758671f
Merge pull request #152 from pmconrad/1952_fix_assert
Possible fix for core #1952
2019-08-30 20:44:18 +02:00
Nathan Hourt
45cb433d47 Fixes from code review 2019-08-30 11:52:05 -05:00
Peter Conrad
9e81e1d5b6
Merge pull request #153 from crypto-ape/fix_for_msvc_broken_static_evaluation_in_array_declaration
Fix Compilation with MSVC
2019-08-30 18:04:17 +02:00
Nathan Hourt
7954c4a9c0
Merge pull request #155 from bitshares/nathanhourt-fix-logger-warnings
Fix warnings (ref bitshares/bitshares-core#1584)
2019-08-29 13:11:25 -05:00
Nathan Hourt
cce644f686
Fix warnings
The `appender` class is intended to be inherited and used polymorphically, but does not have a virtual destructor, which causes warnings. This adds a virtual destructor to fix these warnings.
2019-08-29 11:26:34 -05:00
Nathan Hourt
9f7f1b4790 Replace improper static_variant operator overloads with comparators 2019-08-28 15:51:14 -05:00
crypto-ape
5bb0254d83 fix array declaration for broken msvc static expression evaluation 2019-08-26 14:10:43 +02:00
Peter Conrad
78ffb6dbd3 Possible fix for core #1952 2019-08-22 11:11:17 +02:00
Peter Conrad
1d2d9bf2a4
Merge pull request #151 from pmconrad/1948_fix_editline
Fix editline build on non-win32
2019-08-21 14:10:19 +02:00
Peter Conrad
ea85954e17 Adjust whitespace 2019-08-21 11:31:41 +02:00
Peter Conrad
81cc84c172 Fix core #1948 - editline does not build 2019-08-21 11:31:09 +02:00
John M. Jones
1eebd3c692
Merge pull request #149 from bitshares/jmj_cmake
Remove custom FindBoost.cmake
2019-08-20 14:52:38 -05:00
Peter Conrad
71f5348101
Merge pull request #150 from pmconrad/tcp_socket_size
Fix core #1935
2019-08-20 15:43:39 +02:00
Peter Conrad
7b37cd6eff Fix core #1935 2019-08-19 12:09:53 +02:00
Peter Conrad
699238f08f Fix build with older cmake 2019-08-17 10:23:15 +02:00
Peter Conrad
c94abf71a3
Merge pull request #148 from crypto-ape/support_building_on_open_bsd
Support Building on OpenBSD
2019-08-17 10:09:05 +02:00
John Jones
3f1096d23e Remove custom FindBoost.cmake 2019-08-16 13:24:28 -05:00
crypto-ape
727e09ebe7 support openbsd // implement tcp keep-alive polling 2019-08-15 12:22:59 +02:00
crypto-ape
4ac6887deb support openbsd // compile with libressl 2019-08-15 12:22:59 +02:00
crypto-ape
cb5f7d3cdd support openbsd // get rid of alloca 2019-08-15 12:22:59 +02:00
crypto-ape
a1c2ff9943 support openbsd // make code compliant with clang 2019-08-15 12:22:54 +02:00
John M. Jones
91d8772b7b
Merge pull request #147 from bitshares/jmj_winfix
Increase size for Boost 1.70
2019-08-13 14:02:18 -05:00
Abit
f7a1e532ca
Merge pull request #146 from bitshares/optional-api-fix
Fix optional API arguments
2019-08-13 20:12:59 +02:00
John Jones
8426b45d6c Increase size for Boost 1.70 2019-08-13 13:11:36 -05:00
Abit
17c46399ed
Merge pull request #145 from nathanhourt/bts_1898
Resolves issue https://github.com/bitshares/bitshares-core/issues/1898: Fix crash in API
2019-08-13 19:24:18 +02:00
abitmore
7b6c359a32 Update test case for optional API arguments
Reproduces https://github.com/bitshares/bitshares-core/issues/1898
2019-08-13 13:09:31 -04:00
John M. Jones
82af8b55bd
Merge pull request #140 from pmconrad/1584_more_simplification
Fix simplifications
2019-08-13 06:09:51 -05:00
Nathan Hourt
06f88979a0 Resolve #1898: Fix crash in API
We were getting the moral equivalent of a null pointer dereference by
incrementing an iterator past its past-the-end position, then
dereferencing it. This is now fixed.
2019-08-11 13:51:08 -05:00
Peter Conrad
d3c85a8415 Fix cmake warning 2019-08-11 12:15:54 +02:00
John M. Jones
24f747863d
Merge pull request #144 from bitshares/jmj_ws_boost170
Bump websocketpp for Boost 1.70
2019-08-07 13:37:22 -05:00
Peter Conrad
e45a449701 Fixed type of chr37 2019-08-05 21:28:12 +02:00
Peter Conrad
d8bec3d847 Resolved another begin/data inconsistency 2019-08-05 21:27:53 +02:00
Peter Conrad
2dc5ad8bac Try to work around __int128 problem on mac 2019-08-05 21:18:17 +02:00
John Jones
fd0b197900 bump websocketpp for Boost 1.70 2019-08-05 10:24:12 -05:00
Peter Conrad
42be69c3f7 Removed unused var 2019-08-02 17:31:28 +02:00
Peter Conrad
cabab23e2c Replaced more array::begin() with data() 2019-08-02 17:31:07 +02:00
Peter Conrad
a9a6cb94d1 Replaced more begin() with data() 2019-07-29 12:21:15 +02:00
Peter Conrad
ce79181dcf Replaced more instances of array::begin with array::data 2019-07-26 15:03:22 +02:00
Peter Conrad
6008c96c1a Allow more space for windows sockets due to fc::future changes 2019-07-26 15:02:17 +02:00
Peter Conrad
c8f3e452d3 Use array::data instead of array::begin 2019-07-26 15:02:17 +02:00
Peter Conrad
e160afce16 Attempt to fix uint128 for mac 2019-07-26 15:02:17 +02:00
Peter Conrad
451ed46ecc Replace one more "new promise" with "promise::create" 2019-07-26 15:02:17 +02:00
Abit
966e9ea64e
Merge pull request #121 from crypto-ape/master_mingw
CMake cleanup & MinGW support
2019-07-25 09:44:37 +02:00
John Jones
5681dd1c0e Add hash160 test 2019-07-24 10:15:10 -05:00
John Jones
55e2abe7d5 Fix spacing 2019-07-23 17:32:29 -05:00
John Jones
ea9128257c Remove unnecessary predeclarations 2019-07-23 17:25:02 -05:00
John Jones
94f77ffc85 Add hash160 md algo 2019-07-23 17:14:01 -05:00
Alfredo Garcia
a461d2f5ae
Merge pull request #141 from bitshares/abitmore-patch-1
Update a comment to avoid confusing doxygen
2019-07-21 10:41:23 -03:00
John M. Jones
cd49944222
Merge pull request #142 from bitshares/fix-api-close
Correctly close websocket API connection
2019-07-19 16:33:15 -05:00
abitmore
2c5c30848a Correctly close websocket API connection 2019-07-19 16:00:18 -04:00
Abit
e4b35e4a42
Update a comment to avoid confusing doxygen 2019-07-18 23:15:22 +02:00
crypto-ape
b2c2a47521 CheckLibcxxAtomic after Boost 2019-07-08 13:42:51 +02:00
crypto-ape
dfc0a357d3 Updated Boost Lockfree compilation test 2019-07-08 11:46:26 +02:00
crypto-ape
ab617200a5 Removed unneeded definitions 2019-07-08 11:46:26 +02:00
crypto-ape
86b025007a Bumped Boost version 2019-07-08 11:46:26 +02:00
crypto-ape
241f1f2f0d Legacy/CMakeLists.txt EOF newline 2019-07-08 11:46:26 +02:00
crypto-ape
a2303d3528 Updated CMake for MinGW 2019-07-08 11:46:26 +02:00
crypto-ape
b8a87bde76 BoostConfig EOF newline 2019-07-08 11:46:26 +02:00
crypto-ape
c453db886b CMake version bump 2019-07-08 11:46:26 +02:00
crypto-ape
8d33bb844d Fixed pthread dependency 2019-07-08 11:46:26 +02:00
crypto-ape
c9b3d57b0e Updated Boost searching 2019-07-08 11:46:19 +02:00
crypto-ape
e0dd942875 Update build system for MinGW 2019-07-08 10:43:02 +02:00
Alfredo
e336649b8f lambda capture only whats required 2019-06-21 16:03:00 -03:00
Alfredo
7ec8ead573 chanmge comment from hostname to IP 2019-06-21 15:48:48 -03:00
Alfredo
e90742995b fix tests 2019-06-21 15:46:29 -03:00
Alfredo Garcia
5d8e9e110e
fix remove appender() 2019-06-21 15:05:47 -03:00
Alfredo Garcia
550e092267
Merge branch 'master' into jmj_844b 2019-06-21 14:53:36 -03:00
Peter Conrad
6ed94317ab
Merge pull request #137 from pmconrad/1584_more_simplification
More simplifications
2019-06-19 18:34:59 +02:00
Peter Conrad
deb9d4f0a6 Make task internal storage private 2019-06-19 17:40:22 +02:00
Peter Conrad
491fd31734 Replace 0 with nullptr 2019-06-19 17:39:45 +02:00
Peter Conrad
3fa4fa6148 Fixed typo 2019-06-19 17:31:54 +02:00
crypto-ape
d5fb99b41f SSE intrinsic rename 2019-06-19 16:06:40 +02:00
Abit
a87a99bbeb
Merge pull request #139 from pmconrad/1791_fix_linking_order
Fixes https://github.com/bitshares/bitshares-core/issues/1791
2019-06-12 16:27:32 +02:00
Peter Conrad
2e98d5cc2b Fixes https://github.com/bitshares/bitshares-core/issues/1791 2019-06-12 13:15:41 +02:00
Alfredo Garcia
4cfb54fd56
Merge pull request #138 from crypto-ape/issue_1769-extend_static_variant_with_is_type_method
extend static_variant with is_type() method
2019-06-11 13:34:18 -03:00
crypto-ape
f29248d139 extend static_variant with is_type() method 2019-06-11 18:00:01 +02:00
Peter Conrad
ed7eefec67 Avoid array copy 2019-06-11 13:32:04 +02:00
Peter Conrad
1bda001b8c Use common inline functions for splitting/combining uint128 to/from two uint64 values 2019-06-11 08:51:59 +02:00
Peter Conrad
b16bf00a10 Made task_base destructor virtual 2019-06-10 23:25:56 +02:00
Peter Conrad
f1746b705a Make data_size static in hash classes 2019-06-10 23:24:09 +02:00
Peter Conrad
40797b1026 Fixed typo 2019-06-10 18:52:46 +02:00
Peter Conrad
79b2a0d634 Add support for native 128bit types 2019-06-08 10:25:52 +02:00
Peter Conrad
7649f1f47d Removed broken http_server + unused http_api 2019-06-06 14:54:48 +02:00
Peter Conrad
8196eb98c8 Added fc::int128_t 2019-06-06 14:41:47 +02:00
Peter Conrad
a11a50d4e1 Replaced true_type, false_type, is_class, is_enum with std type_traits 2019-06-06 14:41:47 +02:00
Peter Conrad
f732a587d7 Replace NO_RETURN with [[noreturn]] standard attribute 2019-06-06 14:41:47 +02:00
Peter Conrad
1025c36153 Replaced fc::nullptr_t with std::nullptr_t 2019-06-06 14:41:47 +02:00
Peter Conrad
8ad041cea0 Replaced fc::deduce with std::remove_reference<std::remove_const<>> 2019-06-06 14:41:47 +02:00
Peter Conrad
0aac8a4afc Replaced fc::forward with std::forward 2019-06-06 14:41:47 +02:00
Peter Conrad
a8337ecc42 Added constexpr where applicable 2019-06-06 14:41:47 +02:00
Peter Conrad
632a90709e Replace fc::array with std::array 2019-06-06 14:41:47 +02:00
Peter Conrad
a3e2410091 Replace fc::uint128 with boost::multiprecision::uint128_t 2019-06-06 14:41:09 +02:00
Peter Conrad
648d969fb9 Remove unused header 2019-06-06 14:39:14 +02:00
Peter Conrad
022c40dde2 Removed unused real128 2019-06-06 14:39:14 +02:00
Peter Conrad
7506aaefe7 Moved retain/release to task_base 2019-06-06 14:39:14 +02:00
Peter Conrad
19bbc4080e Added retain where applicable 2019-06-06 14:39:14 +02:00
Peter Conrad
7cf371736b Intermediate 2019-06-06 14:39:14 +02:00
Peter Conrad
e2c5160eba
Merge pull request #97 from cogutvalera/issue_1171_hiding_secret
Safer way to handle secret information of cli_wallet #1171
2019-06-05 12:57:54 +02:00
Valera Cogut
720805493f Fixed conflicts & rebased 2019-06-02 14:26:47 +03:00
Valera Cogut
73ae27e0b8 Added little improvements: free line_read before re-using it & check for nullptr read_line before using it 2019-06-02 12:38:15 +03:00
Valera Cogut
59ad7300ec Safer way to handle secret information of cli_wallet #1171 2019-06-02 12:37:44 +03:00
Peter Conrad
58e16e543d Replaced most fc::shared_ptr with std::shared_ptr 2019-05-29 11:28:40 +02:00
Peter Conrad
ab9b4a234e
Merge pull request #133 from pmconrad/1738_compile_time
Improve build time
2019-05-28 21:50:09 +02:00
Peter Conrad
3b3cadf7d5 Separate exception declaration and implementation 2019-05-28 17:22:57 +02:00
Peter Conrad
9069e05cb0 Get rid of some inlines 2019-05-28 17:20:57 +02:00
Peter Conrad
de46823a99 Dont inline generic pack/unpack to enable externalized serialization 2019-05-28 17:20:57 +02:00
Peter Conrad
8d0693304e
Merge pull request #135 from pmconrad/1688_websocket_errors
Fixed JSONRPC error handling
2019-05-28 14:45:00 +02:00
jmjatlanta
99d7e63636 revert adjustment to capture 2019-05-27 15:26:33 -05:00
Abit
9ce24c2feb
Merge pull request #136 from bitshares/ws-client-fix
Fix websocket client crash on quit
2019-05-27 21:02:28 +02:00
jmjatlanta
94200c1b57 clarify method name, cache value 2019-05-27 10:25:19 -05:00
Peter Conrad
e5869b2800 Amended some error codes 2019-05-27 11:55:03 +02:00
abitmore
debc4bd6c3 Wrap a long line 2019-05-25 10:24:03 -04:00
abitmore
c870cd8e27 Refactor websocket_tls_client_impl with template
Removes unnecessary differences between websocket_client_impl and websocket_tls_client_impl.
2019-05-25 10:01:34 -04:00
abitmore
8aa729da68 Fix websocket_client crash on close 2019-05-25 08:30:05 -04:00
John Jones
0df5f7e905 Use an api call instead of constructor 2019-05-24 11:15:02 -05:00
Peter Conrad
aa8870e793 Fixed JSONRPC error handling 2019-05-24 18:11:19 +02:00
John Jones
4906d8b2da Allow configurable proxy header for logging 2019-05-24 10:41:21 -05:00
John Jones
d821e865ed Add configurable header 2019-05-24 08:53:45 -05:00
John Jones
8b4ef5aa02 Fix bad_alloc 2019-05-23 16:05:05 -05:00
John Jones
82935acd86 Add host information to log messages 2019-05-23 09:56:11 -05:00
Abit
397830b8ef
Merge pull request #130 from openledger/thread_d_memory_leak
Fix memory leak. Not all tasks are deleted in thread_d dtor.
2019-05-21 21:34:45 +02:00
Abit
ab6aa05574
Merge pull request #131 from bitshares/jmj_847b
Update CMake to C++14
2019-05-21 21:33:50 +02:00
Abit
8176f39806
Merge pull request #132 from bitshares/jmj_win_ifndef
Add #ifndef for Windows
2019-05-21 18:31:11 +02:00
John Jones
461b15acb4 Add #ifndef for Windows 2019-05-21 07:11:17 -05:00
John Jones
868fb93518 Add c++14, remove c++11 settings 2019-05-20 13:16:36 -05:00
Dmitry Yakovitsky
55ad023d94 Fix memory leak. Not all tasks are deleted in thread_d dtor. 2019-05-14 17:31:28 +03:00
Nathan Hourt
6bee7ff30b
Merge pull request #126 from nathanhourt/api-optionals
Add API support for optional arguments
2019-05-14 06:52:07 -05:00
Nathan Hourt
6b7874e49a Rebase fixes 2019-05-13 17:26:32 -05:00
Nathan Hourt
afb96a0e7e Ref #126: Cleanup/revert unwanted changes 2019-05-13 17:25:49 -05:00
Nathan Hourt
0a50ac23e0 Remove websocket_server::synchronous_close
It doesn't work as expected, so get rid of it.
2019-05-13 17:25:08 -05:00
Nathan Hourt
b8a03d3a51 Fix failing test 2019-05-13 17:25:08 -05:00
Nathan Hourt
09e4f573ce Improve websocket server close code 2019-05-13 17:25:08 -05:00
Nathan Hourt
bb01f3e925 Use random port for API tests
Add missing functionality to websocket_client and websocket_server to
make API tests more reliable and to make it possible to use a random
port for the tests.
2019-05-13 17:25:08 -05:00
Nathan Hourt
94a18cfccc Roll API tests into all_tests 2019-05-13 17:24:11 -05:00
Nathan Hourt
a89e30187f API Tests
General cleanup of a lot of nonsense
Add tests of optional parameters
2019-05-13 17:24:10 -05:00
Nathan Hourt
eb48480246 Do optional API args without hana
So sad... the hana version was way more expressive... But hey, I'm kinda
proud I actually got this working! :D
2019-05-13 17:11:43 -05:00
Nathan Hourt
24eff3ab6d Add API support for optional arguments
FC_API now supports optional arguments! Any trailing arguments of
an fc::optional type are now optional, and do not need to be
supplied. If omitted, they will be inferred to be null optionals.
2019-05-13 17:11:43 -05:00
Abit
7e612bee5d
Merge pull request #129 from bitshares/quit-cli
Set `cli_quitting` to true in cli::cancel()
2019-05-13 15:08:42 +02:00
abitmore
30ea9b4a1d Let rl_getc() always return EOF when quitting
even if got an EOL or CTRL+C or etc
2019-05-12 19:44:22 -04:00
abitmore
2056a35b44 Set cli_quitting to true in cli::cancel() 2019-05-12 18:23:04 -04:00
Peter Conrad
869ad45242
Merge pull request #118 from crypto-ape/valgrind-inspired-fixes
valgrind inspired fixes
2019-05-12 11:01:20 +02:00
Abit
67e5a06035
Merge pull request #119 from bitshares/shared-ws-client-ptr
Use shared_ptr to WS connection in API connection
2019-05-10 15:24:15 +02:00
abitmore
3d39a51cdc Capture only this in cli::start() 2019-05-09 14:15:34 -04:00
abitmore
b562d81a65 Let CLI be able to restart 2019-05-09 14:15:34 -04:00
abitmore
9605f4826b Bump editline submodule 2019-05-09 13:22:24 -04:00
Peter Conrad
2cf1510d81
Merge pull request #122 from pmconrad/1196_serialization
1196 serialization
2019-05-08 17:32:35 +02:00
abitmore
301f582002 Handle SIGINT when searching in editline 2019-05-08 06:46:36 -04:00
abitmore
51747090a8 Minor function name change 2019-05-08 05:23:33 -04:00
abitmore
bac31e3822 Temporarily comment out check_secret in CLI
due to editline bump
2019-05-08 05:10:50 -04:00
abitmore
c5c94c45f8 Bump editline submodule 2019-05-08 05:00:57 -04:00
abitmore
382970bfa4 Suppress error message when CLI is quitting 2019-05-08 03:51:40 -04:00
abitmore
ed3f1c86dd Fix signal handling in CLI 2019-05-07 19:43:37 -04:00
abitmore
127aadbffc Add function to send signals to threads 2019-05-07 19:21:43 -04:00
abitmore
635cbc24e7 Return the signal_set when setting signal handler 2019-05-07 19:21:43 -04:00
crypto-ape
95ca36d02d properly cleanup previous current thread object 2019-05-07 13:59:56 +02:00
crypto-ape
918502e29e invalidate pointer to deleted object 2019-05-07 13:59:56 +02:00
crypto-ape
a188a95f2c extend openssl cleanup 2019-05-06 14:21:03 +02:00
crypto-ape
e82b327605 sanitize shared_ptr 2019-05-06 14:21:03 +02:00
abitmore
bd3036df8a Increase CLI command history buffer size to 256 2019-05-03 09:46:13 -04:00
abitmore
a71893adba Improve CLI tab completion feature
For example, if there are 3 commands: "gethelp", "get_account" and "get_account_name",
input "ge" then press TAB, the command will be completed to "get";
press TAB again, a list with all 3 commands will show;
input "get_ac" then press TAB, the command will be completed to "get_account";
press TAB again, a list with "get_account" and "get_account_name" will show.
2019-05-02 22:11:43 -04:00
Peter Conrad
bf63236e09
Merge pull request #125 from cwyyprog/tmp
Disable editline in mingw
2019-05-02 12:49:09 +02:00
cwyyprog
34c8fa4f3b clean CMakeLists 2019-04-30 13:51:29 +08:00
Nathan Hourt
e003fec4cd
Merge pull request #123 from nathanhourt/support-1506
Add missing serialization for sha1
2019-04-26 14:24:17 -05:00
John M. Jones
1947a14d4a
Merge pull request #114 from bitshares/jmj_847
Use c++14
2019-04-23 14:44:29 -05:00
Peter Conrad
379e59f661 Moved delete declaration to raw_fwd 2019-04-23 16:49:25 +02:00
Peter Conrad
1ae9169d08 Removed log_test from travis because it no longer exists 2019-04-23 16:49:24 +02:00
Peter Conrad
532093bda5 Added missing serialization for std::shared_ptr<T> 2019-04-23 16:49:24 +02:00
Peter Conrad
9568948350 Back hashes with boost endian buffers 2019-04-23 16:49:24 +02:00
Peter Conrad
5a9cf32696 Fixed AES IV handling 2019-04-23 16:48:17 +02:00
Peter Conrad
006f048ac5 Fixed cityhash endianness 2019-04-23 16:48:17 +02:00
Peter Conrad
cb9a96755d Add proper serialization for boost::endian::endian_buffer 2019-04-23 16:48:17 +02:00
Peter Conrad
89796afb01 Adapted + integrated libatomic check 2019-04-23 16:48:17 +02:00
Peter Conrad
8cbc2a2e22 Pulled CMake check for -latomic 2019-04-23 16:45:44 +02:00
Peter Conrad
f0c6976aea Removed superfluous return statement 2019-04-23 16:45:44 +02:00
Peter Conrad
9a0d92820d Fixes for endianness 2019-04-23 16:45:44 +02:00
Peter Conrad
8f1abdd4be Delete unused backup(?) file 2019-04-23 16:44:44 +02:00
Peter Conrad
41bdac7d58 Removed bitutil because architecture-independent byte order reversal rarely makes sense, and boost::endian provides a better alternative 2019-04-23 16:44:44 +02:00
Peter Conrad
1daac3b4b5 Removed unused endian-dependent code 2019-04-23 16:44:44 +02:00
Peter Conrad
b75f29438b Avoid endian-dependent access to hash value in key checksum test 2019-04-23 16:44:44 +02:00
Peter Conrad
0c69c9b61b Removed architecture-dependent hash64 method 2019-04-23 16:44:44 +02:00
Peter Conrad
7f93f265c7
Merge pull request #120 from pmconrad/1584_simplification
1584 simplifications
2019-04-23 15:54:09 +02:00
Nathan Hourt
cac38b39b6 Add missing serialization for sha1 2019-04-14 15:45:03 -05:00
cwyyprog
7453657591 Disable editline in mingw 2019-04-13 13:26:57 +08:00
John M. Jones
6b1fdd513d
Merge pull request #113 from bitshares/jmj_1646
Help compiler infer correct templated method
2019-04-10 05:34:22 -05:00
John M. Jones
5f8f799185
Merge pull request #111 from bitshares/jmj_1593_variant
Equality check does not work on Windows
2019-04-10 05:33:33 -05:00
Peter Conrad
4511300081 Minor fixes for Windows 2019-04-09 08:46:56 +02:00
Peter Conrad
bfe7904485 Removed obsolete test from travis.yml 2019-04-04 18:48:42 +02:00
Peter Conrad
cf502aab92 Added missing include 2019-04-04 18:22:23 +02:00
Peter Conrad
8a5cbac788 Added missing include 2019-04-04 18:16:23 +02:00
Peter Conrad
a063b8d41b Removed openssl ECC implementation 2019-04-04 17:59:51 +02:00
Peter Conrad
406f1bdd61 Remove unused json_connection 2019-04-04 17:59:51 +02:00
Peter Conrad
d5b817817a Remove unused bstate 2019-04-04 17:59:51 +02:00
Peter Conrad
183a81ba94 Remove unused pke 2019-04-04 17:59:51 +02:00
Peter Conrad
637226a2e4 Remove unused blowfish 2019-04-04 17:59:51 +02:00
Peter Conrad
d2b7354c24 Remove unused base36 2019-04-04 17:59:51 +02:00
Peter Conrad
579914c84d Removed unused stuff 2019-04-04 17:59:51 +02:00
abitmore
3655fe148b Minor code refactory 2019-04-03 12:06:02 -04:00
abitmore
03cc93d0e4 Update WS API test cases due to param type change 2019-04-03 12:06:02 -04:00
abitmore
15d751c3d0 Wrap long lines 2019-04-03 12:06:01 -04:00
abitmore
623d96fe9a Use shared_ptr to WS connection in API connection 2019-04-03 12:06:01 -04:00
Nathan Hourt
af572ba7d0
Merge pull request #117 from nathanhourt/typename-reflect
Add missing typename reflection for flat_map
2019-03-30 09:47:05 -05:00
Nathan Hourt
df01faa1ab Add missing typename reflection for flat_map 2019-03-29 17:36:24 -05:00
Nathan Hourt
cab0a4e8db
Merge pull request #116 from nathanhourt/warnings
Ref bitshares-core#1584 Fix some warnings
2019-03-26 08:43:05 -05:00
Nathan Hourt
4d4ec62f5d
Merge pull request #115 from nathanhourt/support-bts-1670
Support for BTS #1670: allow serializing shared_ptr<const T>
2019-03-25 09:30:27 -05:00
Nathan Hourt
2d0122f1ed More tweaks vis-a-vis warnings
Move crc_c fake usage out of strange main() function in a library
Convert manual string formatting to FC string formatting
2019-03-25 09:26:35 -05:00
Nathan Hourt
04c393a53a Add self-assignment test, sans the compiler warning 2019-03-25 09:18:21 -05:00
John Jones
843e000b74 value initialize result 2019-03-25 08:25:43 -05:00
Nathan Hourt
79886b2e35 Fix warning
Not sure what the story is with this file, but it's making a
warning and this fixes it.
2019-03-24 19:45:30 -05:00
Nathan Hourt
84c16aeebb Fix some warnings 2019-03-24 10:44:03 -05:00
Nathan Hourt
6665406f83 Requested changes for #115 2019-03-24 09:54:57 -05:00
Nathan Hourt
ba96174e7f Support for BTS #1670: allow serializing shared_ptr<const T> 2019-03-23 11:35:40 -05:00
John Jones
7497cb39f6 Use c++14 2019-03-22 16:02:20 -05:00
John Jones
7b07f84f51 Fix spacing 2019-03-22 09:38:51 -05:00
John Jones
aa50364b57 help compiler infer correct templated method 2019-03-22 09:17:01 -05:00
Nathan Hourt
a0ca5ab29d
Merge pull request #112 from nathanhourt/static_variant_fix
Make static_variant::tag_type public
2019-03-19 16:38:21 -05:00
Nathan Hourt
c59c36e006 Make static_variant::tag_type public
It's used in the public interface, so it needs to be a publicly
defined type
2019-03-19 13:06:46 -05:00
John Jones
d22f9ed634 whitespace fix 2019-03-05 13:04:44 -05:00
John Jones
d9634f8755 assist MSVC with comparison 2019-03-05 13:03:09 -05:00
John Jones
d5b2be2782 Equality check does not work on Windows 2019-03-04 17:02:14 -05:00
John M. Jones
6a5ba93fa9
Merge pull request #110 from bitshares/jmj_zlib
Allow zlib to be optional
2019-03-04 16:03:25 -05:00
John Jones
2fa5777038 Allow zlib to be optional 2019-02-26 13:55:42 -05:00
John M. Jones
063be69d07
Merge pull request #109 from bitshares/jmj_1548
Removal of smart_ref
2019-02-18 14:48:54 -05:00
John Jones
19590fd413 Removal of smart_ref 2019-02-15 08:23:05 -05:00
Abit
1a411b813a
Merge pull request #108 from bitshares/pr106
Enable websocket permessage-deflate (follow-up of #106)
2019-02-14 18:52:36 +01:00
abitmore
abdef068b9 Bump websocketpp version 2019-02-13 15:31:50 -05:00
Abit
11caddc13f
Merge pull request #106 from btsabc/enable-permessage
enable websocket permessage-deflate
2019-02-13 21:29:19 +01:00
Alfredo Garcia
66e97393ab
Merge pull request #107 from bitshares/missing-overloads
Add missing operator overloads for fc::unsigned_int
2019-02-13 15:48:01 -03:00
Nathan Hourt
25ae3222f8 Add missing operator overloads for fc::unsigned_int
Turns out that bitshares/bitshares-core#1506 is easier if you can
do greater-than comparisons on fc::unsigned_int. Go ahead and add
the complement of missing operators.
2019-02-13 12:21:30 -06:00
Your Name
b29da15d51 enable websocket permessage-deflate 2019-02-12 09:27:06 +08:00
John M. Jones
8ebd99b786
Merge pull request #105 from bitshares/jmj_1560
fix std::min parameter conversion
2019-02-05 16:53:04 -05:00
jmjatlanta
6fece96eae fix std::min parameter conversion 2019-02-05 15:44:06 -05:00
Peter Conrad
9e6c5ab6e2
Merge pull request #104 from bitshares/build_simplification
Build simplifications
2019-01-30 17:37:38 +01:00
Peter Conrad
4843502c48 travis: added ccache 2019-01-30 14:45:49 +01:00
Peter Conrad
0bbbb5eabf travis: Install only required stuff 2019-01-30 14:39:31 +01:00
Peter Conrad
3633cb4ac9 Switch to xenial build environment 2019-01-30 14:32:21 +01:00
Peter Conrad
98c9e62581 Remove unused boost dependencies serialization + locale 2019-01-30 14:31:08 +01:00
John Jones
29c0e5a0d8 Test to demonstrate fc::mutex and fc::thread 2019-01-22 21:11:46 -05:00
John M. Jones
87260fe0e1
Merge pull request #103 from bitshares/jmj_995
Remove unnecessary asserts
2019-01-22 18:16:27 -05:00
John Jones
7de33aa33a whitespace only 2019-01-21 09:15:56 -05:00
John Jones
fa07984234 fix overly agressive cleanup 2019-01-21 09:11:11 -05:00
John Jones
be4d480174 Remove unnecessary asserts 2019-01-18 12:29:38 -05:00
John M. Jones
2bf93ec086
Merge pull request #102 from bitshares/jmj_macwarn
Fix some macOS warnings
2019-01-17 12:28:56 -05:00
John Jones
9ba95190c4 make assert message more standard 2019-01-15 12:19:00 -05:00
Peter Conrad
b2e738af09
Merge pull request #100 from bitshares/fix_limits
Fix limits
2019-01-08 17:33:28 +01:00
Peter Conrad
72eeb62535 Changed MAX_PREALLOC_SIZE to 2^8 2019-01-07 19:01:33 +01:00
jmjatlanta
f7e5f7396b unneccesary capture 2019-01-07 11:18:14 -05:00
jmjatlanta
310bec6dce Fix warning adding int to string literal 2019-01-07 11:13:48 -05:00
John M. Jones
2baa7df47e
Merge pull request #101 from bitshares/jmj_1512
Remove boost signals
2019-01-06 15:51:21 -05:00
John Jones
e751cf2f2d Removed boost signals (no longer used) 2019-01-04 07:53:37 -05:00
John M. Jones
df7b4e6b52
Merge pull request #99 from bitshares/jmj_1246
Fix some compiler warnings
2019-01-02 05:25:04 -05:00
John Jones
1ed9b4f98f Revert -Wno-??? change 2019-01-01 10:25:57 -05:00
John Jones
51f27f1fcd Fix stacktrace test 2018-12-28 14:49:17 -05:00
Peter Conrad
90f8ad5722 Ported test case from STEEM 2018-12-28 20:36:34 +01:00
Peter Conrad
fb75dc9bb5 Added limits for resize() / reserve() 2018-12-28 20:36:29 +01:00
John Jones
e1bb7c6e14 Add compiler switches to squelch some warnings 2018-12-28 14:19:49 -05:00
John Jones
3f5205ad6b Fix warnings in tests 2018-12-28 14:19:19 -05:00
John M. Jones
0468884ea6
Merge pull request #92 from bitshares/mac_stacktrace
boost stacktrace does not play well with mac
2018-11-21 06:35:44 -05:00
John M. Jones
ec0de9802b
Merge pull request #90 from nathanhourt/patch-1
Fix build against boost 1.68+
2018-11-21 06:35:11 -05:00
John M. Jones
e9886b0628
Merge pull request #95 from bitshares/jmj_readsome
mac fc::io::readsome fix
2018-11-21 06:31:53 -05:00
Peter Conrad
1aecf3ccc8
Merge pull request #85 from crypto-ape/static-variant-memory-optimizations
Memory optimization of static_variant
2018-11-17 10:43:03 +01:00
Peter Conrad
460e7cccc8
Merge pull request #78 from bitshares/multithreading_improvements
Multithreading improvements
2018-11-17 10:41:49 +01:00
John Jones
84318f8d28 readsome instead of read 2018-11-15 13:46:07 -08:00
John Jones
f4dec89dc3 mac fc::io::readsome fix 2018-11-15 03:53:55 -08:00
Peter Conrad
ed775a594f Added missing include 2018-11-14 17:54:09 +01:00
John Jones
fd345e5bc2 fix #if for boost versions > 2 2018-11-13 16:06:59 -05:00
John Jones
5c0ee5d6b7 clarify comment 2018-11-12 20:57:58 -05:00
Peter Conrad
5b99b41a44 Added missing include 2018-11-10 21:29:32 +01:00
John M. Jones
0f110c3219
Merge pull request #91 from nathanhourt/patch-2
Update CMakeLists.txt
2018-11-09 19:27:59 -05:00
John Jones
0090777f34 boost stacktrace does not play well with mac 2018-11-09 14:44:41 -05:00
Nathan Hourt
d3984dd00d
Update CMakeLists.txt
On my Archlinux systems, linking fails unless this change is made.
2018-11-07 11:13:21 -06:00
Nathan Hourt
2e0a03ac1f
Fix build against boost 1.68+
In Boost 1.68, the `boost/context/all.hpp` header was removed.
Ref: 2e37599461
If building against Boost 1.68+, use `boost/context/continuation_fcontext.hpp` instead.
2018-11-07 11:07:34 -06:00
Peter Conrad
9cce60c917
Merge pull request #88 from HarukaMa/patch-1
Silence wrong tag warning
Still requires bumping fc in core.
2018-11-07 14:33:12 +01:00
Haruka Ma
bf36c189c2
Silence wrong tag warning 2018-11-07 16:41:20 +09:00
Peter Conrad
12e4962891
Merge pull request #87 from bitshares/reimprove_compilation_time
Use function pointers instead of std::function objects in static variant visitors
2018-11-05 16:22:03 +01:00
Peter Conrad
ed4a300fd5 Added missing include 2018-11-04 21:14:29 +01:00
Peter Conrad
3c3b76920e Use function pointers instead of std::function objects in static variant visitors 2018-11-04 13:54:05 +01:00
Peter Conrad
9fa03c6786
Merge pull request #86 from cogutvalera/issue_1171
Safer way to handle unlock command of cli_wallet #1171
2018-11-01 14:57:42 +01:00
crypto-ape
f8b86fc757 added testcase types_edge_cases_test for static_variant 2018-10-31 10:59:51 +01:00
crypto-ape
384d4f14c4 Replaced assert with FC_ASSERT 2018-10-31 10:59:40 +01:00
crypto-ape
93a0316607 Dynamic memory allocation of static_variant & other small changes. 2018-10-31 10:59:26 +01:00
Valera Cogut
079de9e177 Check if boost::regex is empty 2018-10-30 22:05:31 +02:00
Valera Cogut
157273fb40 Check if exists regex expression 2018-10-30 11:46:57 +02:00
Peter Conrad
acfe075c5d
Merge pull request #82 from cogutvalera/issue_1171
Safer way to handle unlock command of cli_wallet #1171
2018-10-28 10:51:22 +01:00
Valera Cogut
edd6fa8ded Removed pointer for regex expression 2018-10-27 19:06:24 +03:00
Valera Cogut
44896485d1 Optimized regex expression and other little improvements 2018-10-25 23:52:36 +03:00
Abit
8b6a2dd450
Merge pull request #84 from bitshares/jmj_1383
Fix Compiler Warnings
2018-10-25 10:41:45 +02:00
Abit
bcdaaaa651
Merge pull request #79 from bitshares/for-custom-auth
Changes for BSIP40 custom authorities
2018-10-25 10:40:29 +02:00
Valera Cogut
e14b7c6fc6 bump editline to latest upstream master 2018-10-25 00:01:43 +03:00
Valera Cogut
e00bbdaf72 removed not required output to console 2018-10-25 00:01:43 +03:00
Valera Cogut
c9d95c0c9a Safer way to handle unlock command of cli_wallet #1171 2018-10-25 00:01:43 +03:00
John Jones
c298917b85 Added warning back to avoid additional logic 2018-10-22 19:02:43 -05:00
John Jones
0156023680 Fix Compiler Warnings 2018-10-22 07:38:08 -05:00
Abit
a1d84f22c0
Merge pull request #83 from bitshares/log-obj-depth
Initialize max_object_depth in appender config
2018-10-19 22:11:20 +02:00
abitmore
9f43902b2c Remove empty lines 2018-10-19 15:48:36 +00:00
abitmore
d35e296d29 Initialize max_object_depth in appender config
by setting a default value, for file_appender and gelf_appender.
For issue https://github.com/bitshares/bitshares-core/issues/1392
2018-10-19 15:37:55 +00:00
Peter Conrad
19356497d3
Merge pull request #81 from bitshares/flat_set_serialization
Generalize flat_set serialization templates to allow different sorting and/or allocators
2018-10-13 09:33:27 +02:00
Peter Conrad
01e6ae357a Generalize flat_set serialization templates to allow different sorting and/or allocators 2018-10-12 20:35:50 +02:00
Peter Conrad
62ebc67cb3
Merge pull request #80 from oxarbitrage/remove_exotic_parser
remove WITH_EXOTIC_JSON_PARSERS
2018-10-10 14:44:24 +02:00
Peter Conrad
8174d63fb4 More line wrapping 2018-10-10 14:36:19 +02:00
Peter Conrad
bcce353b8f Check tag >= 0, shortened long lines 2018-10-10 00:07:21 +02:00
Peter Conrad
018642659d Fixed some new code smells 2018-10-09 23:42:03 +02:00
Peter Conrad
d0b280aca7 Fixed possible deadlock 2018-10-09 23:28:02 +02:00
Alfredo
53d3f729ea reduce number of changes 2018-10-09 16:41:51 -03:00
Peter Conrad
b4da12643f Replaced visitors with constant-time implementations 2018-10-09 17:55:34 +02:00
Peter Conrad
72a8168b2b Added a test for static_variant visitor call depth 2018-10-09 17:54:30 +02:00
Alfredo
67d2eb9b63 remove WITH_EXOTIC_JSON_PARSERS 2018-10-08 19:35:56 -03:00
Peter Conrad
8eff001655 Initialize queues properly 2018-10-06 11:07:11 +02:00
Peter Conrad
fc61ef3d04 Improved error handling on thread exit 2018-10-06 11:06:35 +02:00
Peter Conrad
08a66f52d3 Add option --pool-threads for easier testing 2018-10-06 11:05:45 +02:00
Peter Conrad
e336b0bb5c Added serial_valve 2018-10-05 15:02:31 +02:00
Peter Conrad
b0f4e55aee --list-content doesnt work properly until boost-1.59 2018-10-04 14:29:59 +02:00
Peter Conrad
afcb1e3543 Moved do_parallel to fc::thread-based worker pool implementation 2018-10-03 21:25:10 +02:00
Peter Conrad
9d54742741 Added a mechanism to get notifications when a thread is idle 2018-10-03 21:25:10 +02:00
Peter Conrad
fa7f6af01f Delete broken (wrt fc::current_thread()) move stuff 2018-10-03 21:17:37 +02:00
Peter Conrad
7e8debbad4 Want to see thread names also in RelWithDebInfo build 2018-10-03 21:17:37 +02:00
Peter Conrad
21724face7 Give asio threads separate names for better debugging 2018-10-03 21:17:33 +02:00
Peter Conrad
9954a3775c Added constructor for auto-fulfillment 2018-10-03 21:08:42 +02:00
Peter Conrad
ef3d36547e Removed unused file 2018-10-03 21:08:42 +02:00
Peter Conrad
34a2820c90 Added warning 2018-10-03 21:08:42 +02:00
Peter Conrad
6fe8f1d6e6 Added parallel sign/verify test 2018-10-03 21:08:42 +02:00
Peter Conrad
40b2843d15 Added test case for parallel hashing 2018-10-03 21:08:42 +02:00
Peter Conrad
3131c1df43 Implement helper function for real parallel execution 2018-10-03 10:51:15 +02:00
Peter Conrad
8e1b47a460
Merge pull request #76 from cogutvalera/issue_985
Log console output during replay to file #985
2018-10-01 15:05:47 +02:00
abitmore
70dbcc11e3 Added visit_local_member(...) methods to reflector 2018-09-30 10:11:28 -04:00
abitmore
b83108c41a Added static visit(...) methods to static_variant 2018-09-30 10:11:28 -04:00
abitmore
0fb65e4d38 Added to_variant(bool, ...) 2018-09-30 10:11:28 -04:00
Valera Cogut
fa7faee633 fc::create_directories before rotate_files 2018-09-24 22:09:22 +03:00
Valera Cogut
c544b384da Log console output during replay to file #985 2018-09-21 12:14:33 +03:00
Peter Conrad
2405081a18
Merge pull request #64 from bitshares/1088_unsigned_int
64 bits unsigned int
2018-08-22 17:12:15 +02:00
Peter Conrad
02a4516610 Handle b<0 2018-08-21 16:48:00 +02:00
Peter Conrad
79ff75423f Throw overflow_exception instead of silently cutting off data 2018-08-19 18:51:45 +02:00
Peter Conrad
1dcacbafc9 Removed signed_int 2018-08-19 18:26:46 +02:00
Peter Conrad
4b61f3ca3d Fixed alleged c&p bug 2018-08-19 11:01:05 +02:00
Peter Conrad
0c22469090 #993 - unit test 2018-08-19 11:01:05 +02:00
Peter Conrad
a39e0d1a8f Expanded tests for unsigned_int to 64 bits 2018-08-19 11:01:05 +02:00
Peter Conrad
72bcc8a926 Fix #993 - limit unpacking length of signed_int and unsigned_int 2018-08-19 11:01:05 +02:00
Peter Conrad
58ac6ae208 Changed some casts to uint64_t 2018-08-19 11:01:05 +02:00
Peter Conrad
9483935d64 Support 64 bit values in unsigned_int object 2018-08-19 11:01:05 +02:00
Peter Conrad
f8940a686a Added unit test for serialization/deserialization of unsigned_int 2018-08-19 11:01:05 +02:00
John M. Jones
7ac533b0c3
Merge pull request #73 from bitshares/fix-file-copy
Get around boost 1.67 boost::filesystem::copy null pointer dereferencing issue
2018-08-17 06:57:46 -05:00
John M. Jones
46ba4cca5e
Merge pull request #74 from bitshares/jmj_issue_1271
Missing FC Typenames (core issue #1217)
2018-08-13 09:17:19 -05:00
John Jones
9ba8886c8b Change string to static 2018-08-12 19:57:43 -05:00
John Jones
e896188875 additional templates for get_typename 2018-08-10 20:40:21 -05:00
John Jones
da33edc384 additional typenames 2018-08-10 15:33:25 -05:00
John Jones
48901cd1a4 correct templating of static variant 2018-08-10 14:40:47 -05:00
abitmore
64b4bd4900 Wrap system_error::what() in a string 2018-08-09 16:31:56 -04:00
abitmore
35cb63d3ea Call FC wrappers of copy and remove in rename()
to get around boost 1.67 boost::filesystem::copy() null pointer dereferencing issue
2018-08-09 12:57:08 -04:00
BITSG-Jerry
ce7cb0dd06 Check error after called boost::filesystem::copy()
and rethrow if found an error. This is to get around boost 1.67 issue https://svn.boost.org/trac10/ticket/13585
2018-08-09 12:38:09 -04:00
liukunyu
1eca4959e7 fix import_key crash for wallet 2018-08-09 10:38:26 +00:00
Abit
1a457caf33
Merge pull request #70 from cogutvalera/valera_issue_1193
Capture Ctrl+C in cli_wallet when not in daemon mode #1193
2018-07-30 15:00:05 +00:00
Valera Cogut
ec41a06300 reverting throw exception instead of raising SIGINT in order not to terminate cli_test early 2018-07-30 17:53:57 +03:00
Abit
8174558041
Merge pull request #68 from cogutvalera/valera_issue_1193
Capture Ctrl+C in cli_wallet when not in daemon mode #1193
2018-07-30 14:37:57 +00:00
Valera Cogut
40d928e57c raise SIGINT instead of throwing exception in cli_wallet quit command 2018-07-30 16:48:37 +03:00
John M. Jones
e310159ede
Merge pull request #67 from cogutvalera/valera_issue_597
fc::time_point_sec::to_iso_string is broken #597
2018-07-27 07:12:31 -05:00
Valera Cogut
0077926a7c removed comment 2018-07-27 15:00:10 +03:00
Valera Cogut
9e043fb7bc fc::time_point_sec::to_iso_string is broken - issue #597 2018-07-27 10:27:28 +03:00
Peter Conrad
5469bb960a
Merge pull request #63 from cogutvalera/valera_issue_1050
add quit command to cli_wallet #1050
2018-07-25 16:42:33 +02:00
John M. Jones
7080cf44ac
Merge pull request #66 from bitshares/jmj_stacktrace
Add missing header
2018-07-25 05:20:33 -05:00
Abit
f1e48d392e
Merge pull request #56 from nanomobile/valera_issue_809
Log file of current hour gets overwritten by default #809
2018-07-25 00:11:29 +00:00
jmjatlanta
2105bc0ee7 Add header 2018-07-23 19:50:54 -05:00
Abit
0604a5e184
Merge pull request #65 from bitshares/jmj_issue_999
Bump for websocketpp, bitshares-core issue 999
2018-07-23 22:16:10 +00:00
jmjatlanta
82987bb55e Bump for websocketpp, bitshares-core issue 999 2018-07-23 16:26:54 -05:00
Abit
ed168a4844
Merge pull request #62 from cogutvalera/valera_issue_929
RPC logging level inconsistency #929
2018-07-23 21:06:28 +00:00
Valera Cogut
18206552fc throwing fc:canceled_exception for quit cli wallet command 2018-07-20 16:44:31 +03:00
Valera Cogut
535fc869b5 remove hard coded method check to result check from quit command 2018-07-19 09:49:03 +03:00
Valera Cogut
0486a5f1e9 fixed issue #1050 2018-07-19 09:49:03 +03:00
Valera Cogut
ee25279db6 added idump for websocket_tls_server_impl 2018-07-17 20:50:32 +03:00
Valera Cogut
da5f2c3914 fixed issue #929 2018-07-17 20:50:32 +03:00
Valera Cogut
1169c2d966 removed using statement from header file 2018-07-17 19:46:43 +03:00
Peter Conrad
d679377312
Merge pull request #60 from bitshares/jmj_issue_1127
fix editline sigsev
2018-07-17 18:45:12 +02:00
Peter Conrad
996dc14588
Merge pull request #58 from RichardWeiYang/master
Trivial code refine
2018-07-17 18:44:50 +02:00
Peter Conrad
4dc373254a
Merge pull request #59 from cwyyprog/cwyy1
Fix compile error / make OPENSSL_CONF_SOURCE configurable
2018-07-17 18:44:21 +02:00
jmjatlanta
ce2e62f535 fix editline sigsev 2018-07-16 06:37:25 -05:00
Valera Cogut
20724f7ecc fixed issue #809 2018-07-09 17:17:32 +03:00
cwyy
650c0a3c62 fix hardcode of OPENSSL_CONF_SOURCE in CMakeLists.txt 2018-07-05 17:56:45 +08:00
Wei Yang
6d3184ff44 Fix two typo in variant.hpp 2018-07-05 13:50:40 +08:00
Wei Yang
e609d70334 Remove unnecessary structure definition in static_variant.hpp 2018-07-05 13:50:40 +08:00
cwyy
ac982cae2a fix compile error with vs2017 and boost 1.67 2018-06-30 14:10:38 +08:00
John M. Jones
d8437ac286
Merge pull request #54 from bitshares/jmj_issue_992
adjust asserts in fc/crypto
2018-06-07 04:27:43 -07:00
Peter Conrad
0dbf7ffc23
Merge pull request #49 from bitshares/travis_sonar
Modifications to run sonar-scanner during travis build
2018-06-05 15:05:11 +02:00
Alfredo Garcia
ea18aca0e2
Merge pull request #52 from bitshares/bz2-unused-linkage
Remove fc bz2 unused linkage
2018-06-04 10:35:27 -03:00
John Jones
59f503d643 adjust asserts in fc/crypto 2018-06-01 19:00:48 -05:00
Alfredo Garcia
0a90eff697
Merge pull request #7 from bitshares/openssl-1.1-support
Openssl 1.1 support
2018-05-31 17:32:21 -03:00
Alfredo Garcia
64aa56559d
Remove fc bz2 unused linkage 2018-05-30 21:59:06 -03:00
John M. Jones
36359f5895
Merge pull request #50 from bitshares/jmj_issue_762
Add parameterized constructor (part of Issue 762)
2018-05-29 12:46:25 -07:00
Peter Conrad
cff8e9694f
Merge pull request #51 from pmconrad/core_986_cleanup
Remove unused "smaz" compression
2018-05-29 20:22:26 +02:00
Peter Conrad
0fc569cbfc Remove unused "smaz" compression 2018-05-29 16:36:31 +02:00
John Jones
89106809d8 add parameterized constructor 2018-05-28 08:38:38 -05:00
John M. Jones
0d689a4894
Remove hard coded number of IO threads (#47)
This allows for control of the number of IO threads before their creation
2018-05-16 09:44:23 -07:00
Peter Conrad
a6671d6af4
Merge pull request #44 from pmconrad/dh_fix
Fixed diffie-hellman shared key computation
2018-05-15 18:47:13 +02:00
Peter Conrad
b3285b3bc2 Parallelize unit test execution 2018-05-13 10:52:37 +02:00
Peter Conrad
bb626649eb Conditional build with sonar 2018-05-11 22:14:24 +02:00
Peter Conrad
93d3362709 Modifications to run sonar-scanner during travis build 2018-05-11 21:57:19 +02:00
Peter Conrad
29ace9b07d Added specific test case for short secret 2018-05-11 18:13:15 +02:00
Peter Conrad
f0dfc64261 Fixed diffie-hellman shared key computation 2018-05-10 15:24:04 +02:00
Abit
d14daf861b
Merge pull request #41 from pmconrad/openssl-1.1-support
Ripped out unused blinding stuff
2018-05-08 11:18:39 +02:00
Abit
ccc213b72d
Merge pull request #43 from jmjatlanta/Issue_socket
Memory leak on socket destruction
2018-05-06 00:09:16 +02:00
John Jones
3661e835f8 Removed unused parameter 2018-05-04 11:05:20 -05:00
John Jones
cb2965991f Added comment to clarify test purpose 2018-05-04 07:47:37 -05:00
John Jones
58ef1c2c5d Merge remote-tracking branch 'upstream/master' into Issue_socket 2018-05-04 07:40:05 -05:00
Peter Conrad
a3272e4f9e Ripped out unused blinding stuff 2018-04-26 17:35:45 +02:00
Abit
9037ca3fbd
Merge pull request #40 from pmconrad/openssl-1.1-support
Fixed DH memory handling with openssl-1.1
2018-04-26 12:42:39 +02:00
Abit
51688042b0
Merge pull request #38 from jmjatlanta/Issue_727c
Add Boost::Stacktrace to Bitshares
2018-04-26 12:39:34 +02:00
Abit
000ef9a118
Merge pull request #36 from jmjatlanta/boost_1.66
Upgrade to Boost 1.65
2018-04-26 12:37:17 +02:00
Abit
056a326268
Merge pull request #39 from ihla/fix_project_editline_cmakelists
fix incorrect project_editline-build path
2018-04-26 12:08:29 +02:00
Peter Conrad
fccabf1eb6 Fixed blinding test + implementation 2018-04-21 21:42:45 +02:00
Peter Conrad
5706d58cdc Fixed DH memory handling with openssl-1.1 2018-04-21 20:39:40 +02:00
lubos.ilcik
b4fac94858 fix incorrect project_editline-build path 2018-04-18 13:54:20 +02:00
Fabian Schuh
c0db16bf3b Fix erros in unittest 2018-04-13 11:28:51 +02:00
Fabian Schuh
6b81aab6ef [websocketpp] update submodule and provide patched version via separate repository 2018-04-13 11:28:51 +02:00
Fabian Schuh
ef27d4b3a1 Initial work for openssl-1.1 support 2018-04-12 14:58:13 +02:00
Nathan Hourt
13d98e2cad Add OpenSSL 1.1.0 support
These changes should add support for openssl 1.1.0 while maintaining
compatibility with 1.0.2
2018-04-12 14:58:13 +02:00
John Jones
7db8176624 Moved headers within #if macro for cleanliness 2018-04-09 17:29:57 -05:00
John Jones
5383d5b481 boost::hash<fc::sha256> not used, removed 2018-04-09 10:14:00 -05:00
John Jones
133fe62048 Add comment to clarify 2 sections of code. 2018-04-09 08:59:58 -05:00
John Jones
a6738e3265 Added boost stacktrace to segfault handler 2018-04-09 08:11:38 -05:00
John Jones
b01ddeb35f Merge remote-tracking branch 'upstream/master' into boost_1.66 2018-04-09 07:35:08 -05:00
John M. Jones
18640e46e3
Add special handling for mac size_t and variant (#35) 2018-04-02 14:23:31 -05:00
John Jones
38191dcc00 added boost hash header 2018-03-29 15:34:15 -05:00
John Jones
652389644c removed boost_1.51 and interprocess class 2018-03-28 11:38:20 -05:00
Abit
4441e14807
Merge pull request #32 from bitshares/abitmore-patch-1
Remove -std=c++14 flag from CMakeLists.txt
2018-03-27 18:51:39 +02:00
Abit
4dbf6ee080
Merge pull request #34 from bitshares/msvc-editline
Skip editline when building in MSVC
2018-03-27 18:45:06 +02:00
abitmore
6dc06cd598 Skip editline when building in MSVC 2018-03-27 04:08:42 -04:00
Abit
91d294feca
Remove -std=c++14 flag from CMakeLists.txt 2018-03-25 20:27:09 +02:00
oxarbitrage
88d371b0fa
Merge pull request #31 from bitshares/fix-travis-logging
Pipe output to get around logging ANSI color issue
2018-03-23 20:02:11 -03:00
abitmore
52a5956106 Pipe output to get around logging ANSI color issue 2018-03-23 18:43:29 -04:00
John Jones
f84de73e66 added test to demonstrate issue 2018-03-23 17:34:07 -05:00
Abit
d286375e23
Merge pull request #27 from bitshares/oxarbitrage-patch-1
add travis build status
2018-03-23 23:20:02 +01:00
Abit
7e7e3e5fec
Merge pull request #30 from oxarbitrage/time_test
Add travis to FC
2018-03-23 23:15:30 +01:00
oxarbitrage
377235a401
comment out another test 2018-03-23 17:32:01 -03:00
oxarbitrage
6fae537fad
add notes to commented tests 2018-03-23 17:21:15 -03:00
oxarbitrage
eb9cc0be06
add note to commented test 2018-03-23 17:20:13 -03:00
Abit
0fe2e61b21
Merge pull request #28 from bitshares/variant_test
Logging fix
2018-03-23 21:11:08 +01:00
abitmore
5dcebe7b1f Suppress logging when testing mass logging 2018-03-23 14:31:46 -04:00
abitmore
f92671e1b5 Try to avoid throwing exception when logging 2018-03-23 13:19:52 -04:00
abitmore
a57879b3a9 Update test case for variant conversions 2018-03-23 12:46:14 -04:00
abitmore
1b3d53114f Add test case for variant conversions 2018-03-23 08:23:50 -04:00
Alfredo
8a96790c78 remove test 2018-03-22 21:49:27 -03:00
Alfredo
636a50f1f6 comment some failing tests 2018-03-22 21:36:28 -03:00
oxarbitrage
c2d1cfd999
add travis build status 2018-03-22 20:44:40 -03:00
abitmore
a3f8f2f004 Fix websocket_test 2018-03-22 12:42:24 -04:00
abitmore
0065cf00e1 Fix .travis.yml 2018-03-22 12:02:09 -04:00
abitmore
51ba34c586 Add .travis.yml 2018-03-22 11:52:01 -04:00
Abit
0a0d41e9a5
Merge pull request #25 from bitshares/jmjatlanta-patch-1
fixed macOS build
2018-03-22 16:33:16 +01:00
jmjatlanta
956085d72f fixed macOS build 2018-03-22 09:57:06 -05:00
Abit
3e7e0aa969
Merge pull request #24 from bitshares/abitmore-patch-1
Fix redefinition of default arg under macOS
2018-03-22 15:27:36 +01:00
Abit
6e42194f72
Fix redefinition of default arg under macOS 2018-03-22 15:08:56 +01:00
Abit
d5024e85f9
Merge pull request #12 from bitshares/oxarbitrage-patch-1
Add Doxyfile
2018-03-19 17:42:26 +01:00
Abit
2bb93c8b5d
Merge pull request #21 from pmconrad/variant_fix
Variant fix
2018-03-19 17:35:57 +01:00
Peter Conrad
1eb7b9d5c6 Added some missing checks, fixed indentation, handle different meanings of max_depth 2018-03-19 15:49:07 +01:00
Abit
efa4a504de
Merge pull request #22 from abitmore/fix-class-serialization
Fix class serialization
2018-03-18 14:48:20 +01:00
Peter Conrad
a91822616e Added max_depth to remaining variant conversions 2018-03-18 10:49:44 +01:00
abitmore
d9ac2691a1 Remove default pack/unpack functions for class 2018-03-14 17:20:48 -04:00
abitmore
85ea20e2c9 Deprecate default pack/unpack functions for class 2018-03-14 06:25:14 -04:00
abitmore
769dd980b7 Add tests for nested class object serialization 2018-03-14 06:15:01 -04:00
Peter Conrad
2f5f599e0d Moved LOG_*_DEPTH variable to new config.hpp 2018-03-13 22:33:21 +01:00
Peter Conrad
271a8377a6 Adapted API conversions, incomplete 2018-03-13 22:00:18 +01:00
Peter Conrad
dd9197c9d5 Added missing depth check 2018-03-13 22:00:18 +01:00
Peter Conrad
81c8d89341 Added max_depth parameter to variant conversions 2018-03-13 22:00:18 +01:00
Peter Conrad
32869351c9
Merge pull request #11 from openledger/sanitize
sanitizer issues
2018-03-13 21:45:53 +01:00
Peter Conrad
fca5058464
Merge branch 'master' into sanitize 2018-03-13 21:39:40 +01:00
Abit
67e60367a5
Merge pull request #15 from pmconrad/json_parsing_fix
JSON parsing fix from steem PR 2178
2018-03-13 21:36:15 +01:00
Peter Conrad
8f08591e46
Merge pull request #20 from abitmore/fix-serialization
Fix pack/unpack serialization
2018-03-13 21:13:45 +01:00
abitmore
43ac0b0520 Slightly improve performance for pack/unpack 2018-03-13 13:06:00 -04:00
abitmore
86e18663a0 Add max_depth parameter to pack/unpack functions 2018-03-11 17:31:55 -04:00
abitmore
782e7d687b Add test case for nested-object serialization 2018-03-11 17:21:44 -04:00
Peter Conrad
527daab6b7 Moved format_string from variant.cpp to string.cpp (it is declared in string.hpp), added handling of recursion errors 2018-03-09 18:52:01 +01:00
Peter Conrad
d24bee8bf4 Added test case for exception in exception handling 2018-03-09 18:51:48 +01:00
Peter Conrad
1331485c08 Stringify numbers >MAXINT or <MININT 2018-03-08 22:33:54 +01:00
Peter Conrad
f9802f6860 Added max_depth parameter to all to_/from_ methods 2018-03-08 22:33:41 +01:00
Peter Conrad
1412df18d1 Make broken_nul_parser usable 2018-03-08 22:33:27 +01:00
Abit
628548ca02
Merge pull request #17 from jmjatlanta/Issue_673
correctly handle list of methods
2018-03-08 19:39:11 +01:00
John Jones
9ee2bcf0a5 avoid double free 2018-03-08 11:05:34 -05:00
John Jones
2017ed911a fix memory leak 2018-03-08 10:46:23 -05:00
John Jones
43b81cb69b assuring that malloc gets freed 2018-03-08 07:40:20 -05:00
Peter Conrad
66ed9fc3dc Minor fixes 2018-03-07 22:42:43 +01:00
Abit
5f6e4d8523
Merge pull request #16 from bitshares/editline-build
Build editline
2018-03-07 20:51:30 +01:00
John Jones
5b5190a55c changed const to const ref 2018-03-07 09:44:35 -05:00
Peter Conrad
2bacd5fda8 Added broken_nul_parser to preserve previous behaviour 2018-03-07 15:44:18 +01:00
Peter Conrad
90137d400d Fix for recursion depth limitation 2018-03-07 15:44:10 +01:00
Peter Conrad
a7e0c887db Added test case for recursion depth 240 2018-03-07 15:44:01 +01:00
Peter Conrad
d336af82a6 Applied variant_from_stream fix from regular to relaxed 2018-03-07 15:43:49 +01:00
Peter Conrad
4bb8bf7832 Fixed relaxed parser wrt "" input 2018-03-07 15:43:38 +01:00
Peter Conrad
b4f3947cb1 Include variants_from_string in parser test 2018-03-07 15:43:25 +01:00
Peter Conrad
1ae3cc2fad Make unused parsers compile-time optional 2018-03-07 15:43:14 +01:00
Peter Conrad
cb9c61fa2d Avoid legacy_generator 2018-03-07 15:43:05 +01:00
Peter Conrad
43fabf618f Code deduplication 2018-03-07 15:42:46 +01:00
Peter Conrad
e37d9a5051 Code cleanups and simplifications 2018-03-07 15:42:35 +01:00
Peter Conrad
8c09ff09fc Added json write/validate/read test 2018-03-07 15:42:19 +01:00
John Jones
b3053d0421 adjust spacing, add const, remove unnecessary variable, bad malloc check 2018-03-07 02:55:59 -05:00
John Jones
c225488cd4 replace tabs with spaces 2018-03-06 17:17:09 -05:00
Abit
b8e5640238
Merge pull request #19 from bitshares/abitmore-patch-1
Correctly set default C++ standard to c++11
2018-03-06 20:39:42 +01:00
Abit
d810971c83
Merge pull request #18 from bitshares/fork-websocketpp
Update websocketpp submodule to a forked and patched version
2018-03-06 20:38:56 +01:00
Abit
ebdb5eacea
Correctly set default C++ standard to c++11 2018-03-06 20:37:23 +01:00
John Jones
1fe7d4be46 Trying to get the #$%@$ tabs to disappear 2018-03-06 11:44:00 -05:00
abitmore
b5fec06152 Update websocketpp to a forked and patched version 2018-03-06 16:28:20 +00:00
abitmore
0242a05111 Remove FindEditline.cmake 2018-03-06 16:16:52 +00:00
John Jones
f5d68e9336 Adjusting for formatting guidelines 2018-03-06 09:25:38 -05:00
abitmore
d33092f86c More changes on cmake file for editline 2018-03-06 13:47:45 +00:00
Peter Conrad
4d782e894f Deduplicate some code 2018-03-06 14:46:34 +01:00
Peter Conrad
52f6810735 Fixed from_file 2018-03-06 14:46:20 +01:00
Peter Conrad
72e96e3c1d Added first json test case 2018-03-06 14:43:35 +01:00
Peter Conrad
0c75709488 Added unit tests for stringstream, [io]fstream and buffered_[io]stream 2018-03-06 14:43:17 +01:00
abitmore
4258f4f98b Update cmake file for editline 2018-03-06 13:41:40 +00:00
John Jones
5f3ace5ca3 Added space at end of completed command 2018-03-06 08:06:18 -05:00
John Jones
e766ea9429 correctly handle list of methods 2018-03-05 14:37:14 -05:00
abitmore
ade96c1213 Build editline
TODO: the cmake script is copied from the secp256k1 part in the
      same file, may need to review/fix the MSVC and MinGW part.
2018-03-05 00:48:11 +00:00
Peter Conrad
b12205caf6 Minor optimization 2018-03-02 21:13:03 +01:00
Peter Conrad
bbe2a8b289 JSON parsing fix from steem PR 2178 2018-03-01 18:58:23 +01:00
Abit
48dbc096aa
Merge pull request #14 from jmjatlanta/Issue_673
Replace Readline, bitshares-core issue 673
2018-02-28 21:42:36 +01:00
John Jones
046c65016b Replaced tab with spaces 2018-02-26 16:54:32 -05:00
John Jones
9d5a32c536 Moved assignment from within a loop 2018-02-26 16:47:38 -05:00
John Jones
79cf3d2b3a code cleanup 2018-02-26 16:43:54 -05:00
John Jones
abb4b9b0ab Added editline as submodule 2018-02-20 15:18:47 -05:00
oxarbitrage
4818776987
Add Doxyfile 2018-02-06 18:36:07 -03:00
Anton Autushka
7d7872cb7b some minor fixes 2018-02-06 15:37:14 +03:00
Anton Autushka
bf86466be1 In static_variant use int64_t as a tag type 2018-02-06 13:00:51 +03:00
Alexey Frolov
1ae7f6bb02 FIXES:
- 'bloom_test_1': infinite loop if file not exists
- 'websocket_test': uncatched exceptions
- 'fc_crypto*' test_stream<>: uninitialized variable (hash)
- 'blowfish_chain_test': using memory after allocated heap
- memcmp: passing nullptr, when non-null expected
- undefined behavior: return value from function
- static_variant: member alignment - performance issue on 64-bit arch
- memory leak: fc::thread cleanup in asio thread
- warning: signed-unsigned comparison
- warning: unused variables
2018-02-05 12:19:06 +03:00
Alexey Frolov
5138c58e09 sanitize, remove warnings 2018-02-02 15:29:46 +03:00
Abit
226391bbbc
Merge pull request #10 from pmconrad/core_597
Added unit test to demonstrate problem with time_point_sec::to_iso_string
2018-01-23 18:24:52 +01:00
Peter Conrad
c02fe0aaf6 Added unit test to demonstrate problem with time_point_sec::to_iso_string 2018-01-23 17:58:37 +01:00
oxarbitrage
a1e1599f97
Merge pull request #9 from bitshares/abitmore-patch-1
static_variant::set_which() rejects negative param
2018-01-21 09:34:55 -03:00
Abit
dffe2a444e
static_variant::set_which() rejects negative param 2018-01-20 16:54:09 +01:00
oxarbitrage
7cd9f1c7a4
Merge pull request #6 from cwyyprog/master
Fix compile error
2017-11-14 17:46:05 -03:00
oxarbitrage
2a5dd4f45d
Merge pull request #5 from aautushka/master
Boost 1.61/1.62/1.63 compatibility fix
2017-11-14 16:49:39 -03:00
cwyyprog
56d5d45b08
Merge pull request #2 from cwyyprog/cwyyprog-fix-for-build-with-gcc7.2-2
fix compile error
2017-11-14 17:23:19 +08:00
cwyyprog
1296ebb485
Merge pull request #1 from cwyyprog/fix-for-build-with-gcc-7.2-1
Update static_variant.hpp
2017-11-14 17:23:01 +08:00
cwyyprog
d157c2c756
Update typename.hpp 2017-11-14 17:11:24 +08:00
cwyyprog
e754b4940e
Update static_variant.hpp 2017-11-14 17:09:08 +08:00
Anton Autushka
20836338d2 Suppress coroutines deprecation warning in boost 1.62 2017-11-09 15:41:44 +03:00
Anton Autushka
c2a37a83bd Boost 1.61 compatibility fix 2017-11-09 15:18:58 +03:00
325 changed files with 10760 additions and 15259 deletions

170
.github/workflows/build-and-test.yml vendored Normal file
View file

@ -0,0 +1,170 @@
name: Github Autobuild
on: [ push, pull_request ]
env:
CCACHE_COMPRESS: exists means true
CCACHE_SLOPPINESS: include_file_ctime,include_file_mtime,time_macros
jobs:
test-release:
name: Build and run tests in Ubuntu, Release mode
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: |
sudo apt-get install -y \
ccache \
parallel \
libboost-thread-dev \
libboost-iostreams-dev \
libboost-date-time-dev \
libboost-system-dev \
libboost-filesystem-dev \
libboost-program-options-dev \
libboost-chrono-dev \
libboost-test-dev \
libboost-context-dev \
libboost-regex-dev \
libboost-coroutine-dev
- uses: actions/checkout@v1
with:
submodules: recursive
- name: Configure
run: |
mkdir -p _build
pushd _build
export -n BOOST_ROOT BOOST_INCLUDEDIR BOOST_LIBRARYDIR
cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_CXX_OUTPUT_EXTENSION_REPLACE=ON \
-D CMAKE_C_COMPILER=gcc \
-D CMAKE_C_COMPILER_LAUNCHER=ccache \
-D CMAKE_CXX_COMPILER=g++ \
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
..
popd
- name: Load Cache
uses: actions/cache@v1
with:
path: ccache
key: ccache-release-${{ github.ref }}-${{ github.sha }}
restore-keys: |
ccache-release-${{ github.ref }}-
ccache-release-
ccache-
- name: Build
run: |
export CCACHE_DIR="$GITHUB_WORKSPACE/ccache"
mkdir -p "$CCACHE_DIR"
make -j 2 -C _build
- name: Test
run: |
parallel echo Running {}\; sh -c "_build/tests/{}" <<_EOT_
all_tests -l message
bloom_test -- README.md
ecc_test README.md
hmac_test
task_cancel_test
_EOT_
test-debug:
name: Build and run tests in Ubuntu, Debug mode
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: |
sudo apt-get install -y \
ccache \
parallel \
libboost-thread-dev \
libboost-iostreams-dev \
libboost-date-time-dev \
libboost-system-dev \
libboost-filesystem-dev \
libboost-program-options-dev \
libboost-chrono-dev \
libboost-test-dev \
libboost-context-dev \
libboost-regex-dev \
libboost-coroutine-dev
- uses: actions/checkout@v1
with:
submodules: recursive
- name: Configure
run: |
mkdir -p _build
pushd _build
export -n BOOST_ROOT BOOST_INCLUDEDIR BOOST_LIBRARYDIR
cmake -D CMAKE_BUILD_TYPE=Debug \
-D CMAKE_CXX_OUTPUT_EXTENSION_REPLACE=ON \
-D CMAKE_C_COMPILER=gcc \
-D CMAKE_C_COMPILER_LAUNCHER=ccache \
-D CMAKE_CXX_COMPILER=g++ \
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
..
popd
- name: Load Cache
uses: actions/cache@v1
with:
path: ccache
key: ccache-debug-${{ github.ref }}-${{ github.sha }}
restore-keys: |
ccache-debug-${{ github.ref }}-
ccache-debug-
ccache-
- name: Build
run: |
export CCACHE_DIR="$GITHUB_WORKSPACE/ccache"
mkdir -p "$CCACHE_DIR"
make -j 2 -C _build
- name: Test
run: |
parallel echo Running {}\; sh -c "_build/tests/{}" <<_EOT_
all_tests -l message
bloom_test -- README.md
ecc_test README.md
hmac_test
task_cancel_test
_EOT_
test-macos:
name: Build and run tests in macOS
runs-on: macos-latest
steps:
- name: Install dependencies
run: |
brew install autoconf automake libtool
brew install ccache
brew search boost
brew install boost@1.60
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Configure
run: |
mkdir -p _build
pushd _build
cmake -D CMAKE_BUILD_TYPE=Release \
-D CMAKE_C_COMPILER_LAUNCHER=ccache \
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
-D BOOST_ROOT=/usr/local/opt/boost@1.60 \
-D OPENSSL_ROOT_DIR=/usr/local/opt/openssl \
..
popd
- name: Load Cache
uses: actions/cache@v1
with:
path: ccache
key: ccache-osx-${{ github.ref }}-${{ github.sha }}
restore-keys: |
ccache-osx-${{ github.ref }}-
ccache-osx-
- name: Build
run: |
export CCACHE_DIR="$GITHUB_WORKSPACE/ccache"
mkdir -p "$CCACHE_DIR"
make -j 2 -C _build
df -h
- name: Unit-Tests
run: |
pushd _build/tests
./all_tests -l message
./bloom_test -- README.md
./ecc_test README.md
./hmac_test
./task_cancel_test

2
.gitignore vendored Executable file → Normal file
View file

@ -36,7 +36,7 @@ Release/
CMakeCache.txt
CMakeFiles
Makefile
*.cmake
cmake_install.cmake
*.cbp
libfc.a

10
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,10 @@
include:
- template: Jobs/Code-Quality.gitlab-ci.yml
stages:
- test
trigger_build_peerplays:
stage: test
script:
- "curl -X POST -F token=$CI_JOB_TOKEN -F ref=$REF_NAME https://gitlab.com/api/v4/projects/10735589/trigger/pipeline"

6
.gitmodules vendored Executable file → Normal file
View file

@ -1,3 +1,9 @@
[submodule "vendor/diff-match-patch-cpp-stl"]
path = vendor/diff-match-patch-cpp-stl
url = https://github.com/leutloff/diff-match-patch-cpp-stl
[submodule "vendor/secp256k1-zkp"]
path = vendor/secp256k1-zkp
url = https://github.com/bitshares/secp256k1-zkp.git
[submodule "vendor/editline"]
path = vendor/editline
url = https://github.com/troglobit/editline.git

37
.travis.yml Normal file
View file

@ -0,0 +1,37 @@
language: c++
cache: ccache
git:
depth: 1
dist: xenial
sudo: true
install:
- sudo apt-get install --allow-unauthenticated libboost-thread-dev libboost-iostreams-dev libboost-date-time-dev libboost-system-dev libboost-filesystem-dev libboost-program-options-dev libboost-chrono-dev libboost-test-dev libboost-context-dev libboost-regex-dev libboost-coroutine-dev cmake parallel
addons:
sonarcloud:
organization: "flwyiq7go36p6lipr64tbesy5jayad3q"
token:
secure: "Y0DhI1Fn7QXqdYF5kCUFV0l0XUOp5iYp+kHYVAWpt1HSYN5889GTO3SgsZoT7+Cmo1HLAe2P8tSCzz3lECDI0rWMuk7wxFRMVmnxBpbR5P61+Mhe4t/LhSGzuT3PAscttFNPexpDmePKO0EgTY7PemMtXR8LZ2O/RngAMWWfH0Wmyngy68Bm9CvpWfW9aQ8ZUMsjpbDmbaE9dN6FLABE1YZzVL+9SA07gOSQzry/SLbRY19+g9OicaAoCdQCdvIem6af1qIy0x5uDFfz4x1Sows9awBOsAOf6V5WmFlV21YwR1RhT+4WffB+VrMYOF8YpzoUrS+CPmPWlkDDN3fuKsqRGYpbBIxyqBQ+rahDtXfoD5ZbGY1UYTbrHGD8VTNVbvdqAsVEfgZ8ci7NxBnIL3VDduxP1qb46chTJb9KeeIETtN8qTdfsZyudveZLKmULKah8uaOkMX2bJT6oikluVXJnI0OybHQrrMwHula/qmEj3FnC3KKPmL84F/6DSPiiojx+qsMa0STQE9ZwzeJPc8KjllsTYKL492IDQJDXkWGS+PwlOXResr2Dhu/rfYKy6qpHQJzreoPcIRmeM7rFamJZHkqdaldJGm+iQacX2byKJ/tT93IM6hW0BEi4Haucwn1f0Ig5tzE8mzro1/Rj35a9ti2jmO0NWjyeBwnCVo="
env:
global:
- CCACHE_COMPRESS=exists_means_true
- CCACHE_MAXSIZE=1Gi
- CCACHE_SLOPPINESS=include_file_ctime,include_file_mtime,time_macros
script:
- ccache -s
- cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=--coverage -DCMAKE_CXX_FLAGS=--coverage -DBoost_USE_STATIC_LIBS=OFF -DCMAKE_CXX_OUTPUT_EXTENSION_REPLACE=ON .
- 'which build-wrapper-linux-x86-64 && build-wrapper-linux-x86-64 --out-dir bw-output make -j 2 || make -j 2'
- set -o pipefail
- tests/run-parallel-tests.sh tests/all_tests -l message
- tests/hmac_test 2>&1 | cat
- tests/ecc_test README.md 2>&1 | cat
- 'find CMakeFiles/fc.dir -type d | while read d; do gcov -o "$d" "${d/CMakeFiles*.dir/./}"/*.cpp; done >/dev/null'
- 'which sonar-scanner && sonar-scanner || true'
- ccache -s

271
CMakeLists.txt Executable file → Normal file
View file

@ -1,8 +1,19 @@
#
# Defines fc library target.
CMAKE_MINIMUM_REQUIRED( VERSION 3.2 FATAL_ERROR )
PROJECT( fc )
CMAKE_MINIMUM_REQUIRED( VERSION 2.8.12 )
set( CMAKE_CXX_STANDARD 14 )
SET( CMAKE_CXX_STANDARD_REQUIRED ON )
set( FC_BUILD_DYNAMIC_LIBRARIES OFF CACHE BOOL "Whether FC should build as a dynamic library rather than static" )
if( "${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang|GNU$" )
set( CMAKE_CXX_EXTENSIONS ON ) # for __int128 support
else( "${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang|GNU$" )
set( CMAKE_CXX_EXTENSIONS OFF )
endif( "${CMAKE_CXX_COMPILER_ID}" MATCHES "^(Apple)?Clang|GNU$" )
MESSAGE(STATUS "Configuring project fc located in: ${CMAKE_CURRENT_SOURCE_DIR}")
SET( CMAKE_AUTOMOC OFF )
@ -12,9 +23,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/GitVersionGen")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
INCLUDE(GetPrerequisites)
INCLUDE( VersionMacros )
INCLUDE( SetupTargetMacros )
INCLUDE(GetGitRevisionDescription)
INCLUDE(CheckLibraryExists)
get_git_head_revision(GIT_REFSPEC FC_GIT_REVISION_SHA)
get_git_unix_timestamp(FC_GIT_REVISION_UNIX_TIMESTAMP)
@ -24,38 +34,23 @@ SET( DEFAULT_LIBRARY_INSTALL_DIR lib/ )
SET( DEFAULT_EXECUTABLE_INSTALL_DIR bin/ )
SET( CMAKE_DEBUG_POSTFIX _debug )
SET( BUILD_SHARED_LIBS NO )
SET( ECC_IMPL secp256k1 CACHE STRING "secp256k1 or openssl or mixed" )
SET( FC_USE_FULL_ZLIB FALSE CACHE BOOL "TRUE to try to use full zlib for compression, FALSE to use miniz.c")
if( FC_USE_FULL_ZLIB )
find_package( ZLIB REQUIRED )
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFC_USE_FULL_ZLIB")
endif()
set(platformBitness 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(platformBitness 64)
endif()
SET (ORIGINAL_LIB_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
SET(BOOST_COMPONENTS)
LIST(APPEND BOOST_COMPONENTS thread date_time filesystem system program_options signals serialization chrono unit_test_framework context locale iostreams)
SET( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" )
IF( ECC_IMPL STREQUAL openssl )
SET( ECC_REST src/crypto/elliptic_impl_pub.cpp )
ELSE( ECC_IMPL STREQUAL openssl )
SET( ECC_LIB secp256k1 )
IF( ECC_IMPL STREQUAL mixed )
SET( ECC_REST src/crypto/elliptic_impl_priv.cpp src/crypto/elliptic_impl_pub.cpp )
ELSE( ECC_IMPL STREQUAL mixed )
SET( ECC_REST src/crypto/elliptic_impl_priv.cpp )
ENDIF( ECC_IMPL STREQUAL mixed )
ENDIF( ECC_IMPL STREQUAL openssl )
LIST(APPEND BOOST_COMPONENTS coroutine thread date_time filesystem system program_options serialization chrono unit_test_framework context iostreams regex)
# boost::endian is also required, but FindBoost can't handle header-only libs
if(${FC_BUILD_DYNAMIC_LIBRARIES})
SET( Boost_USE_STATIC_LIBS OFF CACHE STRING "ON or OFF" )
else()
SET( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" )
endif()
# Configure secp256k1-zkp
if ( MSVC )
if ( WIN32 )
# autoconf won't work here, hard code the defines
set( SECP256K1_DIR "${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp" )
@ -71,27 +66,24 @@ if ( MSVC )
USE_SCALAR_8X32
USE_SCALAR_INV_BUILTIN )
set_target_properties( secp256k1 PROPERTIES COMPILE_DEFINITIONS "${SECP256K1_BUILD_DEFINES}" LINKER_LANGUAGE C )
else ( MSVC )
else ( WIN32 )
include(ExternalProject)
if ( MINGW )
if( CMAKE_POSITION_INDEPENDENT_CODE )
set( SECP_USE_PIC --with-pic )
else( CMAKE_POSITION_INDEPENDENT_CODE )
set( SECP_USE_PIC "" )
endif()
ExternalProject_Add( project_secp256k1
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/vendor/secp256k1-zkp
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp/configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/vendor/secp256k1-zkp --with-bignum=no --host=x86_64-w64-mingw32
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp/configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/vendor/secp256k1-zkp --with-bignum=no ${SECP_USE_PIC}
BUILD_COMMAND make
INSTALL_COMMAND true
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/vendor/secp256k1-zkp/src/project_secp256k1-build/.libs/libsecp256k1.a
)
else ( MINGW )
ExternalProject_Add( project_secp256k1
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/vendor/secp256k1-zkp
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp/configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/vendor/secp256k1-zkp --with-bignum=no
BUILD_COMMAND make
INSTALL_COMMAND true
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/vendor/secp256k1-zkp/src/project_secp256k1-build/.libs/libsecp256k1.a
)
endif ( MINGW )
ExternalProject_Add_Step(project_secp256k1 autogen
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp/autogen.sh
@ -104,70 +96,91 @@ else ( MSVC )
set_property(TARGET secp256k1 PROPERTY IMPORTED_LOCATION ${binary_dir}/.libs/libsecp256k1${CMAKE_STATIC_LIBRARY_SUFFIX})
set_property(TARGET secp256k1 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp/include)
add_dependencies(secp256k1 project_secp256k1)
install( FILES ${binary_dir}/.libs/libsecp256k1${CMAKE_STATIC_LIBRARY_SUFFIX} DESTINATION lib/cryptonomex )
endif ( MSVC )
if (${FC_BUILD_DYNAMIC_LIBRARIES})
FILE(GLOB SECP_SHARED ${binary_dir}/.libs/libsecp256k1.so*)
endif()
install( FILES ${binary_dir}/.libs/libsecp256k1${CMAKE_STATIC_LIBRARY_SUFFIX} ${SECP_SHARED} DESTINATION lib/cryptonomex )
endif ( WIN32 )
# End configure secp256k1-zkp
# Configure editline
if ( NOT WIN32 )
include(ExternalProject)
ExternalProject_Add( project_editline
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/vendor/editline
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendor/editline
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/vendor/editline/configure --prefix=${CMAKE_CURRENT_BINARY_DIR}/vendor/editline CFLAGS=-fPIC
BUILD_COMMAND make
INSTALL_COMMAND true
BUILD_BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/vendor/editline/src/project_editline-build/src/.libs/libeditline.a
)
ExternalProject_Add_Step(project_editline autogen
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/vendor/editline
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/vendor/editline/autogen.sh
DEPENDERS configure
)
ExternalProject_Get_Property(project_editline binary_dir)
add_library(editline STATIC IMPORTED)
set_property(TARGET editline PROPERTY IMPORTED_LOCATION ${binary_dir}/src/.libs/libeditline${CMAKE_STATIC_LIBRARY_SUFFIX})
set_property(TARGET editline PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/vendor/editline/include)
add_dependencies(editline project_editline)
if (${FC_BUILD_DYNAMIC_LIBRARIES})
FILE(GLOB EDITLINE_SHARED ${binary_dir}/src/.libs/libeditline.so*)
endif()
install( FILES ${binary_dir}/src/.libs/libeditline${CMAKE_STATIC_LIBRARY_SUFFIX} ${EDITLINE_SHARED} DESTINATION lib/cryptonomex )
endif ( NOT WIN32 )
# End configure editline
IF( WIN32 )
MESSAGE(STATUS "Configuring fc to build on Win32")
set( RPCRT4 rpcrt4 )
#boost
SET(BOOST_ROOT $ENV{BOOST_ROOT})
# set(Boost_USE_DEBUG_PYTHON ON)
if ($ENV{BOOST_ROOT})
SET(BOOST_ROOT $ENV{BOOST_ROOT})
endif()
set(Boost_USE_DEBUG_PYTHON ON)
set(Boost_USE_MULTITHREADED ON)
set(BOOST_ALL_DYN_LINK OFF) # force dynamic linking for all libraries
FIND_PACKAGE(Boost 1.53 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
# For Boost 1.53 on windows, coroutine was not in BOOST_LIBRARYDIR and do not need it to build, but if boost versin >= 1.54, find coroutine otherwise will cause link errors
IF(NOT "${Boost_VERSION}" MATCHES "1.53(.*)")
SET(BOOST_LIBRARIES_TEMP ${Boost_LIBRARIES})
FIND_PACKAGE(Boost 1.54 REQUIRED COMPONENTS coroutine)
LIST(APPEND BOOST_COMPONENTS coroutine)
SET(Boost_LIBRARIES ${BOOST_LIBRARIES_TEMP} ${Boost_LIBRARIES})
ENDIF()
LIST(APPEND PLATFORM_SPECIFIC_LIBS ws2_32 crypt32 mswsock userenv)
set( PLATFORM_SPECIFIC_LIBS wsock32.lib ws2_32.lib userenv.lib)
# iphlpapi.lib
ELSE(WIN32)
MESSAGE(STATUS "Configuring fc to build on Unix/Apple")
LIST(APPEND BOOST_COMPONENTS coroutine)
FIND_PACKAGE(Boost 1.53 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a;.so")
IF(NOT APPLE)
# Linux or other unix
SET(rt_library rt )
SET(pthread_library pthread)
ENDIF(NOT APPLE)
ENDIF(WIN32)
set(Boost_DIR "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/Boost")
FIND_PACKAGE(Boost CONFIG COMPONENTS ${BOOST_COMPONENTS} )
IF(NOT WIN32)
MESSAGE(STATUS "Configuring fc to build on Unix/Apple")
IF(NOT "$ENV{OPENSSL_ROOT_DIR}" STREQUAL "")
IF(NOT APPLE AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
SET(rt_library rt )
ENDIF(NOT APPLE AND NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
ENDIF(NOT WIN32)
IF($ENV{OPENSSL_ROOT_DIR})
set(OPENSSL_ROOT_DIR $ENV{OPENSSL_ROOT_DIR} )
set(OPENSSL_INCLUDE_DIR ${OPENSSL_ROOT_DIR}/include)
message(STATUS "Setting up OpenSSL root and include vars to ${OPENSSL_ROOT_DIR}, ${OPENSSL_INCLUDE_DIR}")
ENDIF()
IF( LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB )
LIST( APPEND PLATFORM_SPECIFIC_LIBS atomic )
ENDIF( LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB )
find_package(OpenSSL REQUIRED)
set( CMAKE_FIND_LIBRARY_SUFFIXES ${ORIGINAL_LIB_SUFFIXES} )
option( UNITY_BUILD OFF )
set( fc_sources
src/uint128.cpp
src/real128.cpp
src/popcount.cpp
src/variant.cpp
src/exception.cpp
src/variant_object.cpp
src/static_variant.cpp
src/thread/thread.cpp
src/thread/thread_specific.cpp
src/thread/future.cpp
@ -175,10 +188,11 @@ set( fc_sources
src/thread/spin_lock.cpp
src/thread/spin_yield_lock.cpp
src/thread/mutex.cpp
src/thread/parallel.cpp
src/thread/non_preemptable_scope_check.cpp
src/asio.cpp
src/string.cpp
src/shared_ptr.cpp
src/stacktrace.cpp
src/time.cpp
src/utf8.cpp
src/io/iostream.cpp
@ -188,17 +202,11 @@ set( fc_sources
src/io/sstream.cpp
src/io/json.cpp
src/io/varint.cpp
src/io/console.cpp
src/filesystem.cpp
src/interprocess/signals.cpp
src/interprocess/file_mapping.cpp
src/interprocess/mmap_struct.cpp
src/interprocess/file_mutex.cpp
src/rpc/cli.cpp
src/rpc/http_api.cpp
src/rpc/json_connection.cpp
src/rpc/state.cpp
src/rpc/bstate.cpp
src/rpc/websocket_api.cpp
src/log/log_message.cpp
src/log/logger.cpp
@ -212,34 +220,29 @@ set( fc_sources
src/crypto/aes.cpp
src/crypto/crc.cpp
src/crypto/city.cpp
src/crypto/base36.cpp
src/crypto/base58.cpp
src/crypto/base64.cpp
src/crypto/bigint.cpp
src/crypto/hex.cpp
src/crypto/sha1.cpp
src/crypto/ripemd160.cpp
src/crypto/hash160.cpp
src/crypto/sha256.cpp
src/crypto/sha224.cpp
src/crypto/sha512.cpp
src/crypto/md5.cpp
src/crypto/dh.cpp
src/crypto/blowfish.cpp
src/crypto/elliptic_common.cpp
${ECC_REST}
src/crypto/elliptic_${ECC_IMPL}.cpp
src/crypto/elliptic_impl_priv.cpp
src/crypto/elliptic_secp256k1.cpp
src/crypto/rand.cpp
src/network/tcp_socket.cpp
src/network/udp_socket.cpp
src/network/http/http_connection.cpp
src/network/http/http_server.cpp
src/network/http/websocket.cpp
src/network/ip.cpp
src/network/ntp.cpp
src/network/rate_limiting.cpp
src/network/resolve.cpp
src/network/url.cpp
src/compress/smaz.cpp
src/compress/zlib.cpp
)
@ -255,31 +258,23 @@ list(APPEND sources ${fc_headers})
add_subdirectory( vendor/websocketpp EXCLUDE_FROM_ALL )
setup_library( fc SOURCES ${sources} LIBRARY_TYPE STATIC )
if (NOT ${FC_BUILD_DYNAMIC_LIBRARIES} )
add_library( fc ${sources} )
else()
add_library( fc SHARED ${sources} )
endif()
install( TARGETS fc LIBRARY DESTINATION lib ARCHIVE DESTINATION lib )
install( DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION include )
# begin readline stuff
find_package(Curses)
find_package(Readline)
file(GLOB HEADERS "include/bts/cli/*.hpp")
if (READLINE_FOUND)
target_compile_definitions (fc PRIVATE HAVE_READLINE)
set(readline_libraries ${Readline_LIBRARY})
if (CURSES_FOUND)
list(APPEND readline_libraries ${CURSES_LIBRARY})
endif()
set(readline_includes ${Readline_INCLUDE_DIR})
endif()
# begin editline stuff
if(WIN32)
target_compile_definitions( fc PRIVATE _CRT_NONSTDC_NO_DEPRECATE )
else(WIN32)
target_compile_definitions( fc PRIVATE HAVE_EDITLINE )
set( editline_libraries editline )
endif(WIN32)
# end readline stuff
if( NOT CPP_STANDARD )
set( CPP_STANDARD, "-std=c++11" )
endif()
# end editline stuff
IF(WIN32)
target_compile_definitions(fc PUBLIC WIN32 NOMINMAX _WIN32_WINNT=0x0501 _CRT_SECURE_NO_WARNINGS
@ -302,12 +297,12 @@ ELSE()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall")
IF(APPLE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPP_STANDARD} -stdlib=libc++ -Wall")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Wall")
ELSE()
if( NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
target_compile_options(fc PUBLIC ${CPP_STANDARD} -Wall -fnon-call-exceptions)
target_compile_options(fc PUBLIC -Wall -fnon-call-exceptions)
endif()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPP_STANDARD} -Wall -fnon-call-exceptions")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fnon-call-exceptions")
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
if( CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.0.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0.0 )
@ -329,6 +324,7 @@ ENDIF(APPLE)
if( ZLIB_FOUND )
MESSAGE( STATUS "zlib found" )
target_include_directories(fc PUBLIC ${ZLIB_INCLUDE_DIRS})
add_definitions( -DHAS_ZLIB )
else()
MESSAGE( STATUS "zlib not found" )
@ -360,24 +356,26 @@ target_include_directories(fc
${OPENSSL_INCLUDE_DIR}
"vendor/diff-match-patch-cpp-stl"
${CMAKE_CURRENT_SOURCE_DIR}/vendor/websocketpp
"${readline_includes}"
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/vendor/secp256k1-zkp
)
#target_link_libraries( fc PUBLIC ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${BZIP2_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${ECC_LIB} )
IF(NOT WIN32)
set(LINK_USR_LOCAL_LIB -L/usr/local/lib)
ENDIF()
target_link_libraries( fc PUBLIC ${LINK_USR_LOCAL_LIB} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library} ${readline_libraries} ${ECC_LIB} )
target_link_libraries( fc PUBLIC ${LINK_USR_LOCAL_LIB} ${OPENSSL_LIBRARIES} ${ZLIB_LIBRARIES} ${Boost_LIBRARIES}
${PLATFORM_SPECIFIC_LIBS} ${RPCRT4} ${CMAKE_DL_LIBS} ${rt_library}
${editline_libraries} secp256k1 ${CMAKE_REQUIRED_LIBRARIES} )
if(MSVC)
set_source_files_properties( src/network/http/websocket.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
endif(MSVC)
if(WIN32 AND MSVC)
set_source_files_properties( src/network/http/websocket.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
elseif(WIN32 AND MINGW)
set_source_files_properties( src/network/http/websocket.cpp PROPERTIES LINK_FLAGS "-mbig-obj" )
endif()
IF(NOT Boost_UNIT_TEST_FRAMEWORK_LIBRARY MATCHES "\\.(a|lib)$")
IF(Boost_UNIT_TEST_FRAMEWORK_LIBRARY MATCHES "\\.(so|dll)$" OR FC_BUILD_DYNAMIC_LIBRARIES)
IF(MSVC)
add_definitions(/DBOOST_TEST_DYN_LINK)
ELSE(MSVC)
@ -389,18 +387,10 @@ include_directories( vendor/websocketpp )
add_subdirectory(tests)
if(WIN32)
if(MSVC)
# add addtional import library on windows platform
target_link_libraries( fc PUBLIC crypt32.lib)
# now generate a list of the DLLs we're using to use during the install process
include (ParseLibraryList)
PARSE_LIBRARY_LIST(${Boost_LIBRARIES}
FOUND parseOk
DEBUG Boost_LIBRARIES_DEBUG
OPT Boost_LIBRARIES_RELEASE
GENERAL Boost_LIBRARIES_GENERAL)
#Variable will hold list of .pdb files generated for libraries the 'fc' module is linked to
set(INTERFACE_LINK_PDB_RELEASE)
@ -469,29 +459,8 @@ if(WIN32)
set_property(TARGET fc PROPERTY SHARED_LIBRARIES_DEBUG ${SHARED_LIBRARIES_DEBUG})
set_property(TARGET fc PROPERTY SHARED_LIBRARIES_RELEASE ${SHARED_LIBRARIES_RELEASE})
endif(WIN32)
endif(MSVC)
SET(OPENSSL_CONF_TARGET )
IF(DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
SET (OPENSSL_CONF_TARGET ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
ELSE()
SET (OPENSSL_CONF_TARGET ${CMAKE_CURRENT_BINARY_DIR})
ENDIF()
IF(WIN32)
IF("${OPENSSL_ROOT_DIR}" STREQUAL "")
get_filename_component(OPENSSL_ROOT_DIR "${OPENSSL_INCLUDE_DIR}/.." REALPATH)
ENDIF()
SET(OPENSSL_CONF_SOURCE "${OPENSSL_ROOT_DIR}/ssl/openssl.cnf")
IF(MINGW)
SET(OPENSSL_CONF_SOURCE "${OPENSSL_ROOT_DIR}/openssl.cnf")
ENDIF(MINGW)
SET(POST_BUILD_STEP_COMMANDS ${POST_BUILD_STEP_COMMANDS}
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENSSL_CONF_SOURCE}" "${OPENSSL_CONF_TARGET}/openssl.cnf")
ENDIF(WIN32)
ADD_CUSTOM_COMMAND(TARGET fc POST_BUILD ${POST_BUILD_STEP_COMMANDS}
COMMENT "Copying OpenSSL/ssl/openssl.cnf into target directory."
)
INCLUDE(CheckLibcxxAtomic)
MESSAGE(STATUS "Finished fc module configuration...")

View file

@ -1,74 +0,0 @@
# This module defines the ARGUMENT_PARSER macro for parsing macro arguments.
# ARGUMENT_PARSER Macro
# This macro parses a mixed list of arguments and headers into lists and boolean
# variables. The output lists and boolean variables are stored using
# tolower( header ) variable names. All non-header arguments will be added to
# the output list that corresponds to the header that they follow (or to the
# default list if no header has been parsed yet). If a boolean header is passed,
# then its corresponding output variable is set to YES.
#
# Usage:
# ARGUMENT_PARSER( default_list lists bools ARGN )
#
# Parameters:
# default_list The name of the variable that list values should be added
# to before any list headers have been reached. You may
# pass "" to disregard premature list values.
# lists The list headers (semicolon-separated string).
# bools The boolean headers (semicolon-separated string).
# ARGN The arguments to parse.
MACRO( ARGUMENT_PARSER default_list lists bools )
# Start using the default list.
SET( dest "${default_list}" )
IF( NOT dest )
SET( dest tmp )
ENDIF( NOT dest )
# Clear all of the lists.
FOREACH( list_itr ${lists} )
STRING( TOLOWER ${list_itr} lower )
SET( ${lower} "" )
ENDFOREACH( list_itr )
# Set all boolean variables to NO.
FOREACH( bool_itr ${bools} )
STRING( TOLOWER ${bool_itr} lower )
SET( ${lower} NO )
ENDFOREACH( bool_itr )
# For all arguments.
FOREACH( arg_itr ${ARGN} )
SET( done NO )
# For each of the list headers, if the current argument matches a list
# header, then set the destination to the header.
FOREACH( list_itr ${lists} )
IF( ${arg_itr} STREQUAL ${list_itr} )
STRING( TOLOWER ${arg_itr} lower )
SET( dest ${lower} )
SET( done YES )
ENDIF( ${arg_itr} STREQUAL ${list_itr} )
ENDFOREACH( list_itr )
# For each of the boolean headers, if the current argument matches a
# boolean header, then set the boolean variable to true.
FOREACH( bool_itr ${bools} )
IF( ${arg_itr} STREQUAL ${bool_itr} )
STRING( TOLOWER ${arg_itr} lower )
SET( ${lower} YES )
SET( done YES )
ENDIF( ${arg_itr} STREQUAL ${bool_itr} )
ENDFOREACH( bool_itr )
# If the current argument is not a header, then add it to the current
# destination list.
IF( NOT done )
SET( ${dest} ${${dest}} ${arg_itr} )
ENDIF( NOT done )
ENDFOREACH( arg_itr )
ENDMACRO( ARGUMENT_PARSER )

View file

@ -0,0 +1,18 @@
# This overrides `find_package(Boost ... CONFIG ... )` calls
# - calls the CMake's built-in `FindBoost.cmake` and adds `pthread` library dependency
MESSAGE(STATUS "Using custom FindBoost config")
find_package(Boost 1.58 REQUIRED COMPONENTS ${Boost_FIND_COMPONENTS})
# Inject `pthread` dependency to Boost if needed
if (UNIX AND NOT CYGWIN)
list(FIND Boost_FIND_COMPONENTS thread _using_boost_thread)
if (_using_boost_thread GREATER -1)
find_library(BOOST_THREAD_LIBRARY NAMES pthread DOC "The threading library used by boost-thread")
if (BOOST_THREAD_LIBRARY)
MESSAGE(STATUS "Adding Boost thread lib dependency: ${BOOST_THREAD_LIBRARY}")
list(APPEND Boost_LIBRARIES ${BOOST_THREAD_LIBRARY})
endif ()
endif ()
endif ()

View file

@ -0,0 +1,55 @@
# Taken from https://chromium.googlesource.com/chromium/llvm-project/libcxx/+/refs/heads/master/cmake/Modules/CheckLibcxxAtomic.cmake
# Apache License v2.0 with LLVM Exceptions
INCLUDE(CheckCXXSourceCompiles)
# Sometimes linking against libatomic is required for atomic ops, if
# the platform doesn't support lock-free atomics.
function(check_cxx_atomics varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
if (${LIBCXX_GCC_TOOLCHAIN})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}")
endif()
if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
endif()
if (CMAKE_C_FLAGS MATCHES -fsanitize-coverage OR CMAKE_CXX_FLAGS MATCHES -fsanitize-coverage)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize-coverage=edge,trace-cmp,indirect-calls,8bit-counters")
endif()
set(OLD_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})
set(CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIRS})
check_cxx_source_compiles("
#include <cstdint>
#include <boost/lockfree/queue.hpp>
boost::lockfree::queue<uint32_t*,boost::lockfree::capacity<5>> q;
int main(int, char**) {
uint32_t* a;
uint32_t* b;
q.push(a);
q.pop(b);
}
" ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_INCLUDES ${OLD_CMAKE_REQUIRED_INCLUDES})
endfunction(check_cxx_atomics)
# Perform the check for 64bit atomics without libatomic.
check_cxx_atomics(LIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB)
# If not, check if the library exists, and atomics work with it.
if(NOT LIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB)
check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
if(LIBCXX_HAS_ATOMIC_LIB)
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_cxx_atomics(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
if (NOT LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
message(WARNING "Host compiler must support std::atomic!")
endif()
else()
message(WARNING "Host compiler appears to require libatomic, but cannot find it.")
endif()
endif()

File diff suppressed because it is too large Load diff

View file

@ -1,47 +0,0 @@
# - Try to find readline include dirs and libraries
#
# Usage of this module as follows:
#
# find_package(Readline)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# Readline_ROOT_DIR Set this variable to the root installation of
# readline if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# READLINE_FOUND System has readline, include and lib dirs found
# Readline_INCLUDE_DIR The readline include directories.
# Readline_LIBRARY The readline library.
find_path(Readline_ROOT_DIR
NAMES include/readline/readline.h
)
find_path(Readline_INCLUDE_DIR
NAMES readline/readline.h
HINTS ${Readline_ROOT_DIR}/include
)
find_library(Readline_LIBRARY
NAMES readline
HINTS ${Readline_ROOT_DIR}/lib
)
if(Readline_INCLUDE_DIR AND Readline_LIBRARY AND Ncurses_LIBRARY)
set(READLINE_FOUND TRUE)
else(Readline_INCLUDE_DIR AND Readline_LIBRARY AND Ncurses_LIBRARY)
FIND_LIBRARY(Readline_LIBRARY NAMES readline)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG Readline_INCLUDE_DIR Readline_LIBRARY )
MARK_AS_ADVANCED(Readline_INCLUDE_DIR Readline_LIBRARY)
endif(Readline_INCLUDE_DIR AND Readline_LIBRARY AND Ncurses_LIBRARY)
mark_as_advanced(
Readline_ROOT_DIR
Readline_INCLUDE_DIR
Readline_LIBRARY
)

View file

@ -1,123 +0,0 @@
# Module for locating Visual Leak Detector.
#
# Customizable variables:
# VLD_ROOT_DIR
# This variable points to the Visual Leak Detector root directory. By
# default, the module looks for the installation directory by examining the
# Program Files/Program Files (x86) folders and the VLDROOT environment
# variable.
#
# Read-only variables:
# VLD_FOUND
# Indicates that the library has been found.
#
# VLD_INCLUDE_DIRS
# Points to the Visual Leak Detector include directory.
#
# VLD_LIBRARY_DIRS
# Points to the Visual Leak Detector directory that contains the libraries.
# The content of this variable can be passed to link_directories.
#
# VLD_LIBRARIES
# Points to the Visual Leak Detector libraries that can be passed to
# target_link_libararies.
#
#
# Copyright (c) 2012 Sergiu Dotenco
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
INCLUDE (FindPackageHandleStandardArgs)
SET (_VLD_POSSIBLE_LIB_SUFFIXES lib)
# Version 2.0 uses vld_x86 and vld_x64 instead of simply vld as library names
IF (CMAKE_SIZEOF_VOID_P EQUAL 4)
LIST (APPEND _VLD_POSSIBLE_LIB_SUFFIXES lib/Win32)
ELSEIF (CMAKE_SIZEOF_VOID_P EQUAL 8)
LIST (APPEND _VLD_POSSIBLE_LIB_SUFFIXES lib/Win64)
ENDIF (CMAKE_SIZEOF_VOID_P EQUAL 4)
FIND_PATH (VLD_ROOT_DIR
NAMES include/vld.h
PATHS ENV VLDROOT
"$ENV{PROGRAMFILES}/Visual Leak Detector"
"$ENV{PROGRAMFILES(X86)}/Visual Leak Detector"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Visual Leak Detector;InstallLocation]"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Visual Leak Detector;InstallLocation]"
DOC "VLD root directory")
FIND_PATH (VLD_INCLUDE_DIR
NAMES vld.h
HINTS ${VLD_ROOT_DIR}
PATH_SUFFIXES include
DOC "VLD include directory")
FIND_LIBRARY (VLD_LIBRARY_DEBUG
NAMES vld
HINTS ${VLD_ROOT_DIR}
PATH_SUFFIXES ${_VLD_POSSIBLE_LIB_SUFFIXES}
DOC "VLD debug library")
IF (VLD_ROOT_DIR)
SET (_VLD_VERSION_FILE ${VLD_ROOT_DIR}/CHANGES.txt)
IF (EXISTS ${_VLD_VERSION_FILE})
SET (_VLD_VERSION_REGEX
"Visual Leak Detector \\(VLD\\) Version (([0-9]+)\\.([0-9]+)([a-z]|(.([0-9]+)))?)")
FILE (STRINGS ${_VLD_VERSION_FILE} _VLD_VERSION_TMP REGEX
${_VLD_VERSION_REGEX})
STRING (REGEX REPLACE ${_VLD_VERSION_REGEX} "\\1" _VLD_VERSION_TMP
"${_VLD_VERSION_TMP}")
STRING (REGEX REPLACE "([0-9]+).([0-9]+).*" "\\1" VLD_VERSION_MAJOR
"${_VLD_VERSION_TMP}")
STRING (REGEX REPLACE "([0-9]+).([0-9]+).*" "\\2" VLD_VERSION_MINOR
"${_VLD_VERSION_TMP}")
SET (VLD_VERSION ${VLD_VERSION_MAJOR}.${VLD_VERSION_MINOR})
IF ("${_VLD_VERSION_TMP}" MATCHES "^([0-9]+).([0-9]+).([0-9]+)$")
# major.minor.patch version numbering scheme
STRING (REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\3"
VLD_VERSION_PATCH "${_VLD_VERSION_TMP}")
SET (VLD_VERSION "${VLD_VERSION}.${VLD_VERSION_PATCH}")
SET (VLD_VERSION_COUNT 3)
ELSE ("${_VLD_VERSION_TMP}" MATCHES "^([0-9]+).([0-9]+).([0-9]+)$")
# major.minor version numbering scheme. The trailing letter is ignored.
SET (VLD_VERSION_COUNT 2)
ENDIF ("${_VLD_VERSION_TMP}" MATCHES "^([0-9]+).([0-9]+).([0-9]+)$")
ENDIF (EXISTS ${_VLD_VERSION_FILE})
ENDIF (VLD_ROOT_DIR)
IF (VLD_LIBRARY_DEBUG)
SET (VLD_LIBRARY debug ${VLD_LIBRARY_DEBUG} CACHE DOC "VLD library")
GET_FILENAME_COMPONENT (_VLD_LIBRARY_DIR ${VLD_LIBRARY_DEBUG} PATH)
SET (VLD_LIBRARY_DIR ${_VLD_LIBRARY_DIR} CACHE PATH "VLD library directory")
ENDIF (VLD_LIBRARY_DEBUG)
SET (VLD_INCLUDE_DIRS ${VLD_INCLUDE_DIR})
SET (VLD_LIBRARY_DIRS ${VLD_LIBRARY_DIR})
SET (VLD_LIBRARIES ${VLD_LIBRARY})
MARK_AS_ADVANCED (VLD_INCLUDE_DIR VLD_LIBRARY_DIR VLD_LIBRARY_DEBUG VLD_LIBRARY)
FIND_PACKAGE_HANDLE_STANDARD_ARGS (VLD REQUIRED_VARS VLD_ROOT_DIR
VLD_INCLUDE_DIR VLD_LIBRARY VERSION_VAR VLD_VERSION)

View file

@ -1,79 +0,0 @@
# -*- mode: cmake -*-
#
# Shamelessly stolen from MSTK who shamelessly stole from Amanzi open source code https://software.lanl.gov/ascem/trac)
#
# PARSE_LIBRARY_LIST( <lib_list>
# DEBUG <out_debug_list>
# OPT <out_opt_list>
# GENERAL <out_gen_list> )
# CMake module
include(CMakeParseArguments)
function(PARSE_LIBRARY_LIST)
# Macro: _print_usage
macro(_print_usage)
message("PARSE_LIBRARY_LIST <lib_list>\n"
" FOUND <out_flag>\n"
" DEBUG <out_debug_list>\n"
" OPT <out_opt_list>\n"
" GENERAL <out_gen_list>\n"
"lib_list string to parse\n"
"FOUND flag to indicate if keywords were found\n"
"DEBUG variable containing debug libraries\n"
"OPT variable containing optimized libraries\n"
"GENERAL variable containing debug libraries\n")
endmacro()
# Read in args
cmake_parse_arguments(PARSE_ARGS "" "FOUND;DEBUG;OPT;GENERAL" "" ${ARGN})
set(_parse_list "${PARSE_ARGS_UNPARSED_ARGUMENTS}")
if ( (NOT PARSE_ARGS_FOUND) OR
(NOT PARSE_ARGS_DEBUG) OR
(NOT PARSE_ARGS_OPT) OR
(NOT PARSE_ARGS_GENERAL) OR
(NOT _parse_list )
)
_print_usage()
message(FATAL_ERROR "Invalid arguments")
endif()
# Now split the list
set(_debug_libs "")
set(_opt_libs "")
set(_gen_libs "")
foreach( item ${_parse_list} )
if( ${item} MATCHES debug OR
${item} MATCHES optimized OR
${item} MATCHES general )
if( ${item} STREQUAL "debug" )
set( mylist "_debug_libs" )
elseif( ${item} STREQUAL "optimized" )
set( mylist "_opt_libs" )
elseif( ${item} STREQUAL "general" )
set( mylist "_gen_libs" )
endif()
else()
list( APPEND ${mylist} ${item} )
endif()
endforeach()
# Now set output vairables
set(${PARSE_ARGS_DEBUG} "${_debug_libs}" PARENT_SCOPE)
set(${PARSE_ARGS_OPT} "${_opt_libs}" PARENT_SCOPE)
set(${PARSE_ARGS_GENERAL} "${_gen_libs}" PARENT_SCOPE)
# If any of the lib lists are defined set flag to TRUE
if ( (_debug_libs) OR (_opt_libs) OR (_gen_libs) )
set(${PARSE_ARGS_FOUND} TRUE PARENT_SCOPE)
else()
set(${PARSE_ARGS_FOUND} FALSE PARENT_SCOPE)
endif()
endfunction(PARSE_LIBRARY_LIST)

View file

@ -1,369 +0,0 @@
# This module defines several macros that are useful for setting up library,
# plugin, and executable targets.
INCLUDE( ArgumentParser )
function(enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME)
set(files ${${SOURCE_VARIABLE_NAME}})
# Generate a unique filename for the unity build translation unit
set(unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/ub_${UB_SUFFIX}.cpp)
# Exclude all translation units from compilation
set_source_files_properties(${files} PROPERTIES HEADER_FILE_ONLY true)
# Open the ub file
FILE(WRITE ${unit_build_file} "// Unity Build generated by CMake\n")
# Add include statement for each translation unit
foreach(source_file ${files} )
FILE( APPEND ${unit_build_file} "#include <${CMAKE_CURRENT_SOURCE_DIR}/${source_file}>\n")
endforeach(source_file)
# Complement list of translation units with the name of ub
set(${SOURCE_VARIABLE_NAME} ${${SOURCE_VARIABLE_NAME}} ${unit_build_file} PARENT_SCOPE)
endfunction(enable_unity_build)
# SETUP_LIBRARY Macro
# Sets up to build a library target. The macro uses the following global
# variables to define default values (you may change these variables to change
# the defaults:
# DEFAULT_HEADER_INSTALL_DIR
# DEFAULT_LIBRARY_INSTALL_DIR
#
# Usage:
# SETUP_LIBRARY( target
# SOURCES source1 [source2...]
# MOC_HEADERS header1 [header2...]
# LIBRARIES library1 [library2...]
# INSTALL_HEADERS header1 [header2...]
# HEADER_INSTALL_DIR dir
# LIBRARY_INSTALL_DIR dir
# DEBUG_POSTFIX string
# LIBRARY_TYPE string
# AUTO_INSTALL_HEADERS
# DONT_INSTALL_LIBRARY )
#
# Parameters:
# target The target library.
# SOURCES Follow with the sources to compile.
# MOC_HEADERS Follow with the headers to moc (Requires Qt).
# LIBRARIES Follow with the libraries to link.
# INSTALL_HEADERS Follow with the headers to install.
# HEADER_INSTALL_DIR Follow with the directory to install the headers
# in (${DEFAULT_HEADER_INSTALL_DIR} by default).
# LIBRARY_INSTALL_DIR Follow with the directory to install the library
# in (${DEFAULT_LIBRARY_INSTALL_DIR} by default).
# DEBUG_POSTFIX Follow with the postfix to use when building in
# debug mode (${CMAKE_DEBUG_POSTFIX} by default).
# LIBRARY_TYPE Follow with the type of library to build: SHARED,
# STATIC, or MODULE (if not passed, then the
# behavior is defined by BUILD_SHARED_LIBS).
# AUTO_INSTALL_HEADERS If passed, all *.h files in the current directory
# will be installed.
# DONT_INSTALL_LIBRARY If passed, the library will not be installed.
MACRO( SETUP_LIBRARY target )
# Setup the list headers.
SET( list_headers
SOURCES
MOC_HEADERS
LIBRARIES
INSTALL_HEADERS
HEADER_INSTALL_DIR
LIBRARY_INSTALL_DIR
DEBUG_POSTFIX
LIBRARY_TYPE
)
# Setup the boolean headers.
SET( bool_headers
AUTO_INSTALL_HEADERS
DONT_INSTALL_LIBRARY
)
# Parse the arguments into variables.
ARGUMENT_PARSER( "" "${list_headers}" "${bool_headers}" ${ARGN} )
# Set the default values for the header_install_dir, library_install_dir,
# and debug_postfix.
IF( NOT "${ARGN}" MATCHES "(^|;)HEADER_INSTALL_DIR($|;)" )
SET( header_install_dir ${DEFAULT_HEADER_INSTALL_DIR} )
ENDIF( NOT "${ARGN}" MATCHES "(^|;)HEADER_INSTALL_DIR($|;)" )
IF( NOT "${ARGN}" MATCHES "(^|;)LIBRARY_INSTALL_DIR($|;)" )
SET( library_install_dir ${DEFAULT_LIBRARY_INSTALL_DIR} )
ENDIF( NOT "${ARGN}" MATCHES "(^|;)LIBRARY_INSTALL_DIR($|;)" )
IF( NOT "${ARGN}" MATCHES "(^|;)DEBUG_POSTFIX($|;)" )
SET( debug_postfix ${CMAKE_DEBUG_POSTFIX} )
ENDIF( NOT "${ARGN}" MATCHES "(^|;)DEBUG_POSTFIX($|;)" )
# Configure the header_install_dir and library_install_dir so that ${target}
# may be used in them. Setting target to itself is REQUIRED for the
# configuration to work.
SET( target "${target}" )
STRING( CONFIGURE "${header_install_dir}" header_install_dir )
STRING( CONFIGURE "${library_install_dir}" library_install_dir )
# Setup the library_type.
IF( NOT library_type )
SET( library_type STATIC )
IF( BUILD_SHARED_LIBS )
SET( library_type SHARED )
ENDIF( BUILD_SHARED_LIBS )
ENDIF( NOT library_type )
# Clear the moc_sources.
SET( moc_sources "" )
# If Qt is being used...
IF( QT_FOUND AND QT_LIBRARIES )
# Setup QT to build a shared library.
IF( library_type MATCHES SHARED )
ADD_DEFINITIONS( -DQT_SHARED )
ENDIF( library_type MATCHES SHARED )
# Setup the moc sources.
IF( moc_headers )
QT4_WRAP_CPP( moc_sources ${moc_headers} )
ENDIF( moc_headers )
ENDIF( QT_FOUND AND QT_LIBRARIES )
# Fatal error if moc_headers given but moc_sources not created.
IF( moc_headers AND NOT moc_sources )
MESSAGE( FATAL_ERROR "Calling SETUP_LIBRARY() with MOC_HEADERS failed. "
"Make sure that you included \${QT_USE_FILE} prior to calling "
"SETUP_LIBRARY()." )
ENDIF( moc_headers AND NOT moc_sources )
IF( UNITY_BUILD )
enable_unity_build( ${target} sources )
ENDIF( UNITY_BUILD )
# Add the library.
ADD_LIBRARY( "${target}" ${library_type} ${sources} ${moc_sources} )
# Setup the debug_postfix.
SET_TARGET_PROPERTIES ( "${target}" PROPERTIES
DEBUG_POSTFIX "${debug_postfix}" )
# Link in the dependency libraries.
TARGET_LINK_LIBRARIES( "${target}" ${libraries} )
# If auto_install_headers, then set the headers to all .h files in the
# directory.
IF( auto_install_headers )
FILE( GLOB install_headers *.h )
ENDIF( auto_install_headers )
# Install the headers.
IF( install_headers )
INSTALL( FILES ${install_headers} DESTINATION "${header_install_dir}" )
ENDIF( install_headers )
# Install the library.
IF( NOT dont_install_library )
INSTALL( TARGETS "${target}"
LIBRARY DESTINATION "${library_install_dir}"
ARCHIVE DESTINATION "${library_install_dir}" )
ENDIF( NOT dont_install_library )
ENDMACRO( SETUP_LIBRARY )
# SETUP_MODULE Macro
# Sets up to build a module (also setup as a Qt plugin if using Qt). A module is
# built as a shared library; however, modules are typically loaded dynamically
# rather than linked against. Therefore, this macro does not install header
# files and uses its own default install directory. The macro uses the following
# global variables to define default values (you may change these variables to
# change the defaults:
# DEFAULT_MODULE_INSTALL_DIR
#
# Usage:
# SETUP_MODULE( target
# SOURCES source1 [source2...]
# MOC_HEADERS header1 [header2...]
# LIBRARIES library1 [library2...]
# MODULE_INSTALL_DIR dir
# DEBUG_POSTFIX string
# DONT_INSTALL_MODULE )
#
# Parameters:
# target The target module (built as a shared library).
# SOURCES Follow with the sources to compile.
# MOC_HEADERS Follow with the headers to moc (Requires Qt).
# LIBRARIES Follow with the libraries to link.
# MODULE_INSTALL_DIR Follow with the directory to install the module in
# (${DEFAULT_MODULE_INSTALL_DIR} by default).
# DEBUG_POSTFIX Follow with the postfix to use when building in
# debug mode (${CMAKE_DEBUG_POSTFIX} by default).
# DONT_INSTALL_MODULE If passed, the module will not be installed.
MACRO( SETUP_MODULE target )
# Setup the list headers.
SET( list_headers
SOURCES
MOC_HEADERS
LIBRARIES
MODULE_INSTALL_DIR
DEBUG_POSTFIX
)
# Setup the boolean headers.
SET( bool_headers
DONT_INSTALL_MODULE
)
# Parse the arguments into variables.
ARGUMENT_PARSER( "" "${list_headers}" "${bool_headers}" ${ARGN} )
# Set the default values for the module_install_dir and debug postfix.
IF( NOT "${ARGN}" MATCHES "(^|;)MODULE_INSTALL_DIR($|;)" )
SET( module_install_dir ${DEFAULT_MODULE_INSTALL_DIR} )
ENDIF( NOT "${ARGN}" MATCHES "(^|;)MODULE_INSTALL_DIR($|;)" )
IF( NOT "${ARGN}" MATCHES "(^|;)DEBUG_POSTFIX($|;)" )
SET( debug_postfix ${CMAKE_DEBUG_POSTFIX} )
ENDIF( NOT "${ARGN}" MATCHES "(^|;)DEBUG_POSTFIX($|;)" )
# Configure the module_install_dir so that ${target} may be used in it.
# Setting target to itself is REQUIRED for the configuration to work.
SET( target "${target}" )
STRING( CONFIGURE "${module_install_dir}" module_install_dir )
# Clear the moc_sources.
SET( moc_sources "" )
# If Qt is being used...
IF( QT_FOUND AND QT_LIBRARIES )
ADD_DEFINITIONS( -DQT_PLUGIN )
# Setup the moc sources.
IF( moc_headers )
QT4_WRAP_CPP( moc_sources ${moc_headers} )
ENDIF( moc_headers )
ENDIF( QT_FOUND AND QT_LIBRARIES )
# Fatal error if moc_headers given but moc_sources not created.
IF( moc_headers AND NOT moc_sources )
MESSAGE( FATAL_ERROR "Calling SETUP_MODULE() with MOC_HEADERS failed. "
"Make sure that you included \${QT_USE_FILE} prior to calling "
"SETUP_MODULE()." )
ENDIF( moc_headers AND NOT moc_sources )
# Add the module (built as a shared library).
ADD_LIBRARY( "${target}" SHARED ${sources} ${moc_sources} )
# Setup the debug postfix.
SET_TARGET_PROPERTIES ( "${target}" PROPERTIES
DEBUG_POSTFIX "${debug_postfix}" )
# Link in the dependency libraries.
TARGET_LINK_LIBRARIES( "${target}" ${libraries} )
# Install the module.
IF( NOT dont_install_module )
INSTALL( TARGETS "${target}"
LIBRARY DESTINATION "${module_install_dir}" )
ENDIF( NOT dont_install_module )
ENDMACRO( SETUP_MODULE )
# SETUP_EXECUTABLE Macro
# Sets up to build an executable target. The macro uses the following global
# variables to define default values (you may change these variables to change
# the defaults:
# DEFAULT_EXECUTABLE_INSTALL_DIR
#
# Usage:
# SETUP_EXECUTABLE( target
# SOURCES source1 [source2...]
# MOC_HEADERS header1 [header2...]
# LIBRARIES library1 [library2...]
# EXECUTABLE_INSTALL_DIR dir
# DEBUG_POSTFIX string
# DONT_INSTALL_EXECUTABLE )
#
# Parameters:
# target The target executable.
# SOURCES Follow with the sources to compile.
# MOC_HEADERS Follow with the headers to moc (Requires Qt).
# LIBRARIES Follow with the libraries to link.
# EXECUTABLE_INSTALL_DIR Follow with the directory to install the
# executable in
# (${DEFAULT_EXECUTABLE_INSTALL_DIR} by default).
# DEBUG_POSTFIX Follow with the postfix to use when building in
# debug mode (${CMAKE_DEBUG_POSTFIX} by
# default).
# DONT_INSTALL_EXECUTABLE If passed, the executable will not be
# installed.
MACRO( SETUP_EXECUTABLE target )
# Setup the list headers.
SET( list_headers
SOURCES
MOC_HEADERS
LIBRARIES
EXECUTABLE_INSTALL_DIR
DEBUG_POSTFIX
)
# Setup the boolean headers.
SET( bool_headers
DONT_INSTALL_EXECUTABLE
)
# Parse the arguments into variables.
ARGUMENT_PARSER( "" "${list_headers}" "${bool_headers}" ${ARGN} )
# Set the default values for the executable_install_dir and debug postfix.
IF( NOT "${ARGN}" MATCHES "(^|;)EXECUTABLE_INSTALL_DIR($|;)" )
SET( executable_install_dir ${DEFAULT_EXECUTABLE_INSTALL_DIR} )
ENDIF( NOT "${ARGN}" MATCHES "(^|;)EXECUTABLE_INSTALL_DIR($|;)" )
IF( NOT "${ARGN}" MATCHES "(^|;)DEBUG_POSTFIX($|;)" )
SET( debug_postfix ${CMAKE_DEBUG_POSTFIX} )
ENDIF( NOT "${ARGN}" MATCHES "(^|;)DEBUG_POSTFIX($|;)" )
# Configure the executable_install_dir so that ${target} may be used in it.
# Setting target to itself is REQUIRED for the configuration to work.
SET( target "${target}" )
STRING( CONFIGURE "${executable_install_dir}" executable_install_dir )
# Clear the moc_sources.
SET( moc_sources "" )
# If Qt is being used...
IF( QT_FOUND AND QT_LIBRARIES )
ADD_DEFINITIONS( -DQT_SHARED )
# Setup the moc sources.
IF( moc_headers )
QT4_WRAP_CPP( moc_sources ${moc_headers} )
ENDIF( moc_headers )
ENDIF( QT_FOUND AND QT_LIBRARIES )
# Fatal error if moc_headers given but moc_sources not created.
IF( moc_headers AND NOT moc_sources )
MESSAGE( FATAL_ERROR "Calling SETUP_EXECUTABLE() with MOC_HEADERS failed. "
"Make sure that you included \${QT_USE_FILE} prior to calling "
"SETUP_EXECUTABLE()." )
ENDIF( moc_headers AND NOT moc_sources )
# Add the executable.
ADD_EXECUTABLE( "${target}" ${sources} ${moc_sources} )
# Setup the debug postfix.
SET_TARGET_PROPERTIES ( "${target}" PROPERTIES
DEBUG_POSTFIX "${debug_postfix}" )
# Link in the dependency libraries.
TARGET_LINK_LIBRARIES( "${target}" ${libraries} )
# Install the executable.
IF( NOT dont_install_executable )
INSTALL( TARGETS "${target}" RUNTIME DESTINATION
"${executable_install_dir}" )
ENDIF( NOT dont_install_executable )
ENDMACRO( SETUP_EXECUTABLE )

View file

@ -1,72 +0,0 @@
# This module defines macros that are useful for using libraries in a build. The
# macros in this module are typically used along with the FindDependencyMacros.
# ADD_LIBRARY_TO_LIST Macro
# Adds a library to a list of libraries if it is found. Otherwise, reports an
# error.
#
# Usage:
# ADD_LIBRARY_TO_LIST( libraries found lib lib_name )
#
# Parameters:
# libraries The list of libraries to add the library to.
# found Whether or not the library to add was found.
# lib The library to add to the list.
# lib_name The name of the library to add to the list.
MACRO( ADD_LIBRARY_TO_LIST libraries found lib lib_name )
# Setting found to itself is necessary for the conditional to work.
SET( found ${found} )
# IF found, then add the library to the list, else report an error.
IF( found )
LIST( REMOVE_ITEM ${libraries} ${lib} )
SET( ${libraries} ${${libraries}} ${lib} )
ENDIF( found )
IF( NOT found )
MESSAGE( "Using ${lib_name} failed." )
ENDIF( NOT found )
ENDMACRO( ADD_LIBRARY_TO_LIST )
# USE_LIBRARY_GLOBALS Macro
# If ${prefix}_USE_${LIB} is true, then ${prefix}_${LIB}_LIBRARY will be added
# to ${prefix}_LIBRARIES (assuming the library was correctly found). All of the
# dependencies will also be added to ${prefix}_LIBRARIES.
#
# Usage:
# USE_LIBRARY_GLOBALS( prefix lib
# DEPS dependency1 [dependency2...] )
#
# Parameters:
# prefix The prefix for the global variables.
# lib The library to try to use.
# DEPS Follow with the list of dependencies that should be added with
# the given library.
MACRO( USE_LIBRARY_GLOBALS prefix lib )
STRING( TOUPPER ${lib} upper )
# If the library should be used...
IF( ${prefix}_USE_${upper} )
# Parse the arguments into variables.
ARGUMENT_PARSER( "" "DEPS" "" ${ARGN} )
# Add the library to the list.
ADD_LIBRARY_TO_LIST( ${prefix}_LIBRARIES "${${prefix}_${upper}_FOUND}"
"${${prefix}_${upper}_LIBRARY}" ${lib} )
# For each of the library's dependencies.
FOREACH( dep_itr ${deps} )
STRING( TOUPPER ${dep_itr} upper )
# Add the dependency to the list.
ADD_LIBRARY_TO_LIST( ${prefix}_LIBRARIES
"${${prefix}_${upper}_FOUND}"
"${${prefix}_${upper}_LIBRARY}" ${dep_itr} )
ENDFOREACH( dep_itr )
ENDIF( ${prefix}_USE_${upper} )
ENDMACRO( USE_LIBRARY_GLOBALS )

View file

@ -1,244 +0,0 @@
# This module defines several macros that are useful for handling version
# information. These macros work for version strings of format "#.#.#"
# representing major, minor, and patch integer components.
INCLUDE( ArgumentParser )
# PARSE_VERSION_STR Macro
# This macro parses the version string information from a string. The macro
# parses the string for the given definitions followed by whitespace (or by ':'
# or '"' characters) and then version information. For example, passing
# "MyVersion" as a definition would properly retrieve the version from a string
# "containing the line "def MyVersion: 1.2.3".
#
# Usage:
# PARSE_VERSION_STR( version string definition [definition2...] )
#
# Parameters:
# version The variable to store the version string in.
# string The string to parse.
# definition The definition(s) that may preceed the version string
# information.
MACRO( PARSE_VERSION_STR version string )
# Parse the arguments into variables.
ARGUMENT_PARSER( definitions "" "" ${ARGN} )
# For each of the given definitions...
FOREACH( def_itr ${definitions} )
# If the version has not been found, then attempt to parse it.
IF( NOT ${version} )
# Parse the version string.
STRING( REGEX MATCH "${def_itr}[ \t\":]+[0-9]+(.[0-9]+)?(.[0-9]+)?"
${version} ${string} )
STRING( REGEX MATCH "[0-9]+(.[0-9]+)?(.[0-9]+)?" ${version}
"${${version}}" )
CORRECT_VERSION_STR( ${version} "${${version}}" )
ENDIF( NOT ${version} )
ENDFOREACH( def_itr )
ENDMACRO( PARSE_VERSION_STR )
# PARSE_VERSION_INT Macro
# This macro parses the version integer component information from a string. The
# macro parses the string for the given definitions followed by whitespace (or
# by ':' or '"' characters) and then version information. For example, passing
# "MyVersionMajor" as a definition would properly retrieve the version from a
# string "containing the line "def MyVersionMajor: 1".
#
# Usage:
# PARSE_VERSION_INT( version string definition [definition2...] )
#
# Parameters:
# version The variable to store the version integer component in.
# string The string to parse.
# definition The definition(s) that may preceed the version integer
# component information.
MACRO( PARSE_VERSION_INT version string )
# Parse the arguments into variables.
ARGUMENT_PARSER( definitions "" "" ${ARGN} )
# For each of the given definitions...
FOREACH( def_itr ${definitions} )
# If the version has not been found, then attempt to parse it.
IF( NOT ${version} )
# Parse the version string.
STRING( REGEX MATCH "${def_itr}[ \t\":]+[0-9]+" ${version}
${string} )
STRING( REGEX MATCH "[0-9]+" ${version} "${${version}}" )
ENDIF( NOT ${version} )
ENDFOREACH( def_itr )
ENDMACRO( PARSE_VERSION_INT )
# VERSION_STR_TO_INTS Macro
# This macro converts a version string into its three integer components.
#
# Usage:
# VERSION_STR_TO_INTS( major minor patch version )
#
# Parameters:
# major The variable to store the major integer component in.
# minor The variable to store the minor integer component in.
# patch The variable to store the patch integer component in.
# version The version string to convert ("#.#.#" format).
MACRO( VERSION_STR_TO_INTS major minor patch version )
STRING( REGEX REPLACE "([0-9]+).[0-9]+.[0-9]+" "\\1" ${major} ${version} )
STRING( REGEX REPLACE "[0-9]+.([0-9]+).[0-9]+" "\\1" ${minor} ${version} )
STRING( REGEX REPLACE "[0-9]+.[0-9]+.([0-9]+)" "\\1" ${patch} ${version} )
ENDMACRO( VERSION_STR_TO_INTS )
# VERSION_INTS_TO_STR Macro
# This macro converts three version integer components into a version string.
#
# Usage:
# VERSION_INTS_TO_STR( version major minor patch )
#
# Parameters:
# version The variable to store the version string in.
# major The major version integer.
# minor The minor version integer.
# patch The patch version integer.
MACRO( VERSION_INTS_TO_STR version major minor patch )
SET( ${version} "${major}.${minor}.${patch}" )
CORRECT_VERSION_STR( ${version} ${${version}} )
ENDMACRO( VERSION_INTS_TO_STR version major minor patch )
# COMPARE_VERSION_STR Macro
# This macro compares two version strings to each other. The macro sets the
# result variable to -1 if lhs < rhs, 0 if lhs == rhs, and 1 if lhs > rhs.
#
# Usage:
# COMPARE_VERSION_STR( result lhs rhs )
#
# Parameters:
# result The variable to store the result of the comparison in.
# lhs The version of the left hand side ("#.#.#" format).
# rhs The version of the right hand side ("#.#.#" format).
MACRO( COMPARE_VERSION_STR result lhs rhs )
VERSION_STR_TO_INTS( lhs_major lhs_minor lhs_patch ${lhs} )
VERSION_STR_TO_INTS( rhs_major rhs_minor rhs_patch ${rhs} )
COMPARE_VERSION_INTS( ${result}
${lhs_major} ${lhs_minor} ${lhs_patch}
${rhs_major} ${rhs_minor} ${rhs_patch} )
ENDMACRO( COMPARE_VERSION_STR result lhs rhs )
# COMPARE_VERSION_INTS Macro
# This macro compares two versions to each other using their integer components.
# The macro sets the result variable to -1 if lhs < rhs, 0 if lhs == rhs, and 1
# if lhs > rhs.
#
# Usage:
# COMPARE_VERSION_INTS( result
# lhs_major lhs_minor lhs_patch
# rhs_major rhs_minor rhs_patch )
#
# Parameters:
# result The variable to store the result of the comparison in.
# lhs_major The major integer component for the left hand side.
# lhs_minor The minor integer component for the left hand side.
# lhs_patch The patch integer component for the left hand side.
# rhs_major The major integer component for the right hand side.
# rhs_minor The minor integer component for the right hand side.
# rhs_patch The patch integer component for the right hand side.
MACRO( COMPARE_VERSION_INTS result lhs_major lhs_minor lhs_patch
rhs_major rhs_minor rhs_patch )
SET( ${result} 0 )
IF( NOT ${result} AND ${lhs_major} LESS ${rhs_major} )
SET( ${result} -1 )
ENDIF( NOT ${result} AND ${lhs_major} LESS ${rhs_major} )
IF( NOT ${result} AND ${lhs_major} GREATER ${rhs_major} )
SET( ${result} 1 )
ENDIF( NOT ${result} AND ${lhs_major} GREATER ${rhs_major} )
IF( NOT ${result} AND ${lhs_minor} LESS ${rhs_minor} )
SET( ${result} -1 )
ENDIF( NOT ${result} AND ${lhs_minor} LESS ${rhs_minor} )
IF( NOT ${result} AND ${lhs_minor} GREATER ${rhs_minor} )
SET( ${result} 1 )
ENDIF( NOT ${result} AND ${lhs_minor} GREATER ${rhs_minor} )
IF( NOT ${result} AND ${lhs_patch} LESS ${rhs_patch} )
SET( ${result} -1 )
ENDIF( NOT ${result} AND ${lhs_patch} LESS ${rhs_patch} )
IF( NOT ${result} AND ${lhs_patch} GREATER ${rhs_patch} )
SET( ${result} 1 )
ENDIF( NOT ${result} AND ${lhs_patch} GREATER ${rhs_patch} )
ENDMACRO( COMPARE_VERSION_INTS result lhs_major lhs_minor lhs_patch
rhs_major rhs_minor rhs_patch )
# CORRECT_VERSION_STR Macro
# This macro corrects the version_str and stores the result in the version
# variable. If the version_str contains a version string in "#" or "#.#" format,
# then ".0" will be appended to the string to convert it to "#.#.#" format. If
# the version_str is invalid, then version will be set to "".
#
# Usage:
# CORRECT_VERSION_STR( version version_str )
#
# Parameters:
# version The variable to store the corrected version string in.
# version_str The version string to correct.
MACRO( CORRECT_VERSION_STR version version_str )
SET( ${version} "${version_str}" )
# Add ".0" to the end of the version string in case a full "#.#.#" string
# was not given.
FOREACH( itr RANGE 2 )
IF( NOT ${version} MATCHES "[0-9]+.[0-9]+.[0-9]+" )
SET( ${version} "${${version}}.0" )
ENDIF( NOT ${version} MATCHES "[0-9]+.[0-9]+.[0-9]+" )
ENDFOREACH( itr )
# If the version string is not correct, then set it to "".
IF( NOT ${version} MATCHES "^[0-9]+.[0-9]+.[0-9]+$" )
SET( ${version} "" )
ENDIF( NOT ${version} MATCHES "^[0-9]+.[0-9]+.[0-9]+$" )
ENDMACRO( CORRECT_VERSION_STR )
# CORRECT_VERSION_Int Macro
# This macro corrects the version_int and stores the result in the version
# variable. If the version_int is invalid, then version will be set to "".
#
# Usage:
# CORRECT_VERSION_Int( version version_int )
#
# Parameters:
# version The variable to store the corrected version integer
# component in.
# version_INT The version integer component to correct.
MACRO( CORRECT_VERSION_INT version version_int )
SET( ${version} "${version_int}" )
# If the version is not an integer, then set it to "".
IF( NOT ${version} MATCHES "^[0-9]+$" )
SET( ${version} "" )
ENDIF( NOT ${version} MATCHES "^[0-9]+$" )
ENDMACRO( CORRECT_VERSION_INT )

2362
Doxyfile Normal file

File diff suppressed because it is too large Load diff

2
GitVersionGen/GetGitRevisionDescription.cmake Executable file → Normal file
View file

@ -58,7 +58,7 @@ function(get_git_head_revision _refspecvar _hashvar)
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule})
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${GIT_DIR_RELATIVE} ABSOLUTE BASE_DIR ${SUBMODULE_DIR})
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")

0
GitVersionGen/GetGitRevisionDescription.cmake.in Executable file → Normal file
View file

52
LICENSE.md Normal file
View file

@ -0,0 +1,52 @@
The following license only applies to code that was contributed to this repository in the context of BitShares worker proposals and/or BitShares-1 delegate workers. Other code may be licensed indirectly by our "sister" repositories https://github.com/EOSIO/fc and https://github.com/bytemaster/fc/tree/phoenix .
All subsequent contributions to this repository are licensed by their respective authors under this same license as well, unless explicitly stated otherwise.
Furthermore, this repository includes code from third party authors. See the list at the end of this file.
----
Copyright (c) 2018-2019 BitShares Blockchain Foundation and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
----
The following terms apply to third-party code included here. Most have to be published along with binaries of this software.
Some of the files are only used for building binaries of this software, without becoming an actual part of those binaries. Their respective licenses also do not apply to the binaries.
include/bloom_filter.hpp is copyright Arash Partow and covered by the MIT license. See http://www.opensource.org/licenses/MIT .
src/utf8 is copyright Nemanja Trifunovic and covered by the MIT license (Thrift variant). See licenses/MIT_Thrift_LICENSE.md.
src/crypto/base58.cpp is copyright Satoshi Nakamoto and The Bitcoin Developers and is covered by the MIT/X11 license. See licenses/MIT_X11_LICENSE.md.
src/crypto/base64.cpp is copyright René Nyffenegger and covered by the zlib/libpng license. See licenses/ZLIB_LICENSE.md.
src/crypto/city.cpp and libraries/fc/include/fc/crypto/city.hpp are copyright Google, Inc. and covered by the MIT/X11 license. See licenses/MIT_X11_LICENSE.md.
CMakeModules/CheckLibcxxAtomic.cmake was taken from the LLVM repository and is licensed under the Apache-2.0 license. See licenses/Apache.txt .
GitVersionGen/GetGitRevisionDescription.cmake is copyright Iowa State University and covered by the Boost Software License. See licenses/Boost_License-1.0.txt.
vendor/editline is copyright Simmule Turner and Rich Salz and covered by a BSD-like license. See vendor/editline/LICENSE.
vendor/secp256k1-zkp is copyright Pieter Wuille and covered by the MIT/X11 license. See vendor/secp256k1-zkp/COPYING.
vendor/websocketpp is copyright Peter Thorson and covered by a 3-clause BSD-license. It also includes code from 4th-party authors with various copyrights, see vendor/websocketpp/COPYING.

0
README-ecc.md Executable file → Normal file
View file

3
README.md Executable file → Normal file
View file

@ -1,6 +1,9 @@
fc
==
[![](https://travis-ci.org/bitshares/bitshares-fc.svg?branch=master)](https://travis-ci.org/bitshares/bitshares-fc)
[![](https://github.com/bitshares/bitshares-fc/workflows/Github%20Autobuild/badge.svg?branch=master)](https://github.com/bitshares/bitshares-fc/actions?query=branch%3Amaster)
**NOTE:** This fork reverts upstream commit a421e280488385cab26a42153f7ce3c8d5b6281f to avoid changing the BitShares API.
FC stands for fast-compiling c++ library and provides a set of utility libraries useful

8
fc.natvis Executable file → Normal file
View file

@ -31,12 +31,6 @@
</Expand>
</Type>
<Type Name="fc::string">
<DisplayString>{my}</DisplayString>
<Expand>
<ExpandedItem>my</ExpandedItem>
</Expand>
</Type>
<Type Name="fc::optional&lt;*&gt;">
<DisplayString Condition="!_valid">invalid</DisplayString>
@ -54,4 +48,4 @@
</Expand>
</Type>
</AutoVisualizer>
</AutoVisualizer>

View file

@ -1,65 +0,0 @@
#pragma once
#include <fc/api.hpp>
#include <fc/thread/thread.hpp>
namespace fc {
namespace detail {
struct actor_member {
#if 1 // BOOST_NO_VARIADIC_TEMPLATES
#define RPC_MEMBER_FUNCTOR(z,n,IS_CONST) \
template<typename R, typename C, typename P BOOST_PP_ENUM_TRAILING_PARAMS( n, typename A)> \
static std::function<fc::future<R>( BOOST_PP_ENUM_PARAMS(n,A) ) > \
functor( P p, R (C::*mem_func)(BOOST_PP_ENUM_PARAMS(n,A)) IS_CONST, fc::thread* c = 0) { \
return [=](BOOST_PP_ENUM_BINARY_PARAMS(n,A,a))->fc::future<R>{ \
return c->async( [=](){ return (p->*mem_func)(BOOST_PP_ENUM_PARAMS(n,a)); } ); }; \
}
BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, const )
BOOST_PP_REPEAT( 8, RPC_MEMBER_FUNCTOR, BOOST_PP_EMPTY() )
#undef RPC_MEMBER_FUNCTOR
#else // g++ has a bug that prevents lambdas and varidic templates from working together (G++ Bug 41933)
template<typename R, typename C, typename P, typename... Args>
static std::function<fc::future<R>(Args...)> functor( P&& p, R (C::*mem_func)(Args...), fc::thread* c ) {
return [=](Args... args)->fc::future<R>{ c->async( [=]()->R { return p->*mem_func( fc::forward<Args>(args)... ); } ) };
}
template<typename R, typename C, typename P, typename... Args>
static std::function<fc::future<R>(Args...)> functor( P&& p, R (C::*mem_func)(Args...)const, fc::thread* c ){
return [=](Args... args)->fc::future<R>{ c->async( [=]()->R { return p->*mem_func( fc::forward<Args>(args)... ); } ) };
}
#endif
};
template<typename ThisPtr>
struct actor_vtable_visitor {
template<typename U>
actor_vtable_visitor( fc::thread* t, U&& u ):_thread(t),_this( fc::forward<U>(u) ){}
template<typename Function, typename MemberPtr>
void operator()( const char* name, Function& memb, MemberPtr m )const {
memb = actor_member::functor( _this, m, _thread );
}
fc::thread* _thread;
ThisPtr _this;
};
}
/**
* Posts all method calls to another thread and
* returns a future.
*/
template<typename Interface>
class actor : public api<Interface, detail::actor_member> {
public:
actor(){}
template<typename InterfaceType>
actor( InterfaceType* p, fc::thread* t = &fc::thread::current() )
{
this->_vtable.reset(new detail::vtable<Interface,detail::actor_member>() );
this->_vtable->template visit<InterfaceType>( detail::actor_vtable_visitor<InterfaceType*>(t, p) );
}
};
} // namespace fc

View file

@ -1,14 +0,0 @@
#pragma once
namespace fc {
template<unsigned int S, typename T=double>
struct aligned {
union {
T _align;
char _data[S];
} _store;
operator char*() { return _store._data; }
operator const char*()const { return _store._data; }
};
}

View file

@ -1,7 +0,0 @@
#pragma once
#include <boost/any.hpp>
namespace fc {
// TODO: define this without using boost
typedef boost::any any;
}

96
include/fc/api.hpp Executable file → Normal file
View file

@ -1,7 +1,7 @@
#pragma once
#include <fc/thread/future.hpp>
#include <fc/any.hpp>
#include <functional>
#include <boost/any.hpp>
#include <boost/config.hpp>
// ms visual c++ (as of 2013) doesn't accept the standard syntax for calling a
@ -13,13 +13,91 @@
#endif
namespace fc {
struct identity_member {
namespace detail {
/// This metafunction determines whether its template argument is an instantiation of fc::optional
template<typename T> struct is_optional : public std::false_type {};
template<typename T> struct is_optional<fc::optional<T>> : public std::true_type {};
/// This metafunction determines whether all of its template arguments are instantiations of fc::optional
template<typename... Ts> struct all_optionals;
template<> struct all_optionals<> : public std::true_type {};
template<typename T, typename... Ts> struct all_optionals<T, Ts...> : public std::false_type {};
template<typename T, typename... Ts> struct all_optionals<fc::optional<T>, Ts...> : public all_optionals<Ts...> {};
/// A wrapper of std::function allowing callers to omit the last several arguments if those arguments are
/// fc::optional types. i.e. given a function taking (int, double, bool, fc::optional<string>, fc::optional<char>),
/// whereas normally the last two arguments must be provided, this template allows them to be omitted.
/// Note that this only applies to trailing optional arguments, i.e. given a callable taking
/// (fc::optional<int>, int, fc::optional<int>), only the last argument can be omitted.
///
/// A discussion of how exactly this works is available here:
/// https://github.com/bitshares/bitshares-fc/pull/126#issuecomment-490566060
template<typename R, typename... Parameters>
struct optionals_callable : public std::function<R(Parameters...)> {
using std::function<R(Parameters...)>::operator();
template<typename... CutList>
struct short_pack {};
/// This metafunction removes the first several types from a variadic parameter pack of types.
/// The first parameter is the number of arguments to remove from the beginning of the pack.
/// All subsequent parameters are types in the list to be cut
/// The result pack_cutter<...>::type is a short_pack<RemainingTypes>
template<unsigned RemoveCount, typename... Types>
struct pack_cutter;
template<unsigned RemoveCount, typename, typename... Types>
struct pack_cutter_impl;
template<typename... Types>
struct pack_cutter_impl<0, void, Types...> {
static_assert(all_optionals<Types...>::value, "All omitted arguments must correspond to optional parameters.");
using type = short_pack<Types...>;
};
template<unsigned RemoveCount, typename T, typename... Types>
struct pack_cutter_impl<RemoveCount, std::enable_if_t<RemoveCount != 0>, T, Types...>
: public pack_cutter_impl<RemoveCount - 1, void, Types...> {};
template<unsigned RemoveCount, typename... Types>
struct pack_cutter : public pack_cutter_impl<RemoveCount, void, Types...> {};
template<unsigned RemoveCount, typename... Types>
using pack_cutter_t = typename pack_cutter<RemoveCount, Types...>::type;
template<typename F, typename... OptionalTypes>
R call_function(F&& f, short_pack<OptionalTypes...>) {
return f(OptionalTypes()...);
}
/// Overload the function call operator, enabled if the caller provides fewer arguments than there are parameters.
/// Pads out the provided arguments with default-constructed optionals, checking that they are indeed optional types
template<class... Args>
std::enable_if_t<sizeof...(Args) < sizeof...(Parameters), R> operator()(Args... args) {
// Partially apply with the arguments provided
auto partial_function = [this, &args...](auto&&... rest) {
return (*this)(std::forward<decltype(args)>(args)..., std::move(rest)...);
};
// Cut the provided arguments' types out of the Parameters list, and store the rest in a dummy type
pack_cutter_t<sizeof...(Args), std::decay_t<Parameters>...> dummy;
// Pass the partially applied function and the dummy type to another function which can deduce the optional
// types and call the function with default instantiations of those types
return call_function(std::move(partial_function), dummy);
}
};
}
// This is no longer used and probably no longer can be used without generalizing the infrastructure around it, but I
// kept it because it is informative.
// struct identity_member {
// template<typename R, typename C, typename P, typename... Args>
// static std::function<R(Args...)> functor( P&& p, R (C::*mem_func)(Args...) );
// template<typename R, typename C, typename P, typename... Args>
// static std::function<R(Args...)> functor( P&& p, R (C::*mem_func)(Args...)const );
// };
/// Used as the Transform template parameter for APIs, this type has two main purposes: first, it reads the argument
/// list and return type of a method into template parameters; and second, it uses those types in conjunction with the
/// optionals_callable template above to create a function pointer which supports optional arguments.
struct identity_member_with_optionals {
template<typename R, typename C, typename P, typename... Args>
static std::function<R(Args...)> functor( P&& p, R (C::*mem_func)(Args...) );
static detail::optionals_callable<R, Args...> functor( P&& p, R (C::*mem_func)(Args...) );
template<typename R, typename C, typename P, typename... Args>
static std::function<R(Args...)> functor( P&& p, R (C::*mem_func)(Args...)const );
static detail::optionals_callable<R, Args...> functor( P&& p, R (C::*mem_func)(Args...)const );
};
template< typename Interface, typename Transform >
struct vtable : public std::enable_shared_from_this<vtable<Interface,Transform>>
{ private: vtable(); };
@ -57,13 +135,13 @@ namespace fc {
// defined in api_connection.hpp
template< typename T >
api<T, identity_member> as();
api<T, identity_member_with_optionals> as();
};
typedef std::shared_ptr< api_base > api_ptr;
class api_connection;
template<typename Interface, typename Transform = identity_member >
template<typename Interface, typename Transform = identity_member_with_optionals >
class api : public api_base {
public:
typedef vtable<Interface,Transform> vtable_type;
@ -75,7 +153,7 @@ namespace fc {
api( const T& p )
:_vtable( std::make_shared<vtable_type>() )
{
_data = std::make_shared<fc::any>(p);
_data = std::make_shared<boost::any>(p);
T& ptr = boost::any_cast<T&>(*_data);
auto& pointed_at = *ptr;
typedef typename std::remove_reference<decltype(pointed_at)>::type source_vtable_type;
@ -95,7 +173,7 @@ namespace fc {
protected:
std::shared_ptr<vtable_type> _vtable;
std::shared_ptr<fc::any> _data;
std::shared_ptr<boost::any> _data;
};
} // namespace fc

View file

@ -1,145 +0,0 @@
#pragma once
#include <fc/crypto/base64.hpp>
#include <fc/variant.hpp>
#include <fc/reflect/reflect.hpp>
namespace fc {
/**
* Provides a fixed size array that is easier for templates to specialize
* against or overload than T[N].
*/
template<typename T, size_t N>
class array {
public:
/**
* Checked indexing (when in debug build) that also simplifies dereferencing
* when you have an array<T,N>*.
*/
///@{
T& at( size_t pos ) { assert( pos < N); return data[pos]; }
const T& at( size_t pos )const { assert( pos < N); return data[pos]; }
///@}
T& operator[]( size_t pos ) { assert( pos < N); return data[pos]; }
const T& operator[]( size_t pos )const { assert( pos < N); return data[pos]; }
const T* begin()const { return &data[0]; }
const T* end()const { return &data[N]; }
T* begin() { return &data[0]; }
T* end() { return &data[N]; }
size_t size()const { return N; }
T data[N];
};
/** provided for default 0 init */
template<size_t N>
class array<unsigned char,N>
{
public:
typedef unsigned char T;
array(){ memset( data, 0, sizeof(data) ); }
/**
* Checked indexing (when in debug build) that also simplifies dereferencing
* when you have an array<T,N>*.
*/
///@{
T& at( size_t pos ) { assert( pos < N); return data[pos]; }
const T& at( size_t pos )const { assert( pos < N); return data[pos]; }
///@}
T* begin() { return &data[0]; }
const T* begin()const { return &data[0]; }
const T* end()const { return &data[N]; }
size_t size()const { return N; }
T data[N];
};
/** provided for default 0 init */
template<size_t N>
class array<char,N>
{
public:
typedef char T;
array(){ memset( data, 0, sizeof(data) ); }
/**
* Checked indexing (when in debug build) that also simplifies dereferencing
* when you have an array<T,N>*.
*/
///@{
T& at( size_t pos ) { assert( pos < N); return data[pos]; }
const T& at( size_t pos )const { assert( pos < N); return data[pos]; }
///@}
T* begin() { return &data[0]; }
const T* begin()const { return &data[0]; }
const T* end()const { return &data[N]; }
size_t size()const { return N; }
T data[N];
};
template<typename T, size_t N>
bool operator == ( const array<T,N>& a, const array<T,N>& b )
{ return 0 == memcmp( a.data, b.data, N*sizeof(T) ); }
template<typename T, size_t N>
bool operator < ( const array<T,N>& a, const array<T,N>& b )
{ return memcmp( a.data, b.data, N*sizeof(T) ) < 0 ; }
template<typename T, size_t N>
bool operator > ( const array<T,N>& a, const array<T,N>& b )
{ return memcmp( a.data, b.data, N*sizeof(T) ) > 0 ; }
template<typename T, size_t N>
bool operator != ( const array<T,N>& a, const array<T,N>& b )
{ return 0 != memcmp( a.data, b.data, N*sizeof(T) ); }
template<typename T, size_t N>
void to_variant( const array<T,N>& bi, variant& v, uint32_t max_depth = 1 )
{
to_variant( std::vector<char>( (const char*)&bi, ((const char*)&bi) + sizeof(bi) ), v, 1 );
}
template<typename T, size_t N>
void from_variant( const variant& v, array<T,N>& bi, uint32_t max_depth = 1 )
{
std::vector<char> ve = v.as< std::vector<char> >( 1 );
if( ve.size() )
{
memcpy(&bi, ve.data(), fc::min<size_t>(ve.size(),sizeof(bi)) );
}
else
memset( &bi, char(0), sizeof(bi) );
}
template<typename T,size_t N> struct get_typename< fc::array<T,N> >
{
static const char* name()
{
static std::string _name = std::string("fc::array<")+std::string(fc::get_typename<T>::name())+","+ fc::to_string(N) + ">";
return _name.c_str();
}
};
}
#include <unordered_map>
#include <fc/crypto/city.hpp>
namespace std
{
template<typename T, size_t N>
struct hash<fc::array<T,N> >
{
size_t operator()( const fc::array<T,N>& e )const
{
return fc::city_hash_size_t( (char*)&e, sizeof(e) );
}
};
}

75
include/fc/asio.hpp Executable file → Normal file
View file

@ -5,6 +5,8 @@
#pragma once
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>
#include <vector>
#include <fc/thread/future.hpp>
#include <fc/io/iostream.hpp>
@ -17,7 +19,6 @@ namespace asio {
* @brief internal implementation types/methods for fc::asio
*/
namespace detail {
using namespace fc;
class read_write_handler
{
@ -39,8 +40,17 @@ namespace asio {
std::shared_ptr<const char> _buffer;
};
//void read_write_handler( const promise<size_t>::ptr& p,
// const boost::system::error_code& ec,
// size_t bytes_transferred );
void read_write_handler_ec( promise<size_t>* p,
boost::system::error_code* oec,
const boost::system::error_code& ec,
size_t bytes_transferred );
void error_handler( const promise<void>::ptr& p,
const boost::system::error_code& ec );
const boost::system::error_code& ec );
void error_handler_ec( promise<boost::system::error_code>* p,
const boost::system::error_code& ec );
template<typename C>
struct non_blocking {
@ -49,21 +59,41 @@ namespace asio {
};
#if WIN32 // windows stream handles do not support non blocking!
template<>
struct non_blocking<boost::asio::windows::stream_handle> {
typedef boost::asio::windows::stream_handle C;
bool operator()( C& ) { return false; }
bool operator()( C&, bool ) { return false; }
template<>
struct non_blocking<boost::asio::windows::stream_handle> {
typedef boost::asio::windows::stream_handle C;
bool operator()( C& ) { return false; }
bool operator()( C&, bool ) { return false; }
};
#endif
}
#endif
} // end of namespace detail
/***
* A structure for holding the boost io service and associated
* threads
*/
class default_io_service_scope
{
public:
default_io_service_scope();
~default_io_service_scope();
static void set_num_threads(uint16_t num_threads);
static uint16_t get_num_threads();
boost::asio::io_service* io;
private:
std::vector<boost::thread*> asio_threads;
boost::asio::io_service::work* the_work;
protected:
static uint16_t num_io_threads; // marked protected to help with testing
};
/**
* @return the default boost::asio::io_service for use with fc::asio
*
* This IO service is automatically running in its own thread to service asynchronous
* requests without blocking any other threads.
*/
boost::asio::io_service& default_io_service(bool cleanup = false);
boost::asio::io_service& default_io_service();
/**
* @brief wraps boost::asio::async_read
@ -72,7 +102,7 @@ namespace asio {
*/
template<typename AsyncReadStream, typename MutableBufferSequence>
size_t read( AsyncReadStream& s, const MutableBufferSequence& buf ) {
promise<size_t>::ptr p(new promise<size_t>("fc::asio::read"));
promise<size_t>::ptr p = promise<size_t>::create("fc::asio::read");
boost::asio::async_read( s, buf, detail::read_write_handler(p) );
return p->wait();
}
@ -92,7 +122,7 @@ namespace asio {
template<typename AsyncReadStream, typename MutableBufferSequence>
future<size_t> read_some(AsyncReadStream& s, const MutableBufferSequence& buf)
{
promise<size_t>::ptr completion_promise(new promise<size_t>("fc::asio::async_read_some"));
promise<size_t>::ptr completion_promise = promise<size_t>::create("fc::asio::async_read_some");
s.async_read_some(buf, detail::read_write_handler(completion_promise));
return completion_promise;//->wait();
}
@ -100,7 +130,7 @@ namespace asio {
template<typename AsyncReadStream>
future<size_t> read_some(AsyncReadStream& s, char* buffer, size_t length, size_t offset = 0)
{
promise<size_t>::ptr completion_promise(new promise<size_t>("fc::asio::async_read_some"));
promise<size_t>::ptr completion_promise = promise<size_t>::create("fc::asio::async_read_some");
s.async_read_some(boost::asio::buffer(buffer + offset, length),
detail::read_write_handler(completion_promise));
return completion_promise;//->wait();
@ -109,7 +139,7 @@ namespace asio {
template<typename AsyncReadStream>
future<size_t> read_some(AsyncReadStream& s, const std::shared_ptr<char>& buffer, size_t length, size_t offset)
{
promise<size_t>::ptr completion_promise(new promise<size_t>("fc::asio::async_read_some"));
promise<size_t>::ptr completion_promise = promise<size_t>::create("fc::asio::async_read_some");
s.async_read_some(boost::asio::buffer(buffer.get() + offset, length),
detail::read_write_handler_with_buffer(completion_promise, buffer));
return completion_promise;//->wait();
@ -149,7 +179,7 @@ namespace asio {
*/
template<typename AsyncWriteStream, typename ConstBufferSequence>
size_t write( AsyncWriteStream& s, const ConstBufferSequence& buf ) {
promise<size_t>::ptr p(new promise<size_t>("fc::asio::write"));
promise<size_t>::ptr p = promise<size_t>::create("fc::asio::write");
boost::asio::async_write(s, buf, detail::read_write_handler(p));
return p->wait();
}
@ -161,7 +191,7 @@ namespace asio {
*/
template<typename AsyncWriteStream, typename ConstBufferSequence>
future<size_t> write_some( AsyncWriteStream& s, const ConstBufferSequence& buf ) {
promise<size_t>::ptr p(new promise<size_t>("fc::asio::write_some"));
promise<size_t>::ptr p = promise<size_t>::create("fc::asio::write_some");
s.async_write_some( buf, detail::read_write_handler(p));
return p; //->wait();
}
@ -169,7 +199,7 @@ namespace asio {
template<typename AsyncWriteStream>
future<size_t> write_some( AsyncWriteStream& s, const char* buffer,
size_t length, size_t offset = 0) {
promise<size_t>::ptr p(new promise<size_t>("fc::asio::write_some"));
promise<size_t>::ptr p = promise<size_t>::create("fc::asio::write_some");
s.async_write_some( boost::asio::buffer(buffer + offset, length), detail::read_write_handler(p));
return p; //->wait();
}
@ -177,7 +207,7 @@ namespace asio {
template<typename AsyncWriteStream>
future<size_t> write_some( AsyncWriteStream& s, const std::shared_ptr<const char>& buffer,
size_t length, size_t offset ) {
promise<size_t>::ptr p(new promise<size_t>("fc::asio::write_some"));
promise<size_t>::ptr p = promise<size_t>::create("fc::asio::write_some");
s.async_write_some( boost::asio::buffer(buffer.get() + offset, length), detail::read_write_handler_with_buffer(p, buffer));
return p; //->wait();
}
@ -219,8 +249,7 @@ namespace asio {
*/
template<typename SocketType, typename AcceptorType>
void accept( AcceptorType& acc, SocketType& sock ) {
//promise<boost::system::error_code>::ptr p( new promise<boost::system::error_code>("fc::asio::tcp::accept") );
promise<void>::ptr p( new promise<void>("fc::asio::tcp::accept") );
promise<void>::ptr p = promise<void>::create("fc::asio::tcp::accept");
acc.async_accept( sock, boost::bind( fc::asio::detail::error_handler, p, _1 ) );
p->wait();
//if( ec ) BOOST_THROW_EXCEPTION( boost::system::system_error(ec) );
@ -232,7 +261,7 @@ namespace asio {
*/
template<typename AsyncSocket, typename EndpointType>
void connect( AsyncSocket& sock, const EndpointType& ep ) {
promise<void>::ptr p(new promise<void>("fc::asio::tcp::connect"));
promise<void>::ptr p = promise<void>::create("fc::asio::tcp::connect");
sock.async_connect( ep, boost::bind( fc::asio::detail::error_handler, p, _1 ) );
p->wait();
//if( ec ) BOOST_THROW_EXCEPTION( boost::system::system_error(ec) );
@ -252,7 +281,7 @@ namespace asio {
{
public:
istream( std::shared_ptr<AsyncReadStream> str )
:_stream( fc::move(str) ){}
:_stream( std::move(str) ){}
virtual size_t readsome( char* buf, size_t len )
{
@ -272,7 +301,7 @@ namespace asio {
{
public:
ostream( std::shared_ptr<AsyncWriteStream> str )
:_stream( fc::move(str) ){}
:_stream( std::move(str) ){}
virtual size_t writesome( const char* buf, size_t len )
{

View file

@ -1,28 +0,0 @@
#pragma once
#include <stdint.h>
namespace fc {
inline uint64_t endian_reverse_u64( uint64_t x )
{
return (((x >> 0x38) & 0xFF) )
| (((x >> 0x30) & 0xFF) << 0x08)
| (((x >> 0x28) & 0xFF) << 0x10)
| (((x >> 0x20) & 0xFF) << 0x18)
| (((x >> 0x18) & 0xFF) << 0x20)
| (((x >> 0x10) & 0xFF) << 0x28)
| (((x >> 0x08) & 0xFF) << 0x30)
| (((x ) & 0xFF) << 0x38)
;
}
inline uint32_t endian_reverse_u32( uint32_t x )
{
return (((x >> 0x18) & 0xFF) )
| (((x >> 0x10) & 0xFF) << 0x08)
| (((x >> 0x08) & 0xFF) << 0x10)
| (((x ) & 0xFF) << 0x18)
;
}
} // namespace fc

240
include/fc/bloom_filter.hpp Executable file → Normal file
View file

@ -1,5 +1,3 @@
#pragma once
/*
*********************************************************************
* *
@ -11,27 +9,29 @@
* *
* Copyright notice: *
* Free use of the Open Bloom Filter Library is permitted under the *
* guidelines and in accordance with the most current version of the *
* Common Public License. *
* http://www.opensource.org/licenses/cpl1.0.php *
* guidelines and in accordance with the MIT License. *
* http://www.opensource.org/licenses/MIT *
* *
*********************************************************************
*/
#ifndef INCLUDE_BLOOM_FILTER_HPP
#define INCLUDE_BLOOM_FILTER_HPP
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <iterator>
#include <limits>
#include <string>
#include <vector>
#include <fc/reflect/reflect.hpp>
namespace fc {
static constexpr std::size_t bits_per_char = 0x08; // 8 bits in 1 char(unsigned)
static const std::size_t bits_per_char = 0x08; // 8 bits in 1 char(unsigned)
static const unsigned char bit_mask[bits_per_char] = {
0x01, //00000001
0x02, //00000010
@ -57,6 +57,20 @@ public:
random_seed(0xA5A5A5A55A5A5A5AULL)
{}
bloom_parameters(unsigned long long int projected_element_count,
double false_positive_probability,
unsigned long long int maximum_size) :
minimum_size(1),
maximum_size(maximum_size),
minimum_number_of_hashes(1),
maximum_number_of_hashes(std::numeric_limits<unsigned int>::max()),
projected_element_count(projected_element_count),
false_positive_probability(false_positive_probability),
random_seed(0xA5A5A5A55A5A5A5AULL)
{
compute_optimal_parameters();
}
virtual ~bloom_parameters()
{}
@ -73,22 +87,22 @@ public:
(0xFFFFFFFFFFFFFFFFULL == random_seed);
}
//Allowed min/max size of the bloom filter in bits
// Allowable min/max size of the bloom filter in bits
unsigned long long int minimum_size;
unsigned long long int maximum_size;
//Allowed min/max number of hash functions
// Allowable min/max number of hash functions
unsigned int minimum_number_of_hashes;
unsigned int maximum_number_of_hashes;
//The approximate number of elements to be inserted
//into the bloom filter, should be within one order
//of magnitude. The default is 10000.
// The approximate number of elements to be inserted
// into the bloom filter, should be within one order
// of magnitude. The default is 10000.
unsigned long long int projected_element_count;
//The approximate false positive probability expected
//from the bloom filter. The default is the reciprocal
//of the projected_element_count.
// The approximate false positive probability expected
// from the bloom filter. The default is assumed to be
// the reciprocal of the projected_element_count.
double false_positive_probability;
unsigned long long int random_seed;
@ -119,28 +133,32 @@ public:
if (!(*this))
return false;
double min_m = std::numeric_limits<double>::infinity();
double min_k = 0.0;
double curr_m = 0.0;
double k = 1.0;
double min_m = std::numeric_limits<double>::infinity();
double min_k = 0.0;
double k = 1.0;
while (k < 1000.0)
{
double numerator = (- k * projected_element_count);
double denominator = std::log(1.0 - std::pow(false_positive_probability, 1.0 / k));
curr_m = numerator / denominator;
const double numerator = (- k * projected_element_count);
const double denominator = std::log(1.0 - std::pow(false_positive_probability, 1.0 / k));
const double curr_m = numerator / denominator;
if (curr_m < min_m)
{
min_m = curr_m;
min_k = k;
}
k += 1.0;
}
optimal_parameters_t& optp = optimal_parameters;
optp.number_of_hashes = static_cast<unsigned int>(min_k);
optp.table_size = static_cast<unsigned long long int>(min_m);
optp.table_size += (((optp.table_size % bits_per_char) != 0) ? (bits_per_char - (optp.table_size % bits_per_char)) : 0);
if (optp.number_of_hashes < minimum_number_of_hashes)
@ -164,15 +182,15 @@ protected:
typedef unsigned int bloom_type;
typedef unsigned char cell_type;
typedef std::vector<unsigned char> table_type;
public:
bloom_filter()
: salt_count_(0),
table_size_(0),
raw_table_size_(0),
projected_element_count_(0),
inserted_element_count_(0),
inserted_element_count_ (0),
random_seed_(0),
desired_false_positive_probability_(0.0)
{}
@ -185,12 +203,10 @@ public:
{
salt_count_ = p.optimal_parameters.number_of_hashes;
table_size_ = p.optimal_parameters.table_size;
generate_unique_salt();
raw_table_size_ = table_size_ / bits_per_char;
bit_table_.resize( static_cast<std::size_t>(raw_table_size_) );
//bit_table_ = new cell_type[static_cast<std::size_t>(raw_table_size_)];
std::fill_n(bit_table_.data(),raw_table_size_,0x00);
generate_unique_salt();
bit_table_.resize(table_size_ / bits_per_char, static_cast<unsigned char>(0x00));
}
bloom_filter(const bloom_filter& filter)
@ -203,15 +219,15 @@ public:
if (this != &f)
{
return
(salt_count_ == f.salt_count_) &&
(table_size_ == f.table_size_) &&
(raw_table_size_ == f.raw_table_size_) &&
(projected_element_count_ == f.projected_element_count_) &&
(inserted_element_count_ == f.inserted_element_count_) &&
(random_seed_ == f.random_seed_) &&
(salt_count_ == f.salt_count_ ) &&
(table_size_ == f.table_size_ ) &&
(bit_table_.size() == f.bit_table_.size() ) &&
(projected_element_count_ == f.projected_element_count_ ) &&
(inserted_element_count_ == f.inserted_element_count_ ) &&
(random_seed_ == f.random_seed_ ) &&
(desired_false_positive_probability_ == f.desired_false_positive_probability_) &&
(salt_ == f.salt_) &&
std::equal(f.bit_table_.data(),f.bit_table_.data() + raw_table_size_,bit_table_.data());
(salt_ == f.salt_ ) &&
(bit_table_ == f.bit_table_ ) ;
}
else
return true;
@ -228,21 +244,22 @@ public:
{
salt_count_ = f.salt_count_;
table_size_ = f.table_size_;
raw_table_size_ = f.raw_table_size_;
bit_table_ = f.bit_table_;
salt_ = f.salt_;
projected_element_count_ = f.projected_element_count_;
inserted_element_count_ = f.inserted_element_count_;
inserted_element_count_ = f.inserted_element_count_;
random_seed_ = f.random_seed_;
desired_false_positive_probability_ = f.desired_false_positive_probability_;
bit_table_.resize( raw_table_size_ );
std::copy(f.bit_table_.data(),f.bit_table_.data() + raw_table_size_,bit_table_.data());
salt_ = f.salt_;
}
return *this;
}
virtual ~bloom_filter()
{
}
{}
inline bool operator!() const
{
@ -251,23 +268,26 @@ public:
inline void clear()
{
std::fill_n(bit_table_.data(),raw_table_size_,0x00);
std::fill(bit_table_.begin(), bit_table_.end(), static_cast<unsigned char>(0x00));
inserted_element_count_ = 0;
}
inline void insert(const unsigned char* key_begin, const std::size_t& length)
{
std::size_t bit_index = 0;
std::size_t bit = 0;
std::size_t bit = 0;
for (std::size_t i = 0; i < salt_.size(); ++i)
{
compute_indices(hash_ap(key_begin,length,salt_[i]),bit_index,bit);
compute_indices(hash_ap(key_begin, length, salt_[i]), bit_index, bit);
bit_table_[bit_index / bits_per_char] |= bit_mask[bit];
}
++inserted_element_count_;
}
template<typename T>
template <typename T>
inline void insert(const T& t)
{
// Note: T must be a C++ POD type.
@ -276,7 +296,7 @@ public:
inline void insert(const std::string& key)
{
insert(reinterpret_cast<const unsigned char*>(key.c_str()),key.size());
insert(reinterpret_cast<const unsigned char*>(key.data()),key.size());
}
inline void insert(const char* data, const std::size_t& length)
@ -284,10 +304,11 @@ public:
insert(reinterpret_cast<const unsigned char*>(data),length);
}
template<typename InputIterator>
template <typename InputIterator>
inline void insert(const InputIterator begin, const InputIterator end)
{
InputIterator itr = begin;
while (end != itr)
{
insert(*(itr++));
@ -297,19 +318,22 @@ public:
inline virtual bool contains(const unsigned char* key_begin, const std::size_t length) const
{
std::size_t bit_index = 0;
std::size_t bit = 0;
std::size_t bit = 0;
for (std::size_t i = 0; i < salt_.size(); ++i)
{
compute_indices(hash_ap(key_begin,length,salt_[i]),bit_index,bit);
compute_indices(hash_ap(key_begin, length, salt_[i]), bit_index, bit);
if ((bit_table_[bit_index / bits_per_char] & bit_mask[bit]) != bit_mask[bit])
{
return false;
}
}
return true;
}
template<typename T>
template <typename T>
inline bool contains(const T& t) const
{
return contains(reinterpret_cast<const unsigned char*>(&t),static_cast<std::size_t>(sizeof(T)));
@ -325,33 +349,39 @@ public:
return contains(reinterpret_cast<const unsigned char*>(data),length);
}
template<typename InputIterator>
template <typename InputIterator>
inline InputIterator contains_all(const InputIterator begin, const InputIterator end) const
{
InputIterator itr = begin;
while (end != itr)
{
if (!contains(*itr))
{
return itr;
}
++itr;
}
return end;
}
template<typename InputIterator>
template <typename InputIterator>
inline InputIterator contains_none(const InputIterator begin, const InputIterator end) const
{
InputIterator itr = begin;
while (end != itr)
{
if (contains(*itr))
{
return itr;
}
++itr;
}
return end;
}
@ -360,7 +390,7 @@ public:
return table_size_;
}
inline std::size_t element_count() const
inline unsigned long long int element_count() const
{
return inserted_element_count_;
}
@ -381,16 +411,17 @@ public:
{
/* intersection */
if (
(salt_count_ == f.salt_count_) &&
(table_size_ == f.table_size_) &&
(random_seed_ == f.random_seed_)
(salt_count_ == f.salt_count_ ) &&
(table_size_ == f.table_size_ ) &&
(random_seed_ == f.random_seed_)
)
{
for (std::size_t i = 0; i < raw_table_size_; ++i)
for (std::size_t i = 0; i < bit_table_.size(); ++i)
{
bit_table_[i] &= f.bit_table_[i];
}
}
return *this;
}
@ -398,16 +429,17 @@ public:
{
/* union */
if (
(salt_count_ == f.salt_count_) &&
(table_size_ == f.table_size_) &&
(random_seed_ == f.random_seed_)
(salt_count_ == f.salt_count_ ) &&
(table_size_ == f.table_size_ ) &&
(random_seed_ == f.random_seed_)
)
{
for (std::size_t i = 0; i < raw_table_size_; ++i)
for (std::size_t i = 0; i < bit_table_.size(); ++i)
{
bit_table_[i] |= f.bit_table_[i];
}
}
return *this;
}
@ -415,16 +447,17 @@ public:
{
/* difference */
if (
(salt_count_ == f.salt_count_) &&
(table_size_ == f.table_size_) &&
(random_seed_ == f.random_seed_)
(salt_count_ == f.salt_count_ ) &&
(table_size_ == f.table_size_ ) &&
(random_seed_ == f.random_seed_)
)
{
for (std::size_t i = 0; i < raw_table_size_; ++i)
for (std::size_t i = 0; i < bit_table_.size(); ++i)
{
bit_table_[i] ^= f.bit_table_[i];
}
}
return *this;
}
@ -443,7 +476,7 @@ protected:
inline virtual void compute_indices(const bloom_type& hash, std::size_t& bit_index, std::size_t& bit) const
{
bit_index = hash % table_size_;
bit = bit_index % bits_per_char;
bit = bit_index % bits_per_char;
}
void generate_unique_salt()
@ -455,6 +488,7 @@ protected:
hash function with different values seems to be adequate.
*/
const unsigned int predef_salt_count = 128;
static const bloom_type predef_salt[predef_salt_count] =
{
0xAAAAAAAA, 0x55555555, 0x33333333, 0xCCCCCCCC,
@ -496,25 +530,31 @@ protected:
std::copy(predef_salt,
predef_salt + salt_count_,
std::back_inserter(salt_));
for (unsigned int i = 0; i < salt_.size(); ++i)
{
for (std::size_t i = 0; i < salt_.size(); ++i)
{
/*
Note:
This is done to integrate the user defined random seed,
so as to allow for the generation of unique bloom filter
instances.
Note:
This is done to integrate the user defined random seed,
so as to allow for the generation of unique bloom filter
instances.
*/
salt_[i] = salt_[i] * salt_[(i + 3) % salt_.size()] + static_cast<bloom_type>(random_seed_);
}
}
}
else
{
std::copy(predef_salt,predef_salt + predef_salt_count,std::back_inserter(salt_));
std::copy(predef_salt, predef_salt + predef_salt_count, std::back_inserter(salt_));
srand(static_cast<unsigned int>(random_seed_));
while (salt_.size() < salt_count_)
{
bloom_type current_salt = static_cast<bloom_type>(rand()) * static_cast<bloom_type>(rand());
if (0 == current_salt) continue;
if (0 == current_salt)
continue;
if (salt_.end() == std::find(salt_.begin(), salt_.end(), current_salt))
{
salt_.push_back(current_salt);
@ -526,57 +566,71 @@ protected:
inline bloom_type hash_ap(const unsigned char* begin, std::size_t remaining_length, bloom_type hash) const
{
const unsigned char* itr = begin;
unsigned int loop = 0;
unsigned int loop = 0;
while (remaining_length >= 8)
{
const unsigned int& i1 = *(reinterpret_cast<const unsigned int*>(itr)); itr += sizeof(unsigned int);
const unsigned int& i2 = *(reinterpret_cast<const unsigned int*>(itr)); itr += sizeof(unsigned int);
hash ^= (hash << 7) ^ i1 * (hash >> 3) ^
(~((hash << 11) + (i2 ^ (hash >> 5))));
remaining_length -= 8;
}
if (remaining_length)
{
if (remaining_length >= 4)
{
const unsigned int& i = *(reinterpret_cast<const unsigned int*>(itr));
if (loop & 0x01)
hash ^= (hash << 7) ^ i * (hash >> 3);
else
hash ^= (~((hash << 11) + (i ^ (hash >> 5))));
++loop;
remaining_length -= 4;
itr += sizeof(unsigned int);
}
if (remaining_length >= 2)
{
const unsigned short& i = *(reinterpret_cast<const unsigned short*>(itr));
if (loop & 0x01)
hash ^= (hash << 7) ^ i * (hash >> 3);
else
hash ^= (~((hash << 11) + (i ^ (hash >> 5))));
++loop;
remaining_length -= 2;
itr += sizeof(unsigned short);
}
if (remaining_length)
{
hash += ((*itr) ^ (hash * 0xA5A5A5A5)) + loop;
}
}
return hash;
}
public:
std::vector<bloom_type> salt_;
std::vector<unsigned char> bit_table_;
unsigned int salt_count_;
unsigned long long int table_size_;
unsigned long long int raw_table_size_;
unsigned long long int projected_element_count_;
unsigned int inserted_element_count_;
unsigned long long int random_seed_;
double desired_false_positive_probability_;
public:
std::vector<bloom_type> salt_;
std::vector<unsigned char> bit_table_;
unsigned int salt_count_;
unsigned long long int table_size_;
unsigned long long int projected_element_count_;
unsigned long long int inserted_element_count_;
unsigned long long int random_seed_;
double desired_false_positive_probability_;
};
inline bloom_filter operator & (const bloom_filter& a, const bloom_filter& b)
@ -603,17 +657,15 @@ inline bloom_filter operator ^ (const bloom_filter& a, const bloom_filter& b)
} // namespace fc
#endif
FC_REFLECT( fc::bloom_filter, (salt_)(bit_table_)(salt_count_)(table_size_)(raw_table_size_)(projected_element_count_)(inserted_element_count_)(random_seed_)(desired_false_positive_probability_) )
FC_REFLECT( fc::bloom_parameters::optimal_parameters_t, (number_of_hashes)(table_size) )
FC_REFLECT( fc::bloom_parameters, (minimum_size)(maximum_size)(minimum_number_of_hashes)(maximum_number_of_hashes)(projected_element_count)(false_positive_probability)(random_seed)(optimal_parameters) )
/*
Note 1:
If it can be guaranteed that bits_per_char will be of the form 2^n then
the following optimization can be used:
hash_table[bit_index >> n] |= bit_mask[bit_index & (bits_per_char - 1)];
bit_table_[bit_index >> n] |= bit_mask[bit_index & (bits_per_char - 1)];
Note 2:
For performance reasons where possible when allocating memory it should

View file

@ -1,9 +0,0 @@
#pragma once
#include <string>
namespace fc {
std::string smaz_compress( const std::string& in );
std::string smaz_decompress( const std::string& compressed );
} // namespace fc

10
include/fc/compress/zlib.hpp Executable file → Normal file
View file

@ -1,16 +1,10 @@
#pragma once
#include <fc/string.hpp>
#ifdef FC_USE_FULL_ZLIB
# include <fc/filesystem.hpp>
#endif
#include <string>
namespace fc
{
string zlib_compress(const string& in);
#ifdef FC_USE_FULL_ZLIB
void gzip_compress_file(const path& input_filename, const path& output_filename);
#endif
std::string zlib_compress(const std::string& in);
} // namespace fc

View file

@ -6,4 +6,9 @@
#ifndef FC_MAX_LOG_OBJECT_DEPTH
// how many levels of nested objects are displayed in log messages
#define FC_MAX_LOG_OBJECT_DEPTH 200
#endif
#endif
#ifndef FC_MAX_PREALLOC_SIZE
// how many elements will be reserve()d when deserializing vectors
#define FC_MAX_PREALLOC_SIZE (256UL)
#endif

View file

@ -1,12 +0,0 @@
#pragma once
#include <deque>
#include <fc/io/raw.hpp>
namespace fc {
namespace raw {
} // namespace raw
} // namespace fc

View file

@ -1,14 +0,0 @@
#pragma once
#include <fc/config.hpp>
#include <deque>
namespace fc {
namespace raw {
template<typename Stream, typename T>
void pack( Stream& s, const std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T>
void unpack( Stream& s, std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
}
} // namespace fc

39
include/fc/container/flat.hpp Executable file → Normal file
View file

@ -7,11 +7,11 @@
namespace fc {
namespace raw {
template<typename Stream, typename T>
inline void pack( Stream& s, const flat_set<T>& value, uint32_t _max_depth ) {
template<typename Stream, typename T, typename... A>
inline void pack( Stream& s, const flat_set<T, A...>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
pack( s, unsigned_int(value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
@ -19,14 +19,13 @@ namespace fc {
++itr;
}
}
template<typename Stream, typename T>
inline void unpack( Stream& s, flat_set<T>& value, uint32_t _max_depth ) {
template<typename Stream, typename T, typename... A>
inline void unpack( Stream& s, flat_set<T, A...>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
unsigned_int size; unpack( s, size, _max_depth );
value.clear();
FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE );
value.reserve(size.value);
value.reserve( std::min( size.value, static_cast<uint64_t>(FC_MAX_PREALLOC_SIZE) ) );
for( uint32_t i = 0; i < size.value; ++i )
{
T tmp;
@ -38,7 +37,7 @@ namespace fc {
inline void pack( Stream& s, const flat_map<K,V...>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
pack( s, unsigned_int(value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
@ -53,8 +52,7 @@ namespace fc {
--_max_depth;
unsigned_int size; unpack( s, size, _max_depth );
value.clear();
FC_ASSERT( size.value*(sizeof(K)+sizeof(V)) < MAX_ARRAY_ALLOC_SIZE );
value.reserve(size.value);
value.reserve( std::min( size.value, static_cast<uint64_t>(FC_MAX_PREALLOC_SIZE) ) );
for( uint32_t i = 0; i < size.value; ++i )
{
std::pair<K,V> tmp;
@ -67,7 +65,7 @@ namespace fc {
void pack( Stream& s, const bip::vector<T,A>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
pack( s, unsigned_int(value.size()), _max_depth );
if( !std::is_fundamental<T>::value ) {
auto itr = value.begin();
auto end = value.end();
@ -86,11 +84,16 @@ namespace fc {
--_max_depth;
unsigned_int size;
unpack( s, size, _max_depth );
value.resize( size );
if( !std::is_fundamental<T>::value ) {
for( auto& item : value )
unpack( s, item, _max_depth );
value.resize( std::min( size.value, static_cast<uint64_t>(FC_MAX_PREALLOC_SIZE) ) );
for( uint64_t i = 0; i < size; i++ )
{
if( i >= value.size() )
value.resize( std::min( static_cast<uint64_t>(2*value.size()), size.value ) );
unpack( s, value[i], _max_depth );
}
} else {
value.resize( size );
s.read( (char*)value.data(), value.size() );
}
}
@ -98,8 +101,8 @@ namespace fc {
} // namespace raw
template<typename T>
void to_variant( const flat_set<T>& var, variant& vo, uint32_t _max_depth )
template<typename T, typename... A>
void to_variant( const flat_set<T, A...>& var, variant& vo, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
--_max_depth;
@ -109,8 +112,8 @@ namespace fc {
vars[i++] = variant( item, _max_depth );
vo = vars;
}
template<typename T>
void from_variant( const variant& var, flat_set<T>& vo, uint32_t _max_depth )
template<typename T, typename... A>
void from_variant( const variant& var, flat_set<T, A...>& vo, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
--_max_depth;

8
include/fc/container/flat_fwd.hpp Executable file → Normal file
View file

@ -11,10 +11,10 @@ namespace fc {
namespace bip = boost::interprocess;
namespace raw {
template<typename Stream, typename T>
void pack( Stream& s, const flat_set<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T>
void unpack( Stream& s, flat_set<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T, typename... A>
void pack( Stream& s, const flat_set<T, A...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T, typename... A>
void unpack( Stream& s, flat_set<T, A...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename K, typename... V>
void pack( Stream& s, const flat_map<K,V...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename K, typename V, typename... A>

View file

@ -0,0 +1,87 @@
/*
* Copyright (c) 2019 BitShares Blockchain Foundation, and contributors
*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include <fc/io/raw_fwd.hpp>
namespace fc {
template< typename T, size_t N >
class zero_initialized_array;
template< size_t N >
class zero_initialized_array< unsigned char, N > : public std::array< unsigned char, N > {
public:
zero_initialized_array() : std::array< unsigned char, N >() { }
};
template<typename T,size_t N>
struct get_typename< zero_initialized_array<T,N> >
{
static const char* name()
{
static std::string _name = std::string("zero_initialized_array<")
+ std::string(fc::get_typename<T>::name())
+ "," + fc::to_string(N) + ">";
return _name.c_str();
}
};
class variant;
template<size_t N>
void to_variant( const zero_initialized_array<unsigned char,N>& bi, variant& v, uint32_t max_depth = 1 )
{
to_variant( static_cast<const std::array<unsigned char,N>&>( bi ), v, max_depth );
}
template<size_t N>
void from_variant( const variant& v, zero_initialized_array<unsigned char,N>& bi, uint32_t max_depth = 1 )
{
from_variant( v, static_cast<std::array<unsigned char,N>&>( bi ), max_depth );
}
namespace raw {
template<typename Stream, size_t N>
inline void pack( Stream& s, const zero_initialized_array<unsigned char,N>& v, uint32_t _max_depth ) {
pack( s, static_cast<const std::array<unsigned char,N>&>( v ), _max_depth );
}
template<typename Stream, size_t N>
inline void unpack( Stream& s, zero_initialized_array<unsigned char,N>& v, uint32_t _max_depth ) {
try {
unpack( s, static_cast<std::array<unsigned char,N>&>( v ), _max_depth );
} FC_RETHROW_EXCEPTIONS( warn, "zero_initialized_array<unsigned char,${length}>", ("length",N) )
}
}
}
namespace std {
#if defined(__clang__)
// Fix: https://github.com/bitshares/bitshares-core/issues/2197
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmismatched-tags"
#endif
template< typename T, size_t N >
class tuple_size< fc::zero_initialized_array< T, N > > : public tuple_size< array< T, N > > {};
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
}

10
include/fc/crypto/aes.hpp Executable file → Normal file
View file

@ -1,8 +1,10 @@
#pragma once
#include <fc/crypto/sha512.hpp>
#include <fc/crypto/sha256.hpp>
#include <fc/uint128.hpp>
#include <fc/fwd.hpp>
#include <fc/uint128.hpp>
#include <vector>
namespace fc {
@ -14,9 +16,8 @@ namespace fc {
aes_encoder();
~aes_encoder();
void init( const fc::sha256& key, const fc::uint128& init_value );
void init( const fc::sha256& key, const uint128_t& init_value );
uint32_t encode( const char* plaintxt, uint32_t len, char* ciphertxt );
// uint32_t final_encode( char* ciphertxt );
private:
struct impl;
@ -28,9 +29,8 @@ namespace fc {
aes_decoder();
~aes_decoder();
void init( const fc::sha256& key, const fc::uint128& init_value );
void init( const fc::sha256& key, const uint128_t& init_value );
uint32_t decode( const char* ciphertxt, uint32_t len, char* plaintext );
// uint32_t final_decode( char* plaintext );
private:
struct impl;

View file

@ -1,10 +0,0 @@
#pragma once
#include <fc/vector.hpp>
#include <fc/string.hpp>
namespace fc
{
std::vector<char> from_base36( const fc::string& b36 );
fc::string to_base36( const std::vector<char>& vec );
fc::string to_base36( const char* data, size_t len );
}

2
include/fc/crypto/base58.hpp Executable file → Normal file
View file

@ -1,5 +1,5 @@
#pragma once
#include <fc/string.hpp>
#include <string>
#include <vector>
namespace fc {

0
include/fc/crypto/base64.hpp Executable file → Normal file
View file

6
include/fc/crypto/bigint.hpp Executable file → Normal file
View file

@ -1,7 +1,7 @@
#pragma once
#include <stdint.h>
#include <fc/string.hpp>
#include <fc/vector.hpp>
#include <string>
#include <vector>
struct bignum_st;
typedef bignum_st BIGNUM;
@ -55,7 +55,7 @@ namespace fc {
bigint operator--(int);
bigint& operator--();
operator fc::string()const;
operator std::string()const;
// returns bignum as bigendian bytes
operator std::vector<char>()const;

View file

@ -1,178 +0,0 @@
////////////////////////////////////////////////////////////////////////////
///
// Blowfish.h Header File
//
// BLOWFISH ENCRYPTION ALGORITHM
//
// encryption and decryption of Byte Strings using the Blowfish encryption Algorithm.
// Blowfish is a block cipher that encrypts data in 8-byte blocks. The algorithm consists
// of two parts: a key-expansion part and a data-ancryption part. Key expansion converts a
// variable key of at least 1 and at most 56 bytes into several subkey arrays totaling
// 4168 bytes. Blowfish has 16 rounds. Each round consists of a key-dependent permutation,
// and a key and data-dependent substitution. All operations are XORs and additions on 32-bit words.
// The only additional operations are four indexed array data lookups per round.
// Blowfish uses a large number of subkeys. These keys must be precomputed before any data
// encryption or decryption. The P-array consists of 18 32-bit subkeys: P0, P1,...,P17.
// There are also four 32-bit S-boxes with 256 entries each: S0,0, S0,1,...,S0,255;
// S1,0, S1,1,...,S1,255; S2,0, S2,1,...,S2,255; S3,0, S3,1,...,S3,255;
//
// The Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback modes
// are used:
//
// In ECB mode if the same block is encrypted twice with the same key, the resulting
// ciphertext blocks are the same.
//
// In CBC Mode a ciphertext block is obtained by first xoring the
// plaintext block with the previous ciphertext block, and encrypting the resulting value.
//
// In CFB mode a ciphertext block is obtained by encrypting the previous ciphertext block
// and xoring the resulting value with the plaintext
//
// The previous ciphertext block is usually stored in an Initialization Vector (IV).
// An Initialization Vector of zero is commonly used for the first block, though other
// arrangements are also in use.
/*
http://www.counterpane.com/vectors.txt
Test vectors by Eric Young. These tests all assume Blowfish with 16
rounds.
All data is shown as a hex string with 012345 loading as
data[0]=0x01;
data[1]=0x23;
data[2]=0x45;
ecb test data (taken from the DES validation tests)
key bytes clear bytes cipher bytes
0000000000000000 0000000000000000 4EF997456198DD78
FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 51866FD5B85ECB8A
3000000000000000 1000000000000001 7D856F9A613063F2 ???
1111111111111111 1111111111111111 2466DD878B963C9D
0123456789ABCDEF 1111111111111111 61F9C3802281B096
1111111111111111 0123456789ABCDEF 7D0CC630AFDA1EC7
0000000000000000 0000000000000000 4EF997456198DD78
FEDCBA9876543210 0123456789ABCDEF 0ACEAB0FC6A0A28D
7CA110454A1A6E57 01A1D6D039776742 59C68245EB05282B
0131D9619DC1376E 5CD54CA83DEF57DA B1B8CC0B250F09A0
07A1133E4A0B2686 0248D43806F67172 1730E5778BEA1DA4
3849674C2602319E 51454B582DDF440A A25E7856CF2651EB
04B915BA43FEB5B6 42FD443059577FA2 353882B109CE8F1A
0113B970FD34F2CE 059B5E0851CF143A 48F4D0884C379918
0170F175468FB5E6 0756D8E0774761D2 432193B78951FC98
43297FAD38E373FE 762514B829BF486A 13F04154D69D1AE5
07A7137045DA2A16 3BDD119049372802 2EEDDA93FFD39C79
04689104C2FD3B2F 26955F6835AF609A D887E0393C2DA6E3
37D06BB516CB7546 164D5E404F275232 5F99D04F5B163969
1F08260D1AC2465E 6B056E18759F5CCA 4A057A3B24D3977B
584023641ABA6176 004BD6EF09176062 452031C1E4FADA8E
025816164629B007 480D39006EE762F2 7555AE39F59B87BD
49793EBC79B3258F 437540C8698F3CFA 53C55F9CB49FC019
4FB05E1515AB73A7 072D43A077075292 7A8E7BFA937E89A3
49E95D6D4CA229BF 02FE55778117F12A CF9C5D7A4986ADB5
018310DC409B26D6 1D9D5C5018F728C2 D1ABB290658BC778
1C587F1C13924FEF 305532286D6F295A 55CB3774D13EF201
0101010101010101 0123456789ABCDEF FA34EC4847B268B2
1F1F1F1F0E0E0E0E 0123456789ABCDEF A790795108EA3CAE
E0FEE0FEF1FEF1FE 0123456789ABCDEF C39E072D9FAC631D
0000000000000000 FFFFFFFFFFFFFFFF 014933E0CDAFF6E4
FFFFFFFFFFFFFFFF 0000000000000000 F21E9A77B71C49BC
0123456789ABCDEF 0000000000000000 245946885754369A
FEDCBA9876543210 FFFFFFFFFFFFFFFF 6B5C5A9C5D9E0A5A
set_key test data
data[8]= FEDCBA9876543210
c=F9AD597C49DB005E k[ 1]=F0
c=E91D21C1D961A6D6 k[ 2]=F0E1
c=E9C2B70A1BC65CF3 k[ 3]=F0E1D2
c=BE1E639408640F05 k[ 4]=F0E1D2C3
c=B39E44481BDB1E6E k[ 5]=F0E1D2C3B4
c=9457AA83B1928C0D k[ 6]=F0E1D2C3B4A5
c=8BB77032F960629D k[ 7]=F0E1D2C3B4A596
c=E87A244E2CC85E82 k[ 8]=F0E1D2C3B4A59687
c=15750E7A4F4EC577 k[ 9]=F0E1D2C3B4A5968778
c=122BA70B3AB64AE0 k[10]=F0E1D2C3B4A596877869
c=3A833C9AFFC537F6 k[11]=F0E1D2C3B4A5968778695A
c=9409DA87A90F6BF2 k[12]=F0E1D2C3B4A5968778695A4B
c=884F80625060B8B4 k[13]=F0E1D2C3B4A5968778695A4B3C
c=1F85031C19E11968 k[14]=F0E1D2C3B4A5968778695A4B3C2D
c=79D9373A714CA34F k[15]=F0E1D2C3B4A5968778695A4B3C2D1E ???
c=93142887EE3BE15C k[16]=F0E1D2C3B4A5968778695A4B3C2D1E0F
c=03429E838CE2D14B k[17]=F0E1D2C3B4A5968778695A4B3C2D1E0F00
c=A4299E27469FF67B k[18]=F0E1D2C3B4A5968778695A4B3C2D1E0F0011
c=AFD5AED1C1BC96A8 k[19]=F0E1D2C3B4A5968778695A4B3C2D1E0F001122
c=10851C0E3858DA9F k[20]=F0E1D2C3B4A5968778695A4B3C2D1E0F00112233
c=E6F51ED79B9DB21F k[21]=F0E1D2C3B4A5968778695A4B3C2D1E0F0011223344
c=64A6E14AFD36B46F k[22]=F0E1D2C3B4A5968778695A4B3C2D1E0F001122334455
c=80C7D7D45A5479AD k[23]=F0E1D2C3B4A5968778695A4B3C2D1E0F00112233445566
c=05044B62FA52D080 k[24]=F0E1D2C3B4A5968778695A4B3C2D1E0F0011223344556677
chaining mode test data
key[16] = 0123456789ABCDEFF0E1D2C3B4A59687
iv[8] = FEDCBA9876543210
data[29] = "7654321 Now is the time for " (includes trailing '\0')
data[29] = 37363534333231204E6F77206973207468652074696D6520666F722000
cbc cipher text
cipher[32]= 6B77B4D63006DEE605B156E27403979358DEB9E7154616D959F1652BD5FF92CC
cfb64 cipher text cipher[29]=
E73214A2822139CAF26ECF6D2EB9E76E3DA3DE04D1517200519D57A6C3
ofb64 cipher text cipher[29]=
E73214A2822139CA62B343CC5B65587310DD908D0C241B2263C2CF80DA
*/
#pragma once
#include <stdint.h>
namespace fc {
//Block Structure
struct sblock
{
//Constructors
sblock(unsigned int l=0, unsigned int r=0) : m_uil(l), m_uir(r) {}
//Copy Constructor
sblock(const sblock& roBlock) : m_uil(roBlock.m_uil), m_uir(roBlock.m_uir) {}
sblock& operator^=(sblock& b) { m_uil ^= b.m_uil; m_uir ^= b.m_uir; return *this; }
unsigned int m_uil, m_uir;
};
class blowfish
{
public:
enum { ECB=0, CBC=1, CFB=2 };
//Constructor - Initialize the P and S boxes for a given Key
blowfish();
void start(unsigned char* ucKey, uint64_t n, const sblock& roChain = sblock(0UL,0UL));
//Resetting the chaining block
void reset_chain() { m_oChain = m_oChain0; }
// encrypt/decrypt Buffer in Place
void encrypt(unsigned char* buf, uint64_t n, int iMode=CFB);
void decrypt(unsigned char* buf, uint64_t n, int iMode=CFB);
// encrypt/decrypt from Input Buffer to Output Buffer
void encrypt(const unsigned char* in, unsigned char* out, uint64_t n, int iMode=CFB);
void decrypt(const unsigned char* in, unsigned char* out, uint64_t n, int iMode=CFB);
//Private Functions
private:
unsigned int F(unsigned int ui);
void encrypt(sblock&);
void decrypt(sblock&);
private:
//The Initialization Vector, by default {0, 0}
sblock m_oChain0;
sblock m_oChain;
unsigned int m_auiP[18];
unsigned int m_auiS[4][256];
static const unsigned int scm_auiInitP[18];
static const unsigned int scm_auiInitS[4][256];
};
} // namespace fc

19
include/fc/crypto/city.hpp Executable file → Normal file
View file

@ -41,36 +41,25 @@
// doesn't hold for any hash functions in this file.
#pragma once
#include <fc/uint128.hpp>
#include <stdlib.h> // for size_t.
#include <stdint.h>
#include <utility>
namespace fc {
template<typename T, size_t N>
class array;
class uint128;
// Hash function for a byte array.
uint64_t city_hash64(const char *buf, size_t len);
uint32_t city_hash32(const char *buf, size_t len);
#if SIZE_MAX > UINT32_MAX
inline size_t city_hash_size_t(const char *buf, size_t len) { return city_hash64(buf, len); }
#else
uint32_t city_hash32(const char *buf, size_t len);
inline size_t city_hash_size_t(const char *buf, size_t len) { return city_hash32(buf, len); }
#endif
// Hash function for a byte array.
uint128 city_hash128(const char *s, size_t len);
// Hash function for a byte array.
uint64_t city_hash_crc_64(const char *buf, size_t len);
// Hash function for a byte array.
uint128 city_hash_crc_128(const char *s, size_t len);
array<uint64_t,4> city_hash_crc_256(const char *s, size_t len);
uint128_t city_hash_crc_128(const char *s, size_t len);
} // namespace fc

0
include/fc/crypto/dh.hpp Executable file → Normal file
View file

0
include/fc/crypto/digest.hpp Executable file → Normal file
View file

43
include/fc/crypto/elliptic.hpp Executable file → Normal file
View file

@ -1,12 +1,14 @@
#pragma once
#include <fc/container/zeroed_array.hpp>
#include <fc/crypto/bigint.hpp>
#include <fc/crypto/openssl.hpp>
#include <fc/crypto/sha256.hpp>
#include <fc/crypto/sha512.hpp>
#include <fc/fwd.hpp>
#include <fc/array.hpp>
#include <fc/io/raw_fwd.hpp>
#include <array>
namespace fc {
namespace ecc {
@ -16,16 +18,16 @@ namespace fc {
class private_key_impl;
}
typedef fc::sha256 blind_factor_type;
typedef fc::array<char,33> commitment_type;
typedef fc::array<char,33> public_key_data;
typedef fc::sha256 private_key_secret;
typedef fc::array<char,65> public_key_point_data; ///< the full non-compressed version of the ECC point
typedef fc::array<char,72> signature;
typedef fc::array<unsigned char,65> compact_signature;
typedef std::vector<char> range_proof_type;
typedef fc::array<char,78> extended_key_data;
typedef fc::sha256 blind_factor_type;
typedef zero_initialized_array<unsigned char,33> commitment_type;
typedef zero_initialized_array<unsigned char,33> public_key_data;
typedef fc::sha256 private_key_secret;
typedef zero_initialized_array<unsigned char,65> public_key_point_data; ///< the full non-compressed version of the ECC point
typedef zero_initialized_array<unsigned char,72> signature;
typedef zero_initialized_array<unsigned char,65> compact_signature;
typedef std::vector<char> range_proof_type;
typedef zero_initialized_array<unsigned char,78> extended_key_data;
/**
* @class public_key
* @brief contains only the public point of an elliptic curve key.
@ -117,9 +119,7 @@ namespace fc {
*/
fc::sha512 get_shared_secret( const public_key& pub )const;
// signature sign( const fc::sha256& digest )const;
compact_signature sign_compact( const fc::sha256& digest, bool require_canonical = true )const;
// bool verify( const fc::sha256& digest, const signature& sig );
public_key get_public_key()const;
@ -155,9 +155,9 @@ namespace fc {
extended_key_data serialize_extended() const;
static extended_public_key deserialize( const extended_key_data& data );
fc::string str() const;
fc::string to_base58() const { return str(); }
static extended_public_key from_base58( const fc::string& base58 );
std::string str() const;
std::string to_base58() const { return str(); }
static extended_public_key from_base58( const std::string& base58 );
private:
sha256 c;
@ -179,16 +179,15 @@ namespace fc {
extended_key_data serialize_extended() const;
static extended_private_key deserialize( const extended_key_data& data );
fc::string str() const;
fc::string to_base58() const { return str(); }
static extended_private_key from_base58( const fc::string& base58 );
static extended_private_key generate_master( const fc::string& seed );
std::string str() const;
std::string to_base58() const { return str(); }
static extended_private_key from_base58( const std::string& base58 );
static extended_private_key generate_master( const std::string& seed );
static extended_private_key generate_master( const char* seed, uint32_t seed_len );
private:
private:
extended_private_key private_derive_rest( const fc::sha512& hash,
int num ) const;
sha256 c;
int child_num, parent_fp;
uint8_t depth;

View file

@ -0,0 +1,124 @@
/*
* Copyright (c) 2018 jmjatlanta and contributors.
*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
#include <boost/endian/buffers.hpp>
#include <fc/fwd.hpp>
#include <fc/string.hpp>
#include <fc/io/raw_fwd.hpp>
namespace fc{
class hash160
{
public:
hash160();
explicit hash160( const string& hex_str );
string str()const;
explicit operator string()const;
char* data() const;
static constexpr size_t data_size() { return 160/8; }
static hash160 hash( const char* d, uint32_t dlen );
static hash160 hash( const string& );
template<typename T>
static hash160 hash( const T& t )
{
hash160::encoder e;
fc::raw::pack(e,t);
return e.result();
}
class encoder
{
public:
encoder();
~encoder();
void write( const char* d, uint32_t dlen );
void put( char c ) { write( &c, 1 ); }
void reset();
hash160 result();
private:
struct impl;
fc::fwd<impl,117> my;
};
template<typename T>
inline friend T& operator<<( T& ds, const hash160& ep ) {
ds.write( ep.data(), sizeof(ep) );
return ds;
}
template<typename T>
inline friend T& operator>>( T& ds, hash160& ep ) {
ds.read( ep.data(), sizeof(ep) );
return ds;
}
friend hash160 operator << ( const hash160& h1, uint32_t i );
friend bool operator == ( const hash160& h1, const hash160& h2 );
friend bool operator != ( const hash160& h1, const hash160& h2 );
friend hash160 operator ^ ( const hash160& h1, const hash160& h2 );
friend bool operator >= ( const hash160& h1, const hash160& h2 );
friend bool operator > ( const hash160& h1, const hash160& h2 );
friend bool operator < ( const hash160& h1, const hash160& h2 );
boost::endian::little_uint32_buf_t _hash[5];
};
namespace raw {
template<typename T>
inline void pack( T& ds, const hash160& ep, uint32_t _max_depth ) {
ds << ep;
}
template<typename T>
inline void unpack( T& ds, hash160& ep, uint32_t _max_depth ) {
ds >> ep;
}
}
class variant;
void to_variant( const hash160& bi, variant& v, uint32_t max_depth );
void from_variant( const variant& v, hash160& bi, uint32_t max_depth );
template<> struct get_typename<hash160> { static const char* name() { return "hash160"; } };
} // namespace fc
namespace std
{
template<>
struct hash<fc::hash160>
{
size_t operator()( const fc::hash160& s )const
{
return *((size_t*)&s);
}
};
}

8
include/fc/crypto/hex.hpp Executable file → Normal file
View file

@ -1,15 +1,15 @@
#pragma once
#include <fc/string.hpp>
#include <fc/utility.hpp>
#include <stdint.h>
#include <string>
#include <vector>
namespace fc {
uint8_t from_hex( char c );
fc::string to_hex( const char* d, uint32_t s );
std::string to_hex( const char* d, uint32_t s );
std::string to_hex( const std::vector<char>& data );
/**
* @return the number of bytes decoded
*/
size_t from_hex( const fc::string& hex_str, char* out_data, size_t out_data_len );
size_t from_hex( const std::string& hex_str, char* out_data, size_t out_data_len );
}

0
include/fc/crypto/hmac.hpp Executable file → Normal file
View file

View file

@ -1,76 +0,0 @@
#pragma once
#include <fc/fwd.hpp>
#include <fc/string.hpp>
namespace fc
{
class md5
{
public:
md5();
explicit md5( const string& hex_str );
string str()const;
operator string()const;
char* data()const;
size_t data_size()const { return 128 / 8; }
static md5 hash( const char* d, uint32_t dlen );
static md5 hash( const string& );
template<typename T>
static md5 hash( const T& t )
{
md5::encoder e;
e << t;
return e.result();
}
class encoder
{
public:
encoder();
~encoder();
void write( const char* d, uint32_t dlen );
void put( char c ) { write( &c, 1 ); }
void reset();
md5 result();
private:
struct impl;
fc::fwd<impl,216> my;
};
template<typename T>
inline friend T& operator<<( T& ds, const md5& ep ) {
ds.write( ep.data(), sizeof(ep) );
return ds;
}
template<typename T>
inline friend T& operator>>( T& ds, md5& ep ) {
ds.read( ep.data(), sizeof(ep) );
return ds;
}
friend md5 operator << ( const md5& h1, uint32_t i );
friend bool operator == ( const md5& h1, const md5& h2 );
friend bool operator != ( const md5& h1, const md5& h2 );
friend md5 operator ^ ( const md5& h1, const md5& h2 );
friend bool operator >= ( const md5& h1, const md5& h2 );
friend bool operator > ( const md5& h1, const md5& h2 );
friend bool operator < ( const md5& h1, const md5& h2 );
uint64_t _hash[2];
};
class variant;
void to_variant( const md5& bi, variant& v, uint32_t max_depth = 1 );
void from_variant( const variant& v, md5& bi, uint32_t max_depth = 1 );
} // fc
#include <fc/reflect/reflect.hpp>
FC_REFLECT_TYPENAME( fc::md5 )

28
include/fc/crypto/openssl.hpp Executable file → Normal file
View file

@ -1,6 +1,7 @@
#pragma once
#include <openssl/ec.h>
#include <openssl/crypto.h>
#include <openssl/dh.h>
#include <openssl/evp.h>
#include <openssl/conf.h>
#include <openssl/err.h>
@ -8,6 +9,7 @@
#include <openssl/ecdh.h>
#include <openssl/sha.h>
#include <openssl/obj_mac.h>
#include <openssl/bn.h>
/**
* @file openssl.hpp
@ -21,6 +23,8 @@ namespace fc
struct ssl_wrapper
{
ssl_wrapper(ssl_type* obj):obj(obj) {}
ssl_wrapper( ssl_wrapper& copy ) = delete;
ssl_wrapper& operator=( ssl_wrapper& copy ) = delete;
operator ssl_type*() { return obj; }
operator const ssl_type*() const { return obj; }
@ -30,23 +34,21 @@ namespace fc
ssl_type* obj;
};
#define SSL_TYPE(name, ssl_type, free_func) \
#define SSL_TYPE_DECL(name, ssl_type) \
struct name : public ssl_wrapper<ssl_type> \
{ \
name(ssl_type* obj=nullptr) \
: ssl_wrapper(obj) {} \
~name() \
{ \
if( obj != nullptr ) \
free_func(obj); \
} \
name( ssl_type* obj=nullptr ); \
name( name&& move ); \
~name(); \
name& operator=( name&& move ); \
};
SSL_TYPE(ec_group, EC_GROUP, EC_GROUP_free)
SSL_TYPE(ec_point, EC_POINT, EC_POINT_free)
SSL_TYPE(ecdsa_sig, ECDSA_SIG, ECDSA_SIG_free)
SSL_TYPE(bn_ctx, BN_CTX, BN_CTX_free)
SSL_TYPE(evp_cipher_ctx, EVP_CIPHER_CTX, EVP_CIPHER_CTX_free )
SSL_TYPE_DECL(ec_group, EC_GROUP)
SSL_TYPE_DECL(ec_point, EC_POINT)
SSL_TYPE_DECL(ecdsa_sig, ECDSA_SIG)
SSL_TYPE_DECL(bn_ctx, BN_CTX)
SSL_TYPE_DECL(evp_cipher_ctx, EVP_CIPHER_CTX)
SSL_TYPE_DECL(ssl_dh, DH)
/** allocates a bignum by default.. */
struct ssl_bignum : public ssl_wrapper<BIGNUM>

View file

@ -1,117 +0,0 @@
#pragma once
#include <memory>
#include <vector>
#include <fc/crypto/sha1.hpp>
#include <fc/crypto/sha256.hpp>
#include <fc/io/raw_fwd.hpp>
#include <fc/array.hpp>
namespace fc {
namespace detail { class pke_impl; }
class private_key;
class public_key;
void generate_key_pair( public_key&, private_key& );
typedef std::vector<char> bytes;
typedef bytes signature;
class public_key
{
public:
public_key();
explicit public_key( const bytes& d );
public_key( const public_key& k );
public_key( public_key&& k );
~public_key();
operator bool()const;
public_key& operator=(const public_key& p );
public_key& operator=(public_key&& p );
bool verify( const sha1& digest, const array<char,2048/8>& sig )const;
bool verify( const sha1& digest, const signature& sig )const;
bool verify( const sha256& digest, const signature& sig )const;
bytes encrypt( const char* data, size_t len )const;
bytes encrypt( const bytes& )const;
bytes decrypt( const bytes& )const;
bytes serialize()const;
friend void generate_key_pair( public_key&, private_key& );
private:
std::shared_ptr<detail::pke_impl> my;
};
class private_key
{
public:
private_key();
explicit private_key( const bytes& d );
private_key( const private_key& k );
private_key( private_key&& k );
~private_key();
operator bool()const;
private_key& operator=(const private_key& p );
private_key& operator=(private_key&& p );
void sign( const sha1& digest, array<char,2048/8>& sig )const;
signature sign( const sha1& digest )const;
signature sign( const sha256& digest )const;
bytes decrypt( const char* bytes, size_t len )const;
bytes decrypt( const bytes& )const;
bytes encrypt( const bytes& )const;
bytes serialize()const;
friend void generate_key_pair( public_key&, private_key& );
private:
std::shared_ptr<detail::pke_impl> my;
};
bool operator==( const private_key& a, const private_key& b );
namespace raw
{
template<typename Stream>
void unpack( Stream& s, fc::public_key& pk, uint32_t _max_depth=FC_PACK_MAX_DEPTH )
{
FC_ASSERT( _max_depth > 0 );
bytes ser;
fc::raw::unpack( s, ser, _max_depth - 1 );
pk = fc::public_key( ser );
}
template<typename Stream>
void pack( Stream& s, const fc::public_key& pk, uint32_t _max_depth=FC_PACK_MAX_DEPTH )
{
FC_ASSERT( _max_depth > 0 );
fc::raw::pack( s, pk.serialize(), _max_depth - 1 );
}
template<typename Stream>
void unpack( Stream& s, fc::private_key& pk, uint32_t _max_depth=FC_PACK_MAX_DEPTH )
{
FC_ASSERT( _max_depth > 0 );
bytes ser;
fc::raw::unpack( s, ser, _max_depth - 1 );
pk = fc::private_key( ser );
}
template<typename Stream>
void pack( Stream& s, const fc::private_key& pk, uint32_t _max_depth=FC_PACK_MAX_DEPTH )
{
FC_ASSERT( _max_depth > 0 );
fc::raw::pack( s, pk.serialize(), _max_depth - 1 );
}
}
class variant;
void to_variant( const public_key& bi, variant& v, uint32_t max_depth = 1 );
void from_variant( const variant& v, public_key& bi, uint32_t max_depth = 1 );
void to_variant( const private_key& bi, variant& v, uint32_t max_depth = 1 );
void from_variant( const variant& v, private_key& bi, uint32_t max_depth = 1 );
} // fc

1
include/fc/crypto/rand.hpp Executable file → Normal file
View file

@ -4,5 +4,4 @@ namespace fc {
/* provides access to the OpenSSL random number generator */
void rand_bytes(char* buf, int count);
void rand_pseudo_bytes(char* buf, int count);
} // namespace fc

22
include/fc/crypto/ripemd160.hpp Executable file → Normal file
View file

@ -1,5 +1,5 @@
#pragma once
#include <boost/endian/buffers.hpp>
#include <fc/fwd.hpp>
#include <fc/io/raw_fwd.hpp>
#include <fc/reflect/typename.hpp>
@ -18,7 +18,7 @@ class ripemd160
explicit operator string()const;
char* data()const;
size_t data_size()const { return 160/8; }
static constexpr size_t data_size() { return 160/8; }
static ripemd160 hash( const fc::sha512& h );
static ripemd160 hash( const fc::sha256& h );
@ -45,7 +45,7 @@ class ripemd160
ripemd160 result();
private:
struct impl;
class impl;
fc::fwd<impl,96> my;
};
@ -68,9 +68,23 @@ class ripemd160
friend bool operator > ( const ripemd160& h1, const ripemd160& h2 );
friend bool operator < ( const ripemd160& h1, const ripemd160& h2 );
uint32_t _hash[5];
boost::endian::little_uint32_buf_t _hash[5];
};
namespace raw {
template<typename T>
inline void pack( T& ds, const ripemd160& ep, uint32_t _max_depth ) {
ds << ep;
}
template<typename T>
inline void unpack( T& ds, ripemd160& ep, uint32_t _max_depth ) {
ds >> ep;
}
}
class variant;
void to_variant( const ripemd160& bi, variant& v, uint32_t max_depth );
void from_variant( const variant& v, ripemd160& bi, uint32_t max_depth );

34
include/fc/crypto/sha1.hpp Executable file → Normal file
View file

@ -1,6 +1,9 @@
#pragma once
#include <boost/endian/buffers.hpp>
#include <fc/fwd.hpp>
#include <fc/string.hpp>
#include <functional>
#include <string>
namespace fc{
@ -8,16 +11,16 @@ class sha1
{
public:
sha1();
explicit sha1( const string& hex_str );
explicit sha1( const std::string& hex_str );
string str()const;
operator string()const;
std::string str()const;
operator std::string()const;
char* data()const;
size_t data_size()const { return 20; }
static constexpr size_t data_size() { return 20; }
static sha1 hash( const char* d, uint32_t dlen );
static sha1 hash( const string& );
static sha1 hash( const std::string& );
template<typename T>
static sha1 hash( const T& t )
@ -62,9 +65,23 @@ class sha1
friend bool operator > ( const sha1& h1, const sha1& h2 );
friend bool operator < ( const sha1& h1, const sha1& h2 );
uint32_t _hash[5];
boost::endian::little_uint32_buf_t _hash[5];
};
namespace raw {
template<typename T>
inline void pack( T& ds, const sha1& ep, uint32_t _max_depth ) {
ds << ep;
}
template<typename T>
inline void unpack( T& ds, sha1& ep, uint32_t _max_depth ) {
ds >> ep;
}
}
class variant;
void to_variant( const sha1& bi, variant& v, uint32_t max_depth );
void from_variant( const variant& v, sha1& bi, uint32_t max_depth );
@ -82,3 +99,6 @@ namespace std
}
};
}
#include <fc/reflect/reflect.hpp>
FC_REFLECT_TYPENAME( fc::sha1 )

22
include/fc/crypto/sha224.hpp Executable file → Normal file
View file

@ -1,8 +1,7 @@
#pragma once
#include <unordered_map>
#include <boost/endian/buffers.hpp>
#include <fc/fwd.hpp>
#include <fc/io/raw_fwd.hpp>
#include <fc/string.hpp>
namespace fc
{
@ -17,7 +16,7 @@ class sha224
operator string()const;
char* data()const;
size_t data_size()const { return 224 / 8; }
static constexpr size_t data_size() { return 224 / 8; }
static sha224 hash( const char* d, uint32_t dlen );
static sha224 hash( const string& );
@ -65,11 +64,24 @@ class sha224
friend bool operator >= ( const sha224& h1, const sha224& h2 );
friend bool operator > ( const sha224& h1, const sha224& h2 );
friend bool operator < ( const sha224& h1, const sha224& h2 );
friend std::size_t hash_value( const sha224& v ) { return uint64_t(v._hash[1])<<32 | v._hash[2]; }
uint32_t _hash[7];
boost::endian::little_uint32_buf_t _hash[7];
};
namespace raw {
template<typename T>
inline void pack( T& ds, const sha224& ep, uint32_t _max_depth ) {
ds << ep;
}
template<typename T>
inline void unpack( T& ds, sha224& ep, uint32_t _max_depth ) {
ds >> ep;
}
}
class variant;
void to_variant( const sha224& bi, variant& v, uint32_t max_depth );
void from_variant( const variant& v, sha224& bi, uint32_t max_depth );

50
include/fc/crypto/sha256.hpp Executable file → Normal file
View file

@ -1,7 +1,7 @@
#pragma once
#include <boost/endian/buffers.hpp>
#include <fc/fwd.hpp>
#include <fc/string.hpp>
#include <fc/platform_independence.hpp>
#include <fc/io/raw_fwd.hpp>
namespace fc
@ -18,7 +18,7 @@ class sha256
operator string()const;
char* data()const;
size_t data_size()const { return 256 / 8; }
static constexpr size_t data_size() { return 256 / 8; }
static sha256 hash( const char* d, uint32_t dlen );
static sha256 hash( const string& );
@ -68,44 +68,29 @@ class sha256
friend bool operator > ( const sha256& h1, const sha256& h2 );
friend bool operator < ( const sha256& h1, const sha256& h2 );
uint32_t pop_count()const
{
return (uint32_t)(__builtin_popcountll(_hash[0]) +
__builtin_popcountll(_hash[1]) +
__builtin_popcountll(_hash[2]) +
__builtin_popcountll(_hash[3]));
}
/**
* Count leading zero bits
*/
uint16_t clz()const;
/**
* Approximate (log_2(x) + 1) * 2**24.
*
* Detailed specs:
* - Return 0 when x == 0.
* - High 8 bits of result simply counts nonzero bits.
* - Low 24 bits of result are the 24 bits of input immediately after the most significant 1 in the input.
* - If above would require reading beyond the end of the input, zeros are used instead.
*/
uint32_t approx_log_32()const;
void set_to_inverse_approx_log_32( uint32_t x );
static double inverse_approx_log_32_double( uint32_t x );
uint64_t _hash[4];
boost::endian::little_uint64_buf_t _hash[4];
};
namespace raw {
template<typename T>
inline void pack( T& ds, const sha256& ep, uint32_t _max_depth ) {
ds << ep;
}
template<typename T>
inline void unpack( T& ds, sha256& ep, uint32_t _max_depth ) {
ds >> ep;
}
}
typedef sha256 uint256;
class variant;
void to_variant( const sha256& bi, variant& v, uint32_t max_depth );
void from_variant( const variant& v, sha256& bi, uint32_t max_depth );
uint64_t hash64(const char* buf, size_t len);
} // fc
namespace std
{
@ -119,6 +104,5 @@ namespace std
};
}
#include <fc/reflect/reflect.hpp>
FC_REFLECT_TYPENAME( fc::sha256 )

29
include/fc/crypto/sha512.hpp Executable file → Normal file
View file

@ -1,6 +1,7 @@
#pragma once
#include <boost/endian/buffers.hpp>
#include <fc/io/raw_fwd.hpp>
#include <fc/fwd.hpp>
#include <fc/string.hpp>
namespace fc
{
@ -9,16 +10,16 @@ class sha512
{
public:
sha512();
explicit sha512( const string& hex_str );
explicit sha512( const std::string& hex_str );
string str()const;
operator string()const;
std::string str()const;
operator std::string()const;
char* data()const;
size_t data_size()const { return 512 / 8; }
static constexpr size_t data_size() { return 512 / 8; }
static sha512 hash( const char* d, uint32_t dlen );
static sha512 hash( const string& );
static sha512 hash( const std::string& );
template<typename T>
static sha512 hash( const T& t )
@ -63,9 +64,23 @@ class sha512
friend bool operator > ( const sha512& h1, const sha512& h2 );
friend bool operator < ( const sha512& h1, const sha512& h2 );
uint64_t _hash[8];
boost::endian::little_uint64_buf_t _hash[8];
};
namespace raw {
template<typename T>
inline void pack( T& ds, const sha512& ep, uint32_t _max_depth ) {
ds << ep;
}
template<typename T>
inline void unpack( T& ds, sha512& ep, uint32_t _max_depth ) {
ds >> ep;
}
}
typedef fc::sha512 uint512;
class variant;

144
include/fc/exception/exception.hpp Executable file → Normal file
View file

@ -35,7 +35,8 @@ namespace fc
aes_error_code = 18,
overflow_code = 19,
underflow_code = 20,
divide_by_zero_code = 21
divide_by_zero_code = 21,
method_not_found_exception_code = 22
};
/**
@ -105,7 +106,7 @@ namespace fc
*
* @note does not return.
*/
virtual NO_RETURN void dynamic_rethrow_exception()const;
[[noreturn]] virtual void dynamic_rethrow_exception()const;
/**
* This is equivalent to:
@ -154,7 +155,7 @@ namespace fc
std::exception_ptr get_inner_exception()const;
virtual NO_RETURN void dynamic_rethrow_exception()const;
[[noreturn]] virtual void dynamic_rethrow_exception()const;
virtual std::shared_ptr<exception> dynamic_copy_exception()const;
private:
std::exception_ptr _inner;
@ -165,10 +166,10 @@ namespace fc
{
#if defined(_MSC_VER) && (_MSC_VER < 1700)
return std::make_shared<unhandled_exception>( log_message(),
std::copy_exception(fc::forward<T>(e)) );
std::copy_exception(std::forward<T>(e)) );
#else
return std::make_shared<unhandled_exception>( log_message(),
std::make_exception_ptr(fc::forward<T>(e)) );
std::make_exception_ptr(std::forward<T>(e)) );
#endif
}
@ -178,13 +179,13 @@ namespace fc
public:
struct base_exception_builder
{
virtual NO_RETURN void rethrow( const exception& e )const = 0;
[[noreturn]] virtual void rethrow( const exception& e )const = 0;
};
template<typename T>
struct exception_builder : public base_exception_builder
{
virtual NO_RETURN void rethrow( const exception& e )const override
[[noreturn]] virtual void rethrow( const exception& e )const override
{
throw T( e );
}
@ -200,7 +201,7 @@ namespace fc
_registered_exceptions[T::code_value] = &builder;
}
void NO_RETURN rethrow( const exception& e )const;
[[noreturn]] void rethrow( const exception& e )const;
static exception_factory& instance()
{
@ -222,81 +223,98 @@ namespace fc
}(); \
#define FC_DECLARE_DERIVED_EXCEPTION( TYPE, BASE, CODE, WHAT ) \
#define FC_DECLARE_DERIVED_EXCEPTION( TYPE, BASE, CODE ) \
class TYPE : public BASE \
{ \
public: \
enum code_enum { \
code_value = CODE, \
}; \
explicit TYPE( int64_t code, const std::string& name_value, const std::string& what_value ) \
:BASE( code, name_value, what_value ){} \
explicit TYPE( fc::log_message&& m, int64_t code, const std::string& name_value, const std::string& what_value ) \
:BASE( std::move(m), code, name_value, what_value ){} \
explicit TYPE( fc::log_messages&& m, int64_t code, const std::string& name_value, const std::string& what_value )\
:BASE( std::move(m), code, name_value, what_value ){}\
explicit TYPE( const fc::log_messages& m, int64_t code, const std::string& name_value, const std::string& what_value )\
:BASE( m, code, name_value, what_value ){}\
TYPE( const std::string& what_value, const fc::log_messages& m ) \
:BASE( m, CODE, BOOST_PP_STRINGIZE(TYPE), what_value ){} \
TYPE( fc::log_message&& m ) \
:BASE( fc::move(m), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ){}\
TYPE( fc::log_messages msgs ) \
:BASE( fc::move( msgs ), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \
TYPE( const TYPE& c ) \
:BASE(c){} \
TYPE( const BASE& c ) \
:BASE(c){} \
TYPE():BASE(CODE, BOOST_PP_STRINGIZE(TYPE), WHAT){}\
explicit TYPE( int64_t code, const std::string& name_value, const std::string& what_value ); \
explicit TYPE( fc::log_message&& m, int64_t code, const std::string& name_value, const std::string& what_value ); \
explicit TYPE( fc::log_messages&& m, int64_t code, const std::string& name_value, const std::string& what_value );\
explicit TYPE( const fc::log_messages& m, int64_t code, const std::string& name_value, const std::string& what_value );\
explicit TYPE( const std::string& what_value, const fc::log_messages& m ); \
explicit TYPE( fc::log_message&& m ); \
explicit TYPE( fc::log_messages msgs ); \
TYPE( TYPE&& c ) = default; \
TYPE( const TYPE& c ); \
TYPE( const BASE& c ); \
explicit TYPE();\
\
virtual std::shared_ptr<fc::exception> dynamic_copy_exception()const\
{ return std::make_shared<TYPE>( *this ); } \
virtual NO_RETURN void dynamic_rethrow_exception()const \
{ if( code() == CODE ) throw *this;\
else fc::exception::dynamic_rethrow_exception(); \
} \
virtual std::shared_ptr<fc::exception> dynamic_copy_exception()const;\
[[noreturn]] virtual void dynamic_rethrow_exception()const; \
};
#define FC_DECLARE_EXCEPTION( TYPE, CODE, WHAT ) \
FC_DECLARE_DERIVED_EXCEPTION( TYPE, fc::exception, CODE, WHAT )
#define FC_IMPLEMENT_DERIVED_EXCEPTION( TYPE, BASE, CODE, WHAT ) \
TYPE::TYPE( int64_t code, const std::string& name_value, const std::string& what_value ) \
: BASE( code, name_value, what_value ) {} \
TYPE::TYPE( fc::log_message&& m, int64_t code, const std::string& name_value, const std::string& what_value ) \
: BASE( std::move(m), code, name_value, what_value ) {} \
TYPE::TYPE( fc::log_messages&& m, int64_t code, const std::string& name_value, const std::string& what_value ) \
: BASE( std::move(m), code, name_value, what_value ) {} \
TYPE::TYPE( const fc::log_messages& m, int64_t code, const std::string& name_value, const std::string& what_value ) \
: BASE( m, code, name_value, what_value ) {} \
TYPE::TYPE( const std::string& what_value, const fc::log_messages& m ) \
: BASE( m, CODE, BOOST_PP_STRINGIZE(TYPE), what_value ) {} \
TYPE::TYPE( fc::log_message&& m ) \
: BASE( std::move(m), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \
TYPE::TYPE( fc::log_messages msgs ) \
: BASE( std::move( msgs ), CODE, BOOST_PP_STRINGIZE(TYPE), WHAT ) {} \
TYPE::TYPE( const TYPE& c ) : BASE(c) {} \
TYPE::TYPE( const BASE& c ) : BASE(c) {} \
TYPE::TYPE() : BASE(CODE, BOOST_PP_STRINGIZE(TYPE), WHAT) {} \
\
std::shared_ptr<fc::exception> TYPE::dynamic_copy_exception()const \
{ \
return std::make_shared<TYPE>( *this ); \
} \
[[noreturn]] void TYPE::dynamic_rethrow_exception()const \
{ \
if( code() == CODE ) throw *this;\
else fc::exception::dynamic_rethrow_exception(); \
}
FC_DECLARE_EXCEPTION( timeout_exception, timeout_exception_code, "Timeout" );
FC_DECLARE_EXCEPTION( file_not_found_exception, file_not_found_exception_code, "File Not Found" );
#define FC_DECLARE_EXCEPTION( TYPE, CODE ) \
FC_DECLARE_DERIVED_EXCEPTION( TYPE, fc::exception, CODE )
#define FC_IMPLEMENT_EXCEPTION( TYPE, CODE, WHAT ) \
FC_IMPLEMENT_DERIVED_EXCEPTION( TYPE, fc::exception, CODE, WHAT )
FC_DECLARE_EXCEPTION( timeout_exception, timeout_exception_code );
FC_DECLARE_EXCEPTION( file_not_found_exception, file_not_found_exception_code );
/**
* @brief report's parse errors
* @brief reports parse errors
*/
FC_DECLARE_EXCEPTION( parse_error_exception, parse_error_exception_code, "Parse Error" );
FC_DECLARE_EXCEPTION( invalid_arg_exception, invalid_arg_exception_code, "Invalid Argument" );
FC_DECLARE_EXCEPTION( parse_error_exception, parse_error_exception_code );
FC_DECLARE_EXCEPTION( invalid_arg_exception, invalid_arg_exception_code );
/**
* @brief reports when a key, guid, or other item is not found.
*/
FC_DECLARE_EXCEPTION( key_not_found_exception, key_not_found_exception_code, "Key Not Found" );
FC_DECLARE_EXCEPTION( bad_cast_exception, bad_cast_exception_code, "Bad Cast" );
FC_DECLARE_EXCEPTION( out_of_range_exception, out_of_range_exception_code, "Out of Range" );
FC_DECLARE_EXCEPTION( key_not_found_exception, key_not_found_exception_code );
FC_DECLARE_EXCEPTION( bad_cast_exception, bad_cast_exception_code );
FC_DECLARE_EXCEPTION( out_of_range_exception, out_of_range_exception_code );
FC_DECLARE_EXCEPTION( method_not_found_exception, method_not_found_exception_code );
/** @brief if an operation is unsupported or not valid this may be thrown */
FC_DECLARE_EXCEPTION( invalid_operation_exception,
invalid_operation_exception_code,
"Invalid Operation" );
FC_DECLARE_EXCEPTION( invalid_operation_exception, invalid_operation_exception_code );
/** @brief if an host name can not be resolved this may be thrown */
FC_DECLARE_EXCEPTION( unknown_host_exception,
unknown_host_exception_code,
"Unknown Host" );
FC_DECLARE_EXCEPTION( unknown_host_exception, unknown_host_exception_code );
/**
* @brief used to report a canceled Operation
*/
FC_DECLARE_EXCEPTION( canceled_exception, canceled_exception_code, "Canceled" );
FC_DECLARE_EXCEPTION( canceled_exception, canceled_exception_code );
/**
* @brief used inplace of assert() to report violations of pre conditions.
*/
FC_DECLARE_EXCEPTION( assert_exception, assert_exception_code, "Assert Exception" );
FC_DECLARE_EXCEPTION( eof_exception, eof_exception_code, "End Of File" );
FC_DECLARE_EXCEPTION( null_optional, null_optional_code, "null optional" );
FC_DECLARE_EXCEPTION( aes_exception, aes_error_code, "AES error" );
FC_DECLARE_EXCEPTION( overflow_exception, overflow_code, "Integer Overflow" );
FC_DECLARE_EXCEPTION( underflow_exception, underflow_code, "Integer Underflow" );
FC_DECLARE_EXCEPTION( divide_by_zero_exception, divide_by_zero_code, "Integer Divide By Zero" );
FC_DECLARE_EXCEPTION( assert_exception, assert_exception_code );
FC_DECLARE_EXCEPTION( eof_exception, eof_exception_code );
FC_DECLARE_EXCEPTION( null_optional, null_optional_code );
FC_DECLARE_EXCEPTION( aes_exception, aes_error_code );
FC_DECLARE_EXCEPTION( overflow_exception, overflow_code );
FC_DECLARE_EXCEPTION( underflow_exception, underflow_code );
FC_DECLARE_EXCEPTION( divide_by_zero_exception, divide_by_zero_code );
std::string except_str();
@ -446,11 +464,11 @@ namespace fc
catch( fc::exception& er ) { \
FC_RETHROW_EXCEPTION( er, LOG_LEVEL, FORMAT, __VA_ARGS__ ); \
} catch( const std::exception& e ) { \
fc::exception fce( \
BOOST_PP_EXPAND(FC_LOG_MESSAGE( LOG_LEVEL, "${what}: " FORMAT,__VA_ARGS__("what",e.what()))), \
throw fc::exception( \
FC_LOG_MESSAGE( LOG_LEVEL, "${what}: " FORMAT,__VA_ARGS__("what",e.what())), \
fc::std_exception_code,\
typeid(e).name(), \
e.what() ) ; throw fce;\
e.what() ) ;\
} catch( ... ) { \
throw fc::unhandled_exception( \
FC_LOG_MESSAGE( LOG_LEVEL, FORMAT,__VA_ARGS__), \
@ -461,11 +479,11 @@ namespace fc
catch( fc::exception& er ) { \
FC_RETHROW_EXCEPTION( er, warn, "", FC_FORMAT_ARG_PARAMS(__VA_ARGS__) ); \
} catch( const std::exception& e ) { \
fc::exception fce( \
throw fc::exception( \
FC_LOG_MESSAGE( warn, "${what}: ",FC_FORMAT_ARG_PARAMS(__VA_ARGS__)("what",e.what())), \
fc::std_exception_code,\
typeid(e).name(), \
e.what() ) ; throw fce;\
e.what() ) ;\
} catch( ... ) { \
throw fc::unhandled_exception( \
FC_LOG_MESSAGE( warn, "",FC_FORMAT_ARG_PARAMS(__VA_ARGS__)), \

33
include/fc/filesystem.hpp Executable file → Normal file
View file

@ -2,7 +2,6 @@
#include <utility>
#include <memory>
#include <fc/string.hpp>
#include <fc/reflect/typename.hpp>
#include <fc/optional.hpp>
#include <fc/fwd.hpp>
@ -228,37 +227,5 @@ namespace fc {
temp_directory(const fc::path& tempFolder = fc::temp_directory_path());
};
#if !defined(__APPLE__)
// this code is known to work on linux and windows. It may work correctly on mac,
// or it may need slight tweaks or extra includes. It's disabled now to avoid giving
// a false sense of security.
# define FC_HAS_SIMPLE_FILE_LOCK
#endif
#ifdef FC_HAS_SIMPLE_FILE_LOCK
/** simple class which only allows one process to open any given file.
* approximate usage:
* int main() {
* fc::simple_file_lock instance_lock("~/.my_app/.lock");
* if (!instance_lock.try_lock()) {
* elog("my_app is already running");
* return 1;
* }
* // do stuff here, file will be unlocked when instance_lock goes out of scope
* }
*/
class simple_lock_file
{
public:
simple_lock_file(const path& lock_file_path);
~simple_lock_file();
bool try_lock();
void unlock();
private:
class impl;
std::unique_ptr<impl> my;
};
#endif // FC_HAS_SIMPLE_FILE_LOCK
}

View file

@ -1,143 +0,0 @@
#pragma once
#include <fc/io/raw_fwd.hpp>
namespace fc {
/**
* This class is designed to offer in-place memory allocation of a string up to Length equal to
* sizeof(Storage).
*
* The string will serialize the same way as std::string for variant and raw formats
* The string will sort according to the comparison operators defined for Storage, this enables effecient
* sorting.
*/
template<typename Storage = std::pair<uint64_t,uint64_t> >
class fixed_string {
public:
fixed_string(){}
fixed_string( const fixed_string& c ):data(c.data){}
fixed_string( const std::string& str ) {
if( str.size() <= sizeof(data) )
memcpy( (char*)&data, str.c_str(), str.size() );
else {
memcpy( (char*)&data, str.c_str(), sizeof(data) );
}
}
fixed_string( const char* str ) {
auto l = strlen(str);
if( l <= sizeof(data) )
memcpy( (char*)&data, str, l );
else {
memcpy( (char*)&data, str, sizeof(data) );
}
}
operator std::string()const {
const char* self = (const char*)&data;
return std::string( self, self + size() );
}
uint32_t size()const {
if( *(((const char*)&data)+sizeof(data) - 1) )
return sizeof(data);
return strnlen( (const char*)&data, sizeof(data) );
}
uint32_t length()const { return size(); }
fixed_string& operator=( const fixed_string& str ) {
data = str.data;
return *this;
}
fixed_string& operator=( const char* str ) {
return *this = fixed_string(str);
}
fixed_string& operator=( const std::string& str ) {
if( str.size() <= sizeof(data) ) {
data = Storage();
memcpy( (char*)&data, str.c_str(), str.size() );
}
else {
memcpy( (char*)&data, str.c_str(), sizeof(data) );
}
return *this;
}
friend std::string operator + ( const fixed_string& a, const std::string& b ) {
return std::string(a) + b;
}
friend std::string operator + ( const std::string& a, const fixed_string& b ) {
return a + std::string(b);
}
friend bool operator < ( const fixed_string& a, const fixed_string& b ) {
return a.data < b.data;
}
friend bool operator <= ( const fixed_string& a, const fixed_string& b ) {
return a.data <= b.data;
}
friend bool operator > ( const fixed_string& a, const fixed_string& b ) {
return a.data > b.data;
}
friend bool operator >= ( const fixed_string& a, const fixed_string& b ) {
return a.data >= b.data;
}
friend bool operator == ( const fixed_string& a, const fixed_string& b ) {
return a.data == b.data;
}
friend bool operator != ( const fixed_string& a, const fixed_string& b ) {
return a.data != b.data;
}
//private:
Storage data;
};
namespace raw
{
template<typename Stream, typename Storage>
inline void pack( Stream& s, const fc::fixed_string<Storage>& u, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
FC_ASSERT( _max_depth > 0 );
unsigned_int size = u.size();
pack( s, size, _max_depth - 1 );
s.write( (const char*)&u.data, size );
}
template<typename Stream, typename Storage>
inline void unpack( Stream& s, fc::fixed_string<Storage>& u, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
FC_ASSERT( _max_depth > 0 );
unsigned_int size;
fc::raw::unpack( s, size, _max_depth - 1 );
if( size.value > 0 ) {
if( size.value > sizeof(Storage) ) {
s.read( (char*)&u.data, sizeof(Storage) );
char buf[1024];
size_t left = size.value - sizeof(Storage);
while( left >= 1024 )
{
s.read( buf, 1024 );
left -= 1024;
}
s.read( buf, left );
} else {
s.read( (char*)&u.data, size.value );
}
}
}
}
}
#include <fc/variant.hpp>
namespace fc {
template<typename Storage>
void to_variant( const fixed_string<Storage>& s, variant& v, uint32_t max_depth = 1 ) {
v = std::string(s);
}
template<typename Storage>
void from_variant( const variant& v, fixed_string<Storage>& s, uint32_t max_depth = 1 ) {
s = v.as_string();
}
}

3
include/fc/fwd.hpp Executable file → Normal file
View file

@ -1,5 +1,4 @@
#pragma once
#include <fc/aligned.hpp>
namespace fc {
@ -37,7 +36,7 @@ class fwd {
~fwd();
private:
aligned<S,Align> _store;
alignas(Align) char _store[S];
};

30
include/fc/fwd_impl.hpp Executable file → Normal file
View file

@ -1,33 +1,35 @@
#pragma once
#include <fc/utility.hpp>
#include <fc/fwd.hpp>
#include <cstdint>
#include <new>
#include <type_traits>
#include <utility>
namespace fc {
namespace detail {
template<typename A, typename U>
struct add {
typedef decltype( *((A*)0) + *((typename fc::remove_reference<U>::type*)0) ) type;
typedef decltype( *((A*)0) + *((typename std::remove_reference<U>::type*)0) ) type;
};
template<typename A, typename U>
struct add_eq {
typedef decltype( *((A*)0) += *((typename fc::remove_reference<U>::type*)0) ) type;
typedef decltype( *((A*)0) += *((typename std::remove_reference<U>::type*)0) ) type;
};
template<typename A, typename U>
struct sub {
typedef decltype( *((A*)0) - *((typename fc::remove_reference<U>::type*)0) ) type;
typedef decltype( *((A*)0) - *((typename std::remove_reference<U>::type*)0) ) type;
};
template<typename A, typename U>
struct sub_eq {
typedef decltype( *((A*)0) -= *((typename fc::remove_reference<U>::type*)0) ) type;
typedef decltype( *((A*)0) -= *((typename std::remove_reference<U>::type*)0) ) type;
};
template<typename A, typename U>
struct insert_op {
typedef decltype( *((A*)0) << *((typename fc::remove_reference<U>::type*)0) ) type;
typedef decltype( *((A*)0) << *((typename std::remove_reference<U>::type*)0) ) type;
};
template<typename A, typename U>
struct extract_op {
@ -39,10 +41,10 @@ namespace fc {
template<typename T, unsigned int S, typename U, typename A>
auto operator + ( const fwd<T,S,A>& x, U&& u ) -> typename detail::add<T,U>::type { return *x+fc::forward<U>(u); }
auto operator + ( const fwd<T,S,A>& x, U&& u ) -> typename detail::add<T,U>::type { return *x+std::forward<U>(u); }
template<typename T, unsigned int S, typename U, typename A>
auto operator - ( const fwd<T,S,A>& x, U&& u ) -> typename detail::sub<T,U>::type { return *x-fc::forward<U>(u); }
auto operator - ( const fwd<T,S,A>& x, U&& u ) -> typename detail::sub<T,U>::type { return *x-std::forward<U>(u); }
template<typename T, unsigned int S, typename U, typename A>
auto operator << ( U& u, const fwd<T,S,A>& f ) -> typename detail::insert_op<U,T>::type { return u << *f; }
@ -61,20 +63,20 @@ namespace fc {
template<typename U>
fwd<T,S,A>::fwd( U&& u ) {
check_size<sizeof(T),sizeof(_store)>();
new (this) T( fc::forward<U>(u) );
new (this) T( std::forward<U>(u) );
}
template<typename T,unsigned int S,typename A>
template<typename U,typename V>
fwd<T,S,A>::fwd( U&& u, V&& v ) {
check_size<sizeof(T),sizeof(_store)>();
new (this) T( fc::forward<U>(u), fc::forward<V>(v) );
new (this) T( std::forward<U>(u), std::forward<V>(v) );
}
template<typename T,unsigned int S,typename A>
template<typename U,typename V,typename X,typename Y>
fwd<T,S,A>::fwd( U&& u, V&& v, X&& x, Y&& y ) {
check_size<sizeof(T),sizeof(_store)>();
new (this) T( fc::forward<U>(u), fc::forward<V>(v), fc::forward<X>(x), fc::forward<Y>(y) );
new (this) T( std::forward<U>(u), std::forward<V>(v), std::forward<X>(x), std::forward<Y>(y) );
}
@ -91,7 +93,7 @@ namespace fc {
template<typename T,unsigned int S,typename A>
fwd<T,S,A>::fwd( fwd<T,S,A>&& f ){
check_size<sizeof(T),sizeof(_store)>();
new (this) T( fc::move(*f) );
new (this) T( std::move(*f) );
}
@ -119,12 +121,12 @@ namespace fc {
template<typename T,unsigned int S, typename A>
template<typename U>
T& fwd<T,S,A>::operator = ( U&& u ) {
return **this = fc::forward<U>(u);
return **this = std::forward<U>(u);
}
template<typename T,unsigned int S, typename A>
T& fwd<T,S,A>::operator = ( fwd<T,S,A>&& u ) {
return **this = fc::move(*u);
return **this = std::move(*u);
}
template<typename T,unsigned int S, typename A>
T& fwd<T,S,A>::operator = ( const fwd<T,S,A>& u ) {

0
include/fc/git_revision.hpp Executable file → Normal file
View file

View file

@ -1,135 +0,0 @@
#pragma once
#include <fc/variant.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/containers/map.hpp>
#include <boost/interprocess/containers/flat_map.hpp>
#include <boost/interprocess/containers/set.hpp>
#include <boost/interprocess/containers/deque.hpp>
#include <fc/crypto/hex.hpp>
#include <fc/exception/exception.hpp>
#include <fc/io/raw_fwd.hpp>
namespace fc {
namespace bip = boost::interprocess;
template<typename... T >
void to_variant( const bip::deque< T... >& t, fc::variant& v, uint32_t max_depth ) {
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
--max_depth;
std::vector<variant> vars(t.size());
for( size_t i = 0; i < t.size(); ++i ) {
to_variant( t[i], vars[i], max_depth );
}
v = std::move(vars);
}
template<typename T, typename... A>
void from_variant( const fc::variant& v, bip::deque< T, A... >& d, uint32_t max_depth ) {
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
--max_depth;
const variants& vars = v.get_array();
d.clear();
d.resize( vars.size() );
for( uint32_t i = 0; i < vars.size(); ++i ) {
from_variant( vars[i], d[i], max_depth );
}
}
template<typename K, typename V, typename... T >
void to_variant( const bip::map< K, V, T... >& var, fc::variant& vo, uint32_t max_depth ) {
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
--max_depth;
std::vector< variant > vars(var.size());
size_t i = 0;
for( auto itr = var.begin(); itr != var.end(); ++itr, ++i )
vars[i] = fc::variant( *itr, max_depth );
vo = vars;
}
template<typename... T >
void to_variant( const bip::vector< T... >& t, fc::variant& v, uint32_t max_depth ) {
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
--max_depth;
std::vector<variant> vars(t.size());
for( size_t i = 0; i < t.size(); ++i ) {
to_variant( t[i], vars[i], max_depth );
}
v = std::move(vars);
}
template<typename T, typename... A>
void from_variant( const fc::variant& v, bip::vector< T, A... >& d, uint32_t max_depth ) {
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
--max_depth;
const variants& vars = v.get_array();
d.clear();
d.resize( vars.size() );
for( uint32_t i = 0; i < vars.size(); ++i ) {
from_variant( vars[i], d[i], max_depth );
}
}
template<typename... T >
void to_variant( const bip::set< T... >& t, fc::variant& v, uint32_t max_depth ) {
FC_ASSERT( max_depth > 0, "Recursion depth exceeded!" );
--max_depth;
std::vector<variant> vars;
vars.reserve(t.size());
for( const auto& item : t ) {
vars.emplace_back( variant( item, max_depth ) );
}
v = std::move(vars);
}
template<typename... A>
void to_variant( const bip::vector<char, A...>& t, fc::variant& v, uint32_t max_depth = 1 )
{
if( t.size() )
v = variant(fc::to_hex(t.data(), t.size()));
else
v = "";
}
template<typename... A>
void from_variant( const fc::variant& v, bip::vector<char, A...>& d, uint32_t max_depth = 1 )
{
auto str = v.as_string();
d.resize( str.size() / 2 );
if( d.size() )
{
size_t r = fc::from_hex( str, d.data(), d.size() );
FC_ASSERT( r == d.size() );
}
}
namespace raw {
namespace bip = boost::interprocess;
template<typename Stream, typename T, typename... A>
inline void pack( Stream& s, const bip::vector<T,A...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
fc::raw::pack( s, *itr, _max_depth );
++itr;
}
}
template<typename Stream, typename T, typename... A>
inline void unpack( Stream& s, bip::vector<T,A...>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
unsigned_int size;
unpack( s, size, _max_depth );
value.clear(); value.resize(size);
for( auto& item : value )
fc::raw::unpack( s, item, _max_depth );
}
}
}

5
include/fc/interprocess/file_mapping.hpp Executable file → Normal file
View file

@ -1,6 +1,7 @@
#pragma once
#include <fc/fwd.hpp>
#include <fc/utility.hpp>
#include <cstdint>
#include <cstdlib>
namespace boost {
namespace interprocess {
@ -24,7 +25,7 @@ namespace fc {
#ifdef _WIN64
fc::fwd<boost::interprocess::file_mapping,0x38> my;
#else
fc::fwd<boost::interprocess::file_mapping,0x24> my;
fc::fwd<boost::interprocess::file_mapping,0x28> my;
#endif
};

View file

@ -1,44 +0,0 @@
#pragma once
#include <fc/time.hpp>
#include <fc/thread/spin_yield_lock.hpp>
#include <memory>
namespace fc {
class microseconds;
class time_point;
class path;
struct context;
namespace detail { class file_mutex_impl; }
/**
* The purpose of this class is to support synchronization of
* processes, threads, and coop-threads.
*
* Before grabbing the lock for a thread or coop, a file_mutex will first
* grab a process-level lock. After grabbing the process level lock, it will
* synchronize in the same way as a local process lock.
*/
class file_mutex {
public:
file_mutex( const fc::path& filename );
~file_mutex();
bool try_lock();
bool try_lock_for( const microseconds& rel_time );
bool try_lock_until( const time_point& abs_time );
void lock();
void unlock();
void lock_shared();
void unlock_shared();
bool try_lock_shared();
int readers()const;
private:
std::unique_ptr<detail::file_mutex_impl> my;
};
} // namespace fc

View file

@ -1,67 +0,0 @@
#pragma once
#include <fc/thread/future.hpp>
#include <fc/io/buffered_iostream.hpp>
#include <vector>
#include <fc/string.hpp>
#include <fc/filesystem.hpp>
namespace fc
{
/**
* @brief abstract interface for interacting with external processes
*
* At the very least we have ssh::process and direct child processes, and
* there may be other processes that need to implement this protocol.
*/
class iprocess
{
public:
enum exec_opts {
open_none = 0,
open_stdin = 0x01,
open_stdout = 0x02,
open_stderr = 0x04,
open_all = open_stdin|open_stdout|open_stderr,
suppress_console = 0x08
};
virtual ~iprocess(){}
/**
*
* @return *this
*/
virtual iprocess& exec( const path& exe, std::vector<std::string> args,
const path& work_dir = path(), int opts = open_all ) = 0;
/**
* @return blocks until the process exits
*/
virtual int result(const microseconds& timeout = microseconds::maximum()) = 0;
/**
* Forcefully kills the process.
*/
virtual void kill() = 0;
/**
* @brief returns a stream that writes to the process' stdin
*/
virtual buffered_ostream_ptr in_stream() = 0;
/**
* @brief returns a stream that reads from the process' stdout
*/
virtual buffered_istream_ptr out_stream() = 0;
/**
* @brief returns a stream that reads from the process' stderr
*/
virtual buffered_istream_ptr err_stream() = 0;
};
typedef std::shared_ptr<iprocess> iprocess_ptr;
} // namespace fc

View file

@ -1,59 +0,0 @@
#pragma once
#include <fc/interprocess/file_mapping.hpp>
#include <memory>
namespace fc
{
class path;
namespace detail
{
/**
* Base class used to hide common implementation details.
*/
class mmap_struct_base
{
public:
size_t size()const;
void flush();
protected:
void open( const fc::path& file, size_t s, bool create );
std::unique_ptr<fc::file_mapping> _file_mapping;
std::unique_ptr<fc::mapped_region> _mapped_region;
};
};
/**
* @class mmap_struct
* @brief A struct that has been mapped from a file.
*
* @note T must be POD
*/
template<typename T>
class mmap_struct : public detail::mmap_struct_base
{
public:
mmap_struct():_mapped_struct(nullptr){}
/**
* Create the file if it does not exist or is of the wrong size if create is true, then maps
* the file to memory.
*
* @throw an exception if the file does not exist or is the wrong size and create is false
*/
void open( const fc::path& file, bool create = false )
{
detail::mmap_struct_base::open( file, sizeof(T), create );
_mapped_struct = (T*)_mapped_region->get_address();
}
T* operator->() { return _mapped_struct; }
const T* operator->()const { return _mapped_struct; }
T& operator*() { return *_mapped_struct; }
const T& operator*()const { return *_mapped_struct; }
private:
T* _mapped_struct;
};
}

View file

@ -1,37 +0,0 @@
#pragma once
#include <fc/interprocess/iprocess.hpp>
namespace fc {
fc::path find_executable_in_path( const fc::string name );
/**
* @brief start and manage an local process
* @note this class implements reference semantics.
*/
class process : public iprocess
{
public:
process();
~process();
virtual iprocess& exec( const fc::path& exe,
std::vector<std::string> args,
const fc::path& work_dir = fc::path(),
int opts = open_all );
virtual int result(const microseconds& timeout = microseconds::maximum());
virtual void kill();
virtual fc::buffered_ostream_ptr in_stream();
virtual fc::buffered_istream_ptr out_stream();
virtual fc::buffered_istream_ptr err_stream();
class impl;
private:
std::unique_ptr<impl> my;
};
typedef std::shared_ptr<process> process_ptr;
} // namespace fc

7
include/fc/interprocess/signals.hpp Executable file → Normal file
View file

@ -1,8 +1,11 @@
#pragma once
#include <functional>
#include <boost/asio/signal_set.hpp>
namespace fc
{
/// handler will be called from ASIO thread
void set_signal_handler( std::function<void(int)> handler, int signal_num );
/// Set a handler to process an IPC (inter process communication) signal.
/// Handler will be called from ASIO thread.
/// @return shared pointer to the signal_set that holds the handler
std::shared_ptr<boost::asio::signal_set> set_signal_handler( std::function<void(int)> handler, int signal_num );
}

0
include/fc/io/buffered_iostream.hpp Executable file → Normal file
View file

View file

@ -1,8 +0,0 @@
#pragma once
namespace fc
{
/** enables / disables echoing of console input, useful for
* entering passwords on the console.
*/
void set_console_echo( bool enable_echo );
} // namespace fc

92
include/fc/io/datastream.hpp Executable file → Normal file
View file

@ -1,5 +1,4 @@
#pragma once
#include <fc/utility.hpp>
#include <string.h>
#include <stdint.h>
@ -7,7 +6,7 @@ namespace fc {
namespace detail
{
NO_RETURN void throw_datastream_range_error( const char* file, size_t len, int64_t over );
[[noreturn]] void throw_datastream_range_error( const char* file, size_t len, int64_t over );
}
/**
@ -89,94 +88,5 @@ class datastream<size_t> {
size_t _size;
};
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const int32_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, int32_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint32_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, uint32_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const int64_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, int64_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint64_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, uint64_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const int16_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, int16_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint16_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, uint16_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const int8_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, int8_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint8_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, uint8_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
} // namespace fc

View file

@ -1,178 +0,0 @@
#pragma once
#include <fc/utility.hpp>
#include <string.h>
#include <stdint.h>
namespace fc {
/**
* The purpose of this datastream is to provide a fast, effecient, means
* of calculating the amount of data "about to be written" and then
* writing it. This means having two modes of operation, "test run" where
* you call the entire pack sequence calculating the size, and then
* actually packing it after doing a single allocation.
*/
template<typename T>
class datastream {
public:
datastream( T start, size_t s )
:_start(start),_pos(start),_end(start+s){};
inline void skip( size_t s ){ _pos += s; }
inline bool read( char* d, size_t s ) {
if( size_t(_end - _pos) >= (size_t)s ) {
memcpy( d, _pos, s );
_pos += s;
return true;
}
detail::throw_datastream_range_error( _end-start, int64_t(-((_end-_pos) - 1)))
return false;
}
inline bool write( const char* d, size_t s ) {
if( _end - _pos >= (int32_t)s ) {
memcpy( _pos, d, s );
_pos += s;
return true;
}
detail::throw_datastream_range_error( _end-start, int64_t(-((_end-_pos) - 1)))
return false;
}
inline bool put(char c) {
if( _pos < _end ) {
*_pos = c;
++_pos;
return true;
}
detail::throw_datastream_range_error( _end-start, int64_t(-((_end-_pos) - 1)))
}
inline bool get( unsigned char& c ) { return get( *(char*)&c ); }
inline bool get( char& c ) {
if( _pos < _end ) {
c = *_pos;
++_pos;
return true;
}
detail::throw_datastream_range_error( _end-start, int64_t(-((_end-_pos) - 1)))
}
T pos()const { return _pos; }
inline bool valid()const { return _pos <= _end && _pos >= _start; }
inline bool seekp(size_t p) { _pos = _start + p; return _pos <= _end; }
inline size_t tellp()const { return _pos - _start; }
inline size_t remaining()const { return _end - _pos; }
private:
T _start;
T _pos;
T _end;
};
template<>
class datastream<size_t> {
public:
datastream( size_t init_size = 0):_size(init_size){};
inline bool skip( size_t s ) { _size += s; return true; }
inline bool write( const char* d,size_t s ) { _size += s; return true; }
inline bool put(char c) { ++_size; return true; }
inline bool valid()const { return true; }
inline bool seekp(size_t p) { _size = p; return true; }
inline size_t tellp()const { return _size; }
inline size_t remaining()const { return 0; }
private:
size_t _size;
};
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const int32_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, int32_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint32_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, uint32_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const int64_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, int64_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint64_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, uint64_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const int16_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, int16_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint16_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, uint16_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const int8_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, int8_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
template<typename ST>
inline datastream<ST>& operator<<(datastream<ST>& ds, const uint8_t& d) {
ds.write( (const char*)&d, sizeof(d) );
return ds;
}
template<typename ST, typename DATA>
inline datastream<ST>& operator>>(datastream<ST>& ds, uint8_t& d) {
ds.read((char*)&d, sizeof(d) );
return ds;
}
} // namespace fc

0
include/fc/io/enum_type.hpp Executable file → Normal file
View file

7
include/fc/io/fstream.hpp Executable file → Normal file
View file

@ -1,14 +1,13 @@
#pragma once
#include <fc/shared_ptr.hpp>
#include <fc/filesystem.hpp>
#include <fc/io/iostream.hpp>
#include <fstream>
#include <memory>
namespace fc {
class path;
class ofstream : virtual public ostream {
public:
enum mode { out, binary };
ofstream();
ofstream( const fc::path& file, std::ios_base::openmode m = std::ios_base::out | std::ios_base::binary );
~ofstream();
@ -22,7 +21,7 @@ namespace fc {
private:
class impl;
fc::shared_ptr<impl> my;
std::shared_ptr<impl> my;
};
class ifstream : virtual public istream {
@ -45,7 +44,7 @@ namespace fc {
bool eof()const;
private:
class impl;
fc::shared_ptr<impl> my;
std::shared_ptr<impl> my;
};
/**

View file

@ -1,81 +0,0 @@
#pragma once
#include <fc/io/iostream.hpp>
#include <fc/exception/exception.hpp>
namespace fc
{
/**
* Records the size, but discards the data.
*/
class size_stream : public virtual fc::ostream
{
public:
size_stream( size_t s = 0):_size(s){}
size_t size()const { return _size; }
size_t seek( size_t pos ) { return _size = pos; }
virtual size_t writesome( const char* /*ignored buf*/, size_t len )
{
_size += len;
return len;
}
virtual void close(){}
virtual void flush(){}
private:
size_t _size;
};
class iobuffer : public virtual fc::iostream
{
public:
iobuffer( size_t s )
:_data(s){}
size_t size()const { return _data.size(); }
size_t pos()const { return _pos; }
size_t seek( size_t pos )
{
return _pos = std::min<size_t>(_data.size(),pos);
}
virtual size_t readsome( char* buf, size_t len )
{
auto avail = std::min<size_t>( _data.size()-_pos, len );
if( avail == 0 ) throw fc::eof_exception();
memcpy( buf, _data.data()+_pos, avail );
_pos += avail;
return avail;
}
/**
* This method may block until at least 1 character is
* available.
*/
char peek()const
{
if( _pos == _data.size() ) throw fc::eof_exception();
return _data[_pos];
}
virtual size_t writesome( const char* buf, size_t len )
{
auto avail = std::max<size_t>( _data.size(), _pos + len );
_data.resize(avail);
memcpy( _data.data()+_pos, buf, len );
_pos += avail;
return avail;
}
char* data() { return _data.data(); }
virtual void close(){}
virtual void flush(){}
private:
std::vector<char> _data;
size_t _pos;
};
}

9
include/fc/io/iostream.hpp Executable file → Normal file
View file

@ -1,7 +1,6 @@
#pragma once
#include <fc/utility.hpp>
#include <fc/string.hpp>
#include <memory>
#include <string>
namespace fc {
@ -61,7 +60,7 @@ namespace fc {
class iostream : public virtual ostream, public virtual istream {};
fc::istream& getline( fc::istream&, fc::string&, char delim = '\n' );
fc::istream& getline( fc::istream&, std::string&, char delim = '\n' );
template<size_t N>
ostream& operator<<( ostream& o, char (&array)[N] )
@ -72,7 +71,7 @@ namespace fc {
ostream& operator<<( ostream& o, char );
ostream& operator<<( ostream& o, const char* v );
ostream& operator<<( ostream& o, const std::string& v );
ostream& operator<<( ostream& o, const fc::string& v );
ostream& operator<<( ostream& o, const std::string& v );
ostream& operator<<( ostream& o, const double& v );
ostream& operator<<( ostream& o, const float& v );
ostream& operator<<( ostream& o, const int64_t& v );
@ -88,7 +87,7 @@ namespace fc {
#endif
istream& operator>>( istream& o, std::string& v );
istream& operator>>( istream& o, fc::string& v );
istream& operator>>( istream& o, std::string& v );
istream& operator>>( istream& o, char& v );
istream& operator>>( istream& o, double& v );
istream& operator>>( istream& o, float& v );

4
include/fc/io/json.hpp Executable file → Normal file
View file

@ -30,12 +30,10 @@ namespace fc
enum output_formatting
{
stringify_large_ints_and_doubles = 0,
#ifdef WITH_EXOTIC_JSON_PARSERS
legacy_generator = 1
#endif
};
static ostream& to_stream( ostream& out, const fc::string& );
static ostream& to_stream( ostream& out, const std::string& );
static ostream& to_stream( ostream& out, const variant& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
static ostream& to_stream( ostream& out, const variants& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );
static ostream& to_stream( ostream& out, const variant_object& v, output_formatting format = stringify_large_ints_and_doubles, uint32_t max_depth = DEFAULT_MAX_RECURSION_DEPTH );

23
include/fc/io/json_relaxed.hpp Executable file → Normal file
View file

@ -10,7 +10,6 @@
#include <fc/io/fstream.hpp>
#include <fc/io/sstream.hpp>
#include <fc/log/logger.hpp>
#include <fc/string.hpp>
//#include <utfcpp/utf8.h>
#include <iostream>
#include <fstream>
@ -24,7 +23,7 @@ namespace fc { namespace json_relaxed
variant variant_from_stream( T& in, uint32_t max_depth );
template<typename T>
fc::string tokenFromStream( T& in )
std::string tokenFromStream( T& in )
{
fc::stringstream token;
try
@ -81,7 +80,7 @@ namespace fc { namespace json_relaxed
}
template<typename T, bool strict, bool allow_escape>
fc::string quoteStringFromStream( T& in )
std::string quoteStringFromStream( T& in )
{
fc::stringstream token;
try
@ -107,11 +106,11 @@ namespace fc { namespace json_relaxed
try
{
if( in.peek() != q )
return fc::string();
return std::string();
}
catch( const fc::eof_exception& e )
{
return fc::string();
return std::string();
}
// triple quote processing
@ -186,7 +185,7 @@ namespace fc { namespace json_relaxed
}
template<typename T, bool strict>
fc::string stringFromStream( T& in )
std::string stringFromStream( T& in )
{
try
{
@ -238,6 +237,8 @@ namespace fc { namespace json_relaxed
}
} FC_RETHROW_EXCEPTIONS( warn, "while parsing string" );
return {};
}
struct CharValueTable
@ -292,7 +293,7 @@ namespace fc { namespace json_relaxed
};
template<uint8_t base>
fc::variant parseInt( const fc::string& token, size_t start )
fc::variant parseInt( const std::string& token, size_t start )
{
static const CharValueTable ctbl;
static const uint64_t INT64_MAX_PLUS_ONE = static_cast<uint64_t>(INT64_MAX) + 1;
@ -334,7 +335,7 @@ namespace fc { namespace json_relaxed
}
template<bool strict, uint8_t base>
fc::variant maybeParseInt( const fc::string& token, size_t start )
fc::variant maybeParseInt( const std::string& token, size_t start )
{
try
{
@ -350,7 +351,7 @@ namespace fc { namespace json_relaxed
}
template<bool strict>
fc::variant parseNumberOrStr( const fc::string& token )
fc::variant parseNumberOrStr( const std::string& token )
{ try {
//ilog( (token) );
size_t i = 0, n = token.length();
@ -586,7 +587,7 @@ namespace fc { namespace json_relaxed
template<typename T, bool strict>
variant numberFromStream( T& in )
{ try {
fc::string token = tokenFromStream(in);
std::string token = tokenFromStream(in);
variant result = json_relaxed::parseNumberOrStr<strict>( token );
if( strict && !(result.is_int64() || result.is_uint64() || result.is_double()) )
FC_THROW_EXCEPTION( parse_error_exception, "expected: number" );
@ -596,7 +597,7 @@ namespace fc { namespace json_relaxed
template<typename T, bool strict>
variant wordFromStream( T& in )
{
fc::string token = tokenFromStream(in);
std::string token = tokenFromStream(in);
FC_ASSERT( token.length() > 0 );

418
include/fc/io/raw.hpp Executable file → Normal file
View file

@ -1,16 +1,14 @@
#pragma once
#include <boost/endian/buffers.hpp>
#include <fc/io/raw_variant.hpp>
#include <fc/reflect/reflect.hpp>
#include <fc/io/datastream.hpp>
#include <fc/io/varint.hpp>
#include <fc/optional.hpp>
#include <fc/fwd.hpp>
#include <fc/smart_ref_fwd.hpp>
#include <fc/array.hpp>
#include <fc/time.hpp>
#include <fc/filesystem.hpp>
#include <fc/exception/exception.hpp>
#include <fc/safe.hpp>
#include <fc/io/raw_fwd.hpp>
#include <algorithm>
#include <map>
@ -27,6 +25,22 @@ namespace fc {
pack( s, args..., _max_depth );
}
template<typename Stream>
inline void pack( Stream& s, const uint128_t& v, uint32_t _max_depth )
{
boost::endian::little_uint64_buf_at hilo[2];
hilo[0] = uint128_hi64( v );
hilo[1] = uint128_lo64( v );
s.write( (char*)hilo[0].data(), sizeof(hilo) );
}
template<typename Stream>
inline void unpack( Stream& s, uint128_t& v, uint32_t _max_depth )
{
boost::endian::little_uint64_buf_at hilo[2];
s.read( (char*) hilo, sizeof(hilo) );
v = uint128( hilo[0].value(), hilo[1].value() );
}
template<typename Stream>
inline void pack( Stream& s, const fc::exception& e, uint32_t _max_depth )
{
@ -51,7 +65,7 @@ namespace fc {
fc::raw::unpack( s, what, _max_depth );
fc::raw::unpack( s, msgs, _max_depth );
e = fc::exception( fc::move(msgs), code, name, what );
e = fc::exception( std::move(msgs), code, name, what );
}
template<typename Stream>
@ -90,52 +104,62 @@ namespace fc {
template<typename Stream>
inline void pack( Stream& s, const fc::time_point_sec& tp, uint32_t _max_depth )
{
uint32_t usec = tp.sec_since_epoch();
s.write( (const char*)&usec, sizeof(usec) );
pack( s, tp.sec_since_epoch(), _max_depth );
}
template<typename Stream>
inline void unpack( Stream& s, fc::time_point_sec& tp, uint32_t _max_depth )
{ try {
uint32_t sec;
s.read( (char*)&sec, sizeof(sec) );
unpack( s, sec, _max_depth );
tp = fc::time_point() + fc::seconds(sec);
} FC_RETHROW_EXCEPTIONS( warn, "" ) }
template<typename Stream>
inline void pack( Stream& s, const fc::time_point& tp, uint32_t _max_depth )
{
uint64_t usec = tp.time_since_epoch().count();
s.write( (const char*)&usec, sizeof(usec) );
pack( s, tp.time_since_epoch().count(), _max_depth );
}
template<typename Stream>
inline void unpack( Stream& s, fc::time_point& tp, uint32_t _max_depth )
{ try {
uint64_t usec;
s.read( (char*)&usec, sizeof(usec) );
unpack( s, usec, _max_depth );
tp = fc::time_point() + fc::microseconds(usec);
} FC_RETHROW_EXCEPTIONS( warn, "" ) }
template<typename Stream>
inline void pack( Stream& s, const fc::microseconds& usec, uint32_t _max_depth )
{
uint64_t usec_as_int64 = usec.count();
s.write( (const char*)&usec_as_int64, sizeof(usec_as_int64) );
pack( s, usec.count(), _max_depth );
}
template<typename Stream>
inline void unpack( Stream& s, fc::microseconds& usec, uint32_t _max_depth )
{ try {
uint64_t usec_as_int64;
s.read( (char*)&usec_as_int64, sizeof(usec_as_int64) );
unpack( s, usec_as_int64, _max_depth );
usec = fc::microseconds(usec_as_int64);
} FC_RETHROW_EXCEPTIONS( warn, "" ) }
template<typename Stream, typename T, size_t N>
inline void pack( Stream& s, const fc::array<T,N>& v, uint32_t _max_depth ) {
s.write((const char*)&v.data[0],N*sizeof(T));
template<typename Stream, size_t N>
inline void pack( Stream& s, const std::array<char,N>& v, uint32_t _max_depth ) {
s.write( v.data(), N );
}
template<typename Stream, size_t N>
inline void pack( Stream& s, const std::array<unsigned char,N>& v, uint32_t _max_depth ) {
s.write( (char*)v.data(), N );
}
template<typename Stream, size_t N>
inline void unpack( Stream& s, std::array<char,N>& v, uint32_t _max_depth ) { try {
s.read( v.data(), N );
} FC_RETHROW_EXCEPTIONS( warn, "std::array<char,${length}>", ("length",N) ) }
template<typename Stream, size_t N>
inline void unpack( Stream& s, std::array<unsigned char,N>& v, uint32_t _max_depth ) { try {
s.read( (char*)v.data(), N );
} FC_RETHROW_EXCEPTIONS( warn, "std::array<unsigned char,${length}>", ("length",N) ) }
template<typename Stream, typename T>
inline void pack( Stream& s, const std::shared_ptr<T>& v, uint32_t _max_depth )
@ -144,19 +168,29 @@ namespace fc {
fc::raw::pack( s, *v, _max_depth - 1 );
}
template<typename Stream, typename T, size_t N>
inline void unpack( Stream& s, fc::array<T,N>& v, uint32_t _max_depth )
{ try {
s.read((char*)&v.data[0],N*sizeof(T));
} FC_RETHROW_EXCEPTIONS( warn, "fc::array<type,length>", ("type",fc::get_typename<T>::name())("length",N) ) }
template<typename Stream, typename T>
inline void unpack( Stream& s, std::shared_ptr<T>& v, uint32_t _max_depth )
{ try {
FC_ASSERT( _max_depth > 0 );
v = std::make_shared<T>();
fc::raw::unpack( s, *v, _max_depth - 1 );
} FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr<T>", ("type",fc::get_typename<T>::name()) ) }
} FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr<${type}>", ("type",fc::get_typename<T>::name()) ) }
template<typename Stream, typename T>
inline void pack( Stream& s, const std::shared_ptr<const T>& v, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
fc::raw::pack( s, *v, _max_depth - 1 );
}
template<typename Stream, typename T>
inline void unpack( Stream& s, std::shared_ptr<const T>& v, uint32_t _max_depth )
{ try {
FC_ASSERT( _max_depth > 0 );
T tmp;
fc::raw::unpack( s, tmp, _max_depth - 1 );
v = std::make_shared<const T>(std::move(tmp));
} FC_RETHROW_EXCEPTIONS( warn, "std::shared_ptr<const T>", ("type",fc::get_typename<T>::name()) ) }
template<typename Stream> inline void pack( Stream& s, const signed_int& v, uint32_t _max_depth ) {
uint32_t val = (v.value<<1) ^ (v.value>>31);
@ -184,7 +218,7 @@ namespace fc {
s.get(b);
v |= uint32_t(uint8_t(b) & 0x7f) << by;
by += 7;
} while( uint8_t(b) & 0x80 );
} while( (uint8_t(b) & 0x80) && by < 32 );
vi.value = ((v>>1) ^ (v>>31)) + (v&0x01);
vi.value = v&0x01 ? vi.value : -vi.value;
vi.value = -vi.value;
@ -193,24 +227,18 @@ namespace fc {
uint64_t v = 0; char b = 0; uint8_t by = 0;
do {
s.get(b);
v |= uint32_t(uint8_t(b) & 0x7f) << by;
if( by >= 64 || (by == 63 && uint8_t(b) > 1) )
FC_THROW_EXCEPTION( overflow_exception, "Invalid packed unsigned_int!" );
v |= uint64_t(uint8_t(b) & 0x7f) << by;
by += 7;
} while( uint8_t(b) & 0x80 );
vi.value = static_cast<uint32_t>(v);
}
template<typename Stream, typename T> inline void unpack( Stream& s, const T& vi, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
T tmp;
fc::raw::unpack( s, tmp, _max_depth - 1 );
FC_ASSERT( vi == tmp );
vi.value = static_cast<uint64_t>(v);
}
template<typename Stream> inline void pack( Stream& s, const char* v, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
fc::raw::pack( s, fc::string(v), _max_depth - 1 );
fc::raw::pack( s, std::string(v), _max_depth - 1 );
}
template<typename Stream, typename T>
@ -238,19 +266,6 @@ namespace fc {
FC_ASSERT( _max_depth > 0 );
fc::raw::unpack( *v, _max_depth - 1 ); // TODO not sure about this
}
template<typename Stream, typename T>
void pack( Stream& s, const fc::smart_ref<T>& v, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
fc::raw::pack( s, *v, _max_depth - 1 );
}
template<typename Stream, typename T>
void unpack( Stream& s, fc::smart_ref<T>& v, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
fc::raw::unpack( s, *v, _max_depth - 1 );
}
// optional
template<typename Stream, typename T>
@ -273,9 +288,9 @@ namespace fc {
// std::vector<char>
template<typename Stream> inline void pack( Stream& s, const std::vector<char>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth - 1 );
fc::raw::pack( s, unsigned_int(value.size()), _max_depth - 1 );
if( value.size() )
s.write( &value.front(), (uint32_t)value.size() );
s.write( &value.front(), value.size() );
}
template<typename Stream> inline void unpack( Stream& s, std::vector<char>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
@ -287,25 +302,25 @@ namespace fc {
}
// fc::string
template<typename Stream> inline void pack( Stream& s, const fc::string& v, uint32_t _max_depth ) {
template<typename Stream> inline void pack( Stream& s, const std::string& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
fc::raw::pack( s, unsigned_int((uint32_t)v.size()), _max_depth - 1 );
fc::raw::pack( s, unsigned_int(v.size()), _max_depth - 1 );
if( v.size() ) s.write( v.c_str(), v.size() );
}
template<typename Stream> inline void unpack( Stream& s, fc::string& v, uint32_t _max_depth ) {
template<typename Stream> inline void unpack( Stream& s, std::string& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
std::vector<char> tmp; fc::raw::unpack( s, tmp, _max_depth - 1 );
if( tmp.size() )
v = fc::string( tmp.data(), tmp.data()+tmp.size() );
else v = fc::string();
v = std::string( tmp.data(), tmp.data()+tmp.size() );
else v = std::string();
}
// bool
template<typename Stream> inline void pack( Stream& s, const bool& v, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
fc::raw::pack( s, uint8_t(v), _max_depth - 1 );
fc::raw::pack( s, v ? uint8_t(1) : uint8_t(0), _max_depth - 1 );
}
template<typename Stream> inline void unpack( Stream& s, bool& v, uint32_t _max_depth )
{
@ -354,47 +369,162 @@ namespace fc {
const uint32_t max_depth;
};
template<typename IsClass=fc::true_type>
struct if_class{
template<typename Stream, typename T>
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) { s << v; }
template<typename Stream, typename T>
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) { s >> v; }
// Default pack/unpack functions for classes are removed due to recursion issue.
// Classes should implement pack/unpack functions explicitly.
template<typename T, typename Dummy = void>
struct if_class;
template<typename T>
struct if_class<T, std::enable_if_t<!std::is_class<T>::value>> {
template<typename Stream>
static inline void pack( Stream& s, const T v, uint32_t _max_depth ) = delete;
template<typename Stream>
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) = delete;
};
template<>
struct if_class<fc::false_type> {
template<typename Stream, typename T>
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
s.write( (char*)&v, sizeof(v) );
struct if_class<int64_t, void> {
template<typename Stream>
static inline void pack( Stream& s, const int64_t v, uint32_t _max_depth ) {
boost::endian::little_int64_buf_t tmp;
tmp = v;
s.write( (char*)&tmp, sizeof(tmp) );
}
template<typename Stream, typename T>
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
s.read( (char*)&v, sizeof(v) );
template<typename Stream>
static inline void unpack( Stream& s, int64_t& v, uint32_t _max_depth ) {
boost::endian::little_int64_buf_t tmp;
s.read( (char*)&tmp, sizeof(tmp) );
v = tmp.value();
}
};
template<typename IsEnum=fc::false_type>
struct if_enum {
template<typename Stream, typename T>
template<>
struct if_class<uint64_t, void> {
template<typename Stream>
static inline void pack( Stream& s, const uint64_t v, uint32_t _max_depth ) {
boost::endian::little_uint64_buf_t tmp;
tmp = v;
s.write( (char*)&tmp, sizeof(tmp) );
}
template<typename Stream>
static inline void unpack( Stream& s, uint64_t& v, uint32_t _max_depth ) {
boost::endian::little_uint64_buf_t tmp;
s.read( (char*)&tmp, sizeof(tmp) );
v = tmp.value();
}
};
template<>
struct if_class<int32_t, void> {
template<typename Stream>
static inline void pack( Stream& s, const int32_t v, uint32_t _max_depth ) {
boost::endian::little_int32_buf_t tmp;
tmp = v;
s.write( (char*)&tmp, sizeof(tmp) );
}
template<typename Stream>
static inline void unpack( Stream& s, int32_t& v, uint32_t _max_depth ) {
boost::endian::little_int32_buf_t tmp;
s.read( (char*)&tmp, sizeof(tmp) );
v = tmp.value();
}
};
template<>
struct if_class<uint32_t, void> {
template<typename Stream>
static inline void pack( Stream& s, const uint32_t v, uint32_t _max_depth ) {
boost::endian::little_uint32_buf_t tmp;
tmp = v;
s.write( (char*)&tmp, sizeof(tmp) );
}
template<typename Stream>
static inline void unpack( Stream& s, uint32_t& v, uint32_t _max_depth ) {
boost::endian::little_uint32_buf_t tmp;
s.read( (char*)&tmp, sizeof(tmp) );
v = tmp.value();
}
};
template<>
struct if_class<int16_t, void> {
template<typename Stream>
static inline void pack( Stream& s, const int16_t v, uint32_t _max_depth ) {
boost::endian::little_int16_buf_t tmp;
tmp = v;
s.write( (char*)&tmp, sizeof(tmp) );
}
template<typename Stream>
static inline void unpack( Stream& s, int16_t& v, uint32_t _max_depth ) {
boost::endian::little_int16_buf_t tmp;
s.read( (char*)&tmp, sizeof(tmp) );
v = tmp.value();
}
};
template<>
struct if_class<uint16_t, void> {
template<typename Stream>
static inline void pack( Stream& s, const uint16_t v, uint32_t _max_depth ) {
boost::endian::little_uint16_buf_t tmp;
tmp = v;
s.write( (char*)&tmp, sizeof(tmp) );
}
template<typename Stream>
static inline void unpack( Stream& s, uint16_t& v, uint32_t _max_depth ) {
boost::endian::little_uint16_buf_t tmp;
s.read( (char*)&tmp, sizeof(tmp) );
v = tmp.value();
}
};
template<>
struct if_class<int8_t, void> {
template<typename Stream>
static inline void pack( Stream& s, const int8_t v, uint32_t _max_depth ) {
s.write( (char*)&v, 1 );
}
template<typename Stream>
static inline void unpack( Stream& s, int8_t& v, uint32_t _max_depth ) {
s.read( (char*)&v, 1 );
}
};
template<>
struct if_class<uint8_t, void> {
template<typename Stream>
static inline void pack( Stream& s, const uint8_t v, uint32_t _max_depth ) {
s.write( (char*)&v, 1 );
}
template<typename Stream>
static inline void unpack( Stream& s, uint8_t& v, uint32_t _max_depth ) {
s.read( (char*)&v, 1 );
}
};
template<typename T, typename Dummy=void>
struct if_enum;
template<typename T>
struct if_enum<T, std::enable_if_t<!std::is_enum<T>::value>> {
template<typename Stream>
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
fc::reflector<T>::visit( pack_object_visitor<Stream,T>( v, s, _max_depth - 1 ) );
}
template<typename Stream, typename T>
template<typename Stream>
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
fc::reflector<T>::visit( unpack_object_visitor<Stream,T>( v, s, _max_depth - 1 ) );
}
};
template<>
struct if_enum<fc::true_type> {
template<typename Stream, typename T>
template<typename T>
struct if_enum<T, std::enable_if_t<std::is_enum<T>::value>> {
template<typename Stream>
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
fc::raw::pack( s, signed_int((int64_t)v), _max_depth - 1 );
}
template<typename Stream, typename T>
template<typename Stream>
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
signed_int temp;
@ -403,40 +533,98 @@ namespace fc {
}
};
template<typename IsReflected=fc::false_type>
template<typename...> using void_t = void;
template<typename T, typename=void>
struct has_auxiliary_packing : std::false_type {};
template<typename T>
struct has_auxiliary_packing<T,
void_t<decltype(std::declval<const T>().fc_pack_auxiliary(std::declval<fc::datastream<size_t>&>(), 1)),
decltype(std::declval<T>().fc_unpack_auxiliary(std::declval<fc::datastream<size_t>&>(), 1))>>
: std::true_type {};
template<typename Stream, typename T, std::enable_if_t<has_auxiliary_packing<T>::value, bool> = true>
static inline void pack_auxiliary( Stream& s, const T& v, uint32_t _max_depth ) {
v.fc_pack_auxiliary(s, _max_depth );
}
template<typename Stream, typename T, std::enable_if_t<!has_auxiliary_packing<T>::value, bool> = true>
static inline void pack_auxiliary( Stream&, const T&, uint32_t ) { /* Do nothing */ }
template<typename Stream, typename T, std::enable_if_t<has_auxiliary_packing<T>::value, bool> = true>
static inline void unpack_auxiliary( Stream& s, T& v, uint32_t _max_depth ) {
v.fc_unpack_auxiliary(s, _max_depth );
}
template<typename Stream, typename T, std::enable_if_t<!has_auxiliary_packing<T>::value, bool> = true>
static inline void unpack_auxiliary( Stream&, T&, uint32_t ) { /* Do nothing */ }
template<typename IsReflected=std::false_type>
struct if_reflected {
template<typename Stream, typename T>
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
if_class<typename fc::is_class<T>::type>::pack( s, v, _max_depth - 1 );
if_class<T>::pack( s, v, _max_depth - 1 );
}
template<typename Stream, typename T>
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
if_class<typename fc::is_class<T>::type>::unpack( s, v, _max_depth - 1 );
if_class<T>::unpack( s, v, _max_depth - 1 );
}
};
template<>
struct if_reflected<fc::true_type> {
struct if_reflected<std::true_type> {
template<typename Stream, typename T>
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
if_enum< typename fc::reflector<T>::is_enum >::pack( s, v, _max_depth - 1 );
if_enum<T>::pack( s, v, _max_depth - 1 );
pack_auxiliary( s, v, _max_depth - 1 );
}
template<typename Stream, typename T>
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
if_enum< typename fc::reflector<T>::is_enum >::unpack( s, v, _max_depth - 1 );
if_enum<T>::unpack( s, v, _max_depth - 1 );
unpack_auxiliary( s, v, _max_depth - 1 );
}
};
template<typename T, typename=void>
struct has_custom_packing : std::false_type {};
template<typename T>
struct has_custom_packing<T,
void_t<decltype(std::declval<const T>().fc_pack(std::declval<fc::datastream<size_t>&>(), 1)),
decltype(std::declval<T>().fc_unpack(std::declval<fc::datastream<size_t>&>(), 1))>>
: std::true_type {};
template<typename Stream, typename T, std::enable_if_t<has_custom_packing<T>::value, bool> = true>
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
static_assert(!has_auxiliary_packing<T>::value,
"A class with custom packing must not have auxiliary packing. Pack auxiliary data in custom packer.");
v.fc_pack( s, _max_depth - 1 );
}
template<typename Stream, typename T, std::enable_if_t<!has_custom_packing<T>::value, bool> = true>
static inline void pack( Stream& s, const T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
if_reflected< typename fc::reflector<T>::is_defined >::pack( s, v, _max_depth - 1 );
}
template<typename Stream, typename T, std::enable_if_t<has_custom_packing<T>::value, bool> = true>
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
v.fc_unpack( s, _max_depth - 1 );
}
template<typename Stream, typename T, std::enable_if_t<!has_custom_packing<T>::value, bool> = true>
static inline void unpack( Stream& s, T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
if_reflected< typename fc::reflector<T>::is_defined >::unpack( s, v, _max_depth - 1 );
}
} // namesapce detail
template<typename Stream, typename T>
inline void pack( Stream& s, const std::unordered_set<T>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
@ -450,8 +638,7 @@ namespace fc {
--_max_depth;
unsigned_int size; fc::raw::unpack( s, size, _max_depth );
value.clear();
FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE );
value.reserve(size.value);
value.reserve( std::min( size.value, static_cast<uint64_t>(FC_MAX_PREALLOC_SIZE) ) );
for( uint32_t i = 0; i < size.value; ++i )
{
T tmp;
@ -481,7 +668,7 @@ namespace fc {
inline void pack( Stream& s, const std::unordered_map<K,V>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
@ -496,8 +683,7 @@ namespace fc {
--_max_depth;
unsigned_int size; fc::raw::unpack( s, size, _max_depth );
value.clear();
FC_ASSERT( size.value*(sizeof(K)+sizeof(V)) < MAX_ARRAY_ALLOC_SIZE );
value.reserve(size.value);
value.reserve( std::min( size.value, static_cast<uint64_t>(FC_MAX_PREALLOC_SIZE) ) );
for( uint32_t i = 0; i < size.value; ++i )
{
std::pair<K,V> tmp;
@ -509,7 +695,7 @@ namespace fc {
inline void pack( Stream& s, const std::map<K,V>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
@ -524,7 +710,6 @@ namespace fc {
--_max_depth;
unsigned_int size; fc::raw::unpack( s, size, _max_depth );
value.clear();
FC_ASSERT( size.value*(sizeof(K)+sizeof(V)) < MAX_ARRAY_ALLOC_SIZE );
for( uint32_t i = 0; i < size.value; ++i )
{
std::pair<K,V> tmp;
@ -537,7 +722,7 @@ namespace fc {
inline void pack( Stream& s, const std::deque<T>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
@ -551,13 +736,12 @@ namespace fc {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
unsigned_int size; fc::raw::unpack( s, size, _max_depth );
FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE );
value.resize(size.value);
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
fc::raw::unpack( s, *itr, _max_depth );
++itr;
value.resize( std::min( size.value, static_cast<uint64_t>(FC_MAX_PREALLOC_SIZE) ) );
for( uint64_t i = 0; i < size; i++ )
{
if( i >= value.size() )
value.resize( std::min( static_cast<uint64_t>(2*value.size()), size.value ) );
unpack( s, value[i], _max_depth );
}
}
@ -565,7 +749,7 @@ namespace fc {
inline void pack( Stream& s, const std::vector<T>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
@ -579,13 +763,12 @@ namespace fc {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
unsigned_int size; fc::raw::unpack( s, size, _max_depth );
FC_ASSERT( size.value*sizeof(T) < MAX_ARRAY_ALLOC_SIZE );
value.resize(size.value);
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
fc::raw::unpack( s, *itr, _max_depth );
++itr;
value.resize( std::min( size.value, static_cast<uint64_t>(FC_MAX_PREALLOC_SIZE) ) );
for( uint64_t i = 0; i < size; i++ )
{
if( i >= value.size() )
value.resize( std::min( static_cast<uint64_t>(2*value.size()), size.value ) );
unpack( s, value[i], _max_depth );
}
}
@ -593,7 +776,7 @@ namespace fc {
inline void pack( Stream& s, const std::set<T>& value, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
--_max_depth;
fc::raw::pack( s, unsigned_int((uint32_t)value.size()), _max_depth );
fc::raw::pack( s, unsigned_int(value.size()), _max_depth );
auto itr = value.begin();
auto end = value.end();
while( itr != end ) {
@ -615,18 +798,30 @@ namespace fc {
}
}
template<typename Stream, boost::endian::order O, class T, std::size_t N, boost::endian::align A>
void pack( Stream& s, const boost::endian::endian_buffer<O,T,N,A>& v, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
s.write( (char*)v.data(), sizeof(v) );
}
template<typename Stream, boost::endian::order O, class T, std::size_t N, boost::endian::align A>
void unpack( Stream& s, boost::endian::endian_buffer<O,T,N,A>& v, uint32_t _max_depth )
{
FC_ASSERT( _max_depth > 0 );
s.read( (char*)&v, sizeof(v) );
}
template<typename Stream, typename T>
void pack( Stream& s, const T& v, uint32_t _max_depth ) {
FC_ASSERT( _max_depth > 0 );
fc::raw::detail::if_reflected< typename fc::reflector<T>::is_defined >::pack( s, v, _max_depth - 1 );
fc::raw::detail::pack(s, v, _max_depth);
}
template<typename Stream, typename T>
void unpack( Stream& s, T& v, uint32_t _max_depth )
{ try {
FC_ASSERT( _max_depth > 0 );
fc::raw::detail::if_reflected< typename fc::reflector<T>::is_defined >::unpack( s, v, _max_depth - 1 );
fc::raw::detail::unpack(s, v, _max_depth);
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
template<typename T>
@ -713,7 +908,6 @@ namespace fc {
FC_ASSERT( _max_depth > 0 );
datastream<const char*> ds( d, s );
fc::raw::unpack( ds, v, _max_depth - 1 );
return v;
} FC_RETHROW_EXCEPTIONS( warn, "error unpacking ${type}", ("type",fc::get_typename<T>::name() ) ) }
template<typename Stream>

69
include/fc/io/raw_fwd.hpp Executable file → Normal file
View file

@ -1,11 +1,15 @@
#pragma once
#include <boost/endian/buffers.hpp>
#include <fc/config.hpp>
#include <fc/container/flat_fwd.hpp>
#include <fc/container/deque_fwd.hpp>
#include <fc/io/varint.hpp>
#include <fc/array.hpp>
#include <fc/safe.hpp>
#include <fc/uint128.hpp>
#include <array>
#include <deque>
#include <memory>
#include <vector>
#include <string>
#include <unordered_set>
@ -22,25 +26,29 @@ namespace fc {
class path;
template<typename... Types> class static_variant;
class sha224;
class sha256;
class sha512;
class ripemd160;
template<typename IntType, typename EnumType> class enum_type;
namespace ip { class endpoint; }
namespace ecc { class public_key; class private_key; }
template<typename Storage> class fixed_string;
namespace raw {
template<typename T>
inline size_t pack_size( const T& v );
template<typename Stream, typename Storage> inline void pack( Stream& s, const fc::fixed_string<Storage>& u, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename Storage> inline void unpack( Stream& s, fc::fixed_string<Storage>& u, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename IntType, typename EnumType>
inline void pack( Stream& s, const fc::enum_type<IntType,EnumType>& tp, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename IntType, typename EnumType>
inline void unpack( Stream& s, fc::enum_type<IntType,EnumType>& tp, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream>
inline void pack( Stream& s, const uint128_t& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream>
inline void unpack( Stream& s, uint128_t& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void pack( Stream& s, const std::set<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void unpack( Stream& s, std::set<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
@ -53,8 +61,8 @@ namespace fc {
//template<typename Stream, typename T> inline void pack( Stream& s, const flat_set<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
//template<typename Stream, typename T> inline void unpack( Stream& s, flat_set<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
//template<typename Stream, typename T> inline void pack( Stream& s, const std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
//template<typename Stream, typename T> inline void unpack( Stream& s, std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void pack( Stream& s, const std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void unpack( Stream& s, std::deque<T>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename K, typename V> inline void pack( Stream& s, const std::unordered_map<K,V>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename K, typename V> inline void unpack( Stream& s, std::unordered_map<K,V>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
@ -80,7 +88,6 @@ namespace fc {
template<typename Stream, typename T> void unpack( Stream& s, fc::optional<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> void unpack( Stream& s, const T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> void pack( Stream& s, const fc::optional<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> void pack( Stream& s, const safe<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> void unpack( Stream& s, fc::safe<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
@ -96,8 +103,17 @@ namespace fc {
template<typename Stream> void unpack( Stream& s, fc::ecc::private_key&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> void pack( Stream& s, const fc::ecc::private_key&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void pack( Stream& s, const T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void unpack( Stream& s, T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, fc::sha224&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void pack( Stream& s, const fc::sha224&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, fc::sha256&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void pack( Stream& s, const fc::sha256&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, fc::sha512&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void pack( Stream& s, const fc::sha512&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, fc::ripemd160&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void pack( Stream& s, const fc::ripemd160&, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> void pack( Stream& s, const T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> void unpack( Stream& s, T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void pack( Stream& s, const std::vector<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void unpack( Stream& s, std::vector<T>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
@ -111,15 +127,40 @@ namespace fc {
template<typename Stream> inline void pack( Stream& s, const char* v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void pack( Stream& s, const std::vector<char>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, std::vector<char>& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, boost::endian::order O, class T, std::size_t N, boost::endian::align A>
inline void pack( Stream& s, const boost::endian::endian_buffer<O,T,N,A>& v, uint32_t _max_depth );
template<typename Stream, boost::endian::order O, class T, std::size_t N, boost::endian::align A>
inline void unpack( Stream& s, boost::endian::endian_buffer<O,T,N,A>& v, uint32_t _max_depth );
template<typename Stream, typename T, size_t N> inline void pack( Stream& s, const fc::array<T,N>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T, size_t N> inline void unpack( Stream& s, fc::array<T,N>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH);
template<typename Stream, typename T, size_t N>
inline void pack( Stream& s, const std::array<T,N>& v, uint32_t _max_depth ) = delete;
template<typename Stream, typename T, size_t N>
inline void unpack( Stream& s, std::array<T,N>& v, uint32_t _max_depth ) = delete;
template<typename Stream, size_t N>
inline void pack( Stream& s, const std::array<char,N>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, size_t N>
inline void unpack( Stream& s, std::array<char,N>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH);
template<typename Stream, size_t N>
inline void pack( Stream& s, const std::array<unsigned char,N>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, size_t N>
inline void unpack( Stream& s, std::array<unsigned char,N>& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH);
template<typename Stream, typename T> inline void pack( Stream& s, const std::shared_ptr<T>& v,
uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void unpack( Stream& s, std::shared_ptr<T>& v,
uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void pack( Stream& s, const std::shared_ptr<const T>& v,
uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream, typename T> inline void unpack( Stream& s, std::shared_ptr<const T>& v,
uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void pack( Stream& s, const bool& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename Stream> inline void unpack( Stream& s, bool& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename T> inline std::vector<char> pack( const T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename T> inline T unpack( const std::vector<char>& s, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename T> inline void unpack( const std::vector<char>& s, T& tmp, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename T> inline T unpack( const char* d, uint32_t s, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
template<typename T> inline void unpack( const char* d, uint32_t s, T& v, uint32_t _max_depth=FC_PACK_MAX_DEPTH );
} }

View file

@ -1,24 +0,0 @@
#pragma once
#include <fc/io/raw.hpp>
#include <fc/interprocess/file_mapping.hpp>
#include <fc/filesystem.hpp>
#include <fc/exception/exception.hpp>
namespace fc
{
namespace raw
{
template<typename T>
void unpack_file( const fc::path& filename, T& obj )
{
try {
fc::file_mapping fmap( filename.generic_string().c_str(), fc::read_only);
fc::mapped_region mapr( fmap, fc::read_only, 0, fc::file_size(filename) );
auto cs = (const char*)mapr.get_address();
fc::datastream<const char*> ds( cs, mapr.get_size() );
fc::raw::unpack(ds,obj);
} FC_RETHROW_EXCEPTIONS( info, "unpacking file ${file}", ("file",filename) );
}
}
}

27
include/fc/io/raw_variant.hpp Executable file → Normal file
View file

@ -1,4 +1,5 @@
#pragma once
#include <algorithm>
#include <fc/exception/exception.hpp>
#include <fc/io/raw_fwd.hpp>
#include <fc/variant_object.hpp>
@ -25,7 +26,7 @@ namespace fc { namespace raw {
}
virtual void handle( const double& v )const
{
fc::raw::pack( s, v, max_depth );
FC_THROW_EXCEPTION( invalid_arg_exception, "Can't pack double!" );
}
virtual void handle( const bool& v )const
{
@ -85,10 +86,7 @@ namespace fc { namespace raw {
}
case variant::double_type:
{
double val;
raw::unpack( s, val, _max_depth );
v = val;
return;
FC_THROW_EXCEPTION( invalid_arg_exception, "Can't unpack double!" );
}
case variant::bool_type:
{
@ -99,23 +97,23 @@ namespace fc { namespace raw {
}
case variant::string_type:
{
fc::string val;
std::string val;
raw::unpack( s, val, _max_depth );
v = fc::move(val);
v = std::move(val);
return;
}
case variant::array_type:
{
variants val;
raw::unpack( s, val, _max_depth );
v = fc::move(val);
v = std::move(val);
return;
}
case variant::object_type:
{
variant_object val;
raw::unpack( s, val, _max_depth );
v = fc::move(val);
v = std::move(val);
return;
}
default:
@ -128,7 +126,7 @@ namespace fc { namespace raw {
{
FC_ASSERT( _max_depth > 0 );
--_max_depth;
unsigned_int vs = (uint32_t)v.size();
unsigned_int vs = v.size();
pack( s, vs, _max_depth );
for( auto itr = v.begin(); itr != v.end(); ++itr )
{
@ -143,18 +141,17 @@ namespace fc { namespace raw {
--_max_depth;
unsigned_int vs;
unpack( s, vs, _max_depth );
mutable_variant_object mvo;
mvo.reserve(vs.value);
mvo.reserve( std::min( vs.value, static_cast<uint64_t>(FC_MAX_PREALLOC_SIZE) ) );
for( uint32_t i = 0; i < vs.value; ++i )
{
fc::string key;
std::string key;
fc::variant value;
fc::raw::unpack( s, key, _max_depth );
fc::raw::unpack( s, value, _max_depth );
mvo.set( fc::move(key), fc::move(value) );
mvo.set( std::move(key), std::move(value) );
}
v = fc::move(mvo);
v = std::move(mvo);
}
} } // fc::raw

8
include/fc/io/sstream.hpp Executable file → Normal file
View file

@ -7,12 +7,12 @@ namespace fc {
class stringstream : virtual public iostream {
public:
stringstream();
stringstream( fc::string& s);
stringstream( const fc::string& s);
stringstream( std::string& s);
stringstream( const std::string& s);
~stringstream();
fc::string str();
void str(const fc::string& s);
std::string str();
void str(const std::string& s);
void clear();

0
include/fc/io/stdio.hpp Executable file → Normal file
View file

37
include/fc/io/varint.hpp Executable file → Normal file
View file

@ -4,35 +4,40 @@
namespace fc {
struct unsigned_int {
unsigned_int( uint32_t v = 0 ):value(v){}
unsigned_int( uint64_t v = 0 ):value(v){}
template<typename T>
unsigned_int( T v ):value(v){}
//operator uint32_t()const { return value; }
//operator uint64_t()const { return value; }
template<typename T>
operator T()const { return static_cast<T>(value); }
unsigned_int& operator=( int32_t v ) { value = v; return *this; }
unsigned_int& operator=( uint64_t v ) { value = v; return *this; }
uint32_t value;
uint64_t value;
friend bool operator==( const unsigned_int& i, const uint32_t& v ) { return i.value == v; }
friend bool operator==( const uint32_t& i, const unsigned_int& v ) { return i == v.value; }
friend bool operator==( const unsigned_int& i, const uint64_t& v ) { return i.value == v; }
friend bool operator==( const uint64_t& i, const unsigned_int& v ) { return i == v.value; }
friend bool operator==( const unsigned_int& i, const unsigned_int& v ) { return i.value == v.value; }
friend bool operator!=( const unsigned_int& i, const uint32_t& v ) { return i.value != v; }
friend bool operator!=( const uint32_t& i, const unsigned_int& v ) { return i != v.value; }
friend bool operator!=( const unsigned_int& i, const uint64_t& v ) { return i.value != v; }
friend bool operator!=( const uint64_t& i, const unsigned_int& v ) { return i != v.value; }
friend bool operator!=( const unsigned_int& i, const unsigned_int& v ) { return i.value != v.value; }
friend bool operator<( const unsigned_int& i, const uint32_t& v ) { return i.value < v; }
friend bool operator<( const uint32_t& i, const unsigned_int& v ) { return i < v.value; }
friend bool operator<( const unsigned_int& i, const uint64_t& v ) { return i.value < v; }
friend bool operator<( const uint64_t& i, const unsigned_int& v ) { return i < v.value; }
friend bool operator<( const unsigned_int& i, const unsigned_int& v ) { return i.value < v.value; }
friend bool operator>=( const unsigned_int& i, const uint32_t& v ) { return i.value >= v; }
friend bool operator>=( const uint32_t& i, const unsigned_int& v ) { return i >= v.value; }
friend bool operator<=( const unsigned_int& i, const uint64_t& v ) { return i.value <= v; }
friend bool operator<=( const uint64_t& i, const unsigned_int& v ) { return i <= v.value; }
friend bool operator<=( const unsigned_int& i, const unsigned_int& v ) { return i.value <= v.value; }
friend bool operator>( const unsigned_int& i, const uint64_t& v ) { return i.value > v; }
friend bool operator>( const uint64_t& i, const unsigned_int& v ) { return i > v.value; }
friend bool operator>( const unsigned_int& i, const unsigned_int& v ) { return i.value > v.value; }
friend bool operator>=( const unsigned_int& i, const uint64_t& v ) { return i.value >= v; }
friend bool operator>=( const uint64_t& i, const unsigned_int& v ) { return i >= v.value; }
friend bool operator>=( const unsigned_int& i, const unsigned_int& v ) { return i.value >= v.value; }
};
@ -93,9 +98,9 @@ namespace std
struct hash<fc::unsigned_int>
{
public:
size_t operator()(const fc::signed_int &a) const
size_t operator()(const fc::unsigned_int &a) const
{
return std::hash<uint32_t>()(a.value);
return std::hash<uint64_t>()(a.value);
}
};
}

29
include/fc/log/appender.hpp Executable file → Normal file
View file

@ -1,42 +1,43 @@
#pragma once
#include <fc/shared_ptr.hpp>
#include <fc/string.hpp>
#include <memory>
#include <string>
namespace fc {
class appender;
class log_message;
class variant;
class appender_factory : public fc::retainable {
class appender_factory {
public:
typedef fc::shared_ptr<appender_factory> ptr;
typedef std::shared_ptr<appender_factory> ptr;
virtual ~appender_factory(){};
virtual fc::shared_ptr<appender> create( const variant& args ) = 0;
virtual std::shared_ptr<appender> create( const variant& args ) = 0;
};
namespace detail {
template<typename T>
class appender_factory_impl : public appender_factory {
public:
virtual fc::shared_ptr<appender> create( const variant& args ) {
return fc::shared_ptr<appender>(new T(args));
virtual std::shared_ptr<appender> create( const variant& args ) {
return std::shared_ptr<appender>(new T(args));
}
};
}
class appender : public fc::retainable {
class appender {
public:
typedef fc::shared_ptr<appender> ptr;
typedef std::shared_ptr<appender> ptr;
template<typename T>
static bool register_appender(const fc::string& type) {
return register_appender( type, new detail::appender_factory_impl<T>() );
static bool register_appender(const std::string& type) {
return register_appender( type, appender_factory::ptr( new detail::appender_factory_impl<T>() ) );
}
static appender::ptr create( const fc::string& name, const fc::string& type, const variant& args );
static appender::ptr get( const fc::string& name );
static bool register_appender( const fc::string& type, const appender_factory::ptr& f );
virtual ~appender() = default;
static appender::ptr create( const std::string& name, const std::string& type, const variant& args );
static appender::ptr get( const std::string& name );
static bool register_appender( const std::string& type, const appender_factory::ptr& f );
virtual void log( const log_message& m ) = 0;
};

2
include/fc/log/console_appender.hpp Executable file → Normal file
View file

@ -40,7 +40,7 @@ namespace fc
:format( "${timestamp} ${thread_name} ${context} ${file}:${line} ${method} ${level}] ${message}" ),
stream(console_appender::stream::std_error),max_object_depth(FC_MAX_LOG_OBJECT_DEPTH),flush(true){}
fc::string format;
std::string format;
console_appender::stream::type stream;
std::vector<level_color> level_colors;
uint32_t max_object_depth;

9
include/fc/log/file_appender.hpp Executable file → Normal file
View file

@ -12,14 +12,13 @@ class file_appender : public appender {
struct config {
config( const fc::path& p = "log.txt" );
fc::string format;
std::string format;
fc::path filename;
bool flush = true;
bool rotate = false;
microseconds rotation_interval;
microseconds rotation_limit;
bool rotation_compression = false;
uint32_t max_object_depth;
uint32_t max_object_depth = FC_MAX_LOG_OBJECT_DEPTH;
};
file_appender( const variant& args );
~file_appender();
@ -27,10 +26,10 @@ class file_appender : public appender {
private:
class impl;
fc::shared_ptr<impl> my;
std::unique_ptr<impl> my;
};
} // namespace fc
#include <fc/reflect/reflect.hpp>
FC_REFLECT( fc::file_appender::config,
(format)(filename)(flush)(rotate)(rotation_interval)(rotation_limit)(rotation_compression)(max_object_depth) )
(format)(filename)(flush)(rotate)(rotation_interval)(rotation_limit)(max_object_depth) )

4
include/fc/log/gelf_appender.hpp Executable file → Normal file
View file

@ -15,7 +15,7 @@ namespace fc
{
string endpoint = "127.0.0.1:12201";
string host = "fc"; // the name of the host, source or application that sent this message (just passed through to GELF server)
uint32_t max_object_depth;
uint32_t max_object_depth = FC_MAX_LOG_OBJECT_DEPTH;
};
gelf_appender(const variant& args);
@ -24,7 +24,7 @@ namespace fc
private:
class impl;
fc::shared_ptr<impl> my;
std::unique_ptr<impl> my;
};
} // namespace fc

86
include/fc/log/log_message.hpp Executable file → Normal file
View file

@ -6,23 +6,15 @@
#include <fc/config.hpp>
#include <fc/time.hpp>
#include <fc/variant_object.hpp>
#include <fc/shared_ptr.hpp>
#include <memory>
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/preprocessor/control/if.hpp>
#include <boost/preprocessor/comparison/equal.hpp>
#include <boost/preprocessor/facilities/expand.hpp>
#include <boost/preprocessor/variadic/size.hpp>
#include <boost/preprocessor/seq/variadic_seq_to_seq.hpp>
#include <string>
namespace fc
{
namespace detail
{
class log_context_impl;
class log_message_impl;
namespace detail
{
class log_context_impl;
class log_message_impl;
}
/**
@ -32,19 +24,19 @@ namespace fc
{
public:
/**
* @brief Define's the various log levels for reporting.
* @brief Define's the various log levels for reporting.
*
* Each log level includes all higher levels such that
* Each log level includes all higher levels such that
* Debug includes Error, but Error does not include Debug.
*/
enum values
{
all,
debug,
info,
warn,
error,
off
all,
debug,
info,
warn,
error,
off
};
log_level( values v = off ):value(v){}
explicit log_level( int v ):value( static_cast<values>(v)){}
@ -61,31 +53,31 @@ namespace fc
*
* @see FC_LOG_CONTEXT
*/
class log_context
class log_context
{
public:
log_context();
log_context( log_level ll,
const char* file,
uint64_t line,
const char* method );
const char* file,
uint64_t line,
const char* method );
~log_context();
explicit log_context( const variant& v, uint32_t max_depth );
variant to_variant( uint32_t max_depth )const;
string get_file()const;
std::string get_file()const;
uint64_t get_line_number()const;
string get_method()const;
string get_thread_name()const;
string get_task_name()const;
string get_host_name()const;
std::string get_method()const;
std::string get_thread_name()const;
std::string get_task_name()const;
std::string get_host_name()const;
time_point get_timestamp()const;
log_level get_log_level()const;
string get_context()const;
std::string get_context()const;
void append_context( const fc::string& c );
void append_context( const std::string& c );
string to_string()const;
std::string to_string()const;
private:
std::shared_ptr<detail::log_context_impl> my;
};
@ -116,18 +108,18 @@ namespace fc
public:
log_message();
/**
* @param ctx - generally provided using the FC_LOG_CONTEXT(LEVEL) macro
* @param ctx - generally provided using the FC_LOG_CONTEXT(LEVEL) macro
*/
log_message( log_context ctx, std::string format, variant_object args = variant_object() );
~log_message();
log_message( const variant& v, uint32_t max_depth );
variant to_variant(uint32_t max_depth)const;
string get_message()const;
std::string get_message()const;
log_context get_context()const;
string get_format()const;
std::string get_format()const;
variant_object get_data()const;
private:
@ -155,8 +147,8 @@ FC_REFLECT_TYPENAME( fc::log_message );
* @param LOG_LEVEL - a valid log_level::Enum name.
*/
#define FC_LOG_CONTEXT(LOG_LEVEL) \
fc::log_context( fc::log_level::LOG_LEVEL, __FILE__, __LINE__, __func__ )
fc::log_context( fc::log_level::LOG_LEVEL, (const char*)__FILE__, __LINE__, (const char*)__func__ )
/**
* @def FC_LOG_MESSAGE(LOG_LEVEL,FORMAT,...)
*
@ -166,14 +158,8 @@ FC_REFLECT_TYPENAME( fc::log_message );
* @param FORMAT A const char* string containing zero or more references to keys as "${key}"
* @param ... A set of key/value pairs denoted as ("key",val)("key2",val2)...
*/
#define FC_LOG_MESSAGE_GENERATE_PARAMETER_NAME(VALUE) BOOST_PP_LPAREN() BOOST_PP_STRINGIZE(VALUE), fc::variant(VALUE, FC_MAX_LOG_OBJECT_DEPTH) BOOST_PP_RPAREN()
#define FC_LOG_MESSAGE_DONT_GENERATE_PARAMETER_NAME(NAME, VALUE) BOOST_PP_LPAREN() NAME, fc::variant(VALUE, FC_MAX_LOG_OBJECT_DEPTH) BOOST_PP_RPAREN()
#define FC_LOG_MESSAGE_GENERATE_PARAMETER_NAMES_IF_NEEDED(r, data, PARAMETER_AND_MAYBE_NAME) BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE PARAMETER_AND_MAYBE_NAME,1),FC_LOG_MESSAGE_GENERATE_PARAMETER_NAME,FC_LOG_MESSAGE_DONT_GENERATE_PARAMETER_NAME)PARAMETER_AND_MAYBE_NAME
#define FC_LOG_MESSAGE( LOG_LEVEL, FORMAT, ... ) \
fc::log_message( FC_LOG_CONTEXT(LOG_LEVEL), \
FORMAT, \
fc::limited_mutable_variant_object( FC_MAX_LOG_OBJECT_DEPTH, true )__VA_ARGS__ )
#define FC_LOG_MESSAGE_STRING_ONLY(LOG_LEVEL, FORMAT) \
fc::log_message(FC_LOG_CONTEXT(LOG_LEVEL), FORMAT, fc::variant_object())
#define FC_LOG_MESSAGE_WITH_SUBSTITUTIONS(LOG_LEVEL, FORMAT, ...) \
fc::log_message(FC_LOG_CONTEXT(LOG_LEVEL), FORMAT, fc::mutable_variant_object() BOOST_PP_SEQ_FOR_EACH(FC_LOG_MESSAGE_GENERATE_PARAMETER_NAMES_IF_NEEDED, _, BOOST_PP_VARIADIC_SEQ_TO_SEQ(__VA_ARGS__)))
#define FC_LOG_MESSAGE(LOG_LEVEL, ...) \
BOOST_PP_EXPAND(BOOST_PP_IF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__),1),FC_LOG_MESSAGE_STRING_ONLY,FC_LOG_MESSAGE_WITH_SUBSTITUTIONS)(LOG_LEVEL,__VA_ARGS__))

72
include/fc/log/logger.hpp Executable file → Normal file
View file

@ -1,29 +1,27 @@
#pragma once
#include <fc/config.hpp>
#include <fc/string.hpp>
#include <fc/time.hpp>
#include <fc/shared_ptr.hpp>
#include <fc/log/appender.hpp>
#include <fc/log/log_message.hpp>
#include <cstddef>
#include <memory>
namespace fc
namespace fc
{
class appender;
/**
*
*
@code
void my_class::func()
void my_class::func()
{
fc_dlog( my_class_logger, "Format four: ${arg} five: ${five}", ("arg",4)("five",5) );
}
@endcode
*/
class logger
class logger
{
public:
static logger get( const fc::string& name = "default");
static logger get( const std::string& name = "default");
logger();
logger( const string& name, const logger& parent = nullptr );
@ -33,27 +31,27 @@ namespace fc
~logger();
logger& operator=(const logger&);
logger& operator=(logger&&);
friend bool operator==( const logger&, nullptr_t );
friend bool operator!=( const logger&, nullptr_t );
friend bool operator==( const logger&, std::nullptr_t );
friend bool operator!=( const logger&, std::nullptr_t );
logger& set_log_level( log_level e );
log_level get_log_level()const;
logger& set_parent( const logger& l );
logger get_parent()const;
void set_name( const fc::string& n );
const fc::string& name()const;
void set_name( const std::string& n );
const std::string& name()const;
void add_appender( const fc::shared_ptr<appender>& a );
std::vector<fc::shared_ptr<appender> > get_appenders()const;
void remove_appender( const fc::shared_ptr<appender>& a );
void add_appender( const appender::ptr& a );
std::vector<appender::ptr> get_appenders()const;
void remove_appender( const appender::ptr& a );
bool is_enabled( log_level e )const;
void log( log_message m );
private:
class impl;
fc::shared_ptr<impl> my;
std::shared_ptr<impl> my;
};
} // namespace fc
@ -149,12 +147,18 @@ namespace fc
BOOST_PP_LPAREN() BOOST_PP_STRINGIZE(base),fc::variant(base,FC_MAX_LOG_OBJECT_DEPTH) BOOST_PP_RPAREN()
#define FC_FORMAT( SEQ )\
BOOST_PP_SEQ_FOR_EACH( FC_FORMAT_ARG, v, SEQ )
BOOST_PP_SEQ_FOR_EACH( FC_FORMAT_ARG, v, SEQ )
// takes a ... instead of a SEQ arg because it can be called with an empty SEQ
// takes a ... instead of a SEQ arg because it can be called with an empty SEQ
// from FC_CAPTURE_AND_THROW()
#define FC_FORMAT_ARG_PARAMS( ... )\
BOOST_PP_SEQ_FOR_EACH( FC_FORMAT_ARGS, v, __VA_ARGS__ )
BOOST_PP_SEQ_FOR_EACH( FC_FORMAT_ARGS, v, __VA_ARGS__ )
#define FC_DUMP_FORMAT_ARG_NAME(r, unused, base) \
"(" BOOST_PP_STRINGIZE(base) ")"
#define FC_DUMP_FORMAT_ARG_NAMES( SEQ )\
BOOST_PP_SEQ_FOR_EACH( FC_DUMP_FORMAT_ARG_NAME, v, SEQ )
#define fc_ddump( LOGGER, SEQ ) \
fc_dlog( LOGGER, FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) )
@ -167,12 +171,34 @@ namespace fc
#define ddump( SEQ ) \
dlog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) )
// TODO FC_FORMAT_ARG_PARAMS(...) may throw exceptions when calling fc::variant(...) inside,
// as a quick-fix / workaround, we catch all exceptions here.
// However, to log as much info as possible, it's better to catch exceptions when processing each argument
#define idump( SEQ ) \
ilog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) )
{ \
try { \
ilog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) ); \
} catch( ... ) { \
ilog ( "[ERROR: Got exception while trying to dump ( ${args} )]",("args",FC_DUMP_FORMAT_ARG_NAMES(SEQ)) ); \
} \
}
#define wdump( SEQ ) \
wlog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) )
{ \
try { \
wlog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) ); \
} catch( ... ) { \
wlog ( "[ERROR: Got exception while trying to dump ( ${args} )]",("args",FC_DUMP_FORMAT_ARG_NAMES(SEQ)) ); \
} \
}
#define edump( SEQ ) \
elog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) )
{ \
try { \
elog( FC_FORMAT(SEQ), FC_FORMAT_ARG_PARAMS(SEQ) ); \
} catch( ... ) { \
elog ( "[ERROR: Got exception while trying to dump ( ${args} )]",("args",FC_DUMP_FORMAT_ARG_NAMES(SEQ)) ); \
} \
}
// this disables all normal logging statements -- not something you'd normally want to do,
// but it's useful if you're benchmarking something and suspect logging is causing

4
include/fc/log/logger_config.hpp Executable file → Normal file
View file

@ -9,7 +9,7 @@ namespace fc {
variant args = variant()) :
name(name),
type(type),
args(fc::move(args)),
args(std::move(args)),
enabled(true)
{}
string name;
@ -19,7 +19,7 @@ namespace fc {
};
struct logger_config {
logger_config(const fc::string& name = ""):name(name),enabled(true),additivity(false){}
logger_config(const std::string& name = ""):name(name),enabled(true),additivity(false){}
string name;
ostring parent;
/// if not set, then parents level is used.

View file

@ -1,26 +0,0 @@
#pragma once
#include <fc/tuple.hpp>
#include <fc/function.hpp>
namespace fc {
template<typename R>
std::function<R, fc::tuple<> > make_fused( const std::function<R>& f ) {
return [=]( fc::tuple<> ){ return f(); };
}
template<typename R,typename A>
std::function<R(fc::tuple<A>) > make_fused( const std::function<R(A)>& f ) {
return [f]( fc::tuple<A> t){ return f(t.a); };
}
template<typename R,typename A,typename B>
std::function<R(fc::tuple<A,B>) > make_fused( const std::function<R(A,B)>& f ) {
return [f]( fc::tuple<A,B> t){ return f(t.a,t.b); };
}
template<typename R,typename A,typename B,typename C>
std::function<R(fc::tuple<A,B,C>) > make_fused( const std::function<R(A,B,C)>& f ) {
return [f]( fc::tuple<A,B,C> t){ return f(t.a,t.b,t.c); };
}
template<typename R,typename A,typename B,typename C,typename D>
std::function<R(fc::tuple<A,B,C,D>) > make_fused( const std::function<R(A,B,C,D)>& f ) {
return [f]( fc::tuple<A,B,C> t){ return f(t.a,t.b,t.c,t.d); };
}
}

30
include/fc/network/http/connection.hpp Executable file → Normal file
View file

@ -1,7 +1,7 @@
#pragma once
#include <fc/vector.hpp>
#include <fc/string.hpp>
#include <memory>
#include <string>
#include <vector>
namespace fc {
namespace ip { class endpoint; }
@ -11,11 +11,11 @@ namespace fc {
struct header
{
header( fc::string k, fc::string v )
:key(fc::move(k)),val(fc::move(v)){}
header( std::string k, std::string v )
:key(std::move(k)),val(std::move(v)){}
header(){}
fc::string key;
fc::string val;
std::string key;
std::string val;
};
typedef std::vector<header> headers;
@ -25,6 +25,7 @@ namespace fc {
enum status_code {
OK = 200,
RecordCreated = 201,
NoContent = 204,
BadRequest = 400,
NotAuthorized = 401,
NotFound = 404,
@ -35,20 +36,21 @@ namespace fc {
int status;
std::vector<header> headers;
std::vector<char> body;
std::string body_as_string;
};
struct request
{
fc::string get_header( const fc::string& key )const;
fc::string remote_endpoint;
fc::string method;
fc::string domain;
fc::string path;
std::string get_header( const std::string& key )const;
std::string remote_endpoint;
std::string method;
std::string domain;
std::string path;
std::vector<header> headers;
std::vector<char> body;
};
std::vector<header> parse_urlencoded_params( const fc::string& f );
std::vector<header> parse_urlencoded_params( const std::string& f );
/**
* Connections have reference semantics, all copies refer to the same
@ -61,7 +63,7 @@ namespace fc {
~connection();
// used for clients
void connect_to( const fc::ip::endpoint& ep );
http::reply request( const fc::string& method, const fc::string& url, const fc::string& body = std::string(), const headers& = headers(), const fc::string& content_type = "application/json");
http::reply request( const std::string& method, const std::string& url, const std::string& body = std::string(), const headers& = headers());
// used for servers
fc::tcp_socket& get_socket()const;
@ -79,4 +81,4 @@ namespace fc {
#include <fc/reflect/reflect.hpp>
FC_REFLECT( fc::http::header, (key)(val) )
FC_REFLECT( fc::http::reply, (status)(headers)(body)(body_as_string) )

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