Commit f15ab8ee authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

net: add LocalPeer funcs

parent ff1e672d
......@@ -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
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment