rpc: add disconnect peer service and req/res messages

Issue: 139

This commit contains rpc service and messages for disconnecting
remote peers identified dy public key
This commit is contained in:
afederigo authored and Olaoluwa Osuntokun committed 2017-05-05 14:24:25 -07:00
1 parent 533cd69c7b
commit cf4da784f0
5 files changed
+509 -329

No files matched your search

+2
View File
@@ -39,6 +39,8 @@ description):
nested-pay-to-witness-key-hash (np2wkh). nested-pay-to-witness-key-hash (np2wkh).
* ConnectPeer * ConnectPeer
* Connects to a peer identified by a public key and host. * Connects to a peer identified by a public key and host.
* DisconnectPeer
* Disconnects a peer identified by a public key.
* ListPeers * ListPeers
* Lists all available connected peers. * Lists all available connected peers.
* GetInfo * GetInfo
+384 -321
View File
File diff suppressed because it is too large. Load diff
+59
View File
@@ -97,6 +97,33 @@ func request_Lightning_ConnectPeer_0(ctx context.Context, marshaler runtime.Mars
} }
func request_Lightning_DisconnectPeer_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq DisconnectPeerRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["pub_key"]
if !ok {
return nil, metadata, grpc.Errorf(codes.InvalidArgument, "missing parameter %s", "pub_key")
}
protoReq.PubKey, err = runtime.String(val)
if err != nil {
return nil, metadata, err
}
msg, err := client.DisconnectPeer(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func request_Lightning_ListPeers_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { func request_Lightning_ListPeers_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ListPeersRequest var protoReq ListPeersRequest
var metadata runtime.ServerMetadata var metadata runtime.ServerMetadata
@@ -669,6 +696,34 @@ func RegisterLightningHandler(ctx context.Context, mux *runtime.ServeMux, conn *
}) })
mux.Handle("DELETE", pattern_Lightning_DisconnectPeer_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(ctx)
defer cancel()
if cn, ok := w.(http.CloseNotifier); ok {
go func(done <-chan struct{}, closed <-chan bool) {
select {
case <-done:
case <-closed:
cancel()
}
}(ctx.Done(), cn.CloseNotify())
}
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, req)
if err != nil {
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
}
resp, md, err := request_Lightning_DisconnectPeer_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, outboundMarshaler, w, req, err)
return
}
forward_Lightning_DisconnectPeer_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Lightning_ListPeers_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { mux.Handle("GET", pattern_Lightning_ListPeers_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
defer cancel() defer cancel()
@@ -1217,6 +1272,8 @@ var (
pattern_Lightning_ConnectPeer_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "peers"}, "")) pattern_Lightning_ConnectPeer_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "peers"}, ""))
pattern_Lightning_DisconnectPeer_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v1", "peers", "pub_key"}, ""))
pattern_Lightning_ListPeers_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "peers"}, "")) pattern_Lightning_ListPeers_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "peers"}, ""))
pattern_Lightning_GetInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getinfo"}, "")) pattern_Lightning_GetInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getinfo"}, ""))
@@ -1269,6 +1326,8 @@ var (
forward_Lightning_ConnectPeer_0 = runtime.ForwardResponseMessage forward_Lightning_ConnectPeer_0 = runtime.ForwardResponseMessage
forward_Lightning_DisconnectPeer_0 = runtime.ForwardResponseMessage
forward_Lightning_ListPeers_0 = runtime.ForwardResponseMessage forward_Lightning_ListPeers_0 = runtime.ForwardResponseMessage
forward_Lightning_GetInfo_0 = runtime.ForwardResponseMessage forward_Lightning_GetInfo_0 = runtime.ForwardResponseMessage
+29 -8
View File
@@ -44,6 +44,13 @@ service Lightning {
body: "*" body: "*"
}; };
} }
rpc DisconnectPeer (DisconnectPeerRequest) returns (DisconnectPeerResponse) {
option (google.api.http) = {
delete: "/v1/peers/{pub_key}"
};
}
rpc ListPeers (ListPeersRequest) returns (ListPeersResponse) { rpc ListPeers (ListPeersRequest) returns (ListPeersResponse) {
option (google.api.http) = { option (google.api.http) = {
get: "/v1/peers" get: "/v1/peers"
@@ -232,7 +239,8 @@ message NewAddressRequest {
} }
AddressType type = 1; AddressType type = 1;
} }
message NewWitnessAddressRequest {} message NewWitnessAddressRequest {
}
message NewAddressResponse { message NewAddressResponse {
string address = 1 [json_name = "address"]; string address = 1 [json_name = "address"];
} }
@@ -245,6 +253,12 @@ message ConnectPeerResponse {
int32 peer_id = 1 [json_name = "peer_id"]; int32 peer_id = 1 [json_name = "peer_id"];
} }
message DisconnectPeerRequest {
string pub_key = 1 [json_name = "pub_key"];
}
message DisconnectPeerResponse {
}
message HTLC { message HTLC {
bool incoming = 1 [json_name = "incoming"]; bool incoming = 1 [json_name = "incoming"];
int64 amount = 2 [json_name = "amount"]; int64 amount = 2 [json_name = "amount"];
@@ -271,7 +285,8 @@ message ActiveChannel {
repeated HTLC pending_htlcs = 12 [json_name = "pending_htlcs"]; repeated HTLC pending_htlcs = 12 [json_name = "pending_htlcs"];
} }
message ListChannelsRequest {} message ListChannelsRequest {
}
message ListChannelsResponse { message ListChannelsResponse {
repeated ActiveChannel channels = 11 [json_name = "channels"]; repeated ActiveChannel channels = 11 [json_name = "channels"];
} }
@@ -292,12 +307,14 @@ message Peer {
int64 ping_time = 9 [json_name = "ping_time"]; int64 ping_time = 9 [json_name = "ping_time"];
} }
message ListPeersRequest {} message ListPeersRequest {
}
message ListPeersResponse { message ListPeersResponse {
repeated Peer peers = 1 [json_name = "peers"]; repeated Peer peers = 1 [json_name = "peers"];
} }
message GetInfoRequest{} message GetInfoRequest {
}
message GetInfoResponse { message GetInfoResponse {
string identity_pubkey = 1 [json_name = "identity_pubkey"]; string identity_pubkey = 1 [json_name = "identity_pubkey"];
string alias = 2 [json_name = "alias"]; string alias = 2 [json_name = "alias"];
@@ -493,7 +510,8 @@ message ChannelEdge {
RoutingPolicy node2_policy = 8 [json_name = "node2_policy"]; RoutingPolicy node2_policy = 8 [json_name = "node2_policy"];
} }
message ChannelGraphRequest{} message ChannelGraphRequest {
}
message ChannelGraph { message ChannelGraph {
repeated LightningNode nodes = 1 [json_name = "nodes"]; repeated LightningNode nodes = 1 [json_name = "nodes"];
@@ -504,7 +522,8 @@ message ChanInfoRequest {
uint64 chan_id = 1; uint64 chan_id = 1;
} }
message NetworkInfoRequest{} message NetworkInfoRequest {
}
message NetworkInfo { message NetworkInfo {
uint32 graph_diameter = 1 [json_name = "graph_diameter"]; uint32 graph_diameter = 1 [json_name = "graph_diameter"];
double avg_out_degree = 2 [json_name = "avg_out_degree"]; double avg_out_degree = 2 [json_name = "avg_out_degree"];
@@ -557,7 +576,8 @@ message ClosedChannelUpdate {
message SetAliasRequest { message SetAliasRequest {
string new_alias = 1; string new_alias = 1;
} }
message SetAliasResponse{} message SetAliasResponse {
}
message Invoice { message Invoice {
string memo = 1 [json_name = "memo"]; string memo = 1 [json_name = "memo"];
@@ -591,7 +611,8 @@ message ListInvoiceResponse {
repeated Invoice invoices = 1 [json_name = "invoices"]; repeated Invoice invoices = 1 [json_name = "invoices"];
} }
message InvoiceSubscription {} message InvoiceSubscription {
}
message Payment { message Payment {
+35
View File
@@ -514,6 +514,30 @@
] ]
} }
}, },
"/v1/peers/{pub_key}": {
"delete": {
"operationId": "DisconnectPeer",
"responses": {
"200": {
"description": "",
"schema": {
"$ref": "#/definitions/lnrpcDisconnectPeerResponse"
}
}
},
"parameters": [
{
"name": "pub_key",
"in": "path",
"required": true,
"type": "string"
}
],
"tags": [
"Lightning"
]
}
},
"/v1/transactions": { "/v1/transactions": {
"get": { "get": {
"operationId": "GetTransactions", "operationId": "GetTransactions",
@@ -953,6 +977,17 @@
"lnrpcDeleteAllPaymentsResponse": { "lnrpcDeleteAllPaymentsResponse": {
"type": "object" "type": "object"
}, },
"lnrpcDisconnectPeerRequest": {
"type": "object",
"properties": {
"pub_key": {
"type": "string"
}
}
},
"lnrpcDisconnectPeerResponse": {
"type": "object"
},
"lnrpcGetInfoRequest": { "lnrpcGetInfoRequest": {
"type": "object" "type": "object"
}, },