提交 f15ab8ee 作者: Juan Batiz-Benet

net: add LocalPeer funcs

上级 ff1e672d
...@@ -20,6 +20,9 @@ type Network interface { ...@@ -20,6 +20,9 @@ type Network interface {
// Listen(*ma.Muliaddr) error // Listen(*ma.Muliaddr) error
// TODO: for now, only listen on addrs in local peer when initializing. // 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 attempts to establish a connection to a given peer
DialPeer(context.Context, peer.Peer) error DialPeer(context.Context, peer.Peer) error
...@@ -71,6 +74,8 @@ type Service srv.Service ...@@ -71,6 +74,8 @@ type Service srv.Service
// (this is usually just a Network, but other services may not need the whole // (this is usually just a Network, but other services may not need the whole
// stack, and thus it becomes easier to mock) // stack, and thus it becomes easier to mock)
type Dialer interface { 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 attempts to establish a connection to a given peer
DialPeer(context.Context, peer.Peer) error DialPeer(context.Context, peer.Peer) error
......
...@@ -69,6 +69,11 @@ func (n *IpfsNetwork) DialPeer(ctx context.Context, p peer.Peer) error { ...@@ -69,6 +69,11 @@ func (n *IpfsNetwork) DialPeer(ctx context.Context, p peer.Peer) error {
return err return err
} }
// LocalPeer the network's LocalPeer
func (n *IpfsNetwork) LocalPeer() peer.Peer {
return n.swarm.LocalPeer()
}
// ClosePeer connection to peer // ClosePeer connection to peer
func (n *IpfsNetwork) ClosePeer(p peer.Peer) error { func (n *IpfsNetwork) ClosePeer(p peer.Peer) error {
return n.swarm.CloseConnection(p) return n.swarm.CloseConnection(p)
......
...@@ -217,3 +217,8 @@ func (s *Swarm) GetPeerList() []peer.Peer { ...@@ -217,3 +217,8 @@ func (s *Swarm) GetPeerList() []peer.Peer {
s.connsLock.RUnlock() s.connsLock.RUnlock()
return out return out
} }
// LocalPeer returns the local peer swarm is associated to.
func (s *Swarm) LocalPeer() peer.Peer {
return s.local
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论