// Copyright The Kubernetes Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

// Retransmit?
// Sliding windows?

option go_package = "sigs.k8s.io/apiserver-network-proxy/konnectivity-client/proto/client";

service ProxyService {
  rpc Proxy(stream Packet) returns (stream Packet) {}
}

enum PacketType {
  DIAL_REQ = 0;
  DIAL_RSP = 1;
  CLOSE_REQ = 2;
  CLOSE_RSP = 3;
  DATA = 4;
  DIAL_CLS = 5;
}

enum Error {
  EOF = 0;
  // ...
}

message Packet {
  PacketType type = 1;

  oneof payload {
    DialRequest dialRequest = 2;
    DialResponse dialResponse = 3;
    Data data = 4;
    CloseRequest closeRequest = 5;
    CloseResponse closeResponse = 6;
    CloseDial closeDial = 7;
  }
}

message DialRequest {
    // tcp or udp?
    string protocol = 1;

    // node:port
    string address = 2;

    // random id for client, maybe should be longer
    int64 random = 3;
}

message DialResponse {
    // error failed reason; enum?
    string error = 1;

    // connectID indicates the identifier of the connection
    int64 connectID = 2;

    // random copied from DialRequest
    int64 random = 3;
}

message CloseRequest {
    // connectID of the stream to close
    int64 connectID = 1;
}

message CloseResponse {
    // error message
    string error = 1;

    // connectID indicates the identifier of the connection
    int64 connectID = 2;
}

message CloseDial {
    // random id of the DialRequest
    int64 random = 1;
}

message Data {
    // connectID to connect to
    int64 connectID = 1;

    // error message if error happens
    string error = 2;

    // stream data
    bytes data = 3;
}
