1
0
mirror of https://gitee.com/willfree/mlsr.git synced 2026-06-15 18:44:53 +08:00

加入hello和fib之后,两个问题:1. hello这块要大修,才能合并进来 ;2. fib这块是针对master分支的,对于para分支会报错,要修复

This commit is contained in:
free will
2022-07-08 23:42:29 +08:00
parent c586f5cd3c
commit 4b93bcd0d2
5 changed files with 135 additions and 57 deletions
+13 -2
View File
@@ -6,15 +6,24 @@ require (
//github.com/rakanalh/scheduler v0.1
github.com/go-co-op/gocron v1.13.0
github.com/liyue201/gostl v1.0.1
github.com/olekukonko/tablewriter v0.0.5
github.com/tidwall/buntdb v1.2.9
gopkg.in/ini.v1 v1.62.0
minlib v0.0.0
)
require github.com/sirupsen/logrus v1.8.1
require (
github.com/AlecAivazis/survey/v2 v2.3.5
github.com/sirupsen/logrus v1.8.1
)
require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/mattn/go-isatty v0.0.8 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mutecomm/go-sqlcipher/v4 v4.4.2 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/smartystreets/goconvey v1.7.2 // indirect
@@ -28,7 +37,9 @@ require (
github.com/tylertreat/BoomFilters v0.0.0-20210315201527-1a82519a3e43 // indirect
github.com/zeebo/xxh3 v1.0.1 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 // indirect
golang.org/x/text v0.3.3 // indirect
)
replace minlib v0.0.0 => ../minlib
+30 -1
View File
@@ -1,5 +1,11 @@
github.com/AlecAivazis/survey/v2 v2.3.5 h1:A8cYupsAZkjaUmhtTYv3sSqc7LO5mp1XDfqe5E/9wRQ=
github.com/AlecAivazis/survey/v2 v2.3.5/go.mod h1:4AuI9b7RjAR+G7v9+C4YSlX/YL3K3cWNXgWXOhllqvI=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2 h1:+vx7roKuyA63nhn5WAunQHLTznkw5W8b1Xc0dNjp83s=
github.com/Netflix/go-expect v0.0.0-20220104043353-73e0943537d2/go.mod h1:HBCaDeC1lPdgDeDbhX8XFpy1jqjK0IBG8W5K+xYqA0w=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI=
github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U=
github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -9,14 +15,28 @@ github.com/go-co-op/gocron v1.13.0 h1:BjkuNImPy5NuIPEifhWItFG7pYyr27cyjS6BN9w/D4
github.com/go-co-op/gocron v1.13.0/go.mod h1:GD5EIEly1YNW+LovFVx5dzbYVcIc8544K99D8UVRpGo=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/liyue201/gostl v1.0.1 h1:VQdvogZ90WpCb5WdG9UxS6r5ulnYEp8VfEMEZXVtpIs=
github.com/liyue201/gostl v1.0.1/go.mod h1:rgK+T1a0sQ1+CsAonfuD1J8C4iuGfOU9VAt9mmR/m10=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mutecomm/go-sqlcipher/v4 v4.4.2 h1:eM10bFtI4UvibIsKr10/QT7Yfz+NADfjZYh0GKrXUNc=
github.com/mutecomm/go-sqlcipher/v4 v4.4.2/go.mod h1:mF2UmIpBnzFeBdu/ypTDb/LdbS0nk0dfSN1WUsWTjMA=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
@@ -33,6 +53,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/assert v0.1.0 h1:aWcKyRBUAdLoVebxo95N7+YZVTFF/ASTr7BN4sLP6XI=
@@ -67,9 +88,17 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc=
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56 h1:b8jxX3zqjpqb2LklXPzKSGJhzyxCOZSz8ncv8Nv+y7w=
golang.org/x/term v0.0.0-20210503060354-a79de5458b56/go.mod h1:tfny5GFUkzUvx4ps4ajbZsCe5lw1metzhBm9T3x7oIY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
+68 -52
View File
@@ -11,13 +11,13 @@ import (
"fmt"
"github.com/sirupsen/logrus"
"minlib/component"
"minlib/encoding"
"minlib/logicface"
"minlib/packet"
"minlib/security"
"mlsr/common"
"mlsr/lsa"
"mlsr/lsdb"
"mlsr/route"
"time"
)
@@ -27,19 +27,38 @@ const INFO_COMPONENT = "INFO"
const MLSR_COMPONENT = "MLSR"
type HelloProtocol struct {
encoding.SelfEncodingBase
mlsrConfig *common.MlsrConfig
face *logicface.LogicFace
keychain *security.KeyChain
//RoutingTable
lsdb.Lsdb
scheduler *lsdb.Scheduler
//SignatureInfo *component.SignatureInfo
m_face *logicface.LogicFace
m_scheduler *lsdb.MlsrScheduler
m_keychain *security.KeyChain
mlsrConfig *common.MlsrConfig
m_routingTable *route.RoutingTable
m_lsdb *lsdb.Lsdb
m_adjacencyList *lsa.AdjLsaAdjacenctList
}
//声明一个邻接列表
var adjacentList *lsa.AdjLsaAdjacenctList
//
// Init
// @Description: Hello协议-初始化
// @receiver hp
// @param face
// @param scheduler
// @param keychain
// @param mlsrConfig
// @param routingTable
// @param mlsdb
//
func (hp *HelloProtocol) Init(face *logicface.LogicFace,
scheduler *lsdb.MlsrScheduler,
keychain *security.KeyChain, mlsrConfig *common.MlsrConfig,
routingTable *route.RoutingTable, mlsdb *lsdb.Lsdb) {
hp.m_face = face
hp.m_scheduler = scheduler
hp.m_keychain = keychain
hp.mlsrConfig = mlsrConfig
hp.m_routingTable = routingTable
hp.m_lsdb = mlsdb
hp.m_adjacencyList = mlsrConfig.GetAdjacencys()
}
// ExpressInterest
// @Description:发送一个Hello兴趣包
@@ -47,15 +66,15 @@ var adjacentList *lsa.AdjLsaAdjacenctList
// @param interestNamePrefix
// @param seconds
//
func (h *HelloProtocol) ExpressInterest(interestName *component.Identifier, seconds uint32) error {
func (hp *HelloProtocol) ExpressInterest(interestName *component.Identifier, seconds uint32) error {
logrus.Debug("Expressing Interest: ", interestName)
var interest *packet.Interest
interest.SetName(interestName) //设置兴趣包的名字
interest.SetInterestLifeTime(uint64(seconds)) //设置兴趣包的生命周期
interest.SetMustBeRefresh(true)
interest.SetCanBePrefix(true)
h.face.SendInterest(interest)
err := h.face.SendInterest(interest)
hp.m_face.SendInterest(interest)
err := hp.m_face.SendInterest(interest)
if err == nil {
fmt.Println("Express successfully!")
} else {
@@ -69,12 +88,11 @@ func (h *HelloProtocol) ExpressInterest(interestName *component.Identifier, seco
// @receiver h
// @param neighbor
//
func (h *HelloProtocol) SendHelloInterest(neighbor *component.Identifier) {
func (hp *HelloProtocol) SendHelloInterest(neighbor *component.Identifier) {
//声明一个邻居“对象”,输入其名称前缀获取它的邻接信息,adjacent的类型为*AdjLsaAdjacencyInfo
adjacent, _ := adjacentList.GetAdjacency(neighbor)
adjacent, _ := hp.m_adjacencyList.GetAdjacency(neighbor)
//判定邻接列表是否为空,若为空则返回
if adjacentList.GetAdjList() == nil {
if hp.m_adjacencyList.GetAdjList() == nil {
return
}
if adjacent.LogicFaceId() != 0 {
@@ -87,12 +105,11 @@ func (h *HelloProtocol) SendHelloInterest(neighbor *component.Identifier) {
info, _ := component.CreateIdentifierByString(INFO_COMPONENT)
mlsr1, _ := mlsr.Get(0) //mlsr1的类型是*component.IdentifierComponent
info1, _ := info.Get(0)
thisRouterPrefix, _ := h.ThisRouterPrefix.Get(0)
interestName.Append(mlsr1) //在兴趣包名字后面添加“MLSR
interestName.Append(info1) //在兴趣包名字后面添加“INFO”
interestName.Append(thisRouterPrefix) //兴趣包名字后面添加本路由器的前缀
h.ExpressInterest(interestName, h.mlsrConfig.HelloTimeout) //将兴趣包传出去
logrus.Debug("Sending Hello Interest:", interestName) //日志记录
interestName.Append(mlsr1) //在兴趣包名字后面添加“MLSR”
interestName.Append(info1) //在兴趣包名字后面添加“INFO
interestName.Append(hp.mlsrConfig.GetRouterPrefix().ToUri()) //在兴趣包名字后面添加本路由器的前缀
hp.ExpressInterest(interestName, hp.mlsrConfig.HelloTimeout) //兴趣包传出去
logrus.Debug("Sending Hello Interest:", interestName) //日志记录
}
//使用调度器循环调度上面事件,调度器里传入两个参数:一个是间隔时间,一个是event,意思是每隔HelloInterval时间就调用一次event事件
//h.scheduler.scheduler(h.mlsrConfig.HelloInterval,{h.SendHelloInterest(this.neighbor)})
@@ -104,7 +121,7 @@ func (h *HelloProtocol) SendHelloInterest(neighbor *component.Identifier) {
// @param name
// @param interest
//
func (h *HelloProtocol) ProcessInterest(interest *packet.Interest) {
func (hp *HelloProtocol) ProcessInterest(interest *packet.Interest) {
var interestName *component.Identifier
//假设本机是A,邻居是B
//收到的interest name: /<A路由器前缀>/MLSR/INFO/<B路由器前缀>
@@ -121,7 +138,7 @@ func (h *HelloProtocol) ProcessInterest(interest *packet.Interest) {
neighborPrefix, _ := interestName.Get(-1) //neighborPrefix是IdentifierComponent,与neighbor不同
neighbor.WireDecode(neighborPrefix.Raw())
logrus.Debug("Neighbor: v%", neighbor)
if adjacentList.IsNeighbor(neighbor) {
if hp.m_adjacencyList.IsNeighbor(neighbor) {
var data *packet.Data
dataName := interest.GetName()
dataName.AppendVersionNumber(1)
@@ -129,19 +146,19 @@ func (h *HelloProtocol) ProcessInterest(interest *packet.Interest) {
data.SetFreshnessPeriod(uint64(time.Second * 10)) //10 sec
data.Payload.SetValue([]byte(INFO_COMPONENT))
h.keychain.SignData(data)
hp.m_keychain.SignData(data)
logrus.Debug("Sending out data for name:v%", interestName)
h.face.SendData(data)
err := h.face.SendData(data)
hp.m_face.SendData(data)
err := hp.m_face.SendData(data)
if err == nil {
fmt.Println("Process successfully!")
} else {
fmt.Println("Process unsuccessfully!")
}
//为了优化响应链路恢复的时间,如果邻居当前是非活动状态,那么Hello协议将立即向邻居发送Hello Interest
adjacent, _ := adjacentList.GetAdjacency(neighbor)
adjacent, _ := hp.m_adjacencyList.GetAdjacency(neighbor)
if adjacent.Status == 0 { //邻居路由器的状态:未知-1、未激活0、激活1
if adjacent.LogicFaceId() != 0 { //邻居有face我们才能做
var interestName *component.Identifier
@@ -157,8 +174,8 @@ func (h *HelloProtocol) ProcessInterest(interest *packet.Interest) {
interestName.Append(mlsr1) //在兴趣包名字后面添加“MLSR”
interestName.Append(info1) //在兴趣包名字后面添加“INFO”
interestName.Append(thisRouterPrefix) //在兴趣包名字后面添加本路由器的前缀
h.ExpressInterest(interestName, h.mlsrConfig.HelloTimeout) //将兴趣包传出去
interestName.Append(thisRouterPrefix) //在兴趣包名字后面添加本路由器的前缀
hp.ExpressInterest(interestName, hp.mlsrConfig.HelloTimeout) //将兴趣包传出去
}
}
@@ -171,7 +188,7 @@ func (h *HelloProtocol) ProcessInterest(interest *packet.Interest) {
// @receiver h
// @param interest
//
func (h *HelloProtocol) ProcessInterestTimeOut(interest *packet.Interest) {
func (hp *HelloProtocol) ProcessInterestTimeOut(interest *packet.Interest) {
var interestName *component.Identifier
interestName = interest.GetName()
logrus.Debug("Interest timed out for Name:v%", interestName)
@@ -187,14 +204,14 @@ func (h *HelloProtocol) ProcessInterestTimeOut(interest *packet.Interest) {
//neighbor.WireDecode(neighborPrefix.Raw())
neighbor.BuildIdentifierByString(neighborPrefix.ToString())
logrus.Debug("Neighbor: v%", neighbor)
adjacentList.IncrementTimedOutInterestCount(neighbor)
status, _ := adjacentList.GetStatusOfNeighbor(neighbor) //邻居路由器的状态:未知-1、未激活0、激活1
infoIntTimedOutCount, _ := adjacentList.GetTimedOutInterestCount(neighbor)
hp.m_adjacencyList.IncrementTimedOutInterestCount(neighbor)
status, _ := hp.m_adjacencyList.GetStatusOfNeighbor(neighbor) //邻居路由器的状态:未知-1、未激活0、激活1
infoIntTimedOutCount, _ := hp.m_adjacencyList.GetTimedOutInterestCount(neighbor)
logrus.Debug("Status:v%", status)
logrus.Debug("Info Interest Timed out:v%", infoIntTimedOutCount)
if infoIntTimedOutCount < uint32(h.mlsrConfig.HelloRetries) {
if infoIntTimedOutCount < uint32(hp.mlsrConfig.HelloRetries) {
var interestName *component.Identifier
adjacent, _ := adjacentList.GetAdjacency(neighbor)
adjacent, _ := hp.m_adjacencyList.GetAdjacency(neighbor)
//获取邻居路由器的名称前缀
interestName = adjacent.GetNeighborRouterIdentifier()
//假设本机是A,邻居是B
@@ -208,15 +225,14 @@ func (h *HelloProtocol) ProcessInterestTimeOut(interest *packet.Interest) {
interestName.Append(info1) //在兴趣包名字后面添加“INFO”
interestName.Append(thisRouterPrefix) //在兴趣包名字后面添加本路由器的前缀
logrus.Debug("Resending interest:v%", interestName)
h.ExpressInterest(interestName, h.mlsrConfig.HelloTimeout) //将兴趣包传出去
hp.ExpressInterest(interestName, hp.mlsrConfig.HelloTimeout) //将兴趣包传出去
} else {
if status == 1 {
adjacentList.SetStatusOfNeighbor(neighbor, 0) //邻居被置为未激活
adjacentList.SetTimedOutInterestCount(neighbor, uint32(h.mlsrConfig.HelloRetries)) //邻居的超时计数被设置为hello-retries
hp.m_adjacencyList.SetStatusOfNeighbor(neighbor, 0) //邻居被置为未激活
hp.m_adjacencyList.SetTimedOutInterestCount(neighbor, uint32(hp.mlsrConfig.HelloRetries)) //邻居的超时计数被设置为hello-retries
logrus.Debug("Neighbor:v% status changed to INACTIVE", neighbor)
h.ScheduleAdjLsaBuild() //安排Adjacency LSA的构建
hp.ScheduleAdjLsaBuild() //安排Adjacency LSA的构建
}
}
}
@@ -227,13 +243,13 @@ func (h *HelloProtocol) ProcessInterestTimeOut(interest *packet.Interest) {
// @param interest
// @param data
//
func (h *HelloProtocol) OnContent(data *packet.Data) {
func (hp *HelloProtocol) OnContent(data *packet.Data) {
logrus.Debug("Received data for name:v%", data.GetName())
Sig, _ := data.GetSignature(0) //获取指定位置的签名
if Sig != nil {
kl := Sig.SigInfo.GetKeyLocator()
if kl != nil {
if h.keychain.VerifyData(data) != nil {
if hp.m_keychain.VerifyData(data) != nil {
fmt.Println("Data signed with:v%", kl.GetIdentifier())
logrus.Debug("Data signed with:v%", kl.GetIdentifier())
}
@@ -247,7 +263,7 @@ func (h *HelloProtocol) OnContent(data *packet.Data) {
// @receiver h
// @param data
//
func (h *HelloProtocol) OnContentValidated(data *packet.Data) {
func (hp *HelloProtocol) OnContentValidated(data *packet.Data) {
// data name: /<neighbor>/NLSR/INFO/<router>/<version>
dataName := data.GetName()
logrus.Debug("Data validation successful for name:v%", dataName)
@@ -259,17 +275,17 @@ func (h *HelloProtocol) OnContentValidated(data *packet.Data) {
if neighbor != nil {
neighbor.BuildIdentifierByString(neighborPrefix.ToString())
oldStatus, _ := adjacentList.GetStatusOfNeighbor(neighbor) //*identifier
adjacentList.SetStatusOfNeighbor(neighbor, 1) //邻居路由器的状态:未知-1、未激活0、激活1
adjacentList.SetTimedOutInterestCount(neighbor, 0)
newStatus, _ := adjacentList.GetStatusOfNeighbor(neighbor)
oldStatus, _ := hp.m_adjacencyList.GetStatusOfNeighbor(neighbor) //*identifier
hp.m_adjacencyList.SetStatusOfNeighbor(neighbor, 1) //邻居路由器的状态:未知-1、未激活0、激活1
hp.m_adjacencyList.SetTimedOutInterestCount(neighbor, 0)
newStatus, _ := hp.m_adjacencyList.GetStatusOfNeighbor(neighbor)
fmt.Println("Neighbor:v%", neighbor)
fmt.Println("Old status:v%,New status:v%", oldStatus, newStatus)
logrus.Debug("Neighbor:v%", neighbor)
logrus.Debug("Old status:v%,New status:v%", oldStatus, newStatus)
// change in Adjacency list
if oldStatus != newStatus {
h.ScheduleAdjLsaBuild()
hp.ScheduleAdjLsaBuild()
}
}
+23
View File
@@ -0,0 +1,23 @@
//package cmd
//@Author: Pei Xinyuan
//@Description:
//@Version: 0.1.0
//@Date: 2022/6/24 17:50:00
//@Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
package mir
import "github.com/AlecAivazis/survey/v2"
func AskPassword() (string, error) {
return AskPasswordWithCustomMsg("Please type your password")
}
func AskPasswordWithCustomMsg(msg string) (string, error) {
passwd := ""
prompt := &survey.Password{
Message: msg,
}
err := survey.AskOne(prompt, &passwd)
return passwd, err
}
+1 -2
View File
@@ -17,7 +17,6 @@ import (
"minlib/logicface"
"minlib/mgmt"
"minlib/security"
"mlsr/cmd"
"os"
"strconv"
)
@@ -47,7 +46,7 @@ type FibInfo struct {
//
func init() {
//password first
passwd, err := cmd.AskPassword()
passwd, err := AskPassword()
if err != nil {
common.LogFatal(err)
}