Skip to content

Commit

Permalink
Fixed MapNetDBStorage to compile with templates.
Browse files Browse the repository at this point in the history
Added keys auto-regeneration.
  • Loading branch information
GamePad64 committed Mar 17, 2013
1 parent cf990c7 commit 4fe2e36
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/daemon/databases/MapNetDBStorage.cpp
Expand Up @@ -24,13 +24,16 @@ MapNetDBStorage<peermap_t>::~MapNetDBStorage() {}

template<typename peermap_t>
bool MapNetDBStorage<peermap_t>::hasPeer(crypto::hash_t peer_id){
return m_peermap.count(peer_id) != 0;
return m_peermap.count(peer_id) > 0;
}

template<typename peermap_t>
peer::Peer& MapNetDBStorage<peermap_t>::getPeer(crypto::hash_t peer_id){
return this->m_peermap[peer_id];
}

template class MapNetDBStorage< std::map<crypto::hash_t, peer::Peer> >;
template class MapNetDBStorage< btree::safe_btree_map<crypto::hash_t, peer::Peer> >;

} /* namespace databases */
} /* namespace p2pnet */
7 changes: 6 additions & 1 deletion src/daemon/databases/PersonalKeyStorage.cpp
Expand Up @@ -15,17 +15,22 @@
#include "PersonalKeyStorage.h"
#include "../../common/crypto/CurrentCipherSet.h"
#include <string>
#include <iostream>

namespace p2pnet {
namespace databases {

PersonalKeyStorage::PersonalKeyStorage() {}
PersonalKeyStorage::PersonalKeyStorage() {
// TEMP: We shouldn't regenerate keys every execution, so some sort of caching is required.
regenerateKeys();
}
PersonalKeyStorage::~PersonalKeyStorage() {}

void PersonalKeyStorage::regenerateKeys() {
crypto::CurrentCipherSet cs;
my_key_pair = cs.generateKeyPair();
my_transport_hash = cs.computeHash(std::string(my_key_pair.key_public.begin(), my_key_pair.key_public.end()));
std::clog << "[Crypto] Keys regenerated. New TH: " << crypto::hashToHex(my_transport_hash) << std::endl;
}

crypto::hash_t PersonalKeyStorage::getMyTransportHash() {
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/databases/PersonalKeyStorage.h
Expand Up @@ -27,7 +27,6 @@ class PersonalKeyStorage {

protected:
PersonalKeyStorage();
virtual ~PersonalKeyStorage();

public:
static PersonalKeyStorage* getInstance(){
Expand All @@ -37,6 +36,7 @@ class PersonalKeyStorage {
}
return instance;
}
virtual ~PersonalKeyStorage();

void regenerateKeys();

Expand Down

0 comments on commit 4fe2e36

Please sign in to comment.