syntax = "proto3";

package io.stellarproject.heimdall.api.v1;

import "gogoproto/gogo.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/stellarproject/heimdall/api/v1;v1";

service Heimdall {
        rpc Connect(ConnectRequest) returns (ConnectResponse);
        rpc AuthorizePeer(AuthorizePeerRequest) returns (google.protobuf.Empty);
        rpc DeauthorizePeer(DeauthorizePeerRequest) returns (google.protobuf.Empty);
        rpc AuthorizedPeers(AuthorizedPeersRequest) returns (AuthorizedPeersResponse);
        rpc Join(JoinRequest) returns (JoinResponse);
        rpc Routes(RoutesRequest) returns (RoutesResponse);
        rpc CreateRoute(CreateRouteRequest) returns (google.protobuf.Empty);
        rpc DeleteRoute(DeleteRouteRequest) returns (google.protobuf.Empty);
        rpc Nodes(NodesRequest) returns (NodesResponse);
        rpc Peers(PeersRequest) returns (PeersResponse);
}

message Master {
        string id = 1 [(gogoproto.customname) = "ID"];
        string grpc_address = 2 [(gogoproto.customname) = "GRPCAddress"];
        string redis_url = 3 [(gogoproto.customname) = "RedisURL"];
        string gateway_ip = 4 [(gogoproto.customname) = "GatewayIP"];
        repeated Peer peers = 5;
}

message JoinRequest {
        string id = 1 [(gogoproto.customname) = "ID"];
        string cluster_key = 2;
        string grpc_address = 3 [(gogoproto.customname) = "GRPCAddress"];
        string endpoint_ip = 4 [(gogoproto.customname) = "EndpointIP"];
        uint64 endpoint_port = 5;
        string interface_name = 6;
}

message JoinResponse {
        Master master = 1;
        Node node = 2;
        repeated Peer peers = 3;
}

message ConnectRequest {
        string id = 1 [(gogoproto.customname) = "ID"];
}

message ConnectResponse {
        KeyPair keypair = 1 [(gogoproto.customname) = "KeyPair"];
        string address = 2;
        repeated Peer peers = 3;
        repeated string dns = 4 [(gogoproto.customname) = "DNS"];
}

message AuthorizePeerRequest {
        string id = 1 [(gogoproto.customname) = "ID"];
}

message DeauthorizePeerRequest {
        string id = 1 [(gogoproto.customname) = "ID"];
}

message AuthorizedPeersRequest {}

message AuthorizedPeersResponse {
        repeated string ids = 1 [(gogoproto.customname) = "IDs"];
}

message KeyPair {
        string private_key = 1;
        string public_key = 2;
}

message Node {
        string id = 1 [(gogoproto.customname) = "ID"];
        string addr = 2;
        KeyPair keypair = 3 [(gogoproto.customname) = "KeyPair"];
        string endpoint_ip = 4 [(gogoproto.customname) = "EndpointIP"];
        uint64 endpoint_port = 5;
        string gateway_ip = 6 [(gogoproto.customname) = "GatewayIP"];
        google.protobuf.Timestamp updated = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
        string interface_name = 8;
}

message NodesRequest {}

message NodesResponse {
        repeated Node nodes = 1;
}

message Peer {
        string id = 1 [(gogoproto.customname) = "ID"];
        KeyPair keypair = 2 [(gogoproto.customname) = "KeyPair"];
        repeated string allowed_ips = 3 [(gogoproto.customname) = "AllowedIPs"];
        string endpoint = 4;
}

message PeersRequest {}

message PeersResponse {
        repeated Peer peers = 1;
}

message Route {
        string node_id = 1 [(gogoproto.customname) = "NodeID"];
        string network = 2;
}

message CreateRouteRequest {
        string node_id = 1 [(gogoproto.customname) = "NodeID"];
        string network = 2;
}

message DeleteRouteRequest {
        string network = 1;
}

message RoutesRequest {}

message RoutesResponse {
        repeated Route routes = 1;
}
