1 // Copyright 2023 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 15 package dev.pigweed.pw_transfer; 16 17 import com.google.auto.value.AutoValue; 18 19 /** 20 * Transfer parameters set by the receiver. 21 * 22 * <p> 23 * In a client, these are only used for read transfers. These values can be 24 * adjusted to optimize 25 * for the service/client limitations and the transport between them. 26 */ 27 @AutoValue 28 public abstract class TransferParameters { create( int maxWindowSizeBytes, int maxChunkSizeBytes, int chunkDelayMicroseconds)29 public static TransferParameters create( 30 int maxWindowSizeBytes, int maxChunkSizeBytes, int chunkDelayMicroseconds) { 31 return new AutoValue_TransferParameters( 32 maxWindowSizeBytes, maxChunkSizeBytes, chunkDelayMicroseconds); 33 } 34 35 /** 36 * Max number of bytes to request at once. Should be a multiple of 37 * maxChunkSizeBytes. 38 */ maxWindowSizeBytes()39 public abstract int maxWindowSizeBytes(); 40 41 /** 42 * Max number of bytes to send in a single chunk. Should be a factor of 43 * maxWindowSizeBytes. 44 */ maxChunkSizeBytes()45 public abstract int maxChunkSizeBytes(); 46 47 /** How long to require the sender to wait between sending chunks. */ chunkDelayMicroseconds()48 public abstract int chunkDelayMicroseconds(); 49 50 /** Maximum number of complete chunks that can fit into a receiver window. */ maxChunksInWindow()51 public int maxChunksInWindow() { 52 return maxWindowSizeBytes() / maxChunkSizeBytes(); 53 } 54 } 55