github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/p2p/testing/fuzz_p2p.go (about)

     1  package testing
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/ethereum/go-ethereum/p2p/enr"
     7  	"github.com/libp2p/go-libp2p-core/control"
     8  	"github.com/libp2p/go-libp2p-core/host"
     9  	"github.com/libp2p/go-libp2p-core/network"
    10  	"github.com/libp2p/go-libp2p-core/peer"
    11  	pubsub "github.com/libp2p/go-libp2p-pubsub"
    12  	"github.com/multiformats/go-multiaddr"
    13  	ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
    14  	"github.com/prysmaticlabs/prysm/shared/interfaces"
    15  	"google.golang.org/protobuf/proto"
    16  
    17  	"github.com/prysmaticlabs/prysm/beacon-chain/p2p/encoder"
    18  	"github.com/prysmaticlabs/prysm/beacon-chain/p2p/peers"
    19  )
    20  
    21  // FakeP2P stack
    22  type FakeP2P struct {
    23  }
    24  
    25  // NewFuzzTestP2P - Create a new fake p2p stack.
    26  func NewFuzzTestP2P() *FakeP2P {
    27  	return &FakeP2P{}
    28  }
    29  
    30  // Encoding -- fake.
    31  func (p *FakeP2P) Encoding() encoder.NetworkEncoding {
    32  	return &encoder.SszNetworkEncoder{}
    33  }
    34  
    35  // AddConnectionHandler -- fake.
    36  func (p *FakeP2P) AddConnectionHandler(_, _ func(ctx context.Context, id peer.ID) error) {
    37  
    38  }
    39  
    40  // AddDisconnectionHandler -- fake.
    41  func (p *FakeP2P) AddDisconnectionHandler(_ func(ctx context.Context, id peer.ID) error) {
    42  }
    43  
    44  // AddPingMethod -- fake.
    45  func (p *FakeP2P) AddPingMethod(_ func(ctx context.Context, id peer.ID) error) {
    46  
    47  }
    48  
    49  // PeerID -- fake.
    50  func (p *FakeP2P) PeerID() peer.ID {
    51  	return "fake"
    52  }
    53  
    54  // ENR returns the enr of the local peer.
    55  func (p *FakeP2P) ENR() *enr.Record {
    56  	return new(enr.Record)
    57  }
    58  
    59  // DiscoveryAddresses -- fake
    60  func (p *FakeP2P) DiscoveryAddresses() ([]multiaddr.Multiaddr, error) {
    61  	return nil, nil
    62  }
    63  
    64  // FindPeersWithSubnet mocks the p2p func.
    65  func (p *FakeP2P) FindPeersWithSubnet(_ context.Context, _ string, _, _ uint64) (bool, error) {
    66  	return false, nil
    67  }
    68  
    69  // RefreshENR mocks the p2p func.
    70  func (p *FakeP2P) RefreshENR() {}
    71  
    72  // LeaveTopic -- fake.
    73  func (p *FakeP2P) LeaveTopic(_ string) error {
    74  	return nil
    75  }
    76  
    77  // Metadata -- fake.
    78  func (p *FakeP2P) Metadata() interfaces.Metadata {
    79  	return nil
    80  }
    81  
    82  // Peers -- fake.
    83  func (p *FakeP2P) Peers() *peers.Status {
    84  	return nil
    85  }
    86  
    87  // PublishToTopic -- fake.
    88  func (p *FakeP2P) PublishToTopic(_ context.Context, _ string, _ []byte, _ ...pubsub.PubOpt) error {
    89  	return nil
    90  }
    91  
    92  // Send -- fake.
    93  func (p *FakeP2P) Send(_ context.Context, _ interface{}, _ string, _ peer.ID) (network.Stream, error) {
    94  	return nil, nil
    95  }
    96  
    97  // PubSub -- fake.
    98  func (p *FakeP2P) PubSub() *pubsub.PubSub {
    99  	return nil
   100  }
   101  
   102  // MetadataSeq -- fake.
   103  func (p *FakeP2P) MetadataSeq() uint64 {
   104  	return 0
   105  }
   106  
   107  // SetStreamHandler -- fake.
   108  func (p *FakeP2P) SetStreamHandler(_ string, _ network.StreamHandler) {
   109  
   110  }
   111  
   112  // SubscribeToTopic -- fake.
   113  func (p *FakeP2P) SubscribeToTopic(_ string, _ ...pubsub.SubOpt) (*pubsub.Subscription, error) {
   114  	return nil, nil
   115  }
   116  
   117  // JoinTopic -- fake.
   118  func (p *FakeP2P) JoinTopic(_ string, _ ...pubsub.TopicOpt) (*pubsub.Topic, error) {
   119  	return nil, nil
   120  }
   121  
   122  // Host -- fake.
   123  func (p *FakeP2P) Host() host.Host {
   124  	return nil
   125  }
   126  
   127  // Disconnect -- fake.
   128  func (p *FakeP2P) Disconnect(_ peer.ID) error {
   129  	return nil
   130  }
   131  
   132  // Broadcast -- fake.
   133  func (p *FakeP2P) Broadcast(_ context.Context, _ proto.Message) error {
   134  	return nil
   135  }
   136  
   137  // BroadcastAttestation -- fake.
   138  func (p *FakeP2P) BroadcastAttestation(_ context.Context, _ uint64, _ *ethpb.Attestation) error {
   139  	return nil
   140  }
   141  
   142  // InterceptPeerDial -- fake.
   143  func (p *FakeP2P) InterceptPeerDial(peer.ID) (allow bool) {
   144  	return true
   145  }
   146  
   147  // InterceptAddrDial -- fake.
   148  func (p *FakeP2P) InterceptAddrDial(peer.ID, multiaddr.Multiaddr) (allow bool) {
   149  	return true
   150  }
   151  
   152  // InterceptAccept -- fake.
   153  func (p *FakeP2P) InterceptAccept(_ network.ConnMultiaddrs) (allow bool) {
   154  	return true
   155  }
   156  
   157  // InterceptSecured -- fake.
   158  func (p *FakeP2P) InterceptSecured(network.Direction, peer.ID, network.ConnMultiaddrs) (allow bool) {
   159  	return true
   160  }
   161  
   162  // InterceptUpgraded -- fake.
   163  func (p *FakeP2P) InterceptUpgraded(network.Conn) (allow bool, reason control.DisconnectReason) {
   164  	return true, 0
   165  }