Compare commits
1
Commits
499143050b
...
583e4e752d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
583e4e752d |
No files matched your search
@@ -51,6 +51,13 @@ namespace Echoion::Core
|
||||
configManager_ = cfg;
|
||||
}
|
||||
|
||||
// Re-apply network settings (proxy) to every outbound client:
|
||||
// the HTTP NetworkClient (YouTube Data API, URL shortener), the
|
||||
// yt-dlp subprocess, and the ffmpeg AudioDecoder. Call after a
|
||||
// config reload so proxy changes actually take effect everywhere
|
||||
// instead of only living in the config copy.
|
||||
void applyNetworkConfig(const Api::NetworkConfig& network);
|
||||
|
||||
[[nodiscard]] Api::Result<std::string>
|
||||
play(const std::string& query, uint64_t clientId);
|
||||
[[nodiscard]] Api::Result<void> pause();
|
||||
|
||||
+18
-2
@@ -830,8 +830,11 @@ namespace Echoion::Core
|
||||
commandManager_->setServerConfig(config);
|
||||
}
|
||||
|
||||
// Re-apply the network proxy from config (idempotent store).
|
||||
if (networkClient_) {
|
||||
// Re-apply network settings to every outbound client (NetworkClient,
|
||||
// yt-dlp, ffmpeg), not just the HTTP client.
|
||||
if (musicManager_) {
|
||||
musicManager_->applyNetworkConfig(config.network);
|
||||
} else if (networkClient_) {
|
||||
networkClient_->setProxy(config.network.proxy);
|
||||
}
|
||||
|
||||
@@ -898,12 +901,25 @@ namespace Echoion::Core
|
||||
// Update local config
|
||||
config_ = *configResult;
|
||||
|
||||
// Keep the shared ConfigManager in sync so components that read through
|
||||
// it (cookies, API key, etc.) see the reloaded values.
|
||||
configManager_.updateConfig(config_, false);
|
||||
|
||||
// Update components with new config
|
||||
if (commandManager_) {
|
||||
commandManager_->setPrefix(config_.bot.commandPrefix);
|
||||
commandManager_->setServerConfig(config_);
|
||||
}
|
||||
|
||||
// Re-apply network settings so a proxy edit actually reaches every
|
||||
// outbound client (HTTP NetworkClient, yt-dlp, ffmpeg) — not just the
|
||||
// config copy. Without this the YouTube API kept using the old/no proxy.
|
||||
if (musicManager_) {
|
||||
musicManager_->applyNetworkConfig(config_.network);
|
||||
} else if (networkClient_) {
|
||||
networkClient_->setProxy(config_.network.proxy);
|
||||
}
|
||||
|
||||
Void::Log::info("Core", "{}", "Configuration reloaded from disk");
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -128,6 +128,36 @@ namespace Echoion::Core
|
||||
return {};
|
||||
}
|
||||
|
||||
void MusicManager::applyNetworkConfig(const Api::NetworkConfig& network)
|
||||
{
|
||||
// Push the (possibly changed) proxy to every outbound client. Passing
|
||||
// the optional straight through also clears the proxy everywhere when
|
||||
// it is disabled/removed in the config.
|
||||
const auto& proxy = network.proxy;
|
||||
const bool enabled = proxy.has_value() && proxy->enabled();
|
||||
|
||||
if (networkClient_) {
|
||||
networkClient_->setProxy(proxy);
|
||||
}
|
||||
if (youTubeClient_) {
|
||||
youTubeClient_->setProxyConfig(proxy);
|
||||
}
|
||||
if (audioDecoder_) {
|
||||
audioDecoder_->setProxyConfig(proxy);
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
Void::Log::info("MusicManager", "{}", std::format(
|
||||
"Network config re-applied: {} proxy {}:{}",
|
||||
(proxy->kind == Void::Net::ProxyConfig::Kind::Socks5) ? "SOCKS5"
|
||||
: "HTTP",
|
||||
proxy->host, proxy->port));
|
||||
} else {
|
||||
Void::Log::info("MusicManager", "{}",
|
||||
"Network config re-applied: proxy disabled");
|
||||
}
|
||||
}
|
||||
|
||||
void MusicManager::shutdown()
|
||||
{
|
||||
isPlaying_ = false;
|
||||
|
||||
+13
-2
@@ -13,7 +13,10 @@ namespace Echoion::Core
|
||||
Api::Result<void> NetworkClient::initialize(
|
||||
const std::optional<Void::Net::ProxyConfig>& proxy)
|
||||
{
|
||||
proxy_ = proxy;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
proxy_ = proxy;
|
||||
}
|
||||
initialized_ = true;
|
||||
Void::Log::info("NetworkClient", "{}", std::format("NetworkClient initialized (proxy: {})",
|
||||
proxy.has_value() ? "enabled" : "disabled"));
|
||||
@@ -26,7 +29,15 @@ namespace Echoion::Core
|
||||
NetworkClient::executeRequest(const Void::Net::Request& req)
|
||||
{
|
||||
Void::Net::HttpClient client;
|
||||
const auto active = proxy_;
|
||||
// Snapshot the proxy under the lock. setProxy()/initialize() can run on
|
||||
// other threads (config reload, init), and a torn read of the
|
||||
// optional<ProxyConfig> (it holds std::string host/user/pass) could
|
||||
// yield an empty host -> enabled()==false -> a silent direct connection.
|
||||
std::optional<Void::Net::ProxyConfig> active;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
active = proxy_;
|
||||
}
|
||||
if (active && active->enabled()) {
|
||||
client.set_proxy(*active);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user