network_route.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  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. #ifndef RTC_BASE_NETWORK_ROUTE_H_
  11. #define RTC_BASE_NETWORK_ROUTE_H_
  12. #include <stdint.h>
  13. #include <string>
  14. #include "rtc_base/network_constants.h"
  15. #include "rtc_base/strings/string_builder.h"
  16. #include "rtc_base/system/inline.h"
  17. // TODO(honghaiz): Make a directory that describes the interfaces and structs
  18. // the media code can rely on and the network code can implement, and both can
  19. // depend on that, but not depend on each other. Then, move this file to that
  20. // directory.
  21. namespace rtc {
  22. class RouteEndpoint {
  23. public:
  24. RouteEndpoint() {} // Used by tests.
  25. RouteEndpoint(AdapterType adapter_type,
  26. uint16_t adapter_id,
  27. uint16_t network_id,
  28. bool uses_turn)
  29. : adapter_type_(adapter_type),
  30. adapter_id_(adapter_id),
  31. network_id_(network_id),
  32. uses_turn_(uses_turn) {}
  33. RouteEndpoint(const RouteEndpoint&) = default;
  34. RouteEndpoint& operator=(const RouteEndpoint&) = default;
  35. // Used by tests.
  36. static RouteEndpoint CreateWithNetworkId(uint16_t network_id) {
  37. return RouteEndpoint(ADAPTER_TYPE_UNKNOWN,
  38. /* adapter_id = */ 0, network_id,
  39. /* uses_turn = */ false);
  40. }
  41. RouteEndpoint CreateWithTurn(bool uses_turn) const {
  42. return RouteEndpoint(adapter_type_, adapter_id_, network_id_, uses_turn);
  43. }
  44. AdapterType adapter_type() const { return adapter_type_; }
  45. uint16_t adapter_id() const { return adapter_id_; }
  46. uint16_t network_id() const { return network_id_; }
  47. bool uses_turn() const { return uses_turn_; }
  48. bool operator==(const RouteEndpoint& other) const;
  49. private:
  50. AdapterType adapter_type_ = ADAPTER_TYPE_UNKNOWN;
  51. uint16_t adapter_id_ = 0;
  52. uint16_t network_id_ = 0;
  53. bool uses_turn_ = false;
  54. };
  55. struct NetworkRoute {
  56. bool connected = false;
  57. RouteEndpoint local;
  58. RouteEndpoint remote;
  59. // Last packet id sent on the PREVIOUS route.
  60. int last_sent_packet_id = -1;
  61. // The overhead in bytes from IP layer and above.
  62. // This is the maximum of any part of the route.
  63. int packet_overhead = 0;
  64. RTC_NO_INLINE inline std::string DebugString() const {
  65. rtc::StringBuilder oss;
  66. oss << "[ connected: " << connected << " local: [ " << local.adapter_id()
  67. << "/" << local.network_id() << " "
  68. << AdapterTypeToString(local.adapter_type())
  69. << " turn: " << local.uses_turn() << " ] remote: [ "
  70. << remote.adapter_id() << "/" << remote.network_id() << " "
  71. << AdapterTypeToString(remote.adapter_type())
  72. << " turn: " << remote.uses_turn()
  73. << " ] packet_overhead_bytes: " << packet_overhead << " ]";
  74. return oss.Release();
  75. }
  76. bool operator==(const NetworkRoute& other) const;
  77. };
  78. } // namespace rtc
  79. #endif // RTC_BASE_NETWORK_ROUTE_H_