akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 1 | #include "nlsr.hpp" |
| 2 | #include "nlsr_slh.hpp" |
| 3 | #include "security/nlsr_km.hpp" |
| 4 | #include "utility/nlsr_tokenizer.hpp" |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 5 | #include "utility/nlsr_logger.hpp" |
| 6 | |
| 7 | #define THIS_FILE "nlsr_slh.cpp" |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 8 | |
| 9 | |
| 10 | namespace nlsr |
| 11 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 12 | void |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 13 | SyncLogicHandler::createSyncSocket(Nlsr& pnlsr ) |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 14 | { |
| 15 | cout<<"Creating Sync socket ......"<<endl; |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 16 | cout<<"Sync prefix: "<<m_syncPrefix.toUri()<<endl; |
| 17 | m_syncSocket=make_shared<SyncSocket>(m_syncPrefix, m_validator, m_syncFace, |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 18 | bind(&SyncLogicHandler::nsyncUpdateCallBack,this, |
| 19 | _1, _2,boost::ref(pnlsr)), |
| 20 | bind(&SyncLogicHandler::nsyncRemoveCallBack, this, |
| 21 | _1,boost::ref(pnlsr))); |
| 22 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 23 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 24 | void |
| 25 | SyncLogicHandler::nsyncUpdateCallBack(const vector<MissingDataInfo> &v, |
| 26 | SyncSocket *socket, Nlsr& pnlsr) |
| 27 | { |
| 28 | cout<<"nsyncUpdateCallBack called ...."<<endl; |
| 29 | int n = v.size(); |
| 30 | for(int i=0; i < n; i++) |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 31 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 32 | std::cout<<"Data Name: "<<v[i].prefix<<" Seq: "<<v[i].high.getSeq()<<endl; |
| 33 | processUpdateFromSync(v[i].prefix,v[i].high.getSeq(),pnlsr); |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 34 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 35 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 36 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 37 | void |
| 38 | SyncLogicHandler::nsyncRemoveCallBack(const string& prefix, Nlsr& pnlsr) |
| 39 | { |
| 40 | cout<<"nsyncRemoveCallBack called ...."<<endl; |
| 41 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 42 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 43 | void |
| 44 | SyncLogicHandler::removeRouterFromSyncing(string& routerPrefix) |
| 45 | { |
| 46 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 47 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 48 | void |
| 49 | SyncLogicHandler::processUpdateFromSync(std::string updateName, |
| 50 | uint64_t seqNo, Nlsr& pnlsr) |
| 51 | { |
| 52 | nlsrTokenizer nt(updateName,"/"); |
| 53 | string chkString("LSA"); |
| 54 | if( nt.doesTokenExist(chkString) ) |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 55 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 56 | //process LSA Update here |
| 57 | string routerName=nt.getTokenString(nt.getTokenPosition(chkString)+1); |
| 58 | processRoutingUpdateFromSync(routerName, seqNo, pnlsr); |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 59 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 60 | chkString="keys"; |
| 61 | if( nt.doesTokenExist(chkString) ) |
| 62 | { |
| 63 | //process keys update here |
| 64 | std::string certName=nt.getTokenString(0); |
| 65 | processKeysUpdateFromSync(certName,seqNo, pnlsr); |
| 66 | } |
| 67 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 68 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 69 | void |
| 70 | SyncLogicHandler::processRoutingUpdateFromSync(std::string routerName, |
| 71 | uint64_t seqNo, Nlsr& pnlsr) |
| 72 | { |
| 73 | if( routerName != pnlsr.getConfParameter().getRouterPrefix() ) |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 74 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 75 | SequencingManager sm(seqNo); |
| 76 | cout<<sm; |
| 77 | cout<<"Router Name: "<<routerName<<endl; |
| 78 | if ( pnlsr.getLsdb().isNameLsaNew(routerName+"/1",sm.getNameLsaSeq())) |
| 79 | { |
| 80 | cout<<"Updated Name LSA. Need to fetch it"<<endl; |
| 81 | string lsaPrefix= |
| 82 | pnlsr.getConfParameter().getChronosyncLsaPrefix() + |
| 83 | routerName + "/1/" + |
| 84 | boost::lexical_cast<std::string>(sm.getNameLsaSeq()); |
| 85 | pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3, |
| 86 | pnlsr.getConfParameter().getInterestResendTime()); |
| 87 | } |
| 88 | if ( pnlsr.getLsdb().isAdjLsaNew(routerName+"/2",sm.getAdjLsaSeq())) |
| 89 | { |
| 90 | cout<<"Updated Adj LSA. Need to fetch it"<<endl; |
| 91 | string lsaPrefix= |
| 92 | pnlsr.getConfParameter().getChronosyncLsaPrefix() + |
| 93 | routerName + "/2/" + |
| 94 | boost::lexical_cast<std::string>(sm.getAdjLsaSeq()); |
| 95 | pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3, |
| 96 | pnlsr.getConfParameter().getInterestResendTime()); |
| 97 | } |
| 98 | if ( pnlsr.getLsdb().isCorLsaNew(routerName+"/3",sm.getCorLsaSeq())) |
| 99 | { |
| 100 | cout<<"Updated Cor LSA. Need to fetch it"<<endl; |
| 101 | string lsaPrefix= |
| 102 | pnlsr.getConfParameter().getChronosyncLsaPrefix() + |
| 103 | routerName + "/3/" + |
| 104 | boost::lexical_cast<std::string>(sm.getCorLsaSeq()); |
| 105 | pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3, |
| 106 | pnlsr.getConfParameter().getInterestResendTime()); |
| 107 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 108 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 109 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 110 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 111 | void |
| 112 | SyncLogicHandler::processKeysUpdateFromSync(std::string certName, |
| 113 | uint64_t seqNo, Nlsr& pnlsr) |
| 114 | { |
| 115 | cout<<"Cert Name: "<<certName<<std::endl; |
| 116 | if ( pnlsr.getKeyManager().isNewCertificate(certName,seqNo) ) |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 117 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 118 | string certNamePrefix=certName + "/" + |
| 119 | boost::lexical_cast<string>(seqNo); |
| 120 | pnlsr.getIm().expressInterest(pnlsr, certNamePrefix, 3, |
| 121 | pnlsr.getConfParameter().getInterestResendTime()); |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 122 | } |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 123 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 124 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 125 | void |
| 126 | SyncLogicHandler::publishRoutingUpdate(SequencingManager& sm, |
| 127 | string updatePrefix) |
| 128 | { |
| 129 | sm.writeSeqNoToFile(); |
| 130 | publishSyncUpdate(updatePrefix,sm.getCombinedSeqNo()); |
| 131 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 132 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 133 | void |
| 134 | SyncLogicHandler::publishKeyUpdate(KeyManager& km) |
| 135 | { |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 136 | publishSyncUpdate(km.getProcessCertName().toUri(),km.getCertSeqNo()); |
| 137 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 138 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 139 | void |
| 140 | SyncLogicHandler::publishIdentityUpdate(string identityName) |
| 141 | { |
| 142 | publishSyncUpdate(identityName,0); |
| 143 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 144 | |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 145 | void |
| 146 | SyncLogicHandler::publishSyncUpdate(string updatePrefix, uint64_t seqNo) |
| 147 | { |
| 148 | cout<<"Publishing Sync Update ......"<<endl; |
| 149 | cout<<"Update in prefix: "<<updatePrefix<<endl; |
| 150 | cout<<"Seq No: "<<seqNo<<endl; |
| 151 | ndn::Name updateName(updatePrefix); |
| 152 | string data("NoData"); |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 153 | m_syncSocket->publishData(updateName,0,data.c_str(),data.size(),1000,seqNo); |
akmhoque | 5a44dd4 | 2014-03-12 18:11:32 -0500 | [diff] [blame] | 154 | } |
akmhoque | ba09474 | 2014-02-28 11:47:21 -0600 | [diff] [blame] | 155 | |
| 156 | } |