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