├── .gitattributes ├── frontends ├── CMakeLists.txt └── console │ ├── CMakeLists.txt │ ├── StatsBackend.h │ ├── Logger.h │ ├── Server.h │ └── websocketpp │ ├── client.hpp │ ├── server.hpp │ ├── endpoint_base.hpp │ ├── connection_base.hpp │ ├── common │ ├── platforms.hpp │ ├── chrono.hpp │ ├── regex.hpp │ └── connection_hdl.hpp │ ├── concurrency │ ├── basic.hpp │ └── none.hpp │ ├── version.hpp │ ├── logger │ └── stub.hpp │ └── random │ └── none.hpp ├── python ├── README.md ├── setup.py ├── i2pcpp │ └── util.py └── test.py ├── README.md ├── lib ├── i2p │ ├── c_api │ │ ├── tunnel.cpp │ │ ├── i2p.cpp │ │ ├── util.h │ │ ├── util.cpp │ │ ├── router.cpp │ │ └── db.cpp │ ├── kad │ │ ├── RoutingTable.cpp │ │ └── RoutingTable.h │ ├── handlers │ │ ├── Message.cpp │ │ ├── TunnelData.cpp │ │ ├── TunnelGateway.cpp │ │ ├── VariableTunnelBuild.cpp │ │ ├── DatabaseSearchReply.cpp │ │ ├── VariableTunnelBuildReply.cpp │ │ ├── TunnelData.h │ │ ├── TunnelGateway.h │ │ ├── VariableTunnelBuild.h │ │ ├── DatabaseSearchReply.h │ │ ├── VariableTunnelBuildReply.h │ │ ├── DeliveryStatus.h │ │ ├── Message.h │ │ ├── DatabaseStore.h │ │ └── DeliveryStatus.cpp │ ├── i2np │ │ ├── Garlic.cpp │ │ ├── Garlic.h │ │ ├── DeliveryStatus.cpp │ │ ├── DatabaseSearchReply.cpp │ │ ├── TunnelData.cpp │ │ ├── VariableTunnelBuild.cpp │ │ ├── DatabaseLookup.cpp │ │ ├── VariableTunnelBuildReply.cpp │ │ ├── TunnelGateway.cpp │ │ ├── DeliveryStatus.h │ │ ├── TunnelData.h │ │ ├── TunnelGateway.h │ │ ├── DatabaseStore.cpp │ │ ├── DatabaseSearchReply.h │ │ └── VariableTunnelBuildReply.h │ ├── ProfileManager.cpp │ ├── tunnel │ │ ├── OutboundTunnel.h │ │ ├── InboundTunnel.h │ │ ├── InboundTunnel.cpp │ │ ├── OutboundTunnel.cpp │ │ ├── FollowOnFragment.h │ │ ├── FragmentState.h │ │ ├── FragmentHandler.h │ │ ├── Message.h │ │ ├── Fragment.h │ │ ├── FollowOnFragment.cpp │ │ └── FragmentState.cpp │ ├── Transport.cpp │ ├── statement_guard.h │ ├── ProfileManager.h │ ├── sqlite3cc │ │ ├── util.cc │ │ ├── manipulator.cc │ │ ├── util.h │ │ ├── row.cc │ │ └── manipulator.h │ ├── dht │ │ ├── DHTFacade.cpp │ │ └── DHTFacade.h │ ├── sqlite3cc.h │ ├── Version.cpp │ ├── PeerManager.cpp │ └── PeerManager.h ├── CMakeLists.txt ├── datatypes │ ├── SessionKey.cpp │ ├── LeaseSet.cpp │ ├── ByteArray.cpp │ ├── CMakeLists.txt │ ├── Lease.cpp │ ├── Date.cpp │ ├── Certificate.cpp │ ├── BuildResponseRecord.cpp │ ├── RouterAddress.cpp │ └── RouterIdentity.cpp ├── util │ ├── CMakeLists.txt │ ├── I2PDH.cpp │ └── I2PHMAC.cpp └── ssu │ ├── CMakeLists.txt │ ├── AcknowledgementManager.h │ ├── PeerState.cpp │ ├── InboundMessageState.cpp │ └── OutboundMessageFragments.h ├── share ├── web-console │ ├── transparent.png │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.ttf │ │ └── glyphicons-halflings-regular.woff │ ├── css │ │ └── style.css │ └── index.html ├── genbuild.sh └── schema.sql ├── .gitignore ├── include └── i2pcpp │ ├── util │ ├── I2PDH.h │ ├── Base64.h │ ├── secure_allocator.h │ ├── make_unique.h │ ├── I2PHMAC.h │ └── gzip.h │ ├── Version.h │ ├── LogLevels.h │ ├── datatypes │ ├── SessionKey.h │ ├── RouterHash.h │ ├── Destination.h │ ├── LeaseSet.h │ ├── Datatype.h │ ├── Lease.h │ ├── ByteArray.h │ ├── Date.h │ ├── Certificate.h │ ├── StaticByteArray.h │ ├── Mapping.h │ ├── RouterIdentity.h │ ├── BuildResponseRecord.h │ ├── Endpoint.h │ └── RouterAddress.h │ ├── Callbacks.h │ ├── i2p.h │ ├── c_api │ ├── router.h │ ├── db.h │ └── tunnel.h │ ├── LeaseQuery.h │ ├── Log.h │ ├── Router.h │ └── transports │ └── SSU.h ├── cmake ├── cpp11.cmake ├── FindSQLite3.cmake ├── FindBotan.cmake └── FindPackageMessage.cmake ├── tests └── CMakeLists.txt ├── TODO ├── CMakeLists.txt ├── py └── i2pinit.py └── LICENSE.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | Version.cpp export-subst 2 | -------------------------------------------------------------------------------- /frontends/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(console) 2 | -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | ## python ctypes wrapper for libi2p.so 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # THIS PROJECT IS DISCONTINUED 2 | 3 | Use [i2pd](https://github.com/purplei2p/i2pd) 4 | -------------------------------------------------------------------------------- /lib/i2p/c_api/tunnel.cpp: -------------------------------------------------------------------------------- 1 | #include "../../../include/i2pcpp/c_api/tunnel.h" 2 | 3 | // void i2p_tunnel_build(struct ) 4 | -------------------------------------------------------------------------------- /share/web-console/transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majestrate/i2pcpp/HEAD/share/web-console/transparent.png -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(util) 2 | add_subdirectory(datatypes) 3 | add_subdirectory(ssu) 4 | add_subdirectory(i2p) 5 | -------------------------------------------------------------------------------- /share/web-console/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majestrate/i2pcpp/HEAD/share/web-console/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /share/web-console/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majestrate/i2pcpp/HEAD/share/web-console/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /share/web-console/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/majestrate/i2pcpp/HEAD/share/web-console/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.sh 3 | *.bak 4 | *.log 5 | *.core 6 | *.db 7 | *.swp 8 | *.tgz 9 | .* 10 | *.key 11 | *~ 12 | *.orig 13 | *.me 14 | *.pyc 15 | *.so 16 | -------------------------------------------------------------------------------- /python/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from distutils.core import setup 4 | 5 | 6 | setup(name='libi2p', 7 | version='0.0.0-embreotic', 8 | pacakges=['libi2p']) 9 | -------------------------------------------------------------------------------- /lib/i2p/c_api/i2p.cpp: -------------------------------------------------------------------------------- 1 | #include "../../../include/i2pcpp/i2p.h" 2 | 3 | #include 4 | 5 | void i2p_init() 6 | { 7 | Botan::LibraryInitializer init("thread_safe=true"); 8 | } 9 | -------------------------------------------------------------------------------- /lib/i2p/c_api/util.h: -------------------------------------------------------------------------------- 1 | #ifndef C_API_UTIL_H 2 | #define C_API_UTIL_H 3 | 4 | #include 5 | 6 | i2pcpp::RouterHash i2p_util_to_routerhash(char *hash); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /lib/datatypes/SessionKey.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace i2pcpp { 4 | SessionKey toSessionKey(ByteArray const &b) 5 | { 6 | return toStaticByteArray<32>(b); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /python/i2pcpp/util.py: -------------------------------------------------------------------------------- 1 | from urllib.request import urlopen 2 | 3 | 4 | 5 | def get_external_ip(url='http://ipecho.net/plain'): 6 | f = urlopen(str(url)) 7 | d = f.read() 8 | f.close() 9 | return d.decode('utf-8') 10 | -------------------------------------------------------------------------------- /share/web-console/css/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | /* 3 | background: #252525; 4 | color: #00ff00; 5 | */ 6 | } 7 | 8 | #wrapper { 9 | } 10 | 11 | .col-md-4 { 12 | padding: 10px; 13 | } 14 | 15 | .graph { 16 | margin: 10px; 17 | } -------------------------------------------------------------------------------- /lib/i2p/kad/RoutingTable.cpp: -------------------------------------------------------------------------------- 1 | #include "RoutingTable.h" 2 | 3 | namespace i2pcpp { 4 | namespace Kad { 5 | bool RoutingTable::Entry::operator<(const Entry& e) const 6 | { 7 | return false; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/i2p/c_api/util.cpp: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | #include 4 | 5 | using namespace i2pcpp; 6 | 7 | RouterHash i2p_util_to_routerhash(char *hash) 8 | { 9 | RouterHash rh; 10 | 11 | memcpy(rh.data(), hash, rh.size()); 12 | return rh; 13 | } 14 | -------------------------------------------------------------------------------- /include/i2pcpp/util/I2PDH.h: -------------------------------------------------------------------------------- 1 | #ifndef I2PDH_H 2 | #define I2PDH_H 3 | 4 | namespace Botan { class DL_Group; } 5 | 6 | namespace i2pcpp { 7 | class DH { 8 | public: 9 | static const Botan::DL_Group getGroup(); 10 | }; 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /lib/i2p/handlers/Message.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Message.cpp 3 | * @brief Implements Message.h 4 | */ 5 | #include "Message.h" 6 | 7 | namespace i2pcpp { 8 | namespace Handlers { 9 | Message::Message(RouterContext &ctx) : 10 | m_ctx(ctx) {} 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /include/i2pcpp/Version.h: -------------------------------------------------------------------------------- 1 | #ifndef VERSION_H 2 | #define VERSION_H 3 | 4 | #include 5 | 6 | namespace i2pcpp { 7 | extern const int CLIENT_VERSION; 8 | extern const std::string CLIENT_NAME; 9 | extern const std::string CLIENT_BUILD; 10 | extern const std::string CLIENT_DATE; 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /include/i2pcpp/LogLevels.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGLEVELS_H 2 | #define LOGLEVELS_H 3 | 4 | namespace i2pcpp { 5 | /** 6 | * Defines the level of severity. 7 | */ 8 | enum severity_level 9 | { 10 | debug, 11 | info, 12 | warning, 13 | error, 14 | fatal 15 | }; 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/SessionKey.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SessionKey.h 3 | * @brief Defines the i2pcpp::SessionKey typedef. 4 | */ 5 | #ifndef SESSIONKEY_H 6 | #define SESSIONKEY_H 7 | 8 | #include "StaticByteArray.h" 9 | 10 | namespace i2pcpp { 11 | typedef StaticByteArray<32> SessionKey; 12 | 13 | SessionKey toSessionKey(ByteArray const &b); 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /include/i2pcpp/Callbacks.h: -------------------------------------------------------------------------------- 1 | #ifndef CALLBACKS_H 2 | #define CALLBACKS_H 3 | 4 | #include 5 | #include 6 | 7 | namespace i2pcpp { 8 | struct Callbacks { 9 | std::function querySuccess; 10 | std::function queryFail; 11 | }; 12 | } 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /lib/datatypes/LeaseSet.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace i2pcpp { 4 | LeaseSet::LeaseSet(ByteArrayConstItr &begin, ByteArrayConstItr end) 5 | { 6 | } 7 | 8 | LeaseSet::LeaseSet(Destination const &dst, ByteArray const &encKey, ByteArray const &sigKey) 9 | { 10 | } 11 | 12 | ByteArray LeaseSet::serialize() const 13 | { 14 | return ByteArray(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /include/i2pcpp/i2p.h: -------------------------------------------------------------------------------- 1 | #ifndef I2P_H 2 | #define I2P_H 3 | 4 | #define I2PAPI_VERSION 0 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | /** 14 | * Call this function at the start of your application. 15 | * It must not be called more than one time. 16 | */ 17 | void i2p_init(); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /python/test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Run like this: 4 | # 5 | # LD_LIBRARY_PATH='/path/to/build/directory/out/lib/' ./test.py 6 | # 7 | 8 | from i2pcpp.router import Router 9 | import time 10 | import logging 11 | 12 | logging.basicConfig(level=logging.INFO) 13 | 14 | r = Router(port=11112) 15 | r.import_netdb('/tmp/netDb') 16 | r.start() 17 | try: 18 | while True: 19 | time.sleep(1) 20 | finally: 21 | r.stop() 22 | -------------------------------------------------------------------------------- /lib/i2p/i2np/Garlic.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Garlic.cpp 3 | * @brief Implements Garlic.h 4 | */ 5 | #include "Garlic.h" 6 | 7 | namespace i2pcpp { 8 | namespace I2NP { 9 | ByteArray Garlic::compile() const 10 | { 11 | return ByteArray(); 12 | } 13 | 14 | Garlic Garlic::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) 15 | { 16 | return Garlic(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/RouterHash.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file RouterHash.h 3 | * @brief Defines the i2pcpp::RouterHash typedef. 4 | */ 5 | #ifndef ROUTERHASH_H 6 | #define ROUTERHASH_H 7 | 8 | #include "StaticByteArray.h" 9 | 10 | namespace i2pcpp { 11 | typedef StaticByteArray<32> RouterHash; 12 | 13 | template 14 | inline RouterHash toRouterHash(T const &t) 15 | { 16 | return toStaticByteArray<32>(t); 17 | } 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/Destination.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Destination.h 3 | * @brief Defines the i2pcpp::Destination typedef. 4 | */ 5 | #ifndef DESTINATION_H 6 | #define DESTINATION_H 7 | 8 | #include "StaticByteArray.h" 9 | 10 | namespace i2pcpp { 11 | typedef StaticByteArray<32> Destination; 12 | 13 | template 14 | inline Destination toDestination(T const &t) 15 | { 16 | return toStaticByteArray<32>(t); 17 | } 18 | } 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/LeaseSet.h: -------------------------------------------------------------------------------- 1 | #ifndef LEASESET_H 2 | #define LEASESET_H 3 | 4 | #include "Datatype.h" 5 | #include "Destination.h" 6 | 7 | namespace i2pcpp { 8 | class LeaseSet : public Datatype { 9 | public: 10 | LeaseSet(ByteArrayConstItr &begin, ByteArrayConstItr end); 11 | LeaseSet(Destination const &dst, ByteArray const &encKey, ByteArray const &sigKey); 12 | 13 | virtual ByteArray serialize() const; 14 | }; 15 | } 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /lib/i2p/ProfileManager.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ProfileManager.cpp 3 | * @brief Implements ProfileManager.h 4 | */ 5 | #include "ProfileManager.h" 6 | 7 | #include "RouterContext.h" 8 | 9 | #include 10 | 11 | namespace i2pcpp { 12 | ProfileManager::ProfileManager(RouterContext &ctx) : 13 | m_ctx(ctx) {} 14 | 15 | const RouterInfo ProfileManager::getPeer() 16 | { 17 | return m_ctx.getDatabase()->getRouterInfo(m_ctx.getDatabase()->getRandomRouter()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /include/i2pcpp/c_api/router.h: -------------------------------------------------------------------------------- 1 | #ifndef C_API_ROUTER_H 2 | #define C_API_ROUTER_H 3 | 4 | /** 5 | * Creates a new router instance. 6 | * @param an i2pcpp::Database handle returned from i2p_db_load. 7 | */ 8 | void *i2p_router_new(void *db); 9 | 10 | /** 11 | * Destroys a router instance. 12 | */ 13 | void i2p_router_free(void *router); 14 | 15 | /** 16 | * Starts a router instance. 17 | */ 18 | void i2p_router_start(void *router); 19 | 20 | /** 21 | * Stops a router instance. 22 | */ 23 | void i2p_router_stop(void *router); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/i2pcpp/util/Base64.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE64_H 2 | #define BASE64_H 3 | 4 | #include 5 | #include 6 | 7 | namespace i2pcpp { 8 | namespace Base64 { 9 | bool is_base64(unsigned char c); 10 | 11 | std::string encode(unsigned char *data, size_t length); 12 | template 13 | std::string encode(T x) 14 | { 15 | return encode(x.data(), x.size()); 16 | } 17 | 18 | std::vector decode(std::string const &s); 19 | } 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /cmake/cpp11.cmake: -------------------------------------------------------------------------------- 1 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 2 | set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -stdlib=libc++") 3 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -stdlib=libc++") 4 | set(CMAKE_CXX_FLAGS_MINSIZEREL "-Oz") 5 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-constexpr-not-const") 6 | else("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 7 | message(WARNING "Beware: Only clang is officially supported!") 8 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 9 | endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") 10 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/Datatype.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Datatype.h 3 | * @brief Defines the i2pcpp::Datatype interface. 4 | */ 5 | #ifndef DATATYPE_H 6 | #define DATATYPE_H 7 | 8 | #include "ByteArray.h" 9 | 10 | namespace i2pcpp { 11 | 12 | /** 13 | * Interface for all datatype objects. 14 | */ 15 | class Datatype { 16 | public: 17 | virtual ~Datatype() {}; 18 | 19 | /** 20 | * Serializes this i2pcpp::Datatype into an i2pcpp::ByteArray. 21 | */ 22 | virtual ByteArray serialize() const = 0; 23 | }; 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /lib/util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(util_sources 2 | Base64.cpp 3 | I2PDH.cpp 4 | I2PHMAC.cpp 5 | gzip.cpp 6 | ) 7 | 8 | include(cpp11) 9 | 10 | add_library(util SHARED ${util_sources}) 11 | 12 | include_directories(BEFORE util ${CMAKE_SOURCE_DIR}/include) 13 | 14 | # Botan 15 | include_directories(BEFORE util ${BOTAN_INCLUDE_DIRS}) 16 | target_link_libraries(util "${BOTAN_LIBRARIES}") 17 | 18 | # Boost 19 | include_directories(${Boost_INCLUDE_DIRS}) 20 | target_link_libraries(util ${Boost_LIBRARIES}) 21 | add_definitions(-DBOOST_ALL_DYN_LINK) 22 | 23 | # zlib 24 | include_directories(BEFORE util ${ZLIB_INCLUDE_DIRS}) 25 | target_link_libraries(util "${ZLIB_LIBRARIES}") 26 | -------------------------------------------------------------------------------- /include/i2pcpp/LeaseQuery.h: -------------------------------------------------------------------------------- 1 | #ifndef LEASEQUERY_H 2 | #define LEASEQUERY_H 3 | 4 | #include 5 | 6 | namespace i2pcpp { 7 | class RouterContext; 8 | class LeaseQuerySettings; 9 | 10 | class LeaseQuery { 11 | public: 12 | /** 13 | * Constructor. This will connect the callbacks contained in the LeaseQuerySettings 14 | * to the DHT signals 15 | */ 16 | LeaseQuery(RouterContext const &ctx, Destination const &d, LeaseQuerySettings const &lqs); 17 | 18 | /** 19 | * Initiates a LeaseQuery. 20 | */ 21 | void begin(); 22 | }; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/Lease.h: -------------------------------------------------------------------------------- 1 | #ifndef LEASE_H 2 | #define LEASE_H 3 | 4 | #include "Datatype.h" 5 | #include "Date.h" 6 | #include "RouterHash.h" 7 | 8 | namespace i2pcpp { 9 | class Lease : public Datatype { 10 | public: 11 | Lease(ByteArrayConstItr &begin, ByteArrayConstItr end); 12 | Lease(RouterHash const &gw, uint32_t const &tid, Date const &end); 13 | virtual ByteArray serialize() const; 14 | 15 | RouterHash getGateway() const; 16 | uint32_t getTunnelId() const; 17 | Date getEnd() const; 18 | 19 | private: 20 | RouterHash m_gw; 21 | uint32_t m_tid; 22 | Date m_end; 23 | }; 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /lib/i2p/c_api/router.cpp: -------------------------------------------------------------------------------- 1 | #include "../../../include/i2pcpp/c_api/router.h" 2 | 3 | #include "../../../include/i2pcpp/Router.h" 4 | #include "../../../include/i2pcpp/Database.h" 5 | #include "../../../include/i2pcpp/Callbacks.h" 6 | 7 | #include 8 | 9 | using namespace i2pcpp; 10 | 11 | void *i2p_router_new(void *db) 12 | { 13 | std::shared_ptr db_ptr((Database *)db); 14 | Callbacks cb; 15 | Router *r = new (std::nothrow) Router(db_ptr, cb); 16 | 17 | return r; 18 | } 19 | 20 | void i2p_router_free(void *router) 21 | { 22 | delete (Router *)router; 23 | } 24 | 25 | void i2p_router_start(void *router) 26 | { 27 | ((Router *)router)->start(); 28 | } 29 | 30 | void i2p_router_stop(void *router) 31 | { 32 | ((Router *)router)->stop(); 33 | } 34 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(test_sources 2 | Datatypes.cpp 3 | Dht.cpp 4 | ) 5 | 6 | include(cpp11) 7 | 8 | add_executable(testi2p ${test_sources}) 9 | 10 | # Botan 11 | include_directories(BEFORE testi2p ${BOTAN_INCLUDE_DIRS}) 12 | target_link_libraries(testi2p ${BOTAN_LIBRARIES}) 13 | 14 | # zlib 15 | include_directories(BEFORE testi2p ${ZLIB_INCLUDE_DIRS}) 16 | target_link_libraries(testi2p ${ZLIB_LIBRARIES}) 17 | 18 | # Boost 19 | include_directories(BEFORE testi2p ${Boost_INCLUDE_DIRS}) 20 | target_link_libraries(testi2p ${Boost_LIBRARIES}) 21 | add_definitions(-DBOOST_ALL_DYN_LINK) 22 | 23 | # i2pcpp 24 | include_directories(BEFORE testi2p ${CMAKE_SOURCE_DIR}) 25 | include_directories(BEFORE testi2p ${CMAKE_SOURCE_DIR}/include) 26 | target_link_libraries(testi2p datatypes util i2p) 27 | -------------------------------------------------------------------------------- /lib/datatypes/ByteArray.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ByteArray.cpp 3 | * @brief Implements ByteArray.h. 4 | */ 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | namespace std { 13 | std::ostream& operator<<(std::ostream &s, i2pcpp::ByteArray const &data) 14 | { 15 | for(auto c: data) 16 | s << std::setw(2) << std::setfill('0') << std::hex << (int)c << std::setw(0) << std::dec; 17 | 18 | return s; 19 | } 20 | 21 | std::istream& operator>>(std::istream &s, i2pcpp::ByteArray &data) 22 | { 23 | std::string in(static_cast(std::stringstream() << s.rdbuf()).str()); 24 | boost::algorithm::unhex (in, std::back_inserter(data)); 25 | return s; 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /lib/i2p/tunnel/OutboundTunnel.h: -------------------------------------------------------------------------------- 1 | #ifndef TUNNELOUTBOUNDTUNNEL_H 2 | #define TUNNELOUTBOUNDTUNNEL_H 3 | 4 | #include "Tunnel.h" 5 | 6 | #include 7 | 8 | namespace i2pcpp { 9 | namespace Tunnel { 10 | class OutboundTunnel : public Tunnel { 11 | public: 12 | /** 13 | * Constructs an outbound tunnel given a vector of RouterIdentities \a hops, a \a replyHash, and a \a replyTunnelId. 14 | */ 15 | OutboundTunnel(std::vector const &hops, RouterHash const &replyHash, uint32_t const replyTunnelId); 16 | 17 | /** 18 | * Returns the direction of this tunnel (always outbound). 19 | */ 20 | Tunnel::Direction getDirection() const; 21 | }; 22 | } 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/datatypes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(datatypes_sources 2 | Certificate.cpp 3 | ByteArray.cpp 4 | BuildRecord.cpp 5 | BuildRequestRecord.cpp 6 | BuildResponseRecord.cpp 7 | Date.cpp 8 | Endpoint.cpp 9 | Lease.cpp 10 | LeaseSet.cpp 11 | Mapping.cpp 12 | RouterAddress.cpp 13 | RouterIdentity.cpp 14 | RouterInfo.cpp 15 | SessionKey.cpp 16 | ) 17 | 18 | include(cpp11) 19 | 20 | add_library(datatypes SHARED ${datatypes_sources}) 21 | 22 | include_directories(BEFORE datatypes ${CMAKE_SOURCE_DIR}/include) 23 | 24 | # Botan 25 | include_directories(BEFORE datatypes ${BOTAN_INCLUDE_DIRS}) 26 | target_link_libraries(datatypes "${BOTAN_LIBRARIES}") 27 | 28 | # Boost 29 | include_directories(${Boost_INCLUDE_DIRS}) 30 | target_link_libraries(datatypes ${Boost_LIBRARIES}) 31 | add_definitions(-DBOOST_ALL_DYN_LINK) 32 | -------------------------------------------------------------------------------- /frontends/console/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(i2pd_sources 2 | main.cpp 3 | Logger.cpp 4 | Server.cpp 5 | StatsBackend.cpp 6 | ) 7 | 8 | include(cpp11) 9 | 10 | # websocketpp 11 | add_definitions(-D_WEBSOCKETPP_CPP11_STL_) 12 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 13 | 14 | include_directories(${CMAKE_SOURCE_DIR}/include) 15 | 16 | add_executable(i2pd ${i2pd_sources}) 17 | set_target_properties(i2pd PROPERTIES OUTPUT_NAME i2p) 18 | target_link_libraries(i2pd ssu i2p) 19 | 20 | # Botan 21 | include_directories(BEFORE i2pd ${BOTAN_INCLUDE_DIRS}) 22 | target_link_libraries(i2pd "${BOTAN_LIBRARIES}") 23 | 24 | # Boost 25 | include_directories(BEFORE i2pd ${Boost_INCLUDE_DIRS}) 26 | target_link_libraries(i2pd ${Boost_LIBRARIES}) 27 | 28 | # botan 29 | include_directories(BEFORE i2pd ${BOTAN_INCLUDE_DIRS}) 30 | 31 | add_definitions(-DBOOST_ALL_DYN_LINK) 32 | -------------------------------------------------------------------------------- /include/i2pcpp/util/secure_allocator.h: -------------------------------------------------------------------------------- 1 | #ifndef SECUREALLOCATOR_H 2 | #define SECUREALLOCATOR_H 3 | 4 | namespace i2pcpp { 5 | template 6 | class secure_allocator 7 | { 8 | public: 9 | typedef T value_type; 10 | typedef T* pointer; 11 | typedef std::size_t size_type; 12 | 13 | pointer allocate(size_type n) 14 | { 15 | return static_cast(::operator new(n * sizeof(value_type))); 16 | } 17 | 18 | void deallocate(pointer p, size_type s) noexcept 19 | { 20 | for(size_t i = 0; i != s; ++i) 21 | p[i] = 0; 22 | 23 | ::operator delete((void*)p); 24 | } 25 | }; 26 | } 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /lib/i2p/kad/RoutingTable.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file RoutingTable.h 3 | * @brief Defines the i2pcpp::Kad::RoutingTable class. 4 | */ 5 | 6 | #ifndef KADROUTINGTABLE_H 7 | #define KADROUTINGTABLE_H 8 | 9 | #include 10 | 11 | #include 12 | 13 | #define KEY_SIZE 32 14 | #define NUM_BUCKETS (KEY_SIZE * 8) 15 | #define K_VALUE 20 16 | 17 | namespace i2pcpp { 18 | namespace Kad { 19 | class RoutingTable { 20 | private: 21 | struct Entry { 22 | StaticByteArray<32> key; 23 | RouterInfo value; 24 | 25 | bool operator<(const Entry& e) const; 26 | }; 27 | 28 | typedef std::set bucket_t; 29 | std::array m_buckets; 30 | }; 31 | } 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /lib/i2p/tunnel/InboundTunnel.h: -------------------------------------------------------------------------------- 1 | #ifndef TUNNELINBOUNDTUNNEL_H 2 | #define TUNNELINBOUNDTUNNEL_H 3 | 4 | #include "Tunnel.h" 5 | 6 | #include 7 | 8 | namespace i2pcpp { 9 | namespace Tunnel { 10 | class InboundTunnel : public Tunnel { 11 | public: 12 | /** 13 | * Constructs an inbound tunnel given the current router 14 | * hash \a myHash and the router identities of the hops 15 | * for the tunnel. 16 | */ 17 | InboundTunnel(RouterHash const &myHash, std::vector const &hops = {}); 18 | 19 | /** 20 | * Returns the direction of this tunnel (always inbound). 21 | */ 22 | Tunnel::Direction getDirection() const; 23 | }; 24 | } 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /lib/ssu/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(ssu_sources 2 | AcknowledgementManager.cpp 3 | EstablishmentManager.cpp 4 | EstablishmentState.cpp 5 | InboundMessageState.cpp 6 | InboundMessageFragments.cpp 7 | OutboundMessageFragments.cpp 8 | OutboundMessageState.cpp 9 | Packet.cpp 10 | PacketBuilder.cpp 11 | PacketHandler.cpp 12 | PeerState.cpp 13 | PeerStateList.cpp 14 | Context.cpp 15 | SSU.cpp 16 | ) 17 | 18 | include(cpp11) 19 | 20 | add_library(ssu SHARED ${ssu_sources}) 21 | 22 | include_directories(BEFORE ssu ${CMAKE_SOURCE_DIR}/include) 23 | 24 | # Botan 25 | include_directories(BEFORE ssu ${BOTAN_INCLUDE_DIRS}) 26 | target_link_libraries(ssu "${BOTAN_LIBRARIES}") 27 | 28 | # Boost 29 | include_directories(${Boost_INCLUDE_DIRS}) 30 | target_link_libraries(ssu ${Boost_LIBRARIES}) 31 | add_definitions(-DBOOST_ALL_DYN_LINK) 32 | -------------------------------------------------------------------------------- /lib/i2p/handlers/TunnelData.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file TunnelData.cpp 3 | * @brief Implements TunnelData.h 4 | */ 5 | #include "TunnelData.h" 6 | 7 | #include "../RouterContext.h" 8 | 9 | #include "../i2np/TunnelData.h" 10 | 11 | namespace i2pcpp { 12 | namespace Handlers { 13 | TunnelData::TunnelData(RouterContext &ctx) : 14 | Message(ctx), 15 | m_log(I2P_LOG_CHANNEL("H[TD]")) {} 16 | 17 | void TunnelData::handleMessage(RouterHash const from, I2NP::MessagePtr const msg) 18 | { 19 | std::shared_ptr td = std::dynamic_pointer_cast(msg); 20 | 21 | I2P_LOG_SCOPED_TAG(m_log, "RouterHash", from); 22 | I2P_LOG(m_log, debug) << "received TunnelData message"; 23 | 24 | m_ctx.getSignals().invokeTunnelData(from, td->getTunnelId(), td->getData()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/i2p/handlers/TunnelGateway.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file TunnelGateway.cpp 3 | * @brief Implements TunnelGateway.h 4 | */ 5 | #include "TunnelGateway.h" 6 | 7 | #include "../RouterContext.h" 8 | 9 | #include "../i2np/TunnelGateway.h" 10 | 11 | namespace i2pcpp { 12 | namespace Handlers { 13 | TunnelGateway::TunnelGateway(RouterContext &ctx) : 14 | Message(ctx), 15 | m_log(I2P_LOG_CHANNEL("H[TG]")) {} 16 | 17 | void TunnelGateway::handleMessage(RouterHash const from, I2NP::MessagePtr const msg) 18 | { 19 | std::shared_ptr tg = std::dynamic_pointer_cast(msg); 20 | 21 | I2P_LOG_SCOPED_TAG(m_log, "RouterHash", from); 22 | I2P_LOG(m_log, debug) << "received TunnelGateway message"; 23 | 24 | m_ctx.getSignals().invokeTunnelGatewayData(from, tg->getTunnelId(), tg->getData()); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/util/I2PDH.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace i2pcpp { 6 | const Botan::DL_Group DH::getGroup() 7 | { 8 | const Botan::BigInt p = Botan::BigInt("0x9C05B2AA960D9B97B8931963C9CC9E8C3026E9B8ED92FAD0A69CC886D5BF8015FCADAE31A0AD18FAB3F01B00A358DE237655C4964AFAA2B337E96AD316B9FB1CC564B5AEC5B69A9FF6C3E4548707FEF8503D91DD8602E867E6D35D2235C1869CE2479C3B9D5401DE04E0727FB33D6511285D4CF29538D9E3B6051F5B22CC1C93"); 9 | const Botan::BigInt q = Botan::BigInt("0xA5DFC28FEF4CA1E286744CD8EED9D29D684046B7"); 10 | const Botan::BigInt g = Botan::BigInt("0xC1F4D27D40093B429E962D7223824E0BBC47E7C832A39236FC683AF84889581075FF9082ED32353D4374D7301CDA1D23C431F4698599DDA02451824FF369752593647CC3DDC197DE985E43D136CDCFC6BD5409CD2F450821142A5E6F8EB1C3AB5D0484B8129FCF17BCE4F7F33321C3CB3DBB14A905E7B2B3E93BE4708CBCC82"); 11 | return Botan::DL_Group(p, q, g); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /include/i2pcpp/Log.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Log.h 3 | * @brief Defines the i2pcpp::Log class. 4 | */ 5 | #ifndef LOG_H 6 | #define LOG_H 7 | 8 | #include "LogLevels.h" 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define I2P_LOG(logger, sev) BOOST_LOG_SEV(logger, sev) 17 | #define I2P_LOG_TAG(logger, name, value) logger.add_attribute(name, boost::log::attributes::make_constant(value)) 18 | #define I2P_LOG_SCOPED_TAG(logger, name, value) BOOST_LOG_SCOPED_LOGGER_TAG(logger, name, value) 19 | #define I2P_LOG_CHANNEL(ch) boost::log::keywords::channel = ch 20 | 21 | namespace i2pcpp { 22 | typedef boost::log::sources::severity_channel_logger_mt i2p_logger_mt; 23 | } 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /lib/i2p/Transport.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Transport.cpp 3 | * @brief Implements i2pcpp::Transport. 4 | */ 5 | #include "../../include/i2pcpp/Transport.h" 6 | 7 | namespace i2pcpp { 8 | Transport::~Transport() {} 9 | 10 | boost::signals2::connection Transport::registerEstablishedHandler(EstablishedSignal::slot_type const &eh) 11 | { 12 | return m_establishedSignal.connect(eh); 13 | } 14 | 15 | boost::signals2::connection Transport::registerReceivedHandler(ReceivedSignal::slot_type const &rh) 16 | { 17 | return m_receivedSignal.connect(rh); 18 | } 19 | 20 | boost::signals2::connection Transport::registerFailureSignal(FailureSignal::slot_type const &fs) 21 | { 22 | return m_failureSignal.connect(fs); 23 | } 24 | 25 | boost::signals2::connection Transport::registerDisconnectedSignal(DisconnectedSignal::slot_type const &ds) 26 | { 27 | return m_disconnectedSignal.connect(ds); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/datatypes/Lease.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace i2pcpp { 4 | Lease::Lease(ByteArrayConstItr &begin, ByteArrayConstItr end) 5 | { 6 | if(std::distance(begin, end) != 44) 7 | throw std::runtime_error("malformed lease"); 8 | 9 | std::copy(begin, begin + 32, m_gw.begin()); 10 | begin += 32; 11 | 12 | m_tid = parseUint32(begin); 13 | 14 | m_end = Date(begin, end); 15 | } 16 | 17 | Lease::Lease(RouterHash const &gw, uint32_t const &tid, Date const &end) : 18 | m_gw(gw), 19 | m_tid(tid), 20 | m_end(end) {} 21 | 22 | ByteArray Lease::serialize() const 23 | { 24 | return ByteArray(); 25 | } 26 | 27 | RouterHash Lease::getGateway() const 28 | { 29 | return m_gw; 30 | } 31 | 32 | uint32_t Lease::getTunnelId() const 33 | { 34 | return m_tid; 35 | } 36 | 37 | Date Lease::getEnd() const 38 | { 39 | return m_end; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /share/genbuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This file was copied from the bitcoin-qt project. 4 | 5 | if [ $# -gt 0 ]; then 6 | FILE="$1" 7 | shift 8 | if [ -f "$FILE" ]; then 9 | INFO="$(head -n 1 "$FILE")" 10 | fi 11 | else 12 | echo "Usage: $0 " 13 | exit 1 14 | fi 15 | 16 | if [ -e "$(which git)" -a -d ".git" ]; then 17 | # clean 'dirty' status of touched files that haven't been modified 18 | git diff >/dev/null 2>/dev/null 19 | 20 | # get a string like "v0.6.0-66-g59887e8-dirty" 21 | DESC="$(git describe --dirty 2>/dev/null)" 22 | 23 | # get a string like "2012-04-10 16:27:19 +0200" 24 | TIME="$(git log -n 1 --format="%ci")" 25 | fi 26 | 27 | if [ -n "$DESC" ]; then 28 | NEWINFO="#define BUILD_DESC \"$DESC\" \ 29 | #define BUILD_DATE \"$TIME\"" 30 | else 31 | NEWINFO="// No build information available" 32 | fi 33 | 34 | # only update build.h if necessary 35 | if [ "$INFO" != "$NEWINFO" ]; then 36 | echo "$NEWINFO" >"$FILE" 37 | fi 38 | -------------------------------------------------------------------------------- /lib/datatypes/Date.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Date.cpp 3 | * @brief Implements Date.h. 4 | */ 5 | #include 6 | 7 | #include 8 | 9 | namespace i2pcpp { 10 | Date::Date() : 11 | m_value(std::chrono::duration_cast( 12 | std::chrono::system_clock::now().time_since_epoch()).count() 13 | ) {} 14 | 15 | Date::Date(const uint64_t &value) : 16 | m_value(value) {} 17 | 18 | Date::Date(ByteArrayConstItr &begin, ByteArrayConstItr end) 19 | { 20 | if(std::distance(begin, end) < 8) throw std::runtime_error("malformed date"); 21 | 22 | m_value = 0; 23 | 24 | for(int i = sizeof(uint64_t); i > 0; i--) 25 | m_value = (m_value << 8) + (*(begin++)); 26 | } 27 | 28 | ByteArray Date::serialize() const 29 | { 30 | ByteArray v; 31 | 32 | for(int i = sizeof(uint64_t); i > 0; i--) 33 | v.push_back((m_value >> ((i - 1) * 8))); 34 | 35 | return v; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/i2p/handlers/VariableTunnelBuild.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file VariableTunnelBuild.cpp 3 | * @brief Implements VariableTunnelBuild.h 4 | */ 5 | #include "VariableTunnelBuild.h" 6 | 7 | #include "../Signals.h" 8 | #include "../RouterContext.h" 9 | 10 | #include "../i2np/VariableTunnelBuild.h" 11 | 12 | namespace i2pcpp { 13 | namespace Handlers { 14 | VariableTunnelBuild::VariableTunnelBuild(RouterContext &ctx) : 15 | Message(ctx), 16 | m_log(I2P_LOG_CHANNEL("H[VTB]")) {} 17 | 18 | void VariableTunnelBuild::handleMessage(RouterHash const from, I2NP::MessagePtr const msg) 19 | { 20 | std::shared_ptr vtb = std::dynamic_pointer_cast(msg); 21 | 22 | I2P_LOG_SCOPED_TAG(m_log, "RouterHash", from); 23 | I2P_LOG(m_log, debug) << "received VariableTunnelBuild message"; 24 | 25 | m_ctx.getSignals().invokeTunnelRecordsReceived(vtb->getMsgId(), vtb->getRecords()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/i2p/handlers/DatabaseSearchReply.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DatabaseSearchReply.cpp 3 | * @brief Implements DatabaseSearchReply.h 4 | */ 5 | #include "DatabaseSearchReply.h" 6 | 7 | #include "../RouterContext.h" 8 | 9 | #include "../i2np/DatabaseSearchReply.h" 10 | #include "../i2np/DatabaseLookup.h" 11 | 12 | namespace i2pcpp { 13 | namespace Handlers { 14 | DatabaseSearchReply::DatabaseSearchReply(RouterContext &ctx) : 15 | Message(ctx), 16 | m_log(I2P_LOG_CHANNEL("H[DSR]")) {} 17 | 18 | void DatabaseSearchReply::handleMessage(RouterHash const from, I2NP::MessagePtr const msg) 19 | { 20 | std::shared_ptr dsr = std::dynamic_pointer_cast(msg); 21 | 22 | I2P_LOG_SCOPED_TAG(m_log, "RouterHash", from); 23 | I2P_LOG(m_log, debug) << "received DatabaseSearchReply message"; 24 | 25 | m_ctx.getSignals().invokeSearchReply(from, dsr->getKey(), dsr->getHashes()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/i2p/statement_guard.h: -------------------------------------------------------------------------------- 1 | #include "sqlite3cc/basic_statement.h" 2 | 3 | namespace i2pcpp { 4 | class statement_guard { 5 | std::shared_ptr m_statement; 6 | 7 | void bind() {} 8 | 9 | template 10 | void bind(T&& t) 11 | { 12 | *m_statement << t; 13 | } 14 | 15 | template 16 | void bind(T&& t, U&& ...u) 17 | { 18 | *m_statement << t; 19 | bind(u...); 20 | } 21 | 22 | public: 23 | template 24 | statement_guard(std::shared_ptr s, 25 | Params&&... p) : m_statement(s) 26 | { 27 | bind(std::forward(p)...); 28 | } 29 | 30 | ~statement_guard() 31 | { 32 | m_statement->clear_bindings(); 33 | m_statement->reset(); 34 | } 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /lib/i2p/ProfileManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ProfileManager.h 3 | * @brief Defines the i2pcpp::ProfileManager 4 | */ 5 | #ifndef PROFILEMANAGER_H 6 | #define PROFILEMANAGER_H 7 | 8 | namespace i2pcpp { 9 | class RouterContext; 10 | class RouterInfo; 11 | 12 | /** 13 | * Manages peer profiles. Allows random peer selection. 14 | */ 15 | class ProfileManager { 16 | public: 17 | /** 18 | * Constructs from a reference to the i2pcpp::RouterContext. 19 | */ 20 | ProfileManager(RouterContext &ctx); 21 | ProfileManager(const ProfileManager &) = delete; 22 | ProfileManager& operator=(ProfileManager &) = delete; 23 | 24 | /** 25 | * Randomly selects a peer and returns its RI. 26 | * @return the i2pcpp::RouterInfo structure of the peer 27 | */ 28 | const RouterInfo getPeer(); 29 | 30 | private: 31 | RouterContext& m_ctx; ///< Reference to the router context 32 | }; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/i2p/i2np/Garlic.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Garlic.h 3 | * @brief Defines the i2pcpp::I2NP::Garlic message type. 4 | */ 5 | #ifndef I2NPGARLIC_H 6 | #define I2NPGARLIC_H 7 | 8 | #include "Message.h" 9 | 10 | namespace i2pcpp { 11 | namespace I2NP { 12 | 13 | /** 14 | * Represents a garlic message. These are message that wrap multiple 15 | * i2pcpp::I2NP::Message objects. After decrypting, they consist of 16 | * multiple garlic cloves, containing the I2NP messages. 17 | * @todo actually implement this 18 | */ 19 | class Garlic : public Message { 20 | public: 21 | /* 22 | * Converts an i2pcpp::ByteArray to an i2pcpp::I2NP::Garlic object. 23 | * @todo implement this 24 | */ 25 | static Garlic parse(ByteArrayConstItr &begin, ByteArrayConstItr end); 26 | 27 | protected: 28 | Garlic() = default; 29 | 30 | ByteArray compile() const; 31 | }; 32 | } 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lib/i2p/handlers/VariableTunnelBuildReply.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file VariableTunnelBuildReply.cpp 3 | * @brief Implements VariableTunnelBuildReply.h 4 | */ 5 | #include "VariableTunnelBuildReply.h" 6 | 7 | #include "../Signals.h" 8 | #include "../RouterContext.h" 9 | 10 | #include "../i2np/VariableTunnelBuildReply.h" 11 | 12 | namespace i2pcpp { 13 | namespace Handlers { 14 | VariableTunnelBuildReply::VariableTunnelBuildReply(RouterContext &ctx) : 15 | Message(ctx), 16 | m_log(I2P_LOG_CHANNEL("H[VTBR]")) {} 17 | 18 | void VariableTunnelBuildReply::handleMessage(RouterHash const from, I2NP::MessagePtr const msg) 19 | { 20 | std::shared_ptr vtbr = std::dynamic_pointer_cast(msg); 21 | 22 | I2P_LOG_SCOPED_TAG(m_log, "RouterHash", from); 23 | I2P_LOG(m_log, debug) << "received VariableTunnelBuildReply message"; 24 | 25 | m_ctx.getSignals().invokeTunnelRecordsReceived(vtbr->getMsgId(), vtbr->getRecords()); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /include/i2pcpp/c_api/db.h: -------------------------------------------------------------------------------- 1 | #ifndef C_API_DB_H 2 | #define C_API_DB_H 3 | 4 | /** 5 | * Loads an I2P database. 6 | * @param dbFile The filename of the database to load. 7 | * @return A database handle to be used in subsequent functions. 8 | */ 9 | void *i2p_db_load(char *dbFile); 10 | 11 | /** 12 | * Creates a new I2P database. 13 | */ 14 | void i2p_db_create(char *dbFile); 15 | 16 | /** 17 | * Sets the value of the configuration field \a name to \a value. 18 | */ 19 | void i2p_db_config_set(void *db, char *name, char *value); 20 | 21 | /** 22 | * @return the value of the configuration field \a name 23 | */ 24 | char *i2p_db_config_get(void *db, char *name); 25 | 26 | /** 27 | * @param hash 32 byte RouterHash. 28 | * @return true if the database has RouterInfo for the given 29 | * \a hash, false otherwise. 30 | */ 31 | bool i2p_db_router_exists(void *db, char *hash); 32 | 33 | void * i2p_db_ri_get_rh(void * ri); 34 | 35 | void i2p_db_ri_free(void * ri); 36 | void i2p_db_rh_free(void * rh); 37 | 38 | void * i2p_db_get_ri_via_hash(void * db, char * c_hash_str); 39 | 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /frontends/console/StatsBackend.h: -------------------------------------------------------------------------------- 1 | #ifndef STATSBACKEND_H 2 | #define STATSBACKEND_H 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | namespace sinks = boost::log::sinks; 12 | 13 | struct stats_t { 14 | uint64_t bytes_sent = 0; 15 | uint64_t bytes_recv = 0; 16 | uint32_t peer_count = 0; 17 | uint32_t participating_tunnels = 0; 18 | std::unordered_map i2np_ib; 19 | std::unordered_map i2np_ob; 20 | std::string json(); 21 | }; 22 | 23 | class StatsBackend : public sinks::basic_sink_backend< 24 | sinks::combine_requirements< 25 | sinks::synchronized_feeding 26 | >::type 27 | > 28 | { 29 | public: 30 | void consume(boost::log::record_view const& rec); 31 | 32 | stats_t getStats(); 33 | 34 | private: 35 | mutable std::mutex m_mutex; 36 | stats_t m_stats; 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /lib/i2p/i2np/DeliveryStatus.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DeliveryStatus.cpp 3 | * @brief Implements DeliveryStatus.h 4 | */ 5 | #include "DeliveryStatus.h" 6 | 7 | namespace i2pcpp { 8 | namespace I2NP { 9 | DeliveryStatus::DeliveryStatus(uint32_t msgId, Date timestamp) : 10 | m_msgId(msgId), 11 | m_timestamp(timestamp) {} 12 | 13 | ByteArray DeliveryStatus::compile() const 14 | { 15 | ByteArray b; 16 | 17 | b.insert(b.end(), m_msgId >> 24); 18 | b.insert(b.end(), m_msgId >> 16); 19 | b.insert(b.end(), m_msgId >> 8); 20 | b.insert(b.end(), m_msgId); 21 | 22 | ByteArray ts = m_timestamp.serialize(); 23 | b.insert(b.end(), ts.cbegin(), ts.cend()); 24 | 25 | return b; 26 | } 27 | 28 | DeliveryStatus DeliveryStatus::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) 29 | { 30 | DeliveryStatus ds; 31 | 32 | ds.m_msgId = parseUint32(begin); 33 | 34 | ds.m_timestamp = Date(begin, end); 35 | 36 | return ds; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Refactoring and small changes: 2 | * Comment/document the code and usage (ongoing). 3 | * Convert shared_ptr --> unique_ptr where necessary. 4 | * Double check locking requirements. Ensure that locking is initiated by the object which owns the data to be locked (etc). 5 | * Identify and use c++11 algorithms where possible. 6 | * Handle edge cases in --importdir. 7 | * Write unit tests (ongoing). 8 | * Add exceptions with backtrace support. 9 | * Ensure that unused objects get destroyed (expire tunnels after 10 minutes, etc). 10 | * Add error codes to C API (handle all exceptions). 11 | 12 | New features: 13 | * Implement exploratory tunnel support. 14 | * JSON-RPC(?) and HTML5 control panel. 15 | * NTCP 16 | * DHT 17 | - in-progress table 18 | - max concurrent lookups 19 | - better timeout logic 20 | 21 | Structural changes: 22 | * As part of libssu's initialization, config parameters will need to be passed. These parameters should be stored in a text file (boost propertytree). This obsoletes the `config' table in the libi2p database. 23 | 24 | Ideas to investigate: 25 | * Text based configuration. 26 | * Modification of the Version.cpp/.h system. 27 | -------------------------------------------------------------------------------- /include/i2pcpp/util/make_unique.h: -------------------------------------------------------------------------------- 1 | // http://isocpp.org/files/papers/N3656.txt 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace std { 9 | template struct _Unique_if { 10 | typedef unique_ptr _Single_object; 11 | }; 12 | 13 | template struct _Unique_if { 14 | typedef unique_ptr _Unknown_bound; 15 | }; 16 | 17 | template struct _Unique_if { 18 | typedef void _Known_bound; 19 | }; 20 | 21 | template 22 | typename _Unique_if::_Single_object 23 | make_unique(Args&&... args) { 24 | return unique_ptr(new T(std::forward(args)...)); 25 | } 26 | 27 | template 28 | typename _Unique_if::_Unknown_bound 29 | make_unique(size_t n) { 30 | typedef typename remove_extent::type U; 31 | return unique_ptr(new U[n]()); 32 | } 33 | 34 | template 35 | typename _Unique_if::_Known_bound 36 | make_unique(Args&&...) = delete; 37 | } 38 | -------------------------------------------------------------------------------- /lib/i2p/sqlite3cc/util.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * util.cc 3 | * 4 | * Copyright (C) 2009 Tim Marston 5 | * 6 | * This file is part of sqlite3cc (hereafter referred to as "this program"). 7 | * See http://ed.am/dev/sqlite3cc for more information. 8 | * 9 | * This program is free software: you can redistribute it and/or modify it under 10 | * the terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include 24 | 25 | 26 | int sqlite::threadsafe() 27 | { 28 | return sqlite3_threadsafe(); 29 | } 30 | 31 | 32 | extern "C" void libsqlite3cc_is_present( void ) 33 | { 34 | } 35 | -------------------------------------------------------------------------------- /lib/i2p/handlers/TunnelData.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file TunnelData.h 3 | * @brief Defines the i2pcpp::Handlers::TunnelData handler. 4 | */ 5 | #ifndef HANDLERSTUNNELDATA_H 6 | #define HANDLERSTUNNELDATA_H 7 | 8 | #include "Message.h" 9 | 10 | namespace i2pcpp { 11 | namespace Handlers { 12 | 13 | /** 14 | * Handles tunnel data messages. 15 | */ 16 | class TunnelData : public Message { 17 | public: 18 | /** 19 | * Constructs from a reference to the i2pcpp::RouterContext 20 | * object. 21 | */ 22 | TunnelData(RouterContext &ctx); 23 | 24 | /** 25 | * Handles the tunnel data message by invoking the appropriate 26 | * signal. 27 | * @param from the sending router 28 | * @param msg the actual i2pcpp::I2NP::Message object 29 | */ 30 | void handleMessage(RouterHash const from, I2NP::MessagePtr const msg); 31 | 32 | private: 33 | i2p_logger_mt m_log; ///< Logging object 34 | }; 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(i2pcpp CXX C) 2 | cmake_minimum_required(VERSION 2.8.11) 3 | 4 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/bin) 5 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out/lib) 6 | set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 7 | set(CMAKE_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/cmake) 8 | 9 | # --- EXTERNAL LIBRARIES --- 10 | 11 | # pthreads 12 | find_package(Threads) 13 | 14 | # zlib 15 | find_package(ZLIB REQUIRED) 16 | 17 | # Boost 18 | set(Boost_USE_STATIC_LIBS OFF) 19 | set(Boost_USE_MULTITHREADED ON) 20 | set(Boost_USE_STATIC_RUNTIME OFF) 21 | find_package(Boost 1.55.0 REQUIRED COMPONENTS system thread filesystem chrono date_time log program_options OPTIONAL_COMPONENTS unit_test_framework) 22 | 23 | # Sqlite3 24 | find_package(SQLite3 REQUIRED) 25 | 26 | # Botan 27 | find_package(Botan REQUIRED) 28 | 29 | # --- INTERNAL COMPONENTS --- 30 | 31 | # libs 32 | add_subdirectory(lib) 33 | 34 | # frontends 35 | add_subdirectory(frontends) 36 | 37 | # tests 38 | if(NOT DEFINED I2PCPP_SKIP_TESTS) 39 | add_subdirectory(tests) 40 | enable_testing() 41 | add_test(all "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/testi2p") 42 | endif(NOT DEFINED I2PCPP_SKIP_TESTS) 43 | -------------------------------------------------------------------------------- /lib/i2p/handlers/TunnelGateway.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file TunnelGateway.h 3 | * @brief Defines the i2pcpp::Handlers::TunnelGateway handler. 4 | */ 5 | #ifndef HANDLERSTUNNELGATEWAY_H 6 | #define HANDLERSTUNNELGATEWAY_H 7 | 8 | #include "Message.h" 9 | 10 | namespace i2pcpp { 11 | namespace Handlers { 12 | 13 | /** 14 | * Handles tunnel gateway messages. 15 | */ 16 | class TunnelGateway : public Message { 17 | public: 18 | /** 19 | * Constructs from a reference to the i2pcpp::RouterContext 20 | * object. 21 | */ 22 | TunnelGateway(RouterContext &ctx); 23 | 24 | /** 25 | * Handles the tunnel gateway message by invoking the appropriate 26 | * signal. 27 | * @param from the sending router 28 | * @param msg the actual i2pcpp::I2NP::Message object 29 | */ 30 | void handleMessage(RouterHash const from, I2NP::MessagePtr const msg); 31 | 32 | private: 33 | i2p_logger_mt m_log; ///< Logging object 34 | }; 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /include/i2pcpp/util/I2PHMAC.h: -------------------------------------------------------------------------------- 1 | #ifndef I2PHMAC_H 2 | #define I2PHMAC_H 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | namespace i2pcpp { 10 | class I2PHMAC : public Botan::MessageAuthenticationCode { 11 | public: 12 | void clear(); 13 | std::string name() const; 14 | Botan::MessageAuthenticationCode* clone() const; 15 | size_t output_length() const { return hash->output_length(); } 16 | Botan::Key_Length_Specification key_spec() const 17 | { 18 | return Botan::Key_Length_Specification(0, 512); 19 | } 20 | 21 | I2PHMAC(Botan::HashFunction* hash); 22 | 23 | I2PHMAC(const I2PHMAC&) = delete; 24 | I2PHMAC& operator=(const I2PHMAC&) = delete; 25 | 26 | ~I2PHMAC() { delete hash; } 27 | 28 | private: 29 | void add_data(const Botan::byte[], size_t); 30 | void final_result(Botan::byte[]); 31 | void key_schedule(const Botan::byte[], size_t); 32 | 33 | Botan::HashFunction* hash; 34 | Botan::secure_vector i_key, o_key; 35 | }; 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/i2p/dht/DHTFacade.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DHTFacade.cpp 3 | * @brief Implements DHTFacade.h 4 | */ 5 | #include "DHTFacade.h" 6 | 7 | #include "RouterContext.h" 8 | #include 9 | 10 | #include 11 | 12 | namespace i2pcpp { 13 | namespace DHT { 14 | 15 | DHTFacade::DHTFacade(boost::asio::io_service &ios, 16 | RouterHash const &local, 17 | std::forward_list const &hashes, 18 | RouterContext &ctx) : 19 | m_dht(local), 20 | m_searchManager(ios, ctx) 21 | { 22 | // Populate the DHT 23 | for(const auto& h: hashes) 24 | m_dht.insert(DHT::Kademlia::makeKey(h), h); 25 | } 26 | 27 | 28 | bool DHTFacade::lookup(const RouterHash& hash) 29 | { 30 | auto results = m_dht.find(DHT::Kademlia::makeKey(hash)); 31 | if(std::distance(results.first, results.second) < 1) 32 | return false; 33 | 34 | m_searchManager.createSearch(hash, results); 35 | } 36 | 37 | SearchManager& DHTFacade::getSearchManager() 38 | { 39 | return m_searchManager; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lib/i2p/handlers/VariableTunnelBuild.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file VariableTunnelBuild.h 3 | * @brief Defines the i2pcpp::Handlers::VariableTunnelBuild handler. 4 | */ 5 | #ifndef HANDLERSVARIABLETUNNELBUILD_H 6 | #define HANDLERSVARIABLETUNNELBUILD_H 7 | 8 | #include "Message.h" 9 | 10 | namespace i2pcpp { 11 | namespace Handlers { 12 | /** 13 | * Handles variable tunnel build messages. 14 | */ 15 | class VariableTunnelBuild : public Message { 16 | public: 17 | 18 | /** 19 | * Constructs from a reference to the i2pcpp::RouterContext 20 | * object. 21 | */ 22 | VariableTunnelBuild(RouterContext &ctx); 23 | 24 | /** 25 | * Handles the variable tunnel tunnel build message by invoking 26 | * the appropriate signal. 27 | * @param from the sending router 28 | * @param msg the actual i2pcpp::I2NP::Message object 29 | */ 30 | void handleMessage(RouterHash const from, I2NP::MessagePtr const msg); 31 | 32 | private: 33 | i2p_logger_mt m_log; ///< Logging object 34 | }; 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/i2p/handlers/DatabaseSearchReply.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DatabaseSearchReply.h 3 | * @brief Defines the i2pcpp::Handlers::DatabaseSearchReply handler. 4 | */ 5 | #ifndef HANDLERSDATABASESEARCHREPLY_H 6 | #define HANDLERSDATABASESEARCHREPLY_H 7 | 8 | #include "Message.h" 9 | 10 | namespace i2pcpp { 11 | namespace Handlers { 12 | 13 | /** 14 | * Handles reponses to database search messages. 15 | */ 16 | class DatabaseSearchReply : public Message { 17 | public: 18 | /** 19 | * Constructs from a reference to the i2pcpp::RouterContext 20 | * object. 21 | */ 22 | DatabaseSearchReply(RouterContext &ctx); 23 | 24 | /** 25 | * Handles the database search response message by invoking the appropriate 26 | * signal. 27 | * @param from the sending router 28 | * @param msg the actual i2pcpp::I2NP::Message object 29 | */ 30 | void handleMessage(RouterHash const from, I2NP::MessagePtr const msg); 31 | 32 | private: 33 | i2p_logger_mt m_log; ///< Logging object 34 | }; 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/i2p/sqlite3cc/manipulator.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * manipulator.cc 3 | * 4 | * Copyright (C) 2009 Tim Marston 5 | * 6 | * This file is part of sqlite3cc (hereafter referred to as "this program"). 7 | * See http://ed.am/dev/sqlite3cc for more information. 8 | * 9 | * This program is free software: you can redistribute it and/or modify it under 10 | * the terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include 24 | 25 | 26 | sqlite::detail::null_t sqlite::null = { }; 27 | 28 | sqlite::detail::exec_t sqlite::exec = { }; 29 | 30 | 31 | sqlite::detail::set_index_t sqlite::set_index( 32 | unsigned int index ) 33 | { 34 | detail::set_index_t t = { index }; 35 | return t; 36 | } 37 | -------------------------------------------------------------------------------- /lib/i2p/handlers/VariableTunnelBuildReply.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file VariableTunnelBuildReply.cpp 3 | * @brief Defines the i2pcpp::Handlers::VariableTunnelBuildReply handler. 4 | */ 5 | #ifndef HANDLERSVARIABLETUNNELBUILDREPLY_H 6 | #define HANDLERSVARIABLETUNNELBUILDREPLY_H 7 | 8 | #include "Message.h" 9 | 10 | namespace i2pcpp { 11 | namespace Handlers { 12 | 13 | /** 14 | * Handles the responses to variable tunnel build messages. 15 | */ 16 | class VariableTunnelBuildReply : public Message { 17 | public: 18 | /** 19 | * Constructs from a reference to the i2pcpp::RouterContext 20 | * object. 21 | */ 22 | VariableTunnelBuildReply(RouterContext &ctx); 23 | 24 | /** 25 | * Handles the response to the variable tunnel build message by 26 | * invoking the appropriate * signal. 27 | * @param from the sending router 28 | * @param msg the actual i2pcpp::I2NP::Message object 29 | */ 30 | void handleMessage(RouterHash const from, I2NP::MessagePtr const msg); 31 | 32 | private: 33 | i2p_logger_mt m_log; ///< Logging object 34 | }; 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /lib/i2p/handlers/DeliveryStatus.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DeliveryStatus.h 3 | * @brief Defines the i2pcpp::Handlers::DeliveryStatus handler. 4 | */ 5 | #ifndef HANDLERSDELIVERYSTATUS_H 6 | #define HANDLERSDELIVERYSTATUS_H 7 | 8 | #include "Message.h" 9 | 10 | namespace i2pcpp { 11 | namespace Handlers { 12 | 13 | /** 14 | * Handles delivery status messages. 15 | */ 16 | class DeliveryStatus : public Message { 17 | public: 18 | /** 19 | * Constructs from a reference to the i2pcpp::RouterContext 20 | * object. 21 | */ 22 | DeliveryStatus(RouterContext &ctx); 23 | 24 | /** 25 | * Handles the delivery status message by sending a 26 | * DatabaseStore message. 27 | * @param from the sending router 28 | * @param msg the actual i2pcpp::I2NP::Message object 29 | * @todo Make this invoke a signal instead, so that it is more 30 | * consistent with the other handlers. 31 | */ 32 | void handleMessage(RouterHash const from, I2NP::MessagePtr const msg); 33 | 34 | private: 35 | i2p_logger_mt m_log; ///< Logging object 36 | }; 37 | } 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /cmake/FindSQLite3.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Sqlite3 2 | # Once done this will define 3 | # 4 | # SQLITE3_FOUND - system has Sqlite3 5 | # SQLITE3_INCLUDE_DIRS - the Sqlite3 include directory 6 | # SQLITE3_LIBRARIES - Link these to use Sqlite3 7 | # SQLITE3_DEFINITIONS - Compiler switches required for using Sqlite3 8 | # 9 | # Hints: 10 | # SQLITE_INCLUDEDIR 11 | # SQLITE_LIBRARYDIR 12 | # 13 | 14 | if (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES) 15 | # in cache already 16 | set(Sqlite3_FIND_QUIETLY TRUE) 17 | endif (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES) 18 | 19 | if (NOT WIN32) 20 | find_package(PkgConfig) 21 | PKG_SEARCH_MODULE(PC_SQLITE3 sqlite3) 22 | set (SQLITE3_DEFINITIONS ${PC_SQLITE3_CFLAGS}) 23 | endif (NOT WIN32) 24 | 25 | find_path(SQLITE3_INCLUDE_DIR sqlite3.h 26 | HINTS 27 | ${SQLITE3_INCLUDEDIR} 28 | ${PC_SQLITE3_INCLUDEDIR} 29 | ${PC_SQLITE3_INCLUDE_DIRS} 30 | ) 31 | 32 | find_library(SQLITE3_LIBRARY sqlite3 33 | HINTS 34 | ${SQLITE3_LIBRARYDIR} 35 | ${PC_SQLITE3_LIBRARYDIR} 36 | ${PC_SQLITE3_LIBRARY_DIRS} 37 | ) 38 | 39 | mark_as_advanced(SQLITE3_INCLUDE_DIR SQLITE3_LIBRARY) 40 | 41 | include(FindPackageHandleStandardArgs) 42 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Sqlite3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR) 43 | 44 | if(SQLITE3_FOUND) 45 | set(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY}) 46 | seT(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR}) 47 | endif(SQLITE3_FOUND) 48 | -------------------------------------------------------------------------------- /lib/datatypes/Certificate.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Certificate.cpp 3 | * @brief Implements Certificate.h. 4 | */ 5 | #include 6 | 7 | namespace i2pcpp { 8 | Certificate::Certificate() : 9 | m_type(Certificate::Type::NIL) {} 10 | 11 | Certificate::Certificate(ByteArrayConstItr &begin, ByteArrayConstItr end) 12 | { 13 | if(!std::distance(begin, end)) 14 | throw std::runtime_error("malformed certificate"); 15 | 16 | m_type = (Type)*(begin++); 17 | 18 | if(m_type < (Type)0 || m_type > (Type)4) 19 | throw std::runtime_error("malformed certificate type"); 20 | 21 | uint16_t size = parseUint16(begin); 22 | if(std::distance(begin, end) < size) 23 | throw std::runtime_error("malformed certificate size"); 24 | 25 | m_payload.resize(size); 26 | std::copy(begin, begin + size, m_payload.begin()); 27 | begin += size; 28 | } 29 | 30 | uint16_t Certificate::getLength() const 31 | { 32 | return m_payload.size(); 33 | } 34 | 35 | ByteArray Certificate::serialize() const 36 | { 37 | ByteArray b(m_payload); 38 | uint16_t length = m_payload.size(); 39 | 40 | b.insert(b.begin(), length); 41 | b.insert(b.begin(), (length >> 8)); 42 | b.insert(b.begin(), (unsigned char)m_type); 43 | 44 | return b; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/i2p/i2np/DatabaseSearchReply.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DatabaseSearchReply.cpp 3 | * @brief Implements DatabaeSearchReply.h 4 | */ 5 | #include "DatabaseSearchReply.h" 6 | 7 | namespace i2pcpp { 8 | namespace I2NP { 9 | const StaticByteArray<32>& DatabaseSearchReply::getKey() const 10 | { 11 | return m_key; 12 | } 13 | 14 | const std::list& DatabaseSearchReply::getHashes() const 15 | { 16 | return m_hashes; 17 | } 18 | 19 | const RouterHash& DatabaseSearchReply::getFrom() const 20 | { 21 | return m_from; 22 | } 23 | 24 | ByteArray DatabaseSearchReply::compile() const 25 | { 26 | // TODO 27 | return ByteArray(); 28 | } 29 | 30 | DatabaseSearchReply DatabaseSearchReply::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) 31 | { 32 | DatabaseSearchReply dsr; 33 | 34 | std::copy(begin, begin + 32, dsr.m_key.begin()), begin += 32; 35 | 36 | unsigned char size = *(begin++); 37 | while(size--) { 38 | dsr.m_hashes.emplace_back(); 39 | std::copy(begin, begin + 32, dsr.m_hashes.back().begin()), begin += 32; 40 | } 41 | 42 | std::copy(begin, begin + 32, dsr.m_from.begin()), begin += 32; 43 | 44 | return dsr; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/ByteArray.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ByteArray.h 3 | * @brief Defines the i2pcpp::ByteArray type, as well as a number of useful 4 | * typedefs and operators. 5 | */ 6 | #ifndef BYTEARRAY_H 7 | #define BYTEARRAY_H 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace i2pcpp { 15 | /** 16 | * An i2pcpp::ByteArray is a std::vector. 17 | */ 18 | typedef std::vector ByteArray; 19 | typedef std::shared_ptr ByteArrayPtr; 20 | typedef ByteArray::iterator ByteArrayItr; 21 | typedef ByteArray::const_iterator ByteArrayConstItr; 22 | 23 | template 24 | inline ByteArray toByteArray(T const &t) 25 | { 26 | return ByteArray(t.cbegin(), t.cend()); 27 | } 28 | 29 | template 30 | inline uint32_t parseUint32(T &itr) 31 | { 32 | uint32_t x = (itr[0] << 24) | (itr[1] << 16) | (itr[2] << 8) | (itr[3]); 33 | itr += 4; 34 | 35 | return x; 36 | } 37 | 38 | template 39 | inline uint16_t parseUint16(T &itr) 40 | { 41 | uint16_t x = (itr[0] << 8) | (itr[1]); 42 | itr += 2; 43 | 44 | return x; 45 | } 46 | } 47 | 48 | namespace std { 49 | std::ostream& operator<<(std::ostream &s, i2pcpp::ByteArray const &data); 50 | std::istream& operator>>(std::istream &s, i2pcpp::ByteArray &data); 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /lib/i2p/handlers/Message.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Message.h 3 | * @brief Defines the i2pcpp::Handler::Message handler base class. 4 | */ 5 | #ifndef HANDLERSMESSAGE_H 6 | #define HANDLERSMESSAGE_H 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace i2pcpp { 13 | namespace I2NP { class Message; typedef std::shared_ptr MessagePtr; } 14 | 15 | class RouterContext; 16 | 17 | namespace Handlers { 18 | 19 | /** 20 | * Abstract base class for i2pcpp::I2NP::Message object handlers. 21 | */ 22 | class Message { 23 | public: 24 | /** 25 | * Constructs from a reference to the i2pcpp::RouterContext 26 | * object. 27 | */ 28 | Message(RouterContext &ctx); 29 | virtual ~Message() {} 30 | 31 | /** 32 | * Pure virtual handler function. 33 | * @param from the sending router 34 | * @param msg the actual i2pcpp::I2NP::Message object 35 | */ 36 | virtual void handleMessage(RouterHash const from, I2NP::MessagePtr const msg) = 0; 37 | 38 | protected: 39 | /// A reference to the i2pcpp::RouterContext object 40 | RouterContext& m_ctx; 41 | }; 42 | 43 | typedef std::shared_ptr MessagePtr; 44 | } 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /lib/i2p/sqlite3cc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sqlite3cc.h 3 | * 4 | * Copyright (C) 2009 Tim Marston 5 | * 6 | * This file is part of sqlite3cc (hereafter referred to as "this program"). 7 | * See http://ed.am/dev/sqlite3cc for more information. 8 | * 9 | * This program is free software: you can redistribute it and/or modify it under 10 | * the terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef SQLITE3CC_SQLITE3CC_H_ 24 | #define SQLITE3CC_SQLITE3CC_H_ 25 | 26 | 27 | // include common parts of sqlite3cc 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | 39 | #endif /* SQLITE3CC_SQLITE3CC_H_ */ 40 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/Date.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Date.h 3 | * @brief Defines the i2pcpp::Date datatype. 4 | */ 5 | #ifndef DATE_H 6 | #define DATE_H 7 | 8 | #include "Datatype.h" 9 | 10 | namespace i2pcpp { 11 | 12 | /** 13 | * Represents a data as a UNIX timestamp, that is, as the amount of seconds since 14 | * the unix epoch (00:00, January 1, 1970). 15 | */ 16 | class Date : public Datatype { 17 | public: 18 | /** 19 | * Constructs from the current date. 20 | */ 21 | Date(); 22 | 23 | /** 24 | * Constructs a date from a given unix timestamp. 25 | * @param value amount of seconds from the unix epoch 26 | */ 27 | Date(const uint64_t &value); 28 | 29 | /** 30 | * Constructs a date from iterators to the begin and end of an 31 | * i2pcpp::ByteArray. 32 | * This i2pcpp::ByteArray should simply contain 8 bytes. 33 | * @throw i2pcpp::FormattingError 34 | */ 35 | Date(ByteArrayConstItr &begin, ByteArrayConstItr end); 36 | 37 | /** 38 | * Serializes this i2pcpp::Data object as an i2pcpp::ByteArray of 39 | * 8 bytes. 40 | */ 41 | ByteArray serialize() const; 42 | 43 | private: 44 | /// The underlying uint64 representing the timestamp 45 | uint64_t m_value; 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /frontends/console/Logger.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGGER_H 2 | #define LOGGER_H 3 | 4 | #include "StatsBackend.h" 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #define I2P_LOG(logger, sev) BOOST_LOG_SEV(logger, sev) 17 | #define I2P_LOG_TAG(logger, name, value) logger.add_attribute(name, boost::log::attributes::make_constant(value)) 18 | #define I2P_LOG_SCOPED_TAG(logger, name, value) BOOST_LOG_SCOPED_LOGGER_TAG(logger, name, value) 19 | 20 | typedef boost::log::sources::severity_channel_logger_mt i2p_logger_mt; 21 | 22 | class Logger { 23 | public: 24 | static void logToConsole(i2pcpp::severity_level log_level); 25 | static void logToFile(const std::string &file, i2pcpp::severity_level log_level); 26 | 27 | template 28 | static void addBackendToAsyncSink(boost::shared_ptr backend) 29 | { 30 | typedef sinks::asynchronous_sink sink_t; 31 | boost::shared_ptr sink(new sink_t(backend)); 32 | boost::log::core::get()->add_sink(sink); 33 | } 34 | 35 | private: 36 | static void formatter(boost::log::record_view const &rec, boost::log::formatting_ostream &s); 37 | 38 | boost::shared_ptr m_stats; 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /lib/i2p/i2np/TunnelData.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file TunnelData.cpp 3 | * @brief Implements TunnelData.h 4 | */ 5 | #include "TunnelData.h" 6 | 7 | namespace i2pcpp { 8 | namespace I2NP { 9 | TunnelData::TunnelData(uint32_t const tunnelId, StaticByteArray<1024> const &data) : 10 | m_tunnelId(tunnelId), 11 | m_data(data) {} 12 | 13 | uint32_t TunnelData::getTunnelId() const 14 | { 15 | return m_tunnelId; 16 | } 17 | 18 | const StaticByteArray<1024>& TunnelData::getData() const 19 | { 20 | return m_data; 21 | } 22 | 23 | ByteArray TunnelData::compile() const 24 | { 25 | ByteArray b; 26 | 27 | b.insert(b.end(), m_tunnelId >> 24); 28 | b.insert(b.end(), m_tunnelId >> 16); 29 | b.insert(b.end(), m_tunnelId >> 8); 30 | b.insert(b.end(), m_tunnelId); 31 | 32 | b.insert(b.end(), m_data.cbegin(), m_data.cend()); 33 | 34 | return b; 35 | } 36 | 37 | TunnelData TunnelData::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) 38 | { 39 | TunnelData td; 40 | 41 | if(std::distance(begin,end) < (4 + 1024)) 42 | throw std::runtime_error("invalid tunnel data message"); 43 | 44 | td.m_tunnelId = parseUint32(begin); 45 | 46 | std::copy(begin, begin + 1024, td.m_data.begin()); 47 | 48 | return td; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /frontends/console/Server.h: -------------------------------------------------------------------------------- 1 | #ifndef SERVER_H 2 | #define SERVER_H 3 | 4 | #include "Logger.h" 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace wspp = websocketpp; 20 | 21 | class Server { 22 | public: 23 | Server(i2pcpp::Endpoint const &ep); 24 | ~Server(); 25 | 26 | void run(); 27 | void stop(); 28 | 29 | private: 30 | void on_open(wspp::connection_hdl handle); 31 | void on_close(wspp::connection_hdl handle); 32 | 33 | void broadcastStats(stats_t & stats); 34 | void timerCallback(const boost::system::error_code &e); 35 | 36 | i2pcpp::Endpoint m_endpoint; 37 | 38 | std::thread m_serviceThread; 39 | boost::asio::io_service m_ios; 40 | 41 | typedef wspp::server server_t; 42 | server_t m_server; 43 | 44 | std::set> m_controlClients; 45 | std::set> m_statsClients; 46 | 47 | std::mutex m_connectionsMutex; 48 | 49 | boost::shared_ptr m_stats; 50 | boost::asio::deadline_timer m_statsTimer; 51 | 52 | i2p_logger_mt m_log; 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lib/i2p/tunnel/InboundTunnel.cpp: -------------------------------------------------------------------------------- 1 | #include "InboundTunnel.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | namespace i2pcpp { 8 | namespace Tunnel { 9 | InboundTunnel::InboundTunnel(RouterHash const &myHash, std::vector const &hops) 10 | { 11 | /* Zero hop tunnel */ 12 | if(hops.empty()) { 13 | m_state = State::OPERATIONAL; 14 | return; 15 | } 16 | 17 | uint32_t lastTunnelId; 18 | RouterHash lastRouterHash; 19 | BuildRequestRecordPtr h; 20 | 21 | for(int i = 0; i < hops.size(); i++) { 22 | if(!i) { 23 | h = std::make_shared(hops[i], myHash); 24 | m_tunnelId = h->getNextTunnelId(); 25 | m_nextMsgId = h->getNextMsgId(); 26 | } else 27 | h = std::make_shared(hops[i], lastRouterHash, lastTunnelId); 28 | 29 | lastTunnelId = h->getTunnelId(); 30 | lastRouterHash = h->getLocalHash(); 31 | 32 | m_hops.push_front(h); 33 | } 34 | 35 | std::static_pointer_cast(m_hops.front())->setType(BuildRequestRecord::Type::GATEWAY); 36 | 37 | secureRecords(); 38 | } 39 | 40 | Tunnel::Direction InboundTunnel::getDirection() const 41 | { 42 | return Direction::INBOUND; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lib/i2p/i2np/VariableTunnelBuild.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file VariableTunnelBuild.cpp 3 | * @brief Implements VariableTunnelBuild.h 4 | */ 5 | #include "VariableTunnelBuild.h" 6 | 7 | namespace i2pcpp { 8 | namespace I2NP { 9 | VariableTunnelBuild::VariableTunnelBuild(std::list buildRecords) : 10 | m_buildRecords(std::move(buildRecords)) {} 11 | 12 | VariableTunnelBuild::VariableTunnelBuild(uint32_t msgId, std::list buildRecords) : 13 | Message(msgId), 14 | m_buildRecords(std::move(buildRecords)) {} 15 | 16 | std::list VariableTunnelBuild::getRecords() const 17 | { 18 | return m_buildRecords; 19 | } 20 | 21 | ByteArray VariableTunnelBuild::compile() const 22 | { 23 | ByteArray b; 24 | 25 | b.insert(b.end(), m_buildRecords.size()); 26 | for(auto& r: m_buildRecords) { 27 | const ByteArray recordBytes = r->serialize(); 28 | b.insert(b.end(), recordBytes.cbegin(), recordBytes.cend()); 29 | } 30 | 31 | return b; 32 | } 33 | 34 | VariableTunnelBuild VariableTunnelBuild::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) 35 | { 36 | VariableTunnelBuild vtb; 37 | 38 | unsigned char size = *begin++; 39 | 40 | for(int i = 0; i < size; i++) 41 | vtb.m_buildRecords.emplace_back(std::make_shared(begin, end)); 42 | 43 | return vtb; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /include/i2pcpp/c_api/tunnel.h: -------------------------------------------------------------------------------- 1 | #ifndef C_API_TUNNEL_H 2 | #define C_API_TUNNEL_H 3 | 4 | #include 5 | 6 | // self 7 | typedef void (*__tunnel_build_hook)(struct i2p_tunnel_t *) i2p_tunnel_build_hook_t; 8 | // self, data, size 9 | typedef int (*__tunnel_data_hook)(struct i2p_tunnel_t *, void*, size_t) i2p_data_hook_t; 10 | 11 | // 12 | struct i2p_tunnel_t { 13 | 14 | // do not touch 15 | void * _private; 16 | 17 | // build callbacks 18 | i2p_tunnel_build_hook_t timeout; 19 | i2p_tunnel_build_hook_t success; 20 | i2p_tunnel_build_hook_t reject; 21 | 22 | // Outbound tunnels Only (optional) 23 | i2p_data_hook_t send_raw; 24 | 25 | // Inbound tunnels only (optional) 26 | i2p_data_hook_t got_raw; 27 | 28 | // NULL terminated list of RouterIdentities 29 | // NULL for 0 hops 30 | void ** hops_ri; 31 | 32 | // if rh_reply_to is not NULL this is an Outbound Tunnel 33 | void * rh_reply_to; 34 | // must be set for Outbound tunnel 35 | uint32_t reply_tunnel; 36 | }; 37 | 38 | /** 39 | * allocate and initialize struct i2p_tunnel_t 40 | * all fields except _private set to NULL 41 | */ 42 | struct i2p_tunnel_t * i2p_tunnel_new(void * router); 43 | 44 | /** 45 | * build a tunnel 46 | * all appropriate memebers of the tunnel must be setp 47 | */ 48 | void i2p_tunnel_build(struct i2p_tunnel_t * tunnel); 49 | 50 | uint32_t i2p_tunnel_get_id(struct i2p_tunnel_t * tunnel); 51 | 52 | void i2p_tunnel_destroy(struct i2p_tunnel * tunnel); 53 | 54 | void * i2p_tunnel_get_via_id(void * router, uint32_t tunnelId); 55 | 56 | #endif -------------------------------------------------------------------------------- /lib/i2p/tunnel/OutboundTunnel.cpp: -------------------------------------------------------------------------------- 1 | #include "OutboundTunnel.h" 2 | 3 | #include 4 | 5 | namespace i2pcpp { 6 | namespace Tunnel { 7 | OutboundTunnel::OutboundTunnel(std::vector const &hops, RouterHash const &replyHash, uint32_t const replyTunnelId) 8 | { 9 | /* Zero hop tunnel */ 10 | if(hops.empty()) { 11 | m_state = State::OPERATIONAL; 12 | return; 13 | } 14 | 15 | uint32_t lastTunnelId; 16 | RouterHash lastRouterHash; 17 | 18 | for(int i = hops.size() - 1; i >= 0; i--) { 19 | BuildRequestRecordPtr h; 20 | 21 | if(i == hops.size() - 1) { 22 | h = std::make_shared(hops[i], replyHash); 23 | h->setType(BuildRequestRecord::Type::ENDPOINT); 24 | h->setNextTunnelId(replyTunnelId); 25 | m_tunnelId = h->getNextTunnelId(); 26 | m_nextMsgId = h->getNextMsgId(); 27 | } else { 28 | h = std::make_shared(hops[i], lastRouterHash, lastTunnelId); 29 | } 30 | lastTunnelId = h->getTunnelId(); 31 | lastRouterHash = h->getLocalHash(); 32 | 33 | m_hops.push_front(h); 34 | } 35 | 36 | secureRecords(); 37 | } 38 | 39 | Tunnel::Direction OutboundTunnel::getDirection() const 40 | { 41 | return Direction::OUTBOUND; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lib/ssu/AcknowledgementManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file AcknowledgementManager.h 3 | * @brief Defines i2cpp::SSU::AcknowledgmentManager. 4 | */ 5 | #ifndef SSUACKNOWLEDGEMENTMANAGER_H 6 | #define SSUACKNOWLEDGEMENTMANAGER_H 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace i2pcpp { 13 | namespace SSU { 14 | class Context; 15 | 16 | /** 17 | * Manages acknowledgment (ACK) of receieved data. 18 | */ 19 | class AcknowledgementManager { 20 | public: 21 | 22 | /** 23 | * Constructs given a reference to an i2pcpp::SSU::Context object. 24 | */ 25 | AcknowledgementManager(Context &c); 26 | 27 | AcknowledgementManager(const AcknowledgementManager &) = delete; 28 | AcknowledgementManager& operator=(AcknowledgementManager &) = delete; 29 | 30 | private: 31 | /** 32 | * For each peer, sends a data packet to acknowedge the fragments 33 | * (both partial and complete) that have been received from it. 34 | * This is invoked exactly once every second. 35 | */ 36 | void flushAckCallback(const boost::system::error_code& e); 37 | 38 | /// Reference to the i2pcpp::SSU::Context object. 39 | Context& m_context; 40 | 41 | /// Timer to invoke the ACK callback. 42 | boost::asio::deadline_timer m_timer; 43 | 44 | i2p_logger_mt m_log; 45 | }; 46 | } 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /lib/i2p/i2np/DatabaseLookup.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DatabaseLookup.cpp 3 | * @brief Implements DatabaseLookup.h 4 | */ 5 | #include "DatabaseLookup.h" 6 | 7 | namespace i2pcpp { 8 | namespace I2NP { 9 | DatabaseLookup::DatabaseLookup(StaticByteArray<32> const &key, RouterHash const &from, uint32_t sendReplyTo, std::list excludedPeers) : 10 | m_key(key), 11 | m_from(from), 12 | m_sendReplyTo(sendReplyTo), 13 | m_excludedPeers(excludedPeers) {} 14 | 15 | ByteArray DatabaseLookup::compile() const 16 | { 17 | ByteArray b; 18 | 19 | b.insert(b.end(), m_key.cbegin(), m_key.cend()); 20 | b.insert(b.end(), m_from.cbegin(), m_from.cend()); 21 | 22 | if(m_sendReplyTo) { 23 | b.insert(b.end(), 0x01); 24 | 25 | b.insert(b.end(), m_sendReplyTo >> 24); 26 | b.insert(b.end(), m_sendReplyTo >> 16); 27 | b.insert(b.end(), m_sendReplyTo >> 8); 28 | b.insert(b.end(), m_sendReplyTo); 29 | } else 30 | b.insert(b.end(), 0x00); 31 | 32 | uint16_t size = m_excludedPeers.size(); 33 | b.insert(b.end(), size >> 8); 34 | b.insert(b.end(), size); 35 | 36 | for(auto p: m_excludedPeers) 37 | b.insert(b.end(), p.cbegin(), p.cend()); 38 | 39 | return b; 40 | } 41 | 42 | DatabaseLookup DatabaseLookup::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) 43 | { 44 | return DatabaseLookup(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/i2p/i2np/VariableTunnelBuildReply.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file VariableTunnelBuildReply.cpp 3 | * @brief Implements VariableTunnelBuildReply.h 4 | */ 5 | #include "VariableTunnelBuildReply.h" 6 | 7 | namespace i2pcpp { 8 | namespace I2NP { 9 | VariableTunnelBuildReply::VariableTunnelBuildReply(std::list const &buildRecords) : 10 | m_buildRecords(buildRecords) {} 11 | 12 | VariableTunnelBuildReply::VariableTunnelBuildReply(uint32_t msgId, std::list const &buildRecords) : 13 | Message(msgId), 14 | m_buildRecords(buildRecords) {} 15 | 16 | std::list VariableTunnelBuildReply::getRecords() const 17 | { 18 | return m_buildRecords; 19 | } 20 | 21 | ByteArray VariableTunnelBuildReply::compile() const 22 | { 23 | ByteArray b; 24 | 25 | b.insert(b.end(), m_buildRecords.size()); 26 | for(auto& r: m_buildRecords) { 27 | const ByteArray recordBytes = r->serialize(); 28 | b.insert(b.end(), recordBytes.cbegin(), recordBytes.cend()); 29 | } 30 | 31 | return b; 32 | } 33 | 34 | VariableTunnelBuildReply VariableTunnelBuildReply::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) 35 | { 36 | VariableTunnelBuildReply vtbr; 37 | 38 | unsigned char size = *begin++; 39 | 40 | for(int i = 0; i < size; i++) 41 | vtbr.m_buildRecords.emplace_back(std::make_shared(begin, end)); 42 | 43 | return vtbr; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/i2p/handlers/DatabaseStore.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DatabaseStore.h 3 | * @brief Defines the i2pcpp::Handlers::DatabaseStore handler. 4 | */ 5 | #ifndef HANDLERSDATABASESTORE_H 6 | #define HANDLERSDATABASESTORE_H 7 | 8 | #include "Message.h" 9 | 10 | namespace i2pcpp { 11 | namespace Handlers { 12 | /** 13 | * Handles database store messages. 14 | */ 15 | class DatabaseStore : public Message { 16 | public: 17 | /** 18 | * Constructs from a reference to the i2pcpp::RouterContext 19 | * object. 20 | */ 21 | DatabaseStore(RouterContext &ctx); 22 | 23 | /** 24 | * Handles the database store message. 25 | * If the data to be stored is a (gzip) commpressed i2pcpp::RouterInfo 26 | * object, it is decommpressed and, if the signature if correct, 27 | * it is added to the i2pcpp::Database of the router. 28 | * If the data is an uncompressed i2pcpp::LeaseSet, the associated 29 | * signal is invoked (currently unimplemented). 30 | * @param from the sending router 31 | * @param msg the actual i2pcpp::I2NP::Message object 32 | * @toto implement lease set handling (when floodfill 33 | * is implemented) 34 | */ 35 | void handleMessage(RouterHash const from, I2NP::MessagePtr const msg); 36 | 37 | private: 38 | i2p_logger_mt m_log; ///< Logging object 39 | }; 40 | } 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /lib/ssu/PeerState.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file PeerState.cpp 3 | * @brief Implements PeerState.h 4 | */ 5 | #include "PeerState.h" 6 | 7 | namespace i2pcpp { 8 | namespace SSU { 9 | PeerState::PeerState(Endpoint const &ep, RouterHash const &rh) : 10 | m_endpoint(ep), 11 | m_routerHash(rh) {} 12 | 13 | SessionKey PeerState::getCurrentSessionKey() const 14 | { 15 | return m_sessionKey; 16 | } 17 | 18 | SessionKey PeerState::getCurrentMacKey() const 19 | { 20 | return m_macKey; 21 | } 22 | 23 | SessionKey PeerState::getNextSessionKey() const 24 | { 25 | return m_nextSessionKey; 26 | } 27 | 28 | SessionKey PeerState::getNextMacKey() const 29 | { 30 | return m_nextMacKey; 31 | } 32 | 33 | void PeerState::setCurrentSessionKey(SessionKey const &sk) 34 | { 35 | m_sessionKey = sk; 36 | } 37 | 38 | void PeerState::setCurrentMacKey(SessionKey const &mk) 39 | { 40 | m_macKey = mk; 41 | } 42 | 43 | void PeerState::setNextSessionKey(SessionKey const &sk) 44 | { 45 | m_nextSessionKey = sk; 46 | } 47 | 48 | void PeerState::setNextMacKey(SessionKey const &mk) 49 | { 50 | m_nextMacKey = mk; 51 | } 52 | 53 | RouterHash PeerState::getHash() const 54 | { 55 | return m_routerHash; 56 | } 57 | 58 | Endpoint PeerState::getEndpoint() const 59 | { 60 | return m_endpoint; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/Certificate.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Certificate.h 3 | * @brief Defines the i2pcpp::Certificate structure. 4 | */ 5 | #ifndef CERTIFICATE_H 6 | #define CERTIFICATE_H 7 | 8 | #include "Datatype.h" 9 | 10 | namespace i2pcpp { 11 | 12 | /** 13 | * The certificate type. This is used for RIs, Garlic Cloves, 14 | * Garlic Messages and Destinations. 15 | * Structure is: 16 | * Type (1B) - Size (2B) - Payload (Variable) 17 | */ 18 | class Certificate : public Datatype { 19 | public: 20 | /** 21 | * The enum for the certificate type field. 22 | */ 23 | enum class Type { 24 | NIL, 25 | HASHCASH, 26 | HIDDEN, 27 | SIGNED, 28 | MULTIPLE 29 | }; 30 | 31 | Certificate(); 32 | 33 | /** 34 | * Constructs the certificate from an i2pcpp::ByteArray, given by an 35 | * iterator to its begin and end. 36 | */ 37 | Certificate(ByteArrayConstItr &begin, ByteArrayConstItr end); 38 | 39 | /** 40 | * @return the length of the certificates payload. 41 | */ 42 | uint16_t getLength() const; 43 | 44 | /** 45 | * @return the serialized version of the certficate as an i2pcpp::ByteArray. 46 | */ 47 | ByteArray serialize() const; 48 | 49 | private: 50 | Type m_type; ///< The certificate type 51 | ByteArray m_payload; ///< The actual certificate payload 52 | }; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lib/i2p/dht/DHTFacade.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DHTFacade.h 3 | * @brief Implements the DHT facade class, which allows easy use of the DHT. 4 | */ 5 | #ifndef _DHTFACADE_H_INCLUDE_GUARD 6 | #define _DHTFACADE_H_INCLUDE_GUARD 7 | 8 | #include 9 | 10 | #include "Kademlia.h" 11 | #include "SearchManager.h" 12 | 13 | namespace i2pcpp { 14 | class RouterContext; 15 | 16 | namespace DHT { 17 | 18 | /** 19 | * Facade class for easy use of the DHT functionality. 20 | */ 21 | class DHTFacade { 22 | 23 | public: 24 | /** 25 | * Constructs from a boost::asio::io_service, local router hash (where 26 | * lookups are relative to), and forward_list of initial RouterHashes. 27 | */ 28 | DHTFacade(boost::asio::io_service &ios, 29 | RouterHash const &local, 30 | std::forward_list const &hashes, 31 | RouterContext &ctx); 32 | 33 | DHTFacade(const DHTFacade&) = delete; 34 | DHTFacade& operator=(DHTFacade&) = delete; 35 | 36 | /** 37 | * Starts a lookup operation for a given i2pcpp::RouterHash. 38 | * @param hash the hash of the router to lookup 39 | * @return true if the lookup was succesfully started, false otherwise 40 | */ 41 | bool lookup(const RouterHash& hash); 42 | 43 | SearchManager& getSearchManager(); 44 | 45 | private: 46 | Kademlia m_dht; 47 | SearchManager m_searchManager; 48 | }; 49 | } 50 | } 51 | 52 | 53 | #endif // _DHTFACADE_H_INCLUDE_GUARD 54 | -------------------------------------------------------------------------------- /lib/i2p/sqlite3cc/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * util.h 3 | * 4 | * Copyright (C) 2009 Tim Marston 5 | * 6 | * This file is part of sqlite3cc (hereafter referred to as "this program"). 7 | * See http://ed.am/dev/sqlite3cc for more information. 8 | * 9 | * This program is free software: you can redistribute it and/or modify it under 10 | * the terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef SQLITE3CC_UTIL_H_ 24 | #define SQLITE3CC_UTIL_H_ 25 | 26 | 27 | #include 28 | 29 | 30 | namespace sqlite 31 | { 32 | 33 | 34 | /** 35 | * Check to see if sqlite is threadsafe. See 36 | * http://www.sqlite.org/threadsafe.html for more information. 37 | * 38 | * @returns sqlite threading mode 39 | * @see sqlite3_threadsafe() 40 | */ 41 | int threadsafe(); 42 | 43 | 44 | } // namespace sqlite 45 | 46 | 47 | extern "C" { 48 | 49 | /** 50 | * Convenience function, so that the presence of libsqlite3cc can be 51 | * detected easily from autoconf's AC_CHECK_LIB() macro. 52 | */ 53 | void libsqlite3cc_is_present( void ); 54 | 55 | } // extern "C" 56 | 57 | 58 | #endif /* SQLITE3CC_UTIL_H_ */ 59 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/StaticByteArray.h: -------------------------------------------------------------------------------- 1 | #ifndef STATICBYTEARRAY_H 2 | #define STATICBYTEARRAY_H 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace i2pcpp { 12 | 13 | template 14 | using StaticByteArray = std::array; 15 | 16 | template 17 | StaticByteArray toStaticByteArray(T const &t) 18 | { 19 | StaticByteArray ret; 20 | 21 | if(t.size() < L) 22 | std::copy(t.cbegin(), t.cend(), ret.begin()); 23 | else 24 | std::copy(t.cbegin(), t.cbegin() + L, ret.begin()); 25 | 26 | return ret; 27 | } 28 | 29 | template 30 | inline ByteArray toByteArray(StaticByteArray const &sba) 31 | { 32 | return ByteArray(sba.cbegin(), sba.cend()); 33 | } 34 | 35 | template 36 | std::size_t hash_value(StaticByteArray const &sba) 37 | { 38 | boost::hash f; 39 | return f(sba); 40 | } 41 | } 42 | 43 | namespace std { 44 | template 45 | struct hash> { 46 | size_t operator()(const i2pcpp::StaticByteArray &sba) const 47 | { 48 | hash f; 49 | return f(std::string(sba.cbegin(), sba.cend())); 50 | } 51 | }; 52 | 53 | template 54 | std::ostream& operator<<(std::ostream &s, i2pcpp::StaticByteArray const &sba) 55 | { 56 | s << i2pcpp::Base64::encode(sba); 57 | return s; 58 | } 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /share/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE IF NOT EXISTS "config" ( 2 | "name" TEXT PRIMARY KEY NOT NULL, 3 | "value" TEXT 4 | ); 5 | ; 6 | CREATE TABLE IF NOT EXISTS "routers_raw" ( 7 | "id" BLOB PRIMARY KEY, 8 | "raw" BLOB NOT NULL 9 | ); 10 | ; 11 | CREATE TABLE IF NOT EXISTS "routers" ( 12 | "id" BLOB NOT NULL REFERENCES routers_raw(id) ON UPDATE CASCADE ON DELETE CASCADE, 13 | "encryption_key" BLOB NOT NULL, 14 | "signing_key" BLOB NOT NULL, 15 | "certificate" BLOB NOT NULL, 16 | "published" BLOB NOT NULL, 17 | "signature" BLOB NOT NULL 18 | ); 19 | ; 20 | CREATE TABLE IF NOT EXISTS "router_addresses" ( 21 | "router_id" BLOB NOT NULL REFERENCES routers_raw(id) ON UPDATE CASCADE ON DELETE CASCADE, 22 | "index" INTEGER NOT NULL, 23 | "cost" INTEGER NOT NULL, 24 | "expiration" BLOB NOT NULL, 25 | "transport" TEXT NOT NULL, 26 | PRIMARY KEY(router_id,"index") 27 | ); 28 | ; 29 | CREATE TABLE IF NOT EXISTS "router_options" ( 30 | "router_id" BLOB NOT NULL REFERENCES routers_raw(id) ON UPDATE CASCADE ON DELETE CASCADE, 31 | "name" TEXT NOT NULL, 32 | "value" TEXT NOT NULL, 33 | PRIMARY KEY(router_id, name) 34 | ); 35 | ; 36 | CREATE TABLE IF NOT EXISTS "profiles" ( 37 | "router_id" BLOB NOT NULL REFERENCES routers_raw(id) ON UPDATE CASCADE ON DELETE CASCADE, 38 | "last_seen" INTEGER, 39 | PRIMARY KEY("router_id") 40 | ); 41 | ; 42 | CREATE TABLE IF NOT EXISTS "router_address_options" ( 43 | "router_id" BLOB NOT NULL, 44 | "index" INTEGER NOT NULL, 45 | "name" TEXT NOT NULL, 46 | "value" TEXT NOT NULL, 47 | PRIMARY KEY(router_id, "index", name), 48 | FOREIGN KEY(router_id, "index") REFERENCES router_addresses(router_id, "index") ON UPDATE CASCADE ON DELETE CASCADE 49 | ); 50 | ; 51 | -------------------------------------------------------------------------------- /cmake/FindBotan.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find the Botan library 2 | # 3 | # Once done this will define 4 | # 5 | # BOTAN_FOUND - System has Botan 6 | # BOTAN_INCLUDE_DIRS - The Botan include directory 7 | # BOTAN_LIBRARIES - The libraries needed to use Botan 8 | # BOTAN_DEFINITIONS - Compiler switches required for using Botan 9 | # 10 | # Hints: 11 | # BOTAN_INCLUDEDIR 12 | # BOTAN_LIBRARYDIR 13 | 14 | IF (BOTAN_INCLUDE_DIRS AND BOTAN_LIBRARIES) 15 | # in cache already 16 | SET(Botan_FIND_QUIETLY TRUE) 17 | ENDIF (BOTAN_INCLUDE_DIRS AND BOTAN_LIBRARIES) 18 | 19 | IF (NOT WIN32) 20 | # try using pkg-config to get the directories and then use these values 21 | # in the FIND_PATH() and FIND_LIBRARY() calls 22 | # also fills in BOTAN_DEFINITIONS, although that isn't normally useful 23 | FIND_PACKAGE(PkgConfig) 24 | PKG_SEARCH_MODULE(PC_BOTAN botan-1.11) 25 | SET(BOTAN_DEFINITIONS ${PC_BOTAN_CFLAGS}) 26 | ENDIF (NOT WIN32) 27 | 28 | FIND_PATH(BOTAN_INCLUDE_DIR botan/botan.h 29 | HINTS 30 | ${BOTAN_INCLUDEDIR} 31 | ${PC_BOTAN_INCLUDEDIR} 32 | ${PC_BOTAN_INCLUDE_DIRS} 33 | ) 34 | 35 | FIND_LIBRARY(BOTAN_LIBRARY botan-1.11 36 | HINTS 37 | ${BOTAN_LIBRARYDIR} 38 | ${PC_BOTAN_LIBDIR} 39 | ${PC_BOTAN_LIBRARY_DIRS} 40 | ) 41 | 42 | MARK_AS_ADVANCED(BOTAN_INCLUDE_DIR BOTAN_LIBRARY) 43 | 44 | # handle the QUIETLY and REQUIRED arguments and set BOTAN_FOUND to TRUE if 45 | # all listed variables are TRUE 46 | INCLUDE(FindPackageHandleStandardArgs) 47 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Botan DEFAULT_MSG BOTAN_LIBRARY BOTAN_INCLUDE_DIR) 48 | 49 | IF(BOTAN_FOUND) 50 | SET(BOTAN_LIBRARIES ${BOTAN_LIBRARY}) 51 | SET(BOTAN_INCLUDE_DIRS ${BOTAN_INCLUDE_DIR}) 52 | ENDIF(BOTAN_FOUND) 53 | -------------------------------------------------------------------------------- /lib/i2p/i2np/TunnelGateway.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file TunnelGateway.cpp 3 | * @brief Implements TunnelGateway.h 4 | */ 5 | #include "TunnelGateway.h" 6 | 7 | #include 8 | 9 | namespace i2pcpp { 10 | namespace I2NP { 11 | TunnelGateway::TunnelGateway(uint32_t const tunnelId, ByteArray const &data) : 12 | m_tunnelId(tunnelId), 13 | m_data(data) {} 14 | 15 | uint32_t TunnelGateway::getTunnelId() const 16 | { 17 | return m_tunnelId; 18 | } 19 | 20 | const ByteArray& TunnelGateway::getData() const 21 | { 22 | return m_data; 23 | } 24 | 25 | ByteArray TunnelGateway::compile() const 26 | { 27 | uint16_t size = m_data.size(); 28 | ByteArray b; 29 | 30 | b.insert(b.end(), m_tunnelId >> 24); 31 | b.insert(b.end(), m_tunnelId >> 16); 32 | b.insert(b.end(), m_tunnelId >> 8); 33 | b.insert(b.end(), m_tunnelId); 34 | 35 | b.insert(b.end(), size >> 8); 36 | b.insert(b.end(), size); 37 | 38 | b.insert(b.end(), m_data.cbegin(), m_data.cend()); 39 | 40 | return b; 41 | } 42 | 43 | TunnelGateway TunnelGateway::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) 44 | { 45 | TunnelGateway tg; 46 | 47 | tg.m_tunnelId = parseUint32(begin); 48 | 49 | uint16_t size = parseUint16(begin); 50 | if(size > std::distance(begin, end)) 51 | throw std::runtime_error("invalid tunnel gateway message"); 52 | 53 | tg.m_data = ByteArray(begin, begin + size); 54 | 55 | return tg; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /lib/i2p/c_api/db.cpp: -------------------------------------------------------------------------------- 1 | #include "../../../include/i2pcpp/c_api/db.h" 2 | 3 | #include "util.h" 4 | 5 | #include "../../../include/i2pcpp/Database.h" 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace i2pcpp; 15 | 16 | void *i2p_db_load(char *dbFile) 17 | { 18 | Database *db = new (std::nothrow) Database(std::string(dbFile)); 19 | 20 | return db; 21 | } 22 | 23 | void i2p_db_create(char *dbFile) 24 | { 25 | Database::createDb(std::string(dbFile)); 26 | } 27 | 28 | void i2p_db_config_set(void *db, char *name, char *value) 29 | { 30 | ((Database *)db)->setConfigValue(std::string(name), std::string(value)); 31 | } 32 | 33 | char *i2p_db_config_get(void *db, char *name) 34 | { 35 | std::string result = ((Database *)db)->getConfigValue(std::string(name)); 36 | char *buf = new char[result.length() + 1]; 37 | std::memcpy(buf, result.c_str(), sizeof(*buf)); 38 | 39 | return buf; 40 | } 41 | 42 | bool i2p_db_router_exists(void *db, char *hash) 43 | { 44 | RouterHash rh = i2p_util_to_routerhash(hash); 45 | return ((Database *)db)->routerExists(rh); 46 | } 47 | 48 | void * i2p_db_get_ri_via_hash(void * db, char * c_hash_str) 49 | { 50 | if (! i2p_db_router_exists(db, c_hash_str) ) { 51 | return nullptr; 52 | } 53 | std::string hash(c_hash_str); 54 | RouterInfo * info = new RouterInfo(((Database *)db)->getRouterInfo(hash)); 55 | return info; 56 | } 57 | 58 | void i2p_db_rh_free(void * rh) 59 | { 60 | RouterHash * hash = (RouterHash *) rh; 61 | delete hash; 62 | } 63 | 64 | void i2p_db_ri_free(void * ri) 65 | { 66 | RouterInfo * info = (RouterInfo *) ri; 67 | delete info; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/client.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_CLIENT_HPP 29 | #define WEBSOCKETPP_CLIENT_HPP 30 | 31 | #include 32 | 33 | #endif //WEBSOCKETPP_CLIENT_HPP 34 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/server.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_SERVER_HPP 29 | #define WEBSOCKETPP_SERVER_HPP 30 | 31 | #include 32 | 33 | #endif //WEBSOCKETPP_SERVER_HPP 34 | -------------------------------------------------------------------------------- /lib/i2p/tunnel/FollowOnFragment.h: -------------------------------------------------------------------------------- 1 | #ifndef TUNNELFOLLOWONFRAGMENT_H 2 | #define TUNNELFOLLOWONFRAGMENT_H 3 | 4 | #include "Fragment.h" 5 | 6 | namespace i2pcpp { 7 | namespace Tunnel { 8 | class FollowOnFragment : public Fragment { 9 | public: 10 | /** 11 | * Constructs a follow on fragment from a message ID and \a n, 12 | * a fragment number. 13 | */ 14 | FollowOnFragment(uint32_t msgId, uint8_t n); 15 | 16 | /** 17 | * Set to true is this is the last fragment in a tunnel message 18 | * (bit 0 of frag field). 19 | */ 20 | void setLast(bool isLast); 21 | 22 | /** 23 | * @return whether this is the last fragment in a tunnel message 24 | * (bit 0 of frag field). 25 | */ 26 | bool isLast() const; 27 | 28 | /** 29 | * @return the fragment number associated with this fragment. 30 | */ 31 | uint8_t getFragNum() const; 32 | 33 | /** 34 | * Compiles the class to a i2pcpp::ByteArray. 35 | */ 36 | ByteArray compile() const; 37 | 38 | /** 39 | * Constructs a i2pcpp::Tunnel::FollowOnFragment from a pair of 40 | * const i2pcpp::ByteArray iterators. 41 | */ 42 | static FollowOnFragment parse(ByteArrayConstItr &begin, ByteArrayConstItr end); 43 | 44 | private: 45 | uint8_t headerSize() const; 46 | 47 | uint8_t m_fragNum; 48 | bool m_isLast = false; 49 | }; 50 | 51 | typedef std::unique_ptr FollowOnFragmentPtr; 52 | } 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/i2pcpp/util/gzip.h: -------------------------------------------------------------------------------- 1 | /* This code has been adapted from the Zlib code 2 | * provided by Peter J Jones and Jack Lloyd 3 | */ 4 | 5 | #ifndef GZIP_H 6 | #define GZIP_H 7 | 8 | #include 9 | 10 | namespace i2pcpp { 11 | 12 | using namespace Botan; 13 | 14 | /** 15 | * Gzip Compression Filter 16 | */ 17 | class Gzip_Compression : public Botan::Filter 18 | { 19 | public: 20 | std::string name() const { return "Gzip_Compression"; } 21 | 22 | void write(const byte input[], size_t length); 23 | void start_msg(); 24 | void end_msg(); 25 | 26 | /** 27 | * Flush the compressor 28 | */ 29 | void flush(); 30 | 31 | /** 32 | * @param level how much effort to use on compressing (0 to 9); 33 | * higher levels are slower but tend to give better 34 | * compression 35 | * @param raw_deflate if true no gzip header/trailer will be used 36 | */ 37 | Gzip_Compression(size_t level = 6, 38 | bool raw_deflate = false); 39 | 40 | ~Gzip_Compression() { clear(); } 41 | private: 42 | void clear(); 43 | const size_t level; 44 | const bool raw_deflate; 45 | 46 | secure_vector buffer; 47 | class Gzip_Stream* gzip; 48 | }; 49 | 50 | /** 51 | * Gzip Decompression Filter 52 | */ 53 | class Gzip_Decompression : public Filter 54 | { 55 | public: 56 | std::string name() const { return "Gzip_Decompression"; } 57 | 58 | void write(const byte input[], size_t length); 59 | void start_msg(); 60 | void end_msg(); 61 | 62 | Gzip_Decompression(bool raw_deflate = false); 63 | ~Gzip_Decompression() { clear(); } 64 | private: 65 | void clear(); 66 | 67 | const bool raw_deflate; 68 | 69 | secure_vector buffer; 70 | class Gzip_Stream* gzip; 71 | bool no_writes; 72 | }; 73 | 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /lib/i2p/tunnel/FragmentState.h: -------------------------------------------------------------------------------- 1 | #ifndef TUNNELFRAGMENTSTATE_H 2 | #define TUNNELFRAGMENTSTATE_H 3 | 4 | #include "FirstFragment.h" 5 | #include "FollowOnFragment.h" 6 | 7 | #include 8 | 9 | #include 10 | 11 | namespace i2pcpp { 12 | namespace Tunnel { 13 | class FragmentState { 14 | public: 15 | /** 16 | * Sets the first fragment for this state. 17 | */ 18 | void setFirstFragment(std::unique_ptr ff); 19 | 20 | /** 21 | * Adds a follow on fragment for this state. 22 | */ 23 | void addFollowOnFragment(FollowOnFragment fof); 24 | 25 | /** 26 | * @return true if all the fragments for a message have been 27 | * received. 28 | */ 29 | bool isComplete() const; 30 | 31 | /** 32 | * Compiles all the received fragments in to one i2pcpp::ByteArray. 33 | */ 34 | ByteArray compile(); 35 | 36 | /** 37 | * Returns the first fragment in this state. This is needed because 38 | * the first fragment contains delivery instructions. 39 | */ 40 | const std::unique_ptr& getFirstFragment() const; 41 | 42 | /** 43 | * Sets a timer for this state. 44 | */ 45 | void setTimer(std::unique_ptr t); 46 | 47 | private: 48 | uint8_t m_lastFragNum = 0; 49 | 50 | std::unique_ptr m_firstFragment = nullptr; 51 | std::list m_followOnFragments; 52 | 53 | std::unique_ptr m_timer; 54 | }; 55 | } 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /lib/datatypes/BuildResponseRecord.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file BuildResponseRecord.cpp 3 | * @brief implements BuildReponseRecord.h 4 | */ 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace i2pcpp { 14 | BuildResponseRecord::BuildResponseRecord(const BuildRecord &r) : 15 | BuildRecord(r) {} 16 | 17 | BuildResponseRecord::BuildResponseRecord(Reply r) : 18 | m_reply(r) {} 19 | 20 | void BuildResponseRecord::parse() 21 | { 22 | Botan::Pipe hashPipe(new Botan::Hash_Filter("SHA-256")); 23 | hashPipe.start_msg(); 24 | hashPipe.write(m_data.data() + 16, 496); 25 | hashPipe.end_msg(); 26 | 27 | std::array calcHash; 28 | hashPipe.read(calcHash.data(), 32); 29 | 30 | std::array givenHash; 31 | std::copy(m_header.cbegin(), m_header.cend(), givenHash.begin()); 32 | std::copy(m_data.cbegin(), m_data.cbegin() + 16, givenHash.begin() + m_header.size()); 33 | 34 | if(givenHash != calcHash) 35 | throw std::runtime_error("hash verification failed in BuildResponseRecord"); 36 | 37 | m_reply = (Reply)m_data[511]; 38 | } 39 | 40 | void BuildResponseRecord::compile() 41 | { 42 | Botan::AutoSeeded_RNG rng; 43 | 44 | rng.randomize(m_data.data() + 16, 495); 45 | m_data[511] = (unsigned char)m_reply; 46 | 47 | Botan::Pipe hashPipe(new Botan::Hash_Filter("SHA-256")); 48 | hashPipe.start_msg(); 49 | hashPipe.write(m_data.data() + 16, 496); 50 | hashPipe.end_msg(); 51 | 52 | hashPipe.read(m_header.data(), 16); 53 | hashPipe.read(m_data.data(), 16); 54 | } 55 | 56 | BuildResponseRecord::Reply BuildResponseRecord::getReply() const 57 | { 58 | return m_reply; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/datatypes/RouterAddress.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file RouterAddress.cpp 3 | * @brief Implements RouterAddress.h. 4 | */ 5 | #include 6 | 7 | namespace i2pcpp { 8 | RouterAddress::RouterAddress(int cost, Date const &expiration, std::string const &transport, Mapping const &options) : 9 | m_cost(cost), 10 | m_expiration(expiration), 11 | m_transport(transport), 12 | m_options(options) {} 13 | 14 | RouterAddress::RouterAddress(ByteArrayConstItr &begin, ByteArrayConstItr end) 15 | { 16 | m_cost = *(begin++); 17 | m_expiration = Date(begin, end); 18 | 19 | unsigned char size = *(begin++); 20 | if(std::distance(begin, end) < size) throw std::runtime_error("malformed router address"); 21 | m_transport = std::string(begin, begin + size); 22 | begin += size; 23 | 24 | m_options = Mapping(begin, end); 25 | } 26 | 27 | ByteArray RouterAddress::serialize() const 28 | { 29 | ByteArray b; 30 | 31 | const ByteArray&& expiration = m_expiration.serialize(); 32 | const ByteArray&& options = m_options.serialize(); 33 | 34 | b.insert(b.end(), m_cost); 35 | b.insert(b.end(), expiration.cbegin(), expiration.cend()); 36 | b.insert(b.end(), m_transport.size()); 37 | b.insert(b.end(), m_transport.cbegin(), m_transport.cend()); 38 | b.insert(b.end(), options.cbegin(), options.cend()); 39 | 40 | return b; 41 | } 42 | 43 | const unsigned char RouterAddress::getCost() const 44 | { 45 | return m_cost; 46 | } 47 | 48 | const Date& RouterAddress::getExpiration() const 49 | { 50 | return m_expiration; 51 | } 52 | 53 | const std::string& RouterAddress::getTransport() const 54 | { 55 | return m_transport; 56 | } 57 | 58 | const Mapping& RouterAddress::getOptions() const 59 | { 60 | return m_options; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/endpoint_base.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_ENDPOINT_BASE_HPP 29 | #define WEBSOCKETPP_ENDPOINT_BASE_HPP 30 | 31 | namespace websocketpp { 32 | 33 | /// Stub for user supplied base class. 34 | class endpoint_base {}; 35 | 36 | } // namespace websocketpp 37 | 38 | #endif // WEBSOCKETPP_ENDPOINT_BASE_HPP 39 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/connection_base.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_CONNECTION_BASE_HPP 29 | #define WEBSOCKETPP_CONNECTION_BASE_HPP 30 | 31 | namespace websocketpp { 32 | 33 | /// Stub for user supplied base class. 34 | class connection_base {}; 35 | 36 | } // namespace websocketpp 37 | 38 | #endif // WEBSOCKETPP_CONNECTION_BASE_HPP 39 | -------------------------------------------------------------------------------- /lib/i2p/i2np/DeliveryStatus.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DeliveryStatus.h 3 | * @brief Defines the i2pcpp::I2NP::DeliveryStatus message type. 4 | */ 5 | #ifndef I2NPDELIVERYSTATUS_H 6 | #define I2NPDELIVERYSTATUS_H 7 | 8 | #include "Message.h" 9 | 10 | #include 11 | 12 | namespace i2pcpp { 13 | namespace I2NP { 14 | 15 | /** 16 | * Represents a delivery status message, used for message acknowledgment. 17 | * They are also used for testing tunnels. 18 | * These messages are usually created by the message originator, to be 19 | * returned by the destination. They are then wrapped in an 20 | * i2pcpp::I2NP::Garlic message, together with the actual message. 21 | */ 22 | class DeliveryStatus : public Message { 23 | public: 24 | /** 25 | * Constructs from a \a msgId and an i2pcpp::Date object. 26 | * @param timestamp the time the message was succesfully created 27 | * or delivered 28 | */ 29 | DeliveryStatus(uint32_t msgId, Date timestamp); 30 | 31 | /** 32 | * Converts an i2pcpp::ByteArray to an i2pcpp::I2NP::DeliveryStatus 33 | * object. 34 | * The format to be parsed is a 4B message id followed by an 8B 35 | * i2pcpp::Date. 36 | */ 37 | static DeliveryStatus parse(ByteArrayConstItr &begin, ByteArrayConstItr end); 38 | 39 | protected: 40 | DeliveryStatus() = default; 41 | 42 | /** 43 | * Puts the 4B message identifier, followed by the 8B i2pcpp::Date 44 | * in an i2pcpp::ByteArray. 45 | */ 46 | ByteArray compile() const; 47 | 48 | private: 49 | uint32_t m_msgId; 50 | Date m_timestamp; 51 | }; 52 | } 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lib/i2p/tunnel/FragmentHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef TUNNELFRAGMENTHANDLER_H 2 | #define TUNNELFRAGMENTHANDLER_H 3 | 4 | #include "FragmentState.h" 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace i2pcpp { 12 | class RouterContext; 13 | 14 | namespace Tunnel { 15 | class FragmentHandler { 16 | public: 17 | FragmentHandler(boost::asio::io_service &ios, RouterContext &ctx); 18 | FragmentHandler(const FragmentHandler &) = delete; 19 | FragmentHandler& operator=(FragmentHandler &) = delete; 20 | 21 | /** 22 | * Collects a list of fragments we've received. All fragments go 23 | * in to a corresponding i2pcpp::Tunnel::FragmentState based on 24 | * message ID. FragmentStates are deleted after two minutes. 25 | */ 26 | void receiveFragments(std::list fragments); 27 | 28 | private: 29 | /** 30 | * Checks whether all the fragments for a particular \a msgId have 31 | * been received. If so, the fragments are compiled in to a single 32 | * byte array, wrapped in an i2pcpp::I2NP::Message, and sent to the 33 | * intended destination. 34 | */ 35 | void checkAndFlush(uint32_t msgId); 36 | 37 | /** 38 | * Erases the i2pcpp::Tunnel::FragmentState for a given \a msgId. 39 | */ 40 | void timerCallback(const boost::system::error_code& e, const uint32_t msgId); 41 | 42 | boost::asio::io_service &m_ios; 43 | RouterContext &m_ctx; 44 | 45 | /// A map of message IDs to fragment states. 46 | std::unordered_map m_states; 47 | 48 | mutable std::mutex m_statesMutex; 49 | 50 | i2p_logger_mt m_log; 51 | }; 52 | } 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /lib/i2p/Version.cpp: -------------------------------------------------------------------------------- 1 | /* The contents of this file are adapted from a 2 | * similar file used in the bitcoin-qt client. 3 | */ 4 | 5 | #define CLIENT_VERSION_MAJOR 0 6 | #define CLIENT_VERSION_MINOR 0 7 | #define CLIENT_VERSION_REVISION 0 8 | #define CLIENT_VERSION_BUILD 0 9 | #define CLIENT_VERSION_IS_RELEASE false 10 | #define CLIENT_VERSION_SUFFIX "-alpha" 11 | 12 | #define STRINGIZE(X) DO_STRINGIZE(X) 13 | #define DO_STRINGIZE(X) #X 14 | 15 | #ifdef HAVE_BUILD_INFO 16 | # include "build.h" 17 | #endif 18 | 19 | // 20 | #define GIT_ARCHIVE 1 21 | #ifdef GIT_ARCHIVE 22 | # define GIT_COMMIT_ID "0bca35a" 23 | # define GIT_COMMIT_DATE "$Format:%cD" 24 | #endif 25 | 26 | #define BUILD_DESC_FROM_COMMIT(maj,min,rev,build,commit) \ 27 | "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit 28 | 29 | #define BUILD_DESC_FROM_UNKNOWN(maj,min,rev,build) \ 30 | "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk" 31 | 32 | #ifndef BUILD_DESC 33 | # ifdef GIT_COMMIT_ID 34 | # define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID) 35 | # else 36 | # define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD) 37 | # endif 38 | #endif 39 | 40 | #ifndef BUILD_DATE 41 | # ifdef GIT_COMMIT_DATE 42 | # define BUILD_DATE GIT_COMMIT_DATE 43 | # else 44 | # define BUILD_DATE __DATE__ ", " __TIME__ 45 | # endif 46 | #endif 47 | 48 | #include "../../include/i2pcpp/Version.h" 49 | 50 | namespace i2pcpp { 51 | const int CLIENT_VERSION = 52 | 1000000 * CLIENT_VERSION_MAJOR 53 | + 10000 * CLIENT_VERSION_MINOR 54 | + 100 * CLIENT_VERSION_REVISION 55 | + 1 * CLIENT_VERSION_BUILD; 56 | 57 | const std::string CLIENT_NAME("i2pcpp"); 58 | const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX); 59 | 60 | const std::string CLIENT_DATE(BUILD_DATE); 61 | } 62 | -------------------------------------------------------------------------------- /py/i2pinit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # this script generates initial keys and populates netdb as needed 4 | # 5 | 6 | import sqlite3, os 7 | from urllib.request import urlopen as urlget 8 | 9 | def get_external_ip(): 10 | print ('get external ip address') 11 | return urlget('http://ipecho.net/plain').read().strip().decode('ascii') 12 | 13 | def has_config(cur,k): 14 | return cur.execute('SELECT value FROM config WHERE name = ?',(k,)).fetchone() is not None 15 | 16 | def put_config(cur,k,v): 17 | cur.execute('INSERT INTO config ( name, value ) VALUES ( ? , ? )',(k,v)) 18 | 19 | def init(ndb_dir,ssu_port,db_fname='i2p.db',ssu_ip='0.0.0.0',max_peers=500): 20 | 21 | os.system('./i2p --init --db=%s'%db_fname) # yes i know you can do injection here 22 | 23 | con = sqlite3.connect(db_fname) 24 | cur = con.cursor() 25 | 26 | if not has_config(cur,'ssu_bind_port'): 27 | print ('set ssu port to %d'%ssu_port) 28 | put_config(cur,'ssu_bind_port',ssu_port) 29 | 30 | if not has_config(cur,'ssu_bind_ip'): 31 | print ('set ssu ip to '+ssu_ip) 32 | put_config(cur,'ssu_bind_ip',ssu_ip) 33 | 34 | if not has_config(cur,'ssu_external_port'): 35 | print ('set ssu external port to %d'%ssu_port) 36 | put_config(cur,'ssu_external_port',ssu_port) 37 | 38 | if not has_config(cur,'ssu_external_ip'): 39 | extern_ip = get_external_ip() 40 | print ('set ssu external ip to '+extern_ip) 41 | put_config(cur,'ssu_external_ip',extern_ip) 42 | 43 | if not has_config(cur,'max_peers'): 44 | print ('set max peer count to %d'%max_peers) 45 | put_config(cur,'max_peers',max_peers) 46 | 47 | con.commit() 48 | con.close() 49 | 50 | os.system('./i2p --importdir '+ndb_dir) 51 | 52 | if __name__ == '__main__': 53 | import argparse 54 | ap = argparse.ArgumentParser() 55 | ap.add_argument('--port',default=6699,type=int) 56 | ap.add_argument('--netdb',default=os.path.join(os.environ['HOME'],'.i2p','netDb')) 57 | 58 | args = ap.parse_args() 59 | 60 | init(ssu_port=args.port,ndb_dir=args.netdb) 61 | 62 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/common/platforms.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_COMMON_PLATFORMS_HPP 29 | #define WEBSOCKETPP_COMMON_PLATFORMS_HPP 30 | 31 | /** 32 | * This header contains any platform specific preprocessor adjustments that 33 | * don't fit somewhere else better. 34 | */ 35 | 36 | #if defined(WIN32) && !defined(NOMINMAX) 37 | // don't define min and max macros that conflict with std::min and std::max 38 | #define NOMINMAX 39 | #endif 40 | 41 | #endif // WEBSOCKETPP_COMMON_PLATFORMS_HPP 42 | -------------------------------------------------------------------------------- /cmake/FindPackageMessage.cmake: -------------------------------------------------------------------------------- 1 | # FIND_PACKAGE_MESSAGE( "message for user" "find result details") 2 | # 3 | # This macro is intended to be used in FindXXX.cmake modules files. 4 | # It will print a message once for each unique find result. 5 | # This is useful for telling the user where a package was found. 6 | # The first argument specifies the name (XXX) of the package. 7 | # The second argument specifies the message to display. 8 | # The third argument lists details about the find result so that 9 | # if they change the message will be displayed again. 10 | # The macro also obeys the QUIET argument to the find_package command. 11 | # 12 | # Example: 13 | # 14 | # if(X11_FOUND) 15 | # FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}" 16 | # "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") 17 | # else() 18 | # ... 19 | # endif() 20 | 21 | #============================================================================= 22 | # Copyright 2008-2009 Kitware, Inc. 23 | # 24 | # Distributed under the OSI-approved BSD License (the "License"); 25 | # see accompanying file Copyright.txt for details. 26 | # 27 | # This software is distributed WITHOUT ANY WARRANTY; without even the 28 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 29 | # See the License for more information. 30 | #============================================================================= 31 | # (To distribute this file outside of CMake, substitute the full 32 | # License text for the above reference.) 33 | 34 | function(FIND_PACKAGE_MESSAGE pkg msg details) 35 | # Avoid printing a message repeatedly for the same find result. 36 | if(NOT ${pkg}_FIND_QUIETLY) 37 | string(REGEX REPLACE "[\n]" "" details "${details}") 38 | set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) 39 | if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") 40 | # The message has not yet been printed. 41 | message(STATUS "${msg}") 42 | 43 | # Save the find details in the cache to avoid printing the same 44 | # message again. 45 | set("${DETAILS_VAR}" "${details}" 46 | CACHE INTERNAL "Details about finding ${pkg}") 47 | endif() 48 | endif() 49 | endfunction() 50 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | i2pcpp license: 2 | Public domain. 3 | 4 | http://mises.org/document/3582 5 | 6 | Botan license: 7 | Copyright (C) 1999-2012 Jack Lloyd 8 | 2001 Peter J Jones 9 | 2004-2007 Justin Karneges 10 | 2004 Vaclav Ovsik 11 | 2005 Matthew Gregan 12 | 2005-2006 Matt Johnston 13 | 2006 Luca Piccarreta 14 | 2007 Yves Jerschow 15 | 2007-2008 FlexSecure GmbH 16 | 2007-2008 Technische Universitat Darmstadt 17 | 2007-2008 Falko Strenzke 18 | 2007-2008 Martin Doering 19 | 2007 Manuel Hartl 20 | 2007 Christoph Ludwig 21 | 2007 Patrick Sona 22 | 2010 Olivier de Gaalon 23 | 2012 Vojtech Kral 24 | 2012 Markus Wanner 25 | All rights reserved. 26 | 27 | Redistribution and use in source and binary forms, with or without 28 | modification, are permitted provided that the following conditions are met: 29 | 30 | 1. Redistributions of source code must retain the above copyright notice, 31 | this list of conditions, and the following disclaimer. 32 | 33 | 2. Redistributions in binary form must reproduce the above copyright 34 | notice, this list of conditions, and the following disclaimer in the 35 | documentation and/or other materials provided with the distribution. 36 | 37 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 38 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 39 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 40 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 41 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 42 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 43 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 44 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 45 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 47 | POSSIBILITY OF SUCH DAMAGE. 48 | -------------------------------------------------------------------------------- /lib/i2p/tunnel/Message.h: -------------------------------------------------------------------------------- 1 | #ifndef TUNNELMESSAGE_H 2 | #define TUNNELMESSAGE_H 3 | 4 | #include "Fragment.h" 5 | 6 | #include "../i2np/Message.h" 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace i2pcpp { 17 | namespace Tunnel { 18 | class Message { 19 | public: 20 | /** 21 | * Constructs a Message from 16 bytes of IV and 1008 bytes 22 | * of encrypted data. 23 | */ 24 | Message(StaticByteArray<1024> const &data); 25 | 26 | /** 27 | * Constructs a Message from a list of unencrpyted fragments. 28 | */ 29 | Message(std::list &fragments); 30 | 31 | /** 32 | * After the Message has been decrypted, this method will 33 | * parse the data. 34 | * @return a list of i2pcpp::Tunnel::FragmentPtr 35 | */ 36 | std::list parse() const; 37 | 38 | /** 39 | * @return the encrypted message, if it was set previously. 40 | */ 41 | StaticByteArray<1024> getEncryptedData() const; 42 | 43 | /** 44 | * Encrypts the compiled message. 45 | */ 46 | void encrypt(Botan::SymmetricKey const &ivKey, Botan::SymmetricKey const &layerKey); 47 | 48 | /** 49 | * Compiles the fragments together in preparation for 50 | * encryption. 51 | */ 52 | void compile(); 53 | 54 | private: 55 | void calculateChecksum(); 56 | bool verifyChecksum() const; 57 | 58 | uint32_t m_checksum; 59 | std::list m_fragments; 60 | uint16_t m_payloadSize = 0; 61 | 62 | StaticByteArray<16> m_iv; 63 | StaticByteArray<1008> m_encrypted; 64 | }; 65 | } 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /lib/i2p/i2np/TunnelData.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file TunnelData.h 3 | * @brief Defines the i2pcpp::I2NP::TunnelData message type. 4 | */ 5 | #ifndef I2NPTUNNELDATA_H 6 | #define I2NPTUNNELDATA_H 7 | 8 | #include "Message.h" 9 | 10 | #include 11 | 12 | namespace i2pcpp { 13 | namespace I2NP { 14 | 15 | /** 16 | * Represents a tunnel data message. These are message sent by a tunnel 17 | * gateway or participant to the next participant or endpoint. 18 | */ 19 | class TunnelData : public Message { 20 | public: 21 | /** 22 | * Constructs from a \a tunnelId and 1024 bytes of data. 23 | * @param tunnelId identifies the tunnel that the message is 24 | * intended for 25 | * @param data fragmented, batched, padded and encrypted I2NP messages 26 | */ 27 | TunnelData(uint32_t const tunnelId, StaticByteArray<1024> const &data); 28 | 29 | /** 30 | * @return the tunnel identifier associated with this message 31 | */ 32 | uint32_t getTunnelId() const; 33 | 34 | /** 35 | * @return the actual 1024 bytes of tunnel data 36 | */ 37 | const StaticByteArray<1024>& getData() const; 38 | 39 | /** 40 | * Converts an i2pcpp::ByteArray to an i2pcpp::I2NP::TunnelData object. 41 | * The format to be parsed is a 4B tunnel id and 1024B of data. 42 | */ 43 | static TunnelData parse(ByteArrayConstItr &begin, ByteArrayConstItr end); 44 | protected: 45 | TunnelData() = default; 46 | 47 | /** 48 | * Puts the 4B tunnel identifier, followed by 1024B of data in 49 | * an i2pcpp::ByteArray. 50 | */ 51 | ByteArray compile() const; 52 | 53 | private: 54 | uint32_t m_tunnelId; ///< The 4 byte tunnel id 55 | StaticByteArray<1024> m_data; ///< 1024 bytes of data 56 | }; 57 | } 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/Mapping.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Mapping.h 3 | * @brief Defines the i2pcpp::Mapping datatype. 4 | */ 5 | #ifndef MAPPING_H 6 | #define MAPPING_H 7 | 8 | #include "Datatype.h" 9 | 10 | #include 11 | #include 12 | 13 | namespace i2pcpp { 14 | /** 15 | * A set of (unique) key/value pairs. Implemented on top of 16 | * std::map. 17 | */ 18 | class Mapping : public Datatype { 19 | public: 20 | Mapping() = default; 21 | 22 | /** 23 | * Constructs an i2pcpp::Mapping from iterators to the begin and end of 24 | * an i2pcpp::ByteArray. The format must be: 25 | * size (2B) | len (1B) | key (len) | "=" | len (1B) | value (len) | ";" | ... 26 | */ 27 | Mapping(ByteArrayConstItr &begin, ByteArrayConstItr end); 28 | 29 | /** 30 | * Sets the element at \a name to \a value. 31 | */ 32 | void setValue(std::string const &name, std::string const &value); 33 | 34 | /** 35 | * Deletes the value at \a name. 36 | */ 37 | void deleteValue(std::string const &name); 38 | 39 | /** 40 | * @return the value at \a name 41 | */ 42 | std::string getValue(std::string const &name) const; 43 | 44 | /** 45 | * Serializes in the following format: 46 | * size (2B) | len (1B) | key (len) | "=" | len (1B) | value (len) | ";" | ... 47 | */ 48 | ByteArray serialize() const; 49 | 50 | /** 51 | * @return an iterator to the begin of the underlying std::map. 52 | */ 53 | std::map::const_iterator begin() const; 54 | 55 | /** 56 | * @return an iterator to the end of the underlying std::map. 57 | */ 58 | std::map::const_iterator end() const; 59 | 60 | private: 61 | /// the underlying std::map for storing the pairs 62 | std::map m_map; 63 | }; 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/concurrency/basic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_CONCURRENCY_BASIC_HPP 29 | #define WEBSOCKETPP_CONCURRENCY_BASIC_HPP 30 | 31 | #include 32 | 33 | namespace websocketpp { 34 | namespace concurrency { 35 | 36 | /// Concurrency policy that uses std::mutex / boost::mutex 37 | class basic { 38 | public: 39 | typedef lib::mutex mutex_type; 40 | typedef lib::lock_guard scoped_lock_type; 41 | }; 42 | 43 | } // namespace concurrency 44 | } // namespace websocketpp 45 | 46 | #endif // WEBSOCKETPP_CONCURRENCY_BASIC_HPP 47 | -------------------------------------------------------------------------------- /lib/util/I2PHMAC.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace i2pcpp { 6 | void I2PHMAC::add_data(const Botan::byte input[], size_t length) 7 | { 8 | hash->update(input, length); 9 | } 10 | 11 | void I2PHMAC::final_result(Botan::byte mac[]) 12 | { 13 | /* Because I2P doesn't follow the HMAC RFC, 14 | * we need to make a change right here: 15 | */ 16 | Botan::byte tmp[32] = {0}; 17 | hash->final(tmp); 18 | hash->update(o_key); 19 | hash->update(tmp, 32); 20 | hash->final(mac); 21 | hash->update(i_key); 22 | } 23 | 24 | void I2PHMAC::key_schedule(const Botan::byte key[], size_t length) 25 | { 26 | hash->clear(); 27 | fill(i_key.begin(), i_key.end(), 0x36); 28 | fill(o_key.begin(), o_key.end(), 0x5C); 29 | 30 | if(length > hash->hash_block_size()) 31 | { 32 | Botan::secure_vector hmac_key = hash->process(key, length); 33 | xor_buf(i_key, hmac_key, hmac_key.size()); 34 | xor_buf(o_key, hmac_key, hmac_key.size()); 35 | } 36 | else 37 | { 38 | xor_buf(i_key, key, length); 39 | xor_buf(o_key, key, length); 40 | } 41 | 42 | hash->update(i_key); 43 | } 44 | 45 | void I2PHMAC::clear() 46 | { 47 | hash->clear(); 48 | zeroise(i_key); 49 | zeroise(o_key); 50 | } 51 | 52 | std::string I2PHMAC::name() const 53 | { 54 | return "I2PHMAC(" + hash->name() + ")"; 55 | } 56 | 57 | Botan::MessageAuthenticationCode* I2PHMAC::clone() const 58 | { 59 | return new I2PHMAC(hash->clone()); 60 | } 61 | 62 | I2PHMAC::I2PHMAC(Botan::HashFunction* hash_in) : hash(hash_in) 63 | { 64 | if(hash->hash_block_size() == 0) 65 | throw Botan::Invalid_Argument("HMAC cannot be used with " + hash->name()); 66 | 67 | if(hash->name() != "MD5") 68 | throw Botan::Invalid_Argument("This HMAC is specially adapted for use with MD5 only."); 69 | 70 | i_key.resize(hash->hash_block_size()); 71 | o_key.resize(hash->hash_block_size()); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /lib/i2p/i2np/TunnelGateway.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file TunnelGateway.h 3 | * @brief Defines the i2pcpp::I2NP::TunnelGateway message type. 4 | */ 5 | #ifndef I2NPTUNNELGATEWAY_H 6 | #define I2NPTUNNELGATEWAY_H 7 | 8 | #include "Message.h" 9 | 10 | #include 11 | 12 | namespace i2pcpp { 13 | namespace I2NP { 14 | 15 | /** 16 | * Represents a tunnel gateway message. These messages wrap another 17 | * i2pcpp::I2NP::Message to be sent into the tunnel, at the tunnel 18 | * inbound gateway. 19 | */ 20 | class TunnelGateway : public Message { 21 | public: 22 | /** 23 | * Constructs from a \a tunnelId and a variable amount of data. 24 | * @param tunnelId identifies the tunnel that the message is 25 | * intended for 26 | * @param data an I2NP message with a standard header 27 | */ 28 | TunnelGateway(uint32_t const tunnelId, ByteArray const &data); 29 | 30 | /** 31 | * @return the tunnel identifier associated with this message 32 | */ 33 | uint32_t getTunnelId() const; 34 | 35 | /** 36 | * @return the data 37 | */ 38 | const ByteArray& getData() const; 39 | 40 | /** 41 | * Converts an i2pcpp::ByteArray to an i2pcpp::I2NP::TunnelData object. 42 | * The format to be parsed is a 4B tunnel id, followed by a 2B length, 43 | * and that amount bytes of data. 44 | */ 45 | static TunnelGateway parse(ByteArrayConstItr &begin, ByteArrayConstItr end); 46 | 47 | protected: 48 | TunnelGateway() = default; 49 | 50 | 51 | /** 52 | * Puts the 4B tunnel identifier, followed by the 2B length, 53 | * followed by that amount of bytes of data in an i2pcpp::ByteArray. 54 | */ 55 | ByteArray compile() const; 56 | 57 | private: 58 | uint32_t m_tunnelId; ///< The 4 byte tunnel id 59 | ByteArray m_data; ///< the variable amount of data 60 | }; 61 | } 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /lib/i2p/PeerManager.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file PeerManager.cpp 3 | * @brief Implements PeerManager.h 4 | */ 5 | #include "PeerManager.h" 6 | 7 | #include "RouterContext.h" 8 | 9 | #include "i2np/DeliveryStatus.h" 10 | 11 | #include 12 | 13 | 14 | namespace i2pcpp { 15 | PeerManager::PeerManager(boost::asio::io_service &ios, RouterContext &ctx) : 16 | m_ios(ios), 17 | m_ctx(ctx), 18 | m_graceful(false), 19 | m_timer(m_ios, boost::posix_time::time_duration(0, 0, 5)), 20 | m_log(I2P_LOG_CHANNEL("PM")) {} 21 | 22 | void PeerManager::begin() 23 | { 24 | I2P_LOG(m_log,info) << "PeerManager beginning"; 25 | m_timer.async_wait(boost::bind(&PeerManager::callback, this, boost::asio::placeholders::error)); 26 | } 27 | 28 | void PeerManager::connected(const RouterHash rh) 29 | { 30 | // TODO Ding the peer's profile 31 | } 32 | 33 | void PeerManager::failure(const RouterHash rh) 34 | { 35 | // TODO Ding the peer's profile 36 | } 37 | 38 | void PeerManager::disconnected(const RouterHash rh) 39 | { 40 | } 41 | 42 | void PeerManager::callback(const boost::system::error_code &e) 43 | { 44 | try { 45 | uint32_t minPeers = std::stoi(m_ctx.getDatabase()->getConfigValue("min_peers")); 46 | uint32_t numPeers = m_ctx.getOutMsgDisp().getTransport()->numPeers(); 47 | 48 | I2P_LOG(m_log, debug) << "current number of peers: " << numPeers; 49 | I2P_LOG(m_log, debug) << boost::log::add_value("peers", (uint32_t) numPeers); 50 | int32_t gap = minPeers - numPeers; 51 | for(int32_t i = 0; i < gap; i++) 52 | m_ctx.getOutMsgDisp().getTransport()->connect(m_ctx.getProfileManager().getPeer()); 53 | 54 | } catch(std::exception &e) { 55 | I2P_LOG(m_log, error) << "exception in PeerManager: " << e.what(); 56 | } 57 | if ( ! m_graceful ) { 58 | m_timer.expires_at(m_timer.expires_at() + boost::posix_time::time_duration(0, 0, 10)); 59 | m_timer.async_wait(boost::bind(&PeerManager::callback, this, boost::asio::placeholders::error)); 60 | } 61 | } 62 | 63 | void PeerManager::gracefulShutdown() 64 | { 65 | m_graceful = true; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /lib/i2p/handlers/DeliveryStatus.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DeliveryStatus.cpp 3 | * @brief Implements DeliveryStatus.h 4 | */ 5 | #include "DeliveryStatus.h" 6 | 7 | #include "../RouterContext.h" 8 | 9 | #include "../i2np/DatabaseStore.h" 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace i2pcpp { 17 | namespace Handlers { 18 | DeliveryStatus::DeliveryStatus(RouterContext &ctx) : 19 | Message(ctx), 20 | m_log(I2P_LOG_CHANNEL("H[DStat]")) {} 21 | 22 | void DeliveryStatus::handleMessage(RouterHash const from, I2NP::MessagePtr const msg) 23 | { 24 | I2P_LOG_SCOPED_TAG(m_log, "RouterHash", from); 25 | I2P_LOG(m_log, debug) << "received DeliveryStatus message, replying with DatabaseStore message"; 26 | 27 | // TODO Get this out of here 28 | Mapping am; 29 | am.setValue("caps", "BC"); 30 | am.setValue("host", m_ctx.getDatabase()->getConfigValue("ssu_external_ip")); 31 | am.setValue("key", Base64::encode(m_ctx.getIdentity()->getHash())); 32 | am.setValue("port", m_ctx.getDatabase()->getConfigValue("ssu_external_port")); 33 | RouterAddress a(5, Date(0), "SSU", am); 34 | 35 | Mapping rm; 36 | rm.setValue("coreVersion", "0.9.11"); 37 | rm.setValue("netId", "2"); 38 | rm.setValue("router.version", "0.9.11"); 39 | rm.setValue("stat_uptime", "90m"); 40 | rm.setValue("caps", "OR"); 41 | RouterInfo myInfo(*m_ctx.getIdentity(), Date(), rm); 42 | myInfo.addAddress(a); 43 | myInfo.sign(m_ctx.getSigningKey()); 44 | 45 | Botan::Pipe gzPipe(new Gzip_Compression); 46 | gzPipe.start_msg(); 47 | gzPipe.write(myInfo.serialize()); 48 | gzPipe.end_msg(); 49 | 50 | unsigned int size = gzPipe.remaining(); 51 | ByteArray gzInfoBytes(size); 52 | gzPipe.read(gzInfoBytes.data(), size); 53 | 54 | auto mydsm = std::make_shared(myInfo.getIdentity().getHash(), I2NP::DatabaseStore::DataType::ROUTER_INFO, 0, gzInfoBytes); 55 | m_ctx.getOutMsgDisp().sendMessage(from, mydsm); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/RouterIdentity.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file RouterIdentity.h 3 | * @brief Defines the i2pcpp::RouterIdentity data structure. 4 | */ 5 | #ifndef ROUTERIDENTITY_H 6 | #define ROUTERIDENTITY_H 7 | 8 | #include "Datatype.h" 9 | #include "RouterHash.h" 10 | #include "Certificate.h" 11 | 12 | #include 13 | 14 | namespace i2pcpp { 15 | /** 16 | * Allows a router to be uniquely identified. 17 | */ 18 | class RouterIdentity : public Datatype { 19 | public: 20 | /** 21 | * Constructs from iterators to the begin and end of an i2pcpp::ByteArray. 22 | * Format must be as follows: 23 | * public key (256B) | signing key (128B) | cerificate (>= 3B) 24 | * @throw i2pcpp::FormattingError 25 | */ 26 | RouterIdentity(ByteArrayConstItr &begin, ByteArrayConstItr end); 27 | 28 | /** 29 | * @param public key for ElGamal encryption 30 | * @param signing public key for verifying DSA certificates 31 | */ 32 | RouterIdentity(ByteArray const &encryptionKey, ByteArray const &signingKey, Certificate const &certificate); 33 | 34 | /** 35 | * Serialies the object as follows: 36 | * public key (256B) | signing key (128B) | cerificate (>= 3B) 37 | */ 38 | ByteArray serialize() const; 39 | 40 | /** 41 | * @return the public encryption key 42 | */ 43 | ByteArray getEncryptionKey() const; 44 | 45 | /** 46 | * @return the private encryption key 47 | */ 48 | ByteArray getSigningKey() const; 49 | 50 | /** 51 | * @return SHA256 hash of the i2pcpp::RouterIdentity object 52 | */ 53 | RouterHash getHash() const; 54 | 55 | /** 56 | * @return router identity certificate 57 | */ 58 | const Certificate& getCertificate() const; 59 | 60 | private: 61 | std::array m_encryptionKey; 62 | std::array m_signingKey; 63 | Certificate m_certificate; 64 | 65 | mutable bool m_hashed = false; 66 | mutable RouterHash m_hash; 67 | }; 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /share/web-console/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | i2pcpp control panel 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |

