From 41770ec174635ed4aa61eb20b21900c451f1bf54 Mon Sep 17 00:00:00 2001 From: anwleung Date: Wed, 31 Jan 2007 01:06:36 +0000 Subject: [PATCH] Doesn't compile at the moment but fixing that now git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1059 29311d96-e01e-0410-9327-a35deaab8ce9 --- branches/aleung/security1/ceph/mds/MDSMap.h | 3 ++ branches/aleung/security1/ceph/mon/MonMap.h | 29 +++++++++++++++- branches/aleung/security1/ceph/mon/Monitor.h | 34 +++++++++++++++++++ .../aleung/security1/ceph/mon/OSDMonitor.cc | 2 +- branches/aleung/security1/ceph/osd/OSD.cc | 14 +++++++- branches/aleung/security1/ceph/osd/OSDMap.h | 30 ++++++++++++++-- 6 files changed, 107 insertions(+), 5 deletions(-) diff --git a/branches/aleung/security1/ceph/mds/MDSMap.h b/branches/aleung/security1/ceph/mds/MDSMap.h index c94a7ef88cd48..051cd5cf3bdcd 100644 --- a/branches/aleung/security1/ceph/mds/MDSMap.h +++ b/branches/aleung/security1/ceph/mds/MDSMap.h @@ -20,6 +20,9 @@ #include "include/types.h" +#include "crypto/CryptoLib.h" +using namespace CryptoLib; + #include #include #include diff --git a/branches/aleung/security1/ceph/mon/MonMap.h b/branches/aleung/security1/ceph/mon/MonMap.h index b56ffb4a8549a..b01c4aa043423 100644 --- a/branches/aleung/security1/ceph/mon/MonMap.h +++ b/branches/aleung/security1/ceph/mon/MonMap.h @@ -20,16 +20,26 @@ #include "msg/Message.h" #include "include/types.h" +#include "crypto/CryptoLib.h" +using namespace CryptoLib; class MonMap { public: epoch_t epoch; // what epoch of the osd cluster descriptor is this int num_mon; vector mon_inst; + string pub_str_key; + esignPub pub_key; + bool keyConvert; int last_mon; // last mon i talked to - MonMap(int s=0) : epoch(0), num_mon(s), mon_inst(s), last_mon(-1) {} + // MonMap(int s=0) : epoch(0), num_mon(s), mon_inst(s), + // last_mon(-1), keyConvert(false) {} + // the map constructor when I have a key + MonMap(int s=0,string key=NULL) : epoch(0), num_mon(s), mon_inst(s), + last_mon(-1), + pub_str_key(key), keyConvert(false){} void add_mon(entity_inst_t inst) { mon_inst.push_back(inst); @@ -50,11 +60,27 @@ class MonMap { return mon_inst[m]; } + // key mutator + void set_str_key(string key) { + pub_str_key = key; + } + + // key access + const string get_str_key() { + return pub_str_key; + } + const esignPub get_key() { + if (!keyConvert) + pub_key = _fromStr_esignPubKey(pub_str_key); + return pub_key; + } + void encode(bufferlist& blist) { blist.append((char*)&epoch, sizeof(epoch)); blist.append((char*)&num_mon, sizeof(num_mon)); _encode(mon_inst, blist); + _encode(pub_str_key, blist); } void decode(bufferlist& blist) { @@ -65,6 +91,7 @@ class MonMap { off += sizeof(num_mon); _decode(mon_inst, blist, off); + _decode(pub_str_key, blist, off); } int write(char *fn) { diff --git a/branches/aleung/security1/ceph/mon/Monitor.h b/branches/aleung/security1/ceph/mon/Monitor.h index 9df57cfb23fea..3e0ab26834f82 100644 --- a/branches/aleung/security1/ceph/mon/Monitor.h +++ b/branches/aleung/security1/ceph/mon/Monitor.h @@ -21,6 +21,9 @@ #include "MonMap.h" #include "Elector.h" +#include "crypto/CryptoLib.h" +using namespace CryptoLib; + class ObjectStore; class OSDMonitor; class MDSMonitor; @@ -45,6 +48,10 @@ protected: // my local store ObjectStore *store; + // mon pub/priv keys + esignPriv myPrivKey; + esignPub myPubKey; + const static int INO_ELECTOR = 1; const static int INO_MON_MAP = 2; const static int INO_OSD_MAP = 10; @@ -104,6 +111,33 @@ protected: state = STATE_LEADER; else state = STATE_PEON; + + // init keys + myPrivKey = esignPrivKey("crypto/esig1536.dat"); + myPubKey = esignPubKey(myPrivKey); + } + Monitor(int w, Messenger *m, MonMap *mm, esignPriv key) : + whoami(w), + messenger(m), + monmap(mm), + tick_timer(0), + store(0), + elector(this, w), + mon_epoch(0), + state(STATE_STARTING), + leader(0), + osdmon(0), + mdsmon(0), + myPrivKey(key) + { + // hack leader, until election works. + if (whoami == 0) + state = STATE_LEADER; + else + state = STATE_PEON; + + // init keys + myPubKey = esignPubKey(myPrivKey); } void init(); diff --git a/branches/aleung/security1/ceph/mon/OSDMonitor.cc b/branches/aleung/security1/ceph/mon/OSDMonitor.cc index b6bc774ed8250..90b45fe84697a 100644 --- a/branches/aleung/security1/ceph/mon/OSDMonitor.cc +++ b/branches/aleung/security1/ceph/mon/OSDMonitor.cc @@ -391,7 +391,7 @@ void OSDMonitor::handle_osd_boot(MOSDBoot *m) // add the OSD instance to the map? osdmap.osd_inst[from] = m->get_source_inst(); // adds the key to the map - osdmap.osd_keys[from] = m->get_public_key(); + osdmap.osd_str_keys[from] = m->get_public_key(); if (osdmap.osd_inst.size() == osdmap.osds.size()) { dout(7) << "osd_boot all osds booted." << endl; diff --git a/branches/aleung/security1/ceph/osd/OSD.cc b/branches/aleung/security1/ceph/osd/OSD.cc index 7303f697591fc..ca2bcaca6f241 100644 --- a/branches/aleung/security1/ceph/osd/OSD.cc +++ b/branches/aleung/security1/ceph/osd/OSD.cc @@ -113,6 +113,7 @@ OSD::OSD(int id, Messenger *m, MonMap *mm, char *dev) // create public/private keys myPrivKey = esignPrivKey("crypto/esig1536.dat"); myPubKey = esignPubKey(myPrivKey); + // write these out to disk last_tid = 0; num_pulling = 0; @@ -265,13 +266,16 @@ int OSD::init() } // convert public key to string + string key_str = pubToString(myPubKey); // i'm ready! messenger->set_dispatcher(this); // announce to monitor i exist and have booted. int mon = monmap->pick_mon(); - messenger->send_message(new MOSDBoot(superblock), MSG_ADDR_MON(mon), monmap->get_inst(mon)); + //messenger->send_message(new MOSDBoot(superblock), MSG_ADDR_MON(mon), monmap->get_inst(mon)); + // new boot message w/ public key + messenger->send_message(new MOSDBoot(superblock, key_str), MSG_ADDR_MON(mon), monmap->get_inst(mon)); // start the heart next_heartbeat = new C_Heartbeat(this); @@ -809,6 +813,7 @@ void OSD::wait_for_new_map(Message *m) /** update_map * assimilate new OSDMap(s). scan pgs, etc. + * Takes an OSDMap message */ void OSD::handle_osd_map(MOSDMap *m) { @@ -818,6 +823,7 @@ void OSD::handle_osd_map(MOSDMap *m) ObjectStore::Transaction t; + // checks if I ALREADY had an OSD map if (osdmap) { dout(3) << "handle_osd_map epochs [" << m->get_first() << "," << m->get_last() @@ -834,10 +840,13 @@ void OSD::handle_osd_map(MOSDMap *m) logger->inc("mapmsg"); + // parses all of the available maps to see if + // ive seen it, if not store it? // store them? for (map::iterator p = m->maps.begin(); p != m->maps.end(); p++) { + // checks to see if I have seen this map? object_t oid = get_osdmap_object_name(p->first); if (store->exists(oid)) { dout(10) << "handle_osd_map already had full map epoch " << p->first << endl; @@ -848,6 +857,7 @@ void OSD::handle_osd_map(MOSDMap *m) continue; } + // if I have not already seen the map then store it? dout(10) << "handle_osd_map got full map epoch " << p->first << endl; //t.write(oid, 0, p->second.length(), p->second); store->write(oid, 0, p->second.length(), p->second, 0); @@ -893,8 +903,10 @@ void OSD::handle_osd_map(MOSDMap *m) advanced = true; epoch_t cur = superblock.current_epoch; + // applies all of the new maps until were up to date? while (cur < superblock.newest_map) { bufferlist bl; + // if there is a newer (by 1) inc map OR I have a newer map if (m->incremental_maps.count(cur+1) || store->exists(get_inc_osdmap_object_name(cur+1))) { dout(10) << "handle_osd_map decoding inc map epoch " << cur+1 << endl; diff --git a/branches/aleung/security1/ceph/osd/OSDMap.h b/branches/aleung/security1/ceph/osd/OSDMap.h index 7c4975a64e3e0..d53ee3ab4c52e 100644 --- a/branches/aleung/security1/ceph/osd/OSDMap.h +++ b/branches/aleung/security1/ceph/osd/OSDMap.h @@ -123,7 +123,8 @@ private: set out_osds; // list of unmapped disks map overload_osds; map osd_inst; - map osd_keys; //all public keys + map osd_str_keys; //all public keys in str form + map osd_keys; // all public key objects (cache) public: Crush crush; // hierarchical map @@ -155,7 +156,20 @@ private: const set& get_down_osds() { return down_osds; } const set& get_out_osds() { return out_osds; } const map& get_overload_osds() { return overload_osds; } - const map& get_keys() { return osd_keys; } + const map& get_key_str_map() { return osd_str_keys; } + const map& get_key_map() { return osd_keys; } + const esignPub get_key(int client) { + // I have a cached key object + if (osd_keys.count(client)) { + return osd_keys[client]; + } + // there must be a str key atleast for the client + assert(osd_str_keys.count(client)); + esignPub tempPub = _fromStr_esignPubKey(osd_str_keys[client]); + osd_keys[client] = tempPub; + return tempPub; + } + const string& get_str_keys(int client) { return osd_str_keys[client]; } bool is_down(int osd) { return down_osds.count(osd); } bool is_up(int osd) { return !is_down(osd); } @@ -230,6 +244,18 @@ private: assert(overload_osds.count(*i)); overload_osds.erase(*i); } + // add the incremental keys to osd_keys + for (map::iterator i = inc.added_osd_keys.begin(); + i != inc.added_osd_keys.end(); + i++) { + osd_str_keys[i->first] = i->second; + } + for (list::iterator i = inc.removed_osd_keys.begin(); + i != inc.removed_osd_keys.end(); + i++) { + assert(osd_str_keys.count(*i)); // sanity check + osd_str_keys.erase(*i); + } } // serialize, unserialize -- 2.39.5