github.com/dim4egster/coreth@v0.10.2/plugin/evm/message/handler.go (about)

     1  // (c) 2019-2021, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package message
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/ethereum/go-ethereum/log"
    10  
    11  	"github.com/dim4egster/qmallgo/ids"
    12  )
    13  
    14  var (
    15  	_ GossipHandler  = NoopMempoolGossipHandler{}
    16  	_ RequestHandler = NoopRequestHandler{}
    17  )
    18  
    19  // GossipHandler handles incoming gossip messages
    20  type GossipHandler interface {
    21  	HandleAtomicTx(nodeID ids.NodeID, msg AtomicTxGossip) error
    22  	HandleEthTxs(nodeID ids.NodeID, msg EthTxsGossip) error
    23  }
    24  
    25  type NoopMempoolGossipHandler struct{}
    26  
    27  func (NoopMempoolGossipHandler) HandleAtomicTx(nodeID ids.NodeID, msg AtomicTxGossip) error {
    28  	log.Debug("dropping unexpected AtomicTxGossip message", "peerID", nodeID)
    29  	return nil
    30  }
    31  
    32  func (NoopMempoolGossipHandler) HandleEthTxs(nodeID ids.NodeID, msg EthTxsGossip) error {
    33  	log.Debug("dropping unexpected EthTxsGossip message", "peerID", nodeID)
    34  	return nil
    35  }
    36  
    37  // RequestHandler interface handles incoming requests from peers
    38  // Must have methods in format of handleType(context.Context, ids.ShortID, uint32, request Type) error
    39  // so that the Request object of relevant Type can invoke its respective handle method
    40  // on this struct.
    41  // Also see GossipHandler for implementation style.
    42  type RequestHandler interface {
    43  	HandleStateTrieLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest LeafsRequest) ([]byte, error)
    44  	HandleAtomicTrieLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest LeafsRequest) ([]byte, error)
    45  	HandleBlockRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, request BlockRequest) ([]byte, error)
    46  	HandleCodeRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, codeRequest CodeRequest) ([]byte, error)
    47  }
    48  
    49  // ResponseHandler handles response for a sent request
    50  // Only one of OnResponse or OnFailure is called for a given requestID, not both
    51  type ResponseHandler interface {
    52  	// OnResponse is invoked when the peer responded to a request
    53  	OnResponse(nodeID ids.NodeID, requestID uint32, response []byte) error
    54  	// OnFailure is invoked when there was a failure in processing a request
    55  	OnFailure(nodeID ids.NodeID, requestID uint32) error
    56  }
    57  
    58  type NoopRequestHandler struct{}
    59  
    60  func (NoopRequestHandler) HandleStateTrieLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest LeafsRequest) ([]byte, error) {
    61  	return nil, nil
    62  }
    63  
    64  func (NoopRequestHandler) HandleAtomicTrieLeafsRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, leafsRequest LeafsRequest) ([]byte, error) {
    65  	return nil, nil
    66  }
    67  
    68  func (NoopRequestHandler) HandleBlockRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, request BlockRequest) ([]byte, error) {
    69  	return nil, nil
    70  }
    71  
    72  func (NoopRequestHandler) HandleCodeRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, codeRequest CodeRequest) ([]byte, error) {
    73  	return nil, nil
    74  }