From 0f8cc5fcd2afd5d08b28b5fd2c243b5aa2ae807e Mon Sep 17 00:00:00 2001 From: Chen Kai <281165273grape@gmail.com> Date: Tue, 10 Dec 2024 14:33:42 +0800 Subject: [PATCH] add waitinit Signed-off-by: Chen Kai <281165273grape@gmail.com> --- p2p/discover/table.go | 5 +++++ p2p/discover/v5_udp.go | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/p2p/discover/table.go b/p2p/discover/table.go index 12e189dc6e..ca79dd26a6 100644 --- a/p2p/discover/table.go +++ b/p2p/discover/table.go @@ -695,6 +695,11 @@ func pushNode(list []*tableNode, n *tableNode, max int) ([]*tableNode, *tableNod return list, removed } +// waitInit waits until the table is initialized. +func (tab *Table) waitInit() { + <-tab.initDone +} + // nodeList returns all nodes contained in the table. func (tab *Table) nodeList() []*enode.Node { if !tab.isInitDone() { diff --git a/p2p/discover/v5_udp.go b/p2p/discover/v5_udp.go index 539c4687fc..30c7adbdb9 100644 --- a/p2p/discover/v5_udp.go +++ b/p2p/discover/v5_udp.go @@ -281,6 +281,11 @@ func (t *UDPv5) DeleteNode(n *enode.Node) { t.tab.deleteNode(n) } +// WaitInit waits for the routing table to be initialized. +func (t *UDPv5) WaitInit() { + t.tab.waitInit() +} + // LocalNode returns the current local Node running the // protocol. func (t *UDPv5) LocalNode() *enode.LocalNode {