summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorevoskuil <eric@voskuil.org>2014-03-25 06:06:59 (GMT)
committer evoskuil <eric@voskuil.org>2014-03-25 06:06:59 (GMT)
commit3dd0cf9dec031e519991fb2f39820d1e69639a3a (patch)
tree9819b0de130b6cb5da9d39351f42a89baff78621
parentdf9455a50dc18f055922373a9c0c8f4fafa65787 (diff)
parent16c81b855475105d616b30542104d8ee6a1acf30 (diff)
Merge branch 'spesmilo/master'
-rwxr-xr-xautogen.sh3
-rw-r--r--builds/msvc/vs2013/obelisk/obelisk.props10
-rw-r--r--builds/msvc/vs2013/obelisk/obelisk.vcxproj28
-rw-r--r--builds/msvc/vs2013/obelisk/obelisk.vcxproj.filters28
-rw-r--r--builds/msvc/vs2013/properties/Common.props2
-rw-r--r--builds/msvc/vs2013/properties/Debug.props2
-rw-r--r--builds/msvc/vs2013/properties/Release.props2
-rw-r--r--builds/msvc/vs2013/properties/x64.props6
-rw-r--r--src/client/interface/client_blockchain.cpp (renamed from src/client/interface/blockchain.cpp)4
-rw-r--r--src/client/interface/client_fetch_x.cpp (renamed from src/client/interface/fetch_x.cpp)4
-rw-r--r--src/client/interface/client_fetch_x.hpp (renamed from src/client/interface/fetch_x.hpp)0
-rw-r--r--src/client/interface/client_interface.cpp (renamed from src/client/interface/interface.cpp)4
-rw-r--r--src/client/interface/client_protocol.cpp (renamed from src/client/interface/protocol.cpp)2
-rw-r--r--src/client/interface/client_transaction_pool.cpp (renamed from src/client/interface/transaction_pool.cpp)4
-rw-r--r--src/client/interface/client_util.hpp (renamed from src/client/interface/util.hpp)0
-rw-r--r--src/worker/config.cpp63
-rw-r--r--src/worker/config.hpp22
-rw-r--r--src/worker/main.cpp51
-rw-r--r--src/worker/node_impl.cpp37
-rw-r--r--src/worker/node_impl.hpp5
-rw-r--r--src/worker/publisher.cpp14
21 files changed, 182 insertions, 109 deletions
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..b50dab0
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+autoreconf -i
+
diff --git a/builds/msvc/vs2013/obelisk/obelisk.props b/builds/msvc/vs2013/obelisk/obelisk.props
index 1df887a..61aa89b 100644
--- a/builds/msvc/vs2013/obelisk/obelisk.props
+++ b/builds/msvc/vs2013/obelisk/obelisk.props
@@ -8,14 +8,14 @@
<RunCodeAnalysis>false</RunCodeAnalysis>
</PropertyGroup>
+ <!-- TODO: incorporate _MSC_VER in places where there is a MSVC (vs. Windows/_WIN32) dependency. -->
+ <!-- If the version number of the Visual C++ compiler is 17.00.51106.1, the _MSC_VER macro evaluates to 1700. -->
<ItemDefinitionGroup>
<ClCompile>
- <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\include\;$(ProjectDir)..\..\..\..\include\obelisk\;$(ProjectDir)..\..\..\..\include\obelisk\client\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\..\libbitcoin\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\..\czmqpp\include\;$(ProjectDir)..\..\..\..\..\czmq\include\;$(ProjectDir)..\..\..\..\..\libzmq\include\;(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>$(ProjectDir)..\..\..\..\include\;%(AdditionalIncludeDirectories);$(ProjectDir)..\..\..\..\..\libbitcoin\include\;$(ProjectDir)..\..\..\..\..\czmqpp\include\;$(ProjectDir)..\..\..\..\..\czmq\include\;$(ProjectDir)..\..\..\..\..\libzmq\include\;(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4290;4275;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<EnablePREfast>false</EnablePREfast>
- <PreprocessorDefinitions>_WINDOWS;LEVELDB_ENABLED;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <PreprocessorDefinitions>LEVELDB_ENABLED;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<AdditionalDependencies>libbitcoin.lib;%(AdditionalDependencies)</AdditionalDependencies>
@@ -41,7 +41,7 @@
<ItemDefinitionGroup Condition="$(Configuration.IndexOf('Debug')) != -1">
<Link>
<AdditionalLibraryDirectories>$(ProjectDir)..\..\..\..\..\libbitcoin\bin\$(PlatformName)\Debug\</AdditionalLibraryDirectories>
- <!--<AdditionalDependencies>czmqpp_d.lib;czmq_d.lib;libzmq_d.lib;%(AdditionalDependencies)</AdditionalDependencies>-->
+ <AdditionalDependencies>czmqpp_d.lib;czmq_d.lib;libzmq_d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
diff --git a/builds/msvc/vs2013/obelisk/obelisk.vcxproj b/builds/msvc/vs2013/obelisk/obelisk.vcxproj
index 6686522..b455751 100644
--- a/builds/msvc/vs2013/obelisk/obelisk.vcxproj
+++ b/builds/msvc/vs2013/obelisk/obelisk.vcxproj
@@ -1,9 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="..\..\..\..\..\..\nuget\LevelDB.1.16.0.5\build\native\LevelDB.props" Condition="Exists('..\..\..\..\..\..\nuget\LevelDB.1.16.0.5\build\native\LevelDB.props')" />
- <Import Project="..\..\..\..\..\..\nuget\Snappy.1.1.1.7\build\native\Snappy.props" Condition="Exists('..\..\..\..\..\..\nuget\Snappy.1.1.1.7\build\native\Snappy.props')" />
- <Import Project="..\..\..\..\..\..\nuget\Crc32C.1.0.4\build\native\Crc32C.props" Condition="Exists('..\..\..\..\..\..\nuget\Crc32C.1.0.4\build\native\Crc32C.props')" />
- <Import Project="..\..\..\..\..\..\nuget\openssl.1.0.1.24\build\native\openssl.props" Condition="Exists('..\..\..\..\..\..\nuget\openssl.1.0.1.24\build\native\openssl.props')" />
<PropertyGroup Label="Globals">
<ProjectGuid>{B0BB6841-1FA9-4E09-8672-5B5419971EF6}</ProjectGuid>
<ProjectName>obelisk</ProjectName>
@@ -173,20 +169,23 @@
<Import Project="$(ProjectDir)..\properties\x64.props" />
</ImportGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugDLL|Win32'">
+ <ClCompile />
+ </ItemDefinitionGroup>
+ <!--<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugDLL|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>C:\Source\nuget\LevelDB.1.16.0.5\lib\native\include\;C:\Source\nuget\Snappy.1.1.1.7\lib\native\include\;C:\Source\nuget\Crc32C.1.0.4\lib\native\include\;$(ProjectDir)..\..\..\..\include\;$(ProjectDir)..\..\..\..\include\obelisk\;$(ProjectDir)..\..\..\..\include\obelisk\client\;$(ProjectDir)..\..\..\..\..\libbitcoin\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
- </ItemDefinitionGroup>
+ </ItemDefinitionGroup>-->
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\src\client\backend.cpp" />
- <ClCompile Include="..\..\..\..\src\client\interface\blockchain.cpp" />
- <ClCompile Include="..\..\..\..\src\client\interface\fetch_x.cpp" />
- <ClCompile Include="..\..\..\..\src\client\interface\interface.cpp" />
- <ClCompile Include="..\..\..\..\src\client\interface\protocol.cpp" />
- <ClCompile Include="..\..\..\..\src\client\interface\transaction_pool.cpp" />
+ <ClCompile Include="..\..\..\..\src\client\interface\client_blockchain.cpp" />
+ <ClCompile Include="..\..\..\..\src\client\interface\client_fetch_x.cpp" />
+ <ClCompile Include="..\..\..\..\src\client\interface\client_interface.cpp" />
+ <ClCompile Include="..\..\..\..\src\client\interface\client_protocol.cpp" />
+ <ClCompile Include="..\..\..\..\src\client\interface\client_transaction_pool.cpp" />
<ClCompile Include="..\..\..\..\src\message.cpp" />
<ClCompile Include="..\..\..\..\src\worker\config.cpp" />
<ClCompile Include="..\..\..\..\src\worker\echo.cpp" />
@@ -209,8 +208,8 @@
<ClInclude Include="..\..\..\..\include\obelisk\client\transaction_pool.hpp" />
<ClInclude Include="..\..\..\..\include\obelisk\message.hpp" />
<ClInclude Include="..\..\..\..\include\obelisk\obelisk.hpp" />
- <ClInclude Include="..\..\..\..\src\client\interface\fetch_x.hpp" />
- <ClInclude Include="..\..\..\..\src\client\interface\util.hpp" />
+ <ClInclude Include="..\..\..\..\src\client\interface\client_fetch_x.hpp" />
+ <ClInclude Include="..\..\..\..\src\client\interface\client_util.hpp" />
<ClInclude Include="..\..\..\..\src\worker\config.hpp" />
<ClInclude Include="..\..\..\..\src\worker\echo.hpp" />
<ClInclude Include="..\..\..\..\src\worker\node_impl.hpp" />
@@ -224,6 +223,11 @@
<ClInclude Include="..\..\..\..\src\worker\subscribe_manager.hpp" />
<ClInclude Include="..\..\..\..\src\worker\worker.hpp" />
</ItemGroup>
+ <!-- Move these? -->
+ <Import Project="..\..\..\..\..\..\nuget\LevelDB.1.16.0.5\build\native\LevelDB.props" Condition="Exists('..\..\..\..\..\..\nuget\LevelDB.1.16.0.5\build\native\LevelDB.props')" />
+ <Import Project="..\..\..\..\..\..\nuget\Snappy.1.1.1.7\build\native\Snappy.props" Condition="Exists('..\..\..\..\..\..\nuget\Snappy.1.1.1.7\build\native\Snappy.props')" />
+ <Import Project="..\..\..\..\..\..\nuget\Crc32C.1.0.4\build\native\Crc32C.props" Condition="Exists('..\..\..\..\..\..\nuget\Crc32C.1.0.4\build\native\Crc32C.props')" />
+ <Import Project="..\..\..\..\..\..\nuget\openssl.1.0.1.24\build\native\openssl.props" Condition="Exists('..\..\..\..\..\..\nuget\openssl.1.0.1.24\build\native\openssl.props')" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets" />
<ImportGroup Label="ExtensionSettings">
diff --git a/builds/msvc/vs2013/obelisk/obelisk.vcxproj.filters b/builds/msvc/vs2013/obelisk/obelisk.vcxproj.filters
index 74381dc..d4bc747 100644
--- a/builds/msvc/vs2013/obelisk/obelisk.vcxproj.filters
+++ b/builds/msvc/vs2013/obelisk/obelisk.vcxproj.filters
@@ -69,24 +69,24 @@
<ClCompile Include="..\..\..\..\src\client\backend.cpp">
<Filter>src\client</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\..\src\client\interface\fetch_x.cpp">
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\native\src\leveldb-single-file.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\native\src\snappy-single-file.cpp" />
+ <ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\native\src\crc32c.cpp" />
+ <ClCompile Include="..\..\..\..\src\client\interface\client_blockchain.cpp">
<Filter>src\client\interface</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\..\src\client\interface\interface.cpp">
+ <ClCompile Include="..\..\..\..\src\client\interface\client_fetch_x.cpp">
<Filter>src\client\interface</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\..\src\client\interface\protocol.cpp">
+ <ClCompile Include="..\..\..\..\src\client\interface\client_interface.cpp">
<Filter>src\client\interface</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\..\src\client\interface\transaction_pool.cpp">
+ <ClCompile Include="..\..\..\..\src\client\interface\client_protocol.cpp">
<Filter>src\client\interface</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\..\src\client\interface\blockchain.cpp">
+ <ClCompile Include="..\..\..\..\src\client\interface\client_transaction_pool.cpp">
<Filter>src\client\interface</Filter>
</ClCompile>
- <ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\native\src\leveldb-single-file.cpp" />
- <ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\native\src\snappy-single-file.cpp" />
- <ClCompile Include="$(MSBuildThisFileDirectory)..\..\lib\native\src\crc32c.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\src\worker\subscribe_manager.hpp">
@@ -125,12 +125,6 @@
<ClInclude Include="..\..\..\..\src\worker\service\transaction_pool.hpp">
<Filter>src\worker\service</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\..\src\client\interface\fetch_x.hpp">
- <Filter>src\client\interface</Filter>
- </ClInclude>
- <ClInclude Include="..\..\..\..\src\client\interface\util.hpp">
- <Filter>src\client\interface</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\..\include\obelisk\obelisk.hpp">
<Filter>include</Filter>
</ClInclude>
@@ -152,5 +146,11 @@
<ClInclude Include="..\..\..\..\include\obelisk\client\backend.hpp">
<Filter>include\client</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\..\src\client\interface\client_fetch_x.hpp">
+ <Filter>src\client\interface</Filter>
+ </ClInclude>
+ <ClInclude Include="..\..\..\..\src\client\interface\client_util.hpp">
+ <Filter>src\client\interface</Filter>
+ </ClInclude>
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/builds/msvc/vs2013/properties/Common.props b/builds/msvc/vs2013/properties/Common.props
index 9001a91..8fd7505 100644
--- a/builds/msvc/vs2013/properties/Common.props
+++ b/builds/msvc/vs2013/properties/Common.props
@@ -12,6 +12,8 @@
<ClCompile>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
+ <!-- Windows and CRT definitions for unicode. Note that Linux only supports unicode so char is UCS-16. -->
+ <PreprocessorDefinitions>UNICODE;_UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
diff --git a/builds/msvc/vs2013/properties/Debug.props b/builds/msvc/vs2013/properties/Debug.props
index 98eb2d0..7cc49fa 100644
--- a/builds/msvc/vs2013/properties/Debug.props
+++ b/builds/msvc/vs2013/properties/Debug.props
@@ -5,7 +5,7 @@
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<_PropertySheetDisplayName>Debug Configuration</_PropertySheetDisplayName>
<!-- RootNamespace is used to deconflict output files from differing project versions. -->
- <IntDir>$(ProjectDir)..\..\..\..\obj\$(PlatformName)\Debug\$(RootNamespace)\</IntDir>
+ <IntDir>$(ProjectDir)..\..\..\..\obj\$(PlatformName)\$(Configuration)\$(RootNamespace)\</IntDir>
<OutDir>$(ProjectDir)..\..\..\..\bin\$(PlatformName)\Debug\$(RootNamespace)\</OutDir>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
diff --git a/builds/msvc/vs2013/properties/Release.props b/builds/msvc/vs2013/properties/Release.props
index 8717c40..56767a3 100644
--- a/builds/msvc/vs2013/properties/Release.props
+++ b/builds/msvc/vs2013/properties/Release.props
@@ -5,7 +5,7 @@
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<_PropertySheetDisplayName>Release Configuration</_PropertySheetDisplayName>
<!-- RootNamespace is used to deconflict output files from differing project versions. -->
- <IntDir>$(ProjectDir)..\..\..\..\obj\$(PlatformName)\Release\$(RootNamespace)\</IntDir>
+ <IntDir>$(ProjectDir)..\..\..\..\obj\$(PlatformName)\$(Configuration)\$(RootNamespace)\</IntDir>
<OutDir>$(ProjectDir)..\..\..\..\bin\$(PlatformName)\Release\$(RootNamespace)\</OutDir>
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
diff --git a/builds/msvc/vs2013/properties/x64.props b/builds/msvc/vs2013/properties/x64.props
index 8c736a1..1c750d6 100644
--- a/builds/msvc/vs2013/properties/x64.props
+++ b/builds/msvc/vs2013/properties/x64.props
@@ -8,8 +8,10 @@
<ItemDefinitionGroup>
<ClCompile>
- <!-- Note that Win64 defines may cause WIN32 to become defined when using windows headers (Win32 implies any windows). -->
- <PreprocessorDefinitions>WIN64;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <!-- Note that Win64 defines may cause WIN32 to become defined when using windows headers,
+ but _WIN32 implies Windows 32 bit or above. If the standard headers are not included
+ these are sometimes required even for 64 bit builds and should never cause harm there.-->
+ <PreprocessorDefinitions>WIN32;_WIN32;WIN64;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<TargetMachine>MachineX64</TargetMachine>
diff --git a/src/client/interface/blockchain.cpp b/src/client/interface/client_blockchain.cpp
index 7c390ff..7947af1 100644
--- a/src/client/interface/blockchain.cpp
+++ b/src/client/interface/client_blockchain.cpp
@@ -1,7 +1,7 @@
#include <obelisk/client/blockchain.hpp>
-#include "fetch_x.hpp"
-#include "util.hpp"
+#include "client_fetch_x.hpp"
+#include "client_util.hpp"
namespace obelisk {
diff --git a/src/client/interface/fetch_x.cpp b/src/client/interface/client_fetch_x.cpp
index 8079098..21714ff 100644
--- a/src/client/interface/fetch_x.cpp
+++ b/src/client/interface/client_fetch_x.cpp
@@ -1,6 +1,6 @@
-#include "fetch_x.hpp"
+#include "client_fetch_x.hpp"
-#include "util.hpp"
+#include "client_util.hpp"
namespace obelisk {
diff --git a/src/client/interface/fetch_x.hpp b/src/client/interface/client_fetch_x.hpp
index 723462a..723462a 100644
--- a/src/client/interface/fetch_x.hpp
+++ b/src/client/interface/client_fetch_x.hpp
diff --git a/src/client/interface/interface.cpp b/src/client/interface/client_interface.cpp
index 607203a..badabfd 100644
--- a/src/client/interface/interface.cpp
+++ b/src/client/interface/client_interface.cpp
@@ -1,8 +1,8 @@
#include <obelisk/client/interface.hpp>
#include <bitcoin/bitcoin.hpp>
-#include "fetch_x.hpp"
-#include "util.hpp"
+#include "client_fetch_x.hpp"
+#include "client_util.hpp"
namespace obelisk {
diff --git a/src/client/interface/protocol.cpp b/src/client/interface/client_protocol.cpp
index d502d82..f0df6f7 100644
--- a/src/client/interface/protocol.cpp
+++ b/src/client/interface/client_protocol.cpp
@@ -1,6 +1,6 @@
#include <obelisk/client/protocol.hpp>
-#include "util.hpp"
+#include "client_util.hpp"
namespace obelisk {
diff --git a/src/client/interface/transaction_pool.cpp b/src/client/interface/client_transaction_pool.cpp
index 8c5931c..cbc0fd2 100644
--- a/src/client/interface/transaction_pool.cpp
+++ b/src/client/interface/client_transaction_pool.cpp
@@ -1,7 +1,7 @@
#include <obelisk/client/transaction_pool.hpp>
-#include "fetch_x.hpp"
-#include "util.hpp"
+#include "client_fetch_x.hpp"
+#include "client_util.hpp"
namespace obelisk {
diff --git a/src/client/interface/util.hpp b/src/client/interface/client_util.hpp
index c8e2c2e..c8e2c2e 100644
--- a/src/client/interface/util.hpp
+++ b/src/client/interface/client_util.hpp
diff --git a/src/worker/config.cpp b/src/worker/config.cpp
index a453fa0..b16b4b0 100644
--- a/src/worker/config.cpp
+++ b/src/worker/config.cpp
@@ -1,5 +1,7 @@
#include "config.hpp"
+#include <iostream>
+#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
#include <libconfig.h++>
#include "echo.hpp"
@@ -46,20 +48,67 @@ void load_whitelist(const libconfig::Setting& root, config_type& config)
catch (const libconfig::SettingNotFoundException&) {}
}
-void load_config(config_type& config, const std::string& filename)
+// Address string cross-compile as char and std::string are non-unicode on
+// Windows, which pre-dates unicode so char is ANSI and wchar_t is UCS-16.
+// TODO: centralize this in cross-compile header(s).
+#if defined(_WIN32) && defined(UNICODE)
+#define tmain wmain
+typedef wchar_t tchar;
+typedef std::wstring tstring;
+typedef boost::filesystem::wpath tpath;
+#else
+#define tmain main
+#define L
+typedef char tchar;
+typedef std::string tstring;
+typedef boost::filesystem::path tpath;
+#endif
+
+#ifdef _WIN32
+#include <shlobj.h>
+#include <windows.h>
+tstring system_config_directory()
+{
+ // Use explicitly wide char functions and compile for unicode.
+ tchar app_data_path[MAX_PATH];
+ auto result = SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL,
+ SHGFP_TYPE_CURRENT, app_data_path);
+ return tstring(SUCCEEDED(result) ? app_data_path : L"");
+}
+#else
+tstring system_config_directory()
+{
+ return tstring(SYSCONFDIR);
+}
+#endif
+
+void set_config_path(libconfig::Config& configuration, const tpath& config_path)
{
- // Load values from config file.
- echo() << "Using config file: " << filename;
- libconfig::Config cfg;
// Ignore error if unable to read config file.
try
{
- cfg.readFile(filename.c_str());
+ // libconfig is ANSI/MBCS on Windows - no Unicode support.
+ // This translates the path from Unicode to a "generic" path in
+ // ANSI/MBCS, which can result in failures.
+ configuration.readFile(config_path.generic_string().c_str());
}
catch (const libconfig::FileIOException&) {}
catch (const libconfig::ParseException&) {}
- // Read off values
- const libconfig::Setting& root = cfg.getRoot();
+}
+
+void load_config(config_type& config, tpath& config_path)
+{
+ // Load values from config file.
+ echo() << "Using config file: " << config_path;
+
+ libconfig::Config configuration;
+ set_config_path(configuration, config_path);
+
+ // Read off values.
+ // libconfig is ANSI/MBCS on Windows - no Unicode support.
+ // This reads ANSI/MBCS values from XML. If they are UTF-8 (and above the
+ // ASCII band) the values will be misinterpreted upon use.
+ const libconfig::Setting& root = configuration.getRoot();
root.lookupValue("output-file", config.output_file);
root.lookupValue("error-file", config.error_file);
root.lookupValue("blockchain-path", config.blockchain_path);
diff --git a/src/worker/config.hpp b/src/worker/config.hpp
index f88166a..5d51a0e 100644
--- a/src/worker/config.hpp
+++ b/src/worker/config.hpp
@@ -5,6 +5,21 @@
#include <string>
#include <vector>
#include <stdint.h>
+#include <boost/filesystem.hpp>
+
+// Address string cross-compile as char and std::string are non-unicode on
+// Windows, which pre-dates unicode so char is ANSI and wchar_t is UCS-16.
+// TODO: centralize this in cross-compile header(s).
+#if defined(_WIN32) && defined(UNICODE)
+typedef wchar_t tchar;
+typedef std::wstring tstring;
+typedef boost::filesystem::wpath tpath;
+#else
+#define L
+typedef char tchar;
+typedef std::string tstring;
+typedef boost::filesystem::path tpath;
+#endif
namespace obelisk {
@@ -38,9 +53,10 @@ struct config_type
bool log_requests = false;
};
-void load_config(config_type& config, const std::string& config_path);
+typedef std::map<std::string, std::string> config_map_type;
+void load_config(config_type& config, tpath& config_path);
+tstring system_config_directory();
} // namespace obelisk
-#endif
-
+#endif \ No newline at end of file
diff --git a/src/worker/main.cpp b/src/worker/main.cpp
index 701fd25..7e1b053 100644
--- a/src/worker/main.cpp
+++ b/src/worker/main.cpp
@@ -2,6 +2,7 @@
#include <obelisk/message.hpp>
#include <bitcoin/bitcoin.hpp>
#include <signal.h>
+#include <string>
#include "echo.hpp"
#include "worker.hpp"
#include "node_impl.hpp"
@@ -12,11 +13,11 @@
#include "service/protocol.hpp"
#include "service/transaction_pool.hpp"
-using namespace bc;
using namespace obelisk;
+using namespace obelisk::bc;
+
using std::placeholders::_1;
using std::placeholders::_2;
-using boost::filesystem::path;
bool stopped = false;
void interrupt_handler(int)
@@ -25,46 +26,28 @@ void interrupt_handler(int)
stopped = true;
}
-#ifdef _WIN32
-#include <shlobj.h>
-#include <windows.h>
-const wchar_t* system_config_directory()
+int tmain(int argc, tchar* argv[])
{
- wchar_t app_data_path[MAX_PATH];
- auto result = SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL,
- SHGFP_TYPE_CURRENT, app_data_path);
+ config_type configuration;
+ tpath config_path = argc < 2 ?
+ tpath(system_config_directory()) / "obelisk" / "worker.cfg" :
+ tpath(argv[1]);
- // fix
- return SUCCEEDED(result) ? app_data_path : nullptr;
-}
-#else
-const char* system_config_directory()
-{
- // verify
- return SYSCONFDIR;
-}
-#endif
+ // libconfig is ANSI/MBCS on Windows - no Unicode support.
+ // This translates the path from Unicode to a "generic" path in
+ // ANSI/MBCS, which can result in failures.
+ load_config(configuration, config_path);
-int main(int argc, char** argv)
-{
- config_type config;
- if (argc == 2)
- load_config(config, argv[1]);
- else
- {
- path conf_filename = path(system_config_directory()) / "obelisk" / "worker.cfg";
- load_config(config, conf_filename.generic_string());
- }
echo() << "Press CTRL-C to shut down.";
// Create worker.
request_worker worker;
- worker.start(config);
+ worker.start(configuration);
// Fullnode
node_impl node;
// Publisher
publisher publish(node);
- if (config.publisher_enabled)
- if (!publish.start(config))
+ if (configuration.publisher_enabled)
+ if (!publish.start(configuration))
{
std::cerr << "Failed to start publisher: "
<< zmq_strerror(zmq_errno()) << std::endl;
@@ -103,7 +86,7 @@ int main(int argc, char** argv)
transaction_pool_fetch_transaction);
// Start the node last so that all subscriptions to new blocks
// don't miss anything.
- if (!node.start(config))
+ if (!node.start(configuration))
{
std::cerr << "Failed to start Bitcoin node." << std::endl;
return 1;
@@ -114,7 +97,7 @@ int main(int argc, char** argv)
while (!stopped)
worker.update();
worker.stop();
- if (config.publisher_enabled)
+ if (configuration.publisher_enabled)
publish.stop();
if (!node.stop())
return -1;
diff --git a/src/worker/node_impl.cpp b/src/worker/node_impl.cpp
index 5670348..cdd1334 100644
--- a/src/worker/node_impl.cpp
+++ b/src/worker/node_impl.cpp
@@ -1,17 +1,21 @@
#include "node_impl.hpp"
#include <future>
+#include <iostream>
#include <boost/lexical_cast.hpp>
#include "echo.hpp"
namespace obelisk {
using namespace bc;
+using namespace boost::posix_time;
using std::placeholders::_1;
using std::placeholders::_2;
using std::placeholders::_3;
using std::placeholders::_4;
+const time_duration retry_start_duration = seconds(30);
+
void log_to_file(std::ofstream& file, log_level level,
const std::string& domain, const std::string& body, bool log_requests)
{
@@ -73,7 +77,8 @@ node_impl::node_impl()
txpool_(mem_pool_, chain_),
indexer_(mem_pool_),
session_(mem_pool_, {
- handshake_, protocol_, chain_, poller_, txpool_})
+ handshake_, protocol_, chain_, poller_, txpool_}),
+ retry_start_timer_(mem_pool_.service())
{
}
@@ -131,22 +136,28 @@ bool node_impl::start(config_type& config)
log_info() << "Adding node: " << node.hostname << " " << node.port;
protocol_.maintain_connection(node.hostname, node.port);
}
+ start_session();
+ return true;
+}
+void node_impl::start_session()
+{
// Start session
- std::promise<std::error_code> ec_session;
- auto session_started =
- [&](const std::error_code& ec)
+ auto session_started = [this](const std::error_code& ec)
{
- ec_session.set_value(ec);
+ if (ec)
+ wait_and_retry_start(ec);
};
session_.start(session_started);
- // Query the error_code and wait for startup completion.
- ec = ec_session.get_future().get();
- if (ec)
- {
- log_error() << "Unable to start session: " << ec.message();
- return false;
- }
- return true;
+}
+void node_impl::wait_and_retry_start(const std::error_code& ec)
+{
+ BITCOIN_ASSERT(ec);
+ log_error() << "Unable to start session: " << ec.message();
+ log_error() << "Retrying in "
+ << retry_start_duration.seconds() << " seconds.";
+ retry_start_timer_.expires_from_now(retry_start_duration);
+ retry_start_timer_.async_wait(
+ std::bind(&node_impl::start_session, this));
}
bool node_impl::stop()
diff --git a/src/worker/node_impl.hpp b/src/worker/node_impl.hpp
index 9231281..d3bed3b 100644
--- a/src/worker/node_impl.hpp
+++ b/src/worker/node_impl.hpp
@@ -35,6 +35,9 @@ private:
typedef std::vector<block_notify_callback> block_notify_list;
typedef std::vector<transaction_notify_callback> transaction_notify_list;
+ void start_session();
+ void wait_and_retry_start(const std::error_code& ec);
+
void monitor_tx(const std::error_code& ec, bc::channel_ptr node);
void recv_transaction(const std::error_code& ec,
const bc::transaction_type& tx, bc::channel_ptr node);
@@ -62,6 +65,8 @@ private:
block_notify_list notify_blocks_;
transaction_notify_list notify_txs_;
+
+ boost::asio::deadline_timer retry_start_timer_;
};
} // namespace obelisk
diff --git a/src/worker/publisher.cpp b/src/worker/publisher.cpp
index 02ac145..8ad454d 100644
--- a/src/worker/publisher.cpp
+++ b/src/worker/publisher.cpp
@@ -57,18 +57,16 @@ bool publisher::send_blk(uint32_t height, const block_type& blk)
BITCOIN_ASSERT(raw_height.size() == 4);
// Serialize the 80 byte header.
data_chunk raw_blk_header(bc::satoshi_raw_size(blk.header));
- satoshi_save(blk.header, raw_blk_header.begin());
+ auto it = satoshi_save(blk.header, raw_blk_header.begin());
+ BITCOIN_ASSERT(it == raw_blk_header.end());
+ BITCOIN_ASSERT(raw_blk_header.size() == 80);
// Construct the message.
// height [4 bytes]
- // hash [32 bytes]
- // txs size [4 bytes]
+ // header [80 bytes]
// ... txs ...
czmqpp::message message;
message.append(raw_height);
- append_hash(message, hash_block_header(blk.header));
message.append(raw_blk_header);
- data_chunk raw_txs_size = bc::uncast_type(blk.transactions.size());
- message.append(raw_txs_size);
// Clients should be buffering their unconfirmed txs
// and only be requesting those they don't have.
for (const bc::transaction_type& tx: blk.transactions)
@@ -85,9 +83,9 @@ bool publisher::send_blk(uint32_t height, const block_type& blk)
bool publisher::send_tx(const transaction_type& tx)
{
data_chunk raw_tx(bc::satoshi_raw_size(tx));
- satoshi_save(tx, raw_tx.begin());
+ auto it = satoshi_save(tx, raw_tx.begin());
+ BITCOIN_ASSERT(it == raw_tx.end());
czmqpp::message message;
- append_hash(message, hash_transaction(tx));
message.append(raw_tx);
if (!message.send(socket_tx_))
{