1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-15 19:24:47 +08:00

将hello协议中的logicface替换为logicfaceICN,以丝滑支持收到数据包时的处理

This commit is contained in:
free will
2022-07-15 23:12:58 +08:00
parent 073df73c29
commit 36238cb7db
+30 -4
View File
@@ -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: /<neighbor>/NLSR/INFO/<router>
interestName := interest.GetName()
// 取出兴趣包倒数第二个组件,对其进行校验