xref: /aosp_15_r20/external/webrtc/net/dcsctp/socket/context.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_SOCKET_CONTEXT_H_
11 #define NET_DCSCTP_SOCKET_CONTEXT_H_
12 
13 #include <cstdint>
14 
15 #include "absl/strings/string_view.h"
16 #include "net/dcsctp/common/internal_types.h"
17 #include "net/dcsctp/packet/sctp_packet.h"
18 #include "net/dcsctp/public/dcsctp_socket.h"
19 #include "net/dcsctp/public/types.h"
20 
21 namespace dcsctp {
22 
23 // A set of helper methods used by handlers to e.g. send packets.
24 //
25 // Implemented by the TransmissionControlBlock.
26 class Context {
27  public:
28   virtual ~Context() = default;
29 
30   // Indicates if a connection has been established.
31   virtual bool is_connection_established() const = 0;
32 
33   // Returns this side's initial TSN value.
34   virtual TSN my_initial_tsn() const = 0;
35 
36   // Returns the peer's initial TSN value.
37   virtual TSN peer_initial_tsn() const = 0;
38 
39   // Returns the socket callbacks.
40   virtual DcSctpSocketCallbacks& callbacks() const = 0;
41 
42   // Observes a measured RTT value, in milliseconds.
43   virtual void ObserveRTT(DurationMs rtt_ms) = 0;
44 
45   // Returns the current Retransmission Timeout (rto) value, in milliseconds.
46   virtual DurationMs current_rto() const = 0;
47 
48   // Increments the transmission error counter, given a human readable reason.
49   virtual bool IncrementTxErrorCounter(absl::string_view reason) = 0;
50 
51   // Clears the transmission error counter.
52   virtual void ClearTxErrorCounter() = 0;
53 
54   // Returns true if there have been too many retransmission errors.
55   virtual bool HasTooManyTxErrors() const = 0;
56 
57   // Returns a PacketBuilder, filled in with the correct verification tag.
58   virtual SctpPacket::Builder PacketBuilder() const = 0;
59 
60   // Builds the packet from `builder` and sends it.
61   virtual void Send(SctpPacket::Builder& builder) = 0;
62 };
63 
64 }  // namespace dcsctp
65 
66 #endif  // NET_DCSCTP_SOCKET_CONTEXT_H_
67