英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论