syntax = "proto3";
package defguard.client.v1;

import "google/protobuf/empty.proto";

message InterfaceConfig {
  string name = 1;
  string prvkey = 2;
  string address = 3;
  uint32 port = 4;
  repeated Peer peers = 5;
  optional uint32 mtu = 6;
}

message Peer {
  string public_key = 1;
  optional string preshared_key = 2;
  optional uint32 protocol_version = 3;
  optional string endpoint = 4;
  optional uint64 last_handshake = 5;
  uint64 tx_bytes = 6;
  uint64 rx_bytes = 7;
  optional uint32 persistent_keepalive_interval = 8;
  repeated string allowed_ips = 9;
}

message CreateInterfaceRequest {
  InterfaceConfig config = 1;
  optional string dns = 3;
}

message RemoveInterfaceRequest {
  string interface_name = 2;
  string endpoint = 6;
}

message ReadInterfaceDataRequest {
  string interface_name = 2;
}

message InterfaceData {
  uint32 listen_port = 1;
  repeated Peer peers = 2;
}

enum ServiceLocationMode {
  PRE_LOGON = 0;
  ALWAYS_ON = 1;
}

message ServiceLocation {
  string name = 1;
  string address = 2;
  string pubkey = 3;
  string endpoint = 4;
  string allowed_ips = 5;
  uint32 keepalive_interval = 6;
  string dns = 7;
  ServiceLocationMode mode = 8;
}

message SaveServiceLocationsRequest {
  repeated ServiceLocation service_locations = 1;
  string instance_id = 2;
  string private_key = 3;
}

message DeleteServiceLocationsRequest {
  string instance_id = 1;
}

message StopServiceLocationRequest {
  string instance_id = 1;
  string pubkey = 2;
}

// service used by desktop clients to communicate with interface management
// daemon
service DesktopDaemonService {
  rpc CreateInterface(CreateInterfaceRequest) returns (google.protobuf.Empty);
  rpc RemoveInterface(RemoveInterfaceRequest) returns (google.protobuf.Empty);
  rpc ReadInterfaceData(ReadInterfaceDataRequest) returns (stream InterfaceData);
  rpc SaveServiceLocations(SaveServiceLocationsRequest) returns (google.protobuf.Empty);
  rpc DeleteServiceLocations(DeleteServiceLocationsRequest) returns (google.protobuf.Empty);
}
