├── .gitignore ├── CMakeLists.txt ├── DESIGN.md ├── LICENSE.md ├── README.md ├── TODO.md ├── bitchat ├── CMakeLists.txt └── main.cpp ├── bitsharesgui ├── bitshares.qrc ├── bitsharesgui.pro ├── bitsharesguiprecomp.h ├── bitsharesmainwindow.cpp ├── bitsharesmainwindow.h ├── bitsharesmainwindow.ui ├── bitsharestreemodel.cpp ├── bitsharestreemodel.h ├── bshare_gui.cpp ├── bshare_gui.h ├── bshare_gui.ui ├── bshare_viewport.cpp ├── bshare_viewport.hpp ├── bshare_viewports │ ├── bshare_viewport_mail.cpp │ └── bshare_viewport_mail.hpp ├── chatwidget.cpp ├── chatwidget.h ├── chatwidget.ui ├── images │ └── pencil_small.png ├── main.cpp ├── profileeditor.cpp ├── profileeditor.h ├── profileeditor.ui ├── selfsizingmainwindow.cpp ├── selfsizingmainwindow.h ├── selfsizingwidget.cpp ├── selfsizingwidget.h ├── ui_bitsharesmainwindow.h └── ui_profileeditor.h ├── build.cmd ├── cli_client ├── CMakeLists.txt └── main.cpp ├── coding_standards.md ├── configs ├── a.json ├── b.json └── c.json ├── doc ├── bitname.dox ├── doxygen.cfg └── mainpage.dox ├── include └── bts │ ├── address.hpp │ ├── addressbook │ ├── addressbook.hpp │ └── contact.hpp │ ├── application.hpp │ ├── bitchat │ ├── bitchat_channel.hpp │ ├── bitchat_client.hpp │ ├── bitchat_message_cache.hpp │ ├── bitchat_message_db.hpp │ ├── bitchat_messages.hpp │ └── bitchat_private_message.hpp │ ├── bitchat_message.hpp │ ├── bitmessage.hpp │ ├── bitname │ ├── bitname_block.hpp │ ├── bitname_channel.hpp │ ├── bitname_client.hpp │ ├── bitname_db.hpp │ ├── bitname_fork_db.hpp │ ├── bitname_hash.hpp │ ├── bitname_messages.hpp │ ├── bitname_miner.hpp │ └── bitname_record.hpp │ ├── blockchain │ ├── asset.hpp │ ├── block.hpp │ ├── blockchain_channel.hpp │ ├── blockchain_client.hpp │ ├── blockchain_db.hpp │ ├── blockchain_market_db.hpp │ ├── blockchain_messages.hpp │ ├── blockchain_printer.hpp │ ├── blockchain_time_keeper.hpp │ ├── fork_tree.hpp │ ├── outputs.hpp │ ├── proof.hpp │ ├── transaction.hpp │ └── trx_validation_state.hpp │ ├── config.hpp │ ├── db │ ├── fwd.hpp │ ├── level_map.hpp │ ├── level_pod_map.hpp │ └── peer.hpp │ ├── difficulty.hpp │ ├── extended_address.hpp │ ├── keychain.hpp │ ├── merkle_tree.hpp │ ├── network │ ├── broadcast_manager.hpp │ ├── channel.hpp │ ├── channel_id.hpp │ ├── channel_pow_stats.hpp │ ├── connection.hpp │ ├── feature_id.hpp │ ├── get_public_ip.hpp │ ├── message.hpp │ ├── server.hpp │ ├── stcp_socket.hpp │ └── upnp.hpp │ ├── peer │ ├── peer_channel.hpp │ ├── peer_db.hpp │ ├── peer_host.hpp │ └── peer_messages.hpp │ ├── profile.hpp │ ├── proof_of_work.hpp │ ├── rpc │ └── rpc_server.hpp │ ├── small_hash.hpp │ ├── units.hpp │ ├── wallet.hpp │ └── wallet_cache.hpp ├── keyhotee ├── AddContactDialog.ui ├── AddressBook │ ├── AddressBookModel.cpp │ ├── AddressBookModel.hpp │ ├── ContactView.ui │ └── ContactsTable.ui ├── CMakeLists.txt ├── EditContactDialog.cpp ├── EditContactDialog.hpp ├── EditContactDialog.ui ├── Keyhotee.qrc ├── KeyhoteeMainWindow.cpp ├── KeyhoteeMainWindow.hpp ├── KeyhoteeMainWindow.ui ├── LoginDialog.cpp ├── LoginDialog.hpp ├── LoginDialog.ui ├── images │ └── contact_icon.png ├── main.cpp └── profile_wizard │ ├── ProfileEditPage.ui │ ├── ProfileIntroPage.ui │ ├── ProfileNymPage.ui │ ├── ProfileWizard.cpp │ └── ProfileWizard.hpp ├── src ├── account.cpp ├── account.hpp ├── address.cpp ├── addressbook │ └── addressbook.cpp ├── application.cpp ├── bitchat │ ├── bitchat_channel.cpp │ ├── bitchat_client.cpp │ ├── bitchat_message_cache.cpp │ ├── bitchat_message_db.cpp │ ├── bitchat_messages.cpp │ └── bitchat_private_message.cpp ├── bitchat_message.cpp ├── bitname │ ├── bitname_block.cpp │ ├── bitname_channel.cpp │ ├── bitname_client.cpp │ ├── bitname_db.cpp │ ├── bitname_fork_db.cpp │ ├── bitname_hash.cpp │ ├── bitname_messages.cpp │ ├── bitname_miner.cpp │ └── bitname_record.cpp ├── blockchain │ ├── asset.cpp │ ├── block.cpp │ ├── blockchain_channel.cpp │ ├── blockchain_client.cpp │ ├── blockchain_db.cpp │ ├── blockchain_market_db.cpp │ ├── blockchain_messages.cpp │ ├── blockchain_outputs.cpp │ ├── blockchain_printer.cpp │ ├── blockchain_time_keeper.cpp │ ├── transaction.cpp │ └── trx_validation_state.cpp ├── difficulty.cpp ├── extended_address.cpp ├── keychain.cpp ├── main.cpp ├── merkle_tree.cpp ├── miner.cpp ├── miner.hpp ├── network │ ├── channel_pow_stats.cpp │ ├── connection.cpp │ ├── get_public_ip.cpp │ ├── server.cpp │ ├── stcp_socket.cpp │ └── upnp.cpp ├── peer │ ├── peer_channel.cpp │ ├── peer_db.cpp │ └── peer_messages.cpp ├── profile.cpp ├── proof_of_work.cpp ├── rpc │ └── rpc_server.cpp ├── small_hash.cpp ├── wallet.cpp └── wallet_cache.cpp ├── tasks.md ├── tests ├── CMakeLists.txt ├── blockchain_tests.cpp ├── chain.html ├── pow_test.cpp ├── timekeeper.cpp ├── unit_tests.cpp └── wallet_test.cpp └── vendor ├── SFMT-src-1.4 ├── LICENSE.txt ├── SFMT-alti.h ├── SFMT-common.h ├── SFMT-params.h ├── SFMT-params11213.h ├── SFMT-params1279.h ├── SFMT-params132049.h ├── SFMT-params19937.h ├── SFMT-params216091.h ├── SFMT-params2281.h ├── SFMT-params4253.h ├── SFMT-params44497.h ├── SFMT-params607.h ├── SFMT-params86243.h ├── SFMT-sse2.h ├── SFMT.c ├── SFMT.h └── test.c ├── leveldb-1.12.0 ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── db │ ├── builder.cc │ ├── builder.h │ ├── c.cc │ ├── corruption_test.cc │ ├── db_bench.cc │ ├── db_impl.cc │ ├── db_impl.h │ ├── db_iter.cc │ ├── db_iter.h │ ├── db_test.cc │ ├── dbformat.cc │ ├── dbformat.h │ ├── dbformat_test.cc │ ├── filename.cc │ ├── filename.h │ ├── filename_test.cc │ ├── leveldb_main.cc │ ├── log_format.h │ ├── log_reader.cc │ ├── log_reader.h │ ├── log_test.cc │ ├── log_writer.cc │ ├── log_writer.h │ ├── memtable.cc │ ├── memtable.h │ ├── repair.cc │ ├── skiplist.h │ ├── skiplist_test.cc │ ├── snapshot.h │ ├── table_cache.cc │ ├── table_cache.h │ ├── version_edit.cc │ ├── version_edit.h │ ├── version_edit_test.cc │ ├── version_set.cc │ ├── version_set.h │ ├── version_set_test.cc │ ├── write_batch.cc │ ├── write_batch_internal.h │ └── write_batch_test.cc ├── helpers │ └── memenv │ │ ├── memenv.cc │ │ └── memenv.h ├── include │ └── leveldb │ │ ├── c.h │ │ ├── cache.h │ │ ├── comparator.h │ │ ├── db.h │ │ ├── env.h │ │ ├── filter_policy.h │ │ ├── iterator.h │ │ ├── options.h │ │ ├── slice.h │ │ ├── status.h │ │ ├── table.h │ │ ├── table_builder.h │ │ └── write_batch.h ├── port │ ├── atomic_pointer.h │ ├── port.h │ ├── port_example.h │ ├── port_posix.cc │ ├── port_posix.h │ ├── thread_annotations.h │ └── win │ │ └── stdint.h ├── table │ ├── block.cc │ ├── block.h │ ├── block_builder.cc │ ├── block_builder.h │ ├── filter_block.cc │ ├── filter_block.h │ ├── filter_block_test.cc │ ├── format.cc │ ├── format.h │ ├── iterator.cc │ ├── iterator_wrapper.h │ ├── merger.cc │ ├── merger.h │ ├── table.cc │ ├── table_builder.cc │ ├── table_test.cc │ ├── two_level_iterator.cc │ └── two_level_iterator.h └── util │ ├── arena.cc │ ├── arena.h │ ├── arena_test.cc │ ├── bloom.cc │ ├── bloom_test.cc │ ├── cache.cc │ ├── cache_test.cc │ ├── coding.cc │ ├── coding.h │ ├── coding_test.cc │ ├── comparator.cc │ ├── crc32c.cc │ ├── crc32c.h │ ├── crc32c_test.cc │ ├── env.cc │ ├── env_posix.cc │ ├── env_test.cc │ ├── filter_policy.cc │ ├── hash.cc │ ├── hash.h │ ├── histogram.cc │ ├── histogram.h │ ├── logging.cc │ ├── logging.h │ ├── mutexlock.h │ ├── options.cc │ ├── posix_logger.h │ ├── random.h │ ├── status.cc │ ├── testharness.cc │ ├── testharness.h │ ├── testutil.cc │ └── testutil.h └── miniupnp └── miniupnpc ├── CMakeLists.txt ├── bsdqueue.h ├── codelength.h ├── connecthostport.c ├── connecthostport.h ├── declspec.h ├── igd_desc_parse.c ├── igd_desc_parse.h ├── minihttptestserver.c ├── minisoap.c ├── minisoap.h ├── minissdpc.c ├── minissdpc.h ├── miniupnpc.c ├── miniupnpc.h ├── miniupnpcmodule.c ├── miniupnpcstrings.h.cmake ├── miniupnpctypes.h ├── miniwget.c ├── miniwget.h ├── minixml.c ├── minixml.h ├── minixmlvalid.c ├── portlistingparse.c ├── portlistingparse.h ├── receivedata.c ├── receivedata.h ├── testigddescparse.c ├── testminiwget.c ├── testminixml.c ├── testupnpreplyparse.c ├── upnpc.c ├── upnpcommands.c ├── upnpcommands.h ├── upnperrors.c ├── upnperrors.h ├── upnpreplyparse.c ├── upnpreplyparse.h └── wingenminiupnpcstrings.c /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | *.dylib 10 | *.dll 11 | 12 | # Compiled Static libraries 13 | *.lai 14 | *.la 15 | *.a 16 | *.lib 17 | 18 | 19 | #CMake->MSVC artifacts 20 | *.sln 21 | *.vcxproj 22 | ALL_BUILD 23 | ZERO_CHECK 24 | 25 | #MSVC secondary artifacts 26 | *.suo 27 | *.vcxproj.filters 28 | *.vcxproj.user 29 | *.pdb 30 | *.ilk 31 | *.lastbuildstate 32 | *.sdf 33 | *.opensdf 34 | Debug/ 35 | Release/ 36 | 37 | # Log files 38 | *.tlog 39 | 40 | #DLN 41 | vendor/qt.5.1 42 | 43 | 44 | fc 45 | doc/html 46 | CMakeCache.txt 47 | Makefile 48 | CMakeFiles 49 | cmake_install.cmake 50 | ecc_test 51 | pow_test 52 | unit_tests 53 | wallet_test 54 | libbshare.a 55 | tests/dds_test 56 | tests/pow_test 57 | vendor/miniupnp/miniupnpc/miniupnpcstrings.h 58 | bitshared 59 | bitchatc 60 | bitchat/bitchat 61 | tests/blockchain_tests 62 | *automoc.cpp 63 | src/gui/sexc 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | bitshares - Polymorphic Digital Asset Library 2 | ========= 3 | 4 | BitShares is a new blockchain that pays dividends and enables users 5 | to short and trade any arbitrary asset type. 6 | 7 | 8 | Project Status 9 | ------------ 10 | This code is only fit for developers and the api, design is evolving 11 | rapidly. If you would like to be involved please contact me via 12 | github or bytemaster on bitcointalk.org 13 | 14 | Dependencies 15 | ------------------- 16 | g++ 4.6, VC2010 17 | boost 1.54 18 | OpenSSL 19 | Qt 5.1 (for GUI only) 20 | cmake 2.8.11.2 21 | 22 | Build 23 | -------------------- 24 | 25 | git clone https://github.com/InvictusInnovations/BitShares.git 26 | cd BitShares 27 | git clone https://github.com/InvictusInnovations/fc.git 28 | cmake . 29 | make 30 | 31 | Coding Standards 32 | ---------------- 33 | all lower case names with underscores with the exception of macros. 34 | private implmentation classes in the detail namespace. 35 | Make it look like the rest of the code. 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | TODO List 2 | --------------------------- 3 | 1) make bitchat messages have flexible encryption algorithms 4 | 2) bitchat messages should support the best compression possible 5 | -------------------------------------------------------------------------------- /bitchat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | set( sources main.cpp ) 3 | add_executable( bitchat ${sources} ) 4 | target_link_libraries( bitchat upnpc-static bshare fc leveldb ${BOOST_LIBRARIES} upnpc-static ) 5 | -------------------------------------------------------------------------------- /bitsharesgui/bitshares.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/pencil_small.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /bitsharesgui/bitsharesgui.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2013-08-14T18:36:27 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | QMAKE_CXX=/opt/local/bin/g++ 11 | QMAKE_LINK=/opt/local/bin/g++ 12 | QMAKE_CC=/opt/local/bin/gcc 13 | 14 | TARGET = bitsharesgui 15 | TEMPLATE = app 16 | 17 | !win32 { 18 | QMAKE_CXXFLAGS += -std=c++11 19 | } 20 | 21 | win32 { 22 | LIBS += ../Debug/bshare.lib ../fc/Debug/fc_debug.lib 23 | } else { 24 | LIBS += ../libbshare.a ../fc/libfc.a 25 | LIBS += -L${BOOST_LIBRARY_DIR} -lboost_context -lboost_thread -lboost_system -lboost_chrono -lboost_filesystem -lboost_system -lboost_date_time -lboost_coroutine 26 | LIBS += ../libbshare.a ../fc/libfc.a 27 | } 28 | 29 | 30 | INCLUDEPATH += ../include 31 | INCLUDEPATH += /usr/local/include 32 | INCLUDEPATH += ../fc/include 33 | 34 | #PRECOMPILED_HEADER = bitsharesguiprecomp.h 35 | 36 | SOURCES += main.cpp \ 37 | bitsharesmainwindow.cpp \ 38 | profileeditor.cpp \ 39 | bitsharestreemodel.cpp \ 40 | chatwidget.cpp \ 41 | selfsizingwidget.cpp \ 42 | selfsizingmainwindow.cpp 43 | 44 | HEADERS += \ 45 | bitsharesmainwindow.h \ 46 | profileeditor.h \ 47 | bitsharestreemodel.h \ 48 | chatwidget.h \ 49 | selfsizingwidget.h \ 50 | selfsizingmainwindow.h \ 51 | bitsharesguiprecomp.h 52 | 53 | FORMS += \ 54 | bitsharesmainwindow.ui \ 55 | profileeditor.ui \ 56 | chatwidget.ui 57 | 58 | 59 | #SOURCES += main.cpp \ 60 | # bshare_gui.cpp \ 61 | # bshare_viewport.cpp \ 62 | # bshare_viewports/bshare_viewport_mail.cpp 63 | 64 | #HEADERS += \ 65 | # bshare_gui.h \ 66 | # bshare_viewport.hpp \ 67 | # bshare_viewports/bshare_viewport_mail.hpp 68 | 69 | #FORMS += \ 70 | # bshare_gui.ui 71 | 72 | RESOURCES += \ 73 | bitshares.qrc 74 | 75 | -------------------------------------------------------------------------------- /bitsharesgui/bitsharesguiprecomp.h: -------------------------------------------------------------------------------- 1 | #ifndef BITSHARESGUIPRECOMP_H 2 | #define BITSHARESGUIPRECOMP_H 3 | 4 | #include 5 | #include 6 | 7 | 8 | #define VERSIONNUM (int32_t(1)) 9 | 10 | 11 | #endif // BITSHARESGUIPRECOMP_H 12 | -------------------------------------------------------------------------------- /bitsharesgui/bitsharesmainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef BITSHARESMAINWINDOW_H 2 | #define BITSHARESMAINWINDOW_H 3 | 4 | #include "bitsharestreemodel.h" 5 | #include "selfsizingmainwindow.h" 6 | 7 | namespace Ui { 8 | class BitSharesMainWindow; 9 | } 10 | 11 | class BitSharesMainWindow : public SelfSizingMainWindow 12 | { 13 | Q_OBJECT 14 | 15 | void readSettings(); 16 | void writeSettings(); 17 | void closeEvent(QCloseEvent *event); 18 | bool okToContinue() { return true; } 19 | 20 | public: 21 | explicit BitSharesMainWindow(QWidget *parent = 0); 22 | ~BitSharesMainWindow(); 23 | 24 | private slots: 25 | 26 | void on_actionExit_triggered(); 27 | 28 | void on_actionCreateMail_triggered(); 29 | 30 | private: 31 | Ui::BitSharesMainWindow *ui; 32 | BitSharesTreeModel _bitSharesTreeModel; 33 | 34 | }; 35 | 36 | #endif // BITSHARESMAINWINDOW_H 37 | -------------------------------------------------------------------------------- /bitsharesgui/bitsharestreemodel.h: -------------------------------------------------------------------------------- 1 | #ifndef BITSHARESTREEMODEL_H 2 | #define BITSHARESTREEMODEL_H 3 | 4 | #include 5 | 6 | class BitSharesTreeModel : public QAbstractItemModel 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit BitSharesTreeModel(QObject *parent = 0); 11 | 12 | int columnCount(const QModelIndex & parent = QModelIndex()) const; 13 | int rowCount(const QModelIndex & parent = QModelIndex()) const; 14 | Qt::ItemFlags flags ( const QModelIndex & index ) const; 15 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; 16 | QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; 17 | QModelIndex parent(const QModelIndex & index) const; 18 | signals: 19 | 20 | public slots: 21 | 22 | }; 23 | 24 | #endif // BITSHARESTREEMODEL_H 25 | -------------------------------------------------------------------------------- /bitsharesgui/bshare_gui.h: -------------------------------------------------------------------------------- 1 | #ifndef BSHARE_GUI_H 2 | #define BSHARE_GUI_H 3 | 4 | //Qt libs 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | //bshare libs 12 | #include "bshare_viewport.hpp" 13 | 14 | namespace Ui { 15 | class bshare_gui; 16 | } 17 | 18 | class bshare_gui : public QWidget 19 | { 20 | Q_OBJECT 21 | 22 | public: 23 | explicit bshare_gui(QWidget *parent = 0); 24 | ~bshare_gui(); 25 | 26 | private: 27 | Ui::bshare_gui *ui; 28 | 29 | /** Private Variables **/ 30 | QStandardItemModel * bshare_menu_treeview_model; 31 | bshare_viewport * viewport_controller; 32 | 33 | /** Private Functions **/ 34 | }; 35 | 36 | #endif // BSHARE_GUI_H 37 | -------------------------------------------------------------------------------- /bitsharesgui/bshare_gui.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | bshare_gui 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 500 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 10 20 | 9 21 | 781 22 | 481 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /bitsharesgui/bshare_viewport.cpp: -------------------------------------------------------------------------------- 1 | #include "bshare_viewport.hpp" 2 | 3 | bshare_viewport::bshare_viewport(QWidget *parent) : 4 | QWidget(parent) 5 | { 6 | /*** 7 | ** Notes about structure 8 | ** 9 | ** This class is a QWidget with a QStackedWidget attached 10 | ** allowing multiple widgets to be called in one area. 11 | ** Instead of calling the qstackedwidget, we will be calling 12 | ** bshare_viewport functions to control the stackedwidget/viewport. 13 | ** The benifits should be apparent. 14 | ***/ 15 | 16 | layout = new QGridLayout(this); 17 | this->setLayout(layout); 18 | //layout settings 19 | //layout->setMargin(0); 20 | 21 | /** 22 | * Initialize viewport 23 | **/ 24 | stacked_widget_viewport = new QStackedWidget(0); 25 | stacked_widget_viewport->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 26 | stacked_widget_viewport->setStyleSheet("QStackedWidget{border:1px solid #000;}"); 27 | layout->addWidget(stacked_widget_viewport, 0,0, 1,1, Qt::AlignLeft); 28 | 29 | mail_view = new bshare_viewport_mail(0); 30 | mail_view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 31 | //Add to (stacked widget)viewport 32 | stacked_widget_viewport->addWidget(mail_view); 33 | } 34 | 35 | 36 | 37 | /*** 38 | * Group of Functions 39 | * Select which view should be showing 40 | ***/ 41 | void bshare_viewport::show_view(QString view){ 42 | if(view == "mail"){ 43 | stacked_widget_viewport->setCurrentIndex(0); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /bitsharesgui/bshare_viewport.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BSHARE_VIEWPORT_HPP 2 | #define BSHARE_VIEWPORT_HPP 3 | 4 | //qt libs 5 | #include 6 | #include 7 | 8 | //bshare libs 9 | #include "bshare_viewports/bshare_viewport_mail.hpp" 10 | 11 | class bshare_viewport : public QWidget 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit bshare_viewport(QWidget *parent = 0); 16 | 17 | private: 18 | /** Private Variables **/ 19 | QGridLayout * layout; 20 | 21 | //Contains everything in one widget 22 | QStackedWidget * stacked_widget_viewport; 23 | 24 | //Account 25 | 26 | //Trade 27 | 28 | //Contacts 29 | 30 | //Identities 31 | 32 | //Mail 33 | bshare_viewport_mail * mail_view; 34 | 35 | //Favorites 36 | 37 | /** Private Functions **/ 38 | void show_view(QString); 39 | 40 | 41 | signals: 42 | 43 | public slots: 44 | 45 | }; 46 | 47 | #endif // BSHARE_VIEWPORT_HPP 48 | -------------------------------------------------------------------------------- /bitsharesgui/bshare_viewports/bshare_viewport_mail.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BSHARE_VIEWPORT_MAIL_HPP 2 | #define BSHARE_VIEWPORT_MAIL_HPP 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class bshare_viewport_mail : public QWidget 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit bshare_viewport_mail(QWidget *parent = 0); 17 | private: 18 | QGridLayout * layout; 19 | 20 | //To 21 | QLabel * to_label; 22 | //HBoxLayout (Hints the input to stretch horizontally) 23 | QWidget * to_input_container_widget; 24 | QHBoxLayout * to_input_container; 25 | 26 | QLineEdit * to_input; 27 | 28 | //From 29 | QLabel * from_label; 30 | QLineEdit * from_input; 31 | 32 | //Subject 33 | QLabel * subject_label; 34 | QLineEdit * subject_input; 35 | 36 | //Body (Rich text editor functionality) 37 | QTextEdit * message_input; 38 | 39 | 40 | signals: 41 | 42 | public slots: 43 | 44 | }; 45 | 46 | #endif // BSHARE_VIEWPORT_MAIL_HPP 47 | -------------------------------------------------------------------------------- /bitsharesgui/chatwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef CHATWIDGET_H 2 | #define CHATWIDGET_H 3 | 4 | //DLN only include one of these 5 | #include "selfsizingwidget.h" 6 | //#include "selfsizingmainwindow.h" 7 | #include 8 | 9 | class StringListModel : public QStringListModel 10 | { 11 | public: 12 | StringListModel(QObject* parent) : QStringListModel(parent) {} 13 | void append(const QString& string) 14 | { 15 | insertRows(rowCount(), 1); 16 | setData(index(rowCount()-1), string); 17 | } 18 | 19 | StringListModel& operator<<(const QString& string) 20 | { 21 | append(string); 22 | return *this; 23 | } 24 | }; 25 | 26 | 27 | namespace Ui { 28 | class ChatWidget; 29 | } 30 | 31 | class ChatWidget : public SelfSizingWidget 32 | { 33 | Q_OBJECT 34 | //identity 35 | //contact 36 | //communication data 37 | //session message history (list model) 38 | public: 39 | explicit ChatWidget(QWidget *parent = 0); 40 | ~ChatWidget(); 41 | 42 | void setContact(QString contactName); 43 | bool eventFilter(QObject *watched, QEvent *e); 44 | 45 | private slots: 46 | void sendCurrentChatMessage(); 47 | void sendChatMessage(QString messageToSend); 48 | void messageReceived(QString receivedMessage); 49 | private: 50 | 51 | 52 | Ui::ChatWidget *ui; 53 | StringListModel* chatViewModel; 54 | }; 55 | 56 | #endif // CHATWIDGET_H 57 | -------------------------------------------------------------------------------- /bitsharesgui/chatwidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ChatWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Chat 23 | 24 | 25 | 26 | 27 | 28 | 29 | Qt::Vertical 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /bitsharesgui/images/pencil_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xenland/BitShares/f8d5bf4ef0517fd566119c2f8daf7776b0be00aa/bitsharesgui/images/pencil_small.png -------------------------------------------------------------------------------- /bitsharesgui/main.cpp: -------------------------------------------------------------------------------- 1 | #if 1 2 | #include "bitsharesmainwindow.h" 3 | #else 4 | #include "bshare_gui.h" 5 | #endif 6 | #include 7 | #include 8 | #include 9 | 10 | int main(int argc, char *argv[]) 11 | { 12 | QApplication application(argc, argv); 13 | #if 1 14 | BitSharesMainWindow mainWindow; 15 | mainWindow.show(); 16 | #else 17 | bshare_gui bshare_window; 18 | bshare_window.setWindowTitle("Bitshares | Invictus Innovations"); 19 | bshare_window.show(); 20 | qDebug() << "RUNNING"; 21 | fc::usleep( fc::microseconds(1000) ); 22 | #endif 23 | return application.exec(); 24 | } 25 | -------------------------------------------------------------------------------- /bitsharesgui/profileeditor.cpp: -------------------------------------------------------------------------------- 1 | #include "profileeditor.h" 2 | #include "ui_profileeditor.h" 3 | 4 | ProfileEditor::ProfileEditor(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::ProfileEditor) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | ProfileEditor::~ProfileEditor() 12 | { 13 | delete ui; 14 | } 15 | -------------------------------------------------------------------------------- /bitsharesgui/profileeditor.h: -------------------------------------------------------------------------------- 1 | #ifndef PROFILEEDITOR_H 2 | #define PROFILEEDITOR_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class ProfileEditor; 8 | } 9 | 10 | class ProfileEditor : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit ProfileEditor(QWidget *parent = 0); 16 | ~ProfileEditor(); 17 | 18 | private: 19 | Ui::ProfileEditor *ui; 20 | }; 21 | 22 | #endif // PROFILEEDITOR_H 23 | -------------------------------------------------------------------------------- /bitsharesgui/profileeditor.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ProfileEditor 6 | 7 | 8 | 9 | 0 10 | 0 11 | 400 12 | 300 13 | 14 | 15 | 16 | Dialog 17 | 18 | 19 | 20 | 21 | 30 22 | 240 23 | 341 24 | 32 25 | 26 | 27 | 28 | Qt::Horizontal 29 | 30 | 31 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | buttonBox 40 | accepted() 41 | ProfileEditor 42 | accept() 43 | 44 | 45 | 248 46 | 254 47 | 48 | 49 | 157 50 | 274 51 | 52 | 53 | 54 | 55 | buttonBox 56 | rejected() 57 | ProfileEditor 58 | reject() 59 | 60 | 61 | 316 62 | 260 63 | 64 | 65 | 286 66 | 274 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /bitsharesgui/selfsizingmainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "selfsizingmainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | SelfSizingMainWindow::SelfSizingMainWindow(QWidget *parent) : 8 | QMainWindow(parent) 9 | { 10 | } 11 | 12 | // this should be called in constructor of derived classes after call to setupUi 13 | void SelfSizingMainWindow::readSettings() 14 | { 15 | QSettings settings("Invictus Innovations","BitSharesGUI"); 16 | settings.beginGroup(windowTitle()); 17 | restoreGeometry(settings.value("geometry").toByteArray()); 18 | restoreState(settings.value("state").toByteArray(),VERSIONNUM); 19 | settings.endGroup(); 20 | } 21 | 22 | void SelfSizingMainWindow::writeSettings() 23 | { 24 | QSettings settings("Invictus Innovations","BitSharesGUI"); 25 | settings.beginGroup(windowTitle()); 26 | settings.setValue("geometry", saveGeometry()); 27 | settings.setValue("state", saveState(VERSIONNUM)); 28 | settings.endGroup(); 29 | } 30 | 31 | void SelfSizingMainWindow::closeEvent(QCloseEvent *event) 32 | { 33 | if (okToContinue()) 34 | { 35 | writeSettings(); 36 | event->accept(); 37 | } 38 | else 39 | { 40 | event->ignore(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /bitsharesgui/selfsizingmainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef SELFSIZINGMAINWINDOW_H 2 | #define SELFSIZINGMAINWINDOW_H 3 | 4 | #include 5 | 6 | class SelfSizingMainWindow : public QMainWindow 7 | { 8 | Q_OBJECT 9 | 10 | protected: 11 | virtual void readSettings(); 12 | virtual void writeSettings(); 13 | virtual void closeEvent(QCloseEvent *event); 14 | virtual bool okToContinue() { return true; } 15 | 16 | public: 17 | explicit SelfSizingMainWindow(QWidget *parent = 0); 18 | 19 | signals: 20 | 21 | public slots: 22 | 23 | }; 24 | 25 | #endif // SELFSIZINGMAINWINDOW_H 26 | -------------------------------------------------------------------------------- /bitsharesgui/selfsizingwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "selfsizingwidget.h" 2 | #include 3 | #include 4 | 5 | SelfSizingWidget::SelfSizingWidget(QWidget *parent) : 6 | QWidget(parent) 7 | { 8 | } 9 | 10 | // this should be called in constructor of derived classes after call to setupUi 11 | void SelfSizingWidget::readSettings() 12 | { 13 | QSettings settings("Invictus Innovations","BitSharesGUI"); 14 | settings.beginGroup(windowTitle()); 15 | restoreGeometry(settings.value("geometry").toByteArray()); 16 | settings.endGroup(); 17 | } 18 | 19 | void SelfSizingWidget::writeSettings() 20 | { 21 | QSettings settings("Invictus Innovations","BitSharesGUI"); 22 | settings.beginGroup(windowTitle()); 23 | settings.setValue("geometry", saveGeometry()); 24 | settings.endGroup(); 25 | } 26 | 27 | void SelfSizingWidget::closeEvent(QCloseEvent *event) 28 | { 29 | if (okToContinue()) 30 | { 31 | writeSettings(); 32 | event->accept(); 33 | } 34 | else 35 | { 36 | event->ignore(); 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /bitsharesgui/selfsizingwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SELFSIZINGWIDGET_H 2 | #define SELFSIZINGWIDGET_H 3 | 4 | #include 5 | 6 | class SelfSizingWidget : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | protected: 11 | virtual void readSettings(); 12 | virtual void writeSettings(); 13 | virtual void closeEvent(QCloseEvent *event); 14 | virtual bool okToContinue() { return true; } 15 | 16 | public: 17 | explicit SelfSizingWidget(QWidget *parent = 0); 18 | 19 | signals: 20 | 21 | public slots: 22 | 23 | }; 24 | 25 | #endif // SELFSIZINGWIDGET_H 26 | -------------------------------------------------------------------------------- /bitsharesgui/ui_profileeditor.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************** 2 | ** Form generated from reading UI file 'profileeditor.ui' 3 | ** 4 | ** Created by: Qt User Interface Compiler version 5.1.1 5 | ** 6 | ** WARNING! All changes made in this file will be lost when recompiling UI file! 7 | ********************************************************************************/ 8 | 9 | #ifndef UI_PROFILEEDITOR_H 10 | #define UI_PROFILEEDITOR_H 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | QT_BEGIN_NAMESPACE 21 | 22 | class Ui_ProfileEditor 23 | { 24 | public: 25 | QDialogButtonBox *buttonBox; 26 | 27 | void setupUi(QDialog *ProfileEditor) 28 | { 29 | if (ProfileEditor->objectName().isEmpty()) 30 | ProfileEditor->setObjectName(QStringLiteral("ProfileEditor")); 31 | ProfileEditor->resize(400, 300); 32 | buttonBox = new QDialogButtonBox(ProfileEditor); 33 | buttonBox->setObjectName(QStringLiteral("buttonBox")); 34 | buttonBox->setGeometry(QRect(30, 240, 341, 32)); 35 | buttonBox->setOrientation(Qt::Horizontal); 36 | buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); 37 | 38 | retranslateUi(ProfileEditor); 39 | QObject::connect(buttonBox, SIGNAL(accepted()), ProfileEditor, SLOT(accept())); 40 | QObject::connect(buttonBox, SIGNAL(rejected()), ProfileEditor, SLOT(reject())); 41 | 42 | QMetaObject::connectSlotsByName(ProfileEditor); 43 | } // setupUi 44 | 45 | void retranslateUi(QDialog *ProfileEditor) 46 | { 47 | ProfileEditor->setWindowTitle(QApplication::translate("ProfileEditor", "Dialog", 0)); 48 | } // retranslateUi 49 | 50 | }; 51 | 52 | namespace Ui { 53 | class ProfileEditor: public Ui_ProfileEditor {}; 54 | } // namespace Ui 55 | 56 | QT_END_NAMESPACE 57 | 58 | #endif // UI_PROFILEEDITOR_H 59 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | cmake -G "Visual Studio 11" -------------------------------------------------------------------------------- /cli_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable( cli_client main.cpp ) 2 | target_link_libraries( cli_client upnpc-static bshare fc leveldb ${BOOST_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ) 3 | -------------------------------------------------------------------------------- /coding_standards.md: -------------------------------------------------------------------------------- 1 | General Coding Standards 2 | ================ 3 | - 3 spaces instead of tabs 4 | - all c++ headers end in .hpp 5 | - all c headers end in .h 6 | - pragma once instead of header guards 7 | - use private implementation classes for long-lived objects 8 | - long-lived objects are anything that could be allocated on the heap without 9 | significant overhead. Not temporaries or 'structs'. 10 | 11 | Example of using private implementation: 12 | 13 | namespace detail { class_name_impl; } 14 | class class_name 15 | { 16 | public: 17 | class_name(); 18 | ~class_name(); 19 | 20 | private: 21 | std::unique_ptr my; 22 | }; 23 | 24 | This should be used anytime where the private members would require an additional include 25 | dependency not required by the public API. 26 | 27 | 28 | - note the formatting of the class, braces, indentions, etc. 29 | - avoid abreviations as much as possible 30 | - const std::string& x (not const string &x) 31 | - char* y (not char *y) 32 | - always use {} for conditionals and loops. 33 | 34 | Here is an example of proper usage of braces: 35 | 36 | while( true ) 37 | { 38 | } 39 | 40 | try { 41 | 42 | } 43 | catch ( ... ) 44 | { 45 | } 46 | 47 | switch( x ) 48 | { 49 | case a: 50 | break; 51 | case b: 52 | { 53 | int local = 0; 54 | break; 55 | } 56 | default: 57 | break; 58 | } 59 | 60 | GUI Coding Standards 61 | -------------------- 62 | The following list includes is an example of high-level standard. 63 | 64 | - follow the Qt conventions 65 | - ClassName 66 | - methodName 67 | - _member_variable 68 | - local_varaible 69 | - ClassName.hpp 70 | - ClassName.cpp 71 | - No namespaces unless creating a GUI library 72 | 73 | 74 | 75 | 76 | Library Coding Standards 77 | ------------------------ 78 | All classes within a library are namespaced. 79 | 80 | - follow stdlib and boost naming convention (generally) 81 | - class_name 82 | - set_method_name 83 | - _member_variable 84 | - local_variable 85 | 86 | -------------------------------------------------------------------------------- /configs/a.json: -------------------------------------------------------------------------------- 1 | { 2 | "data_dir": "data/aa", 3 | "server_config": { 4 | "port": 9876, 5 | "chain": "", 6 | "bootstrap_endpoints": [], 7 | "blacklist": [] 8 | }, 9 | "bitname_config": { 10 | "data_dir": "data/aa", 11 | "max_mining_effort": 1 12 | }, 13 | "rpc_config": { 14 | "port": 6789, 15 | "user": "rpc_user", 16 | "pass": "rpc_pass" 17 | }, 18 | "ids": [{ 19 | "label": "dan", 20 | "key": "c7714b9021d9ec9078a58012e164f163a5228721164c68059dff61ad566a3b0b", 21 | "broadcast": "1eeb411196ba463fadccd460d254d54e343f21fe01493e4bddecd025e22d7caa", 22 | "recv_channels": [ 23 | 0 24 | ] 25 | },{ 26 | "label": "stan", 27 | "key": "9a7821bf393904e39999e5cc600d424177680327efc11e7858c29f88ef70a201", 28 | "broadcast": "34822a38bbdf80af0c72f1ea50f7946fa5c518f780ed804d7c0ab20c96c3d50b", 29 | "recv_channels": [ 30 | 0 31 | ] 32 | },{ 33 | "label": "mkdali", 34 | "key": "08cd0cef10069d250343884aa5fd4b55c03ca1dd14e22e56376c62b6ad190efd", 35 | "broadcast": "9ad09e5a5f7f8bb13b90cd3a46d71b389a9b3a9585eac88c9c48614ec810f39a", 36 | "recv_channels": [ 37 | 0 38 | ] 39 | } 40 | ], 41 | "contacts": [{ 42 | "label": "scott", 43 | "key": "02ee9f61b6c3f71d6887efb0678aa0cd2c73bb825ab5197649b98d80d5c6022ccc", 44 | "recv_broadcast": null, 45 | "send_channels": [ 46 | 0 47 | ] 48 | },{ 49 | "label": "trish", 50 | "key": "026ff2741e8827ad4c73c37bdd333df94a1493aa95429f1d1b92aac5163dfbcc62", 51 | "recv_broadcast": null, 52 | "send_channels": [ 53 | 0 54 | ] 55 | } 56 | ] 57 | } -------------------------------------------------------------------------------- /configs/b.json: -------------------------------------------------------------------------------- 1 | { 2 | "data_dir": "data/bb", 3 | "server_config": { 4 | "port": 9877, 5 | "chain": "", 6 | "bootstrap_endpoints": [], 7 | "blacklist": [] 8 | }, 9 | "bitname_config": { 10 | "data_dir": "data/bb", 11 | "max_mining_effort": 1 12 | }, 13 | "rpc_config": { 14 | "port": 5789, 15 | "user": "rpc_user", 16 | "pass": "rpc_pass" 17 | }, 18 | "ids": [{ 19 | "label": "scott", 20 | "key": "ba85dd2da5d908ff677042adfbff779853fd44cc246ccdaf45c6e9730fbe6e81", 21 | "broadcast": "2d29a97188fcb258450fbb83ddb03053cbdfd5361ec57cf08ed010935b0bd804", 22 | "recv_channels": [ 23 | 0 24 | ] 25 | },{ 26 | "label": "scott2", 27 | "key": "5f74816e700996a49a1e716d57dc3754adeaa1ed37aeef1b6cc497381d20034e", 28 | "broadcast": "82f2b99a1f8fe7f85beb9d1a30c895245aacfa2d2495a66528a7381d05692574", 29 | "recv_channels": [ 30 | 0 31 | ] 32 | } 33 | ], 34 | "contacts": [{ 35 | "label": "dan", 36 | "key": "03ad7290bace92ee96d05cd3e2b1049c6dfe078fa603dc12aa17bad23cc125803f", 37 | "recv_broadcast": null, 38 | "send_channels": [ 39 | 0 40 | ] 41 | } 42 | ] 43 | } -------------------------------------------------------------------------------- /configs/c.json: -------------------------------------------------------------------------------- 1 | { 2 | "server_config": { 3 | "port": 9878, 4 | "chain": "", 5 | "bootstrap_endpoints": [], 6 | "blacklist": [] 7 | }, 8 | "rpc_config": { 9 | "port": 8789, 10 | "user": "rpc_user", 11 | "pass": "rpc_pass" 12 | }, 13 | "ids": [{ 14 | "label": "trish", 15 | "key": "69a20e1989844781c43195af281db99b0b184cde3922d77f5f24faa35beaa062", 16 | "broadcast": "0af4827159be57dbce42e7575d9a4abffe420f3ddc6bc92aac49653587e367c7", 17 | "recv_channels": [ 18 | 0 19 | ] 20 | } 21 | ], 22 | "contacts": [{ 23 | "label": "dan", 24 | "key": "03ad7290bace92ee96d05cd3e2b1049c6dfe078fa603dc12aa17bad23cc125803f", 25 | "recv_broadcast": null, 26 | "send_channels": [ 27 | 0 28 | ] 29 | },{ 30 | "label": "scott", 31 | "key": "02ee9f61b6c3f71d6887efb0678aa0cd2c73bb825ab5197649b98d80d5c6022ccc", 32 | "recv_broadcast": null, 33 | "send_channels": [ 34 | 0 35 | ] 36 | } 37 | ] 38 | } -------------------------------------------------------------------------------- /doc/bitname.dox: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @defgroup bit_id BitID 4 | @brief Provides a name/key block chain. 5 | 6 | @section bit_id_protocol Bit ID Protocol 7 | 8 | BitID uses the standard inventory / fetch broadcast system as 9 | everything else in the BitShares system. When a node first 10 | connects it will send a request for any new valid blocks since 11 | its last connection. The remote node will respond with up to 12 | 1000 headers and an indication of how many more there are. 13 | 14 | These headers will be added to the fork database and any additional 15 | headers will be requested. When the remote node reports that 16 | there are no more new headers, then the client will consult the 17 | fork tree and start downloading and verifing the blocks on the 18 | longest fork and pushing them into the name_db. 19 | 20 | If an error occurs on the name_db push, then the next fork in 21 | the fork_db chain is attempted provided its difficulty is 22 | greater than the current name_db head. 23 | 24 | While we are synchronizing with the network we do not participate 25 | in the broadcast of new names because we are unable to validate 26 | them. 27 | */ 28 | -------------------------------------------------------------------------------- /doc/mainpage.dox: -------------------------------------------------------------------------------- 1 | /** 2 | @mainpage BitShares 3 | 4 | BitShares is a new dividend-paying crypto-asset known as a polymorphic digital 5 | asset that facilitates hedging against price fluxuations in other assets such 6 | as gold, silver, and dollars. 7 | 8 | This project is divided into two parts: 9 | 10 |
  1. libBitShares - which implements the a 11 | reusable toolkit to enable the development of a wide variety of BitShares 12 | enabled applications.
  2. 13 |
  3. BitShares - which provides a fully function client to the BitShares 14 | network
  4. 15 |
