2021-01-14 20:48:40 +00:00
|
|
|
package testing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/libp2p/go-libp2p-core/connmgr"
|
|
|
|
"github.com/libp2p/go-libp2p-core/event"
|
|
|
|
"github.com/libp2p/go-libp2p-core/network"
|
|
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
|
|
"github.com/libp2p/go-libp2p-core/peerstore"
|
|
|
|
"github.com/libp2p/go-libp2p-core/protocol"
|
|
|
|
ma "github.com/multiformats/go-multiaddr"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MockHost is a fake implementation of libp2p2's Host interface.
|
|
|
|
type MockHost struct {
|
|
|
|
Addresses []ma.Multiaddr
|
|
|
|
}
|
|
|
|
|
|
|
|
// ID --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) ID() peer.ID {
|
2021-01-14 20:48:40 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Peerstore --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) Peerstore() peerstore.Peerstore {
|
2021-01-14 20:48:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Addrs --
|
|
|
|
func (m *MockHost) Addrs() []ma.Multiaddr {
|
|
|
|
return m.Addresses
|
|
|
|
}
|
|
|
|
|
|
|
|
// Network --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) Network() network.Network {
|
2021-01-14 20:48:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mux --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) Mux() protocol.Switch {
|
2021-01-14 20:48:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connect --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) Connect(_ context.Context, _ peer.AddrInfo) error {
|
2021-01-14 20:48:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetStreamHandler --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) SetStreamHandler(_ protocol.ID, _ network.StreamHandler) {}
|
2021-01-14 20:48:40 +00:00
|
|
|
|
|
|
|
// SetStreamHandlerMatch --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) SetStreamHandlerMatch(protocol.ID, func(string) bool, network.StreamHandler) {}
|
2021-01-14 20:48:40 +00:00
|
|
|
|
|
|
|
// RemoveStreamHandler --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) RemoveStreamHandler(_ protocol.ID) {}
|
2021-01-14 20:48:40 +00:00
|
|
|
|
|
|
|
// NewStream --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) NewStream(_ context.Context, _ peer.ID, _ ...protocol.ID) (network.Stream, error) {
|
2021-01-14 20:48:40 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) Close() error {
|
2021-01-14 20:48:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnManager --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) ConnManager() connmgr.ConnManager {
|
2021-01-14 20:48:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// EventBus --
|
2021-12-07 17:52:39 +00:00
|
|
|
func (_ *MockHost) EventBus() event.Bus {
|
2021-01-14 20:48:40 +00:00
|
|
|
return nil
|
|
|
|
}
|