Skip to content

Commit

Permalink
Fix yaml_service,
Browse files Browse the repository at this point in the history
  • Loading branch information
MizukiSonoko committed Sep 26, 2016
1 parent 2ac902d commit 2705edd
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 14 deletions.
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mediaDriver:
name: mizuki

peer:
publicKey: "AAA"
leader: true
node:
- name: Hanako
Expand Down
7 changes: 5 additions & 2 deletions core/consensus/sumeragi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ struct Context {
int panicCount;
int numValidatingPeers;
std::vector<peer::Node> validatingPeers;

//std::unique_ptr<TransactionCache> txCache;
//std::unique_ptr<TransactionValidator> txValidator;

std::queue<ConsensusEvent> eventCache;

std::map<std::string, std::shared_ptr<ConsensusEvent> > processedCache;
Expand All @@ -50,14 +52,15 @@ struct Context {
std::unique_ptr<Context> context;

void initializeSumeragi(std::string myPublicKey, std::vector<peer::Node> peers) {
logger::info( __FILE__, "initializeSumeragi");
context->validatingPeers = peers;
logger::info( "initialize sumeragi", "initialize.....");
context->validatingPeers = std::move(peers);
context->numValidatingPeers = peers.size();
context->maxFaulty = context->numValidatingPeers / 3; // Default to approx. 1/3 of the network. TODO: make this configurable
context->proxyTailNdx = context->maxFaulty*2 + 1;
context->panicCount = 0;

context->myPublicKey = myPublicKey;
logger::info( "initialize sumeragi", "complate!");
}

void processTransaction(std::shared_ptr<ConsensusEvent> const event, std::vector<peer::Node> const nodeOrder) {
Expand Down
13 changes: 8 additions & 5 deletions core/service/peer_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace peer{
return publicKey;
}


std::string getMyPublicKey() {
return "Base64";// WIP
}
Expand All @@ -24,9 +23,13 @@ namespace peer{
return "Base64";// WIP
}

std::vector<Node> getPeerList() {
std::unique_ptr<yaml::YamlLoader> yamlLoader(new yaml::YamlLoader(std::string(getenv("IROHA_HOME")) + "/config/config.yml"));
return std::vector<Node>();
//return std::move(yamlLoader->get<std::vector<std::string> >("peer", "ip"));
std::vector<Node> getPeerList() {
std::vector<Node> res;
std::unique_ptr<yaml::YamlLoader> yaml(new yaml::YamlLoader(std::string(getenv("IROHA_HOME")) + "/config/config.yml"));
auto nodes = yaml->get<std::vector<peer::Node> >("peer", "node");
for (std::size_t i=0;i < nodes.size();i++) {
res.push_back( nodes[i] );
}
return res;
}
};
10 changes: 8 additions & 2 deletions core/service/peer_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@


namespace peer{

class Node {
public:
std::string ip;
std::string publicKey;
public:

Node(){}

Node(
std::string aip,
std::string apubkey
);
):
ip(aip),
publicKey(apubkey)
{}

/*
virtual ~Node() = default; // make dtor virtual
Expand Down
33 changes: 31 additions & 2 deletions core/util/yaml_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,40 @@ namespace yaml{
template <>
std::vector<peer::Node> YamlLoader::get<
std::vector<peer::Node>
>(const std::string& root, const std::string& key);
>(const std::string& root, const std::string& key){
YAML::Node config = YAML::LoadFile(std::move(fileName));
try{
return config[root][key].as<std::vector<peer::Node>>();
}catch(YAML::Exception& e){
logger::fital("YamlLoader.get()", e.what());
terminate::finish();
}
}

template <>
std::vector<std::string> YamlLoader::get<
std::vector<std::string>
>(const std::string& root, const std::string& key);

};
};

namespace YAML {
template<>
struct convert<peer::Node> {
static Node encode(const peer::Node& rhs) {
Node node;
node.push_back(rhs.getIP());
node.push_back(rhs.getPublicKey());
return node;
}

static bool decode(const Node& node, peer::Node& rhs) {
if(!node.IsMap()) {
return false;
}
rhs.ip = node["ip"].as<std::string>();
rhs.publicKey = node["publicKey"].as<std::string>();
return true;
}
};
}
12 changes: 9 additions & 3 deletions peer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ int main() {
std::thread http_th( server );

// std::cout << "(Second) Process ID is " << getpid() << std::endl;
std::unique_ptr<yaml::YamlLoader> yaml(new yaml::YamlLoader(std::string(getenv("IROHA_HOME"))+"/config/config.yml"));
std::string myPublicKey = yaml->get<std::string>("peer", "publicKey");
std::vector<peer::Node> peer = peer::getPeerList();
// std::unique_ptr<yaml::YamlLoader> yaml(new yaml::YamlLoader(std::string(getenv("IROHA_HOME"))+"/config/config.yml"));
std::string myPublicKey = "AA"; //yaml->get<std::string>("peer", "publicKey");
std::vector<peer::Node> peer = {
peer::Node("1.2.5.6","AAA"),
peer::Node("1.2.5.6","AAA"),
peer::Node("1.2.5.6","AAA")
};

//peer::getPeerList();
sumeragi::initializeSumeragi(myPublicKey, peer);

sumeragi::loop();
Expand Down
6 changes: 6 additions & 0 deletions test/crypto/signature_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ TEST(Signature, keyPair){
base64::encode(keyPair.publicKey))
);
}

TEST(Signature, PrintkeyPair){
signature::KeyPair keyPair = signature::generateKeyPair();
std::cout << base64::encode(keyPair.publicKey) << std::endl;
std::cout << base64::encode(keyPair.privateKey) << std::endl;
}

0 comments on commit 2705edd

Please sign in to comment.