forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpc_client.go
109 lines (84 loc) · 2.97 KB
/
rpc_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package p2p
import (
"context"
"net"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/rpc"
)
var NamespaceRPC = "opp2p"
type Client struct {
c *rpc.Client
}
var _ API = (*Client)(nil)
func NewClient(c *rpc.Client) *Client {
return &Client{c: c}
}
func prefixRPC(method string) string {
return NamespaceRPC + "_" + method
}
func (c *Client) Self(ctx context.Context) (*PeerInfo, error) {
var out *PeerInfo
err := c.c.CallContext(ctx, &out, prefixRPC("self"))
return out, err
}
func (c *Client) Peers(ctx context.Context, connected bool) (*PeerDump, error) {
var out *PeerDump
err := c.c.CallContext(ctx, &out, prefixRPC("peers"), connected)
return out, err
}
func (c *Client) PeerStats(ctx context.Context) (*PeerStats, error) {
var out *PeerStats
err := c.c.CallContext(ctx, &out, prefixRPC("peerStats"))
return out, err
}
func (c *Client) DiscoveryTable(ctx context.Context) ([]*enode.Node, error) {
var out []*enode.Node
err := c.c.CallContext(ctx, &out, prefixRPC("discoveryTable"))
return out, err
}
func (c *Client) BlockPeer(ctx context.Context, p peer.ID) error {
return c.c.CallContext(ctx, nil, prefixRPC("blockPeer"), p)
}
func (c *Client) UnblockPeer(ctx context.Context, p peer.ID) error {
return c.c.CallContext(ctx, nil, prefixRPC("unblockPeer"), p)
}
func (c *Client) ListBlockedPeers(ctx context.Context) ([]peer.ID, error) {
var out []peer.ID
err := c.c.CallContext(ctx, &out, prefixRPC("listBlockedPeers"))
return out, err
}
func (c *Client) BlockAddr(ctx context.Context, ip net.IP) error {
return c.c.CallContext(ctx, nil, prefixRPC("blockAddr"), ip)
}
func (c *Client) UnblockAddr(ctx context.Context, ip net.IP) error {
return c.c.CallContext(ctx, nil, prefixRPC("unblockAddr"), ip)
}
func (c *Client) ListBlockedAddrs(ctx context.Context) ([]net.IP, error) {
var out []net.IP
err := c.c.CallContext(ctx, &out, prefixRPC("listBlockedAddrs"))
return out, err
}
func (c *Client) BlockSubnet(ctx context.Context, ipnet *net.IPNet) error {
return c.c.CallContext(ctx, nil, prefixRPC("blockSubnet"), ipnet)
}
func (c *Client) UnblockSubnet(ctx context.Context, ipnet *net.IPNet) error {
return c.c.CallContext(ctx, nil, prefixRPC("unblockSubnet"), ipnet)
}
func (c *Client) ListBlockedSubnets(ctx context.Context) ([]*net.IPNet, error) {
var out []*net.IPNet
err := c.c.CallContext(ctx, &out, prefixRPC("listBlockedSubnets"))
return out, err
}
func (c *Client) ProtectPeer(ctx context.Context, p peer.ID) error {
return c.c.CallContext(ctx, nil, prefixRPC("protectPeer"), p)
}
func (c *Client) UnprotectPeer(ctx context.Context, p peer.ID) error {
return c.c.CallContext(ctx, nil, prefixRPC("unprotectPeer"), p)
}
func (c *Client) ConnectPeer(ctx context.Context, addr string) error {
return c.c.CallContext(ctx, nil, prefixRPC("connectPeer"), addr)
}
func (c *Client) DisconnectPeer(ctx context.Context, id peer.ID) error {
return c.c.CallContext(ctx, nil, prefixRPC("disconnectPeer"), id)
}