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_HEARTBEAT_ACK_CHUNK_H_ 11 #define NET_DCSCTP_PACKET_CHUNK_HEARTBEAT_ACK_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/parameter/heartbeat_info_parameter.h" 23 #include "net/dcsctp/packet/parameter/parameter.h" 24 #include "net/dcsctp/packet/tlv_trait.h" 25 26 namespace dcsctp { 27 28 // https://tools.ietf.org/html/rfc4960#section-3.3.6 29 struct HeartbeatAckChunkConfig : ChunkConfig { 30 static constexpr int kType = 5; 31 static constexpr size_t kHeaderSize = 4; 32 static constexpr size_t kVariableLengthAlignment = 1; 33 }; 34 35 class HeartbeatAckChunk : public Chunk, 36 public TLVTrait<HeartbeatAckChunkConfig> { 37 public: 38 static constexpr int kType = HeartbeatAckChunkConfig::kType; 39 HeartbeatAckChunk(Parameters parameters)40 explicit HeartbeatAckChunk(Parameters parameters) 41 : parameters_(std::move(parameters)) {} 42 43 HeartbeatAckChunk(HeartbeatAckChunk&& other) = default; 44 HeartbeatAckChunk& operator=(HeartbeatAckChunk&& other) = default; 45 46 static absl::optional<HeartbeatAckChunk> Parse( 47 rtc::ArrayView<const uint8_t> data); 48 49 void SerializeTo(std::vector<uint8_t>& out) const override; 50 std::string ToString() const override; 51 parameters()52 const Parameters& parameters() const { return parameters_; } 53 info()54 absl::optional<HeartbeatInfoParameter> info() const { 55 return parameters_.get<HeartbeatInfoParameter>(); 56 } 57 58 private: 59 Parameters parameters_; 60 }; 61 } // namespace dcsctp 62 63 #endif // NET_DCSCTP_PACKET_CHUNK_HEARTBEAT_ACK_CHUNK_H_ 64