github.com/ethereum-optimism/optimism@v1.7.2/op-node/p2p/rpc_api.go (about)

     1  package p2p
     2  
     3  import (
     4  	"context"
     5  	"net"
     6  	"time"
     7  
     8  	"github.com/ethereum/go-ethereum/p2p/enode"
     9  	"github.com/libp2p/go-libp2p/core/network"
    10  	"github.com/libp2p/go-libp2p/core/peer"
    11  
    12  	"github.com/ethereum-optimism/optimism/op-node/p2p/store"
    13  )
    14  
    15  type PeerInfo struct {
    16  	PeerID          peer.ID  `json:"peerID"`
    17  	NodeID          enode.ID `json:"nodeID"`
    18  	UserAgent       string   `json:"userAgent"`
    19  	ProtocolVersion string   `json:"protocolVersion"`
    20  	ENR             string   `json:"ENR"`       // might not always be known, e.g. if the peer connected us instead of us discovering them
    21  	Addresses       []string `json:"addresses"` // multi-addresses. may be mix of LAN / docker / external IPs. All of them are communicated.
    22  	Protocols       []string `json:"protocols"` // negotiated protocols list
    23  	// GossipScore float64
    24  	// PeerScore float64
    25  	Connectedness network.Connectedness `json:"connectedness"` // "NotConnected", "Connected", "CanConnect" (gracefully disconnected), or "CannotConnect" (tried but failed)
    26  	Direction     network.Direction     `json:"direction"`     // "Unknown", "Inbound" (if the peer contacted us), "Outbound" (if we connected to them)
    27  	Protected     bool                  `json:"protected"`     // Protected peers do not get
    28  	ChainID       uint64                `json:"chainID"`       // some peers might try to connect, but we figure out they are on a different chain later. This may be 0 if the peer is not an optimism node at all.
    29  	Latency       time.Duration         `json:"latency"`
    30  
    31  	GossipBlocks bool `json:"gossipBlocks"` // if the peer is in our gossip topic
    32  
    33  	PeerScores store.PeerScores `json:"scores"`
    34  }
    35  
    36  type PeerDump struct {
    37  	TotalConnected uint                 `json:"totalConnected"`
    38  	Peers          map[string]*PeerInfo `json:"peers"`
    39  	BannedPeers    []peer.ID            `json:"bannedPeers"`
    40  	BannedIPS      []net.IP             `json:"bannedIPS"`
    41  	BannedSubnets  []*net.IPNet         `json:"bannedSubnets"`
    42  }
    43  
    44  //go:generate mockery --name API --output mocks/ --with-expecter=true
    45  type API interface {
    46  	Self(ctx context.Context) (*PeerInfo, error)
    47  	Peers(ctx context.Context, connected bool) (*PeerDump, error)
    48  	PeerStats(ctx context.Context) (*PeerStats, error)
    49  	DiscoveryTable(ctx context.Context) ([]*enode.Node, error)
    50  	BlockPeer(ctx context.Context, p peer.ID) error
    51  	UnblockPeer(ctx context.Context, p peer.ID) error
    52  	ListBlockedPeers(ctx context.Context) ([]peer.ID, error)
    53  	BlockAddr(ctx context.Context, ip net.IP) error
    54  	UnblockAddr(ctx context.Context, ip net.IP) error
    55  	ListBlockedAddrs(ctx context.Context) ([]net.IP, error)
    56  	BlockSubnet(ctx context.Context, ipnet *net.IPNet) error
    57  	UnblockSubnet(ctx context.Context, ipnet *net.IPNet) error
    58  	ListBlockedSubnets(ctx context.Context) ([]*net.IPNet, error)
    59  	ProtectPeer(ctx context.Context, p peer.ID) error
    60  	UnprotectPeer(ctx context.Context, p peer.ID) error
    61  	ConnectPeer(ctx context.Context, addr string) error
    62  	DisconnectPeer(ctx context.Context, id peer.ID) error
    63  }