从DHT中删除引导节点

huangapple go评论91阅读模式
英文:

Remove bootstrapped peers from DHT

问题

我在我的项目中使用golang-libp2p,其中我使用Kadmelia DHT进行节点发现。
我可以通过以下方式访问引导节点的信息。

import (
   "github.com/libp2p/go-libp2p/core/peer"
)

for _, peerAddr := range dht.DefaultBootstrapPeers {
    peerInfo, _ := peer.AddrInfoFromP2pAddr(peerAddr)

我注意到,随着我不断添加新的节点,peerInfo列表不断增长,即使在重新启动程序后也是如此。我正在寻找一种方法来修剪/删除现有的引导节点。我看到了一个讨论此问题的拉取请求,但似乎该方法尚未包含在库中。问题的链接在这里

在golang实现中是否有可能修剪引导节点?

英文:

I am using golang-libp2p in my project where I am using Kadmelia DHT for peer discovery.
I can access info of bootstrapped peers in the following manner.

import (
   "github.com/libp2p/go-libp2p/core/peer"
)

for _, peerAddr := range dht.DefaultBootstrapPeers {
    peerInfo, _ := peer.AddrInfoFromP2pAddr(peerAddr)

I can see as I keep adding new peers, peerInfo list keeps on increasing, even after I restart the program. I am looking for a method to prune/remove existing bootstrapped peers. I have seen a pull request that talks about this issue but it seems like the method has not been included in the library. The link to the issue here.

Is it possible to prune bootstrapped peers in the golang implementation?

答案1

得分: 1

你是想从DHT路由表中移除引导节点,还是断开与主机的连接?

如果你想从DHT路由表中移除一个节点,你可以使用RemovePeer(p peer.ID)函数。

dht.RoutingTable().RemovePeer(peerid)

如果你想关闭与一个节点的连接,你可以尝试使用ClosePeer(peer.ID)RemovePeer(peer.ID)

dht.host.Network().ClosePeer(peerid)
dht.host.Peerstore().RemovePeer(peerid)
英文:

Are you trying to remove the bootstrap peer from the DHT routing table, or to disconnect it from the host?

If you want to remove a peer from the DHT routing table, you can use the RemovePeer(p peer.ID) function.

dht.RoutingTable().RemovePeer(peerid)

If you want to close the connection to a peer, you can try ClosePeer(peer.ID) and RemovePeer(peer.ID)

dht.host.Network().ClosePeer(peerid)
dht.host.Peerstore().RemovePeer(peerid)

huangapple
  • 本文由 发表于 2022年12月17日 21:40:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/74834566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定