xref: /aosp_15_r20/external/webrtc/p2p/base/transport_description_factory.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2012 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 
11 #ifndef P2P_BASE_TRANSPORT_DESCRIPTION_FACTORY_H_
12 #define P2P_BASE_TRANSPORT_DESCRIPTION_FACTORY_H_
13 
14 #include <memory>
15 #include <utility>
16 
17 #include "api/field_trials_view.h"
18 #include "p2p/base/ice_credentials_iterator.h"
19 #include "p2p/base/transport_description.h"
20 #include "rtc_base/rtc_certificate.h"
21 
22 namespace rtc {
23 class SSLIdentity;
24 }
25 
26 namespace cricket {
27 
28 struct TransportOptions {
29   bool ice_restart = false;
30   bool prefer_passive_role = false;
31   // If true, ICE renomination is supported and will be used if it is also
32   // supported by the remote side.
33   bool enable_ice_renomination = false;
34 };
35 
36 // Creates transport descriptions according to the supplied configuration.
37 // When creating answers, performs the appropriate negotiation
38 // of the various fields to determine the proper result.
39 class TransportDescriptionFactory {
40  public:
41   // Default ctor; use methods below to set configuration.
42   explicit TransportDescriptionFactory(
43       const webrtc::FieldTrialsView& field_trials);
44   ~TransportDescriptionFactory();
45 
secure()46   SecurePolicy secure() const { return secure_; }
47   // The certificate to use when setting up DTLS.
certificate()48   const rtc::scoped_refptr<rtc::RTCCertificate>& certificate() const {
49     return certificate_;
50   }
51 
52   // Specifies the transport security policy to use.
set_secure(SecurePolicy s)53   void set_secure(SecurePolicy s) { secure_ = s; }
54   // Specifies the certificate to use (only used when secure != SEC_DISABLED).
set_certificate(rtc::scoped_refptr<rtc::RTCCertificate> certificate)55   void set_certificate(rtc::scoped_refptr<rtc::RTCCertificate> certificate) {
56     certificate_ = std::move(certificate);
57   }
58 
59   // Creates a transport description suitable for use in an offer.
60   std::unique_ptr<TransportDescription> CreateOffer(
61       const TransportOptions& options,
62       const TransportDescription* current_description,
63       IceCredentialsIterator* ice_credentials) const;
64   // Create a transport description that is a response to an offer.
65   //
66   // If `require_transport_attributes` is true, then TRANSPORT category
67   // attributes are expected to be present in `offer`, as defined by
68   // sdp-mux-attributes, and null will be returned otherwise. It's expected
69   // that this will be set to false for an m= section that's in a BUNDLE group
70   // but isn't the first m= section in the group.
71   std::unique_ptr<TransportDescription> CreateAnswer(
72       const TransportDescription* offer,
73       const TransportOptions& options,
74       bool require_transport_attributes,
75       const TransportDescription* current_description,
76       IceCredentialsIterator* ice_credentials) const;
77 
trials()78   const webrtc::FieldTrialsView& trials() const { return field_trials_; }
79 
80  private:
81   bool SetSecurityInfo(TransportDescription* description,
82                        ConnectionRole role) const;
83 
84   SecurePolicy secure_;
85   rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
86   const webrtc::FieldTrialsView& field_trials_;
87 };
88 
89 }  // namespace cricket
90 
91 #endif  // P2P_BASE_TRANSPORT_DESCRIPTION_FACTORY_H_
92