mirror of
https://git.eden-emu.dev/archive/citron
synced 2026-03-22 17:46:08 -04:00
revert c575341d1e
revert Merge pull request 'fix(multiplayer): Race Condition during Packet Discovery' (#101) from fix/lan_discovery_race_condition into main Reviewed-on: https://git.citron-emu.org/Citron/Emulator/pulls/101
This commit is contained in:
@@ -77,8 +77,6 @@ void LANDiscovery::SetState(State new_state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result LANDiscovery::GetNetworkInfo(NetworkInfo& out_network) const {
|
Result LANDiscovery::GetNetworkInfo(NetworkInfo& out_network) const {
|
||||||
// Lock must be held while copying to prevent the Network thread from corrupting the copy
|
|
||||||
std::scoped_lock lock{packet_mutex};
|
|
||||||
if (state == State::AccessPointCreated || state == State::StationConnected) {
|
if (state == State::AccessPointCreated || state == State::StationConnected) {
|
||||||
std::memcpy(&out_network, &network_info, sizeof(network_info));
|
std::memcpy(&out_network, &network_info, sizeof(network_info));
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
@@ -119,7 +117,7 @@ Result LANDiscovery::Scan(std::span<NetworkInfo> out_networks, s16& out_count,
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO(Service_LDN, "Waiting for scan replies");
|
LOG_INFO(Service_LDN, "Waiting for scan replies");
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
|
||||||
std::scoped_lock lock{packet_mutex};
|
std::scoped_lock lock{packet_mutex};
|
||||||
for (const auto& [key, info] : scan_results) {
|
for (const auto& [key, info] : scan_results) {
|
||||||
@@ -569,19 +567,10 @@ void LANDiscovery::ReceivePacket(const Network::LDNPacket& packet) {
|
|||||||
}
|
}
|
||||||
case Network::LDNPacketType::SyncNetwork: {
|
case Network::LDNPacketType::SyncNetwork: {
|
||||||
if (state == State::StationOpened || state == State::StationConnected) {
|
if (state == State::StationOpened || state == State::StationConnected) {
|
||||||
if (packet.data.size() < sizeof(NetworkInfo)) {
|
LOG_INFO(Frontend, "SyncNetwork packet received!");
|
||||||
LOG_ERROR(Service_LDN, "SyncNetwork packet too small!");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
NetworkInfo info{};
|
NetworkInfo info{};
|
||||||
std::memcpy(&info, packet.data.data(), sizeof(NetworkInfo));
|
std::memcpy(&info, packet.data.data(), sizeof(NetworkInfo));
|
||||||
|
|
||||||
if (info.ldn.node_count == 0) {
|
|
||||||
LOG_ERROR(Service_LDN, "SyncNetwork reported 0 nodes! Ignoring to prevent SDK crash.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
OnSyncNetwork(info);
|
OnSyncNetwork(info);
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(Frontend, "SyncNetwork packet received but in wrong State!");
|
LOG_INFO(Frontend, "SyncNetwork packet received but in wrong State!");
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ protected:
|
|||||||
static constexpr Ssid fake_ssid{"CitronFakeSsidForLdn"};
|
static constexpr Ssid fake_ssid{"CitronFakeSsidForLdn"};
|
||||||
|
|
||||||
bool inited{};
|
bool inited{};
|
||||||
mutable std::mutex packet_mutex;
|
std::mutex packet_mutex;
|
||||||
std::array<LanStation, StationCountMax> stations;
|
std::array<LanStation, StationCountMax> stations;
|
||||||
std::array<NodeLatestUpdate, NodeCountMax> node_changes{};
|
std::array<NodeLatestUpdate, NodeCountMax> node_changes{};
|
||||||
std::array<u8, NodeCountMax> node_last_states{};
|
std::array<u8, NodeCountMax> node_last_states{};
|
||||||
|
|||||||
Reference in New Issue
Block a user