1 Star 1 Fork 0

凡卡/libp2parea

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
search_id.go 2.09 KB
一键复制 编辑 原始数据 按行查看 历史
凡卡 提交于 2023-11-29 11:01 +08:00 . first commit
package main
import (
"math/big"
"gitee.com/prestonTao/libp2parea/config"
"gitee.com/prestonTao/libp2parea/engine"
"gitee.com/prestonTao/libp2parea/nodeStore"
"gitee.com/prestonTao/utils"
)
/*
搜索逻辑节点id算法
*/
func main() {
example()
}
func example() {
engine.Log.Info("start")
kl := nodeStore.NewKademlia(0)
//要查找的节点ID
findNetid := nodeStore.AddressFromB58String("J4VhVRKxqsuTrqTDreHz8qemMWAT3S5kg9mBdgusuv5p")
// netids := make([]*big.Int, 0)
netid1 := nodeStore.AddressFromB58String("65U2vEhNAq2PNzMT9SCK2d6sZCULSFvD8vvLwRZpJkgx")
kl.Add(new(big.Int).SetBytes(netid1))
// netids = append(netids, new(big.Int).SetBytes(netid1))
netid2 := nodeStore.AddressFromB58String("AfwFmdvpqjXmVpR7MP1vQonLucaf1rQg6v7BJ9W6AirL")
kl.Add(new(big.Int).SetBytes(netid2))
// netids = append(netids, new(big.Int).SetBytes(netid2))
netid3 := nodeStore.AddressFromB58String("6vk8xDbbZaT74eMfvbfby1VCifYF31qKmTpcwFk41aQH")
kl.Add(new(big.Int).SetBytes(netid3))
// netids = append(netids, new(big.Int).SetBytes(netid3))
netid4 := nodeStore.AddressFromB58String("5bzPVbPzp9WMbXkH6w1qaYSD93FGVdbyuHYUNbioZCrU")
kl.Add(new(big.Int).SetBytes(netid4))
// netids = append(netids, new(big.Int).SetBytes(netid4))
netid5 := nodeStore.AddressFromB58String("YYBNvYGxyAxPeLNwjkBrjwuPnaCawwD3nbEPH7vyuZ5")
kl.Add(new(big.Int).SetBytes(netid5))
// netids = append(netids, new(big.Int).SetBytes(netid5))
netid6 := nodeStore.AddressFromB58String("9cV2PRMi9g7g92EQjQG4jU3pA3Rdu1ffxGu3i4KgQ9yX")
kl.Add(new(big.Int).SetBytes(netid6))
// netids = append(netids, new(big.Int).SetBytes(netid6))
// asc := nodeStore.NewIdASC(new(big.Int).SetBytes(findNetid), netids)
// result := asc.Sort()
// for _, idBig := range result {
// netidBs := idBig.Bytes()
// engine.Log.Info("最近的节点:%s", nodeStore.AddressNet(netidBs).B58String())
// }
targetIds := kl.Get(new(big.Int).SetBytes(findNetid))
targetId := targetIds[0]
targetIdBs := targetId.Bytes()
mh := nodeStore.AddressNet(*utils.FullHighPositionZero(&targetIdBs, config.Addr_byte_length))
engine.Log.Info("检查id结果:%s", mh.B58String())
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/prestonTao/libp2parea.git
git@gitee.com:prestonTao/libp2parea.git
prestonTao
libp2parea
libp2parea
3aaa451ef873

搜索帮助