Gateway related protos

git-svn-id: http://google-cache-invalidation-api.googlecode.com/svn/trunk@239 1cc9d426-c294-39be-ba72-c0199ca0f247
diff --git a/src/google/cacheinvalidation/channel.proto b/src/google/cacheinvalidation/channel.proto
new file mode 100644
index 0000000..2ceb287
--- /dev/null
+++ b/src/google/cacheinvalidation/channel.proto
@@ -0,0 +1,71 @@
+// Copyright 2011 Google Inc.
+//
+// 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.
+
+// Specification of the messages between registrar and gateway.
+
+syntax = "proto2";
+
+package ipc.invalidation;
+
+option optimize_for = LITE_RUNTIME;
+
+import "channel_common.proto";
+
+message NetworkEndpointId {
+  enum NetworkAddress {
+    TEST = 1;  // A delivery service for testing
+
+    // Low numbers reserved.
+    BUZZ = 111;  // Buzz delivery service.
+    STUBBY = 112;  // Delivery service using direct Stubby calls.
+    ANDROID = 113;  // Android delivery service using c2dm / http.
+  }
+  optional NetworkAddress network_address = 1;
+  optional bytes client_address = 2;
+}
+
+// Message sent from the client to the server and vice-versa via the
+// delivery service.
+message AddressedMessage {
+  // The encoding type for the network_message field.
+  optional ChannelMessageEncoding.MessageEncoding encoding = 1;
+
+  // Authenticated user identifier.
+  optional bytes auth_user_id = 2;
+
+  // Network id for the client
+  optional NetworkEndpointId client_network_id = 3;
+
+  // ClientToServerMessage or ServerToClientMessage.
+  optional bytes network_message = 4;
+
+  // (For debugging) Caller's info, e.g., task address
+  optional string caller_info = 5;
+}
+
+// Response to AddressedMessage
+message AddressedMessageResponse {
+}
+
+// Message batched from the client to the server and vice-versa via the
+// delivery service.
+message AddressedMessageBatch {
+  repeated AddressedMessage requests = 1;
+}
+
+// Responses to AddressedMessageBatch, containing batched responses to
+// each of AddressedMessage
+message AddressedMessageBatchResponse {
+  repeated AddressedMessageResponse responses = 1;
+}
diff --git a/src/google/cacheinvalidation/channel_common.proto b/src/google/cacheinvalidation/channel_common.proto
new file mode 100644
index 0000000..638faf4
--- /dev/null
+++ b/src/google/cacheinvalidation/channel_common.proto
@@ -0,0 +1,32 @@
+// Copyright 2011 Google Inc.
+//
+// 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.
+
+// Common utilities used by all channel related protos.
+// This is also publicly visible to all channel implementors.
+
+syntax = "proto2";
+
+package ipc.invalidation;
+
+option optimize_for = LITE_RUNTIME;
+
+message ChannelMessageEncoding {
+    // What kind of encoding is used for network_message
+  enum MessageEncoding {
+    // Raw proto encoding
+    PROTOBUF_BINARY_FORMAT = 1;
+
+    PROTOBUF_JSON_FORMAT = 2;
+  }
+}
diff --git a/src/google/cacheinvalidation/client_gateway.proto b/src/google/cacheinvalidation/client_gateway.proto
index 5b12452..b99b083 100644
--- a/src/google/cacheinvalidation/client_gateway.proto
+++ b/src/google/cacheinvalidation/client_gateway.proto
@@ -12,8 +12,7 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// Specification of invalidation gateway internal forwarding messages and
-// services.
+// Specification of message types between clients and channel gateways.
 
 syntax = "proto2";
 
@@ -21,8 +20,32 @@
 
 package ipc.invalidation;
 
-// The message communicated between gateway and clients.
+import "channel.proto";
+import "channel_common.proto";
+import "client_protocol.proto";
+
+// The message communicated between gateway and clients. Note that
+// RegistrarGatewayMessage is between and inside gateways and registrars,
+// and ClientGatewayMessage is between gateways and clients.
+// The message contains:
+// 1) protocol version: version of the protocol between clients and gateways.
+// 2) The message type: whether it wraps ServerToClientMessage, or
+//    ClientToServiceMessage or DisconnectRequest message.
+// 3) encoding: the encoding type of the message: raw protobuf or json.
+// 4) client network endpoint id. Stubby and Android clients are expected to
+//    set this field, and Buzz clients do not set this field.
+// 5) service endpoint id. It is the routing info the clients can provide to
+//    gateway servers. Typically, it is a serialization of instance spec
+//    of the targeted server instance.
+// 6) network_message is the payload, either C2SMsg or S2CMsg or
+//    DisconnectRequest
+// 7) debug_info: some extra text for debug purpose.
+// Note that for backward compatibility, ClientGatewayMessage also tentatively
+// contains three old fields that are not used for now: is_client_to_server,
+// service_context and rpc_scheduling_hash.
 message ClientGatewayMessage {
+  // The following fields are for backward compatibility
+
   // Whether it is client to server or server to client.
   optional bool is_client_to_server = 1;
 
@@ -32,7 +55,35 @@
   // Rpc scheduling hash.
   optional int64 rpc_scheduling_hash = 3;
 
-  // Payload of the network message (ClientToServerMessage or
-  // ServerToClientMessage).
+  // The following fields are the new-format message.
+
+  // Version of the protocol between clients and gateways
+  optional ProtocolVersion protocol_version = 5;
+
+  // ClientGatewayMessage could wrap three types of messages as its payload.
+  enum MessageType {
+    CLIENT_TO_SERVER = 1; // a ClientToServerMessage.
+    SERVER_TO_CLIENT = 2; // a ServerToClientMessage.
+    DISCONNECT = 3;       // a DisconnectRequest message.
+  }
+
+  // Type of the wrapped network_message.
+  optional MessageType message_type = 6;
+
+  // The encoding type of the message.
+  optional ChannelMessageEncoding.MessageEncoding encoding = 7;
+
+  // The client network endpoint id.
+  optional NetworkEndpointId client_endpoint_id = 8;
+
+  // The service endpoint end for the targeted server instance.
+  optional bytes service_endpoint_id = 9;
+
+  // Payload of the network message (ClientToServerMessage
+  // or ServerToClientMessage or DisconnectRequest)
+  // Keep the field number = 4 for backward compatibility.
   optional bytes network_message = 4;
+
+  // debug information for the message. Ex: sequence number.
+  optional string debug_info = 10;
 }