Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Oct 16, 2024
2 parents 68b0470 + f8cff74 commit b55d480
Show file tree
Hide file tree
Showing 55 changed files with 2,477 additions and 1,649 deletions.
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@
"chacha",
"nullopt",
"chrono",
"ciphersuite"
"ciphersuite",
"rmap",
"WSAPOLLFD"
],
"flagWords": [
"hte"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:noble@sha256:b359f1067efa76f37863778f7b6d0e8d911e3ee8efa807ad01fbf5dc1ef9006b
FROM ubuntu:noble@sha256:d4f6f70979d0758d7a6f81e34a61195677f4f4fa576eaf808b79f17499fd93d1

RUN apt-get update && apt-get install --no-install-recommends -y libssl-dev zlib1g-dev libopus-dev cmake pkg-config g++ gcc git make && apt-get clean && rm -rf /var/lib/apt/lists/*

Expand Down
3 changes: 2 additions & 1 deletion buildtools/classes/Generator/SyncGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function checkForChanges(): bool
*/
public function generateHeaderDef(string $returnType, string $currentFunction, string $parameters, string $noDefaults, string $parameterTypes, string $parameterNames): string
{
return "$returnType {$currentFunction}_sync($parameters);\n\n";
return "DPP_DEPRECATED(\"Please use coroutines instead of sync functions: https://dpp.dev/coro-introduction.html\") $returnType {$currentFunction}_sync($parameters);\n\n";
}

/**
Expand All @@ -107,6 +107,7 @@ public function getCommentArray(): array
return [
" * \memberof dpp::cluster",
" * @throw dpp::rest_exception upon failure to execute REST function",
" * @deprecated This function is deprecated, please use coroutines instead.",
" * @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.",
" * Avoid direct use of this function inside an event handler.",
];
Expand Down
9 changes: 7 additions & 2 deletions docpages/advanced_reference/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

At present our roadmap is:

*Short term (6 months):*: Stabilise coroutine support and release it as stable a feature
## Short term (1 month)
* Implement user apps support

*Long term*: Continue development of the library to implement Discord new features as they add them. Discord does not share their internal roadmap with library developers, so we are informed of these new features shortly before they become public given enough time to implement them. This is our permanent ongoing goal.
## Medium term (6 months)
* Stabilise DAVE E2EE support and release it as stable a feature

## Long term
* Continue development of the library to implement Discord new features as they add them. Discord does not share their internal roadmap with library developers, so we are informed of these new features shortly before they become public given enough time to implement them. This is our permanent ongoing goal.
618 changes: 410 additions & 208 deletions include/dpp/cluster_sync_calls.h

Large diffs are not rendered by default.

62 changes: 58 additions & 4 deletions include/dpp/discordvoiceclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ enum voice_websocket_opcode_t : uint8_t {
voice_opcode_connection_hello = 8,
voice_opcode_connection_resumed = 9,
voice_opcode_multiple_clients_connect = 11,
voice_opcode_client_connect = 12,
voice_opcode_client_disconnect = 13,
voice_opcode_media_sink = 15,
voice_client_flags = 18,
Expand All @@ -167,7 +166,7 @@ enum voice_websocket_opcode_t : uint8_t {
voice_client_dave_mls_key_package = 26,
voice_client_dave_mls_proposals = 27,
voice_client_dave_mls_commit_message = 28,
voice_client_dave_announce_commit_transaction = 29,
voice_client_dave_announce_commit_transition = 29,
voice_client_dave_mls_welcome = 30,
voice_client_dave_mls_invalid_commit_welcome = 31,
};
Expand Down Expand Up @@ -207,7 +206,7 @@ struct dave_binary_header_t {
[[nodiscard]] std::vector<uint8_t> get_data() const;

/**
* Get transition ID for process_welcome
* Get transition ID for process_commit and process_welcome
*
* @return Transition ID
*/
Expand All @@ -216,7 +215,7 @@ struct dave_binary_header_t {
private:
/**
* @brief Transition id, only valid when the opcode is
* welcome state. Use get_transition_id() to obtain value.
* commit and welcome state. Use get_transition_id() to obtain value.
*/
uint16_t transition_id;
};
Expand Down Expand Up @@ -478,6 +477,12 @@ class DPP_EXPORT discord_voice_client : public websocket_client
*/
std::set<std::string> dave_mls_user_list;

/**
* @brief The list of users that have left the voice channel but
* not yet removed from MLS group.
*/
std::set<std::string> dave_mls_pending_remove_list;

/**
* @brief File descriptor for UDP connection
*/
Expand Down Expand Up @@ -579,6 +584,13 @@ class DPP_EXPORT discord_voice_client : public websocket_client
*/
dave_version_t dave_version;

/**
* @brief Destination address for where packets go
* on the UDP socket
*/
address_t destination{};


/**
* @brief Send data to UDP socket immediately.
*
Expand Down Expand Up @@ -678,6 +690,12 @@ class DPP_EXPORT discord_voice_client : public websocket_client
*/
size_t encode(uint8_t *input, size_t inDataSize, uint8_t *output, size_t &outDataSize);

/**
* Updates DAVE MLS ratchets for users in the VC
* @param force True to force updating of ratchets regardless of state
*/
void update_ratchets(bool force = false);

public:

/**
Expand Down Expand Up @@ -1184,6 +1202,42 @@ class DPP_EXPORT discord_voice_client : public websocket_client
* which internally uses scrypt.
*/
void get_user_privacy_code(const dpp::snowflake user, privacy_code_callback_t callback) const;

/**
* @brief Notify gateway ready for a DAVE transition.
*
* Fires Voice Ready event when appropriate.
*
* https://daveprotocol.com/#commit-handling
*
* @param data Websocket frame data
*/
void ready_for_transition(const std::string &data);

/**
* @brief Reset dave session, send voice_client_dave_mls_invalid_commit_welcome
* payload with current transition Id and our new key package to gateway.
*
* https://daveprotocol.com/#recovery-from-invalid-commit-or-welcome
*/
void recover_from_invalid_commit_welcome();

/**
* @brief Execute pending protocol upgrade/downgrade to/from dave.
* @return true if did an upgrade/downgrade
*/
bool execute_pending_upgrade_downgrade();

/**
* @brief Reset dave session and prepare initial session group.
*/
void reinit_dave_mls_group();

/**
* @brief Process roster map from commit/welcome.
* @param rmap Roster map
*/
void process_mls_group_rosters(const std::map<uint64_t, std::vector<uint8_t>>& rmap);
};

} // namespace dpp
Expand Down
37 changes: 29 additions & 8 deletions include/dpp/dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <sys/types.h>
#include <string>
#include <unordered_map>
#include <cstring>
#include <dpp/socket.h>

