Skip to content

Commit

Permalink
wip fix cmake and dependence
Browse files Browse the repository at this point in the history
  • Loading branch information
satellitex committed Jun 19, 2017
1 parent 7edef1b commit 1727cc4
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 476 deletions.
4 changes: 1 addition & 3 deletions irohad/peer_service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#)

ADD_LIBRARY(peer_service STATIC
peer_service.cpp
monitor.cpp
change_state.cpp
self_state.cpp
Expand All @@ -22,10 +21,9 @@ ADD_LIBRARY(peer_service STATIC

target_link_libraries(peer_service
timer
exception
time64
logger
crypto
schema
ametsuchi
datetime
)
14 changes: 13 additions & 1 deletion irohad/peer_service/change_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/
#include <peer_service/change_state.hpp>
#include <peer_service/monitor.hpp>
#include <peer_service/self_state.hpp>

#include <unordered_set>

Expand Down Expand Up @@ -109,11 +110,11 @@ namespace peer_service {
detail::eraseActive(publicKey);
}
node->state_ = state;
return true;
}
};

namespace detail {

void insertActive(const std::shared_ptr<Node> node) {
for (auto it = active_peer_list_.begin(); it != active_peer_list_.end();
it++) {
Expand All @@ -139,5 +140,16 @@ namespace peer_service {
insertActive(node);
}
}

void initialize() {
if (!peer_list_.empty()) return;
// TODO Read config.json

// At First myself only
peer_list_.emplace_back(std::make_shared<Node>(
self_state::getIp(), self_state::getPublicKey(),
self_state::getName(), self_state::getTrust(),
self_state::getActiveTime(), self_state::getState()));
}
}
};
3 changes: 2 additions & 1 deletion irohad/peer_service/change_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
#define __IROHA_PEER_SERVICE_CHANGE_STATE_HPP__

#include <peer_service/peer_service.hpp>
#include <string>

namespace peer_service {
namespace change_state {
Expand Down Expand Up @@ -60,6 +59,8 @@ namespace peer_service {
void eraseActive(const std::string &publicKey);
void changeActive(const std::shared_ptr<Node> node);
}

void initialize();
};
};

Expand Down
24 changes: 2 additions & 22 deletions irohad/peer_service/monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ limitations under the License.
*/

#include <peer_service/monitor.hpp>
#include <peer_service/self_state.hpp>

#include <algorithm>

namespace peer_service{
namespace monitor{
Expand All @@ -30,23 +27,6 @@ namespace peer_service{
}


void initialize(){
if( !peer_list_.empty() ) return;
// TODO Read config.json

// At First myself only
peer_list_.emplace_back(
std::make_shared<Node>(
self_state::getIp(),
self_state::getPublicKey(),
self_state::getName(),
self_state::getTrust(),
self_state::getActiveTime(),
self_state::getState()
)
);
}

size_t getMaxFaulty(){
return std::max(0, (getActivePeerSize() - 1) / 3);
}
Expand All @@ -60,6 +40,7 @@ namespace peer_service{
} catch( const std::out_of_range& oor ){
// TODO Out ot Range Exception
}
return nullptr;
}
std::vector<std::string> getAllIpList(){
std::vector<std::string> ret;
Expand All @@ -77,6 +58,7 @@ namespace peer_service{
} catch( const std::out_of_range& oor ){
// TODO Out ot Range Exception
}
return nullptr;
}
std::vector<std::string> getActiveIpList(){
std::vector<std::string> ret;
Expand All @@ -98,12 +80,10 @@ namespace peer_service{
}

Nodes::iterator findPeerIP(const std::string &ip){
initialize();
return std::find_if(peer_list_.begin(), peer_list_.end(),
[&ip](const auto &p) { return p->ip_ == ip; });
}
Nodes::iterator findPeerPublicKey(const std::string &publicKey){
initialize();
return std::find_if(
peer_list_.begin(), peer_list_.end(),
[&publicKey](const auto &p) { return p->public_key_ == publicKey; });
Expand Down
2 changes: 0 additions & 2 deletions irohad/peer_service/monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ namespace peer_service {
std::shared_ptr<Node> getCurrentLeader();
std::string getCurrentLeaderIp();

void initialize();

size_t getMaxFaulty();

Nodes getAllPeerList();
Expand Down
Loading

0 comments on commit 1727cc4

Please sign in to comment.