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_ERROR_CHUNK_H_ 11 #define NET_DCSCTP_PACKET_CHUNK_ERROR_CHUNK_H_ 12 #include <stddef.h> 13 #include <stdint.h> 14 15 #include <string> 16 #include <utility> 17 #include <vector> 18 19 #include "absl/strings/string_view.h" 20 #include "api/array_view.h" 21 #include "net/dcsctp/packet/chunk/chunk.h" 22 #include "net/dcsctp/packet/error_cause/error_cause.h" 23 #include "net/dcsctp/packet/tlv_trait.h" 24 25 namespace dcsctp { 26 27 // https://tools.ietf.org/html/rfc4960#section-3.3.10 28 struct ErrorChunkConfig : ChunkConfig { 29 static constexpr int kType = 9; 30 static constexpr size_t kHeaderSize = 4; 31 static constexpr size_t kVariableLengthAlignment = 4; 32 }; 33 34 class ErrorChunk : public Chunk, public TLVTrait<ErrorChunkConfig> { 35 public: 36 static constexpr int kType = ErrorChunkConfig::kType; 37 ErrorChunk(Parameters error_causes)38 explicit ErrorChunk(Parameters error_causes) 39 : error_causes_(std::move(error_causes)) {} 40 41 ErrorChunk(ErrorChunk&& other) = default; 42 ErrorChunk& operator=(ErrorChunk&& other) = default; 43 44 static absl::optional<ErrorChunk> Parse(rtc::ArrayView<const uint8_t> data); 45 46 void SerializeTo(std::vector<uint8_t>& out) const override; 47 std::string ToString() const override; 48 error_causes()49 const Parameters& error_causes() const { return error_causes_; } 50 51 private: 52 Parameters error_causes_; 53 }; 54 55 } // namespace dcsctp 56 57 #endif // NET_DCSCTP_PACKET_CHUNK_ERROR_CHUNK_H_ 58