1 /* 2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef NET_DCSCTP_PACKET_CHUNK_SHUTDOWN_CHUNK_H_ 11 #define NET_DCSCTP_PACKET_CHUNK_SHUTDOWN_CHUNK_H_ 12 #include <stddef.h> 13 #include <stdint.h> 14 15 #include <string> 16 #include <vector> 17 18 #include "absl/strings/string_view.h" 19 #include "api/array_view.h" 20 #include "net/dcsctp/packet/chunk/chunk.h" 21 #include "net/dcsctp/packet/tlv_trait.h" 22 23 namespace dcsctp { 24 25 // https://tools.ietf.org/html/rfc4960#section-3.3.8 26 struct ShutdownChunkConfig : ChunkConfig { 27 static constexpr int kType = 7; 28 static constexpr size_t kHeaderSize = 8; 29 static constexpr size_t kVariableLengthAlignment = 0; 30 }; 31 32 class ShutdownChunk : public Chunk, public TLVTrait<ShutdownChunkConfig> { 33 public: 34 static constexpr int kType = ShutdownChunkConfig::kType; 35 ShutdownChunk(TSN cumulative_tsn_ack)36 explicit ShutdownChunk(TSN cumulative_tsn_ack) 37 : cumulative_tsn_ack_(cumulative_tsn_ack) {} 38 39 static absl::optional<ShutdownChunk> Parse( 40 rtc::ArrayView<const uint8_t> data); 41 42 void SerializeTo(std::vector<uint8_t>& out) const override; 43 std::string ToString() const override; 44 cumulative_tsn_ack()45 TSN cumulative_tsn_ack() const { return cumulative_tsn_ack_; } 46 47 private: 48 TSN cumulative_tsn_ack_; 49 }; 50 51 } // namespace dcsctp 52 53 #endif // NET_DCSCTP_PACKET_CHUNK_SHUTDOWN_CHUNK_H_ 54