xref: /aosp_15_r20/external/webrtc/net/dcsctp/packet/chunk/abort_chunk.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
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_ABORT_CHUNK_H_
11 #define NET_DCSCTP_PACKET_CHUNK_ABORT_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.7
28 struct AbortChunkConfig : ChunkConfig {
29   static constexpr int kType = 6;
30   static constexpr size_t kHeaderSize = 4;
31   static constexpr size_t kVariableLengthAlignment = 1;
32 };
33 
34 class AbortChunk : public Chunk, public TLVTrait<AbortChunkConfig> {
35  public:
36   static constexpr int kType = AbortChunkConfig::kType;
37 
AbortChunk(bool filled_in_verification_tag,Parameters error_causes)38   AbortChunk(bool filled_in_verification_tag, Parameters error_causes)
39       : filled_in_verification_tag_(filled_in_verification_tag),
40         error_causes_(std::move(error_causes)) {}
41 
42   AbortChunk(AbortChunk&& other) = default;
43   AbortChunk& operator=(AbortChunk&& other) = default;
44 
45   static absl::optional<AbortChunk> Parse(rtc::ArrayView<const uint8_t> data);
46 
47   void SerializeTo(std::vector<uint8_t>& out) const override;
48   std::string ToString() const override;
49 
filled_in_verification_tag()50   bool filled_in_verification_tag() const {
51     return filled_in_verification_tag_;
52   }
53 
error_causes()54   const Parameters& error_causes() const { return error_causes_; }
55 
56  private:
57   static constexpr int kFlagsBitT = 0;
58   bool filled_in_verification_tag_;
59   Parameters error_causes_;
60 };
61 
62 }  // namespace dcsctp
63 
64 #endif  // NET_DCSCTP_PACKET_CHUNK_ABORT_CHUNK_H_
65