// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

syntax = "proto3";

package vault;

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "helper/forwarding/types.proto";

option go_package = "github.com/hashicorp/vault/vault";

message EchoRequest {
  string message = 1;
  // ClusterAddr is used to send up a standby node's address to the active
  // node upon heartbeat
  string cluster_addr = 2;
  // ClusterAddrs is used to send up a list of cluster addresses to a dr
  // primary from a dr secondary
  repeated string cluster_addrs = 3;

  uint64 raft_applied_index = 4;
  string raft_node_id = 5;
  NodeInformation node_info = 6;
  uint64 raft_term = 7;
  string raft_desired_suffrage = 8;
  string raft_upgrade_version = 9;
  string raft_redundancy_zone = 10;
  string sdk_version = 11;
  google.protobuf.Timestamp now = 12;
  // last_roundtrip_time is the time taken for the last echo request
  google.protobuf.Duration last_roundtrip_time = 13;
  // clock_skew_millis is the server time minus the local time
  int64 clock_skew_millis = 14;
  int64 replication_primary_canary_age_millis = 15;
}

message EchoReply {
  string message = 1;
  repeated string cluster_addrs = 2;
  uint32 replication_state = 3;
  uint64 raft_applied_index = 4;
  string raft_node_id = 5;
  NodeInformation node_info = 6;
  // now is the time on the server
  google.protobuf.Timestamp now = 7;
}

message NodeInformation {
  string cluster_addr = 1;
  string api_addr = 2;
  string mode = 3;
  string node_id = 4;
  uint32 replication_state = 5;
  string hostname = 6;
}

message ClientKey {
  string type = 1;
  bytes x = 2;
  bytes y = 3;
  bytes d = 4;
}

message PerfStandbyElectionInput {}
message PerfStandbyElectionResponse {
  string id = 1;
  string cluster_id = 2;
  string primary_cluster_addr = 3;
  bytes ca_cert = 4;
  bytes client_cert = 5;
  ClientKey client_key = 6;
}

service RequestForwarding {
  rpc ForwardRequest(forwarding.Request) returns (forwarding.Response) {}
  rpc Echo(EchoRequest) returns (EchoReply) {}
  rpc PerformanceStandbyElectionRequest(PerfStandbyElectionInput) returns (stream PerfStandbyElectionResponse) {}
}
