diff --git a/internal/proto/BUILD b/internal/proto/BUILD index e765eec7..dfa6642f 100644 --- a/internal/proto/BUILD +++ b/internal/proto/BUILD @@ -42,3 +42,22 @@ cc_proto_library( ], deps = [":metadata_proto"], ) + +proto_library( + name = "tachyon_proto", + srcs = [ + "duration.proto", + "ice.proto", + "tachyon.proto", + "tachyon_common.proto", + "tachyon_enums.proto", + ], + compatible_with = ["//buildenv/target:non_prod"], +) + +cc_proto_library( + name = "tachyon_cc_proto", + compatible_with = ["//buildenv/target:non_prod"], + visibility = ["//visibility:public"], + deps = [":tachyon_proto"], +) diff --git a/internal/proto/duration.proto b/internal/proto/duration.proto new file mode 100644 index 00000000..ab1d6b5c --- /dev/null +++ b/internal/proto/duration.proto @@ -0,0 +1,24 @@ +// Copyright 2021 Google LLC +// +// 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 +// +// https://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. + +syntax = "proto3"; + +package nearby.internal.tachyon_proto; + +option optimize_for = LITE_RUNTIME; + +message Duration { + int64 seconds = 1; + int32 nanos = 2; +} diff --git a/internal/proto/ice.proto b/internal/proto/ice.proto new file mode 100644 index 00000000..954d7e43 --- /dev/null +++ b/internal/proto/ice.proto @@ -0,0 +1,46 @@ +// Copyright 2021 Google LLC +// +// 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 +// +// https://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. + +syntax = "proto3"; + +package nearby.internal.tachyon_proto; + +import "internal/proto/duration.proto"; + +option optimize_for = LITE_RUNTIME; + +message ICEConfiguration { + // Duration the config is valid for. + Duration lifetime_duration = 1; + + // ICE servers to be used by the client to establish a connection. + // E.g.: + // [ { "urls": "stun:stun1.example.net" }, { "urls": "turn:turn.example.org", + // "username": "user", "credential": "myPassword" } ] + repeated ICEServerList ice_servers = 2; +} + +message ICEServerList { + // STUN or TURN URI(s) as defined in [rfc7064] and [rfc7065] or other URI + // types. + repeated string urls = 1; + + // If this IceServer object represents a TURN server, then this attribute + // specifies the credential to use with that TURN server. + string username = 2; + + // If this IceServer object represents a TURN server, then this attribute + // specifies the credential to use with that TURN server. + string credential = 3; +} diff --git a/internal/proto/tachyon.proto b/internal/proto/tachyon.proto new file mode 100644 index 00000000..42427e6a --- /dev/null +++ b/internal/proto/tachyon.proto @@ -0,0 +1,55 @@ +// Copyright 2021 Google LLC +// +// 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 +// +// https://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. + +syntax = "proto3"; + +package nearby.internal.tachyon_proto; + +import "internal/proto/ice.proto"; +import "internal/proto/tachyon_common.proto"; + +option optimize_for = LITE_RUNTIME; + +message GetICEServerRequest { + // header is the request header + RequestHeader header = 1; + // ICE config preference. + string ice_config_preference = 3; +} + +message GetICEServerResponse { + // The ice server configuration to use. + ICEConfiguration ice_config = 4; +} + +message SendMessageExpressRequest { + RequestHeader header = 1; + Id dest_id = 3; + InboxMessage message = 4; +} + +message ReceiveMessagesExpressRequest { + RequestHeader header = 1; +} + +message ReceiveMessagesResponse { + message Header {} + Header header = 1; + message FastPathReady {} + + oneof body { + InboxMessage inbox_message = 2; + FastPathReady fast_path_ready = 7; + } +} diff --git a/internal/proto/tachyon_common.proto b/internal/proto/tachyon_common.proto new file mode 100644 index 00000000..bc155c33 --- /dev/null +++ b/internal/proto/tachyon_common.proto @@ -0,0 +1,119 @@ +// Copyright 2021 Google LLC +// +// 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 +// +// https://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. + +syntax = "proto3"; + +package nearby.internal.tachyon_proto; + +import "internal/proto/tachyon_enums.proto"; + +option optimize_for = LITE_RUNTIME; + +message Id { + // type defines what the id field contains, e.g. phone number, Fi-number, Gaia + // ID etc. + IdType.Type type = 1; + // id is a unique (for this type and app) identifier of a message source or + // recipient. + string id = 2; + + // app is the tachyon client application that generated or is to receive a + // message. + string app = 3; + + // location_hint is used as a hint for the user's region. + LocationHint location_hint = 5; +} + +// LocationHint is used to specify a location as well as format. +message LocationHint { + // Location is the location, provided in the format specified by format. + string location = 1; + + // the format of location. + LocationStandard.Format format = 2; +} + +// RequestHeader must be included in all request messages with the field name +// `header`. +// This will make the generated Go types of requests have GetHeader and +// SetHeader funcs, which makes it simple to create a common interface to access +// the header values. +message RequestHeader { + // request_id identifies this request and its responses, must be unique, and + // is generated by the request creator. + // This does not need to be set if request_id_binary is set. + string request_id = 1; + + // app identifies the application; this is used to isolate different + // applications in the backend. + string app = 3; + + // client_info holds information about the calling client application. + ClientInfo client_info = 7; + + // requester_id is the user ID of the requester. + Id requester_id = 10; +} + +message ClientInfo { + // major, minor, point and details carry version information from client. + int32 major = 3; + int32 minor = 4; + int32 point = 5; + + // api_version identifies what api_version the client was built against. + // This is used by server to: + // - push warning messages to clients during bind + // - fail RPCs if client is using a too old version + // - add backwards compatible code + ApiVersion.Value api_version = 7; + + // platform_type is the type of platform, used to construct user agent string + // and to determine client node type in logging. + Platform.Type platform_type = 9; + + // The APK version name (e.g. "4.0.006_RC2"). + // Fireball Android sends down the version code in the above major field and + // leaves minor and point empty. The code results in a version that is tough + // to decipher like "20011296.0.0". The version name here is formatted to make + // versioning easier and safer on the server. Currently, this field is only + // populated by Fireball Android. See go/fireball-gbot-version. + string app_version = 10; +} + +message InboxMessage { + string message_id = 1; + + enum MessageType { + UNKNOWN = 0; + BASIC = 4; + } + MessageType message_type = 2; + + bytes message = 12; + + enum MessageClass { + USER = 0; + EPHEMERAL = 2; + } + MessageClass message_class = 5; +} + +// Matches StreamBody definition from the server: +// google3/google/rpc/stream_body.proto +message StreamBody { + repeated bytes messages = 1; + repeated bytes noop = 15; +} diff --git a/internal/proto/tachyon_enums.proto b/internal/proto/tachyon_enums.proto new file mode 100644 index 00000000..3f72a6ab --- /dev/null +++ b/internal/proto/tachyon_enums.proto @@ -0,0 +1,86 @@ +// Copyright 2021 Google LLC +// +// 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 +// +// https://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. + +syntax = "proto3"; + +package nearby.internal.tachyon_proto; + +option optimize_for = LITE_RUNTIME; + +message ApiVersion { + enum Value { + UNKNOWN = 0; + + // Initial version. + V1 = 1; + + // RequestHeaders and AuthToken only. + V2 = 2; + + // Block leaked playstore APKs. + V3 = 3; + + // InboxMessage.message bytes are used. + V4 = 4; + } +} + +message Platform { + enum Type { + UNKNOWN = 0; + TEST = 4; + DESKTOP = 6; + } +} + +message LocationStandard { + enum Format { + UNKNOWN = 0; + // E164 country codes: + // https://en.wikipedia.org/wiki/List_of_country_calling_codes + // e.g. +1 for USA + E164_CALLING = 1; + + // ISO 3166-1 alpha-2 country codes: + // https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 + ISO_3166_1_ALPHA_2 = 2; + } +} + +message IdType { + enum Type { + UNSET = 0; + NOT_KNOWN = 25; // client does not know the id type. + NEARBY_ID = 27; // Used by Nearby devices. go/tachyon-express-nearby. + } +} + +// Connectivity status from the client network to ice_servers. +// +// This message is intended to be binary compatible and should be kept up to +// date with BlockStatus in +// google3/google/communications/networktraversal/v1alpha/networktraversal.proto +message ConnectivityStatus { + // Status enumerations. + enum Type { + // Unspecified. + UNKNOWN = 0; + + // ICE connectivity is not blocked. + ICE_UNBLOCKED = 1; + + // ICE connectivity is possibly blocked. + ICE_POSSIBLY_BLOCKED = 2; + } +}