11/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22/*
3- * Copyright (c) 2014-2024 , The University of Memphis,
3+ * Copyright (c) 2014-2026 , The University of Memphis,
44 * Regents of the University of California,
55 * Arizona Board of Regents.
66 *
@@ -36,9 +36,6 @@ Lsdb::Lsdb(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
3636 , m_scheduler(face.getIoContext())
3737 , m_confParam(confParam)
3838 , m_sync(m_face, keyChain,
39- [this ] (const auto & routerName, Lsa::Type lsaType, uint64_t seqNo, uint64_t ) {
40- return isLsaNew (routerName, lsaType, seqNo);
41- },
4239 SyncLogicOptions{
4340 confParam.getSyncProtocol (),
4441 confParam.getSyncPrefix (),
@@ -51,12 +48,10 @@ Lsdb::Lsdb(ndn::Face& face, ndn::KeyChain& keyChain, ConfParameter& confParam)
5148 , m_adjLsaBuildInterval(m_confParam.getAdjLsaBuildInterval())
5249 , m_thisRouterPrefix(m_confParam.getRouterPrefix())
5350 , m_sequencingManager(m_confParam.getStateFileDir(), m_confParam.getHyperbolicState())
54- , m_onNewLsaConnection (m_sync.onNewLsa .connect(
51+ , m_onSyncUpdate (m_sync.onSyncUpdate .connect(
5552 [this ] (const ndn::Name& updateName, uint64_t sequenceNumber,
5653 const ndn::Name& originRouter, uint64_t incomingFaceId) {
57- ndn::Name lsaInterest{updateName};
58- lsaInterest.appendNumber (sequenceNumber);
59- expressInterest (lsaInterest, 0 , incomingFaceId);
54+ processUpdateFromSync (updateName, sequenceNumber, originRouter, incomingFaceId);
6055 }))
6156 , m_segmenter(keyChain, m_confParam.getSigningInfo())
6257 , m_segmentFifo(100 )
@@ -89,6 +84,63 @@ Lsdb::~Lsdb()
8984 }
9085}
9186
87+ void
88+ Lsdb::processUpdateFromSync (const ndn::Name& updateName, uint64_t seqNo,
89+ const ndn::Name& originRouter, uint64_t incomingFaceId)
90+ {
91+ NLSR_LOG_DEBUG (" Origin Router of update: " << originRouter << " seq: " << seqNo);
92+ auto lsaType = boost::lexical_cast<Lsa::Type>(updateName.get (-1 ).toUri ());
93+
94+ if (originRouter == m_thisRouterPrefix) {
95+ NLSR_LOG_TRACE (" Received sync update for own router" );
96+ // Other routers might be telling us that they have higher sequence number
97+ // than what we started with because of our sequence file corruption
98+ // So we adapt that sequence number
99+ if (isLsaNew (originRouter, lsaType, seqNo)) {
100+ if (lsaType == Lsa::Type::NAME) {
101+ m_sequencingManager.setNameLsaSeq (seqNo);
102+ buildAndInstallOwnNameLsa ();
103+ }
104+ if (lsaType == Lsa::Type::ADJACENCY &&
105+ m_confParam.getHyperbolicState () == HYPERBOLIC_STATE_OFF) {
106+ m_sequencingManager.setAdjLsaSeq (seqNo);
107+ buildAndInstallOwnAdjLsa ();
108+ }
109+ if (lsaType == Lsa::Type::COORDINATE &&
110+ m_confParam.getHyperbolicState () == HYPERBOLIC_STATE_ON) {
111+ m_sequencingManager.setCorLsaSeq (seqNo);
112+ buildAndInstallOwnCoordinateLsa ();
113+ }
114+ }
115+ // A router should not try to fetch its own LSA
116+ return ;
117+ }
118+
119+ NLSR_LOG_DEBUG (" Received sync update with higher " << lsaType << " sequence number than entry in LSDB" );
120+
121+ if (isLsaNew (originRouter, lsaType, seqNo)) {
122+ if (lsaType == Lsa::Type::ADJACENCY && seqNo != 0 &&
123+ m_confParam.getHyperbolicState () == HYPERBOLIC_STATE_ON) {
124+ NLSR_LOG_ERROR (" Got an update for adjacency LSA when hyperbolic routing "
125+ " is enabled. Not going to fetch." );
126+ return ;
127+ }
128+
129+ if (lsaType == Lsa::Type::COORDINATE && seqNo != 0 &&
130+ m_confParam.getHyperbolicState () == HYPERBOLIC_STATE_OFF) {
131+ NLSR_LOG_ERROR (" Got an update for coordinate LSA when link-state "
132+ " is enabled. Not going to fetch." );
133+ return ;
134+ }
135+
136+ onNewLsa (updateName, seqNo, originRouter, incomingFaceId);
137+
138+ ndn::Name lsaInterest{updateName};
139+ lsaInterest.appendNumber (seqNo);
140+ expressInterest (lsaInterest, 0 , incomingFaceId);
141+ }
142+ }
143+
92144void
93145Lsdb::buildAndInstallOwnNameLsa ()
94146{
0 commit comments