From 495ddf064128cb39537e7080713bbe007d6dca61 Mon Sep 17 00:00:00 2001 From: Yongkun Gui Date: Fri, 22 Mar 2019 17:22:04 -0700 Subject: [PATCH] gRPC Change --- .../20190226-network-proxy.md | 103 +++--------------- 1 file changed, 15 insertions(+), 88 deletions(-) diff --git a/keps/sig-api-machinery/20190226-network-proxy.md b/keps/sig-api-machinery/20190226-network-proxy.md index 39ca2695832..dd86615095c 100644 --- a/keps/sig-api-machinery/20190226-network-proxy.md +++ b/keps/sig-api-machinery/20190226-network-proxy.md @@ -241,102 +241,29 @@ or which user/tenant tries to initiate the request, etc. ### Proxy gRPC definition +In order to serve a proxy request, one gRPC bidirectional stream on proxy +server is created to serve it. It's a 1:1 mapping from TCP connection to a +gRPC stream, so the state of TCP connection is exactly the same as the gRPC +stream state. + ```grpc syntax = "proto3"; service ProxyService { - // Proxy connects to a remote address by stream id, and establish - // a bi-directional stream of packet exchange. - rpc Proxy(stream Packet) returns (stream Packet) {} -} - -enum PacketType { - DIAL_REQ = 0; - DIAL_RSP = 1; - CLOSE_REQ = 2; - CLOSE_RSP = 3; - DATA = 4; -} - -message Packet { - PacketType type = 1; - - oneof payload { - DialRequest dialRequest = 2; - DialResponse dialResponse = 3; - CloseRequest closeRequest = 4; - CloseResponse closeResponse = 5; - Data data = 6; - } -} - -// Error is sent when error happens from remote side of connection when it tries -// to read or write from it -enum Error { - EOF = 0; - EIO = 1; - ECONNRESET = 2; - ETIMEOUT = 3; - EADDRNOTAVAIL = 4; - EMFILE = 5; - // … + // Proxy a TCP connection to a remote address defined by ConnectParam. + // The ConnectParam is defined in metadata under key "x-kube-net-proxy". + // metadata["x-kube-net-proxy"] = base64.Encode(proto.Marshal(connectOptions)) + rpc Proxy(stream Payload) returns (stream Payload) {} } -// DialRequest represents a request to dial to an address on the other -// side of the tunnel. The format is inspired by golang's net interface -// https://golang.org/pkg/net/#Dial -message DialRequest { - // network representing a named network. "Tcp" is the only supported - // value - string network = 1; - - // For TCP network, the address has the form "ip:port", where host must - // be IP address. - string address = 2; - - // random is the randomly generated bytes that represents a given dial request. - // the number is kept unchanged across the proxies, and copied to DialResponse - // from the other side of the tunnel. The number cannot be reused across - // different DialRequests. - bytes random = 3; +// ConnectOptions defines the remote TCP endpoint to connect +message ConnectOptions { + string remote_addr = 1; // remote address to connect to. e.g. 8.8.8.8:53 } -// DialResponse is the response to a DialRequest. -message DialResponse { - // Error when the dial request cannot be fulfilled. - Error error = 1; - - // connectID represents a unique connect ID for the connection/stream. - int64 connectID = 2; - - // Copied from DialRequest. Explained also in DialRequest. - bytes random = 3; -} - -// CloseRequest requests to close a connection -message CloseRequest { - // connection id to close. - int64 connectID = 1; -} - -// CloseResponse is the response to a close connection request. -message CloseResponse { - // connection id to close. - int64 connectionID = 1; - - // Error when close request cannot be fulfilled. - Error error = 2; -} - -message Data { - // connectID that data or error payload is belonged to - int32 connectID = 1; - - // data payload - bytes data = 2; - - // Error that happens to the connection. - Error error = 3; +// Payload defines a TCP payload. +message Payload { + bytes data = 1; } ```