Skip to content

Commit

Permalink
FIX project warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
muratovv committed Aug 1, 2017
1 parent 04f15aa commit 6813539
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 63 deletions.
39 changes: 7 additions & 32 deletions irohad/common/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,44 +30,19 @@ namespace common {

class ConfigLoader {
public:
ConfigLoader(const std::string& file);
ConfigLoader(const std::string &file);

int getIntOrDefault(const std::string& key, int def);
std::string getStringOrDefault(const std::string& key, const std::string& def);
bool getBoolOrDefault(const std::string& key, bool def);
int getIntOrDefault(const std::string &key, int def);

// template <class T>
// T getValueOrDefault(const std::string& key, T&& def) {
// const auto& val = doc[key.c_str()];
// if (!(doc.IsObject() && doc.HasMember(key.c_str()))) {
// goto end;
// }
std::string getStringOrDefault(const std::string &key,
const std::string &def);

// if (std::is_same<T, int>::value && val.IsInt()) {
// // quite dirty hack for pleasing the compiler
// // maybe that switch(type){..} possible
// // to make compile-time
// auto v = val.GetInt();
// return *((T*)(&v));
// }

// if (std::is_same<T, std::string>::value && val.IsString()) {
// auto v = val.GetString();
// return *((T*)(&v));
// }

// if (std::is_same<T, bool>::value && val.IsBool()) {
// auto v = val.GetBool();
// return *((T*)(&v));
// }
// end:
// return def;
// }
bool getBoolOrDefault(const std::string &key, bool def);

private:
Document doc;
};
};
}; // namespace common
} // namespace config
} // namespace common

#endif // __COMMON_CONFIG_HPP_
2 changes: 1 addition & 1 deletion irohad/consensus/yac/storage/impl/yac_proposal_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace iroha {
BlockHash block_hash) {

// find exist
for (auto i = 0; i < block_votes_.size(); ++i) {
for (uint32_t i = 0; i < block_votes_.size(); ++i) {
if (block_votes_.at(i).getProposalHash() == proposal_hash and
block_votes_.at(i).getBlockHash() == block_hash) {
return i;
Expand Down
5 changes: 3 additions & 2 deletions irohad/consensus/yac/yac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,16 @@ namespace iroha {
void propagateRejectDirectly(model::Peer to, RejectMessage msg);

// ------|Fields|------
rxcpp::subjects::subject<CommitMessage> notifier_;
YacVoteStorage vote_storage_;
std::shared_ptr<YacNetwork> network_;
std::shared_ptr<YacCryptoProvider> crypto_;
std::shared_ptr<Timer> timer_;
YacVoteStorage vote_storage_;
rxcpp::subjects::subject<CommitMessage> notifier_;

// ------|One round|------
ClusterOrdering cluster_order_;


// ------|Constants|------
const uint64_t delay_;
};
Expand Down
2 changes: 1 addition & 1 deletion irohad/consensus/yac/yac_hash_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace iroha {

bool operator!=(const YacHash &obj) const {
return !this->operator==(obj);
}
};
};

/**
Expand Down
1 change: 1 addition & 0 deletions irohad/network/peer_communication_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace iroha {

rxcpp::observable <rxcpp::observable<model::Block>>
PeerCommunicationServiceStub::on_commit() {
return consensus_.on_commit();
}

rxcpp::observable <model::Proposal>
Expand Down
2 changes: 1 addition & 1 deletion irohad/peer_service/connection_to.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace peerservice {
Heartbeat answer;

status = stub_->RequestHeartbeat(&context, *request, &answer);
printf("[my ledger is %d] ping %s... ", request->height(),
printf("[my ledger is %lu] ping %s... ", request->height(),
context.peer().c_str());

// TODO: validate heartbeat messages
Expand Down
44 changes: 18 additions & 26 deletions irohad/validation/impl/stateless_validator_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,48 @@
namespace iroha {
namespace validation {
StatelessValidatorImpl::StatelessValidatorImpl(
model::ModelCryptoProvider& crypto_provider)
model::ModelCryptoProvider &crypto_provider)
: crypto_provider_(crypto_provider) {}

bool StatelessValidatorImpl::validate(
const model::Transaction& transaction) const {
const model::Transaction &transaction) const {
// signatures are correct
{
if (!crypto_provider_.verify(transaction)) return false;
}

// time between creation and validation of tx
std::chrono::milliseconds now =
uint64_t now = static_cast<uint64_t>(
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch());
{
if (now.count() - transaction.created_ts > MAX_DELAY) {
return false;
}
std::chrono::system_clock::now().time_since_epoch()).count());

if (now - transaction.created_ts > MAX_DELAY) {
return false;
}

// tx is not sent from future
{
if (now.count() < transaction.created_ts) {
return false;
}
if (now < transaction.created_ts) {
return false;
}
return true;
}

bool StatelessValidatorImpl::validate(const model::Query& query) const {
bool StatelessValidatorImpl::validate(const model::Query &query) const {
// signatures are correct
{
if (!crypto_provider_.verify(query)) return false;
}
if (!crypto_provider_.verify(query)) return false;

// time between creation and validation of the query
std::chrono::milliseconds now =
uint64_t now = static_cast<uint64_t>(
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch());
{
if (now.count() - query.created_ts > MAX_DELAY) {
return false;
}
std::chrono::system_clock::now().time_since_epoch()).count());

if (now - query.created_ts > MAX_DELAY) {
return false;
}

// query is not sent from future
{
if (now.count() < query.created_ts) {
return false;
}
if (now < query.created_ts) {
return false;
}
return true;
}
Expand Down

0 comments on commit 6813539

Please sign in to comment.