mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-09 10:18:04 +08:00
net: add LocalPeer funcs
This commit is contained in:
parent
ff1e672d5a
commit
f15ab8eec3
@ -20,6 +20,9 @@ type Network interface {
|
||||
// Listen(*ma.Muliaddr) error
|
||||
// TODO: for now, only listen on addrs in local peer when initializing.
|
||||
|
||||
// LocalPeer returns the local peer associated with this network
|
||||
LocalPeer() peer.Peer
|
||||
|
||||
// DialPeer attempts to establish a connection to a given peer
|
||||
DialPeer(context.Context, peer.Peer) error
|
||||
|
||||
@ -71,6 +74,8 @@ type Service srv.Service
|
||||
// (this is usually just a Network, but other services may not need the whole
|
||||
// stack, and thus it becomes easier to mock)
|
||||
type Dialer interface {
|
||||
// LocalPeer returns the local peer associated with this network
|
||||
LocalPeer() peer.Peer
|
||||
|
||||
// DialPeer attempts to establish a connection to a given peer
|
||||
DialPeer(context.Context, peer.Peer) error
|
||||
|
||||
@ -69,6 +69,11 @@ func (n *IpfsNetwork) DialPeer(ctx context.Context, p peer.Peer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// LocalPeer the network's LocalPeer
|
||||
func (n *IpfsNetwork) LocalPeer() peer.Peer {
|
||||
return n.swarm.LocalPeer()
|
||||
}
|
||||
|
||||
// ClosePeer connection to peer
|
||||
func (n *IpfsNetwork) ClosePeer(p peer.Peer) error {
|
||||
return n.swarm.CloseConnection(p)
|
||||
|
||||
@ -217,3 +217,8 @@ func (s *Swarm) GetPeerList() []peer.Peer {
|
||||
s.connsLock.RUnlock()
|
||||
return out
|
||||
}
|
||||
|
||||
// LocalPeer returns the local peer swarm is associated to.
|
||||
func (s *Swarm) LocalPeer() peer.Peer {
|
||||
return s.local
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user