add GetHost API in p2p/host package

Signed-off-by: Leo Chen <leo@harmony.one>
pull/348/head
Leo Chen 6 years ago
parent e7b867425f
commit 984bd15fa4
  1. 6
      p2p/host.go
  2. 6
      p2p/host/hostv1/hostv1.go
  3. 5
      p2p/host/hostv2/hostv2.go
  4. 13
      p2p/host/mock/host_mock.go

@ -1,6 +1,9 @@
package p2p
import peer "github.com/libp2p/go-libp2p-peer"
import (
p2p_host "github.com/libp2p/go-libp2p-host"
peer "github.com/libp2p/go-libp2p-peer"
)
// Host is the client + server in p2p network.
type Host interface {
@ -10,4 +13,5 @@ type Host interface {
Close() error
AddPeer(*Peer) error
GetID() peer.ID
GetP2PHost() p2p_host.Host
}

@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/harmony-one/harmony/p2p"
p2p_host "github.com/libp2p/go-libp2p-host"
peer "github.com/libp2p/go-libp2p-peer"
)
@ -111,3 +112,8 @@ func (host *HostV1) Close() error {
host.quit <- struct{}{}
return host.listener.Close()
}
// GetP2PHost returns nothing
func (host *HostV1) GetP2PHost() p2p_host.Host {
return nil
}

@ -135,3 +135,8 @@ func (host *HostV2) SendMessage(p p2p.Peer, message []byte) error {
func (host *HostV2) Close() error {
return host.h.Close()
}
// GetP2PHost returns the p2p.Host
func (host *HostV2) GetP2PHost() p2p_host.Host {
return host.h
}

@ -9,6 +9,7 @@ import (
gomock "github.com/golang/mock/gomock"
p2p "github.com/harmony-one/harmony/p2p"
p2p_host "github.com/libp2p/go-libp2p-host"
peer "github.com/libp2p/go-libp2p-peer"
)
@ -104,3 +105,15 @@ func (m *MockHost) GetID() peer.ID {
func (mr *MockHostMockRecorder) GetID() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetID", reflect.TypeOf((*MockHost)(nil).GetID))
}
// GetP2PHost mocks base method
func (m *MockHost) GetP2PHost() p2p_host.Host {
ret := m.ctrl.Call(m, "GetP2PHost")
ret0, _ := ret[0].(p2p_host.Host)
return ret0
}
// GetP2PHost indicates an expected call of GetP2PHost
func (mr *MockHostMockRecorder) GetP2PHost() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetP2PHost", reflect.TypeOf((*MockHost)(nil).GetP2PHost))
}

Loading…
Cancel
Save