I2P Router: Disconnected

18 |
19 |
20 |
21 |
22 |
23 |
24 |

UDP outbound N/A

25 |
26 |
27 |
28 | UDP inbound N/A 29 |
30 |
31 |
32 |
33 |
34 | Outbound I2NP 35 |
36 |
37 |
38 | Inbound I2NP 39 |
40 |
41 |
42 |
43 |
44 | Connected Peers: N/A 45 |
46 |
47 |
48 | Participating Tunnels: N/A 49 |
50 |
51 |
52 |
53 |
54 |
55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /include/i2pcpp/Router.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Router.h 3 | * @brief Defines the i2pcpp::Router class. 4 | */ 5 | #ifndef ROUTER_H 6 | #define ROUTER_H 7 | 8 | #include 9 | 10 | #include 11 | 12 | namespace i2pcpp { 13 | class RouterInfo; 14 | class Transport; 15 | class Database; 16 | struct Callbacks; 17 | 18 | /** 19 | * Represents an I2P router. 20 | */ 21 | class Router { 22 | public: 23 | /** 24 | * Constructs a router. 25 | * @param db a valid i2pcpp::Database object. 26 | * @param cb a struct containing the callbacks for various events. 27 | */ 28 | Router(std::shared_ptr const &db, Callbacks const &cb); 29 | Router(const Router &) = delete; 30 | Router& operator=(Router &) = delete; 31 | ~Router(); 32 | 33 | /** 34 | * Initializes various global states. Call this once and only once 35 | * per application, regardless of how many routers you start. 36 | */ 37 | static void initialize(); 38 | 39 | /** 40 | * Registers a transport with libi2p. The transport must already have 41 | * been initialized properly. 42 | */ 43 | void addTransport(std::shared_ptr t); 44 | 45 | /** 46 | * Starts the i2pcpp::Router. 47 | * That is, runs the boost::asio I/O service, registers the handlers, 48 | * binds the signals, etc. 49 | */ 50 | void start(); 51 | 52 | /** 53 | * Stops the i2pcpp::Router. 54 | * That is, stops the control server and I/O service. 55 | */ 56 | void stop(); 57 | 58 | /** 59 | * determinte if the router is running 60 | */ 61 | bool isRunning(); 62 | 63 | /** 64 | * begin graceful shutdown process 65 | */ 66 | void gracefulShutdown(); 67 | 68 | /** 69 | * determine if the router is participating in the network 70 | */ 71 | bool isActive(); 72 | 73 | private: 74 | struct RouterImpl; 75 | std::unique_ptr m_impl; 76 | }; 77 | } 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/common/chrono.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_COMMON_CHRONO_HPP 29 | #define WEBSOCKETPP_COMMON_CHRONO_HPP 30 | 31 | #if defined _WEBSOCKETPP_CPP11_STL_ && !defined _WEBSOCKETPP_NO_CPP11_CHRONO_ 32 | #ifndef _WEBSOCKETPP_CPP11_CHRONO_ 33 | #define _WEBSOCKETPP_CPP11_CHRONO_ 34 | #endif 35 | #endif 36 | 37 | #ifdef _WEBSOCKETPP_CPP11_CHRONO_ 38 | #include 39 | #else 40 | #include 41 | #endif 42 | 43 | namespace websocketpp { 44 | namespace lib { 45 | 46 | #ifdef _WEBSOCKETPP_CPP11_CHRONO_ 47 | using std::chrono::system_clock; 48 | #else 49 | using boost::chrono::system_clock; 50 | #endif 51 | 52 | } // namespace lib 53 | } // namespace websocketpp 54 | 55 | #endif // WEBSOCKETPP_COMMON_CHRONO_HPP 56 | -------------------------------------------------------------------------------- /lib/i2p/tunnel/Fragment.h: -------------------------------------------------------------------------------- 1 | #ifndef TUNNELFRAGMENT_H 2 | #define TUNNELFRAGMENT_H 3 | 4 | #include "../i2np/Message.h" 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | namespace i2pcpp { 12 | namespace Tunnel { 13 | class Fragment { 14 | public: 15 | virtual ~Fragment() {} 16 | 17 | /** 18 | * Sets the message ID for the fragment. 19 | */ 20 | void setMsgId(uint32_t id); 21 | 22 | /** 23 | * Gets the message ID for the fragment. 24 | */ 25 | uint32_t getMsgId() const; 26 | 27 | /** 28 | * Copies \a max bytes from the pair of const i2pcpp::ByteArray 29 | * iterators and sets them as the payload. 30 | */ 31 | void setPayload(ByteArrayConstItr &begin, ByteArrayConstItr end, uint16_t max); 32 | 33 | /** 34 | * @return the payload of the fragment. 35 | */ 36 | const ByteArray& getPayload() const; 37 | 38 | /** 39 | * @return the size of the fragment, including the header. 40 | */ 41 | uint16_t size() const; 42 | 43 | virtual ByteArray compile() const = 0; 44 | 45 | /** 46 | * Fragments a complete array of \a data in to the corresponding 47 | * i2pcpp::Tunnel::FirstFragment and any additional 48 | * i2pcpp::Tunnel::FollowOnFragments. 49 | */ 50 | static std::vector> fragmentMessage(ByteArray const &data); 51 | 52 | /** 53 | * Parses the data at the iterator, creating a 54 | * i2pcpp::Tunnel::FirstFragment or i2pcpp::Tunnel::FollowOnFragment 55 | * as necessary. 56 | */ 57 | static std::unique_ptr parse(ByteArrayConstItr &begin, ByteArrayConstItr end); 58 | 59 | protected: 60 | uint32_t m_msgId = 0; 61 | ByteArray m_payload; 62 | 63 | private: 64 | virtual uint8_t headerSize() const = 0; 65 | }; 66 | 67 | typedef std::unique_ptr FragmentPtr; 68 | }; 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/BuildResponseRecord.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file BuildResponseRecord.h 3 | * @brief Defines the i2pcpp::BuildResponseRecord type. 4 | */ 5 | #ifndef BUILDRESPONSERECORD_H 6 | #define BUILDRESPONSERECORD_H 7 | 8 | #include "SessionKey.h" 9 | 10 | #include "BuildRecord.h" 11 | 12 | namespace i2pcpp { 13 | /** 14 | * The tunnel response record type. Consists of a 32 bytes hash, 15 | * followed by 495 bytes of random badding and finally the reply value. 16 | */ 17 | class BuildResponseRecord : public BuildRecord { 18 | public: 19 | 20 | /** 21 | * This is a one byte value indicates success or failure responses 22 | * on tunnel build requests. 23 | * SUCCESS(0x00) means that the hop agrees to participate. 24 | * Any higher value indicates that the hop rejects the build request. 25 | */ 26 | enum class Reply { 27 | SUCCESS = 0, 28 | PROBABALISTIC_REJECT = 10, 29 | TRANSIENT_OVERLOAD = 20, 30 | BANDWIDTH = 30, 31 | CRITICAL = 50 32 | }; 33 | 34 | /** 35 | * Creates a tunnel response record from a 36 | * i2pcpp::BuildResponseRecord::Reply. 37 | */ 38 | BuildResponseRecord(Reply r); 39 | 40 | /** 41 | * Constructs from an i2pcpp::BuildRecord. 42 | */ 43 | BuildResponseRecord(const BuildRecord &r); 44 | 45 | /** 46 | * Checks whether the given data and corresponding hash are correct. 47 | * That is, recomputes the hash and compares it to the given hash. 48 | * @throw std::runtime_error if the hash is incorrect 49 | */ 50 | void parse(); 51 | 52 | /** 53 | * Creates the record by first generating 495 bytes of random padding followed 54 | * by the reply byte. Then computes the SHA256 hash, which is placed before 55 | * that. 56 | */ 57 | void compile(); 58 | 59 | /** 60 | * @return i2pcpp::BuildResponseRecord::m_reply 61 | */ 62 | Reply getReply() const; 63 | 64 | private: 65 | Reply m_reply; 66 | }; 67 | 68 | typedef std::shared_ptr BuildResponseRecordPtr; 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /lib/i2p/i2np/DatabaseStore.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DatabaseStore.cpp 3 | * @brief Implements DatabaseStore.h 4 | */ 5 | #include "DatabaseStore.h" 6 | 7 | namespace i2pcpp { 8 | namespace I2NP { 9 | DatabaseStore::DatabaseStore(StaticByteArray<32> const &key, DataType type, uint32_t replyToken, ByteArray const &data) : 10 | Message(), 11 | m_key(key), 12 | m_type(type), 13 | m_replyToken(replyToken), 14 | m_data(data) {} 15 | 16 | DatabaseStore::DataType DatabaseStore::getDataType() const 17 | { 18 | return m_type; 19 | } 20 | 21 | uint32_t DatabaseStore::getReplyToken() const 22 | { 23 | return m_replyToken; 24 | } 25 | 26 | const ByteArray& DatabaseStore::getData() const 27 | { 28 | return m_data; 29 | } 30 | 31 | ByteArray DatabaseStore::compile() const 32 | { 33 | ByteArray b; 34 | 35 | b.insert(b.end(), m_key.cbegin(), m_key.cend()); 36 | b.insert(b.end(), (unsigned char)m_type); 37 | 38 | b.insert(b.end(), m_replyToken >> 24); 39 | b.insert(b.end(), m_replyToken >> 16); 40 | b.insert(b.end(), m_replyToken >> 8); 41 | b.insert(b.end(), m_replyToken); 42 | 43 | if(m_type == DataType::ROUTER_INFO) { 44 | uint16_t size = m_data.size(); 45 | b.insert(b.end(), size >> 8); 46 | b.insert(b.end(), size); 47 | } 48 | 49 | b.insert(b.end(), m_data.cbegin(), m_data.cend()); 50 | 51 | return b; 52 | } 53 | 54 | DatabaseStore DatabaseStore::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) 55 | { 56 | DatabaseStore ds; 57 | 58 | std::copy(begin, begin + 32, ds.m_key.begin()); 59 | begin += 32; 60 | 61 | ds.m_type = (DataType)*(begin++); 62 | ds.m_replyToken = parseUint32(begin); 63 | 64 | if(ds.m_replyToken) { 65 | ds.m_replyTunnelId = parseUint32(begin); 66 | 67 | std::copy(begin, begin + 32, ds.m_replyGateway.begin()); 68 | begin += 32; 69 | } 70 | 71 | uint16_t size = parseUint16(begin); 72 | 73 | ds.m_data = ByteArray(begin, begin + size); 74 | 75 | return ds; 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /lib/i2p/sqlite3cc/row.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * row.cc 3 | * 4 | * Copyright (C) 2009 Tim Marston 5 | * 6 | * This file is part of sqlite3cc (hereafter referred to as "this program"). 7 | * See http://ed.am/dev/sqlite3cc for more information. 8 | * 9 | * This program is free software: you can redistribute it and/or modify it under 10 | * the terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | sqlite::row::row( 29 | sqlite3_stmt *handle, 30 | unsigned long long row_number ) 31 | : 32 | _handle( handle ), 33 | _column_index( 0 ), 34 | _row_number( row_number ) 35 | { 36 | } 37 | 38 | 39 | sqlite::row::row() 40 | : 41 | _handle( NULL ) 42 | { 43 | } 44 | 45 | 46 | sqlite::row::operator bool() 47 | const 48 | { 49 | return _handle? true : false; 50 | } 51 | 52 | 53 | int sqlite::row::column_type( 54 | unsigned int index ) 55 | { 56 | assert( index < 57 | static_cast< unsigned int >( sqlite3_column_count( _handle ) ) ); 58 | return sqlite3_column_type( _handle, index ); 59 | } 60 | 61 | 62 | unsigned int sqlite::row::column_bytes( 63 | unsigned int index ) 64 | { 65 | return sqlite3_column_bytes( _handle, index ); 66 | } 67 | 68 | 69 | sqlite::row &sqlite::row::operator >>( 70 | sqlite::detail::set_index_t t ) 71 | { 72 | _column_index = t._index; 73 | return *this; 74 | } 75 | 76 | 77 | bool sqlite::row::operator ==( 78 | const sqlite::row &other ) 79 | const 80 | { 81 | return !_handle? !other._handle : 82 | _handle == other._handle && _row_number == other._row_number; 83 | } 84 | 85 | 86 | template< > 87 | sqlite::row &sqlite::row::operator >> < sqlite::detail::null_t >( 88 | sqlite::detail::null_t & ) 89 | { 90 | assert( _column_index < 91 | static_cast< unsigned int >( sqlite3_column_count( _handle ) ) ); 92 | _column_index++; 93 | return *this; 94 | } 95 | -------------------------------------------------------------------------------- /lib/i2p/sqlite3cc/manipulator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * manipulator.h 3 | * 4 | * Copyright (C) 2009 Tim Marston 5 | * 6 | * This file is part of sqlite3cc (hereafter referred to as "this program"). 7 | * See http://ed.am/dev/sqlite3cc for more information. 8 | * 9 | * This program is free software: you can redistribute it and/or modify it under 10 | * the terms of the GNU Lesser General Public License as published by the Free 11 | * Software Foundation, either version 3 of the License, or (at your option) any 12 | * later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 | * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 17 | * details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #ifndef SQLITE3CC_MANIPULATOR_H_ 24 | #define SQLITE3CC_MANIPULATOR_H_ 25 | 26 | 27 | namespace sqlite 28 | { 29 | 30 | 31 | namespace detail 32 | { 33 | // types to represent special manipulators for use with stream operators 34 | struct null_t { }; 35 | struct exec_t { }; 36 | struct set_index_t { unsigned int _index; }; 37 | } 38 | 39 | 40 | /** 41 | * Stream manipulator. When used with a statment's stream operator, this 42 | * specifies a NULL value to bind to a parameter. When used with a row's stream 43 | * operator, no value is fetched for a column. 44 | */ 45 | extern detail::null_t null; 46 | 47 | /** 48 | * Stream manipulator. When used with a statment's stream operator, this 49 | * indicates that the statement should be executed immediately. Unlike a 50 | * statment's exec() method, this will throw on error. Also, it will throw if 51 | * the execution returns any result rows. When used with a query's stream 52 | * operator, behaviour is the same except that it will not throw when the 53 | * execution returns results. 54 | */ 55 | extern detail::exec_t exec; 56 | 57 | /** 58 | * Stream manipulator. When used with a statment's or a row's stream operator, 59 | * this manipulator sets the index used to automatically bind values or get 60 | * column values. 61 | * 62 | * @param index the new index 63 | */ 64 | detail::set_index_t set_index( 65 | unsigned int index ); 66 | 67 | 68 | } // namespace sqlite 69 | 70 | 71 | #endif /* SQLITE3CC_MANIPULATOR_H_ */ 72 | -------------------------------------------------------------------------------- /lib/i2p/tunnel/FollowOnFragment.cpp: -------------------------------------------------------------------------------- 1 | #include "FollowOnFragment.h" 2 | 3 | #include 4 | 5 | namespace i2pcpp { 6 | namespace Tunnel { 7 | FollowOnFragment::FollowOnFragment(uint32_t msgId, uint8_t n) : 8 | m_fragNum(n) 9 | { 10 | m_msgId = msgId; 11 | 12 | if(m_fragNum > 63) 13 | throw std::runtime_error("too many fragments!"); 14 | } 15 | 16 | void FollowOnFragment::setLast(bool isLast) 17 | { 18 | m_isLast = isLast; 19 | } 20 | 21 | bool FollowOnFragment::isLast() const 22 | { 23 | return m_isLast; 24 | } 25 | 26 | uint8_t FollowOnFragment::getFragNum() const 27 | { 28 | return m_fragNum; 29 | } 30 | 31 | ByteArray FollowOnFragment::compile() const 32 | { 33 | ByteArray output; 34 | 35 | unsigned char flag = 0x80; 36 | 37 | flag |= m_fragNum << 1; 38 | flag |= (unsigned char)m_isLast; 39 | output.insert(output.end(), flag); 40 | 41 | output.insert(output.end(), m_msgId >> 24); 42 | output.insert(output.end(), m_msgId >> 16); 43 | output.insert(output.end(), m_msgId >> 8); 44 | output.insert(output.end(), m_msgId); 45 | 46 | uint16_t size = (uint16_t)m_payload.size(); 47 | output.insert(output.end(), size >> 8); 48 | output.insert(output.end(), size); 49 | 50 | output.insert(output.end(), m_payload.cbegin(), m_payload.cend()); 51 | 52 | return output; 53 | } 54 | 55 | FollowOnFragment FollowOnFragment::parse(ByteArrayConstItr &begin, ByteArrayConstItr end) 56 | { 57 | unsigned char flag = *begin++; 58 | uint8_t fragNum = ((flag & 0x7e) >> 1); 59 | uint32_t msgId = parseUint32(begin); 60 | 61 | FollowOnFragment fof(msgId, fragNum); 62 | fof.m_isLast = flag & 0x01; 63 | 64 | uint16_t size = parseUint16(begin); 65 | if(std::distance(begin, end) < size) 66 | throw std::runtime_error("malformed followon fragment"); 67 | 68 | fof.m_payload = ByteArray(begin, begin + size); 69 | begin += size; 70 | 71 | return fof; 72 | } 73 | 74 | uint8_t FollowOnFragment::headerSize() const 75 | { 76 | return 7; 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /include/i2pcpp/transports/SSU.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file SSU.h 3 | * @brief Defines the i2pcpp::SSU::SSU class. 4 | */ 5 | #ifndef SSU_H 6 | #define SSU_H 7 | 8 | #include 9 | 10 | namespace Botan { class DSA_PrivateKey; } 11 | 12 | namespace i2pcpp { 13 | class Endpoint; 14 | class RouterIdentity; 15 | 16 | namespace SSU { 17 | struct Context; 18 | 19 | class SSU : public Transport { 20 | friend class Context; 21 | 22 | public: 23 | /** 24 | * Constructs an SSU transport given a private DSA key and 25 | * RouterIdentity. The DSA key is used for signing and the 26 | * RouterIdentity key (ElGamal) is used for encryption. 27 | */ 28 | SSU(std::shared_ptr const &dsaPrivKey, RouterIdentity const &ri); 29 | ~SSU(); 30 | 31 | /** 32 | * Starts the transport. That is, binds the socket to the 33 | * i2pcpp::Endpoint and then starts receiving data. 34 | * @param ep the i2pcpp::Endpoint to listen on 35 | */ 36 | void start(Endpoint const &ep); 37 | 38 | /** 39 | * Iterates over all addresses listed in the i2pcpp::RouterInfo, and 40 | * attempts to establish a session with the first one that has SSU 41 | * as the transport. 42 | */ 43 | void connect(RouterInfo const &ri); 44 | 45 | void send(RouterHash const &rh, uint32_t msgId, ByteArray const &data); 46 | 47 | /** 48 | * Disconnects the peer given by i2pcpp::RouterHash \a rh. 49 | */ 50 | void disconnect(RouterHash const &rh); 51 | 52 | uint32_t numPeers() const; 53 | 54 | bool isConnected(RouterHash const &rh) const; 55 | 56 | /** 57 | * Stops the transport. That is, iterates over all connected peers and sends 58 | * them a session destroyed i2pcpp::Destroyed. Then stops the IO service 59 | * and joins all of the service threads. 60 | */ 61 | void shutdown(); 62 | 63 | virtual void gracefulShutdown(); 64 | private: 65 | std::unique_ptr m_impl; 66 | }; 67 | } 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/concurrency/none.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_CONCURRENCY_NONE_HPP 29 | #define WEBSOCKETPP_CONCURRENCY_NONE_HPP 30 | 31 | namespace websocketpp { 32 | namespace concurrency { 33 | 34 | namespace none_impl { 35 | class fake_mutex { 36 | public: 37 | fake_mutex() {} 38 | ~fake_mutex() {} 39 | }; 40 | 41 | class fake_lock_guard { 42 | public: 43 | explicit fake_lock_guard(fake_mutex foo) {} 44 | ~fake_lock_guard() {} 45 | }; 46 | } // namespace none_impl 47 | 48 | /// Stub Concurrency policy to remove locking in single threaded projects 49 | class none { 50 | public: 51 | typedef none_impl::fake_mutex mutex_type; 52 | typedef none_impl::fake_lock_guard scoped_lock_type; 53 | }; 54 | 55 | } // namespace concurrency 56 | } // namespace websocketpp 57 | 58 | #endif // WEBSOCKETPP_CONCURRENCY_ASYNC_HPP 59 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/common/regex.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_COMMON_REGEX_HPP 29 | #define WEBSOCKETPP_COMMON_REGEX_HPP 30 | 31 | #if defined _WEBSOCKETPP_CPP11_STL_ && !defined _WEBSOCKETPP_NO_CPP11_REGEX_ 32 | #ifndef _WEBSOCKETPP_CPP11_REGEX_ 33 | #define _WEBSOCKETPP_CPP11_REGEX_ 34 | #endif 35 | #endif 36 | 37 | #ifdef _WEBSOCKETPP_CPP11_REGEX_ 38 | #include 39 | #else 40 | #include 41 | #endif 42 | 43 | namespace websocketpp { 44 | namespace lib { 45 | 46 | #ifdef _WEBSOCKETPP_CPP11_REGEX_ 47 | using std::cmatch; 48 | using std::regex; 49 | using std::regex_match; 50 | #else 51 | using boost::cmatch; 52 | using boost::regex; 53 | using boost::regex_match; 54 | #endif 55 | 56 | } // namespace lib 57 | } // namespace websocketpp 58 | 59 | #endif // WEBSOCKETPP_COMMON_REGEX_HPP 60 | -------------------------------------------------------------------------------- /lib/datatypes/RouterIdentity.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file RouterIdentity.cpp 3 | * @brief Implements RouterIdentity.h. 4 | */ 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | namespace i2pcpp { 13 | RouterIdentity::RouterIdentity(ByteArrayConstItr &begin, ByteArrayConstItr end) 14 | { 15 | if(std::distance(begin, end) < 256 + 128) 16 | throw std::runtime_error("malformed router identity"); 17 | 18 | std::copy(begin, begin + 256, m_encryptionKey.begin()); 19 | begin += 256; 20 | std::copy(begin, begin + 128, m_signingKey.begin()); 21 | begin += 128; 22 | m_certificate = Certificate(begin, end); 23 | } 24 | 25 | RouterIdentity::RouterIdentity(ByteArray const &encryptionKey, ByteArray const &signingKey, Certificate const &certificate) : 26 | m_certificate(certificate) 27 | { 28 | copy(encryptionKey.begin(), encryptionKey.end(), m_encryptionKey.begin()); 29 | copy(signingKey.begin(), signingKey.end(), m_signingKey.begin()); 30 | } 31 | 32 | ByteArray RouterIdentity::serialize() const 33 | { 34 | ByteArray b; 35 | 36 | const ByteArray&& cert = m_certificate.serialize(); 37 | 38 | b.insert(b.end(), m_encryptionKey.begin(), m_encryptionKey.end()); 39 | b.insert(b.end(), m_signingKey.begin(), m_signingKey.end()); 40 | b.insert(b.end(), cert.begin(), cert.end()); 41 | 42 | return b; 43 | } 44 | 45 | ByteArray RouterIdentity::getEncryptionKey() const 46 | { 47 | ByteArray b(256); 48 | copy(m_encryptionKey.begin(), m_encryptionKey.end(), b.begin()); 49 | return b; 50 | } 51 | 52 | ByteArray RouterIdentity::getSigningKey() const 53 | { 54 | ByteArray b(128); 55 | copy(m_signingKey.begin(), m_signingKey.end(), b.begin()); 56 | return b; 57 | } 58 | 59 | RouterHash RouterIdentity::getHash() const 60 | { 61 | if(m_hashed) 62 | return m_hash; 63 | 64 | Botan::Pipe hashPipe(new Botan::Hash_Filter("SHA-256")); 65 | hashPipe.start_msg(); 66 | 67 | hashPipe.write(serialize()); 68 | 69 | hashPipe.end_msg(); 70 | 71 | hashPipe.read(m_hash.data(), 32); 72 | m_hashed = true; 73 | 74 | return m_hash; 75 | } 76 | 77 | const Certificate& RouterIdentity::getCertificate() const 78 | { 79 | return m_certificate; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /lib/i2p/PeerManager.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file PeerManager.h 3 | * @brief Defines the i2pcpp::PeerManager type. 4 | */ 5 | #ifndef PEERMANAGER_H 6 | #define PEERMANAGER_H 7 | 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace i2pcpp { 17 | class RouterContext; 18 | 19 | /** 20 | * Manages peers. Tries to connect to as many peers as possible. 21 | */ 22 | class PeerManager { 23 | public: 24 | /** 25 | * Constructs from a i2pcpp::RouterContext. 26 | * Sets the deadline duration to 5 seconds. 27 | */ 28 | PeerManager(boost::asio::io_service &ios, RouterContext &ctx); 29 | PeerManager(const PeerManager &) = delete; 30 | PeerManager& operator=(PeerManager &) = delete; 31 | 32 | /** 33 | * Starts the i2pcpp::PeerManager. 34 | * That is, starts the deadline timer. 35 | */ 36 | void begin(); 37 | 38 | /** 39 | * Called when a new peer has connected. 40 | * @param rh the i2pcpp::RouterHash of the peer 41 | */ 42 | void connected(const RouterHash rh); 43 | 44 | /** 45 | * Called when something goes wrong with a peer a new peer has connected. 46 | * @param rh the i2pcpp::RouterHash of the peer 47 | */ 48 | void failure(const RouterHash rh); 49 | 50 | /** 51 | * Called when a peer has disconnected. 52 | * @param rh the i2pcpp::RouterHash of the peer 53 | */ 54 | void disconnected(const RouterHash rh); 55 | 56 | void gracefulShutdown(); 57 | 58 | private: 59 | /** 60 | * Called when the deadline timer expires. 61 | * Logs the number of peers. 62 | * Tries to connect to \a n random known peers, where \a n is the 63 | * difference between the maximum amount of peers and the current 64 | * amount. 65 | * The deadline duration is set to 10 seconds. 66 | */ 67 | void callback(const boost::system::error_code &e); 68 | 69 | boost::asio::io_service& m_ios; 70 | RouterContext& m_ctx; 71 | 72 | boost::asio::deadline_timer m_timer; 73 | 74 | i2p_logger_mt m_log; ///< Logging object 75 | 76 | bool m_graceful; 77 | }; 78 | } 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /lib/ssu/InboundMessageState.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file InboundMessageState.cpp 3 | * @brief Implements InboundMessageState.h. 4 | */ 5 | #include "InboundMessageState.h" 6 | 7 | namespace i2pcpp { 8 | namespace SSU { 9 | InboundMessageState::InboundMessageState(RouterHash const &rh, const uint32_t msgId) : 10 | m_routerHash(rh), 11 | m_msgId(msgId) {} 12 | 13 | void InboundMessageState::addFragment(const uint8_t fragNum, ByteArray const &data, bool isLast) 14 | { 15 | if(m_gotLast && fragNum > m_lastFragment) 16 | return; // TODO Exception -- trying to give us a fragment greater than last 17 | 18 | if(fragNum < m_fragments.size() && m_fragments[fragNum]) 19 | return; // TODO Exception -- already got thsi fragment 20 | 21 | if(isLast) { 22 | m_gotLast = true; 23 | m_lastFragment = fragNum; 24 | } 25 | 26 | if(m_fragments.size() < (uint8_t)(fragNum + 1)) 27 | m_fragments.resize(fragNum + 1); 28 | 29 | auto f = std::make_shared(data); 30 | m_fragments[fragNum] = f; 31 | 32 | m_byteTotal += data.size(); 33 | } 34 | 35 | ByteArray InboundMessageState::assemble() const 36 | { 37 | ByteArray dst(m_byteTotal); 38 | 39 | auto itr = dst.begin(); 40 | for(auto& fp: m_fragments) 41 | { 42 | if(fp) { 43 | copy(fp->cbegin(), fp->cend(), itr); 44 | itr += fp->size(); 45 | } 46 | } 47 | 48 | return dst; 49 | } 50 | 51 | RouterHash InboundMessageState::getRouterHash() const 52 | { 53 | return m_routerHash; 54 | } 55 | 56 | uint32_t InboundMessageState::getMsgId() const 57 | { 58 | return m_msgId; 59 | } 60 | 61 | bool InboundMessageState::allFragmentsReceived() const 62 | { 63 | if(!m_gotLast) return false; 64 | 65 | for(auto f: m_fragments) 66 | if(!f) 67 | return false; 68 | 69 | return true; 70 | } 71 | 72 | std::vector InboundMessageState::getFragmentsReceived() const 73 | { 74 | std::vector v(m_fragments.size()); 75 | 76 | for(unsigned int i = 0; i < m_fragments.size(); i++) 77 | v[i] = (m_fragments[i] != ByteArrayPtr()); 78 | 79 | return v; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /lib/i2p/tunnel/FragmentState.cpp: -------------------------------------------------------------------------------- 1 | #include "FragmentState.h" 2 | 3 | namespace i2pcpp { 4 | namespace Tunnel { 5 | void FragmentState::setFirstFragment(std::unique_ptr ff) 6 | { 7 | if(!m_firstFragment) 8 | m_firstFragment = std::move(ff); 9 | else 10 | throw std::runtime_error("multiple first fragments in state"); 11 | } 12 | 13 | void FragmentState::addFollowOnFragment(FollowOnFragment fof) 14 | { 15 | uint8_t thisFragNum = fof.getFragNum(); 16 | if(fof.isLast()) { 17 | if(m_lastFragNum) 18 | throw std::runtime_error("multiple last fragments with the same fragment number in state"); 19 | m_lastFragNum = thisFragNum; 20 | } 21 | 22 | if(std::none_of(m_followOnFragments.cbegin(), m_followOnFragments.cend(), [thisFragNum](const FollowOnFragment &x) { return x.getFragNum() == thisFragNum; })) 23 | m_followOnFragments.push_back(std::move(fof)); 24 | } 25 | 26 | bool FragmentState::isComplete() const 27 | { 28 | // We didn't get the first fragment yet 29 | if(!m_firstFragment) 30 | return false; 31 | 32 | // We got the first fragment, and we aren't waiting for anything else 33 | if(!m_firstFragment->isFragmented()) 34 | return true; 35 | 36 | // We ARE waiting for something else, but we haven't gotten anything yet 37 | if(m_lastFragNum == 0) 38 | return false; 39 | 40 | // We don't have everything yet and are expecting more 41 | return (m_followOnFragments.size() == m_lastFragNum); 42 | } 43 | 44 | ByteArray FragmentState::compile() 45 | { 46 | m_followOnFragments.sort([](const FollowOnFragment &f1, const FollowOnFragment &f2) { return f1.getFragNum() < f2.getFragNum(); } ); 47 | 48 | ByteArray ret = m_firstFragment->getPayload(); 49 | for(auto& f: m_followOnFragments) { 50 | ByteArray p = f.getPayload(); 51 | ret.insert(ret.end(), p.cbegin(), p.cend()); 52 | } 53 | 54 | return ret; 55 | } 56 | 57 | const std::unique_ptr& FragmentState::getFirstFragment() const 58 | { 59 | return m_firstFragment; 60 | } 61 | 62 | void FragmentState::setTimer(std::unique_ptr t) 63 | { 64 | m_timer = std::move(t); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/common/connection_hdl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_COMMON_CONNECTION_HDL_HPP 29 | #define WEBSOCKETPP_COMMON_CONNECTION_HDL_HPP 30 | 31 | #include 32 | 33 | namespace websocketpp { 34 | 35 | /// A handle to uniquely identify a connection. 36 | /** 37 | * This type uniquely identifies a connection. It is implemented as a weak 38 | * pointer to the connection in question. This provides uniqueness across 39 | * multiple endpoints and ensures that IDs never conflict or run out. 40 | * 41 | * It is safe to make copies of this handle, store those copies in containers, 42 | * and use them from other threads. 43 | * 44 | * This handle can be upgraded to a full shared_ptr using 45 | * `endpoint::get_con_from_hdl()` from within a handler fired by the connection 46 | * that owns the handler. 47 | */ 48 | typedef lib::weak_ptr connection_hdl; 49 | 50 | } // namespace websocketpp 51 | 52 | #endif // WEBSOCKETPP_COMMON_CONNECTION_HDL_HPP 53 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/Endpoint.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Endpoint.h 3 | * @brief Defines the i2pcpp::Endpoint type. 4 | */ 5 | #ifndef ENDPOINT_H 6 | #define ENDPOINT_H 7 | 8 | #include "ByteArray.h" 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | namespace i2pcpp { 16 | /** 17 | * Represents any UDP endpoint. 18 | */ 19 | class Endpoint { 20 | public: 21 | Endpoint(boost::asio::ip::udp::endpoint const &ep); 22 | Endpoint(std::string ip = "127.0.0.1", uint16_t port = 0); 23 | Endpoint(ByteArray const &addr, uint16_t port); 24 | 25 | boost::asio::ip::tcp::endpoint getTCPEndpoint() const; 26 | boost::asio::ip::udp::endpoint getUDPEndpoint() const; 27 | 28 | /** 29 | * @return the IP address as a byte array 30 | */ 31 | ByteArray getRawIP() const; 32 | 33 | /** 34 | * @return the IP address in human-readable notation 35 | */ 36 | std::string getIP() const; 37 | 38 | /** 39 | * @return the port for the endpoint 40 | */ 41 | uint16_t getPort() const; 42 | 43 | /** 44 | * Compares this endpoint with another endpoint by comparing their 45 | * addresses and ports. Two endpoints are said to be equal if their ports 46 | * and addresses are equal. 47 | * @return true if they equal, false otherwise 48 | */ 49 | bool operator==(const Endpoint& rhs) const; 50 | 51 | /** 52 | * Creates a std::string representation of the endpoint. The format is 53 | * IP address + ":" + port. 54 | * @return the string representation of the endpoint 55 | */ 56 | operator std::string() const; 57 | 58 | private: 59 | boost::asio::ip::address m_addr; 60 | unsigned short m_port; 61 | }; 62 | 63 | std::ostream& operator<<(std::ostream &s, Endpoint const &ep); 64 | std::size_t hash_value(Endpoint const &ep); 65 | } 66 | 67 | namespace std { 68 | template<> 69 | struct hash { 70 | size_t operator()(const i2pcpp::Endpoint &ep) const 71 | { 72 | hash f; 73 | return f(ep); 74 | } 75 | }; 76 | 77 | template<> 78 | struct equal_to { 79 | bool operator()(const i2pcpp::Endpoint& lhs, const i2pcpp::Endpoint& rhs) const 80 | { 81 | return lhs == rhs; 82 | } 83 | }; 84 | } 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /lib/i2p/i2np/DatabaseSearchReply.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DatabaseSearchReply.h 3 | * @brief Defines the i2pcpp::I2NP::DatabaeSearchReply message type. 4 | */ 5 | #ifndef I2NPDATABASESEARCHREPLY_H 6 | #define I2NPDATABASESEARCHREPLY_H 7 | 8 | #include "Message.h" 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace i2pcpp { 15 | namespace I2NP { 16 | 17 | /** 18 | * Represents a negative response to an i2pcpp::DatabaseLookup search 19 | * message. This message type is used for failed database responses. 20 | * Rather than returning the value associated with the key, a list of 21 | * router hashes closest to the requested key are returned (typically 3). 22 | */ 23 | class DatabaseSearchReply : public Message { 24 | public: 25 | /** 26 | * @return the key of the object that was searched for 27 | */ 28 | const StaticByteArray<32>& getKey() const; 29 | 30 | /** 31 | * @return a list of typically 3 i2pcpp::RouterHash objects, 32 | * closest to the key 33 | */ 34 | const std::list& getHashes() const; 35 | 36 | /** 37 | * @return the i2pcpp::RouterHash of the sending router. 38 | * @warning this is unauthenticated, thus it should not be 39 | * trusted 40 | */ 41 | const RouterHash& getFrom() const; 42 | 43 | /** 44 | * Converts an i2pcpp::ByteArray to an i2pcpp::I2NP::DatabaseSearchReply 45 | * object. 46 | * The format to be parsed is the 32B key, followed by a 1B 47 | * integer (size), followed by \a size 32B i2pcpp::RouterHash 48 | * objects and an i2pcpp::RouterHash (from field). 49 | */ 50 | static DatabaseSearchReply parse(ByteArrayConstItr &begin, ByteArrayConstItr end); 51 | 52 | protected: 53 | DatabaseSearchReply() = default; 54 | 55 | /** 56 | * Puts the 32B key, the 1B size integer, the \a size 57 | * i2pcpp::RouterHash objects and the from i2pcpp::RouterHash 58 | * in an i2pcpp::ByteArray. 59 | */ 60 | ByteArray compile() const; 61 | 62 | private: 63 | StaticByteArray<32> m_key; 64 | std::list m_hashes; 65 | RouterHash m_from; 66 | }; 67 | } 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/version.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_VERSION_HPP 29 | #define WEBSOCKETPP_VERSION_HPP 30 | 31 | /// Namespace for the WebSocket++ project 32 | namespace websocketpp { 33 | 34 | /* 35 | other places where version information is kept 36 | - readme.md 37 | - changelog.md 38 | - Doxyfile 39 | - CMakeLists.txt 40 | */ 41 | 42 | /// Library major version number 43 | static int const major_version = 0; 44 | /// Library minor version number 45 | static int const minor_version = 3; 46 | /// Library patch version number 47 | static int const patch_version = 0; 48 | /// Library pre-release flag 49 | /** 50 | * This is a textual flag indicating the type and number for pre-release 51 | * versions (dev, alpha, beta, rc). This will be blank for release versions. 52 | */ 53 | static char const prerelease_flag[] = "alpha4"; 54 | 55 | /// Default user agent string 56 | static char const user_agent[] = "WebSocket++/0.3.0-alpha4"; 57 | 58 | } // namespace websocketpp 59 | 60 | #endif // WEBSOCKETPP_VERSION_HPP 61 | -------------------------------------------------------------------------------- /lib/i2p/i2np/VariableTunnelBuildReply.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file VariableTunnelBuildReply.h 3 | * @brief Defines the i2pcpp::I2NP::VariableTunnelBuildReply message type. 4 | */ 5 | #ifndef I2NPVARIABLETUNNELBUILDREPLY_H 6 | #define I2NPVARIABLETUNNELBUILDREPLY_H 7 | 8 | #include "Message.h" 9 | 10 | #include 11 | 12 | #include 13 | 14 | namespace i2pcpp { 15 | namespace I2NP { 16 | 17 | /** 18 | * Represents a response to an i2pcpp::I2NP::VariableTunnelBuild message. 19 | * For outbound tunnels, these messages are created by the OBEP and sent 20 | * into the reply tunnel (an inbound tunnel specified in the 21 | * i2pcpp::BuildRequestRecord object). 22 | * For inbound tunnels, this is not used, as the last hop of such a tunnel 23 | * is the tunnel creator. 24 | */ 25 | class VariableTunnelBuildReply : public Message { 26 | public: 27 | /** 28 | * Constructs from a std::list of pointers to i2pcpp::BuildRecord objects. 29 | */ 30 | VariableTunnelBuildReply(std::list const &buildRecords); 31 | 32 | /** 33 | * Constructs from a \a msgId and a std::list of pointers to 34 | * i2pcpp::BuildRecord objects. 35 | */ 36 | VariableTunnelBuildReply(uint32_t msgId, std::list const &buildRecords); 37 | 38 | /** 39 | * @return the std::list of pointers to i2pcpp::BuildRecord objects 40 | */ 41 | std::list getRecords() const; 42 | 43 | /** 44 | * Converts an i2pcpp::ByteArray to an 45 | * i2pcpp::I2NP::VariableTunnelBuildReply object. 46 | * The format to be parsed is a 1B intger specifying the amount 47 | * of i2pcpp::BuildRecord objects, followed by that many 48 | * i2pcpp::BuildRecord objects. 49 | */ 50 | static VariableTunnelBuildReply parse(ByteArrayConstItr &begin, ByteArrayConstItr end); 51 | 52 | protected: 53 | VariableTunnelBuildReply() = default; 54 | 55 | /** 56 | * Puts the 1B i2pcpp::BuildRecord count, followed by that many 57 | * i2pcpp::BuildRecord objects in an i2pcpp::ByteArray. 58 | */ 59 | ByteArray compile() const; 60 | 61 | private: 62 | std::list m_buildRecords; 63 | }; 64 | } 65 | } 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/logger/stub.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_LOGGER_STUB_HPP 29 | #define WEBSOCKETPP_LOGGER_STUB_HPP 30 | 31 | #include 32 | 33 | #include 34 | #include 35 | 36 | namespace websocketpp { 37 | namespace log { 38 | 39 | /// Stub logger that ignores all input 40 | class stub { 41 | public: 42 | explicit stub(std::ostream * out) {} 43 | stub(level c, std::ostream * out) {} 44 | _WEBSOCKETPP_CONSTEXPR_TOKEN_ stub() {} 45 | 46 | void set_channels(level channels) {} 47 | void clear_channels(level channels) {} 48 | 49 | void write(level channel, std::string const & msg) {} 50 | void write(level channel, char const * msg) {} 51 | 52 | _WEBSOCKETPP_CONSTEXPR_TOKEN_ bool static_test(level channel) const { 53 | return false; 54 | } 55 | bool dynamic_test(level channel) { 56 | return false; 57 | } 58 | }; 59 | 60 | } // log 61 | } // websocketpp 62 | 63 | #endif // WEBSOCKETPP_LOGGER_STUB_HPP 64 | -------------------------------------------------------------------------------- /frontends/console/websocketpp/random/none.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | */ 27 | 28 | #ifndef WEBSOCKETPP_RANDOM_NONE_HPP 29 | #define WEBSOCKETPP_RANDOM_NONE_HPP 30 | 31 | namespace websocketpp { 32 | namespace random { 33 | /// Stub RNG policy that always returns 0 34 | namespace none { 35 | 36 | /// Thread safe stub "random" integer generator. 37 | /** 38 | * This template class provides a random integer stub. The interface mimics the 39 | * WebSocket++ RNG generator classes but the generater function always returns 40 | * zero. This can be used to stub out the RNG for unit and performance testing. 41 | * 42 | * Call operator() to generate the next number 43 | */ 44 | template 45 | class int_generator { 46 | public: 47 | int_generator() {} 48 | 49 | /// advances the engine's state and returns the generated value 50 | int_type operator()() { 51 | return 0; 52 | } 53 | }; 54 | 55 | } // namespace none 56 | } // namespace random 57 | } // namespace websocketpp 58 | 59 | #endif //WEBSOCKETPP_RANDOM_NONE_HPP 60 | -------------------------------------------------------------------------------- /include/i2pcpp/datatypes/RouterAddress.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file RouterAddress.h 3 | * @brief Defines the i2pcpp::RouterAddress datatype. 4 | */ 5 | #ifndef ROUTERADDRESS_H 6 | #define ROUTERADDRESS_H 7 | 8 | #include "Datatype.h" 9 | #include "Date.h" 10 | #include "Mapping.h" 11 | 12 | #include 13 | 14 | namespace i2pcpp { 15 | 16 | /** 17 | * Datatype that allows a router to be contacted through a transport protocol. 18 | */ 19 | class RouterAddress : public Datatype { 20 | public: 21 | /** 22 | * @param cost the weighed cost of using the address (0 = free, 255 = expensive) 23 | * @param expiration the expiration date of the address 24 | * @param transport the type of transport used as a string 25 | * @param options i2pcpp::Mapping of options related to transport 26 | * @warning expiration must be zero (currently unusued) 27 | * @note cost is used for hashcash 28 | */ 29 | RouterAddress(int cost, Date const &expiration, std::string const &transport, Mapping const &options); 30 | 31 | /** 32 | * Constructs from iterators to the begin and end of an i2pcpp::ByteArray. 33 | * Format must be: 34 | * cost (1B) | expiration (8B) | len (1B) | transport (len) | options 35 | */ 36 | RouterAddress(ByteArrayConstItr &begin, ByteArrayConstItr end); 37 | 38 | /** 39 | * Serializes the object into an i2pcpp::ByteArray with the following 40 | * format: 41 | * cost (1B) | expiration (8B) | len (1B) | transport (len) | options 42 | */ 43 | ByteArray serialize() const; 44 | 45 | /** 46 | * @return the cost of using the address (0 = free, 255 = expensive) 47 | */ 48 | const unsigned char getCost() const; 49 | 50 | /** 51 | * @return the expiration date 52 | * @warning curently unused 53 | */ 54 | const Date& getExpiration() const; 55 | 56 | /** 57 | * @return the transport type as a string 58 | */ 59 | const std::string& getTransport() const; 60 | 61 | /** 62 | * @return the i2pcpp::Mapping containing all the options related 63 | * to the transport. 64 | */ 65 | const Mapping& getOptions() const; 66 | 67 | private: 68 | unsigned char m_cost; 69 | Date m_expiration; 70 | std::string m_transport; 71 | Mapping m_options; 72 | }; 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /lib/ssu/OutboundMessageFragments.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file OutboundMessageFragments.h 3 | * @brief Defines the i2pcpp::SSU::OutboundMessageFragments class. 4 | */ 5 | #ifndef SSUOUTBOUNDMESSAGEFRAGMENTS_H 6 | #define SSUOUTBOUNDMESSAGEFRAGMENTS_H 7 | 8 | #include "OutboundMessageState.h" 9 | 10 | #include 11 | 12 | namespace i2pcpp { 13 | namespace SSU { 14 | class Context; 15 | class PeerState; 16 | 17 | /** 18 | * Manages (fragments) of messages sent by this router. 19 | */ 20 | class OutboundMessageFragments { 21 | friend class InboundMessageFragments; 22 | 23 | public: 24 | /** 25 | * Constructs from a reference to the i2pcpp::UDPTransport object. 26 | */ 27 | OutboundMessageFragments(Context &c); 28 | OutboundMessageFragments(const OutboundMessageFragments &) = delete; 29 | OutboundMessageFragments& operator=(OutboundMessageFragments &) = delete; 30 | 31 | /** 32 | * Writes a message given by its \a msgId to the i2pcpp::SSU::PeerState 33 | * \a ps. 34 | */ 35 | void sendData(PeerState const &ps, uint32_t const msgId, ByteArray const &data); 36 | 37 | private: 38 | /** 39 | * Removes a state from the states std::map, OutboundMessageFragments::m_states. 40 | * @param msgId the message ID of the state to be deleted 41 | */ 42 | void delState(const uint32_t msgId); 43 | 44 | /** 45 | * Iterates over all of the states and sends the (incomplete) messages 46 | * using the i2pcpp::UDPTranport. If not all of the fragments have 47 | * been sent, posts a message to the IO service to call this function 48 | * again. 49 | */ 50 | void sendDataCallback(PeerState ps, uint32_t const msgId); 51 | 52 | /** 53 | * Called when the timer's deadline expires. Tries to resend the 54 | * next un ACK'd fragment for the message. If it this had been 55 | * tried more than 5 times before, removes the timer for the 56 | * given \a msgId. 57 | */ 58 | void timerCallback(const boost::system::error_code& e, PeerState ps, uint32_t const msgId); 59 | 60 | std::map m_states; 61 | 62 | mutable std::mutex m_mutex; 63 | 64 | Context& m_context; 65 | }; 66 | } 67 | } 68 | 69 | #endif 70 | --------------------------------------------------------------------------------