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