File: ice_transport.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (127 lines) | stat: -rw-r--r-- 4,782 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_PROTOCOL_ICE_TRANSPORT_H_
#define REMOTING_PROTOCOL_ICE_TRANSPORT_H_

#include <list>
#include <map>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "remoting/protocol/datagram_channel_factory.h"
#include "remoting/protocol/ice_transport_channel.h"
#include "remoting/protocol/jingle_messages.h"
#include "remoting/protocol/transport.h"

namespace remoting::protocol {

class ChannelMultiplexer;
class PseudoTcpChannelFactory;
class SecureChannelFactory;
class MessageChannelFactory;

class IceTransport : public Transport,
                     public IceTransportChannel::Delegate,
                     public DatagramChannelFactory {
 public:
  class EventHandler {
   public:
    // Called when transport route changes.
    virtual void OnIceTransportRouteChange(const std::string& channel_name,
                                           const TransportRoute& route) = 0;

    // Called when there is an error connecting the session.
    virtual void OnIceTransportError(ErrorCode error) = 0;
  };

  // |transport_context| must outlive the session.
  IceTransport(scoped_refptr<TransportContext> transport_context,
               EventHandler* event_handler);

  IceTransport(const IceTransport&) = delete;
  IceTransport& operator=(const IceTransport&) = delete;

  ~IceTransport() override;

  MessageChannelFactory* GetChannelFactory();
  MessageChannelFactory* GetMultiplexedChannelFactory();

  void ApplyNetworkSettings(const NetworkSettings& settings);

  // Transport interface.
  void Start(Authenticator* authenticator,
             SendTransportInfoCallback send_transport_info_callback) override;
  bool ProcessTransportInfo(jingle_xmpp::XmlElement* transport_info) override;

 private:
  typedef std::map<std::string, raw_ptr<IceTransportChannel, CtnExperimental>>
      ChannelsMap;
  using PendingChannelCreatedCallbacks =
      std::map<std::string, ChannelCreatedCallback>;

  // DatagramChannelFactory interface.
  void CreateChannel(const std::string& name,
                     ChannelCreatedCallback callback) override;
  void CancelChannelCreation(const std::string& name) override;

  // Passes transport info to a new |channel| in case it was received before the
  // channel was created.
  void AddPendingRemoteTransportInfo(IceTransportChannel* channel);

  // IceTransportChannel::Delegate interface.
  void OnChannelIceCredentials(IceTransportChannel* transport,
                               const std::string& ufrag,
                               const std::string& password) override;
  void OnChannelCandidate(IceTransportChannel* transport,
                          const webrtc::Candidate& candidate) override;
  void OnChannelRouteChange(IceTransportChannel* transport,
                            const TransportRoute& route) override;
  void OnChannelFailed(IceTransportChannel* transport) override;
  void OnChannelDeleted(IceTransportChannel* transport) override;

  // Creates empty |pending_transport_info_message_| and schedules timer for
  // SentTransportInfo() to sent the message later.
  void EnsurePendingTransportInfoMessage();

  // Sends transport-info message with candidates from |pending_candidates_|.
  void SendTransportInfo();

  // Callback passed to StreamMessageChannelFactoryAdapter to handle read/write
  // errors on the data channels.
  void OnChannelError(int error);

  scoped_refptr<TransportContext> transport_context_;
  raw_ptr<EventHandler> event_handler_;

  SendTransportInfoCallback send_transport_info_callback_;

  ChannelsMap channels_;
  std::unique_ptr<PseudoTcpChannelFactory> pseudotcp_channel_factory_;
  std::unique_ptr<SecureChannelFactory> secure_channel_factory_;
  std::unique_ptr<MessageChannelFactory> message_channel_factory_;

  std::unique_ptr<ChannelMultiplexer> channel_multiplexer_;
  std::unique_ptr<MessageChannelFactory> mux_channel_factory_;

  // Pending remote transport info received before the local channels were
  // created.
  std::list<IceTransportInfo::IceCredentials> pending_remote_ice_credentials_;
  std::list<IceTransportInfo::NamedCandidate> pending_remote_candidates_;

  std::unique_ptr<IceTransportInfo> pending_transport_info_message_;
  base::OneShotTimer transport_info_timer_;

  // Pending channel creations to be executed after network settings are
  // applied.
  PendingChannelCreatedCallbacks pending_channel_created_callbacks_;
  std::unique_ptr<NetworkSettings> network_settings_;

  base::WeakPtrFactory<IceTransport> weak_factory_{this};
};

}  // namespace remoting::protocol

#endif  // REMOTING_PROTOCOL_ICE_TRANSPORT_H_