1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
diff --git a/.gitignore b/.gitignore
index 4a0174f..e1c7852 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,4 +6,4 @@
/cmake-build-debug-visual-studio/
/cmake-build-release/
/cmake-build-release-ccache/
-/cmake-build-releasewithtests
+/cmake-build-release-with-tests/
diff --git a/main.cpp b/main.cpp
index f80f15c..6a9f0d5 100644
--- a/main.cpp
+++ b/main.cpp
@@ -15,8 +15,12 @@
*/
#include <iostream>
+
+#include <boost/filesystem.hpp>
+
#include <git_info.h>
+#include "scn/Common/Common.h"
#include "scn/Miner/MinerLocal.h"
#include "scn/Blockchain/Blockchain.h"
#include "scn/P2PConnector/P2PConnector.h"
@@ -41,6 +45,8 @@ int startCommandLineApp(int argc, char* argv[]) {
return 1;
}
+ boost::filesystem::create_directory(scn::path_helper::getRuntimeDir());
+
std::srand(std::time(nullptr));
std::ifstream public_key_stream(argv[1]);
@@ -49,7 +55,7 @@ int startCommandLineApp(int argc, char* argv[]) {
std::stringstream private_key_string;
private_key_string << private_key_stream.rdbuf();
- scn::Blockchain blockchain("./blockchains/" + std::string(argv[4]) + "/");
+ scn::Blockchain blockchain(scn::path_helper::getRuntimeDir() + "blockchains/" + std::string(argv[4]) + "/");
scn::P2PConnector p2p_connector(std::stoi(std::string(argv[4])), blockchain);
scn::MinerLocal miner(std::stoi(std::string(argv[3])));
scn::BlockchainManager manager(public_key, private_key_string.str(), blockchain, p2p_connector, miner);
diff --git a/src/scn/Common/Common.cpp b/src/scn/Common/Common.cpp
index 1d55842..7683299 100644
--- a/src/scn/Common/Common.cpp
+++ b/src/scn/Common/Common.cpp
@@ -16,6 +16,10 @@
#include "Common.h"
+#include <iostream>
+
+#include <boost/filesystem.hpp>
+
using namespace scn;
std::string scn::hash_helper::toString(const hash_t& hash) {
@@ -37,4 +41,13 @@ hash_t scn::hash_helper::fromArray(const uint8_t* array) {
ret |= array[i];
}
return ret;
+}
+
+
+std::string scn::path_helper::getRuntimeDir() {
+
+ std::stringstream runtime_dir;
+ runtime_dir << boost::filesystem::temp_directory_path().string() << "/" << "SwabianCoin-" << getpid() << "/";
+ return runtime_dir.str();
+
}
\ No newline at end of file
diff --git a/src/scn/Common/Common.h b/src/scn/Common/Common.h
index e19acc0..ee511ad 100644
--- a/src/scn/Common/Common.h
+++ b/src/scn/Common/Common.h
@@ -64,6 +64,12 @@ namespace scn {
hash_t fromArray(const uint8_t* array);
}
+
+ namespace path_helper {
+
+ std::string getRuntimeDir();
+
+ }
}
diff --git a/src/scn/P2PConnector/P2PConnector.cpp b/src/scn/P2PConnector/P2PConnector.cpp
index 041ee5e..735b852 100644
--- a/src/scn/P2PConnector/P2PConnector.cpp
+++ b/src/scn/P2PConnector/P2PConnector.cpp
@@ -52,7 +52,7 @@ P2PConnector::P2PConnector(uint16_t port, const Blockchain& blockchain)
t.add_node(std::pair<std::string, int>(entry_point.first, entry_point.second));
}
libtorrent::set_piece_hashes(t, ".");
- std::ofstream out("scn.torrent", std::ios_base::binary);
+ std::ofstream out(scn::path_helper::getRuntimeDir() + "scn.torrent", std::ios_base::binary);
libtorrent::bencode(std::ostream_iterator<char>(out), t.generate());
}
boost::filesystem::remove("scn");
@@ -78,7 +78,7 @@ P2PConnector::P2PConnector(uint16_t port, const Blockchain& blockchain)
p.save_path = "./";
p.max_connections = 10;
libtorrent::error_code ec;
- p.ti = std::make_shared<libtorrent::torrent_info>("scn.torrent", std::ref(ec));
+ p.ti = std::make_shared<libtorrent::torrent_info>(scn::path_helper::getRuntimeDir() + "scn.torrent", std::ref(ec));
if (ec) {
LOG(ERROR) << "error reading torrent file: " << ec.message();
return;
diff --git a/test/TestP2PConnector.cpp b/test/TestP2PConnector.cpp
index 090715f..2c92282 100644
--- a/test/TestP2PConnector.cpp
+++ b/test/TestP2PConnector.cpp
@@ -25,7 +25,7 @@ using namespace scn;
class TestP2PConnector : public testing::Test {
public:
TestP2PConnector()
- :blockchain_("./blockchain_test/")
+ :blockchain_(scn::path_helper::getRuntimeDir() + "blockchain_test/")
,p2p_connector_(13386, blockchain_)
,last_received_baseline_block(nullptr)
,last_received_collection_block(nullptr) {
|