blob: 3f678e3455f8362b8bffd0de690c336bb60df4a0 [file] [log] [blame]
Honghai Zhangcc411c02016-03-30 00:27:211/*
2 * Copyright 2016 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
Steve Anton10542f22019-01-11 17:11:0011#ifndef RTC_BASE_NETWORK_ROUTE_H_
12#define RTC_BASE_NETWORK_ROUTE_H_
Honghai Zhangcc411c02016-03-30 00:27:2113
Sebastian Janssone4be6da2018-02-15 15:51:4114#include <stdint.h>
15
Jonas Oreland71fda362020-03-20 15:11:5616#include <string>
17
18#include "rtc_base/network_constants.h"
19#include "rtc_base/strings/string_builder.h"
20#include "rtc_base/system/inline.h"
21
Henrik Kjellanderec78f1c2017-06-29 05:52:5022// TODO(honghaiz): Make a directory that describes the interfaces and structs
23// the media code can rely on and the network code can implement, and both can
24// depend on that, but not depend on each other. Then, move this file to that
25// directory.
26namespace rtc {
Honghai Zhangcc411c02016-03-30 00:27:2127
Jonas Oreland71fda362020-03-20 15:11:5628class RouteEndpoint {
29 public:
30 RouteEndpoint() {} // Used by tests.
31 RouteEndpoint(AdapterType adapter_type,
32 uint16_t adapter_id,
33 uint16_t network_id,
34 bool uses_turn)
35 : adapter_type_(adapter_type),
36 adapter_id_(adapter_id),
37 network_id_(network_id),
38 uses_turn_(uses_turn) {}
39
40 RouteEndpoint(const RouteEndpoint&) = default;
41 RouteEndpoint& operator=(const RouteEndpoint&) = default;
42
43 // Used by tests.
44 static RouteEndpoint CreateWithNetworkId(uint16_t network_id) {
45 return RouteEndpoint(ADAPTER_TYPE_UNKNOWN,
46 /* adapter_id = */ 0, network_id,
47 /* uses_turn = */ false);
48 }
Christoffer Rodbro1c7a6582020-03-26 21:48:2549 RouteEndpoint CreateWithTurn(bool uses_turn) const {
50 return RouteEndpoint(adapter_type_, adapter_id_, network_id_, uses_turn);
51 }
Jonas Oreland71fda362020-03-20 15:11:5652
53 AdapterType adapter_type() const { return adapter_type_; }
54 uint16_t adapter_id() const { return adapter_id_; }
55 uint16_t network_id() const { return network_id_; }
56 bool uses_turn() const { return uses_turn_; }
57
Jonas Oreland5b6a4d82020-03-24 06:36:5258 bool operator==(const RouteEndpoint& other) const;
59
Jonas Oreland71fda362020-03-20 15:11:5660 private:
61 AdapterType adapter_type_ = ADAPTER_TYPE_UNKNOWN;
62 uint16_t adapter_id_ = 0;
63 uint16_t network_id_ = 0;
64 bool uses_turn_ = false;
65};
66
Henrik Kjellanderec78f1c2017-06-29 05:52:5067struct NetworkRoute {
Steve Antonea1bb352018-07-23 17:12:3768 bool connected = false;
Jonas Oreland71fda362020-03-20 15:11:5669 RouteEndpoint local;
70 RouteEndpoint remote;
Steve Antonea1bb352018-07-23 17:12:3771 // Last packet id sent on the PREVIOUS route.
72 int last_sent_packet_id = -1;
73 // The overhead in bytes from IP layer and above.
Jonas Oreland71fda362020-03-20 15:11:5674 // This is the maximum of any part of the route.
Steve Antonea1bb352018-07-23 17:12:3775 int packet_overhead = 0;
Jonas Oreland71fda362020-03-20 15:11:5676
Jonas Oreland71fda362020-03-20 15:11:5677 RTC_NO_INLINE inline std::string DebugString() const {
78 rtc::StringBuilder oss;
79 oss << "[ connected: " << connected << " local: [ " << local.adapter_id()
80 << "/" << local.network_id() << " "
81 << AdapterTypeToString(local.adapter_type())
82 << " turn: " << local.uses_turn() << " ] remote: [ "
83 << remote.adapter_id() << "/" << remote.network_id() << " "
84 << AdapterTypeToString(remote.adapter_type())
85 << " turn: " << remote.uses_turn()
86 << " ] packet_overhead_bytes: " << packet_overhead << " ]";
87 return oss.Release();
88 }
Jonas Oreland5b6a4d82020-03-24 06:36:5289
90 bool operator==(const NetworkRoute& other) const;
Per K1d2f85d2024-10-23 12:11:4191 bool operator!=(const NetworkRoute& other) { return !operator==(other); }
Henrik Kjellanderec78f1c2017-06-29 05:52:5092};
Jonas Oreland71fda362020-03-20 15:11:5693
Henrik Kjellanderec78f1c2017-06-29 05:52:5094} // namespace rtc
Honghai Zhangcc411c02016-03-30 00:27:2195
Steve Anton10542f22019-01-11 17:11:0096#endif // RTC_BASE_NETWORK_ROUTE_H_