blob: c1754ed59a35e42d5de1cdf76474be8bbd5b9835 [file] [log] [blame]
Victor Boivie5457ec02021-03-30 17:27:351/*
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_DATA_H_
11#define NET_DCSCTP_PACKET_DATA_H_
12
13#include <cstdint>
14#include <utility>
15#include <vector>
16
Victor Boiviea8655192021-04-01 06:23:5417#include "net/dcsctp/common/internal_types.h"
18#include "net/dcsctp/public/types.h"
19
Victor Boivie5457ec02021-03-30 17:27:3520namespace dcsctp {
21
22// Represents data that is either received and extracted from a DATA/I-DATA
23// chunk, or data that is supposed to be sent, and wrapped in a DATA/I-DATA
24// chunk (depending on peer capabilities).
25//
26// The data wrapped in this structure is actually the same as the DATA/I-DATA
27// chunk (actually the union of them), but to avoid having all components be
28// aware of the implementation details of the different chunks, this abstraction
29// is used instead. A notable difference is also that it doesn't carry a
30// Transmission Sequence Number (TSN), as that is not known when a chunk is
31// created (assigned late, just when sending), and that the TSNs in DATA/I-DATA
32// are wrapped numbers, and within the library, unwrapped sequence numbers are
33// preferably used.
34struct Data {
Victor Boiviea8655192021-04-01 06:23:5435 // Indicates if a chunk is the first in a fragmented message and maps to the
36 // "beginning" flag in DATA/I-DATA chunk.
Victor Boivieb9182302021-09-21 12:51:0537 using IsBeginning = webrtc::StrongAlias<class IsBeginningTag, bool>;
Victor Boiviea8655192021-04-01 06:23:5438
39 // Indicates if a chunk is the last in a fragmented message and maps to the
40 // "end" flag in DATA/I-DATA chunk.
Victor Boivieb9182302021-09-21 12:51:0541 using IsEnd = webrtc::StrongAlias<class IsEndTag, bool>;
Victor Boiviea8655192021-04-01 06:23:5442
43 Data(StreamID stream_id,
44 SSN ssn,
45 MID message_id,
46 FSN fsn,
47 PPID ppid,
Victor Boivie4b7024b2021-12-01 18:57:2248 std::vector<uint8_t> payload,
Victor Boiviea8655192021-04-01 06:23:5449 IsBeginning is_beginning,
50 IsEnd is_end,
51 IsUnordered is_unordered)
Victor Boivie5457ec02021-03-30 17:27:3552 : stream_id(stream_id),
53 ssn(ssn),
54 message_id(message_id),
55 fsn(fsn),
56 ppid(ppid),
57 payload(std::move(payload)),
58 is_beginning(is_beginning),
59 is_end(is_end),
60 is_unordered(is_unordered) {}
61
62 // Move-only, to avoid accidental copies.
63 Data(Data&& other) = default;
64 Data& operator=(Data&& other) = default;
65
66 // Creates a copy of this `Data` object.
Victor Boivie03e912a2021-04-05 18:18:3467 Data Clone() const {
Victor Boivie5457ec02021-03-30 17:27:3568 return Data(stream_id, ssn, message_id, fsn, ppid, payload, is_beginning,
69 is_end, is_unordered);
70 }
71
72 // The size of this data, which translates to the size of its payload.
73 size_t size() const { return payload.size(); }
74
75 // Stream Identifier.
Victor Boiviea8655192021-04-01 06:23:5476 StreamID stream_id;
Victor Boivie5457ec02021-03-30 17:27:3577
78 // Stream Sequence Number (SSN), per stream, for ordered chunks. Defined by
79 // RFC4960 and used only in DATA chunks (not I-DATA).
Victor Boiviea8655192021-04-01 06:23:5480 SSN ssn;
Victor Boivie5457ec02021-03-30 17:27:3581
82 // Message Identifier (MID) per stream and ordered/unordered. Defined by
83 // RFC8260, and used together with options.is_unordered and stream_id to
84 // uniquely identify a message. Used only in I-DATA chunks (not DATA).
Victor Boiviea8655192021-04-01 06:23:5485 MID message_id;
Victor Boivie5457ec02021-03-30 17:27:3586 // Fragment Sequence Number (FSN) per stream and ordered/unordered, as above.
Victor Boiviea8655192021-04-01 06:23:5487 FSN fsn;
Victor Boivie5457ec02021-03-30 17:27:3588
89 // Payload Protocol Identifier (PPID).
Victor Boiviea8655192021-04-01 06:23:5490 PPID ppid;
Victor Boivie5457ec02021-03-30 17:27:3591
92 // The actual data payload.
Victor Boivie4b7024b2021-12-01 18:57:2293 std::vector<uint8_t> payload;
Victor Boivie5457ec02021-03-30 17:27:3594
95 // If this data represents the first, last or a middle chunk.
Victor Boiviea8655192021-04-01 06:23:5496 IsBeginning is_beginning;
97 IsEnd is_end;
Victor Boivie5457ec02021-03-30 17:27:3598 // If this data is sent/received unordered.
Victor Boiviea8655192021-04-01 06:23:5499 IsUnordered is_unordered;
Victor Boivie5457ec02021-03-30 17:27:35100};
101} // namespace dcsctp
102
103#endif // NET_DCSCTP_PACKET_DATA_H_