1// Copyright 2022 The Pigweed Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); you may not 4// use this file except in compliance with the License. You may obtain a copy of 5// the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12// License for the specific language governing permissions and limitations under 13// the License. 14 15syntax = "proto3"; 16 17package pw.transfer; 18 19option java_multiple_files = true; 20option java_package = "dev.pigweed.pw_transfer"; 21 22// The transfer RPC service is used to send data between the client and server. 23service Transfer { 24 // Transfer data from the server to the client; a "download" from the client's 25 // perspective. 26 rpc Read(stream Chunk) returns (stream Chunk); 27 28 // Transfer data from the client to the server; an "upload" from the client's 29 // perspective. 30 rpc Write(stream Chunk) returns (stream Chunk); 31} 32 33// Represents a chunk of data sent by the transfer service. Includes fields for 34// configuring the transfer parameters. 35// 36// Notation: (Read|Write) (→|←) 37// X → Means client sending data to the server. 38// X ← Means server sending data to the client. 39message Chunk { 40 // Represents the source or destination of the data. May be ephemeral or 41 // stable depending on the implementation. Sent in every request to identify 42 // the transfer target. 43 // 44 // LEGACY FIELD ONLY. Split into resource_id and session_id in transfer v2. 45 // 46 // Read → ID of transfer 47 // Read ← ID of transfer 48 // Write → ID of transfer 49 // Write ← ID of transfer 50 uint32 transfer_id = 1; 51 52 // Used by the receiver to indicate how many bytes it can accept. The 53 // transmitter sends this much data, divided into chunks no larger than 54 // max_chunk_size_bytes. The receiver then starts another window by sending 55 // request_bytes again with a new offset. 56 // 57 // Read → The client requests this many bytes to be sent. 58 // Read ← N/A 59 // Write → N/A 60 // Write ← The server requests this many bytes to be sent. 61 optional uint32 pending_bytes = 2; 62 63 // Maximum size of an individual chunk. The transmitter may send smaller 64 // chunks if required. 65 // 66 // Read → Set maximum size for subsequent chunks. 67 // Read ← N/A 68 // Write → N/A 69 // Write ← Set maximum size for subsequent chunks. 70 optional uint32 max_chunk_size_bytes = 3; 71 72 // Minimum required delay between chunks. The transmitter may delay longer if 73 // desired. 74 // 75 // Read → Set minimum delay for subsequent chunks. 76 // Read ← N/A 77 // Write → N/A 78 // Write ← Set minimum delay for subsequent chunks. 79 optional uint32 min_delay_microseconds = 4; 80 81 // On writes, the offset of the data. On reads, the offset at which to read. 82 // 83 // Read → Read data starting at this offset. 84 // Read ← Offset of the data. 85 // Write → Offset of the data. 86 // Write ← Write data starting at this offset. 87 uint64 offset = 5; 88 89 // The data that was read or the data to write. 90 // 91 // Read → N/A 92 // Read ← Data read 93 // Write → Data to write 94 // Write ← N/A 95 bytes data = 6; 96 97 // Estimated bytes remaining to read/write. Optional except for the last data 98 // chunk, for which remaining_bytes must be set to 0. 99 // 100 // The sender can set remaining_bytes at the beginning of a read/write so that 101 // the receiver can track progress or cancel the transaction if the value is 102 // too large. 103 // 104 // Read → N/A 105 // Read ← Remaining bytes to read, excluding any data in this chunk. Set to 106 // 0 for the last chunk. 107 // Write → Remaining bytes to write, excluding any data in is chunk. Set to 108 // 0 for the last chunk. 109 // Write ← N/A 110 optional uint64 remaining_bytes = 7; 111 112 // Pigweed status code indicating the completion of a transfer. This is only 113 // present in the final packet sent by either the transmitter or receiver. 114 // 115 // The possible status codes and their meanings are listed below: 116 // 117 // OK: Transfer completed successfully. 118 // DATA_LOSS: Transfer data could not be read/written (e.g. corruption). 119 // INVALID_ARGUMENT: Received malformed chunk. 120 // NOT_FOUND: The requested resource ID is not registered (read/write). 121 // OUT_OF_RANGE: The requested offset is larger than the data (read/write). 122 // RESOURCE_EXHAUSTED: Concurrent transfer limit reached. 123 // UNIMPLEMENTED: Resource ID does not support requested operation (e.g. 124 // trying to write to a read-only transfer). 125 // 126 // Read → Transfer complete. 127 // Read ← Transfer complete. 128 // Write → Transfer complete. 129 // Write ← Transfer complete. 130 optional uint32 status = 8; 131 132 // The offset up to which the transmitter can send data before waiting for the 133 // receiver to acknowledge. 134 // 135 // Read → Offset up to which the server can send without blocking. 136 // Read ← N/A 137 // Write → N/A 138 // Write ← Offset up to which the client can send without blocking. 139 // 140 // TODO(frolv): This will replace the pending_bytes field. Once all uses of 141 // transfer are migrated, that field should be removed. 142 uint32 window_end_offset = 9; 143 144 enum Type { 145 // Chunk containing transfer data. 146 DATA = 0; 147 148 // First chunk of a transfer (only sent by the client). 149 START = 1; 150 151 // Transfer parameters indicating that the transmitter should retransmit 152 // from the specified offset. 153 PARAMETERS_RETRANSMIT = 2; 154 155 // Transfer parameters telling the transmitter to continue sending up to 156 // index `offset + pending_bytes` of data. If the transmitter is already 157 // beyond `offset`, it does not have to rewind. 158 PARAMETERS_CONTINUE = 3; 159 160 // Sender of the chunk is terminating the transfer. 161 COMPLETION = 4; 162 163 // Acknowledge the completion of a transfer. Currently unused. 164 // TODO(konkers): Implement this behavior. 165 COMPLETION_ACK = 5; 166 167 // Acknowledges a transfer start request, assigning a session ID for the 168 // transfer and optionally negotiating the protocol version. Sent from 169 // server to client. 170 START_ACK = 6; 171 172 // Confirmation of a START_ACK's assigned session ID and negotiated 173 // parameters, sent by the client to the server. Initiates the data transfer 174 // proper. 175 START_ACK_CONFIRMATION = 7; 176 }; 177 178 // The type of this chunk. This field should only be processed when present. 179 // TODO(frolv): Update all users of pw_transfer and remove the optional 180 // semantics from this field. 181 // 182 // Read → Chunk type (start/parameters). 183 // Read ← Chunk type (data). 184 // Write → Chunk type (data). 185 // Write ← Chunk type (start/parameters). 186 optional Type type = 10; 187 188 // Unique identifier for the source or destination of transfer data. May be 189 // stable or ephemeral depending on the implementation. Only sent during the 190 // initial handshake phase of a version 2 or higher transfer. 191 // 192 // Read → ID of transferable resource 193 // Read ← ID of transferable resource 194 // Write → ID of transferable resource 195 // Write ← ID of transferable resource 196 optional uint32 resource_id = 11; 197 198 // Unique identifier for a specific transfer session. Assigned by a transfer 199 // service during the initial handshake phase, and persists for the remainder 200 // of that transfer operation. 201 // 202 // Read → ID of transfer session 203 // Read ← ID of transfer session 204 // Write → ID of transfer session 205 // Write ← ID of transfer session 206 optional uint32 session_id = 12; 207 208 // The protocol version to use for this transfer. Only sent during the initial 209 // handshake phase of a version 2 or higher transfer to negotiate a common 210 // protocol version between the client and server. 211 // 212 // Read → Desired (START) or configured (START_ACK_CONFIRMATION) version. 213 // Read ← Configured protocol version (START_ACK). 214 // Write → Desired (START) or configured (START_ACK_CONFIRMATION) version. 215 // Write ← Configured protocol version (START_ACK). 216 optional uint32 protocol_version = 13; 217} 218