namespace dpp {

Expand All @@ -40,23 +42,42 @@ namespace dpp {
*/
struct dns_cache_entry {
/**
* @brief Resolved address information
* @brief Resolved address metadata
*/
addrinfo addr;

/**
* @brief Socket address.
* Discord only supports ipv4, but sockaddr_in6 is larger
* than sockaddr_in, sockaddr_storage will hold either. This
* means that if discord ever do support ipv6 we just flip
* one value in dns.cpp and that should be all that is needed.
* @brief Resolved address as string.
* The metadata is needed to know what type of address it is.
* Do not do silly stuff like just looking to see if '.' is in it!
*/
sockaddr_storage ai_addr;
std::string resolved_addr;

/**
* @brief Time at which this cache entry is invalidated
*/
time_t expire_timestamp;

/**
* @brief Get address length
* @return address length
*/
[[nodiscard]] int size() const;

/**
* @brief Get the address_t that corresponds to this cache entry
* for use when connecting with ::connect()
* @param port Port number to connect to
* @return address_t prefilled with the IP and port number
*/
[[nodiscard]] const address_t get_connecting_address(uint16_t port) const;

/**
* @brief Allocate a socket file descriptor for the given dns address
* @return File descriptor ready for calling connect(), or INVALID_SOCKET
* on failure.
*/
[[nodiscard]] socket make_connecting_socket() const;
};

/**
Expand All @@ -73,4 +94,4 @@ namespace dpp {
* @throw dpp::connection_exception On failure to resolve hostname
*/
const dns_cache_entry* resolve_hostname(const std::string& hostname, const std::string& port);
} // namespace dpp
}
135 changes: 130 additions & 5 deletions include/dpp/socket.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,53 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once

