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 #include "net/dcsctp/packet/parameter/add_incoming_streams_request_parameter.h" 11 12 #include <stdint.h> 13 14 #include <string> 15 #include <type_traits> 16 #include <vector> 17 18 #include "absl/types/optional.h" 19 #include "api/array_view.h" 20 #include "net/dcsctp/common/internal_types.h" 21 #include "net/dcsctp/packet/bounded_byte_reader.h" 22 #include "net/dcsctp/packet/bounded_byte_writer.h" 23 #include "net/dcsctp/packet/tlv_trait.h" 24 #include "rtc_base/strings/string_builder.h" 25 26 namespace dcsctp { 27 28 // https://tools.ietf.org/html/rfc6525#section-4.6 29 30 // 0 1 2 3 31 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 32 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 33 // | Parameter Type = 18 | Parameter Length = 12 | 34 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 35 // | Re-configuration Request Sequence Number | 36 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 37 // | Number of new streams | Reserved | 38 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 39 constexpr int AddIncomingStreamsRequestParameter::kType; 40 41 absl::optional<AddIncomingStreamsRequestParameter> Parse(rtc::ArrayView<const uint8_t> data)42AddIncomingStreamsRequestParameter::Parse(rtc::ArrayView<const uint8_t> data) { 43 absl::optional<BoundedByteReader<kHeaderSize>> reader = ParseTLV(data); 44 if (!reader.has_value()) { 45 return absl::nullopt; 46 } 47 ReconfigRequestSN request_sequence_number(reader->Load32<4>()); 48 uint16_t nbr_of_new_streams = reader->Load16<8>(); 49 50 return AddIncomingStreamsRequestParameter(request_sequence_number, 51 nbr_of_new_streams); 52 } 53 SerializeTo(std::vector<uint8_t> & out) const54void AddIncomingStreamsRequestParameter::SerializeTo( 55 std::vector<uint8_t>& out) const { 56 BoundedByteWriter<kHeaderSize> writer = AllocateTLV(out); 57 writer.Store32<4>(*request_sequence_number_); 58 writer.Store16<8>(nbr_of_new_streams_); 59 } 60 ToString() const61std::string AddIncomingStreamsRequestParameter::ToString() const { 62 rtc::StringBuilder sb; 63 sb << "Add Incoming Streams Request, req_seq_nbr=" 64 << *request_sequence_number(); 65 return sb.Release(); 66 } 67 68 } // namespace dcsctp 69