16 | 17 | @section design_principles Design Principles 18 | 19 | libBitShares is targeted for high performance and reusability and borrows many of the 20 | design principles employed by libbitcoin (http://libbitcoin.dyne.org). Specifically, 21 | it is designed to be asynchronous and yet easy to follow. 22 | 23 | -# Scalability - The library should facilitate the development of applications that scale to thousands of concurrent opperations. 24 | -# Intuitive - The library should model concepts in a clear and intuitive manner. 25 | -# Layered - The library should support development of higher-level APIs 26 | -# No Blocking - There should be no blocking except at the lowest level. 27 | 28 | libBitShares is implementing a financial system that requires a high degree of stability and 29 | correctness. These are requirements that can be designed into the development process to ensure 30 | that the resulting code is as free from bugs as possible. 31 | 32 | -# Simplicity. It is very important for the implementation to be simple and easy to follow. 33 | -# Consistant. It is very important to follow consistant design patterns and avoid special cases. 34 | -# Testable. It is very important for as many components in the system to be independently testable as possible 35 | -# Robust. Errors should be detected, handled, and logged in a robust and meaninful manner. All assumptions, 36 | must be documented and checked 37 | -# Documented. All code must be intential and have a purpose and this purpose should be documented. 38 | 39 | @section development_process Development Process 40 | 41 | 42 | 43 | 44 | */ 45 | -------------------------------------------------------------------------------- /include/bts/address.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | namespace bts 9 | { 10 | /** 11 | * @brief encapsulates an encoded, checksumed public key in 12 | * binary form. It can be converted to base58 for display 13 | * or input purposes and can also be constructed from an ecc 14 | * public key. 15 | * 16 | * An valid address is 20 bytes with the following form: 17 | * 18 | * First 3-bits are 0, followed by bits to 3-127 of sha256(pub_key), followed 19 | * a 32 bit checksum calculated as the first 32 bits of the sha256 of 20 | * the first 128 bits of the address. 21 | * 22 | * The result of this is an address that can be 'verified' by 23 | * looking at the first character (base58) and has a built-in 24 | * checksum to prevent mixing up characters. 25 | * 26 | * It is stored as 20 bytes. 27 | */ 28 | struct address 29 | { 30 | address(); ///< constructs empty / null address 31 | address( const std::string& base58str ); ///< converts to binary, validates checksum 32 | address( const fc::ecc::public_key& pub ); ///< converts to binary 33 | 34 | bool is_valid()const; 35 | 36 | operator std::string()const; ///< converts to base58 + checksum 37 | 38 | fc::array addr; ///< binary representation of address 39 | }; 40 | 41 | 42 | inline bool operator == ( const address& a, const address& b ) { return a.addr == b.addr; } 43 | inline bool operator != ( const address& a, const address& b ) { return a.addr != b.addr; } 44 | inline bool operator < ( const address& a, const address& b ) { return a.addr < b.addr; } 45 | 46 | } // namespace bts 47 | 48 | FC_REFLECT( bts::address, (addr) ) 49 | 50 | namespace fc 51 | { 52 | void to_variant( const bts::address& var, fc::variant& vo ); 53 | void from_variant( const fc::variant& var, bts::address& vo ); 54 | } 55 | 56 | namespace std 57 | { 58 | template<> 59 | struct hash 60 | { 61 | public: 62 | size_t operator()(const bts::address &a) const 63 | { 64 | size_t s; 65 | memcpy( (char*)&s, &a.addr.data[sizeof(a)-sizeof(s)], sizeof(s) ); 66 | return s; 67 | } 68 | }; 69 | } 70 | -------------------------------------------------------------------------------- /include/bts/addressbook/addressbook.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace fc { class path; } 6 | 7 | namespace bts { namespace addressbook { 8 | 9 | namespace detail { class addressbook_impl; } 10 | 11 | /** 12 | * Provides indexes for effecient lookup of contacts 13 | * and abstracts the storage of the addressbook on 14 | * disk. 15 | */ 16 | class addressbook 17 | { 18 | public: 19 | addressbook(); 20 | ~addressbook(); 21 | 22 | void open( const fc::path& abook_dir ); 23 | 24 | /** 25 | * @return a list of all known bitname_label's that can be used to lookup 26 | * contacts. 27 | */ 28 | std::vector get_known_bitnames()const; 29 | 30 | fc::optional get_contact_by_bitname( const std::string& bitname_label )const; 31 | std::string get_bitname_by_address( const bts::address& bitname_address )const; 32 | void store_contact( const contact& contact_to_store ); 33 | 34 | private: 35 | std::unique_ptr my; 36 | }; 37 | 38 | typedef std::shared_ptr addressbook_ptr; 39 | 40 | } } // bts::addressbook 41 | -------------------------------------------------------------------------------- /include/bts/addressbook/contact.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace bts { namespace addressbook { 5 | 6 | /** 7 | * Ultimately this class is used to manage all information 8 | * known about an individual contact. 9 | */ 10 | struct contact 11 | { 12 | contact() 13 | :version(0),next_send_trx_id(0){} 14 | 15 | /** just incase we update the contact datafields 16 | * in future versions. 17 | **/ 18 | uint32_t version; 19 | 20 | std::string first_name; 21 | std::string last_name; 22 | std::string company; 23 | 24 | /** bitname used by this contact (should line up with send_msg_address */ 25 | std::string bitname_id; 26 | 27 | /** Key used to encode private messages sent to this contact */ 28 | fc::ecc::public_key send_msg_address; 29 | /** channels this contact is expected to be listening on */ 30 | std::vector send_msg_channels; 31 | 32 | /** 33 | * Private key to which broadcast messages are 34 | * sent. 35 | */ 36 | fc::ecc::private_key recv_broadcast_msg_address; 37 | 38 | /** channels on which this contact broadcasts */ 39 | std::vector recv_broadcast_msg_channels; 40 | 41 | /** used to generate adresses for sending funds to this 42 | * contact. 43 | */ 44 | extended_public_key send_trx_address; 45 | 46 | /** 47 | * Incremented everytime a new trx is created to 48 | * this contact. 49 | */ 50 | uint32_t next_send_trx_id; 51 | 52 | /** 53 | * Addresses that this uesr has the private 54 | * keys to. This address is given to the 55 | * contact who can use these keys to 56 | * send us money. 57 | */ 58 | extended_public_key recv_trx_address; 59 | }; 60 | 61 | } } // bts::addressbook 62 | 63 | #include 64 | FC_REFLECT( bts::addressbook::contact, 65 | (version) 66 | (first_name) 67 | (last_name) 68 | (company) 69 | (bitname_id) 70 | (send_msg_address) 71 | (send_msg_channels) 72 | (recv_broadcast_msg_address) 73 | (recv_broadcast_msg_channels) 74 | (send_trx_address) 75 | (recv_trx_address) 76 | ) 77 | 78 | -------------------------------------------------------------------------------- /include/bts/bitchat/bitchat_channel.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace bts { namespace bitchat { 6 | 7 | namespace detail { class channel_impl; } 8 | 9 | class encrypted_message; 10 | 11 | class channel_delegate 12 | { 13 | public: 14 | virtual ~channel_delegate(){} 15 | 16 | virtual void handle_message( const encrypted_message& pm, const network::channel_id& c ) = 0; 17 | 18 | }; 19 | 20 | struct channel_config 21 | { 22 | channel_config( const fc::path& p = fc::path() ) 23 | :data_dir(p){} 24 | 25 | fc::path data_dir; 26 | }; 27 | 28 | /** 29 | * @brief Implements the message broadcast/routing for a single channel. 30 | * 31 | * This class is agnostic to anything but message routing. It does not 32 | * handle private messages nor attempt to decrypt anything, instead it 33 | * manages the bandwidth and passes all messages it receives through 34 | * to the delegate. 35 | */ 36 | class channel 37 | { 38 | public: 39 | channel( const bts::peer::peer_channel_ptr& peers, const network::channel_id& c, channel_delegate* d ); 40 | ~channel(); 41 | 42 | network::channel_id get_id()const; 43 | 44 | void configure( const channel_config& conf ); 45 | 46 | void broadcast( encrypted_message&& m ); 47 | 48 | private: 49 | std::shared_ptr my; 50 | }; 51 | 52 | typedef std::shared_ptr channel_ptr; 53 | 54 | } } // bts::bitchat 55 | -------------------------------------------------------------------------------- /include/bts/bitchat/bitchat_client.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace bts { namespace bitchat 11 | { 12 | namespace detail { class client_impl; } 13 | 14 | class client_delegate 15 | { 16 | public: 17 | virtual void bitchat_message_received( const decrypted_message& m ){} 18 | }; 19 | 20 | /** 21 | * Provides checked conversion of public key to / from bitchat address 22 | * TODO: move this someplace else, this type of address representation 23 | * is only useful for user-facing interfaces, under the hood we just 24 | * deal with public keys. 25 | struct address 26 | { 27 | address( const fc::ecc::public_key& k ); 28 | address( const std::string& a ); 29 | 30 | operator std::string()const; 31 | operator fc::ecc::public_key()const; 32 | 33 | uint32_t check; 34 | fc::ecc::public_key_data key; 35 | }; 36 | */ 37 | 38 | 39 | /** 40 | * Provides a simple chat client that hides both the 41 | * sender and receiver of the message. 42 | * 43 | */ 44 | class client 45 | { 46 | public: 47 | client( const bts::peer::peer_channel_ptr& s, client_delegate* d ); 48 | ~client(); 49 | 50 | void configure( const fc::path& dir ); 51 | 52 | /** sets the private keys that are used to receive incoming messages*/ 53 | void set_receive_keys( const std::vector& recv_keys ); 54 | 55 | void join_channel( uint16_t chan_num ); 56 | void send_message( const decrypted_message& m, const fc::ecc::public_key& to, uint16_t chan = 0); 57 | 58 | private: 59 | std::unique_ptr my; 60 | }; 61 | 62 | typedef std::shared_ptr client_ptr; 63 | } } // bts::bitchat 64 | 65 | 66 | -------------------------------------------------------------------------------- /include/bts/bitchat/bitchat_message_cache.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace bts { namespace bitchat { 6 | 7 | namespace detail { class message_cache_impl; } 8 | 9 | /** 10 | * Caches encrypted messages for up to 1 month. 11 | * Once 'full', messages can be bumped based upon difficulty with the least difficult going first. 12 | */ 13 | class message_cache 14 | { 15 | public: 16 | message_cache(); 17 | ~message_cache(); 18 | 19 | void open( const fc::path& db_dir ); 20 | 21 | void cache( const encrypted_message& msg ); 22 | std::vector get_inventory( const fc::time_point& start_time, const fc::time_point& end_time ); 23 | 24 | private: 25 | std::unique_ptr my; 26 | }; 27 | 28 | 29 | 30 | } } // bts::bitchat 31 | -------------------------------------------------------------------------------- /include/bts/bitchat/bitchat_messages.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace bts { namespace bitchat { 5 | 6 | // other protocol messages... not encapsulated by data_message 7 | struct inv_message 8 | { 9 | static const message_type type = message_type::inv_msg; 10 | std::vector items; 11 | }; 12 | 13 | struct get_priv_message 14 | { 15 | static const message_type type = message_type::get_priv_msg; 16 | get_priv_message(){} 17 | get_priv_message( const fc::uint128& p ) 18 | { 19 | items.push_back(p); 20 | } 21 | std::vector items; 22 | }; 23 | 24 | /** 25 | * Used to request all inventory after the given time. 26 | */ 27 | struct get_inv_message 28 | { 29 | static const message_type type = message_type::get_inv_msg; 30 | fc::time_point_sec after; 31 | }; 32 | 33 | } } // bts::bitchat 34 | 35 | FC_REFLECT( bts::bitchat::inv_message, (items) ) 36 | FC_REFLECT( bts::bitchat::get_priv_message, (items) ) 37 | FC_REFLECT( bts::bitchat::get_inv_message, (after) ) 38 | -------------------------------------------------------------------------------- /include/bts/bitname/bitname_hash.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace bts { namespace bitname { 4 | 5 | /** 6 | * Performs a hash on n that will generate collisions for names 7 | * that look similar in some fonts / cases. For example the 8 | * following strings would generate collisions: 9 | * 10 | * GN00B, 6MOO8, gmoob 11 | * rin, njm 12 | */ 13 | uint64_t name_hash( const std::string& n ); 14 | 15 | } } 16 | -------------------------------------------------------------------------------- /include/bts/bitname/bitname_record.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace bts { namespace bitname { 6 | 7 | /** 8 | * Summary information about a name registered on the 9 | * bitname blockchain. 10 | */ 11 | struct name_record 12 | { 13 | name_record() 14 | :revoked(false),age(0),repute(0){} 15 | 16 | /** handle to/from hex conversion */ 17 | uint64_t get_name_hash()const; 18 | void set_name_hash( uint64_t h ); 19 | 20 | fc::time_point_sec last_update; ///< the most recent update of this name 21 | fc::ecc::public_key_data pub_key; ///< the public key paired to this name. 22 | bool revoked; ///< this name has been canceled, by its owner (invalidating the public key) 23 | uint32_t age; ///< first block this name was registered in 24 | uint32_t repute; ///< how many repute points have been earned by this name 25 | std::string name_hash; ///< the unique hash assigned to this name, in hex format 26 | fc::optional name; ///< if we know the name that generated the hash 27 | }; 28 | 29 | } } // bts::bitname 30 | 31 | #include 32 | FC_REFLECT( bts::bitname::name_record, 33 | (last_update) 34 | (pub_key) 35 | (revoked) 36 | (age) 37 | (repute) 38 | (name_hash) 39 | (name) 40 | ) 41 | -------------------------------------------------------------------------------- /include/bts/blockchain/blockchain_market_db.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace bts { namespace blockchain { 8 | 9 | namespace detail { class market_db_impl; } 10 | 11 | /** 12 | * Bids: (offers to buy Base Unit with Quote Unit) 13 | * Quote Unit, Base Unit Price UnspentOutput 14 | * 15 | * Asks: (offers to sell Base Unit for Quote Unit ) includes open short orders when BaseUnit = BTS) 16 | * Quote Unit, Base Unit Price UnspentOutput 17 | * 18 | */ 19 | struct market_order 20 | { 21 | market_order( const price& p, const output_reference& loc ); 22 | market_order(){} 23 | asset_type base_unit; 24 | asset_type quote_unit; 25 | fc::uint128_t ratio; // 64.64 26 | output_reference location; 27 | 28 | price get_price()const; 29 | }; 30 | bool operator < ( const market_order& a, const market_order& b ); 31 | bool operator == ( const market_order& a, const market_order& b ); 32 | 33 | /** 34 | * Manages the current state of the market to enable effecient 35 | * pairing of the highest bid with the lowest ask. 36 | */ 37 | class market_db 38 | { 39 | public: 40 | market_db(); 41 | ~market_db(); 42 | 43 | void open( const fc::path& db_dir ); 44 | std::vector get_bids( asset::type quote_unit, asset::type base_unit )const; 45 | std::vector get_asks( asset::type quote_unit, asset::type base_unit )const; 46 | 47 | void insert_bid( const market_order& m ); 48 | void insert_ask( const market_order& m ); 49 | void remove_bid( const market_order& m ); 50 | void remove_ask( const market_order& m ); 51 | 52 | /** @pre quote > base */ 53 | fc::optional get_highest_bid( asset::type quote, asset::type base ); 54 | /** @pre quote > base */ 55 | fc::optional get_lowest_ask( asset::type quote, asset::type base ); 56 | 57 | private: 58 | std::unique_ptr my; 59 | }; 60 | 61 | } } // bts::blockchain 62 | 63 | FC_REFLECT( bts::blockchain::market_order, (base_unit)(quote_unit)(ratio)(location) ); 64 | -------------------------------------------------------------------------------- /include/bts/blockchain/blockchain_printer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace bts { namespace blockchain { 5 | 6 | std::string pretty_print( const trx_block& b, blockchain_db& db ); 7 | 8 | } } 9 | -------------------------------------------------------------------------------- /include/bts/blockchain/proof.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace bts { namespace blockchain { 6 | 7 | /** 8 | * @brief Data that is paired with 9 | */ 10 | struct proof 11 | { 12 | proof() 13 | :branch_path(),nonce(0){} 14 | 15 | /** 16 | * Does not include the leaf_hash which must be passed to the 17 | * merkle_root() method to properly reconstruct the merkle root. 18 | * 19 | * The leaf is not included in this struct because it can always be 20 | * calculated from the header and it is helpful to avoid an extra 21 | * 28 bytes. 22 | * 23 | * Includes the full merkle branch to the hash of the header. 24 | */ 25 | merkle_branch branch_path; 26 | uint32_t nonce; 27 | }; 28 | 29 | } } // bts::blockchain 30 | 31 | FC_REFLECT( bts::blockchain::proof, (branch_path)(nonce) ) 32 | -------------------------------------------------------------------------------- /include/bts/db/fwd.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace bts { namespace db { 5 | 6 | class peer; 7 | typedef std::shared_ptr peer_ptr; 8 | 9 | class peer_ram; 10 | typedef std::shared_ptr peer_ram_ptr; 11 | 12 | }} // namespace bts::db 13 | -------------------------------------------------------------------------------- /include/bts/db/peer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace bts { namespace db 11 | { 12 | /** 13 | * @brief abstracts the interface to the peer database 14 | * 15 | * There may be multiple backends for storing IP/Port/stats 16 | * for various peers in the network. This interface 17 | * abstracts that process. 18 | */ 19 | class peer 20 | { 21 | public: 22 | virtual ~peer(){} 23 | 24 | struct record 25 | { 26 | record():failures(0){} 27 | 28 | fc::ip::endpoint contact; 29 | fc::time_point last_com; 30 | uint32_t failures; 31 | std::set channels; 32 | std::unordered_set features; 33 | }; 34 | 35 | virtual void store( const record& r ) = 0; 36 | virtual void remove( const fc::ip::endpoint& ep ) = 0; 37 | virtual void update_last_com( const fc::ip::endpoint& ep, 38 | const fc::time_point& ) = 0; 39 | 40 | virtual record fetch( const fc::ip::endpoint& ep )const = 0; 41 | virtual std::vector get_all_peers()const = 0; 42 | virtual std::vector get_peers_on_channel( const network::channel_id& cid )const = 0; 43 | virtual std::vector get_peers_with_feature( const std::string& s )const = 0; 44 | 45 | }; 46 | typedef std::shared_ptr peer_ptr; 47 | 48 | 49 | } } // namespace bts::db 50 | 51 | #include 52 | FC_REFLECT( bts::db::peer::record, 53 | (contact) 54 | (last_com) 55 | (failures) 56 | (channels) 57 | (features) ) 58 | -------------------------------------------------------------------------------- /include/bts/difficulty.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace bts 6 | { 7 | 8 | /** 9 | * Calculates the difficulty of hash as 10 | * 11 | * (max224() / hash) >> 24 12 | */ 13 | uint64_t difficulty( const fc::sha224& hash_value ); 14 | 15 | /** return 2^224 -1 */ 16 | const fc::bigint& max224(); 17 | 18 | } // namespace bts 19 | -------------------------------------------------------------------------------- /include/bts/merkle_tree.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace bts { 6 | 7 | /** 8 | * Provides a merkle branch that proves a hash was 9 | * included in the root. 10 | */ 11 | struct merkle_branch 12 | { 13 | merkle_branch() 14 | :branch(0){} 15 | 16 | uint160 calculate_root()const; 17 | 18 | uint32_t branch; 19 | std::vector mid_states; 20 | }; 21 | 22 | /** 23 | * Maintains a merkle tree as updates are made via 24 | * get/set. 25 | */ 26 | struct merkle_tree 27 | { 28 | void resize( uint64_t s ); 29 | uint64_t size(); 30 | 31 | /** 32 | * Updates all hashes in the merkle branch to index. 33 | * @throw out_of_range_exception if index > size 34 | */ 35 | void set( uint64_t index, const uint160& val ); 36 | 37 | /** 38 | * @throw out_of_range_exception if index > size 39 | */ 40 | uint160 get( uint32_t index ); 41 | 42 | /** 43 | * @return the full merkle branch for the tree. 44 | */ 45 | merkle_branch get_branch( uint32_t index )const; 46 | 47 | /** 48 | * @note do not modify this field directly, it will 49 | * automatically be updated after every call to 50 | * set / get. 51 | */ 52 | uint160 mroot; 53 | 54 | /** 55 | * mtree[0] is the leef layer of the tree 56 | * mtree[mtree.size()-1].size() should always be 2 57 | * 58 | * @note only modify this via get/set to keep the 59 | * struture accurate. This is public for 60 | * serialization purposes only. 61 | * 62 | * TODO: update fc::reflect to support private 63 | * members. 64 | */ 65 | std::vector< std::vector < uint160 > > mtree; 66 | }; 67 | 68 | } 69 | #include 70 | FC_REFLECT( bts::merkle_branch, (branch)(mid_states) ) 71 | FC_REFLECT( bts::merkle_tree, (mroot)(mtree) ) 72 | 73 | -------------------------------------------------------------------------------- /include/bts/network/channel.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace bts { namespace network { 6 | 7 | class channel 8 | { 9 | public: 10 | virtual ~channel(){} 11 | 12 | virtual void handle_message( const connection_ptr&, 13 | const message& m ) = 0; 14 | virtual void handle_subscribe( const connection_ptr& c )=0; 15 | virtual void handle_unsubscribe( const connection_ptr& c )=0; 16 | }; 17 | 18 | typedef std::shared_ptr channel_ptr; 19 | 20 | } } 21 | 22 | 23 | -------------------------------------------------------------------------------- /include/bts/network/channel_pow_stats.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace bts { namespace network { 5 | 6 | /** 7 | * Tracks the bandwidth used by a specific channel and calculates 8 | * the average proof-of-work per message to get an idea of what 9 | * is required to broadcast on the network. 10 | * 11 | * If the bandwidth is above the target bandwidth over the last 12 | * 5 minutes then the required proof-of-work for rebroadcast is 13 | * 5% above average, otherwise it is 5% below average. 14 | */ 15 | class channel_pow_stats 16 | { 17 | public: 18 | channel_pow_stats(); 19 | 20 | /** 21 | * Updates the weighted-average bits per microsecond handled by 22 | * a particular channel using the system clock to measure elapsed 23 | * time between calls. 24 | * 25 | * @param bytes_received the bytes received since the last call 26 | * @param msg_pow the proof of work associated with these bytes. 27 | * 28 | * @pre msg_pow < target_pow 29 | * 30 | * @return true if these bytes can be received / processed at the given 31 | * proof of work level. 32 | */ 33 | bool update_bpus_avg( uint64_t bytes_recv, const mini_pow& msg_pow ); 34 | 35 | mini_pow target_pow; 36 | mini_pow average_pow; 37 | uint64_t target_bits_per_usec; 38 | uint64_t avg_bits_per_usec; 39 | fc::time_point last_recv; 40 | }; 41 | 42 | } } 43 | 44 | #include 45 | FC_REFLECT( bts::network::channel_pow_stats, 46 | (target_pow) 47 | (average_pow) 48 | (target_bits_per_usec) 49 | (avg_bits_per_usec) 50 | (last_recv) 51 | ) 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /include/bts/network/feature_id.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace bts { namespace network { 4 | 5 | /** 6 | * Different nodes may support different features that are not necessarily 7 | * associated with channels. Feature IDs allow us to identify these nodes. 8 | */ 9 | enum feature_id 10 | { 11 | unspecified = 0, 12 | kad = 1 /** node participates in a KAD hash table **/ 13 | }; 14 | 15 | } } 16 | 17 | FC_REFLECT_ENUM( bts::network::feature_id, (unspecified)(kad) ) 18 | -------------------------------------------------------------------------------- /include/bts/network/get_public_ip.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace bts { namespace network { 4 | 5 | fc::ip::address get_public_ip(); 6 | 7 | } } 8 | -------------------------------------------------------------------------------- /include/bts/network/stcp_socket.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace bts { namespace network { 7 | 8 | /** 9 | * Uses ECDH to negotiate a blowfish key for communicating 10 | * with other nodes on the network. 11 | */ 12 | class stcp_socket : public virtual fc::iostream 13 | { 14 | public: 15 | stcp_socket(); 16 | ~stcp_socket(); 17 | fc::tcp_socket& get_socket() { return _sock; } 18 | void accept(); 19 | 20 | void connect_to( const fc::ip::endpoint& ep ); 21 | 22 | virtual size_t readsome( char* buffer, size_t max ); 23 | virtual bool eof()const; 24 | 25 | virtual size_t writesome( const char* buffer, size_t len ); 26 | virtual void flush(); 27 | virtual void close(); 28 | 29 | void get( char& c ) { read( &c, 1 ); } 30 | 31 | private: 32 | fc::ecc::private_key _priv_key; 33 | fc::array _buf; 34 | uint32_t _buf_len; 35 | fc::tcp_socket _sock; 36 | fc::aes_encoder _send_aes; 37 | fc::aes_decoder _recv_aes; 38 | }; 39 | 40 | typedef std::shared_ptr stcp_socket_ptr; 41 | 42 | } } // bts::network 43 | -------------------------------------------------------------------------------- /include/bts/network/upnp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace bts { namespace network { 6 | 7 | namespace detail { class upnp_service_impl; } 8 | 9 | class upnp_service 10 | { 11 | public: 12 | upnp_service(); 13 | ~upnp_service(); 14 | 15 | void map_port( uint16_t p ); 16 | private: 17 | std::unique_ptr my; 18 | }; 19 | 20 | } } 21 | -------------------------------------------------------------------------------- /include/bts/peer/peer_channel.hpp: -------------------------------------------------------------------------------- 1 | /** @file peer_channel.hpp 2 | * @brief Defines messages exchanged on the peer/discovery channel (0) 3 | */ 4 | #pragma once 5 | #include 6 | #include 7 | #include 8 | 9 | namespace bts { namespace peer { 10 | 11 | namespace detail { class peer_channel_impl; } 12 | 13 | /** 14 | * Tracks a contact address and the last time it was heard about. 15 | struct host 16 | { 17 | fc::ip::endpoint ep; 18 | fc::time_point_sec last_com; 19 | }; 20 | */ 21 | 22 | /** 23 | * Manages the state of all peers including what channels they 24 | * are connected to and known IPs of hosts that we are not 25 | * connected to. 26 | * 27 | * The peer channel is how the nodes communicate information about 28 | * eachother, their features, and meta information about the channels 29 | * they are subscribed to. 30 | */ 31 | class peer_channel 32 | { 33 | public: 34 | peer_channel( const network::server_ptr& netw ); 35 | ~peer_channel(); 36 | 37 | /** 38 | * broadcasts the new channel subscription to all connected nodes. If less than 39 | * the minimum number of connections exist to this channel, new connections are 40 | * opened. 41 | */ 42 | void subscribe_to_channel( const network::channel_id& chan, const network::channel_ptr& c ); 43 | void unsubscribe_from_channel( const network::channel_id& chan ); 44 | 45 | /** 46 | * @return a list of all known hosts. 47 | */ 48 | std::vector get_known_hosts()const; 49 | 50 | /** 51 | * @return a list of connections subscribed to a particular channel. 52 | */ 53 | std::vector get_connections( const network::channel_id& chan ); 54 | private: 55 | std::shared_ptr my; 56 | }; 57 | 58 | typedef std::shared_ptr peer_channel_ptr; 59 | 60 | 61 | 62 | } } 63 | 64 | //#include 65 | //FC_REFLECT( bts::peer::host, (ep)(last_com) ) 66 | 67 | -------------------------------------------------------------------------------- /include/bts/peer/peer_db.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace bts { namespace peer { 5 | 6 | using network::channel_id; 7 | 8 | 9 | /** 10 | * Maintains a database of peers indexed by age, channels, and features. This 11 | * index is persistant and enables a node to maintain a large set of potential 12 | * bootstrap nodes for future connections and to quickly connect to new channels 13 | * when they need to. 14 | */ 15 | class peer_db 16 | { 17 | public: 18 | peer_db(); 19 | ~peer_db(); 20 | 21 | void open( const fc::path& dbdir, bool create = true ); 22 | void close(); 23 | 24 | /** 25 | * On a fresh startup the entire database is 'out of date' and therefore 26 | * all hosts should be reset to 1 hour old so they can expire if we have 27 | * not heard about them in 2 hours. 28 | */ 29 | void reset_ages( const fc::time_point_sec& s ); 30 | 31 | void store( const host& r ); 32 | host fetch_record( const fc::ip::endpoint& ep ); 33 | 34 | /** Removes a host from the DB, presumably because we attempted to connect 35 | * to it and were unable to. 36 | * 37 | * TODO: how do we prevent purging the entire DB if the internet goes down 38 | * and no hosts are reachable? Perhaps only perge nodes if we are successfully 39 | * connected to other nodes. 40 | */ 41 | void remove( const fc::ip::endpoint& ep ); 42 | 43 | void add_channel( const fc::ip::endpoint& e, const channel_id& c ); 44 | void remove_channel( const fc::ip::endpoint& e, const channel_id& c ); 45 | 46 | std::vector fetch_hosts( const channel_id& c, uint32_t limit = 10 ); 47 | void purge_old( const fc::time_point& age ); 48 | 49 | private: 50 | std::unique_ptr my; 51 | 52 | }; // peer_db 53 | 54 | } } // bts::peer 55 | 56 | FC_REFLECT( bts::peer::host, (ep)(last_com)(first_com)(channels)(features) ) 57 | -------------------------------------------------------------------------------- /include/bts/peer/peer_host.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace bts { namespace peer { 10 | 11 | using network::channel_id; 12 | 13 | /** 14 | * Tracks a contact address and the last time it was heard about. 15 | */ 16 | struct host 17 | { 18 | host( const fc::ip::endpoint& ep, const network::channel_id& c, const fc::time_point_sec& = fc::time_point::now() ); 19 | host(){} 20 | 21 | fc::ip::endpoint ep; 22 | fc::time_point_sec last_com; 23 | 24 | /** 25 | * hosts that we hear about frequently and that never leave our DB are probably long lived nodes 26 | * and thus good candidates for seed hosts... 27 | */ 28 | fc::time_point_sec first_com; // set when a host is added to the database 29 | std::vector channels; // TODO: defien size limit for unpacking these 30 | std::vector< fc::enum_type > features; // TODO: define size limit for unpacking these 31 | }; 32 | 33 | } } // bts::peer 34 | 35 | FC_REFLECT( bts::peer::host, (ep)(last_com)(first_com)(channels)(features) ) 36 | -------------------------------------------------------------------------------- /include/bts/proof_of_work.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace bts { 7 | 8 | /** typedef to the same size */ 9 | typedef fc::ripemd160 pow_hash; 10 | 11 | /** 12 | * The purpose of this method is to generate a determinstic proof-of-work 13 | * that cannot be optimized via ASIC or extreme parallelism. 14 | * 15 | * @param in - initial hash 16 | * @param buffer_128m - 128 MB buffer used for scratch space. 17 | * @return processed hash after doing proof of work. 18 | */ 19 | pow_hash proof_of_work( const fc::sha256& in, unsigned char* buffer_128m ); 20 | pow_hash proof_of_work( const fc::sha256& in ); 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /include/bts/rpc/rpc_server.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace bts { namespace rpc { 5 | 6 | namespace detail { class server_impl; } 7 | 8 | /** 9 | * @brief provides a JSON-RPC interface bitshare components 10 | * 11 | * Before any RPC commands will be processed, the user must call 12 | * the login method and get a valid response. 13 | * 14 | * @code 15 | * { "method":"login", "params":["user","pass"], "id":0 } 16 | * @endcode 17 | * 18 | * TODO: Implement SSL connections, perhaps with CERT requirement 19 | * TODO: Restrict connections to a user-specified interface (ie: loopback) 20 | */ 21 | class server 22 | { 23 | public: 24 | struct config 25 | { 26 | config() 27 | :port(0){} 28 | 29 | uint16_t port; 30 | std::string user; 31 | std::string pass; 32 | }; 33 | 34 | server(); 35 | ~server(); 36 | 37 | void configure( const config& cfg ); 38 | void set_bitname_client( const bts::bitname::client_ptr& name_cl ); 39 | 40 | private: 41 | std::unique_ptr my; 42 | }; 43 | 44 | typedef std::shared_ptr server_ptr; 45 | 46 | } } // bts::rpc 47 | 48 | FC_REFLECT( bts::rpc::server::config, (port)(user)(pass) ) 49 | -------------------------------------------------------------------------------- /include/bts/small_hash.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace bts 5 | { 6 | typedef fc::ripemd160 uint160; 7 | 8 | /** 9 | * Performs ripemd160(seed); 10 | */ 11 | uint160 small_hash( const fc::sha512& seed ); 12 | 13 | /** 14 | * The goal of the small hash is to be secure using as few 15 | * bits as possible. 16 | * 17 | * Performs small_hash( sha512(data,len) ) 18 | */ 19 | uint160 small_hash( const char* data, size_t len ); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /include/bts/units.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace bts 5 | { 6 | 7 | /** 8 | * All balanes are annotated with a unit, each BitShare 9 | * chain supports 8 basic units 10 | */ 11 | enum unit_type 12 | { 13 | BitShares = 0, 14 | BitGold = 1, 15 | BitSilver = 2, 16 | BitUSD = 3, 17 | BitEUR = 4, 18 | BitYUAN = 5, 19 | BitGBP = 6, 20 | BitBTC = 7, 21 | NumUnits 22 | }; 23 | 24 | struct bond_type 25 | { 26 | bond_type():issue_type(BitShares),backing_type(BitShares){} 27 | unit_type issue_type; 28 | unit_type backing_type; 29 | }; 30 | 31 | } // namespace bts 32 | 33 | FC_REFLECT_ENUM( bts::unit_type, 34 | (BitShares) 35 | (BitGold) 36 | (BitSilver) 37 | (BitUSD) 38 | (BitEUR) 39 | (BitYUAN) 40 | (BitGBP) 41 | (BitBTC) 42 | (NumUnits) 43 | ) 44 | 45 | FC_REFLECT( bts::bond_type, (issue_type)(backing_type) ) 46 | 47 | // TODO: define raw pack to 1 byte 48 | 49 | -------------------------------------------------------------------------------- /include/bts/wallet.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace bts 6 | { 7 | /** 8 | * @class wallet 9 | * @brief A deterministic wallet that generates a family of public/private keys. 10 | * 11 | * A wallet can deterministicaly generate a whole family of public / private keys 12 | * given an initial secret value. If only the master public key is given, then 13 | * all other public keys could be generated, however, the private keys could not 14 | * be generated. This makes it easy to have read-only wallets that do not 15 | * require access to the secret. 16 | * 17 | * This wallet class only conserns itself with the generation of the deterministic 18 | * keys and does not implement any storage system or caching. 19 | */ 20 | class wallet 21 | { 22 | public: 23 | wallet(); 24 | ~wallet(); 25 | 26 | /** 27 | * The seed should be the hash of a long pass phrase and not something that 28 | * would end up in a dictionary attack. 29 | */ 30 | void set_seed( const fc::sha256& s, bool stretch = true ); 31 | 32 | /** 33 | * Used to generate public keys without any private keys. 34 | */ 35 | void set_master_public_key( const fc::ecc::public_key& k ); 36 | fc::ecc::public_key get_master_public_key()const; 37 | 38 | /** 39 | * @throws if no seed has been set. 40 | */ 41 | fc::ecc::private_key get_master_private_key()const; 42 | 43 | /** 44 | * @throws if set_seed() or set_master_public_key() has not been called 45 | */ 46 | fc::ecc::public_key get_public_key( uint32_t index ); 47 | 48 | /** 49 | * @throws if no seed has been set. 50 | */ 51 | fc::ecc::private_key get_private_key( uint32_t index ); 52 | 53 | private: 54 | fc::sha256 _stretched_seed; 55 | fc::optional _master_priv; 56 | fc::optional _master_pub; 57 | }; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /keyhotee/AddressBook/AddressBookModel.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Detail { class AddressBookModelImpl; } 6 | 7 | class AddressBookModel : public QAbstractTableModel 8 | { 9 | public: 10 | AddressBookModel( bts::addressbook::addressbook_ptr abook ); 11 | ~AddressBookModel(); 12 | 13 | enum Columns 14 | { 15 | FirstName, 16 | LastName, 17 | Id, 18 | Age, 19 | Repute, 20 | NumColumns 21 | }; 22 | void storeContact( const bts::addressbook::contact& new_contact ); 23 | 24 | virtual int rowCount( const QModelIndex& parent = QModelIndex() )const; 25 | virtual int columnCount( const QModelIndex& parent = QModelIndex() )const; 26 | 27 | virtual bool removeRows( int row, int count, const QModelIndex& parent = QModelIndex() ); 28 | 29 | virtual QVariant headerData( int section, Qt::Orientation o, int role = Qt::DisplayRole )const; 30 | virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole )const; 31 | 32 | private: 33 | std::unique_ptr my; 34 | }; 35 | -------------------------------------------------------------------------------- /keyhotee/AddressBook/ContactsTable.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ContactsTable 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 543 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 0 19 | 20 | 21 | 0 22 | 23 | 24 | 0 25 | 26 | 27 | 0 28 | 29 | 30 | 5 31 | 32 | 33 | 34 | 35 | Qt::Horizontal 36 | 37 | 38 | 39 | 278 40 | 20 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Add Contact 49 | 50 | 51 | 52 | 53 | 54 | 55 | Qt::Vertical 56 | 57 | 58 | 9 59 | 60 | 61 | 62 | true 63 | 64 | 65 | true 66 | 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /keyhotee/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set( CMAKE_INCLUDE_CURRENT_DIR ON) 2 | set( CMAKE_AUTOMOC ON ) 3 | find_package( Qt5Widgets ) 4 | find_package( Qt5WebKitWidgets ) 5 | include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) 6 | 7 | # Only build the Keyhotee gui when we find Qt 8 | IF( NOT Qt5Widgets_DIR MATCHES Qt5Widgets_DIR-NOTFOUND ) 9 | 10 | set( headers 11 | profile_wizard/ProfileWizard.hpp 12 | ) 13 | 14 | qt5_wrap_ui( profile_wizard/UiProfileEditPage profile_wizard/ProfileEditPage.ui ) 15 | qt5_wrap_ui( profile_wizard/UiProfileIntroPage profile_wizard/ProfileIntroPage.ui ) 16 | qt5_wrap_ui( profile_wizard/UiNymPage profile_wizard/ProfileNymPage.ui ) 17 | qt5_wrap_ui( UiLoginDialog LoginDialog.ui ) 18 | qt5_wrap_ui( UiEditContactDialog EditContactDialog.ui ) 19 | qt5_wrap_ui( UiKeyhoteeMainWindow KeyhoteeMainWindow.ui ) 20 | QT5_ADD_RESOURCES( KeyhoteeQRC Keyhotee.qrc ) 21 | 22 | set( sources 23 | Keyhotee.qrc 24 | 25 | profile_wizard/ProfileEditPage.ui 26 | profile_wizard/ProfileIntroPage.ui 27 | profile_wizard/ProfileNymPage.ui 28 | profile_wizard/ProfileWizard.cpp 29 | 30 | AddressBook/AddressBookModel.hpp 31 | AddressBook/AddressBookModel.cpp 32 | 33 | LoginDialog.ui 34 | LoginDialog.cpp 35 | 36 | EditContactDialog.ui 37 | EditContactDialog.cpp 38 | 39 | KeyhoteeMainWindow.ui 40 | KeyhoteeMainWindow.cpp 41 | main.cpp ) 42 | 43 | add_executable( Keyhotee MACOSX_BUNDLE WIN32 ${sources} ) 44 | target_link_libraries( Keyhotee upnpc-static bshare fc leveldb ${BOOST_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} Qt5::Widgets Qt5::WebKitWidgets) 45 | 46 | ENDIF( NOT Qt5Widgets_DIR MATCHES Qt5Widgets_DIR-NOTFOUND ) 47 | -------------------------------------------------------------------------------- /keyhotee/EditContactDialog.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Ui { class EditContactDialog; } 8 | 9 | class EditContactDialog : public QDialog 10 | { 11 | public: 12 | EditContactDialog( QWidget* parent ); 13 | ~EditContactDialog(); 14 | 15 | void validateId( const QString& id ); 16 | void lookupId(); 17 | 18 | void setContact( const bts::addressbook::contact& con ); 19 | bts::addressbook::contact getContact()const; 20 | 21 | private: 22 | std::unique_ptr ui; 23 | bts::addressbook::contact _contact; 24 | bool _complete; 25 | fc::time_point _last_validate; 26 | }; 27 | -------------------------------------------------------------------------------- /keyhotee/Keyhotee.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/contact_icon.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /keyhotee/KeyhoteeMainWindow.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Ui { class KeyhoteeMainWindow; } 6 | 7 | class KeyhoteeMainWindow : public QMainWindow 8 | { 9 | public: 10 | KeyhoteeMainWindow(); 11 | ~KeyhoteeMainWindow(); 12 | 13 | void addContact(); 14 | 15 | private: 16 | std::unique_ptr ui; 17 | }; 18 | -------------------------------------------------------------------------------- /keyhotee/LoginDialog.cpp: -------------------------------------------------------------------------------- 1 | #include "LoginDialog.hpp" 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | LoginDialog::LoginDialog( QWidget* parent ) 9 | :QDialog(parent) 10 | { 11 | ui.reset( new Ui::LoginDialog() ); 12 | ui->setupUi(this); 13 | connect( ui->login, &QPushButton::clicked, this, &LoginDialog::onLogin ); 14 | connect( ui->quit, &QPushButton::clicked, this, &LoginDialog::onQuit ); 15 | } 16 | 17 | LoginDialog::~LoginDialog() 18 | {} 19 | 20 | 21 | void LoginDialog::onLogin() 22 | { 23 | try { 24 | password = ui->password->text().toStdString(); 25 | auto pro = bts::application::instance()->load_profile(password); 26 | if( pro ) 27 | { 28 | accept(); 29 | } 30 | } 31 | catch ( const fc::exception& e ) 32 | { 33 | wlog( "error ${w}", ("w",e.to_detail_string()) ); 34 | } 35 | ui->password->setText(QString()); 36 | shake(); 37 | } 38 | void LoginDialog::shake( ) 39 | { 40 | move( pos() + QPoint(10,0) ); 41 | fc::usleep( fc::microseconds( 50*1000 ) ); 42 | move( pos() + QPoint(-20,0) ); 43 | fc::usleep( fc::microseconds( 50*1000 ) ); 44 | move( pos() + QPoint(20,0) ); 45 | fc::usleep( fc::microseconds( 50*1000 ) ); 46 | move( pos() + QPoint(-10,0) ); 47 | } 48 | void LoginDialog::onQuit() 49 | { 50 | qApp->quit(); 51 | reject(); 52 | } 53 | -------------------------------------------------------------------------------- /keyhotee/LoginDialog.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Ui { class LoginDialog; } 6 | 7 | class LoginDialog : public QDialog 8 | { 9 | public: 10 | LoginDialog( QWidget* parent = nullptr ); 11 | ~LoginDialog(); 12 | 13 | void onLogin(); 14 | void onQuit(); 15 | void shake(); 16 | 17 | std::string password; 18 | private: 19 | std::unique_ptr ui; 20 | }; 21 | -------------------------------------------------------------------------------- /keyhotee/LoginDialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | LoginDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 302 10 | 188 11 | 12 | 13 | 14 | Keyhotee Login 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Password 24 | 25 | 26 | 27 | 28 | 29 | 30 | QLineEdit::Password 31 | 32 | 33 | 34 | 35 | 36 | 37 | Quit 38 | 39 | 40 | false 41 | 42 | 43 | false 44 | 45 | 46 | 47 | 48 | 49 | 50 | Login 51 | 52 | 53 | true 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /keyhotee/images/contact_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Xenland/BitShares/f8d5bf4ef0517fd566119c2f8daf7776b0be00aa/keyhotee/images/contact_icon.png -------------------------------------------------------------------------------- /keyhotee/profile_wizard/ProfileIntroPage.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | IntroPage 4 | 5 | 6 | 7 | 0 8 | 0 9 | 469 10 | 377 11 | 12 | 13 | 14 | WizardPage 15 | 16 | 17 | 18 | 19 | 20 | 21 | about:blank 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | QWebView 31 | QWidget 32 |
QtWebKitWidgets/QWebView
33 |
34 |
35 | 36 | 37 |
38 | -------------------------------------------------------------------------------- /keyhotee/profile_wizard/ProfileWizard.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Ui { 6 | class IntroPage; 7 | } // namespace Ui 8 | 9 | class NymPage; 10 | class ProfileEditPage; 11 | 12 | class ProfileWizard : public QWizard 13 | { 14 | public: 15 | ProfileWizard( QWidget* parent ); 16 | ~ProfileWizard(); 17 | 18 | enum Pages 19 | { 20 | Page_Intro, 21 | Page_Profile, 22 | Page_FirstNym 23 | }; 24 | 25 | public slots: 26 | void showHelp(); 27 | void createProfile( int result ); 28 | 29 | private: 30 | NymPage* _nym_page; 31 | ProfileEditPage* _profile_edit; 32 | Ui::IntroPage* _profile_intro_ui; 33 | }; 34 | -------------------------------------------------------------------------------- /src/address.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace bts 8 | { 9 | address::address() 10 | { 11 | memset( addr.data, 0, sizeof(addr.data) ); 12 | } 13 | address::address( const std::string& base58str ) 14 | { 15 | std::vector v = fc::from_base58( fc::string(base58str) ); 16 | if( v.size() ) 17 | memcpy( addr.data, v.data(), std::min( v.size(), sizeof(addr) ) ); 18 | 19 | if( !is_valid() ) 20 | { 21 | FC_THROW_EXCEPTION( exception, "invalid address ${a}", ("a", base58str) ); 22 | } 23 | } 24 | 25 | address::address( const fc::ecc::public_key& pub ) 26 | { 27 | auto dat = pub.serialize(); 28 | auto dat_hash = small_hash(dat.data, sizeof(dat) ); 29 | // set the version number 30 | ((char*)&dat_hash)[0] &= 0x0f; // set first 4 bits to 0 31 | ((char*)&dat_hash)[0] |= 0x10; // set the first 4 bits to 0001 32 | auto check = fc::ripemd160::hash( (char*)&dat_hash, 16 ); 33 | memcpy( addr.data, (char*)&dat_hash, sizeof(addr) ); 34 | memcpy( &addr.data[16], (char*)&check, 4 ); 35 | } 36 | 37 | /** 38 | * Checks the address to verify it has a 39 | * valid checksum and prefix. 40 | */ 41 | bool address::is_valid()const 42 | { 43 | if( (addr.data[0] & 0xf0) != 0x10 ) // version 1 44 | { 45 | FC_THROW_EXCEPTION( exception, "invalid address version" ); 46 | return false; 47 | } 48 | auto check = fc::ripemd160::hash( addr.data, 16 ); 49 | return memcmp(&addr.data[16], &check, 4 ) == 0; 50 | } 51 | 52 | address::operator std::string()const 53 | { 54 | return fc::to_base58( addr.data, sizeof(addr) ); 55 | } 56 | } // namespace bts 57 | 58 | 59 | namespace fc 60 | { 61 | void to_variant( const bts::address& var, variant& vo ) 62 | { 63 | vo = std::string(var); 64 | } 65 | void from_variant( const variant& var, bts::address& vo ) 66 | { 67 | vo = bts::address( var.as_string() ); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/addressbook/addressbook.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace bts { namespace addressbook { 8 | 9 | namespace detail 10 | { 11 | class addressbook_impl 12 | { 13 | public: 14 | db::level_map _contact_db; 15 | db::level_map _address_index; 16 | }; 17 | } 18 | 19 | addressbook::addressbook() 20 | :my( new detail::addressbook_impl() ) 21 | { 22 | } 23 | 24 | addressbook::~addressbook() 25 | { 26 | } 27 | 28 | void addressbook::open( const fc::path& abook_dir ) 29 | { try { 30 | 31 | if( !fc::exists( abook_dir ) ) 32 | { 33 | fc::create_directories( abook_dir ); 34 | } 35 | my->_contact_db.open( abook_dir / "contact_db" ); 36 | my->_address_index.open( abook_dir / "address_index" ); 37 | 38 | } FC_RETHROW_EXCEPTIONS( warn, "", ("directory", abook_dir) ) } 39 | 40 | std::vector addressbook::get_known_bitnames()const 41 | { 42 | std::vector known_bitnames; 43 | auto itr = my->_contact_db.begin(); 44 | while( itr.valid() ) 45 | { 46 | known_bitnames.push_back(itr.key()); 47 | ++itr; 48 | } 49 | return known_bitnames; 50 | } 51 | 52 | fc::optional addressbook::get_contact_by_bitname( const std::string& bitname_id )const 53 | { try { 54 | fc::optional con; 55 | auto itr = my->_contact_db.find(bitname_id); 56 | if( itr.valid() ) con = itr.value(); 57 | return con; 58 | } FC_RETHROW_EXCEPTIONS( warn, "", ("bitname_id", bitname_id) ) } 59 | 60 | std::string addressbook::get_bitname_by_address( const bts::address& bitname_address )const 61 | { try { 62 | return my->_address_index.fetch( bitname_address ); 63 | } FC_RETHROW_EXCEPTIONS( warn, "", ("bitname_address", bitname_address) ) } 64 | 65 | void addressbook::store_contact( const contact& contact_param ) 66 | { try { 67 | my->_contact_db.store( contact_param.bitname_id, contact_param ); 68 | my->_address_index.store( bts::address(contact_param.send_msg_address), contact_param.bitname_id ); 69 | } FC_RETHROW_EXCEPTIONS( warn, "", ("contact", contact_param) ) } 70 | 71 | } } // bts::addressbook 72 | -------------------------------------------------------------------------------- /src/bitchat/bitchat_messages.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace bts { namespace bitchat { 4 | 5 | const message_type inv_message::type; 6 | const message_type get_priv_message::type; 7 | const message_type get_inv_message::type; 8 | const message_type encrypted_message::type; 9 | 10 | } } // bts::bitchat 11 | -------------------------------------------------------------------------------- /src/bitname/bitname_messages.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace bts { namespace bitname { 4 | 5 | const message_type name_inv_message::type = name_inv_msg; 6 | const message_type block_inv_message::type = block_inv_msg; 7 | const message_type get_name_inv_message::type = get_name_inv_msg; 8 | const message_type get_headers_message::type = get_headers_msg; 9 | const message_type get_block_message::type = get_block_msg; 10 | const message_type get_block_index_message::type = get_block_index_msg; 11 | const message_type get_name_header_message::type = get_name_header_msg; 12 | const message_type name_header_message::type = name_header_msg; 13 | const message_type block_message::type = block_msg; 14 | const message_type block_index_message::type = block_index_msg; 15 | const message_type headers_message::type = headers_msg; 16 | 17 | } } // bts::bitname 18 | -------------------------------------------------------------------------------- /src/bitname/bitname_record.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace bts { namespace bitname { 5 | uint64_t name_record::get_name_hash()const 6 | { 7 | uint64_t result = 0; 8 | fc::from_hex( name_hash, (char*)&result, sizeof(result) ); 9 | return result; 10 | } 11 | 12 | void name_record::set_name_hash( uint64_t nhash ) 13 | { 14 | name_hash = fc::to_hex( (char*)&nhash, sizeof(nhash) ); 15 | } 16 | 17 | } } // bts::bitname 18 | -------------------------------------------------------------------------------- /src/blockchain/blockchain_messages.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace bts { namespace blockchain { 4 | 5 | const message_type trx_inv_message::type; 6 | const message_type block_inv_message::type; 7 | const message_type get_trx_inv_message::type; 8 | const message_type get_trxs_message::type; 9 | const message_type get_full_block_message::type; 10 | const message_type get_trx_block_message::type; 11 | const message_type trxs_message::type; 12 | const message_type full_block_message::type; 13 | const message_type trx_block_message::type; 14 | 15 | } } // bts::bitchat 16 | -------------------------------------------------------------------------------- /src/blockchain/blockchain_outputs.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace bts { namespace blockchain { 4 | 5 | const claim_type_enum claim_by_signature_output::type = claim_type_enum::claim_by_signature; 6 | const claim_type_enum claim_by_bid_output::type = claim_type_enum::claim_by_bid; 7 | const claim_type_enum claim_by_long_output::type = claim_type_enum::claim_by_long; 8 | const claim_type_enum claim_by_cover_output::type = claim_type_enum::claim_by_cover; 9 | const claim_type_enum claim_by_opt_execute_output::type = claim_type_enum::claim_by_opt_execute; 10 | const claim_type_enum claim_by_password_output::type = claim_type_enum::claim_by_password; 11 | const claim_type_enum claim_by_escrow_output::type = claim_type_enum::claim_by_password; 12 | const claim_type_enum claim_by_multi_sig_output::type = claim_type_enum::claim_by_multi_sig; 13 | 14 | 15 | const claim_type_enum claim_by_signature_input::type = claim_type_enum::claim_by_signature; 16 | const claim_type_enum claim_by_bid_input::type = claim_type_enum::claim_by_bid; 17 | const claim_type_enum claim_by_long_input::type = claim_type_enum::claim_by_long; 18 | const claim_type_enum claim_by_cover_input::type = claim_type_enum::claim_by_cover; 19 | const claim_type_enum claim_by_opt_execute_input::type = claim_type_enum::claim_by_opt_execute; 20 | const claim_type_enum claim_by_password_input::type = claim_type_enum::claim_by_password; 21 | const claim_type_enum claim_by_multi_sig_input::type = claim_type_enum::claim_by_multi_sig; 22 | 23 | bool claim_by_bid_output::is_ask( asset::type out_unit )const 24 | { 25 | return ask_price.quote_unit == out_unit; 26 | } 27 | 28 | bool claim_by_bid_output::is_bid( asset::type out_unit )const 29 | { 30 | return !is_ask(out_unit); 31 | } 32 | 33 | bool claim_by_bid_output::operator == ( const claim_by_bid_output& other )const 34 | { 35 | return (other.pay_address == pay_address) && 36 | (other.ask_price == ask_price) && 37 | (other.min_trade == min_trade); 38 | } 39 | 40 | } } // bts::blockchain 41 | -------------------------------------------------------------------------------- /src/difficulty.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace bts 6 | { 7 | const fc::bigint& max224() 8 | { 9 | static fc::bigint m = [](){ 10 | char data[224/8+1]; 11 | memset( data, 0xff, sizeof(data) ); 12 | data[0] = 0; 13 | return fc::bigint(data,sizeof(data)); 14 | }(); 15 | return m; 16 | } 17 | 18 | uint64_t difficulty( const fc::sha224& hash_value ) 19 | { 20 | if( hash_value == fc::sha224() ) return uint64_t(-1); // div by 0 21 | 22 | auto dif = max224() / fc::bigint( (char*)&hash_value, sizeof(hash_value) ); 23 | // TODO... restore this dif >>= 24; 24 | int64_t tmp = dif.to_int64(); 25 | // possible if hash_value starts with 1 26 | if( tmp < 0 ) tmp = 0; 27 | return tmp; 28 | } 29 | 30 | 31 | } // bts 32 | -------------------------------------------------------------------------------- /src/merkle_tree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace bts { 5 | 6 | uint160 merkle_branch::calculate_root()const 7 | { 8 | if( mid_states.size() == 0 ) return uint160(); 9 | if( mid_states.size() == 1 ) return mid_states[0]; 10 | FC_ASSERT( !"TODO: Merged Mining is Not Yet Implemented" ); 11 | } 12 | 13 | } // namespace bts 14 | -------------------------------------------------------------------------------- /src/miner.cpp: -------------------------------------------------------------------------------- 1 | #include "miner.hpp" 2 | 3 | 4 | miner::miner( block_chain& bc, account& a ) 5 | :_block_chain(bc),_mining_account(a) 6 | { 7 | } 8 | 9 | miner::~miner() 10 | { 11 | } 12 | 13 | void miner::start( float effort ) 14 | { 15 | } 16 | 17 | void miner::stop() 18 | { 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/miner.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "api.hpp" 3 | #include 4 | 5 | class account; 6 | 7 | 8 | /** 9 | * The miner will monitor the block chain for changes and 10 | * attempt to solve new blocks as they come in. When a new 11 | * block is solved it will be 'added' to the chain. 12 | */ 13 | class miner 14 | { 15 | public: 16 | miner( block_chain& bc, account& a ); 17 | ~miner(); 18 | 19 | void start( float effort = 1); 20 | void stop(); 21 | 22 | private: 23 | fc::thread _mining_thread; 24 | block_chain& _block_chain; 25 | account& _mining_account; 26 | float _effort; 27 | }; 28 | -------------------------------------------------------------------------------- /src/network/get_public_ip.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace bts { namespace network 6 | { 7 | /** 8 | * Attempts to connect to checkip.dyndns.org to and then parse the 9 | * HTML for the IP address. 10 | * 11 | * @throw if no IP could be discovered. 12 | */ 13 | fc::ip::address get_public_ip() 14 | { 15 | fc::http::connection con; 16 | con.connect_to( fc::ip::endpoint::from_string( "91.198.22.70:80" ) ); 17 | auto reply = con.request( "GET", "/", std::string() ); 18 | 19 | std::string s( reply.body.data(), reply.body.data() + reply.body.size() ); 20 | // ilog( "${body}", ( "body", s) ); 21 | auto pos = s.find( "Address: " ); 22 | auto end = s.find( "" ); 23 | 24 | return fc::ip::address( s.substr( pos + 9, end-pos - 9) ); 25 | } 26 | 27 | } } 28 | -------------------------------------------------------------------------------- /src/peer/peer_db.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace bts { namespace peer { 4 | 5 | namespace detail 6 | { 7 | class peer_db_impl 8 | { 9 | public: 10 | 11 | }; 12 | 13 | } 14 | 15 | peer_db::peer_db() 16 | :my( new detail::peer_db_impl() ) 17 | { 18 | } 19 | 20 | 21 | peer_db::~peer_db(){} 22 | void peer_db::open( const fc::path& dbdir, bool create ) 23 | { 24 | } 25 | void peer_db::close() 26 | { 27 | } 28 | 29 | /** 30 | * On a fresh startup the entire database is 'out of date' and therefore 31 | * all hosts should be reset to 1 hour old so they can expire if we have 32 | * not heard about them in 2 hours. 33 | */ 34 | void peer_db::reset_ages( const fc::time_point_sec& s ) 35 | { 36 | } 37 | 38 | void peer_db::store( const host& r ) 39 | { 40 | } 41 | 42 | host peer_db::fetch_record( const fc::ip::endpoint& ep ) 43 | { 44 | return host(); 45 | } 46 | 47 | /** Removes a host from the DB, presumably because we attempted to connect 48 | * to it and were unable to. 49 | * 50 | * TODO: how do we prevent purging the entire DB if the internet goes down 51 | * and no hosts are reachable? Perhaps only perge nodes if we are successfully 52 | * connected to other nodes. 53 | */ 54 | void peer_db::remove( const fc::ip::endpoint& ep ) 55 | { 56 | } 57 | 58 | void peer_db::add_channel( const fc::ip::endpoint& e, const channel_id& c ) 59 | { 60 | } 61 | 62 | void peer_db::remove_channel( const fc::ip::endpoint& e, const channel_id& c ) 63 | { 64 | } 65 | 66 | 67 | std::vector peer_db::fetch_hosts( const channel_id& c ) 68 | { 69 | return std::vector(); 70 | } 71 | 72 | void peer_db::purge_old( const fc::time_point& age ) 73 | { 74 | } 75 | 76 | 77 | } } 78 | -------------------------------------------------------------------------------- /src/peer/peer_messages.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace bts { namespace peer { 4 | 5 | const message_code config_msg::type; 6 | const message_code known_hosts_msg::type; 7 | const message_code subscribe_msg::type; 8 | const message_code unsubscribe_msg::type; 9 | const message_code get_subscribed_msg::type; 10 | const message_code error_report_msg::type; 11 | const message_code get_known_hosts_msg::type; 12 | 13 | } } // bts::peer 14 | -------------------------------------------------------------------------------- /src/small_hash.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace bts 5 | { 6 | typedef fc::ripemd160 uint160; 7 | 8 | /** 9 | * Performs ripemd160(seed); 10 | */ 11 | uint160 small_hash( const fc::sha512& seed ) 12 | { 13 | return fc::ripemd160::hash(seed); 14 | } 15 | 16 | /** 17 | * The goal of the small hash is to be secure using as few 18 | * bits as possible. 19 | * 20 | * Performs small_hash( sha512(data,len) ) 21 | */ 22 | uint160 small_hash( const char* data, size_t len ) 23 | { 24 | return small_hash( fc::sha512::hash(data,len) ); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tasks.md: -------------------------------------------------------------------------------- 1 | If you would like to work on these tasks please contact a project lead and they 2 | will give you dibs on them provided you commit to a completion date. Fork the code, 3 | and generate a pull request when complete. After a code review, your patch will 4 | be imported into the code code base and your funds will be paid. 5 | 6 | 0.5 BTC - fc hashing refactor: 7 | ------------------------------- 8 | replace fc::sha224 fc::sha256 fc::sha512 fc::sha1 with a single generic template class of the proper byte bitsiz 9 | and then typedef define fc::uint160, 224, 256, 512 to that template type. 10 | 11 | move fc::shaX::encoder to fc::shaX_encoder and update to produce uintX 12 | move fc::shaX::hash(...) to fc::shaX_hash(...) 13 | update all of BitShares to compile with these changes. 14 | 15 | 1 BTC - generate an input via socket connection that can cause our client to crash. 16 | -------------------------------- 17 | not yet open for dibs, but will be opened after we complete our initial security audit. 18 | must provide unit test that demonstrates the crash in reproduceable manner. 19 | 20 | 2 BTC - generate full coverage tests for bts::bitname::fork_db 21 | -------------------------------- 22 | not yet open for dibs, but will be once the full funtionality is defined. Let me 23 | know if you are interested. 24 | 25 | must generate chains at least 2 years deep at 1 header every 5 minutes 26 | must handle populating the blocks in any order and generate the same result. 27 | must benchmark get_forks(), set_valid() 28 | must verify that the contents of unknown is always accurate 29 | must be in the form of a boost unit test. 30 | must check setting and clearing the valid state on random nodes 31 | must exersize every method and every branch in the code (verify this somehow?) 32 | 33 | 34 | .25 BTC - implement from_variant in src/blockchain/transaction.cpp 35 | open for bids now 36 | void from_variant( const variant& var, bts::blockchain::trx_output& vo ) 37 | - must provide boost unit tests for all variations. 38 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (WIN32) 2 | set( PLATFORM_SPECIFIC_LIBS WS2_32 ) 3 | else (WIN32) 4 | set( PLATFORM_SPECIFIC_LIBS ) 5 | endif(WIN32) 6 | 7 | add_executable( blockchain_tests blockchain_tests.cpp ) 8 | target_link_libraries( blockchain_tests bshare fc leveldb ${BOOST_LIBRARIES} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${PLATFORM_SPECIFIC_LIBS} ) 9 | 10 | add_executable( pow_test pow_test.cpp ) 11 | target_link_libraries( pow_test bshare fc ${BOOST_LIBRARIES}) 12 | 13 | add_executable( timekeeper timekeeper.cpp ) 14 | target_link_libraries( timekeeper bshare fc ${BOOST_LIBRARIES} ${PLATFORM_SPECIFIC_LIBS} ) 15 | -------------------------------------------------------------------------------- /tests/unit_tests.cpp: -------------------------------------------------------------------------------- 1 | #define BOOST_TEST_MODULE BitSharesTest 2 | #include 3 | #include 4 | #include 5 | #include "../src/blockchain.hpp" 6 | #include "../src/chain_state.hpp" 7 | 8 | /** 9 | * This test will validate that a transaction signed with a private 10 | * key will result in the address showing up in get signed addresses 11 | * used for validation. 12 | */ 13 | BOOST_AUTO_TEST_CASE( transaction_signing_and_verification ) 14 | { 15 | fc::ecc::private_key dst = fc::ecc::private_key::generate(); 16 | 17 | signed_transaction trx; 18 | 19 | trx.outputs.resize(1); 20 | trx.outputs[0].set_claim_function( claim_with_address( dst.get_public_key() ) ); 21 | 22 | trx.sign_with_key( dst ); 23 | 24 | auto saddr = trx.get_signed_addresses(); 25 | BOOST_REQUIRE( saddr[0] == address(dst.get_public_key()) ); 26 | } 27 | 28 | 29 | 30 | BOOST_AUTO_TEST_CASE( chain_state_commit_undo ) 31 | { 32 | chain_state cs; 33 | 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tests/wallet_test.cpp: -------------------------------------------------------------------------------- 1 | #include "../src/wallet.hpp" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main( int argc, char** argv ) 8 | { 9 | if( argc < 3 ) 10 | { 11 | fc::cerr<<"Usage: "<number. On success, the rest of 22 | // *meta will be filled with metadata about the generated table. 23 | // If no data is present in *iter, meta->file_size will be set to 24 | // zero, and no Table file will be produced. 25 | extern Status BuildTable(const std::string& dbname, 26 | Env* env, 27 | const Options& options, 28 | TableCache* table_cache, 29 | Iterator* iter, 30 | FileMetaData* meta); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_DB_BUILDER_H_ 35 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/db/db_iter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_DB_ITER_H_ 6 | #define STORAGE_LEVELDB_DB_DB_ITER_H_ 7 | 8 | #include 9 | #include "leveldb/db.h" 10 | #include "db/dbformat.h" 11 | 12 | namespace leveldb { 13 | 14 | // Return a new iterator that converts internal keys (yielded by 15 | // "*internal_iter") that were live at the specified "sequence" number 16 | // into appropriate user keys. 17 | extern Iterator* NewDBIterator( 18 | const std::string* dbname, 19 | Env* env, 20 | const Comparator* user_key_comparator, 21 | Iterator* internal_iter, 22 | const SequenceNumber& sequence); 23 | 24 | } // namespace leveldb 25 | 26 | #endif // STORAGE_LEVELDB_DB_DB_ITER_H_ 27 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/db/log_format.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Log format information shared by reader and writer. 6 | // See ../doc/log_format.txt for more detail. 7 | 8 | #ifndef STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 9 | #define STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 10 | 11 | namespace leveldb { 12 | namespace log { 13 | 14 | enum RecordType { 15 | // Zero is reserved for preallocated files 16 | kZeroType = 0, 17 | 18 | kFullType = 1, 19 | 20 | // For fragments 21 | kFirstType = 2, 22 | kMiddleType = 3, 23 | kLastType = 4 24 | }; 25 | static const int kMaxRecordType = kLastType; 26 | 27 | static const int kBlockSize = 32768; 28 | 29 | // Header is checksum (4 bytes), type (1 byte), length (2 bytes). 30 | static const int kHeaderSize = 4 + 1 + 2; 31 | 32 | } // namespace log 33 | } // namespace leveldb 34 | 35 | #endif // STORAGE_LEVELDB_DB_LOG_FORMAT_H_ 36 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/db/log_writer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_LOG_WRITER_H_ 6 | #define STORAGE_LEVELDB_DB_LOG_WRITER_H_ 7 | 8 | #include 9 | #include "db/log_format.h" 10 | #include "leveldb/slice.h" 11 | #include "leveldb/status.h" 12 | 13 | namespace leveldb { 14 | 15 | class WritableFile; 16 | 17 | namespace log { 18 | 19 | class Writer { 20 | public: 21 | // Create a writer that will append data to "*dest". 22 | // "*dest" must be initially empty. 23 | // "*dest" must remain live while this Writer is in use. 24 | explicit Writer(WritableFile* dest); 25 | ~Writer(); 26 | 27 | Status AddRecord(const Slice& slice); 28 | 29 | private: 30 | WritableFile* dest_; 31 | int block_offset_; // Current offset in block 32 | 33 | // crc32c values for all supported record types. These are 34 | // pre-computed to reduce the overhead of computing the crc of the 35 | // record type stored in the header. 36 | uint32_t type_crc_[kMaxRecordType + 1]; 37 | 38 | Status EmitPhysicalRecord(RecordType type, const char* ptr, size_t length); 39 | 40 | // No copying allowed 41 | Writer(const Writer&); 42 | void operator=(const Writer&); 43 | }; 44 | 45 | } // namespace log 46 | } // namespace leveldb 47 | 48 | #endif // STORAGE_LEVELDB_DB_LOG_WRITER_H_ 49 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/db/snapshot.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_SNAPSHOT_H_ 6 | #define STORAGE_LEVELDB_DB_SNAPSHOT_H_ 7 | 8 | #include "leveldb/db.h" 9 | 10 | namespace leveldb { 11 | 12 | class SnapshotList; 13 | 14 | // Snapshots are kept in a doubly-linked list in the DB. 15 | // Each SnapshotImpl corresponds to a particular sequence number. 16 | class SnapshotImpl : public Snapshot { 17 | public: 18 | SequenceNumber number_; // const after creation 19 | 20 | private: 21 | friend class SnapshotList; 22 | 23 | // SnapshotImpl is kept in a doubly-linked circular list 24 | SnapshotImpl* prev_; 25 | SnapshotImpl* next_; 26 | 27 | SnapshotList* list_; // just for sanity checks 28 | }; 29 | 30 | class SnapshotList { 31 | public: 32 | SnapshotList() { 33 | list_.prev_ = &list_; 34 | list_.next_ = &list_; 35 | } 36 | 37 | bool empty() const { return list_.next_ == &list_; } 38 | SnapshotImpl* oldest() const { assert(!empty()); return list_.next_; } 39 | SnapshotImpl* newest() const { assert(!empty()); return list_.prev_; } 40 | 41 | const SnapshotImpl* New(SequenceNumber seq) { 42 | SnapshotImpl* s = new SnapshotImpl; 43 | s->number_ = seq; 44 | s->list_ = this; 45 | s->next_ = &list_; 46 | s->prev_ = list_.prev_; 47 | s->prev_->next_ = s; 48 | s->next_->prev_ = s; 49 | return s; 50 | } 51 | 52 | void Delete(const SnapshotImpl* s) { 53 | assert(s->list_ == this); 54 | s->prev_->next_ = s->next_; 55 | s->next_->prev_ = s->prev_; 56 | delete s; 57 | } 58 | 59 | private: 60 | // Dummy head of doubly-linked list of snapshots 61 | SnapshotImpl list_; 62 | }; 63 | 64 | } // namespace leveldb 65 | 66 | #endif // STORAGE_LEVELDB_DB_SNAPSHOT_H_ 67 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/db/table_cache.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Thread-safe (provides internal synchronization) 6 | 7 | #ifndef STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 8 | #define STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 9 | 10 | #include 11 | #include 12 | #include "db/dbformat.h" 13 | #include "leveldb/cache.h" 14 | #include "leveldb/table.h" 15 | #include "port/port.h" 16 | 17 | namespace leveldb { 18 | 19 | class Env; 20 | 21 | class TableCache { 22 | public: 23 | TableCache(const std::string& dbname, const Options* options, int entries); 24 | ~TableCache(); 25 | 26 | // Return an iterator for the specified file number (the corresponding 27 | // file length must be exactly "file_size" bytes). If "tableptr" is 28 | // non-NULL, also sets "*tableptr" to point to the Table object 29 | // underlying the returned iterator, or NULL if no Table object underlies 30 | // the returned iterator. The returned "*tableptr" object is owned by 31 | // the cache and should not be deleted, and is valid for as long as the 32 | // returned iterator is live. 33 | Iterator* NewIterator(const ReadOptions& options, 34 | uint64_t file_number, 35 | uint64_t file_size, 36 | Table** tableptr = NULL); 37 | 38 | // If a seek to internal key "k" in specified file finds an entry, 39 | // call (*handle_result)(arg, found_key, found_value). 40 | Status Get(const ReadOptions& options, 41 | uint64_t file_number, 42 | uint64_t file_size, 43 | const Slice& k, 44 | void* arg, 45 | void (*handle_result)(void*, const Slice&, const Slice&)); 46 | 47 | // Evict any entry for the specified file number 48 | void Evict(uint64_t file_number); 49 | 50 | private: 51 | Env* const env_; 52 | const std::string dbname_; 53 | const Options* options_; 54 | Cache* cache_; 55 | 56 | Status FindTable(uint64_t file_number, uint64_t file_size, Cache::Handle**); 57 | }; 58 | 59 | } // namespace leveldb 60 | 61 | #endif // STORAGE_LEVELDB_DB_TABLE_CACHE_H_ 62 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/db/version_edit_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "db/version_edit.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | 10 | static void TestEncodeDecode(const VersionEdit& edit) { 11 | std::string encoded, encoded2; 12 | edit.EncodeTo(&encoded); 13 | VersionEdit parsed; 14 | Status s = parsed.DecodeFrom(encoded); 15 | ASSERT_TRUE(s.ok()) << s.ToString(); 16 | parsed.EncodeTo(&encoded2); 17 | ASSERT_EQ(encoded, encoded2); 18 | } 19 | 20 | class VersionEditTest { }; 21 | 22 | TEST(VersionEditTest, EncodeDecode) { 23 | static const uint64_t kBig = 1ull << 50; 24 | 25 | VersionEdit edit; 26 | for (int i = 0; i < 4; i++) { 27 | TestEncodeDecode(edit); 28 | edit.AddFile(3, kBig + 300 + i, kBig + 400 + i, 29 | InternalKey("foo", kBig + 500 + i, kTypeValue), 30 | InternalKey("zoo", kBig + 600 + i, kTypeDeletion)); 31 | edit.DeleteFile(4, kBig + 700 + i); 32 | edit.SetCompactPointer(i, InternalKey("x", kBig + 900 + i, kTypeValue)); 33 | } 34 | 35 | edit.SetComparatorName("foo"); 36 | edit.SetLogNumber(kBig + 100); 37 | edit.SetNextFile(kBig + 200); 38 | edit.SetLastSequence(kBig + 1000); 39 | TestEncodeDecode(edit); 40 | } 41 | 42 | } // namespace leveldb 43 | 44 | int main(int argc, char** argv) { 45 | return leveldb::test::RunAllTests(); 46 | } 47 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/db/write_batch_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 6 | #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 7 | 8 | #include "leveldb/write_batch.h" 9 | 10 | namespace leveldb { 11 | 12 | class MemTable; 13 | 14 | // WriteBatchInternal provides static methods for manipulating a 15 | // WriteBatch that we don't want in the public WriteBatch interface. 16 | class WriteBatchInternal { 17 | public: 18 | // Return the number of entries in the batch. 19 | static int Count(const WriteBatch* batch); 20 | 21 | // Set the count for the number of entries in the batch. 22 | static void SetCount(WriteBatch* batch, int n); 23 | 24 | // Return the seqeunce number for the start of this batch. 25 | static SequenceNumber Sequence(const WriteBatch* batch); 26 | 27 | // Store the specified number as the seqeunce number for the start of 28 | // this batch. 29 | static void SetSequence(WriteBatch* batch, SequenceNumber seq); 30 | 31 | static Slice Contents(const WriteBatch* batch) { 32 | return Slice(batch->rep_); 33 | } 34 | 35 | static size_t ByteSize(const WriteBatch* batch) { 36 | return batch->rep_.size(); 37 | } 38 | 39 | static void SetContents(WriteBatch* batch, const Slice& contents); 40 | 41 | static Status InsertInto(const WriteBatch* batch, MemTable* memtable); 42 | 43 | static void Append(WriteBatch* dst, const WriteBatch* src); 44 | }; 45 | 46 | } // namespace leveldb 47 | 48 | 49 | #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_ 50 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/helpers/memenv/memenv.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 6 | #define STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Env; 11 | 12 | // Returns a new environment that stores its data in memory and delegates 13 | // all non-file-storage tasks to base_env. The caller must delete the result 14 | // when it is no longer needed. 15 | // *base_env must remain live while the result is in use. 16 | Env* NewMemEnv(Env* base_env); 17 | 18 | } // namespace leveldb 19 | 20 | #endif // STORAGE_LEVELDB_HELPERS_MEMENV_MEMENV_H_ 21 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/include/leveldb/write_batch.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // WriteBatch holds a collection of updates to apply atomically to a DB. 6 | // 7 | // The updates are applied in the order in which they are added 8 | // to the WriteBatch. For example, the value of "key" will be "v3" 9 | // after the following batch is written: 10 | // 11 | // batch.Put("key", "v1"); 12 | // batch.Delete("key"); 13 | // batch.Put("key", "v2"); 14 | // batch.Put("key", "v3"); 15 | // 16 | // Multiple threads can invoke const methods on a WriteBatch without 17 | // external synchronization, but if any of the threads may call a 18 | // non-const method, all threads accessing the same WriteBatch must use 19 | // external synchronization. 20 | 21 | #ifndef STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 22 | #define STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 23 | 24 | #include 25 | #include "leveldb/status.h" 26 | 27 | namespace leveldb { 28 | 29 | class Slice; 30 | 31 | class WriteBatch { 32 | public: 33 | WriteBatch(); 34 | ~WriteBatch(); 35 | 36 | // Store the mapping "key->value" in the database. 37 | void Put(const Slice& key, const Slice& value); 38 | 39 | // If the database contains a mapping for "key", erase it. Else do nothing. 40 | void Delete(const Slice& key); 41 | 42 | // Clear all updates buffered in this batch. 43 | void Clear(); 44 | 45 | // Support for iterating over the contents of a batch. 46 | class Handler { 47 | public: 48 | virtual ~Handler(); 49 | virtual void Put(const Slice& key, const Slice& value) = 0; 50 | virtual void Delete(const Slice& key) = 0; 51 | }; 52 | Status Iterate(Handler* handler) const; 53 | 54 | private: 55 | friend class WriteBatchInternal; 56 | 57 | std::string rep_; // See comment in write_batch.cc for the format of rep_ 58 | 59 | // Intentionally copyable 60 | }; 61 | 62 | } // namespace leveldb 63 | 64 | #endif // STORAGE_LEVELDB_INCLUDE_WRITE_BATCH_H_ 65 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/port/port.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_PORT_H_ 6 | #define STORAGE_LEVELDB_PORT_PORT_H_ 7 | 8 | #include 9 | 10 | // Include the appropriate platform specific file below. If you are 11 | // porting to a new platform, see "port_example.h" for documentation 12 | // of what the new port_.h file must provide. 13 | #if 1 // defined(LEVELDB_PLATFORM_POSIX) 14 | # include "port/port_posix.h" 15 | #elif defined(LEVELDB_PLATFORM_CHROMIUM) 16 | # include "port/port_chromium.h" 17 | #endif 18 | 19 | #endif // STORAGE_LEVELDB_PORT_PORT_H_ 20 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/port/port_posix.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "port/port_posix.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include "util/logging.h" 11 | 12 | namespace leveldb { 13 | namespace port { 14 | 15 | static void PthreadCall(const char* label, int result) { 16 | if (result != 0) { 17 | fprintf(stderr, "pthread %s: %s\n", label, strerror(result)); 18 | abort(); 19 | } 20 | } 21 | 22 | Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); } 23 | 24 | Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); } 25 | 26 | void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); } 27 | 28 | void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); } 29 | 30 | CondVar::CondVar(Mutex* mu) 31 | : mu_(mu) { 32 | PthreadCall("init cv", pthread_cond_init(&cv_, NULL)); 33 | } 34 | 35 | CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); } 36 | 37 | void CondVar::Wait() { 38 | PthreadCall("wait", pthread_cond_wait(&cv_, &mu_->mu_)); 39 | } 40 | 41 | void CondVar::Signal() { 42 | PthreadCall("signal", pthread_cond_signal(&cv_)); 43 | } 44 | 45 | void CondVar::SignalAll() { 46 | PthreadCall("broadcast", pthread_cond_broadcast(&cv_)); 47 | } 48 | 49 | void InitOnce(OnceType* once, void (*initializer)()) { 50 | PthreadCall("once", pthread_once(once, initializer)); 51 | } 52 | 53 | } // namespace port 54 | } // namespace leveldb 55 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/port/thread_annotations.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H 6 | 7 | // Some environments provide custom macros to aid in static thread-safety 8 | // analysis. Provide empty definitions of such macros unless they are already 9 | // defined. 10 | 11 | #ifndef EXCLUSIVE_LOCKS_REQUIRED 12 | #define EXCLUSIVE_LOCKS_REQUIRED(...) 13 | #endif 14 | 15 | #ifndef SHARED_LOCKS_REQUIRED 16 | #define SHARED_LOCKS_REQUIRED(...) 17 | #endif 18 | 19 | #ifndef LOCKS_EXCLUDED 20 | #define LOCKS_EXCLUDED(...) 21 | #endif 22 | 23 | #ifndef LOCK_RETURNED 24 | #define LOCK_RETURNED(x) 25 | #endif 26 | 27 | #ifndef LOCKABLE 28 | #define LOCKABLE 29 | #endif 30 | 31 | #ifndef SCOPED_LOCKABLE 32 | #define SCOPED_LOCKABLE 33 | #endif 34 | 35 | #ifndef EXCLUSIVE_LOCK_FUNCTION 36 | #define EXCLUSIVE_LOCK_FUNCTION(...) 37 | #endif 38 | 39 | #ifndef SHARED_LOCK_FUNCTION 40 | #define SHARED_LOCK_FUNCTION(...) 41 | #endif 42 | 43 | #ifndef EXCLUSIVE_TRYLOCK_FUNCTION 44 | #define EXCLUSIVE_TRYLOCK_FUNCTION(...) 45 | #endif 46 | 47 | #ifndef SHARED_TRYLOCK_FUNCTION 48 | #define SHARED_TRYLOCK_FUNCTION(...) 49 | #endif 50 | 51 | #ifndef UNLOCK_FUNCTION 52 | #define UNLOCK_FUNCTION(...) 53 | #endif 54 | 55 | #ifndef NO_THREAD_SAFETY_ANALYSIS 56 | #define NO_THREAD_SAFETY_ANALYSIS 57 | #endif 58 | 59 | #endif // STORAGE_LEVELDB_PORT_THREAD_ANNOTATIONS_H 60 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/port/win/stdint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | // MSVC didn't ship with this file until the 2010 version. 6 | 7 | #ifndef STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 8 | #define STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 9 | 10 | #if !defined(_MSC_VER) 11 | #error This file should only be included when compiling with MSVC. 12 | #endif 13 | 14 | // Define C99 equivalent types. 15 | typedef signed char int8_t; 16 | typedef signed short int16_t; 17 | typedef signed int int32_t; 18 | typedef signed long long int64_t; 19 | typedef unsigned char uint8_t; 20 | typedef unsigned short uint16_t; 21 | typedef unsigned int uint32_t; 22 | typedef unsigned long long uint64_t; 23 | 24 | #endif // STORAGE_LEVELDB_PORT_WIN_STDINT_H_ 25 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/table/block.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_H_ 7 | 8 | #include 9 | #include 10 | #include "leveldb/iterator.h" 11 | 12 | namespace leveldb { 13 | 14 | struct BlockContents; 15 | class Comparator; 16 | 17 | class Block { 18 | public: 19 | // Initialize the block with the specified contents. 20 | explicit Block(const BlockContents& contents); 21 | 22 | ~Block(); 23 | 24 | size_t size() const { return size_; } 25 | Iterator* NewIterator(const Comparator* comparator); 26 | 27 | private: 28 | uint32_t NumRestarts() const; 29 | 30 | const char* data_; 31 | size_t size_; 32 | uint32_t restart_offset_; // Offset in data_ of restart array 33 | bool owned_; // Block owns data_[] 34 | 35 | // No copying allowed 36 | Block(const Block&); 37 | void operator=(const Block&); 38 | 39 | class Iter; 40 | }; 41 | 42 | } // namespace leveldb 43 | 44 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_H_ 45 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/table/block_builder.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 6 | #define STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 7 | 8 | #include 9 | 10 | #include 11 | #include "leveldb/slice.h" 12 | 13 | namespace leveldb { 14 | 15 | struct Options; 16 | 17 | class BlockBuilder { 18 | public: 19 | explicit BlockBuilder(const Options* options); 20 | 21 | // Reset the contents as if the BlockBuilder was just constructed. 22 | void Reset(); 23 | 24 | // REQUIRES: Finish() has not been callled since the last call to Reset(). 25 | // REQUIRES: key is larger than any previously added key 26 | void Add(const Slice& key, const Slice& value); 27 | 28 | // Finish building the block and return a slice that refers to the 29 | // block contents. The returned slice will remain valid for the 30 | // lifetime of this builder or until Reset() is called. 31 | Slice Finish(); 32 | 33 | // Returns an estimate of the current (uncompressed) size of the block 34 | // we are building. 35 | size_t CurrentSizeEstimate() const; 36 | 37 | // Return true iff no entries have been added since the last Reset() 38 | bool empty() const { 39 | return buffer_.empty(); 40 | } 41 | 42 | private: 43 | const Options* options_; 44 | std::string buffer_; // Destination buffer 45 | std::vector restarts_; // Restart points 46 | int counter_; // Number of entries emitted since restart 47 | bool finished_; // Has Finish() been called? 48 | std::string last_key_; 49 | 50 | // No copying allowed 51 | BlockBuilder(const BlockBuilder&); 52 | void operator=(const BlockBuilder&); 53 | }; 54 | 55 | } // namespace leveldb 56 | 57 | #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_ 58 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/table/iterator.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/iterator.h" 6 | 7 | namespace leveldb { 8 | 9 | Iterator::Iterator() { 10 | cleanup_.function = NULL; 11 | cleanup_.next = NULL; 12 | } 13 | 14 | Iterator::~Iterator() { 15 | if (cleanup_.function != NULL) { 16 | (*cleanup_.function)(cleanup_.arg1, cleanup_.arg2); 17 | for (Cleanup* c = cleanup_.next; c != NULL; ) { 18 | (*c->function)(c->arg1, c->arg2); 19 | Cleanup* next = c->next; 20 | delete c; 21 | c = next; 22 | } 23 | } 24 | } 25 | 26 | void Iterator::RegisterCleanup(CleanupFunction func, void* arg1, void* arg2) { 27 | assert(func != NULL); 28 | Cleanup* c; 29 | if (cleanup_.function == NULL) { 30 | c = &cleanup_; 31 | } else { 32 | c = new Cleanup; 33 | c->next = cleanup_.next; 34 | cleanup_.next = c; 35 | } 36 | c->function = func; 37 | c->arg1 = arg1; 38 | c->arg2 = arg2; 39 | } 40 | 41 | namespace { 42 | class EmptyIterator : public Iterator { 43 | public: 44 | EmptyIterator(const Status& s) : status_(s) { } 45 | virtual bool Valid() const { return false; } 46 | virtual void Seek(const Slice& target) { } 47 | virtual void SeekToFirst() { } 48 | virtual void SeekToLast() { } 49 | virtual void Next() { assert(false); } 50 | virtual void Prev() { assert(false); } 51 | Slice key() const { assert(false); return Slice(); } 52 | Slice value() const { assert(false); return Slice(); } 53 | virtual Status status() const { return status_; } 54 | private: 55 | Status status_; 56 | }; 57 | } // namespace 58 | 59 | Iterator* NewEmptyIterator() { 60 | return new EmptyIterator(Status::OK()); 61 | } 62 | 63 | Iterator* NewErrorIterator(const Status& status) { 64 | return new EmptyIterator(status); 65 | } 66 | 67 | } // namespace leveldb 68 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/table/iterator_wrapper.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 6 | #define STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 7 | 8 | namespace leveldb { 9 | 10 | // A internal wrapper class with an interface similar to Iterator that 11 | // caches the valid() and key() results for an underlying iterator. 12 | // This can help avoid virtual function calls and also gives better 13 | // cache locality. 14 | class IteratorWrapper { 15 | public: 16 | IteratorWrapper(): iter_(NULL), valid_(false) { } 17 | explicit IteratorWrapper(Iterator* iter): iter_(NULL) { 18 | Set(iter); 19 | } 20 | ~IteratorWrapper() { delete iter_; } 21 | Iterator* iter() const { return iter_; } 22 | 23 | // Takes ownership of "iter" and will delete it when destroyed, or 24 | // when Set() is invoked again. 25 | void Set(Iterator* iter) { 26 | delete iter_; 27 | iter_ = iter; 28 | if (iter_ == NULL) { 29 | valid_ = false; 30 | } else { 31 | Update(); 32 | } 33 | } 34 | 35 | 36 | // Iterator interface methods 37 | bool Valid() const { return valid_; } 38 | Slice key() const { assert(Valid()); return key_; } 39 | Slice value() const { assert(Valid()); return iter_->value(); } 40 | // Methods below require iter() != NULL 41 | Status status() const { assert(iter_); return iter_->status(); } 42 | void Next() { assert(iter_); iter_->Next(); Update(); } 43 | void Prev() { assert(iter_); iter_->Prev(); Update(); } 44 | void Seek(const Slice& k) { assert(iter_); iter_->Seek(k); Update(); } 45 | void SeekToFirst() { assert(iter_); iter_->SeekToFirst(); Update(); } 46 | void SeekToLast() { assert(iter_); iter_->SeekToLast(); Update(); } 47 | 48 | private: 49 | void Update() { 50 | valid_ = iter_->Valid(); 51 | if (valid_) { 52 | key_ = iter_->key(); 53 | } 54 | } 55 | 56 | Iterator* iter_; 57 | bool valid_; 58 | Slice key_; 59 | }; 60 | 61 | } // namespace leveldb 62 | 63 | #endif // STORAGE_LEVELDB_TABLE_ITERATOR_WRAPPER_H_ 64 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/table/merger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_MERGER_H_ 6 | #define STORAGE_LEVELDB_TABLE_MERGER_H_ 7 | 8 | namespace leveldb { 9 | 10 | class Comparator; 11 | class Iterator; 12 | 13 | // Return an iterator that provided the union of the data in 14 | // children[0,n-1]. Takes ownership of the child iterators and 15 | // will delete them when the result iterator is deleted. 16 | // 17 | // The result does no duplicate suppression. I.e., if a particular 18 | // key is present in K child iterators, it will be yielded K times. 19 | // 20 | // REQUIRES: n >= 0 21 | extern Iterator* NewMergingIterator( 22 | const Comparator* comparator, Iterator** children, int n); 23 | 24 | } // namespace leveldb 25 | 26 | #endif // STORAGE_LEVELDB_TABLE_MERGER_H_ 27 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/table/two_level_iterator.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 6 | #define STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 7 | 8 | #include "leveldb/iterator.h" 9 | 10 | namespace leveldb { 11 | 12 | struct ReadOptions; 13 | 14 | // Return a new two level iterator. A two-level iterator contains an 15 | // index iterator whose values point to a sequence of blocks where 16 | // each block is itself a sequence of key,value pairs. The returned 17 | // two-level iterator yields the concatenation of all key/value pairs 18 | // in the sequence of blocks. Takes ownership of "index_iter" and 19 | // will delete it when no longer needed. 20 | // 21 | // Uses a supplied function to convert an index_iter value into 22 | // an iterator over the contents of the corresponding block. 23 | extern Iterator* NewTwoLevelIterator( 24 | Iterator* index_iter, 25 | Iterator* (*block_function)( 26 | void* arg, 27 | const ReadOptions& options, 28 | const Slice& index_value), 29 | void* arg, 30 | const ReadOptions& options); 31 | 32 | } // namespace leveldb 33 | 34 | #endif // STORAGE_LEVELDB_TABLE_TWO_LEVEL_ITERATOR_H_ 35 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/arena.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/arena.h" 6 | #include 7 | 8 | namespace leveldb { 9 | 10 | static const int kBlockSize = 4096; 11 | 12 | Arena::Arena() { 13 | blocks_memory_ = 0; 14 | alloc_ptr_ = NULL; // First allocation will allocate a block 15 | alloc_bytes_remaining_ = 0; 16 | } 17 | 18 | Arena::~Arena() { 19 | for (size_t i = 0; i < blocks_.size(); i++) { 20 | delete[] blocks_[i]; 21 | } 22 | } 23 | 24 | char* Arena::AllocateFallback(size_t bytes) { 25 | if (bytes > kBlockSize / 4) { 26 | // Object is more than a quarter of our block size. Allocate it separately 27 | // to avoid wasting too much space in leftover bytes. 28 | char* result = AllocateNewBlock(bytes); 29 | return result; 30 | } 31 | 32 | // We waste the remaining space in the current block. 33 | alloc_ptr_ = AllocateNewBlock(kBlockSize); 34 | alloc_bytes_remaining_ = kBlockSize; 35 | 36 | char* result = alloc_ptr_; 37 | alloc_ptr_ += bytes; 38 | alloc_bytes_remaining_ -= bytes; 39 | return result; 40 | } 41 | 42 | char* Arena::AllocateAligned(size_t bytes) { 43 | const int align = sizeof(void*); // We'll align to pointer size 44 | assert((align & (align-1)) == 0); // Pointer size should be a power of 2 45 | size_t current_mod = reinterpret_cast(alloc_ptr_) & (align-1); 46 | size_t slop = (current_mod == 0 ? 0 : align - current_mod); 47 | size_t needed = bytes + slop; 48 | char* result; 49 | if (needed <= alloc_bytes_remaining_) { 50 | result = alloc_ptr_ + slop; 51 | alloc_ptr_ += needed; 52 | alloc_bytes_remaining_ -= needed; 53 | } else { 54 | // AllocateFallback always returned aligned memory 55 | result = AllocateFallback(bytes); 56 | } 57 | assert((reinterpret_cast(result) & (align-1)) == 0); 58 | return result; 59 | } 60 | 61 | char* Arena::AllocateNewBlock(size_t block_bytes) { 62 | char* result = new char[block_bytes]; 63 | blocks_memory_ += block_bytes; 64 | blocks_.push_back(result); 65 | return result; 66 | } 67 | 68 | } // namespace leveldb 69 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/arena.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_ARENA_H_ 6 | #define STORAGE_LEVELDB_UTIL_ARENA_H_ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace leveldb { 14 | 15 | class Arena { 16 | public: 17 | Arena(); 18 | ~Arena(); 19 | 20 | // Return a pointer to a newly allocated memory block of "bytes" bytes. 21 | char* Allocate(size_t bytes); 22 | 23 | // Allocate memory with the normal alignment guarantees provided by malloc 24 | char* AllocateAligned(size_t bytes); 25 | 26 | // Returns an estimate of the total memory usage of data allocated 27 | // by the arena (including space allocated but not yet used for user 28 | // allocations). 29 | size_t MemoryUsage() const { 30 | return blocks_memory_ + blocks_.capacity() * sizeof(char*); 31 | } 32 | 33 | private: 34 | char* AllocateFallback(size_t bytes); 35 | char* AllocateNewBlock(size_t block_bytes); 36 | 37 | // Allocation state 38 | char* alloc_ptr_; 39 | size_t alloc_bytes_remaining_; 40 | 41 | // Array of new[] allocated memory blocks 42 | std::vector blocks_; 43 | 44 | // Bytes of memory in blocks allocated so far 45 | size_t blocks_memory_; 46 | 47 | // No copying allowed 48 | Arena(const Arena&); 49 | void operator=(const Arena&); 50 | }; 51 | 52 | inline char* Arena::Allocate(size_t bytes) { 53 | // The semantics of what to return are a bit messy if we allow 54 | // 0-byte allocations, so we disallow them here (we don't need 55 | // them for our internal use). 56 | assert(bytes > 0); 57 | if (bytes <= alloc_bytes_remaining_) { 58 | char* result = alloc_ptr_; 59 | alloc_ptr_ += bytes; 60 | alloc_bytes_remaining_ -= bytes; 61 | return result; 62 | } 63 | return AllocateFallback(bytes); 64 | } 65 | 66 | } // namespace leveldb 67 | 68 | #endif // STORAGE_LEVELDB_UTIL_ARENA_H_ 69 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/arena_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/arena.h" 6 | 7 | #include "util/random.h" 8 | #include "util/testharness.h" 9 | 10 | namespace leveldb { 11 | 12 | class ArenaTest { }; 13 | 14 | TEST(ArenaTest, Empty) { 15 | Arena arena; 16 | } 17 | 18 | TEST(ArenaTest, Simple) { 19 | std::vector > allocated; 20 | Arena arena; 21 | const int N = 100000; 22 | size_t bytes = 0; 23 | Random rnd(301); 24 | for (int i = 0; i < N; i++) { 25 | size_t s; 26 | if (i % (N / 10) == 0) { 27 | s = i; 28 | } else { 29 | s = rnd.OneIn(4000) ? rnd.Uniform(6000) : 30 | (rnd.OneIn(10) ? rnd.Uniform(100) : rnd.Uniform(20)); 31 | } 32 | if (s == 0) { 33 | // Our arena disallows size 0 allocations. 34 | s = 1; 35 | } 36 | char* r; 37 | if (rnd.OneIn(10)) { 38 | r = arena.AllocateAligned(s); 39 | } else { 40 | r = arena.Allocate(s); 41 | } 42 | 43 | for (int b = 0; b < s; b++) { 44 | // Fill the "i"th allocation with a known bit pattern 45 | r[b] = i % 256; 46 | } 47 | bytes += s; 48 | allocated.push_back(std::make_pair(s, r)); 49 | ASSERT_GE(arena.MemoryUsage(), bytes); 50 | if (i > N/10) { 51 | ASSERT_LE(arena.MemoryUsage(), bytes * 1.10); 52 | } 53 | } 54 | for (int i = 0; i < allocated.size(); i++) { 55 | size_t num_bytes = allocated[i].first; 56 | const char* p = allocated[i].second; 57 | for (int b = 0; b < num_bytes; b++) { 58 | // Check the "i"th allocation for the known bit pattern 59 | ASSERT_EQ(int(p[b]) & 0xff, i % 256); 60 | } 61 | } 62 | } 63 | 64 | } // namespace leveldb 65 | 66 | int main(int argc, char** argv) { 67 | return leveldb::test::RunAllTests(); 68 | } 69 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/crc32c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_CRC32C_H_ 6 | #define STORAGE_LEVELDB_UTIL_CRC32C_H_ 7 | 8 | #include 9 | #include 10 | 11 | namespace leveldb { 12 | namespace crc32c { 13 | 14 | // Return the crc32c of concat(A, data[0,n-1]) where init_crc is the 15 | // crc32c of some string A. Extend() is often used to maintain the 16 | // crc32c of a stream of data. 17 | extern uint32_t Extend(uint32_t init_crc, const char* data, size_t n); 18 | 19 | // Return the crc32c of data[0,n-1] 20 | inline uint32_t Value(const char* data, size_t n) { 21 | return Extend(0, data, n); 22 | } 23 | 24 | static const uint32_t kMaskDelta = 0xa282ead8ul; 25 | 26 | // Return a masked representation of crc. 27 | // 28 | // Motivation: it is problematic to compute the CRC of a string that 29 | // contains embedded CRCs. Therefore we recommend that CRCs stored 30 | // somewhere (e.g., in files) should be masked before being stored. 31 | inline uint32_t Mask(uint32_t crc) { 32 | // Rotate right by 15 bits and add a constant. 33 | return ((crc >> 15) | (crc << 17)) + kMaskDelta; 34 | } 35 | 36 | // Return the crc whose masked representation is masked_crc. 37 | inline uint32_t Unmask(uint32_t masked_crc) { 38 | uint32_t rot = masked_crc - kMaskDelta; 39 | return ((rot >> 17) | (rot << 15)); 40 | } 41 | 42 | } // namespace crc32c 43 | } // namespace leveldb 44 | 45 | #endif // STORAGE_LEVELDB_UTIL_CRC32C_H_ 46 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/crc32c_test.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/crc32c.h" 6 | #include "util/testharness.h" 7 | 8 | namespace leveldb { 9 | namespace crc32c { 10 | 11 | class CRC { }; 12 | 13 | TEST(CRC, StandardResults) { 14 | // From rfc3720 section B.4. 15 | char buf[32]; 16 | 17 | memset(buf, 0, sizeof(buf)); 18 | ASSERT_EQ(0x8a9136aa, Value(buf, sizeof(buf))); 19 | 20 | memset(buf, 0xff, sizeof(buf)); 21 | ASSERT_EQ(0x62a8ab43, Value(buf, sizeof(buf))); 22 | 23 | for (int i = 0; i < 32; i++) { 24 | buf[i] = i; 25 | } 26 | ASSERT_EQ(0x46dd794e, Value(buf, sizeof(buf))); 27 | 28 | for (int i = 0; i < 32; i++) { 29 | buf[i] = 31 - i; 30 | } 31 | ASSERT_EQ(0x113fdb5c, Value(buf, sizeof(buf))); 32 | 33 | unsigned char data[48] = { 34 | 0x01, 0xc0, 0x00, 0x00, 35 | 0x00, 0x00, 0x00, 0x00, 36 | 0x00, 0x00, 0x00, 0x00, 37 | 0x00, 0x00, 0x00, 0x00, 38 | 0x14, 0x00, 0x00, 0x00, 39 | 0x00, 0x00, 0x04, 0x00, 40 | 0x00, 0x00, 0x00, 0x14, 41 | 0x00, 0x00, 0x00, 0x18, 42 | 0x28, 0x00, 0x00, 0x00, 43 | 0x00, 0x00, 0x00, 0x00, 44 | 0x02, 0x00, 0x00, 0x00, 45 | 0x00, 0x00, 0x00, 0x00, 46 | }; 47 | ASSERT_EQ(0xd9963a56, Value(reinterpret_cast(data), sizeof(data))); 48 | } 49 | 50 | TEST(CRC, Values) { 51 | ASSERT_NE(Value("a", 1), Value("foo", 3)); 52 | } 53 | 54 | TEST(CRC, Extend) { 55 | ASSERT_EQ(Value("hello world", 11), 56 | Extend(Value("hello ", 6), "world", 5)); 57 | } 58 | 59 | TEST(CRC, Mask) { 60 | uint32_t crc = Value("foo", 3); 61 | ASSERT_NE(crc, Mask(crc)); 62 | ASSERT_NE(crc, Mask(Mask(crc))); 63 | ASSERT_EQ(crc, Unmask(Mask(crc))); 64 | ASSERT_EQ(crc, Unmask(Unmask(Mask(Mask(crc))))); 65 | } 66 | 67 | } // namespace crc32c 68 | } // namespace leveldb 69 | 70 | int main(int argc, char** argv) { 71 | return leveldb::test::RunAllTests(); 72 | } 73 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/filter_policy.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/filter_policy.h" 6 | 7 | namespace leveldb { 8 | 9 | FilterPolicy::~FilterPolicy() { } 10 | 11 | } // namespace leveldb 12 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/hash.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "util/coding.h" 7 | #include "util/hash.h" 8 | 9 | // The FALLTHROUGH_INTENDED macro can be used to annotate implicit fall-through 10 | // between switch labels. The real definition should be provided externally. 11 | // This one is a fallback version for unsupported compilers. 12 | #ifndef FALLTHROUGH_INTENDED 13 | #define FALLTHROUGH_INTENDED do { } while (0) 14 | #endif 15 | 16 | namespace leveldb { 17 | 18 | uint32_t Hash(const char* data, size_t n, uint32_t seed) { 19 | // Similar to murmur hash 20 | const uint32_t m = 0xc6a4a793; 21 | const uint32_t r = 24; 22 | const char* limit = data + n; 23 | uint32_t h = seed ^ (n * m); 24 | 25 | // Pick up four bytes at a time 26 | while (data + 4 <= limit) { 27 | uint32_t w = DecodeFixed32(data); 28 | data += 4; 29 | h += w; 30 | h *= m; 31 | h ^= (h >> 16); 32 | } 33 | 34 | // Pick up remaining bytes 35 | switch (limit - data) { 36 | case 3: 37 | h += data[2] << 16; 38 | FALLTHROUGH_INTENDED; 39 | case 2: 40 | h += data[1] << 8; 41 | FALLTHROUGH_INTENDED; 42 | case 1: 43 | h += data[0]; 44 | h *= m; 45 | h ^= (h >> r); 46 | break; 47 | } 48 | return h; 49 | } 50 | 51 | 52 | } // namespace leveldb 53 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/hash.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Simple hash function used for internal data structures 6 | 7 | #ifndef STORAGE_LEVELDB_UTIL_HASH_H_ 8 | #define STORAGE_LEVELDB_UTIL_HASH_H_ 9 | 10 | #include 11 | #include 12 | 13 | namespace leveldb { 14 | 15 | extern uint32_t Hash(const char* data, size_t n, uint32_t seed); 16 | 17 | } 18 | 19 | #endif // STORAGE_LEVELDB_UTIL_HASH_H_ 20 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/histogram.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 6 | #define STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | class Histogram { 13 | public: 14 | Histogram() { } 15 | ~Histogram() { } 16 | 17 | void Clear(); 18 | void Add(double value); 19 | void Merge(const Histogram& other); 20 | 21 | std::string ToString() const; 22 | 23 | private: 24 | double min_; 25 | double max_; 26 | double num_; 27 | double sum_; 28 | double sum_squares_; 29 | 30 | enum { kNumBuckets = 154 }; 31 | static const double kBucketLimit[kNumBuckets]; 32 | double buckets_[kNumBuckets]; 33 | 34 | double Median() const; 35 | double Percentile(double p) const; 36 | double Average() const; 37 | double StandardDeviation() const; 38 | }; 39 | 40 | } // namespace leveldb 41 | 42 | #endif // STORAGE_LEVELDB_UTIL_HISTOGRAM_H_ 43 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/logging.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/logging.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "leveldb/env.h" 12 | #include "leveldb/slice.h" 13 | 14 | namespace leveldb { 15 | 16 | void AppendNumberTo(std::string* str, uint64_t num) { 17 | char buf[30]; 18 | snprintf(buf, sizeof(buf), "%llu", (unsigned long long) num); 19 | str->append(buf); 20 | } 21 | 22 | void AppendEscapedStringTo(std::string* str, const Slice& value) { 23 | for (size_t i = 0; i < value.size(); i++) { 24 | char c = value[i]; 25 | if (c >= ' ' && c <= '~') { 26 | str->push_back(c); 27 | } else { 28 | char buf[10]; 29 | snprintf(buf, sizeof(buf), "\\x%02x", 30 | static_cast(c) & 0xff); 31 | str->append(buf); 32 | } 33 | } 34 | } 35 | 36 | std::string NumberToString(uint64_t num) { 37 | std::string r; 38 | AppendNumberTo(&r, num); 39 | return r; 40 | } 41 | 42 | std::string EscapeString(const Slice& value) { 43 | std::string r; 44 | AppendEscapedStringTo(&r, value); 45 | return r; 46 | } 47 | 48 | bool ConsumeChar(Slice* in, char c) { 49 | if (!in->empty() && (*in)[0] == c) { 50 | in->remove_prefix(1); 51 | return true; 52 | } else { 53 | return false; 54 | } 55 | } 56 | 57 | bool ConsumeDecimalNumber(Slice* in, uint64_t* val) { 58 | uint64_t v = 0; 59 | int digits = 0; 60 | while (!in->empty()) { 61 | char c = (*in)[0]; 62 | if (c >= '0' && c <= '9') { 63 | ++digits; 64 | const int delta = (c - '0'); 65 | static const uint64_t kMaxUint64 = ~static_cast(0); 66 | if (v > kMaxUint64/10 || 67 | (v == kMaxUint64/10 && delta > kMaxUint64%10)) { 68 | // Overflow 69 | return false; 70 | } 71 | v = (v * 10) + delta; 72 | in->remove_prefix(1); 73 | } else { 74 | break; 75 | } 76 | } 77 | *val = v; 78 | return (digits > 0); 79 | } 80 | 81 | } // namespace leveldb 82 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/logging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | // 5 | // Must not be included from any .h files to avoid polluting the namespace 6 | // with macros. 7 | 8 | #ifndef STORAGE_LEVELDB_UTIL_LOGGING_H_ 9 | #define STORAGE_LEVELDB_UTIL_LOGGING_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include "port/port.h" 15 | 16 | namespace leveldb { 17 | 18 | class Slice; 19 | class WritableFile; 20 | 21 | // Append a human-readable printout of "num" to *str 22 | extern void AppendNumberTo(std::string* str, uint64_t num); 23 | 24 | // Append a human-readable printout of "value" to *str. 25 | // Escapes any non-printable characters found in "value". 26 | extern void AppendEscapedStringTo(std::string* str, const Slice& value); 27 | 28 | // Return a human-readable printout of "num" 29 | extern std::string NumberToString(uint64_t num); 30 | 31 | // Return a human-readable version of "value". 32 | // Escapes any non-printable characters found in "value". 33 | extern std::string EscapeString(const Slice& value); 34 | 35 | // If *in starts with "c", advances *in past the first character and 36 | // returns true. Otherwise, returns false. 37 | extern bool ConsumeChar(Slice* in, char c); 38 | 39 | // Parse a human-readable number from "*in" into *value. On success, 40 | // advances "*in" past the consumed number and sets "*val" to the 41 | // numeric value. Otherwise, returns false and leaves *in in an 42 | // unspecified state. 43 | extern bool ConsumeDecimalNumber(Slice* in, uint64_t* val); 44 | 45 | } // namespace leveldb 46 | 47 | #endif // STORAGE_LEVELDB_UTIL_LOGGING_H_ 48 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/mutexlock.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 6 | #define STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 7 | 8 | #include "port/port.h" 9 | #include "port/thread_annotations.h" 10 | 11 | namespace leveldb { 12 | 13 | // Helper class that locks a mutex on construction and unlocks the mutex when 14 | // the destructor of the MutexLock object is invoked. 15 | // 16 | // Typical usage: 17 | // 18 | // void MyClass::MyMethod() { 19 | // MutexLock l(&mu_); // mu_ is an instance variable 20 | // ... some complex code, possibly with multiple return paths ... 21 | // } 22 | 23 | class SCOPED_LOCKABLE MutexLock { 24 | public: 25 | explicit MutexLock(port::Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu) 26 | : mu_(mu) { 27 | this->mu_->Lock(); 28 | } 29 | ~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); } 30 | 31 | private: 32 | port::Mutex *const mu_; 33 | // No copying allowed 34 | MutexLock(const MutexLock&); 35 | void operator=(const MutexLock&); 36 | }; 37 | 38 | } // namespace leveldb 39 | 40 | 41 | #endif // STORAGE_LEVELDB_UTIL_MUTEXLOCK_H_ 42 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/options.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "leveldb/options.h" 6 | 7 | #include "leveldb/comparator.h" 8 | #include "leveldb/env.h" 9 | 10 | namespace leveldb { 11 | 12 | Options::Options() 13 | : comparator(BytewiseComparator()), 14 | create_if_missing(false), 15 | error_if_exists(false), 16 | paranoid_checks(false), 17 | env(Env::Default()), 18 | info_log(NULL), 19 | write_buffer_size(4<<20), 20 | max_open_files(1000), 21 | block_cache(NULL), 22 | block_size(4096), 23 | block_restart_interval(16), 24 | compression(kSnappyCompression), 25 | filter_policy(NULL) { 26 | } 27 | 28 | 29 | } // namespace leveldb 30 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/random.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_RANDOM_H_ 6 | #define STORAGE_LEVELDB_UTIL_RANDOM_H_ 7 | 8 | #include 9 | 10 | namespace leveldb { 11 | 12 | // A very simple random number generator. Not especially good at 13 | // generating truly random bits, but good enough for our needs in this 14 | // package. 15 | class Random { 16 | private: 17 | uint32_t seed_; 18 | public: 19 | explicit Random(uint32_t s) : seed_(s & 0x7fffffffu) { } 20 | uint32_t Next() { 21 | static const uint32_t M = 2147483647L; // 2^31-1 22 | static const uint64_t A = 16807; // bits 14, 8, 7, 5, 2, 1, 0 23 | // We are computing 24 | // seed_ = (seed_ * A) % M, where M = 2^31-1 25 | // 26 | // seed_ must not be zero or M, or else all subsequent computed values 27 | // will be zero or M respectively. For all other values, seed_ will end 28 | // up cycling through every number in [1,M-1] 29 | uint64_t product = seed_ * A; 30 | 31 | // Compute (product % M) using the fact that ((x << 31) % M) == x. 32 | seed_ = static_cast((product >> 31) + (product & M)); 33 | // The first reduction may overflow by 1 bit, so we may need to 34 | // repeat. mod == M is not possible; using > allows the faster 35 | // sign-bit-based test. 36 | if (seed_ > M) { 37 | seed_ -= M; 38 | } 39 | return seed_; 40 | } 41 | // Returns a uniformly distributed value in the range [0..n-1] 42 | // REQUIRES: n > 0 43 | uint32_t Uniform(int n) { return Next() % n; } 44 | 45 | // Randomly returns true ~"1/n" of the time, and false otherwise. 46 | // REQUIRES: n > 0 47 | bool OneIn(int n) { return (Next() % n) == 0; } 48 | 49 | // Skewed: pick "base" uniformly from range [0,max_log] and then 50 | // return "base" random bits. The effect is to pick a number in the 51 | // range [0,2^max_log-1] with exponential bias towards smaller numbers. 52 | uint32_t Skewed(int max_log) { 53 | return Uniform(1 << Uniform(max_log + 1)); 54 | } 55 | }; 56 | 57 | } // namespace leveldb 58 | 59 | #endif // STORAGE_LEVELDB_UTIL_RANDOM_H_ 60 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/status.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include 6 | #include "port/port.h" 7 | #include "leveldb/status.h" 8 | 9 | namespace leveldb { 10 | 11 | const char* Status::CopyState(const char* state) { 12 | uint32_t size; 13 | memcpy(&size, state, sizeof(size)); 14 | char* result = new char[size + 5]; 15 | memcpy(result, state, size + 5); 16 | return result; 17 | } 18 | 19 | Status::Status(Code code, const Slice& msg, const Slice& msg2) { 20 | assert(code != kOk); 21 | const uint32_t len1 = msg.size(); 22 | const uint32_t len2 = msg2.size(); 23 | const uint32_t size = len1 + (len2 ? (2 + len2) : 0); 24 | char* result = new char[size + 5]; 25 | memcpy(result, &size, sizeof(size)); 26 | result[4] = static_cast(code); 27 | memcpy(result + 5, msg.data(), len1); 28 | if (len2) { 29 | result[5 + len1] = ':'; 30 | result[6 + len1] = ' '; 31 | memcpy(result + 7 + len1, msg2.data(), len2); 32 | } 33 | state_ = result; 34 | } 35 | 36 | std::string Status::ToString() const { 37 | if (state_ == NULL) { 38 | return "OK"; 39 | } else { 40 | char tmp[30]; 41 | const char* type; 42 | switch (code()) { 43 | case kOk: 44 | type = "OK"; 45 | break; 46 | case kNotFound: 47 | type = "NotFound: "; 48 | break; 49 | case kCorruption: 50 | type = "Corruption: "; 51 | break; 52 | case kNotSupported: 53 | type = "Not implemented: "; 54 | break; 55 | case kInvalidArgument: 56 | type = "Invalid argument: "; 57 | break; 58 | case kIOError: 59 | type = "IO error: "; 60 | break; 61 | default: 62 | snprintf(tmp, sizeof(tmp), "Unknown code(%d): ", 63 | static_cast(code())); 64 | type = tmp; 65 | break; 66 | } 67 | std::string result(type); 68 | uint32_t length; 69 | memcpy(&length, state_, sizeof(length)); 70 | result.append(state_ + 5, length); 71 | return result; 72 | } 73 | } 74 | 75 | } // namespace leveldb 76 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/testharness.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testharness.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | namespace { 16 | struct Test { 17 | const char* base; 18 | const char* name; 19 | void (*func)(); 20 | }; 21 | std::vector* tests; 22 | } 23 | 24 | bool RegisterTest(const char* base, const char* name, void (*func)()) { 25 | if (tests == NULL) { 26 | tests = new std::vector; 27 | } 28 | Test t; 29 | t.base = base; 30 | t.name = name; 31 | t.func = func; 32 | tests->push_back(t); 33 | return true; 34 | } 35 | 36 | int RunAllTests() { 37 | const char* matcher = getenv("LEVELDB_TESTS"); 38 | 39 | int num = 0; 40 | if (tests != NULL) { 41 | for (int i = 0; i < tests->size(); i++) { 42 | const Test& t = (*tests)[i]; 43 | if (matcher != NULL) { 44 | std::string name = t.base; 45 | name.push_back('.'); 46 | name.append(t.name); 47 | if (strstr(name.c_str(), matcher) == NULL) { 48 | continue; 49 | } 50 | } 51 | fprintf(stderr, "==== Test %s.%s\n", t.base, t.name); 52 | (*t.func)(); 53 | ++num; 54 | } 55 | } 56 | fprintf(stderr, "==== PASSED %d tests\n", num); 57 | return 0; 58 | } 59 | 60 | std::string TmpDir() { 61 | std::string dir; 62 | Status s = Env::Default()->GetTestDirectory(&dir); 63 | ASSERT_TRUE(s.ok()) << s.ToString(); 64 | return dir; 65 | } 66 | 67 | int RandomSeed() { 68 | const char* env = getenv("TEST_RANDOM_SEED"); 69 | int result = (env != NULL ? atoi(env) : 301); 70 | if (result <= 0) { 71 | result = 301; 72 | } 73 | return result; 74 | } 75 | 76 | } // namespace test 77 | } // namespace leveldb 78 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/testutil.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #include "util/testutil.h" 6 | 7 | #include "util/random.h" 8 | 9 | namespace leveldb { 10 | namespace test { 11 | 12 | Slice RandomString(Random* rnd, int len, std::string* dst) { 13 | dst->resize(len); 14 | for (int i = 0; i < len; i++) { 15 | (*dst)[i] = static_cast(' ' + rnd->Uniform(95)); // ' ' .. '~' 16 | } 17 | return Slice(*dst); 18 | } 19 | 20 | std::string RandomKey(Random* rnd, int len) { 21 | // Make sure to generate a wide variety of characters so we 22 | // test the boundary conditions for short-key optimizations. 23 | static const char kTestChars[] = { 24 | '\0', '\1', 'a', 'b', 'c', 'd', 'e', '\xfd', '\xfe', '\xff' 25 | }; 26 | std::string result; 27 | for (int i = 0; i < len; i++) { 28 | result += kTestChars[rnd->Uniform(sizeof(kTestChars))]; 29 | } 30 | return result; 31 | } 32 | 33 | 34 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 35 | int len, std::string* dst) { 36 | int raw = static_cast(len * compressed_fraction); 37 | if (raw < 1) raw = 1; 38 | std::string raw_data; 39 | RandomString(rnd, raw, &raw_data); 40 | 41 | // Duplicate the random data until we have filled "len" bytes 42 | dst->clear(); 43 | while (dst->size() < len) { 44 | dst->append(raw_data); 45 | } 46 | dst->resize(len); 47 | return Slice(*dst); 48 | } 49 | 50 | } // namespace test 51 | } // namespace leveldb 52 | -------------------------------------------------------------------------------- /vendor/leveldb-1.12.0/util/testutil.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. See the AUTHORS file for names of contributors. 4 | 5 | #ifndef STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 6 | #define STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 7 | 8 | #include "leveldb/env.h" 9 | #include "leveldb/slice.h" 10 | #include "util/random.h" 11 | 12 | namespace leveldb { 13 | namespace test { 14 | 15 | // Store in *dst a random string of length "len" and return a Slice that 16 | // references the generated data. 17 | extern Slice RandomString(Random* rnd, int len, std::string* dst); 18 | 19 | // Return a random key with the specified length that may contain interesting 20 | // characters (e.g. \x00, \xff, etc.). 21 | extern std::string RandomKey(Random* rnd, int len); 22 | 23 | // Store in *dst a string of length "len" that will compress to 24 | // "N*compressed_fraction" bytes and return a Slice that references 25 | // the generated data. 26 | extern Slice CompressibleString(Random* rnd, double compressed_fraction, 27 | int len, std::string* dst); 28 | 29 | // A wrapper that allows injection of errors. 30 | class ErrorEnv : public EnvWrapper { 31 | public: 32 | bool writable_file_error_; 33 | int num_writable_file_errors_; 34 | 35 | ErrorEnv() : EnvWrapper(Env::Default()), 36 | writable_file_error_(false), 37 | num_writable_file_errors_(0) { } 38 | 39 | virtual Status NewWritableFile(const std::string& fname, 40 | WritableFile** result) { 41 | if (writable_file_error_) { 42 | ++num_writable_file_errors_; 43 | *result = NULL; 44 | return Status::IOError(fname, "fake error"); 45 | } 46 | return target()->NewWritableFile(fname, result); 47 | } 48 | }; 49 | 50 | } // namespace test 51 | } // namespace leveldb 52 | 53 | #endif // STORAGE_LEVELDB_UTIL_TESTUTIL_H_ 54 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/codelength.h: -------------------------------------------------------------------------------- 1 | /* $Id: codelength.h,v 1.3 2011/07/30 13:10:05 nanard Exp $ */ 2 | /* Project : miniupnp 3 | * Author : Thomas BERNARD 4 | * copyright (c) 2005-2011 Thomas Bernard 5 | * This software is subjet to the conditions detailed in the 6 | * provided LICENCE file. */ 7 | #ifndef CODELENGTH_H_INCLUDED 8 | #define CODELENGTH_H_INCLUDED 9 | 10 | /* Encode length by using 7bit per Byte : 11 | * Most significant bit of each byte specifies that the 12 | * following byte is part of the code */ 13 | #define DECODELENGTH(n, p) n = 0; \ 14 | do { n = (n << 7) | (*p & 0x7f); } \ 15 | while((*(p++)&0x80) && (n<(1<<25))); 16 | 17 | #define DECODELENGTH_CHECKLIMIT(n, p, p_limit) \ 18 | n = 0; \ 19 | do { \ 20 | if((p) >= (p_limit)) break; \ 21 | n = (n << 7) | (*(p) & 0x7f); \ 22 | } while((*((p)++)&0x80) && (n<(1<<25))); 23 | 24 | #define CODELENGTH(n, p) if(n>=268435456) *(p++) = (n >> 28) | 0x80; \ 25 | if(n>=2097152) *(p++) = (n >> 21) | 0x80; \ 26 | if(n>=16384) *(p++) = (n >> 14) | 0x80; \ 27 | if(n>=128) *(p++) = (n >> 7) | 0x80; \ 28 | *(p++) = n & 0x7f; 29 | 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/connecthostport.h: -------------------------------------------------------------------------------- 1 | /* $Id: connecthostport.h,v 1.2 2012/06/23 22:32:33 nanard Exp $ */ 2 | /* Project: miniupnp 3 | * http://miniupnp.free.fr/ 4 | * Author: Thomas Bernard 5 | * Copyright (c) 2010-2012 Thomas Bernard 6 | * This software is subjects to the conditions detailed 7 | * in the LICENCE file provided within this distribution */ 8 | #ifndef CONNECTHOSTPORT_H_INCLUDED 9 | #define CONNECTHOSTPORT_H_INCLUDED 10 | 11 | /* connecthostport() 12 | * return a socket connected (TCP) to the host and port 13 | * or -1 in case of error */ 14 | int connecthostport(const char * host, unsigned short port, 15 | unsigned int scope_id); 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/declspec.h: -------------------------------------------------------------------------------- 1 | #ifndef DECLSPEC_H_INCLUDED 2 | #define DECLSPEC_H_INCLUDED 3 | 4 | #if defined(_WIN32) && !defined(STATICLIB) 5 | #ifdef MINIUPNP_EXPORTS 6 | #define LIBSPEC __declspec(dllexport) 7 | #else 8 | #define LIBSPEC __declspec(dllimport) 9 | #endif 10 | #else 11 | #define LIBSPEC 12 | #endif 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/igd_desc_parse.h: -------------------------------------------------------------------------------- 1 | /* $Id: igd_desc_parse.h,v 1.10 2011/04/11 09:19:24 nanard Exp $ */ 2 | /* Project : miniupnp 3 | * http://miniupnp.free.fr/ 4 | * Author : Thomas Bernard 5 | * Copyright (c) 2005-2010 Thomas Bernard 6 | * This software is subject to the conditions detailed in the 7 | * LICENCE file provided in this distribution. 8 | * */ 9 | #ifndef IGD_DESC_PARSE_H_INCLUDED 10 | #define IGD_DESC_PARSE_H_INCLUDED 11 | 12 | /* Structure to store the result of the parsing of UPnP 13 | * descriptions of Internet Gateway Devices */ 14 | #define MINIUPNPC_URL_MAXSIZE (128) 15 | struct IGDdatas_service { 16 | char controlurl[MINIUPNPC_URL_MAXSIZE]; 17 | char eventsuburl[MINIUPNPC_URL_MAXSIZE]; 18 | char scpdurl[MINIUPNPC_URL_MAXSIZE]; 19 | char servicetype[MINIUPNPC_URL_MAXSIZE]; 20 | /*char devicetype[MINIUPNPC_URL_MAXSIZE];*/ 21 | }; 22 | 23 | struct IGDdatas { 24 | char cureltname[MINIUPNPC_URL_MAXSIZE]; 25 | char urlbase[MINIUPNPC_URL_MAXSIZE]; 26 | char presentationurl[MINIUPNPC_URL_MAXSIZE]; 27 | int level; 28 | /*int state;*/ 29 | /* "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" */ 30 | struct IGDdatas_service CIF; 31 | /* "urn:schemas-upnp-org:service:WANIPConnection:1" 32 | * "urn:schemas-upnp-org:service:WANPPPConnection:1" */ 33 | struct IGDdatas_service first; 34 | /* if both WANIPConnection and WANPPPConnection are present */ 35 | struct IGDdatas_service second; 36 | /* "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1" */ 37 | struct IGDdatas_service IPv6FC; 38 | /* tmp */ 39 | struct IGDdatas_service tmp; 40 | }; 41 | 42 | void IGDstartelt(void *, const char *, int); 43 | void IGDendelt(void *, const char *, int); 44 | void IGDdata(void *, const char *, int); 45 | void printIGD(struct IGDdatas *); 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/minisoap.h: -------------------------------------------------------------------------------- 1 | /* $Id: minisoap.h,v 1.4 2010/04/12 20:39:41 nanard Exp $ */ 2 | /* Project : miniupnp 3 | * Author : Thomas Bernard 4 | * Copyright (c) 2005 Thomas Bernard 5 | * This software is subject to the conditions detailed in the 6 | * LICENCE file provided in this distribution. */ 7 | #ifndef MINISOAP_H_INCLUDED 8 | #define MINISOAP_H_INCLUDED 9 | 10 | /*int httpWrite(int, const char *, int, const char *);*/ 11 | int soapPostSubmit(int, const char *, const char *, unsigned short, 12 | const char *, const char *, const char *); 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/minissdpc.h: -------------------------------------------------------------------------------- 1 | /* $Id: minissdpc.h,v 1.1 2007/08/31 15:15:33 nanard Exp $ */ 2 | /* Project: miniupnp 3 | * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ 4 | * Author: Thomas Bernard 5 | * Copyright (c) 2005-2007 Thomas Bernard 6 | * This software is subjects to the conditions detailed 7 | * in the LICENCE file provided within this distribution */ 8 | #ifndef MINISSDPC_H_INCLUDED 9 | #define MINISSDPC_H_INCLUDED 10 | 11 | struct UPNPDev * 12 | getDevicesFromMiniSSDPD(const char * devtype, const char * socketpath); 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/miniupnpcstrings.h.cmake: -------------------------------------------------------------------------------- 1 | #ifndef MINIUPNPCSTRINGS_H_INCLUDED 2 | #define MINIUPNPCSTRINGS_H_INCLUDED 3 | 4 | #define OS_STRING "${CMAKE_SYSTEM_NAME}" 5 | #define MINIUPNPC_VERSION_STRING "${MINIUPNPC_VERSION}" 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/miniupnpctypes.h: -------------------------------------------------------------------------------- 1 | /* $Id: miniupnpctypes.h,v 1.1 2011/02/15 11:10:40 nanard Exp $ */ 2 | /* Miniupnp project : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org 3 | * Author : Thomas Bernard 4 | * Copyright (c) 2011 Thomas Bernard 5 | * This software is subject to the conditions detailed in the 6 | * LICENCE file provided within this distribution */ 7 | #ifndef MINIUPNPCTYPES_H_INCLUDED 8 | #define MINIUPNPCTYPES_H_INCLUDED 9 | 10 | #if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) 11 | #define UNSIGNED_INTEGER unsigned long long 12 | #define STRTOUI strtoull 13 | #else 14 | #define UNSIGNED_INTEGER unsigned int 15 | #define STRTOUI strtoul 16 | #endif 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/miniwget.h: -------------------------------------------------------------------------------- 1 | /* $Id: miniwget.h,v 1.7 2012/06/23 22:35:59 nanard Exp $ */ 2 | /* Project : miniupnp 3 | * Author : Thomas Bernard 4 | * Copyright (c) 2005-2012 Thomas Bernard 5 | * This software is subject to the conditions detailed in the 6 | * LICENCE file provided in this distribution. 7 | * */ 8 | #ifndef MINIWGET_H_INCLUDED 9 | #define MINIWGET_H_INCLUDED 10 | 11 | #include "declspec.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | LIBSPEC void * getHTTPResponse(int s, int * size); 18 | 19 | LIBSPEC void * miniwget(const char *, int *, unsigned int); 20 | 21 | LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int); 22 | 23 | int parseURL(const char *, char *, unsigned short *, char * *, unsigned int *); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/minixml.h: -------------------------------------------------------------------------------- 1 | /* $Id: minixml.h,v 1.6 2006/11/30 11:47:21 nanard Exp $ */ 2 | /* minimal xml parser 3 | * 4 | * Project : miniupnp 5 | * Website : http://miniupnp.free.fr/ 6 | * Author : Thomas Bernard 7 | * Copyright (c) 2005 Thomas Bernard 8 | * This software is subject to the conditions detailed in the 9 | * LICENCE file provided in this distribution. 10 | * */ 11 | #ifndef MINIXML_H_INCLUDED 12 | #define MINIXML_H_INCLUDED 13 | #define IS_WHITE_SPACE(c) ((c==' ') || (c=='\t') || (c=='\r') || (c=='\n')) 14 | 15 | /* if a callback function pointer is set to NULL, 16 | * the function is not called */ 17 | struct xmlparser { 18 | const char *xmlstart; 19 | const char *xmlend; 20 | const char *xml; /* pointer to current character */ 21 | int xmlsize; 22 | void * data; 23 | void (*starteltfunc) (void *, const char *, int); 24 | void (*endeltfunc) (void *, const char *, int); 25 | void (*datafunc) (void *, const char *, int); 26 | void (*attfunc) (void *, const char *, int, const char *, int); 27 | }; 28 | 29 | /* parsexml() 30 | * the xmlparser structure must be initialized before the call 31 | * the following structure members have to be initialized : 32 | * xmlstart, xmlsize, data, *func 33 | * xml is for internal usage, xmlend is computed automatically */ 34 | void parsexml(struct xmlparser *); 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/portlistingparse.h: -------------------------------------------------------------------------------- 1 | /* $Id: portlistingparse.h,v 1.5 2012/01/21 13:30:33 nanard Exp $ */ 2 | /* MiniUPnP project 3 | * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ 4 | * (c) 2011-2012 Thomas Bernard 5 | * This software is subject to the conditions detailed 6 | * in the LICENCE file provided within the distribution */ 7 | #ifndef PORTLISTINGPARSE_H_INCLUDED 8 | #define PORTLISTINGPARSE_H_INCLUDED 9 | 10 | #include "declspec.h" 11 | /* for the definition of UNSIGNED_INTEGER */ 12 | #include "miniupnpctypes.h" 13 | 14 | #if defined(NO_SYS_QUEUE_H) || defined(_WIN32) || defined(__HAIKU__) 15 | #include "bsdqueue.h" 16 | #else 17 | #include 18 | #endif 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /* sample of PortMappingEntry : 25 | 26 | 202.233.2.1 27 | 2345 28 | TCP 29 | 2345 30 | 192.168.1.137 31 | 1 32 | dooom 33 | 345 34 | 35 | */ 36 | typedef enum { PortMappingEltNone, 37 | PortMappingEntry, NewRemoteHost, 38 | NewExternalPort, NewProtocol, 39 | NewInternalPort, NewInternalClient, 40 | NewEnabled, NewDescription, 41 | NewLeaseTime } portMappingElt; 42 | 43 | struct PortMapping { 44 | LIST_ENTRY(PortMapping) entries; 45 | UNSIGNED_INTEGER leaseTime; 46 | unsigned short externalPort; 47 | unsigned short internalPort; 48 | char remoteHost[64]; 49 | char internalClient[64]; 50 | char description[64]; 51 | char protocol[4]; 52 | unsigned char enabled; 53 | }; 54 | 55 | struct PortMappingParserData { 56 | LIST_HEAD(portmappinglisthead, PortMapping) head; 57 | portMappingElt curelt; 58 | }; 59 | 60 | LIBSPEC void 61 | ParsePortListing(const char * buffer, int bufsize, 62 | struct PortMappingParserData * pdata); 63 | 64 | LIBSPEC void 65 | FreePortListing(struct PortMappingParserData * pdata); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/receivedata.h: -------------------------------------------------------------------------------- 1 | /* $Id: receivedata.h,v 1.3 2012/06/23 22:34:47 nanard Exp $ */ 2 | /* Project: miniupnp 3 | * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ 4 | * Author: Thomas Bernard 5 | * Copyright (c) 2011-2012 Thomas Bernard 6 | * This software is subjects to the conditions detailed 7 | * in the LICENCE file provided within this distribution */ 8 | #ifndef RECEIVEDATA_H_INCLUDED 9 | #define RECEIVEDATA_H_INCLUDED 10 | 11 | /* Reads data from the specified socket. 12 | * Returns the number of bytes read if successful, zero if no bytes were 13 | * read or if we timed out. Returns negative if there was an error. */ 14 | int receivedata(int socket, 15 | char * data, int length, 16 | int timeout, unsigned int * scope_id); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/testigddescparse.c: -------------------------------------------------------------------------------- 1 | /* $Id: testigddescparse.c,v 1.4 2012/06/28 18:52:12 nanard Exp $ */ 2 | /* Project : miniupnp 3 | * http://miniupnp.free.fr/ 4 | * Author : Thomas Bernard 5 | * Copyright (c) 2008-2012 Thomas Bernard 6 | * This software is subject to the conditions detailed in the 7 | * LICENCE file provided in this distribution. 8 | * */ 9 | #include 10 | #include 11 | #include 12 | #include "igd_desc_parse.h" 13 | #include "minixml.h" 14 | #include "miniupnpc.h" 15 | 16 | int test_igd_desc_parse(char * buffer, int len) 17 | { 18 | struct IGDdatas igd; 19 | struct xmlparser parser; 20 | struct UPNPUrls urls; 21 | memset(&igd, 0, sizeof(struct IGDdatas)); 22 | memset(&parser, 0, sizeof(struct xmlparser)); 23 | parser.xmlstart = buffer; 24 | parser.xmlsize = len; 25 | parser.data = &igd; 26 | parser.starteltfunc = IGDstartelt; 27 | parser.endeltfunc = IGDendelt; 28 | parser.datafunc = IGDdata; 29 | parsexml(&parser); 30 | printIGD(&igd); 31 | GetUPNPUrls(&urls, &igd, "http://fake/desc/url/file.xml", 0); 32 | printf("ipcondescURL='%s'\n", urls.ipcondescURL); 33 | printf("controlURL='%s'\n", urls.controlURL); 34 | printf("controlURL_CIF='%s'\n", urls.controlURL_CIF); 35 | FreeUPNPUrls(&urls); 36 | return 0; 37 | } 38 | 39 | int main(int argc, char * * argv) 40 | { 41 | FILE * f; 42 | char * buffer; 43 | int len; 44 | int r = 0; 45 | if(argc<2) { 46 | fprintf(stderr, "Usage: %s file.xml\n", argv[0]); 47 | return 1; 48 | } 49 | f = fopen(argv[1], "r"); 50 | if(!f) { 51 | fprintf(stderr, "Cannot open %s for reading.\n", argv[1]); 52 | return 1; 53 | } 54 | fseek(f, 0, SEEK_END); 55 | len = ftell(f); 56 | fseek(f, 0, SEEK_SET); 57 | buffer = malloc(len); 58 | fread(buffer, 1, len, f); 59 | fclose(f); 60 | r = test_igd_desc_parse(buffer, len); 61 | free(buffer); 62 | return r; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/testminiwget.c: -------------------------------------------------------------------------------- 1 | /* $Id: testminiwget.c,v 1.4 2012/06/23 22:35:59 nanard Exp $ */ 2 | /* Project : miniupnp 3 | * Author : Thomas Bernard 4 | * Copyright (c) 2005-2012 Thomas Bernard 5 | * This software is subject to the conditions detailed in the 6 | * LICENCE file provided in this distribution. 7 | * */ 8 | #include 9 | #include 10 | #include "miniwget.h" 11 | 12 | /** 13 | * This program uses the miniwget / miniwget_getaddr function 14 | * from miniwget.c in order to retreive a web ressource using 15 | * a GET HTTP method, and store it in a file. 16 | */ 17 | int main(int argc, char * * argv) 18 | { 19 | void * data; 20 | int size, writtensize; 21 | FILE *f; 22 | char addr[64]; 23 | 24 | if(argc < 3) { 25 | fprintf(stderr, "Usage:\t%s url file\n", argv[0]); 26 | fprintf(stderr, "Example:\t%s http://www.google.com/ out.html\n", argv[0]); 27 | return 1; 28 | } 29 | data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr), 0); 30 | if(!data) { 31 | fprintf(stderr, "Error fetching %s\n", argv[1]); 32 | return 1; 33 | } 34 | printf("local address : %s\n", addr); 35 | printf("got %d bytes\n", size); 36 | f = fopen(argv[2], "wb"); 37 | if(!f) { 38 | fprintf(stderr, "Cannot open file %s for writing\n", argv[2]); 39 | free(data); 40 | return 1; 41 | } 42 | writtensize = fwrite(data, 1, size, f); 43 | if(writtensize != size) { 44 | fprintf(stderr, "Could only write %d bytes out of %d to %s\n", 45 | writtensize, size, argv[2]); 46 | } else { 47 | printf("%d bytes written to %s\n", writtensize, argv[2]); 48 | } 49 | fclose(f); 50 | free(data); 51 | return 0; 52 | } 53 | 54 | -------------------------------------------------------------------------------- /vendor/miniupnp/miniupnpc/testminixml.c: -------------------------------------------------------------------------------- 1 | /* $Id: testminixml.c,v 1.9 2013/05/14 19:50:49 nanard Exp $ 2 | * MiniUPnP project 3 | * Website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ 4 | * Author : Thomas Bernard. 5 | * Copyright (c) 2005-2013 Thomas Bernard 6 | * 7 | * testminixml.c 8 | * test program for the "minixml" functions. 9 | */ 10 | #include 11 | #include 12 | #include 13 | #include "minixml.h" 14 | #include "igd_desc_parse.h" 15 | 16 | /* ---------------------------------------------------------------------- */ 17 | void printeltname1(void * d, const char * name, int l) 18 | { 19 | int i; 20 | (void)d; 21 | printf("element "); 22 | for(i=0;i 15 | #endif 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | struct NameValue { 22 | LIST_ENTRY(NameValue) entries; 23 | char name[64]; 24 | char value[128]; 25 | }; 26 | 27 | struct NameValueParserData { 28 | LIST_HEAD(listhead, NameValue) head; 29 | char curelt[64]; 30 | char * portListing; 31 | int portListingLength; 32 | int topelt; 33 | const char * cdata; 34 | int cdatalen; 35 | }; 36 | 37 | /* ParseNameValue() */ 38 | void 39 | ParseNameValue(const char * buffer, int bufsize, 40 | struct NameValueParserData * data); 41 | 42 | /* ClearNameValueList() */ 43 | void 44 | ClearNameValueList(struct NameValueParserData * pdata); 45 | 46 | /* GetValueFromNameValueList() */ 47 | char * 48 | GetValueFromNameValueList(struct NameValueParserData * pdata, 49 | const char * Name); 50 | 51 | #if 0 52 | /* GetValueFromNameValueListIgnoreNS() */ 53 | char * 54 | GetValueFromNameValueListIgnoreNS(struct NameValueParserData * pdata, 55 | const char * Name); 56 | #endif 57 | 58 | /* DisplayNameValueList() */ 59 | #ifdef DEBUG 60 | void 61 | DisplayNameValueList(char * buffer, int bufsize); 62 | #endif 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | #endif 69 | 70 | --------------------------------------------------------------------------------