Skip to content

Commit

Permalink
Fix compilation and clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenke committed May 26, 2024
1 parent 1b972a9 commit 910d069
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 86 deletions.
3 changes: 3 additions & 0 deletions client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ set_target_properties(
)

find_package(Boost ${BOOST_REQUIRED_VERSION} REQUIRED COMPONENTS program_options)
find_package(OpenSSL CONFIG REQUIRED)
pkg_check_modules(Opus REQUIRED IMPORTED_TARGET opus)
find_package(RtAudio CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
Expand All @@ -28,6 +29,8 @@ target_link_libraries(
PRIVATE mumble_protocol
PRIVATE Boost::boost
PRIVATE Boost::program_options
PRIVATE OpenSSL::SSL
PRIVATE OpenSSL::Crypto
PRIVATE PkgConfig::Opus
PRIVATE RtAudio::rtaudio
PRIVATE spdlog::spdlog
Expand Down
2 changes: 1 addition & 1 deletion mumble_protocol/src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct MumbleClient::Impl final {

queuePacket(MumbleAuthenticatePacket(userName, "", {}));

io_thread = std::thread{&asio::io_context::run, &io_context};
io_thread = std::thread{[this] { io_context.run(); }};
}

~Impl() {
Expand Down
6 changes: 6 additions & 0 deletions mumble_protocol/src/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class MUMBLE_PROTOCOL_EXPORT MumbleClient final {
MumbleClient(std::string_view serverName, std::uint16_t port, std::string_view userName,
bool validateServerCertificate = true);

MumbleClient(const MumbleClient& other) = delete;
MumbleClient(MumbleClient&& other) noexcept = delete;

auto operator=(const MumbleClient& other) -> MumbleClient& = delete;
auto operator=(MumbleClient&& other) noexcept -> MumbleClient& = delete;

~MumbleClient();

private:
Expand Down
28 changes: 14 additions & 14 deletions mumble_protocol/src/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

namespace libmumble_protocol {

std::tuple<PacketType, std::span<const std::byte> >
ParseNetworkBuffer(std::span<const std::byte, kMaxPacketLength> buffer) {
auto ParseNetworkBuffer(
std::span<const std::byte, kMaxPacketLength> buffer) -> std::tuple<PacketType, std::span<const std::byte>> {

std::uint16_t raw_packet_type;
std::uint32_t payload_length;
Expand All @@ -27,7 +27,7 @@ ParseNetworkBuffer(std::span<const std::byte, kMaxPacketLength> buffer) {
buffer.subspan(kHeaderLength, SwapNetworkBytes(payload_length))};
}

std::size_t MumbleControlPacket::Serialize(std::span<std::byte, kMaxPacketLength> buffer) const {
auto MumbleControlPacket::Serialize(std::span<std::byte, kMaxPacketLength> buffer) const -> std::size_t {

const auto& message = this->Message();
const std::size_t payload_bytes = message.ByteSizeLong();
Expand All @@ -43,13 +43,13 @@ std::size_t MumbleControlPacket::Serialize(std::span<std::byte, kMaxPacketLength
return total_length;
}

std::string MumbleControlPacket::DebugString() const { return Message().DebugString(); }
auto MumbleControlPacket::DebugString() const -> std::string { return Message().DebugString(); }

/*
* Mumble version_ packet (ID 0)
*/

MumbleVersionPacket::MumbleVersionPacket(const std::span<const std::byte> buffer) : version_(), mumbleVersion_() {
MumbleVersionPacket::MumbleVersionPacket(const std::span<const std::byte> buffer) {
const auto bufferSize = std::size(buffer);
version_.ParseFromArray(buffer.data(), static_cast<int>(bufferSize));
mumbleVersion_.parse(version_.version_v2());
Expand All @@ -58,7 +58,7 @@ MumbleVersionPacket::MumbleVersionPacket(const std::span<const std::byte> buffer
MumbleVersionPacket::MumbleVersionPacket(const MumbleVersion mumble_version, const std::string_view release,
const std::string_view operating_system,
const std::string_view operating_system_version)
: version_(), mumbleVersion_(mumble_version) {
: mumbleVersion_(mumble_version) {

version_.set_version_v1(static_cast<std::uint32_t>(mumbleVersion_));
version_.set_version_v2(static_cast<std::uint64_t>(mumbleVersion_));
Expand All @@ -67,8 +67,8 @@ MumbleVersionPacket::MumbleVersionPacket(const MumbleVersion mumble_version, con
version_.set_os_version(std::string(operating_system_version));
}

PacketType MumbleVersionPacket::PacketType() const { return PacketType::Version; }
google::protobuf::Message const& MumbleVersionPacket::Message() const { return version_; }
auto MumbleVersionPacket::PacketType() const -> enum PacketType { return PacketType::Version; }
auto MumbleVersionPacket::Message() const -> google::protobuf::Message const& { return version_; }

/*
* Mumble authenticate packet (ID 2)
Expand All @@ -90,8 +90,8 @@ MumbleAuthenticatePacket::MumbleAuthenticatePacket(std::span<const std::byte> bu
authenticate_.ParseFromArray(buffer.data(), static_cast<int>(bufferSize));
}

PacketType MumbleAuthenticatePacket::PacketType() const { return PacketType::Authenticate; }
google::protobuf::Message const& MumbleAuthenticatePacket::Message() const { return authenticate_; }
auto MumbleAuthenticatePacket::PacketType() const -> enum PacketType { return PacketType::Authenticate; }
auto MumbleAuthenticatePacket::Message() const -> google::protobuf::Message const& { return authenticate_; }

/*
* Mumble ping packet (ID 3)
Expand Down Expand Up @@ -121,8 +121,8 @@ MumblePingPacket::MumblePingPacket(std::span<const std::byte> buffer) {
ping_.ParseFromArray(buffer.data(), static_cast<int>(bufferSize));
}

PacketType MumblePingPacket::PacketType() const { return PacketType::Ping; }
const google::protobuf::Message& MumblePingPacket::Message() const { return ping_; }
auto MumblePingPacket::PacketType() const -> enum PacketType { return PacketType::Ping; }
auto MumblePingPacket::Message() const -> const google::protobuf::Message& { return ping_; }

/*
* Mumble crypt setup packet (ID 15)
Expand Down Expand Up @@ -159,7 +159,7 @@ MumbleCryptographySetupPacket::MumbleCryptographySetupPacket(std::span<const std
cryptSetup_.ParseFromArray(buffer.data(), static_cast<int>(bufferSize));
}

PacketType MumbleCryptographySetupPacket::PacketType() const { return PacketType::CryptSetup; }
const google::protobuf::Message& MumbleCryptographySetupPacket::Message() const { return cryptSetup_; }
auto MumbleCryptographySetupPacket::PacketType() const -> enum PacketType { return PacketType::CryptSetup; }
auto MumbleCryptographySetupPacket::Message() const -> const google::protobuf::Message& { return cryptSetup_; }

} // namespace libmumble_protocol
96 changes: 58 additions & 38 deletions mumble_protocol/src/packet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,21 @@ enum struct MUMBLE_PROTOCOL_EXPORT PacketType : uint16_t {
SuggestConfig = 25
};

MUMBLE_PROTOCOL_EXPORT std::tuple<PacketType, std::span<const std::byte> >
ParseNetworkBuffer(std::span<const std::byte, kMaxPacketLength>);
MUMBLE_PROTOCOL_EXPORT auto ParseNetworkBuffer(
std::span<const std::byte, kMaxPacketLength>) -> std::tuple<PacketType, std::span<const std::byte>>;

class MUMBLE_PROTOCOL_EXPORT MumbleControlPacket {
public:
virtual ~MumbleControlPacket() = default;

[[nodiscard]] std::size_t Serialize(std::span<std::byte, kMaxPacketLength>) const;
[[nodiscard]] auto Serialize(std::span<std::byte, kMaxPacketLength>) const -> std::size_t;

[[nodiscard]] std::string DebugString() const;
[[nodiscard]] auto DebugString() const -> std::string;

protected:
[[nodiscard]] virtual enum PacketType PacketType() const = 0;
[[nodiscard]] virtual auto PacketType() const -> PacketType = 0;

[[nodiscard]] virtual google::protobuf::Message const& Message() const = 0;
[[nodiscard]] virtual auto Message() const -> google::protobuf::Message const& = 0;
};

//
Expand Down Expand Up @@ -122,9 +122,9 @@ class MumbleVersion {
return result;
}

[[nodiscard]] std::uint16_t major() const { return major_; }
[[nodiscard]] std::uint16_t minor() const { return minor_; }
[[nodiscard]] std::uint16_t patch() const { return patch_; }
[[nodiscard]] auto major() const { return major_; }
[[nodiscard]] auto minor() const { return minor_; }
[[nodiscard]] auto patch() const { return patch_; }

void parse(const std::uint64_t version) {
major_ = static_cast<std::uint16_t>((version & 0xffff'0000'0000'0000) >> 48);
Expand All @@ -133,76 +133,90 @@ class MumbleVersion {
}
};

class MUMBLE_PROTOCOL_EXPORT MumbleVersionPacket : public MumbleControlPacket {
class MUMBLE_PROTOCOL_EXPORT MumbleVersionPacket final : public MumbleControlPacket {
public:
MumbleVersionPacket(MumbleVersion mumble_version, std::string_view release, std::string_view operating_system,
std::string_view operating_system_version);

explicit MumbleVersionPacket(std::span<const std::byte>);

MumbleVersionPacket(const MumbleVersionPacket& other) = default;
MumbleVersionPacket(MumbleVersionPacket&& other) noexcept = default;
auto operator=(const MumbleVersionPacket& other) -> MumbleVersionPacket& = default;
auto operator=(MumbleVersionPacket&& other) noexcept -> MumbleVersionPacket& = default;

~MumbleVersionPacket() override = default;

std::uint16_t majorVersion() const { return mumbleVersion_.major(); }
auto majorVersion() const { return mumbleVersion_.major(); }

std::uint16_t minorVersion() const { return mumbleVersion_.minor(); }
auto minorVersion() const { return mumbleVersion_.minor(); }

std::uint16_t patchVersion() const { return mumbleVersion_.patch(); }
auto patchVersion() const { return mumbleVersion_.patch(); }

std::string_view release() const { return version_.release(); }
auto release() const -> std::string_view { return version_.release(); }

std::string_view operatingSystem() const { return version_.os(); }
auto operatingSystem() const -> std::string_view { return version_.os(); }

std::string_view operatingSystemVersion() const { return version_.os_version(); }
auto operatingSystemVersion() const -> std::string_view { return version_.os_version(); }

protected:
enum PacketType PacketType() const override;
auto PacketType() const -> enum PacketType override;

google::protobuf::Message const& Message() const override;
auto Message() const -> google::protobuf::Message const& override;

private:
MumbleProto::Version version_;
MumbleVersion mumbleVersion_;
};

class MUMBLE_PROTOCOL_EXPORT MumbleAuthenticatePacket : public MumbleControlPacket {
class MUMBLE_PROTOCOL_EXPORT MumbleAuthenticatePacket final : public MumbleControlPacket {
public:
MumbleAuthenticatePacket(std::string_view username, std::string_view password,
const std::vector<std::string_view>& tokens);

explicit MumbleAuthenticatePacket(std::span<const std::byte>);

MumbleAuthenticatePacket(const MumbleAuthenticatePacket& other) = default;
MumbleAuthenticatePacket(MumbleAuthenticatePacket&& other) noexcept = default;
auto operator=(const MumbleAuthenticatePacket& other) -> MumbleAuthenticatePacket& = default;
auto operator=(MumbleAuthenticatePacket&& other) noexcept -> MumbleAuthenticatePacket& = default;

~MumbleAuthenticatePacket() override = default;

std::string_view username() const { return authenticate_.username(); }
auto username() const -> std::string_view { return authenticate_.username(); }

std::string_view password() const { return authenticate_.password(); }
auto password() const -> std::string_view { return authenticate_.password(); }

std::vector<std::string_view> tokens() const {
auto tokens() const -> std::vector<std::string_view> {
std::vector<std::string_view> result;
result.reserve(authenticate_.tokens_size());
for (const auto& token : authenticate_.tokens()) { result.emplace_back(token); }
for (const auto& token : authenticate_.tokens()) {
result.emplace_back(token);
}
return result;
};

std::vector<std::int32_t> celtVersions() const {
auto celtVersions() const -> std::vector<std::int32_t> {
std::vector<std::int32_t> result;
result.reserve(authenticate_.celt_versions_size());
for (const auto celtVersion : authenticate_.celt_versions()) { result.push_back(celtVersion); }
for (const auto celtVersion : authenticate_.celt_versions()) {
result.push_back(celtVersion);
}
return result;
}

bool opusSupported() const { return authenticate_.opus(); }
auto opusSupported() const { return authenticate_.opus(); }

protected:
enum PacketType PacketType() const override;
auto PacketType() const -> enum PacketType override;

google::protobuf::Message const& Message() const override;
auto Message() const -> google::protobuf::Message const& override;

private:
MumbleProto::Authenticate authenticate_;
};

class MUMBLE_PROTOCOL_EXPORT MumblePingPacket : public MumbleControlPacket {
class MUMBLE_PROTOCOL_EXPORT MumblePingPacket final : public MumbleControlPacket {
public:
explicit MumblePingPacket(std::uint64_t);

Expand All @@ -214,31 +228,37 @@ class MUMBLE_PROTOCOL_EXPORT MumblePingPacket : public MumbleControlPacket {
explicit MumblePingPacket(std::span<const std::byte>);

protected:
enum PacketType PacketType() const override;
auto PacketType() const -> enum PacketType override;

const google::protobuf::Message& Message() const override;
auto Message() const -> const google::protobuf::Message& override;

private:
MumbleProto::Ping ping_;
};

class MumbleCryptographySetupPacket : public MumbleControlPacket {
class MUMBLE_PROTOCOL_EXPORT MumbleCryptographySetupPacket final : public MumbleControlPacket {
public:
MumbleCryptographySetupPacket(std::span<const std::byte>& key, std::span<const std::byte>& client_nonce,
std::span<const std::byte>& server_nonce);

explicit MumbleCryptographySetupPacket(std::span<const std::byte>);

std::span<const std::byte> key() const { return as_bytes(std::span(cryptSetup_.key())); }
auto key() const -> std::span<const std::byte> {
return as_bytes(std::span(cryptSetup_.key()));
}

std::span<const std::byte> clientNonce() const { return as_bytes(std::span(cryptSetup_.client_nonce())); }
auto clientNonce() const -> std::span<const std::byte> {
return as_bytes(std::span(cryptSetup_.client_nonce()));
}

std::span<const std::byte> serverNonce() const { return as_bytes(std::span(cryptSetup_.server_nonce())); }
auto serverNonce() const -> std::span<const std::byte> {
return as_bytes(std::span(cryptSetup_.server_nonce()));
}

protected:
enum PacketType PacketType() const override;
auto PacketType() const -> enum PacketType override;

const google::protobuf::Message& Message() const override;
auto Message() const -> const google::protobuf::Message& override;

private:
MumbleProto::CryptSetup cryptSetup_;
Expand All @@ -247,7 +267,7 @@ class MumbleCryptographySetupPacket : public MumbleControlPacket {
} // namespace libmumble_protocol

template <>
struct std::formatter<libmumble_protocol::PacketType> : public std::formatter<std::uint16_t> {
struct std::formatter<libmumble_protocol::PacketType> : std::formatter<std::uint16_t> {
auto format(const libmumble_protocol::PacketType& packet_type, std::format_context& ctx) const {
return std::formatter<std::uint16_t>::format(static_cast<uint16_t>(packet_type), ctx);
}
Expand Down
8 changes: 7 additions & 1 deletion mumble_protocol/src/pimpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ class Pimpl {
Pimpl();

template <typename... Args>
Pimpl(Args&&...);
explicit Pimpl(Args&&...);

Pimpl(const Pimpl& other) = delete;
Pimpl(Pimpl&& other) noexcept = default;

auto operator=(const Pimpl& other) -> Pimpl& = delete;
auto operator=(Pimpl&& other) noexcept -> Pimpl& = default;

~Pimpl();

Expand Down
6 changes: 3 additions & 3 deletions mumble_protocol/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct MumbleServer::Impl final {
const std::uint16_t thread_count =
concurrency != 0 ? concurrency : static_cast<std::uint16_t>(std::jthread::hardware_concurrency());
for (std::size_t i = 0; i < thread_count; ++i) {
thread_handles.emplace_back(&asio::io_context::run, &io_context);
thread_handles.emplace_back([this] { io_context.run(); });
}
}

Expand All @@ -43,8 +43,8 @@ struct MumbleServer::Impl final {
};

MumbleServer::MumbleServer(ServerStatePersistence& server_state_persistance, const std::filesystem::path& certificate,
const std::filesystem::path& key_file, std::uint16_t concurrency)
: pimpl_(server_state_persistance, certificate, key_file, concurrency) {}
const std::filesystem::path& key_file, std::uint16_t concurrency) : pimpl_(
server_state_persistance, certificate, key_file, concurrency) {}

MumbleServer::~MumbleServer() = default;

Expand Down
2 changes: 0 additions & 2 deletions mumble_protocol/src/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ class MUMBLE_PROTOCOL_EXPORT MumbleServer final {
const std::filesystem::path& key_file, std::uint16_t concurrency = 0);

MumbleServer(const MumbleServer& other) = delete;

MumbleServer(MumbleServer&& other) noexcept = delete;

auto operator=(const MumbleServer& other) -> MumbleServer& = delete;

auto operator=(MumbleServer&& other) noexcept -> MumbleServer& = delete;

~MumbleServer();
Expand Down
Loading

0 comments on commit 910d069

Please sign in to comment.