|
| 1 | +package rpc |
| 2 | + |
| 3 | +type Net struct { |
| 4 | +rpcClient rpcClient |
| 5 | +} |
| 6 | + |
| 7 | +func (n *Net) LocalKeyFor(address string, port int) (string, error) { |
| 8 | +const method = "net_localKeyFor" |
| 9 | +var result string |
| 10 | +err := n.rpcClient.call(callInterface{method: method, id: ""}, &result, address, port) |
| 11 | +return result, err |
| 12 | +} |
| 13 | + |
| 14 | +func (n *Net) RegisterRemoteKeyFor(address string, port int, remotePublicKey string) (string, error) { |
| 15 | +const method = "net_registerRemoteKeyFor" |
| 16 | +var result string |
| 17 | +err := n.rpcClient.call(callInterface{method: method, id: ""}, &result, address, port, remotePublicKey) |
| 18 | +return result, err |
| 19 | +} |
| 20 | + |
| 21 | +func (n *Net) Connect(address string, port int) error { |
| 22 | +const method = "net_connect" |
| 23 | +return n.rpcClient.call(callInterface{method: method, id: ""}, nil, address, port) |
| 24 | +} |
| 25 | + |
| 26 | +func (n *Net) IsConnected(address string, port int) (bool, error) { |
| 27 | +const method = "net_isConnected" |
| 28 | +var result bool |
| 29 | +err := n.rpcClient.call(callInterface{method: method, id: ""}, &result, address, port) |
| 30 | +return result, err |
| 31 | +} |
| 32 | + |
| 33 | +func (n *Net) Disconnect(address string, port int) error { |
| 34 | +const method = "net_disconnect" |
| 35 | +return n.rpcClient.call(callInterface{method: method, id: ""}, nil, address, port) |
| 36 | +} |
| 37 | + |
| 38 | +func (n *Net) GetPeerCount() (int, error) { |
| 39 | +const method = "net_getPeerCount" |
| 40 | +var result int |
| 41 | +err := n.rpcClient.call(callInterface{method: method, id: ""}, &result) |
| 42 | +return result, err |
| 43 | +} |
| 44 | + |
| 45 | +func (n *Net) GetEstablishedPeers() ([]string, error) { |
| 46 | +const method = "net_getEstablishedPeers" |
| 47 | +var result []string |
| 48 | +err := n.rpcClient.call(callInterface{method: method, id: ""}, &result) |
| 49 | +return result, err |
| 50 | +} |
| 51 | + |
| 52 | +func (n *Net) GetPort() (int, error) { |
| 53 | +const method = "net_getPort" |
| 54 | +var port int |
| 55 | +err := n.rpcClient.call(callInterface{method: method, id: ""}, &port) |
| 56 | +return port, err |
| 57 | +} |
| 58 | + |
| 59 | +func (n *Net) AddToWhitelist(address string, tag string) error { |
| 60 | +const method = "net_addToWhitelist" |
| 61 | +return n.rpcClient.call(callInterface{method: method, id: ""}, nil, address, tag) |
| 62 | +} |
| 63 | + |
| 64 | +func (n *Net) RemoveFromWhitelist(address string) error { |
| 65 | +const method = "net_removeFromWhitelist" |
| 66 | +return n.rpcClient.call(callInterface{method: method, id: ""}, nil, address) |
| 67 | +} |
| 68 | + |
| 69 | +func (n *Net) AddToBlacklist(address string, tag string) error { |
| 70 | +const method = "net_addToBlacklist" |
| 71 | +return n.rpcClient.call(callInterface{method: method, id: ""}, nil, address, tag) |
| 72 | +} |
| 73 | + |
| 74 | +func (n *Net) RemoveFromBlacklist(address string) error { |
| 75 | +const method = "net_removeFromBlacklist" |
| 76 | +return n.rpcClient.call(callInterface{method: method, id: ""}, nil, address) |
| 77 | +} |
| 78 | + |
| 79 | +func (n *Net) EnableWhitelist() error { |
| 80 | +const method = "net_enableWhitelist" |
| 81 | +return n.rpcClient.call(callInterface{method: method, id: ""}, nil) |
| 82 | +} |
| 83 | + |
| 84 | +func (n *Net) DisableWhitelist() error { |
| 85 | +const method = "net_disableWhitelist" |
| 86 | +return n.rpcClient.call(callInterface{method: method, id: ""}, nil) |
| 87 | +} |
| 88 | + |
| 89 | +func (n *Net) EnableBlacklist() error { |
| 90 | +const method = "net_enableBlacklist" |
| 91 | +return n.rpcClient.call(callInterface{method: method, id: ""}, nil) |
| 92 | +} |
| 93 | + |
| 94 | +func (n *Net) DisableBlacklist() error { |
| 95 | +const method = "net_disableBlacklist" |
| 96 | +return n.rpcClient.call(callInterface{method: method, id: ""}, nil) |
| 97 | +} |
| 98 | + |
| 99 | +func (n *Net) GetWhitelist() (interface{}, error) { |
| 100 | +const method = "net_getWhitelist" |
| 101 | +var reusult interface{} |
| 102 | +err := n.rpcClient.call(callInterface{method: method, id: ""}, &reusult) |
| 103 | +return reusult, err |
| 104 | +} |
| 105 | + |
| 106 | +func (n *Net) GetBlacklist() (interface{}, error) { |
| 107 | +const method = "net_getBlacklist" |
| 108 | +var reusult interface{} |
| 109 | +err := n.rpcClient.call(callInterface{method: method, id: ""}, &reusult) |
| 110 | +return reusult, err |
| 111 | +} |
| 112 | + |
| 113 | +func (n *Net) RecentNetworkUsage() (interface{}, error) { |
| 114 | +const method = "net_recentNetworkUsage" |
| 115 | +var reusult interface{} |
| 116 | +err := n.rpcClient.call(callInterface{method: method, id: ""}, &reusult) |
| 117 | +return reusult, err |
| 118 | +} |
0 commit comments