2 * Copyright 2011 Google Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 // Specification of protocol buffers and the client-server protocol that
18 // are used by the clients of the system.
20 // Note: unless otherwise specified in a comment, all fields in all messages
21 // are required, even though they are listed as optional.
25 package com.google.protos.ipc.invalidation;
27 option optimize_for = LITE_RUNTIME;
31 option java_outer_classname = "NanoClientProtocol";
32 option java_package = "com.google.protos.ipc.invalidation";
36 // Here is a high-level overview of the protocol. The protocol is designed in a
37 // "message-passing" style, i.e., the client (C) or the server (S) can send any
38 // message SPONTANEOUSLY at any time and both sides have to be prepared for any
39 // message from the other side. However, even with this style, there are some
40 // "flows" which are somewhat like requests and replies.
42 // 1. Initialization: When a client starts up, it needs a token to alow it to
43 // perform any other operation with the server.
44 // C -> S: InitializeMessage
45 // S -> C: TokenControlMessage
47 // 2. Registration: When a client has to register or unregister for a set of
48 // objects, the following flow occurs:
49 // C -> S: RegistrationMessage
50 // S -> C: RegistrationStatusMessage
52 // 3. Invalidation: The server sends an invalidation and the client sends back
54 // S -> C InvalidationMessage
55 // C -> S InvalidationMessage
57 // 4. Registration sync: Once in a while the server may detect that the client
58 // and server's registration state is out of sync (the server can detect this
59 // since it gets the client's registration summary in the client's message
60 // header). In that case, it asks the client some registration information
61 // and the client sends it to the server.
62 // S -> C: RegistrationSyncRequestMessage
63 // C -> S: RegistrationSyncMessage
65 // 5. Information messages: The server can occasionally for client-side
66 // information such as statistics, etc. The client responds with the
67 // requested information
68 // S -> C: InfoRequestMessage
69 // C -> S: InfoMessage
71 // Client protocol messages are typically validated. Validation rules may be
72 // declared in the following locations when making changes to this file:
74 // 1. TiclMessageValidator2.java: validation logic that is run on the
77 // 2. ClientProtoWrapperGenerator.java: validation logic that is run
79 // ------------------------------------------------------------------------
81 // A basic message type used for versioning public proto messages and/or
82 // types. The two fields are supposed to be used as follows:
84 // * The major version number is changed whenever an incompatible protocol
85 // change or type has been made. When a message/object with a particular
86 // major version is received, the receiver needs to either know how to handle
87 // this version or it needs to drop the message
89 // * The minor version can be changed (say) to document some internal change
90 // for debugging purposes. When a message is received by a receiver, it MUST
91 // ignore the minor version number for making any protocol/type
92 // decisions. I.e., the minor version number is for debugging purposes only.
94 // Versioning is used in various places - for entities that are part of a
95 // protocol (e.g., message requests), for various client implementations, and
96 // for other data types that change independently of the protocol (e.g.,
97 // session tokens). For each versioned entity, we define a specific message
98 // type to encapsulate the version of that entity (e.g., ProtocolVersion,
99 // ClientVersion, etc.).
101 optional int32 major_version = 1;
102 optional int32 minor_version = 2;
105 // Message included in all client <-> server messages to indicate the version
106 // of the protocol in use by the sender.
107 message ProtocolVersion {
108 optional Version version = 1;
111 // Defines a specific version of the client library (for information purposes
112 // only) May not be used to make decisions at the server (use ProtocolVersion
114 message ClientVersion {
116 // A client-specific version number.
117 optional Version version = 1;
119 // All fields below are for informational/debugging/monitoring purposes only.
120 // No critical code decision is supposed to be made using them.
122 // Optional: information about the client operating system/platform, e.g.,
123 // Windows, ChromeOS.
124 optional string platform = 2;
126 // Optional: language used for the library.
127 optional string language = 3;
129 // Optional: extra information about the client (e.g., application name).
130 optional string application_info = 4;
133 // Message indicating the result of an operation.
136 // Whether operation is successful or not
139 TRANSIENT_FAILURE = 2;
140 PERMANENT_FAILURE = 3;
143 optional Code code = 1;
145 // Textual description of the status or additional context about any
146 // error. (Optional - Can be set for success also.)
147 optional string description = 2;
150 // Identifies an object that a client can register for.
153 // The source of the data.
154 optional int32 source = 1;
156 // The id of the object relative to the source. Must be <= 64 bytes.
157 optional bytes name = 2;
160 // A message containing the part of the client's id that the application
161 // controls. This id is used for squelching invalidations on the server side.
162 // For example, if a client C1 modifies object x and informs the backend about
163 // C1's application client id as part of the invalidation. The backend can then
164 // avoid sending the invalidation unnecessarily to that client.
166 // If the application wishes to use this squelching feature, it must assign a
167 // globally unique client_name for a given client_type so that the particular
168 // instantation of the application can be identified.
169 message ApplicationClientIdP {
170 // The type of the client.
171 optional int32 client_type = 1;
173 // A client name or unique id assigned by the application. Application should
174 // choose a unique name for different client instances if it wants to squelch
175 // invalidations by name (as discussed above).
176 optional bytes client_name = 2;
179 // Invalidation for a given object/version.
180 message InvalidationP {
181 // The id of the object being invalidated.
182 optional ObjectIdP object_id = 1;
184 // Whether the invalidation is for a known version of the object as assigned
185 // by an application backend (is_known_version == true) or an unknown system
186 // version synthesized by the invalidation service. (Note that if
187 // is_known_version is false then is_trickle_restart be true or missing
188 // because an unknown version implies that invalidation versions prior to the
189 // current backend version may have been dropped.)
190 optional bool is_known_version = 2;
192 // Version being invalidated (see comment on is_known_version). If the
193 // is_known_version is false, the version corresponds to an internal "system
194 // version" for *that* object. An object's system version has no meaning to
195 // the application other than the fact that these system versions are also
196 // monotonically increasing and the client must ack such an invalidation with
197 // this system version (and an ack for a later system version acknowledges an
198 // invalidation for all earlier system version for *that* object.
199 optional int64 version = 3;
201 // Whether the object's Trickle is restarting at this version.
202 // sets this value to true to inform Trickle API clients that it may
203 // have dropped invalidations prior to "version", or, if is_known_version is
204 // false, prior to the current backend version. This field is logically
205 // required and is always set by current code. The default is true because
206 // old Android invalidation clients strip this field when acking
207 // invalidations due to ProtoLite limitations; true is the correct default
208 // because invalidation clients logically ack all current versions and
209 // because old persisted invalidations are all restarted.
210 optional bool is_trickle_restart = 6 [default = true];
212 // Optional payload associated with this invalidation.
213 optional bytes payload = 4;
216 // Specifies the intention to change a registration on a specific object. To
217 // update registrations, a client sends a message containing repeated
218 // RegistrationP messages.
219 message RegistrationP {
225 // The object for which to (un)register.
226 optional ObjectIdP object_id = 1;
228 // Whether to register or unregister.
229 optional OpType op_type = 2;
232 // Summary of the registration state associated with a particular client, sent
233 // in the header of client<->server messages. This summary has two different
234 // (but related) meanings depending on where it is used:
236 // 1) In a client->server message, it describes the DESIRED client state.
237 // 2) In a server->client message, it describes the ACTUAL state at the server
239 message RegistrationSummary {
240 // Number of registrations desired (client) or held (server).
241 optional int32 num_registrations = 1;
243 // Top-level digest over the registrations.
245 // The digest for an object id is computed as following (the digest chosen for
246 // this method is SHA-1):
248 // digest = new Digest();
249 // digest.update(Little endian encoding of object source type)
250 // digest.update(object name)
251 // digest.getDigestSummary()
253 // For a set of objects, digest is computing by sorting lexicographically
254 // based on their digests and then performing the update process given above
255 // (i.e., calling digest.update on each object's digest and then calling
256 // getDigestSummary at the end).
257 optional bytes registration_digest = 2;
260 // Header included on every client -> server message.
261 message ClientHeader {
263 // Protocol version of this message.
264 optional ProtocolVersion protocol_version = 1;
266 // Token identifying the client. Tokens are issued by the server in response
267 // to client requests (see InitializeMessage, below). In order to perform any
268 // operation other than initialization, the client must supply a token. When
269 // performing initialization, this field must be left unset.
270 optional bytes client_token = 2;
272 // Optional summary of the client's desired registration state. The client is
273 // encouraged to provide this summary in every message once a "steady" state
274 // of registrations/unregistrations has been reached. For example, it may not
275 // want to send this summary during initialization (but after the initial set
276 // has been registered, it should try to send it).
277 optional RegistrationSummary registration_summary = 3;
279 // Timestamp from the client's clock, expressed as ms since 00:00:00 UTC, 1
280 // January 1970 (i.e., the UNIX epoch) - for debugging/monitoring purposes.
281 optional int64 client_time_ms = 4;
283 // Highest server timestamp observed by the client (the server includes its
284 // time on every message to the client). Note: this time is NOT necessarily
285 // expressed as relative to the UNIX epoch - for debugging/monitoring
287 optional int64 max_known_server_time_ms = 5;
289 // Message id to identify the message -for debugging/monitoring purposes.
290 optional string message_id = 6;
292 // Client typecode (as in the InitializeMessage, below). This field may or
294 optional int32 client_type = 7;
297 // A message from the client to the server.
298 message ClientToServerMessage {
300 optional ClientHeader header = 1;
302 // Any or all of the follow messages may be present.
304 // Optional initialization message, used to obtain a new token. Note that, if
305 // present, this message is always processed before the messages below, and
306 // those messages will be interpreted relative to the new token assigned here.
307 optional InitializeMessage initialize_message = 2;
309 // Optional request to perform registrations.
310 optional RegistrationMessage registration_message = 3;
312 // Optional data for registration sync.
313 optional RegistrationSyncMessage registration_sync_message = 4;
315 // Optional invalidation acks.
316 optional InvalidationMessage invalidation_ack_message = 5;
318 // Optional information about the client.
319 optional InfoMessage info_message = 6;
322 // Used to obtain a new token when the client does not have one.
323 message InitializeMessage {
325 // Defines how clients serialize object ids when computing digests for
327 enum DigestSerializationType {
329 // The digest for an object id is computed by serializing the object id into
333 // The digest for an object id is computed by serializing the object id into
334 // an array of numbers. TODO: Determine and specify this
339 // Type of the client. This value is assigned by the backend notification
340 // system (out-of-band) and the client must use the correct value.
341 optional int32 client_type = 1;
343 // Nonce. This value will be echoed as the existing token in the header of
344 // the server message that supplies the new token (the new token itself will
345 // be provided in a TokenControlMessage; see below).
346 optional bytes nonce = 2;
348 // Id of the client as assigned by the application.
349 optional ApplicationClientIdP application_client_id = 3;
351 // Type of registration digest used by this client.
352 optional DigestSerializationType digest_serialization_type = 4;
355 // Registration operations to perform.
356 message RegistrationMessage {
357 repeated RegistrationP registration = 1;
360 // Message from the client to the server.
361 message RegistrationSyncMessage {
363 // Objects for which the client is registered.
364 repeated RegistrationSubtree subtree = 1;
367 // Message sent from the client to the server about registered objects
368 // (typically) in response to a registration sync request.
370 // The name of the message implies a "tree" for future expansion where the
371 // intention is to not necessarily send the complete set of objects but to
372 // partition the object space into multiple ranges and then exchange Merkle-tree
373 // like data structures to determine which ranges are out-of-sync.
374 message RegistrationSubtree {
375 // Registered objects
376 repeated ObjectIdP registered_object = 1;
379 // A message from the client to the server with info such as performance
380 // counters, client os info, etc.
381 message InfoMessage {
382 optional ClientVersion client_version = 1;
384 // Config parameters used by the client.
385 // Deprecated and removed - the client_config parameter is what is used now.
386 repeated PropertyRecord config_parameter = 2;
388 // Performance counters from the client.
389 repeated PropertyRecord performance_counter = 3;
391 // If 'true', indicates that the client does not know the server's
392 // registration summary, so the server should respond with it even if the
393 // client's summary matches the server's.
394 optional bool server_registration_summary_requested = 4;
396 // Configuration parameters for this client.
397 optional ClientConfigP client_config = 5;
400 // Information about a single config/performance counter value in the
402 message PropertyRecord {
404 // Name of the performance counter/config parameter.
405 optional string name = 1;
407 // Value of the performance counter/config parameter.
408 optional int32 value = 2;
411 message ServerHeader {
412 // Protocol version of this message.
413 optional ProtocolVersion protocol_version = 1;
415 // Current token that the server expects the client to have. Clients must
416 // ignore messages where this token field does not match their current token.
417 // During initialization, the client's "token" is the nonce that it generates
418 // and sends in the InitializeMessage.
419 optional bytes client_token = 2;
421 // Summary of registration state held by the server for the client.
422 optional RegistrationSummary registration_summary = 3;
424 // Timestamp from the server's clock. No guarantee on when this time is
426 optional int64 server_time_ms = 4;
428 // Message id to identify the message (for debug purposes only).
429 optional string message_id = 5;
432 // If ServerToClientMessage is modified, you need to change the type
433 // TestServerToClientMessageWithExtraFields in the same way to match.
434 message ServerToClientMessage {
435 optional ServerHeader header = 1;
437 // Message to assign a new client token or invalidate an existing one. Note
438 // that, if present, this message is always processed before the messages
439 // below, and those messages will be interpreted relative to the new token
441 optional TokenControlMessage token_control_message = 2;
444 optional InvalidationMessage invalidation_message = 3;
446 // Registration operation replies.
447 optional RegistrationStatusMessage registration_status_message = 4;
449 // Request for client registration state.
450 optional RegistrationSyncRequestMessage registration_sync_request_message = 5;
452 // Request to change config from the server.
453 optional ConfigChangeMessage config_change_message = 6;
455 // Request for client information.
456 optional InfoRequestMessage info_request_message = 7;
458 // Asynchronous error information that the server sends to the client.
459 optional ErrorMessage error_message = 8;
462 // Message used to supply a new client token or invalidate an existing one.
463 message TokenControlMessage {
464 // If status is failure, new_token cannot be set.
465 optional bytes new_token = 1; // If missing, means destroy_token
468 // Status of a particular registration (could be sent spontaneously by the
469 // server or in response to a registration request).
470 message RegistrationStatus {
471 optional RegistrationP registration = 1;
472 optional StatusP status = 2;
475 // Registration status of several messages from the server to the client.
476 message RegistrationStatusMessage {
477 repeated RegistrationStatus registration_status = 1;
480 // Request from the server to get the registration info from the client for
482 message RegistrationSyncRequestMessage {
485 // A set of invalidations from the client to the server or vice-versa
486 message InvalidationMessage {
487 repeated InvalidationP invalidation = 1;
490 // A request from the server to the client for information such as
491 // performance counters, client os, etc
492 message InfoRequestMessage {
494 GET_PERFORMANCE_COUNTERS = 1;
496 repeated InfoType info_type = 1;
499 // A rate limit: a count of events and a window duration in which the events
503 // The size of the window over which the rate limit applies.
504 optional int32 window_ms = 1;
506 // The number of events allowed within a given window.
507 optional int32 count = 2;
510 // Configuration parameters for the protocol handler in the Ticl.
511 message ProtocolHandlerConfigP {
512 // Batching delay - certain messages (e.g., registrations, invalidation acks)
513 // are sent to the server after this delay.
514 optional int32 batching_delay_ms = 1 [default = 500];
516 // Rate limits for sending messages. Only two levels allowed currently.
517 repeated RateLimitP rate_limit = 2;
520 // Configuration parameters for the Ticl.
521 message ClientConfigP {
523 optional Version version = 1;
525 // The delay after which a network message sent to the server is considered
527 optional int32 network_timeout_delay_ms = 2 [default = 60000];
529 // Retry delay for a persistent write if it fails
530 optional int32 write_retry_delay_ms = 3 [default = 10000];
532 // Delay for sending heartbeats to the server.
533 optional int32 heartbeat_interval_ms = 4 [default = 1200000];
535 // Delay after which performance counters are sent to the server.
536 optional int32 perf_counter_delay_ms = 5 [default = 21600000]; // 6 hours.
538 // The maximum exponential backoff factor used for network and persistence
540 optional int32 max_exponential_backoff_factor = 6 [default = 500];
542 // Smearing percent for randomizing delays.
543 optional int32 smear_percent = 7 [default = 20];
545 // Whether the client is transient, that is, does not write its session
546 // token to durable storage.
547 // TODO: need to expose to the clients.
548 optional bool is_transient = 8 [default = false];
550 // Initial delay for a heartbeat after restarting from persistent state. We
551 // use this so that the application has a chance to respond to the
552 // reissueRegistrations call.
553 optional int32 initial_persistent_heartbeat_delay_ms = 9 [default = 2000];
555 // Configuration for the protocol client to control batching etc.
556 optional ProtocolHandlerConfigP protocol_handler_config = 10;
558 // Whether the channel supports delivery while the client is offline. If
559 // true, then the servers' use of the channel is such that the
560 // following holds: if any number of messages are sent to the client while
561 // the client is unreachable, then the channel will eventually deliver at
562 // least one message to the client such that, on receiving the message, the
563 // client will send a message to the server. E.g., the channel could deliver
564 // a single invalidation or a single registration sync request. C2DM is
565 // an example of a suitable channel.
567 // When this is true, the Ticl will record in persistent storage the last
568 // time it sent a message to the server. On persistent restart, it will not
569 // send a message to the server unless the last one was sent more than a
570 // heartbeat-interval ago. This is designed to support efficient Android
571 // clients, which will destroy and recreate the Ticl when transitioning
572 // between foreground and background states.
573 optional bool channel_supports_offline_delivery = 11 [default = false];
575 // If the client loses network connectivity, it will send a heartbeat after it
576 // comes online, unless it had already sent a message more recently than this
578 optional int32 offline_heartbeat_threshold_ms = 12 [default = 60000];
580 // Whether the client allows suppression. If true (the default), then
581 // both continuous and restarted invalidations result in an invalidate()
582 // upcall, which is appropriate for invalidation clients. If false,
583 // then restarted invalidations result in an invalidateUnknownVersion()
584 // upcall, which provides correct semantics for Trickles clients.
585 optional bool allow_suppression = 13 [default = true];
588 // A message asking the client to change its configuration parameters
589 message ConfigChangeMessage {
591 // On receipt of this value, do not send any new message to the server
592 // for the specified delay (this message needs to be accepted without
593 // any token check). A zero value is ignored by the client. So the lowest
594 // value for this field is 1. This concept exists to allow the server
595 // to tell the clients that they should not come back to the server
596 // for some period of time.
597 optional int64 next_message_delay_ms = 1;
600 // An error message that contains an enum for different types of failures with a
601 // textual description of the failure (as the need arises new error codes will
602 // be added to this message).
603 message ErrorMessage {
606 AUTH_FAILURE = 1; // Authorization or authentication failure.
607 UNKNOWN_FAILURE = 10000; // Some failure which is not described above.
610 optional Code code = 1;
612 // Textual description of the error
613 optional string description = 2;