mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-12 23:04:45 +00:00
close peer connection and get num of connected peers
This commit is contained in:
parent
fa7169bbbc
commit
bc32532401
@ -272,7 +272,7 @@ func (node *WakuNode) Subscribe(topic *Topic) (*Subscription, error) {
|
|||||||
|
|
||||||
wakuMessage := &protocol.WakuMessage{}
|
wakuMessage := &protocol.WakuMessage{}
|
||||||
if err := proto.Unmarshal(msg.Data, wakuMessage); err != nil {
|
if err := proto.Unmarshal(msg.Data, wakuMessage); err != nil {
|
||||||
log.Error("could not decode message", err) // TODO: use log lib
|
log.Error("could not decode message", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,3 +373,26 @@ func (w *WakuNode) DialPeer(address string) error {
|
|||||||
w.host.Connect(w.ctx, *info)
|
w.host.Connect(w.ctx, *info)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WakuNode) ClosePeerByAddress(address string) error {
|
||||||
|
p, err := ma.NewMultiaddr(address)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the peer ID from the multiaddr.
|
||||||
|
info, err := peer.AddrInfoFromP2pAddr(p)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return w.ClosePeerById(info.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WakuNode) ClosePeerById(id peer.ID) error {
|
||||||
|
return w.host.Network().ClosePeer(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *WakuNode) PeerCount() int {
|
||||||
|
return len(w.host.Network().Peers())
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user