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