mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-18 04:49:57 +00:00
Address some review comments
This commit is contained in:
parent
aa11d73bba
commit
4213f1c126
7 changed files with 38 additions and 52 deletions
|
@ -35,12 +35,9 @@ void LanStation::OverrideInfo() {
|
|||
|
||||
LANDiscovery::LANDiscovery(Network::RoomNetwork& room_network_)
|
||||
: stations({{{1, this}, {2, this}, {3, this}, {4, this}, {5, this}, {6, this}, {7, this}}}),
|
||||
room_network{room_network_} {
|
||||
LOG_INFO(Service_LDN, "LANDiscovery");
|
||||
}
|
||||
room_network{room_network_} {}
|
||||
|
||||
LANDiscovery::~LANDiscovery() {
|
||||
LOG_INFO(Service_LDN, "~LANDiscovery");
|
||||
if (inited) {
|
||||
Result rc = Finalize();
|
||||
LOG_INFO(Service_LDN, "Finalize: {}", rc.raw);
|
||||
|
@ -62,7 +59,7 @@ void LANDiscovery::InitNetworkInfo() {
|
|||
}
|
||||
|
||||
void LANDiscovery::InitNodeStateChange() {
|
||||
for (auto& node_update : nodeChanges) {
|
||||
for (auto& node_update : node_changes) {
|
||||
node_update.state_change = NodeStateChange::None;
|
||||
}
|
||||
for (auto& node_state : node_last_states) {
|
||||
|
@ -97,8 +94,8 @@ Result LANDiscovery::GetNetworkInfo(NetworkInfo& out_network,
|
|||
if (state == State::AccessPointCreated || state == State::StationConnected) {
|
||||
std::memcpy(&out_network, &network_info, sizeof(network_info));
|
||||
for (std::size_t i = 0; i < buffer_count; i++) {
|
||||
out_updates[i].state_change = nodeChanges[i].state_change;
|
||||
nodeChanges[i].state_change = NodeStateChange::None;
|
||||
out_updates[i].state_change = node_changes[i].state_change;
|
||||
node_changes[i].state_change = NodeStateChange::None;
|
||||
}
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -168,9 +165,9 @@ Result LANDiscovery::Scan(std::vector<NetworkInfo>& networks, u16& count,
|
|||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result LANDiscovery::SetAdvertiseData(std::vector<u8>& data) {
|
||||
Result LANDiscovery::SetAdvertiseData(std::span<const u8> data) {
|
||||
std::scoped_lock lock{packet_mutex};
|
||||
std::size_t size = data.size();
|
||||
const std::size_t size = data.size();
|
||||
if (size > AdvertiseDataSizeMax) {
|
||||
return ResultAdvertiseDataTooLarge;
|
||||
}
|
||||
|
@ -288,7 +285,7 @@ Result LANDiscovery::DestroyNetwork() {
|
|||
ResetStations();
|
||||
|
||||
SetState(State::AccessPointOpened);
|
||||
LanEvent();
|
||||
lan_event();
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
@ -323,12 +320,12 @@ Result LANDiscovery::Disconnect() {
|
|||
}
|
||||
|
||||
SetState(State::StationOpened);
|
||||
LanEvent();
|
||||
lan_event();
|
||||
|
||||
return ResultSuccess;
|
||||
}
|
||||
|
||||
Result LANDiscovery::Initialize(LanEventFunc lan_event, bool listening) {
|
||||
Result LANDiscovery::Initialize(LanEventFunc lan_event_, bool listening) {
|
||||
std::scoped_lock lock{packet_mutex};
|
||||
if (inited) {
|
||||
return ResultSuccess;
|
||||
|
@ -341,7 +338,7 @@ Result LANDiscovery::Initialize(LanEventFunc lan_event, bool listening) {
|
|||
}
|
||||
|
||||
connected_clients.clear();
|
||||
LanEvent = lan_event;
|
||||
lan_event = lan_event_;
|
||||
|
||||
SetState(State::Initialized);
|
||||
|
||||
|
@ -408,13 +405,13 @@ void LANDiscovery::OnDisconnectFromHost() {
|
|||
host_ip = std::nullopt;
|
||||
if (state == State::StationConnected) {
|
||||
SetState(State::StationOpened);
|
||||
LanEvent();
|
||||
lan_event();
|
||||
}
|
||||
}
|
||||
|
||||
void LANDiscovery::OnNetworkInfoChanged() {
|
||||
if (IsNodeStateChanged()) {
|
||||
LanEvent();
|
||||
lan_event();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -439,7 +436,6 @@ void LANDiscovery::SendPacket(Network::LDNPacketType type, const Data& data,
|
|||
packet.local_ip = GetLocalIp();
|
||||
packet.remote_ip = remote_ip;
|
||||
|
||||
packet.data.clear();
|
||||
packet.data.resize(sizeof(data));
|
||||
std::memcpy(packet.data.data(), &data, sizeof(data));
|
||||
SendPacket(packet);
|
||||
|
@ -453,7 +449,6 @@ void LANDiscovery::SendPacket(Network::LDNPacketType type, Ipv4Address remote_ip
|
|||
packet.local_ip = GetLocalIp();
|
||||
packet.remote_ip = remote_ip;
|
||||
|
||||
packet.data.clear();
|
||||
SendPacket(packet);
|
||||
}
|
||||
|
||||
|
@ -465,7 +460,6 @@ void LANDiscovery::SendBroadcast(Network::LDNPacketType type, const Data& data)
|
|||
packet.broadcast = true;
|
||||
packet.local_ip = GetLocalIp();
|
||||
|
||||
packet.data.clear();
|
||||
packet.data.resize(sizeof(data));
|
||||
std::memcpy(packet.data.data(), &data, sizeof(data));
|
||||
SendPacket(packet);
|
||||
|
@ -478,7 +472,6 @@ void LANDiscovery::SendBroadcast(Network::LDNPacketType type) {
|
|||
packet.broadcast = true;
|
||||
packet.local_ip = GetLocalIp();
|
||||
|
||||
packet.data.clear();
|
||||
SendPacket(packet);
|
||||
}
|
||||
|
||||
|
@ -581,9 +574,9 @@ bool LANDiscovery::IsNodeStateChanged() {
|
|||
for (int i = 0; i < NodeCountMax; i++) {
|
||||
if (nodes[i].is_connected != node_last_states[i]) {
|
||||
if (nodes[i].is_connected) {
|
||||
nodeChanges[i].state_change |= NodeStateChange::Connect;
|
||||
node_changes[i].state_change |= NodeStateChange::Connect;
|
||||
} else {
|
||||
nodeChanges[i].state_change |= NodeStateChange::Disconnect;
|
||||
node_changes[i].state_change |= NodeStateChange::Disconnect;
|
||||
}
|
||||
node_last_states[i] = nodes[i].is_connected;
|
||||
changed = true;
|
||||
|
@ -598,15 +591,11 @@ bool LANDiscovery::IsFlagSet(ScanFilterFlag flag, ScanFilterFlag search_flag) co
|
|||
return (flag_value & search_flag_value) == search_flag_value;
|
||||
}
|
||||
|
||||
int LANDiscovery::GetStationCount() {
|
||||
int count = 0;
|
||||
for (const auto& station : stations) {
|
||||
if (station.GetStatus() != NodeStatus::Disconnected) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
int LANDiscovery::GetStationCount() const {
|
||||
return static_cast<int>(
|
||||
std::count_if(stations.begin(), stations.end(), [](const auto& station) {
|
||||
return station.GetStatus() != NodeStatus::Disconnected;
|
||||
}));
|
||||
}
|
||||
|
||||
MacAddress LANDiscovery::GetFakeMac() const {
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <random>
|
||||
#include <span>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
|
@ -44,7 +45,7 @@ protected:
|
|||
|
||||
class LANDiscovery {
|
||||
public:
|
||||
typedef std::function<void()> LanEventFunc;
|
||||
using LanEventFunc = std::function<void()>;
|
||||
|
||||
LANDiscovery(Network::RoomNetwork& room_network_);
|
||||
~LANDiscovery();
|
||||
|
@ -58,7 +59,7 @@ public:
|
|||
|
||||
DisconnectReason GetDisconnectReason() const;
|
||||
Result Scan(std::vector<NetworkInfo>& networks, u16& count, const ScanFilter& filter);
|
||||
Result SetAdvertiseData(std::vector<u8>& data);
|
||||
Result SetAdvertiseData(std::span<const u8> data);
|
||||
|
||||
Result OpenAccessPoint();
|
||||
Result CloseAccessPoint();
|
||||
|
@ -74,7 +75,7 @@ public:
|
|||
u16 local_communication_version);
|
||||
Result Disconnect();
|
||||
|
||||
Result Initialize(LanEventFunc lan_event = empty_func, bool listening = true);
|
||||
Result Initialize(LanEventFunc lan_event_ = empty_func, bool listening = true);
|
||||
Result Finalize();
|
||||
|
||||
void ReceivePacket(const Network::LDNPacket& packet);
|
||||
|
@ -94,7 +95,7 @@ protected:
|
|||
|
||||
bool IsNodeStateChanged();
|
||||
bool IsFlagSet(ScanFilterFlag flag, ScanFilterFlag search_flag) const;
|
||||
int GetStationCount();
|
||||
int GetStationCount() const;
|
||||
MacAddress GetFakeMac() const;
|
||||
Result GetNodeInfo(NodeInfo& node, const UserConfig& user_config,
|
||||
u16 local_communication_version);
|
||||
|
@ -109,12 +110,12 @@ protected:
|
|||
void SendPacket(const Network::LDNPacket& packet);
|
||||
|
||||
static const LanEventFunc empty_func;
|
||||
const Ssid fake_ssid{"YuzuFakeSsidForLdn"};
|
||||
static constexpr Ssid fake_ssid{"YuzuFakeSsidForLdn"};
|
||||
|
||||
bool inited{};
|
||||
std::mutex packet_mutex;
|
||||
std::array<LanStation, StationCountMax> stations;
|
||||
std::array<NodeLatestUpdate, NodeCountMax> nodeChanges{};
|
||||
std::array<NodeLatestUpdate, NodeCountMax> node_changes{};
|
||||
std::array<u8, NodeCountMax> node_last_states{};
|
||||
std::unordered_map<MacAddress, NetworkInfo, MACAddressHash> scan_results{};
|
||||
NodeInfo node_info{};
|
||||
|
@ -124,9 +125,9 @@ protected:
|
|||
|
||||
// TODO (flTobi): Should this be an std::set?
|
||||
std::vector<Ipv4Address> connected_clients;
|
||||
std::optional<Ipv4Address> host_ip = std::nullopt;
|
||||
std::optional<Ipv4Address> host_ip;
|
||||
|
||||
LanEventFunc LanEvent;
|
||||
LanEventFunc lan_event;
|
||||
|
||||
Network::RoomNetwork& room_network;
|
||||
};
|
||||
|
|
|
@ -205,8 +205,6 @@ public:
|
|||
}
|
||||
|
||||
void GetIpv4Address(Kernel::HLERequestContext& ctx) {
|
||||
LOG_CRITICAL(Service_LDN, "called");
|
||||
|
||||
const auto network_interface = Network::GetSelectedNetworkInterface();
|
||||
|
||||
if (!network_interface) {
|
||||
|
|
|
@ -31,13 +31,7 @@ enum class NodeStateChange : u8 {
|
|||
DisconnectAndConnect,
|
||||
};
|
||||
|
||||
inline NodeStateChange operator|(NodeStateChange a, NodeStateChange b) {
|
||||
return static_cast<NodeStateChange>(static_cast<u8>(a) | static_cast<u8>(b));
|
||||
}
|
||||
|
||||
inline NodeStateChange operator|=(NodeStateChange& a, NodeStateChange b) {
|
||||
return a = a | b;
|
||||
}
|
||||
DECLARE_ENUM_FLAG_OPERATORS(NodeStateChange)
|
||||
|
||||
enum class ScanFilterFlag : u32 {
|
||||
None = 0,
|
||||
|
@ -163,7 +157,7 @@ struct Ssid {
|
|||
|
||||
Ssid() = default;
|
||||
|
||||
explicit Ssid(std::string_view data) {
|
||||
constexpr explicit Ssid(std::string_view data) {
|
||||
length = static_cast<u8>(std::min(data.size(), SsidLengthMax));
|
||||
data.copy(raw.data(), length);
|
||||
raw[length] = 0;
|
||||
|
@ -176,6 +170,10 @@ struct Ssid {
|
|||
bool operator==(const Ssid& b) const {
|
||||
return (length == b.length) && (std::memcmp(raw.data(), b.raw.data(), length) == 0);
|
||||
}
|
||||
|
||||
bool operator!=(const Ssid& b) const {
|
||||
return !operator==(b);
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(Ssid) == 0x22, "Ssid is an invalid size");
|
||||
|
||||
|
|
|
@ -188,7 +188,7 @@ std::vector<NetworkInterface> GetAvailableNetworkInterfaces() {
|
|||
std::optional<NetworkInterface> GetSelectedNetworkInterface() {
|
||||
const auto& selected_network_interface = Settings::values.network_interface.GetValue();
|
||||
const auto network_interfaces = Network::GetAvailableNetworkInterfaces();
|
||||
if (network_interfaces.size() == 0) {
|
||||
if (network_interfaces.empty()) {
|
||||
LOG_ERROR(Network, "GetAvailableNetworkInterfaces returned no interfaces");
|
||||
return std::nullopt;
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ std::optional<NetworkInterface> GetSelectedNetworkInterface() {
|
|||
void SelectFirstNetworkInterface() {
|
||||
const auto network_interfaces = Network::GetAvailableNetworkInterfaces();
|
||||
|
||||
if (network_interfaces.size() == 0) {
|
||||
if (network_interfaces.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -716,7 +716,7 @@ RoomMember::CallbackHandle<ProxyPacket> RoomMember::BindOnProxyPacketReceived(
|
|||
|
||||
RoomMember::CallbackHandle<LDNPacket> RoomMember::BindOnLdnPacketReceived(
|
||||
std::function<void(const LDNPacket&)> callback) {
|
||||
return room_member_impl->Bind(callback);
|
||||
return room_member_impl->Bind(std::move(callback));
|
||||
}
|
||||
|
||||
RoomMember::CallbackHandle<RoomInformation> RoomMember::BindOnRoomInformationChanged(
|
||||
|
|
|
@ -125,7 +125,7 @@
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Multiplayer</string>
|
||||
<string>&Multiplayer</string>
|
||||
</property>
|
||||
<addaction name="action_View_Lobby"/>
|
||||
<addaction name="action_Start_Room"/>
|
||||
|
|
Loading…
Reference in a new issue