#include <dpp/export.h>
#ifdef _WIN32
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <io.h>
#define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout)
#define pollfd WSAPOLLFD
#else
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#endif
#include <string_view>
#include <cstdint>


namespace dpp
{
/**
* @brief Represents a socket file descriptor.
* This is used to ensure parity between windows and unix-like systems.
*/
/**
* @brief Represents a socket file descriptor.
* This is used to ensure parity between windows and unix-like systems.
*/
#ifndef _WIN32
using socket = int;
#else
using socket = SOCKET;
#endif
} // namespace dpp

#ifndef SOCKET_ERROR
/**
Expand All @@ -26,3 +62,92 @@ namespace dpp
*/
#define INVALID_SOCKET ~0
#endif

/**
* @brief Represents an IPv4 address for use with socket functions such as
* bind().
*
* Avoids type punning with C style casts from sockaddr_in to sockaddr pointers.
*/
class DPP_EXPORT address_t {
/**
* @brief Internal sockaddr struct
*/
sockaddr socket_addr{};

public:

/**
* @brief Create a new address_t
* @param ip IPv4 address
* @param port Port number
* @note Leave both as defaults to create a default bind-to-any setting
*/
address_t(const std::string_view ip = "0.0.0.0", uint16_t port = 0);

/**
* @brief Get sockaddr
* @return sockaddr pointer
*/
[[nodiscard]] sockaddr *get_socket_address();

/**
* @brief Returns size of sockaddr_in
* @return sockaddr_in size
* @note It is important the size this returns is sizeof(sockaddr_in) not
* sizeof(sockaddr), this is NOT a bug but requirement of C socket functions.
*/
[[nodiscard]] size_t size();

/**
* @brief Get the port bound to a file descriptor
* @param fd File descriptor
* @return Port number, or 0 if no port bound
*/
[[nodiscard]] uint16_t get_port(socket fd);
};

/**
* @brief Allocates a dpp::socket, closing it on destruction
*/
struct DPP_EXPORT raii_socket {
/**
* @brief File descriptor
*/
socket fd;

/**
* @brief Construct a socket.
* Calls socket() and returns a new file descriptor
*/
raii_socket();

/**
* @brief Non-copyable
*/
raii_socket(raii_socket&) = delete;

/**
* @brief Non-movable
*/
raii_socket(raii_socket&&) = delete;

/**
* @brief Non-copyable
*/
raii_socket operator=(raii_socket&) = delete;

/**
* @brief Non-movable
*/
raii_socket operator=(raii_socket&&) = delete;

/**
* @brief Destructor
* Frees the socket by closing it
*/
~raii_socket();
};


}
8 changes: 4 additions & 4 deletions include/dpp/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
************************************************************************************/
#pragma once

#if !defined(DPP_VERSION_LONG)
#define DPP_VERSION_LONG 0x00100032
#define DPP_VERSION_SHORT 100032
#define DPP_VERSION_TEXT "D++ 10.0.32 (22-Sep-2024)"
#ifndef DPP_VERSION_LONG
#define DPP_VERSION_LONG 0x00100033
#define DPP_VERSION_SHORT 100033
#define DPP_VERSION_TEXT "D++ 10.0.33 (13-Oct-2024)"

#define DPP_VERSION_MAJOR ((DPP_VERSION_LONG & 0x00ff0000) >> 16)
#define DPP_VERSION_MINOR ((DPP_VERSION_LONG & 0x0000ff00) >> 8)
Expand Down
Loading

0 comments on commit b55d480

Please sign in to comment.