Fixed windows build

This commit is contained in:
WolverinDEV 2020-04-18 00:46:45 +02:00
parent 17d2d7ae56
commit 65dad8e9cb
8 changed files with 42 additions and 38 deletions

View File

@ -8,10 +8,12 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
#include <memory> #include <memory>
#include <mutex>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include <cstdint> #include <functional>
#include <any> #include <any>
#include <array>
#include "misc/spin_lock.h" #include "misc/spin_lock.h"
#include "converters/converter.h" #include "converters/converter.h"
@ -466,9 +468,17 @@ namespace ts {
*/ */
namespace impl { namespace impl {
template <typename... Properties> constexpr inline auto property_count() {
constexpr auto make_property_array(Properties&&... props) noexcept { size_t result{0};
return std::array<std::common_type_t<Properties...>, sizeof...(Properties)>{std::forward<Properties>(props)...}; result += VIRTUALSERVER_ENDMARKER;
result += CHANNEL_ENDMARKER;
result += CLIENT_ENDMARKER;
result += GROUP_ENDMARKER;
result += SERVERINSTANCE_ENDMARKER;
result += CONNECTION_ENDMARKER;
result += PLAYLIST_ENDMARKER;
result += UNKNOWN_ENDMARKER;
return result;
} }
extern bool validateInput(const std::string& input, ValueType type); extern bool validateInput(const std::string& input, ValueType type);
@ -539,19 +549,7 @@ namespace ts {
}; };
#ifdef EXTERNALIZE_PROPERTY_DEFINITIONS #ifdef EXTERNALIZE_PROPERTY_DEFINITIONS
constexpr inline auto property_count() { extern std::array<PropertyDescription, impl::property_count()> property_list;
size_t result{0};
result += VIRTUALSERVER_ENDMARKER;
result += CHANNEL_ENDMARKER;
result += CLIENT_ENDMARKER;
result += GROUP_ENDMARKER;
result += SERVERINSTANCE_ENDMARKER;
result += CONNECTION_ENDMARKER;
result += PLAYLIST_ENDMARKER;
result += UNKNOWN_ENDMARKER;
return result;
}
extern std::array<PropertyDescription, property_count()> property_list;
#else #else
#include "./PropertyDefinition.h" #include "./PropertyDefinition.h"
@ -784,7 +782,7 @@ namespace ts {
[[nodiscard]] const property::PropertyDescription& type() const { return *this->data_ptr->description; } [[nodiscard]] const property::PropertyDescription& type() const { return *this->data_ptr->description; }
[[nodiscard]] std::string value() const { [[nodiscard]] std::string value() const {
std::lock_guard lock(this->data_ptr->value_lock); std::lock_guard lock{this->data_ptr->value_lock};
return this->data_ptr->value; return this->data_ptr->value;
} }

View File

@ -14,7 +14,7 @@ decltype(property::property_list) property::
#else #else
constexpr auto constexpr auto
#endif #endif
property_list = property::impl::make_property_array( property_list = std::array<PropertyDescription, impl::property_count()>{
PropertyDescription{UNKNOWN_UNDEFINED, "undefined", "", TYPE_UNKNOWN, 0}, PropertyDescription{UNKNOWN_UNDEFINED, "undefined", "", TYPE_UNKNOWN, 0},
/* virtual server properties */ /* virtual server properties */
@ -347,7 +347,7 @@ property_list = property::impl::make_property_array(
PropertyDescription{PLAYLIST_FLAG_FINISHED, "playlist_flag_finished", "0", TYPE_BOOL, FLAG_PLAYLIST_VARIABLE | FLAG_USER_EDITABLE | FLAG_SAVE}, PropertyDescription{PLAYLIST_FLAG_FINISHED, "playlist_flag_finished", "0", TYPE_BOOL, FLAG_PLAYLIST_VARIABLE | FLAG_USER_EDITABLE | FLAG_SAVE},
PropertyDescription{PLAYLIST_REPLAY_MODE, "playlist_replay_mode", "0", TYPE_UNSIGNED_NUMBER, FLAG_PLAYLIST_VARIABLE | FLAG_USER_EDITABLE | FLAG_SAVE}, PropertyDescription{PLAYLIST_REPLAY_MODE, "playlist_replay_mode", "0", TYPE_UNSIGNED_NUMBER, FLAG_PLAYLIST_VARIABLE | FLAG_USER_EDITABLE | FLAG_SAVE},
PropertyDescription{PLAYLIST_CURRENT_SONG_ID, "playlist_current_song_id", "0", TYPE_UNSIGNED_NUMBER, FLAG_PLAYLIST_VARIABLE | FLAG_SAVE} PropertyDescription{PLAYLIST_CURRENT_SONG_ID, "playlist_current_song_id", "0", TYPE_UNSIGNED_NUMBER, FLAG_PLAYLIST_VARIABLE | FLAG_SAVE}
); };
#undef str_ #undef str_
#undef V #undef V

View File

@ -1,4 +1,7 @@
#ifndef NO_OPEN_SSL
#define NO_OPEN_SSL #define NO_OPEN_SSL
#endif
#include "./digest.h" #include "./digest.h"
#include <tomcrypt.h> #include <tomcrypt.h>

View File

@ -5,8 +5,10 @@
#include <deque> #include <deque>
#include <vector> #include <vector>
#include <tuple> #include <tuple>
#include <stdexcept>
#ifdef WIN32 #ifdef WIN32
#define _WINSOCK_DEPRECATED_NO_WARNINGS /* gethostbyname is deprecated for windows */
#include <WS2tcpip.h> #include <WS2tcpip.h>
#include <WinSock2.h> #include <WinSock2.h>
#include <Windows.h> #include <Windows.h>

View File

@ -72,7 +72,7 @@ namespace str_obf {
static_assert(sizeof(char_t) == 1, "Currently only 8 bit supported"); static_assert(sizeof(char_t) == 1, "Currently only 8 bit supported");
if(length == 0) return; if(length == 0) return;
if(key.size() == 0) _invalid_key_size(); if(key.size() == 0) _invalid_key_size();
if(key.size() & (key.size() - 1)) _invalid_key_size(); /* key must be an power of 2 */ if(key.size() & (key.size() - 1UL)) _invalid_key_size(); /* key must be an power of 2 */
auto left = length; auto left = length;
size_t key_index{0}; size_t key_index{0};
@ -140,7 +140,7 @@ namespace str_obf {
length = (std::uint64_t) ((internal::rng32_next(rng_base, (uint32_t) seed) >> 12UL) & 0xFFUL); length = (std::uint64_t) ((internal::rng32_next(rng_base, (uint32_t) seed) >> 12UL) & 0xFFUL);
} while(length == 0 || length > power2); } while(length == 0 || length > power2);
return 1U << length; return uint64_t{1} << length;
} }
template <uint64_t line_number, std::uint64_t message_size> template <uint64_t line_number, std::uint64_t message_size>

View File

@ -1,6 +1,7 @@
#include "AcknowledgeManager.h" #include "AcknowledgeManager.h"
#include <cmath> #include <cmath>
#include <misc/endianness.h> #include <misc/endianness.h>
#include <algorithm>
using namespace ts; using namespace ts;
using namespace ts::connection; using namespace ts::connection;
@ -107,7 +108,7 @@ ssize_t AcknowledgeManager::execute_resend(const system_clock::time_point& now ,
} }
} else { } else {
if(entry->next_resend <= now) { if(entry->next_resend <= now) {
entry->next_resend = now + std::chrono::milliseconds{(int64_t) min(ceil(this->rto), 1500.f)}; entry->next_resend = now + std::chrono::milliseconds{(int64_t) std::min(ceil(this->rto), 1500.f)};
need_resend.push_back(entry); need_resend.push_back(entry);
entry->resend_count++; entry->resend_count++;
entry->send_count++; entry->send_count++;
@ -139,7 +140,7 @@ ssize_t AcknowledgeManager::execute_resend(const system_clock::time_point& now ,
/* we're not taking the clock granularity into account because its nearly 1ms and it would only add more branches */ /* we're not taking the clock granularity into account because its nearly 1ms and it would only add more branches */
void AcknowledgeManager::update_rto(size_t r) { void AcknowledgeManager::update_rto(size_t r) {
if(srtt == -1) { if(srtt == -1) {
this->srtt = r; this->srtt = (float) r;
this->rttvar = r / 2.f; this->rttvar = r / 2.f;
this->rto = srtt + 4 * this->rttvar; this->rto = srtt + 4 * this->rttvar;
} else { } else {

View File

@ -15,22 +15,22 @@ void UnorderedPacketLossCalculator::packet_received(uint32_t packet_id) {
if(age < this->packet_history.max_bits()) { if(age < this->packet_history.max_bits()) {
const auto received = this->packet_history.shift_in_bounds(age).count(); const auto received = this->packet_history.shift_in_bounds(age).count();
this->received_packets_ += received; this->received_packets_ += (uint32_t) received;
this->received_packets_total_ += received; this->received_packets_total_ += (uint32_t) received;
this->lost_packets_ += age - received; this->lost_packets_ += (uint32_t) (age - received);
this->lost_packets_total_ += age - received; this->lost_packets_total_ += (uint32_t) (age - received);
} else { } else {
const auto received = this->packet_history.clear().count(); const auto received = this->packet_history.clear().count();
this->received_packets_ += received; this->received_packets_ += (uint32_t) received;
this->received_packets_total_ += received; this->received_packets_total_ += (uint32_t) received;
this->lost_packets_ += this->packet_history.max_bits() - received; this->lost_packets_ += (uint32_t) (this->packet_history.max_bits() - received);
this->lost_packets_total_ += this->packet_history.max_bits() - received; this->lost_packets_total_ += (uint32_t) (this->packet_history.max_bits() - received);
if(age >= this->packet_history.max_bits() * 2) { if(age >= this->packet_history.max_bits() * 2) {
this->packet_history.set_unchecked(0); this->packet_history.set_unchecked(0);
this->lost_packets_ += age - this->packet_history.max_bits() * 2; this->lost_packets_ += (uint32_t) (age - this->packet_history.max_bits() * 2);
this->lost_packets_total_ += age - this->packet_history.max_bits() * 2; this->lost_packets_total_ += (uint32_t) (age - this->packet_history.max_bits() * 2);
} else { } else {
this->packet_history.set_unchecked(age - this->packet_history.max_bits()); this->packet_history.set_unchecked(age - this->packet_history.max_bits());
} }
@ -60,8 +60,8 @@ void UnorderedPacketLossCalculator::short_stats() {
if(packets_passed < target_interval) return; if(packets_passed < target_interval) return;
const auto factor = .5; const auto factor = .5;
this->received_packets_ *= factor; this->received_packets_ = (uint32_t) (this->received_packets_ * factor);
this->lost_packets_ *= factor; this->lost_packets_ = (uint32_t) (this->lost_packets_ * factor);
this->last_history_offset = this->packet_history_offset; this->last_history_offset = this->packet_history_offset;
} }

View File

@ -60,8 +60,8 @@ namespace ts::protocol {
[[nodiscard]] inline uint32_t received_packets_total() const { return this->received_packets_total_; } [[nodiscard]] inline uint32_t received_packets_total() const { return this->received_packets_total_; }
[[nodiscard]] inline uint32_t lost_packets_total() const { return this->lost_packets_total_; } [[nodiscard]] inline uint32_t lost_packets_total() const { return this->lost_packets_total_; }
[[nodiscard]] inline uint32_t unconfirmed_received_packets() const { return this->packet_history.count(); }; [[nodiscard]] inline uint32_t unconfirmed_received_packets() const { return (uint32_t) this->packet_history.count(); };
[[nodiscard]] inline uint32_t unconfirmed_lost_packets() const { return this->packet_history.max_bits() - this->packet_history.count(); }; [[nodiscard]] inline uint32_t unconfirmed_lost_packets() const { return (uint32_t) (this->packet_history.max_bits() - this->packet_history.count()); };
private: private:
uint32_t received_packets_{0}, received_packets_total_{0}, lost_packets_{0}, lost_packets_total_{0}; uint32_t received_packets_{0}, received_packets_total_{0}, lost_packets_{0}, lost_packets_total_{0};