candidate.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Copyright (c) 2019 Paul-Louis Ageneau
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  7. */
  8. #ifndef RTC_CANDIDATE_H
  9. #define RTC_CANDIDATE_H
  10. #include "common.hpp"
  11. #include <string>
  12. namespace rtc {
  13. class RTC_CPP_EXPORT Candidate {
  14. public:
  15. enum class Family { Unresolved, Ipv4, Ipv6 };
  16. enum class Type { Unknown, Host, ServerReflexive, PeerReflexive, Relayed };
  17. enum class TransportType { Unknown, Udp, TcpActive, TcpPassive, TcpSo, TcpUnknown };
  18. Candidate();
  19. Candidate(string candidate);
  20. Candidate(string candidate, string mid);
  21. void hintMid(string mid);
  22. void changeAddress(string addr);
  23. void changeAddress(string addr, uint16_t port);
  24. void changeAddress(string addr, string service);
  25. enum class ResolveMode { Simple, Lookup };
  26. bool resolve(ResolveMode mode = ResolveMode::Simple);
  27. Type type() const;
  28. TransportType transportType() const;
  29. uint32_t priority() const;
  30. string candidate() const;
  31. string mid() const;
  32. operator string() const;
  33. bool operator==(const Candidate &other) const;
  34. bool operator!=(const Candidate &other) const;
  35. bool isResolved() const;
  36. Family family() const;
  37. optional<string> address() const;
  38. optional<uint16_t> port() const;
  39. private:
  40. void parse(string candidate);
  41. string mFoundation;
  42. uint32_t mComponent, mPriority;
  43. string mTypeString, mTransportString;
  44. Type mType;
  45. TransportType mTransportType;
  46. string mNode, mService;
  47. string mTail;
  48. optional<string> mMid;
  49. // Extracted on resolution
  50. Family mFamily;
  51. string mAddress;
  52. uint16_t mPort;
  53. };
  54. RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const Candidate &candidate);
  55. RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out, const Candidate::Type &type);
  56. RTC_CPP_EXPORT std::ostream &operator<<(std::ostream &out,
  57. const Candidate::TransportType &transportType);
  58. } // namespace rtc
  59. #endif