Skip to content

Commit

Permalink
Merge pull request #35 from soramitsu/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
MizukiSonoko committed Oct 23, 2016
2 parents 59f021a + 4225418 commit dd9b71e
Show file tree
Hide file tree
Showing 64 changed files with 302 additions and 426 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ build/*
*.o
.gradle/*
.vscode/*
.idea/*
8 changes: 0 additions & 8 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@
path = core/vendor/Aeron
url = https://github.com/real-logic/Aeron.git
ignore = dirty
[submodule "core/vendor/yaml-cpp"]
path = core/vendor/yaml-cpp
url = https://github.com/jbeder/yaml-cpp.git
ignore = dirty
[submodule "core/vendor/ed25519"]
path = core/vendor/ed25519
url = https://github.com/luca3104/ed25519.git
ignore = dirty
[submodule "core/vendor/msgpack-c"]
path = core/vendor/msgpack-c
url = https://github.com/msgpack/msgpack-c.git
ignore = dirty
[submodule "core/vendor/json"]
path = core/vendor/json
url = https://github.com/nlohmann/json.git
Expand Down
6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

2 changes: 0 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ checkout:
- cd $IROHA_HOME/core/vendor/leveldb; make
- cd $IROHA_HOME/core/vendor/ed25519; make
- cd $IROHA_HOME/core/vendor/KeccakCodePackage; make; make generic64/libkeccak.a
- cd $IROHA_HOME/core/vendor/yaml-cpp; mkdir build; cd build; cmake ..; make
- cd $IROHA_HOME/core/vendor/crow; mkdir build; cd build; cmake ..; make
- cd $IROHA_HOME/core/vendor/msgpack-c; cmake -DMSGPACK_CXX11=ON .; sudo make install
- cd $IROHA_HOME/core/infra/crypto/; make
test:
override:
Expand Down
24 changes: 24 additions & 0 deletions config/sumeragi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"me":{
"ip":"",
"name":"mizuki",
"public_key":""
},
"group":[
{
"ip":"",
"name":"iori",
"public_key":""
},
{
"ip":"",
"name":"mizuki",
"public_key":""
},
{
"ip":"",
"name":"natori",
"public_key":""
}
]
}
1 change: 0 additions & 1 deletion core/consensus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ ADD_LIBRARY(sumeragi STATIC
target_link_libraries(sumeragi
event_repository
crypto
yaml_loader
validator
merkle_transaction_repository
unconfirmed_transaction_repository
Expand Down
15 changes: 11 additions & 4 deletions core/consensus/connection/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
#include <functional>

namespace connection {
void initialize_peer(const std::unordered_map<std::string, std::string>& config);

bool sendAll(std::string message);
bool send(std::string to, std::string message);
bool receive(std::function<void(std::string from, std::string message)> callback);
struct Config{
std::string name;
std::string ip_addr;
std::string port;
};

void initialize_peer(std::unique_ptr<connection::Config> config);

bool sendAll(const std::string& message);
bool send(const std::string& to, const std::string& message);
bool receive(const std::function<void(std::string from, std::string message)>& callback);

}; // end connection

Expand Down
1 change: 0 additions & 1 deletion core/infra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ add_subdirectory(crypto)
add_subdirectory(repository)
add_subdirectory(server)
add_subdirectory(connection)
add_subdirectory(util)
4 changes: 2 additions & 2 deletions core/infra/connection/connection_with_aeron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace connection {
publications.insert(std::pair<std::string, std::shared_ptr<Publication>>{ ip, publication});
}

bool send(std::string to,std::string msg) {
bool send(const std::string& to,const std::string& msg) {
logger::info("connection", "Start send()");
if(publications.find(to) == publications.end()){
logger::error("connection", to + " is not registerd");
Expand Down Expand Up @@ -141,7 +141,7 @@ namespace connection {
}
}

bool sendAll(std::string msg) {
bool sendAll(const std::string& msg) {
for(auto& p : publications){
send( p.first, msg);
}
Expand Down
2 changes: 1 addition & 1 deletion core/infra/crypto/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
all: libhash.a

CC = g++
KECCAK_PATH = $(IROHA_HOME)/core/vendor/KeccakCodePackage
KECCAK_PATH = ../../vendor/KeccakCodePackage

DEFINE = -DKeccakP200_excluded -DKeccakP400_excluded -DKeccakP800_excluded

Expand Down
7 changes: 2 additions & 5 deletions core/infra/repository/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

SET(MESSAGE_PACK_PATH ${PROJECT_SOURCE_DIR}/core/vendor/msgpack-c)
SET(LEVELDB_PATH ${PROJECT_SOURCE_DIR}/core/vendor/leveldb)

include_directories(
${LEVELDB_PATH}/include
${MESSAGE_PACK_PATH}/include
)

link_directories(
${MESSAGE_PACK_PATH}
${LEVELDB_PATH}/out-static
)

ADD_LIBRARY(world_state_repo_with_level_db STATIC world_state_repository_with_level_db.cpp)
target_link_libraries(world_state_repo_with_level_db
msgpackc
snappy
leveldb
logger
exception
)
)
5 changes: 0 additions & 5 deletions core/infra/repository/consensus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)


SET(MESSAGE_PACK_PATH ${PROJECT_SOURCE_DIR}/core/vendor/msgpack-c)
SET(LEVELDB_PATH ${PROJECT_SOURCE_DIR}/core/vendor/leveldb)

include_directories(
${LEVELDB_PATH}/include
${MESSAGE_PACK_PATH}/include
)

link_directories(
${MESSAGE_PACK_PATH}
${LEVELDB_PATH}/out-static
)

ADD_LIBRARY(merkle_transaction_repository STATIC merkle_transaction_repository.cpp)
target_link_libraries(merkle_transaction_repository
msgpackc
snappy
leveldb
exception
)

ADD_LIBRARY(unconfirmed_transaction_repository STATIC unconfirmed_transaction_repository.cpp)
target_link_libraries(unconfirmed_transaction_repository
msgpackc
snappy
leveldb
exception
Expand Down
97 changes: 57 additions & 40 deletions core/infra/repository/world_state_repository_with_level_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,99 @@
#include <leveldb/write_batch.h>
#include <leveldb/db.h>


// +------------------------------------------------+
// | Repository should save string to any database. |
// +------------------------------------------------+
// | |
// | I know ... |
// | - leveldb |
// | |
// | I don't know |
// | - json library |
// | |
// +------------------------------------------------+
namespace repository{

// Level DB is known only to me.
namespace world_state_repository {

std::unique_ptr<leveldb::DB> db;

bool loggerStatus(leveldb::Status const status) {
if (!status.ok()) {
logger::info("merkle_transaction",status.ToString());
return false;
namespace detail {

static std::unique_ptr<leveldb::DB> db = nullptr;

bool loggerStatus(leveldb::Status const status) {
if (!status.ok()) {
logger::info(__FILE__, status.ToString());
return false;
}
return true;
}

void loadDb() {
leveldb::DB *tmpDb;
leveldb::Options options;
options.error_if_exists = false;
options.create_if_missing = true;
loggerStatus(leveldb::DB::Open(options, "/tmp/irohaDB", &tmpDb)); //TODO: This path should be configurable
db.reset(tmpDb);
}
}
return true;
}

void loadDb() {
leveldb::DB* tmpDb;
leveldb::Options options;
options.error_if_exists = false;
options.create_if_missing = true;
loggerStatus(leveldb::DB::Open(options, "/tmp/irohaDB", &tmpDb)); //TODO: This path should be configurable
db.reset(tmpDb);
}
bool add(const std::string &key, const std::string &value) {
if (detail::db == nullptr) detail::loadDb();

bool add(const std::string& key, const std::string& value){
return loggerStatus( db->Put(leveldb::WriteOptions(), key, value));
return detail::loggerStatus(detail::db->Put(leveldb::WriteOptions(), key, value));
}

bool update(const std::string& key, const std::string& value){
bool update(const std::string &key, const std::string &value) {
if (detail::db == nullptr) detail::loadDb();

std::string dummy;
if( loggerStatus(db->Get(leveldb::ReadOptions(), key, &dummy)) ){
if (detail::loggerStatus(detail::db->Get(leveldb::ReadOptions(), key, &dummy))) {
leveldb::WriteBatch batch;
batch.Delete(key);
batch.Put(key, value);
return loggerStatus( db->Write(leveldb::WriteOptions(), &batch));
return detail::loggerStatus(detail::db->Write(leveldb::WriteOptions(), &batch));
}
return false;
}

bool remove(const std::string& key){
return loggerStatus(db->Delete(leveldb::WriteOptions(), key));
bool remove(const std::string &key) {
if (detail::db == nullptr) detail::loadDb();
return detail::loggerStatus(detail::db->Delete(leveldb::WriteOptions(), key));
}

std::string find(const std::string& key){
std::string find(const std::string &key) {
if (detail::db == nullptr) detail::loadDb();

std::string readData;
loggerStatus(db->Get(leveldb::ReadOptions(), key, &readData));
if(readData != ""){
detail::loggerStatus(detail::db->Get(leveldb::ReadOptions(), key, &readData));
if (readData != "") {
return readData;
} else {
return "";
}
}

std::string findOrElse(
const std::string& key,
const std::string& defaultValue
const std::string &key,
const std::string &defaultValue
) {
if (detail::db == nullptr) detail::loadDb();

std::string result = "";
loggerStatus(db->Get(leveldb::ReadOptions(), key, &result));
if(result == "") {
detail::loggerStatus(detail::db->Get(leveldb::ReadOptions(), key, &result));
if (result == "") {
return defaultValue;
} else {
return result;
}
}

bool isExist(const std::string& key){
bool isExist(const std::string &key) {
std::string result = "";
loggerStatus(db->Get(leveldb::ReadOptions(), key, &result));
if(result == "") {
return false;
} else {
return true;
}
detail::loggerStatus(detail::db->Get(leveldb::ReadOptions(), key, &result));
return result == "";
}

};

};
1 change: 0 additions & 1 deletion core/infra/server/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

SET(YAML_PATH "${PROJECT_SOURCE_DIR}/core/vendor/yaml-cpp")
set(CROW_PATH "${PROJECT_SOURCE_DIR}/core/vendor/crow")
set(JSON_PATH "${PROJECT_SOURCE_DIR}/core/vendor/json")

Expand Down
17 changes: 0 additions & 17 deletions core/infra/util/CMakeLists.txt

This file was deleted.

28 changes: 0 additions & 28 deletions core/infra/util/convert_string_with_message_pack.cpp

This file was deleted.

0 comments on commit dd9b71e

Please sign in to comment.