diff --git a/go.sum b/go.sum index 676150d..7d06bb2 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -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= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -9,8 +7,6 @@ github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGa github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= 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/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/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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -25,9 +21,8 @@ github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hg github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -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= github.com/tidwall/assert v0.1.0/go.mod h1:QLYtGyeqse53vuELQheYl9dngGCJQ+mTtlxcktb+Kj8= github.com/tidwall/btree v1.1.0/go.mod h1:TzIRzen6yHbibdSfK6t8QimqbUnoxUSrZfeW7Uob0q4= @@ -50,11 +45,7 @@ github.com/tidwall/rtred v0.1.2 h1:exmoQtOLvDoO8ud++6LwVsAMTu0KPzLTUrMln8u1yu8= github.com/tidwall/rtred v0.1.2/go.mod h1:hd69WNXQ5RP9vHd7dqekAz+RIdtfBogmglkZSRxCHFQ= github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaymYE= github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw= -github.com/tylertreat/BoomFilters v0.0.0-20210315201527-1a82519a3e43 h1:QEePdg0ty2r0t1+qwfZmQ4OOl/MB2UXIeJSpIZv56lg= -github.com/tylertreat/BoomFilters v0.0.0-20210315201527-1a82519a3e43/go.mod h1:OYRfF6eb5wY9VRFkXJH8FFBi3plw2v+giaIu7P054pM= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= -github.com/zeebo/xxh3 v1.0.1 h1:FMSRIbkrLikb/0hZxmltpg84VkqDAT5M8ufXynuhXsI= -github.com/zeebo/xxh3 v1.0.1/go.mod h1:8VHV24/3AZLn3b6Mlp/KuC33LWH687Wq6EnziEB+rsA= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/hello/HelloProtocol.go b/hello/HelloProtocol.go new file mode 100644 index 0000000..e67cdf0 --- /dev/null +++ b/hello/HelloProtocol.go @@ -0,0 +1,115 @@ +//package hello +//@Author: Pei Xinyuan +//@Description: +//@Version: 0.1.0 +//@Date: 2022/4/27 10:57:00 +//@Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 + +package hello + +import ( + "minlib/component" + "minlib/encoding" + "minlib/logicface" + "minlib/packet" + "minlib/security" + "mlsr/common" + "mlsr/lsa" + "mlsr/lsdb" + "time" +) + +//INIT_LOGGER(HelloProtocol) + +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 +} + +// +// expressInterest +// @Description:发送一个Hello兴趣包 +// @receiver h +// @param interestNamePrefix +// @param seconds +// +func (h *HelloProtocol) expressInterest(interestNamePrefix *component.Identifier, seconds int) { + var interest packet.Interest + interest.SetName(interestNamePrefix) + interest.SetInterestLifeTime(seconds) + interest.SetMustBeRefresh(true) + interest.SetCanBePrefix(true) + h.face.SendInterest(&interest) + +} + +// +// sendHelloInterest +// @Description:发送Hello兴趣包给所有的邻居 +// @receiver h +// @param neighbor +// +func (h *HelloProtocol) sendHelloInterest(neighbor *lsa.AdjLsaAdjacenctList) { + var number = neighbor.GetNumOfActiveNeighbor() + neighbor.GetNumOfActiveNeighbor() + if number != 0 { + for i := 0; i < number; i++ { + var adjList = neighbor.GetAdjList() + var interestName = adjList[i].GetNeighborRouterIdentifier() + interestName.BuildIdentifierByString(MLSR_COMPONENT) + interestName.BuildIdentifierByString(INFO_COMPONENT) + //少一个添加commandname的 + h.expressInterest(interestName, h.mlsrConfig.LsaInterestLifetime) + + } + } + //调度器 +} + +// +// processInterest +// @Description: 处理来自邻居的Hello兴趣包 +// @receiver h +// @param name +// @param interest +// +func (h *HelloProtocol) processInterest(name *component.Identifier, interest *packet.Interest) { + var neighbor *lsa.AdjLsaAdjacencyInfo + var neighborList *lsa.AdjLsaAdjacenctList + neighbor.WireDecode(interest.Raw()) + if neighborList.IsNeighbor(name) { + var data *packet.Data + data.SetName((interest.GetName()).AppendVersionNumber()) + data.SetFreshnessPeriod(uint64(time.Second * 10)) + h.keychain.SignData(data) + h.face.SendData(data) + if neighbor.Status == 0 { + name.BuildIdentifierByString(MLSR_COMPONENT) + name.BuildIdentifierByString(INFO_COMPONENT) + //少一个添加commandname + h.expressInterest(name, h.mlsrConfig.LsaInterestLifetime) + + } + } +} + +// +// processInterestTimeOut +// @Description: 尝试通过hello协议重新联系邻居 +// @receiver h +// @param interest +// +func (h *HelloProtocol) processInterestTimeOut(interest *packet.Interest) { + +} + +func (h *HelloProtocol) onContent(interest *packet.Interest, data *packet.Data) { + +}