From 36238cb7db1a22cd404607845ddce5abb72f5a71 Mon Sep 17 00:00:00 2001 From: free will <2647778488@qq.com> Date: Fri, 15 Jul 2022 23:12:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86hello=E5=8D=8F=E8=AE=AE=E4=B8=AD?= =?UTF-8?q?=E7=9A=84logicface=E6=9B=BF=E6=8D=A2=E4=B8=BAlogicfaceICN?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E4=B8=9D=E6=BB=91=E6=94=AF=E6=8C=81=E6=94=B6?= =?UTF-8?q?=E5=88=B0=E6=95=B0=E6=8D=AE=E5=8C=85=E6=97=B6=E7=9A=84=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hello/HelloProtocol.go | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/hello/HelloProtocol.go b/hello/HelloProtocol.go index 89d3838..8c209d6 100644 --- a/hello/HelloProtocol.go +++ b/hello/HelloProtocol.go @@ -19,6 +19,7 @@ import ( "mlsr/lsdb" "mlsr/route" "mlsr/utils" + "time" ) // 用于hello兴趣包的名称的组件 @@ -37,7 +38,7 @@ type TimeoutCallback = func(interest *packet.Interest) //type OptionalNack = *packet.Nack type HelloProtocol struct { - m_face *logicface.LogicFace + m_face *logicface.LogicFaceICN m_scheduler *lsdb.MlsrScheduler m_keychain *security.KeyChain mlsrConfig *common.MlsrConfig @@ -64,7 +65,7 @@ type HelloProtocol struct { // @param routingTable // @param mlsdb // -func (hp *HelloProtocol) Init(face *logicface.LogicFace, +func (hp *HelloProtocol) Init(face *logicface.LogicFaceICN, scheduler *lsdb.MlsrScheduler, keychain *security.KeyChain, mlsrConfig *common.MlsrConfig, routingTable *route.RoutingTable, mlsdb *lsdb.Lsdb) { @@ -115,7 +116,12 @@ func (hp *HelloProtocol) expressInterest(interestName *component.Identifier, _mi interest := packet.NewInterest() interest.SetName(interestName) interest.SetInterestLifeTime(uint64(_millseconds)) - // todo 这里需要实现的是,将兴趣包通过face发出,并对超时、nack、正常应答三种情况进行处理 + // 将兴趣包通过face发出,并对超时、nack、正常应答三种情况进行处理 + err := hp.m_face.ExpressInterest(interest, hp.onContent, hp.processInterestTimedOut, hp.processInterestNack) + if err != nil { + common2.LogDebug("HelloProtocol express interest error, maybe the icn logic face doesn't work.", err) + return + } } // @@ -158,13 +164,33 @@ func (hp *HelloProtocol) SendHelloInterest(neighbor *component.Identifier) { } } +// +// processInterestNack +// @Description: 发送兴趣包给邻居路由器,当收到nack时,执行本函数 +// @receiver hp +// @param interest +// @param nack +// +func (hp *HelloProtocol) processInterestNack(interest *packet.Interest, nack *packet.Nack) { + common2.LogDebug("HelloProtocol receive nack for interest: "+interest.GetName().ToUri()+ + ", the nack reason is: ", nack.GetNackReason(), "will treat as time out in 2s later.") + job, err := hp.m_scheduler.ScheduleTaskAfterDuration(2*time.Second, 1). + Do(hp.processInterestTimedOut, interest) + job.LimitRunsTo(1) + hp.m_scheduler.StartAsync() + if err != nil { + common2.LogError("HelloProtocol ScheduleTask to processInterestTimedOut error. ", err.Error()) + } +} + // // processInterestTimedOut -// @Description: 发送兴趣包给邻居路由器,当超时或nack时,执行本函数 +// @Description: 发送兴趣包给邻居路由器,当超时时,执行本函数 // @receiver hp // @param interest // func (hp *HelloProtocol) processInterestTimedOut(interest *packet.Interest) { + common2.LogDebug("HelloProtocol time out for interest: " + interest.GetName().ToUri()) // interest name: //NLSR/INFO/ interestName := interest.GetName() // 取出兴趣包倒数第二个组件,对其进行校验