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