/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with this
 * work for additional information regarding copyright ownership.  The ASF
 * licenses this file to you 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.
 *
 */

/**
 * These .proto interfaces are private and unstable.
 * Please see http://wiki.apache.org/hadoop/Compatibility
 * for what changes are allowed for a *unstable* .proto interface.
 */
syntax = "proto2";
option java_package = "org.apache.hadoop.hdds.protocol.scm.proto";
option java_outer_classname = "SCMUpdateServiceProtos";
option java_generate_equals_and_hash = true;
option java_generic_services = true;
package hadoop.hdds.scm;

/**
 * Information for Certificate Revocation List.
 */
message CRLInfoProto {
  required string x509CRL = 1;
  required uint64 creationTimestamp = 2;
  required int64 crlSequenceID = 3;
}
message ClientId {
  required int64 msb = 1;
  required int64 lsb = 2;
}

message SubscribeRequest {
  optional string hostname = 1;
}

message SubscribeResponse {
  required ClientId clientId = 1;
}

enum Type {
  CRLUpdate = 1;
  PipelineUpdate = 2;
 }

message UpdateRequest {
  required Type updateType = 1; // Type of the update
  optional string traceID = 2;
  required ClientId clientId = 3;
  optional CRLUpdateRequest crlUpdateRequest= 4;
}

message UpdateResponse {
  required Type updateType = 1; // Type of the update
  optional string traceID = 2;
  optional CRLUpdateResponse crlUpdateResponse = 3;
}

message CRLUpdateRequest {
  required int64 receivedCrlId = 1;
  repeated int64 pendingCrlIds = 2;
}

message CRLUpdateResponse {
  optional CRLInfoProto crlInfo = 1;
}

message UnsubscribeRequest {
  required ClientId clientId = 1;
}

message UnsubscribeResponse {
}

// SCM Update service streams updates to all subscribers
service SCMUpdateService {

  // Client subscribe to future SCM CRL update
  rpc subscribe (SubscribeRequest) returns (SubscribeResponse) {};

  // Client update SCM about its CRL processing status
  rpc updateStatus (stream UpdateRequest) returns (stream UpdateResponse) {};

  // Client unsubscribe to future SCM CRL update
  rpc unsubscribe (UnsubscribeRequest) returns (UnsubscribeResponse) {};

}