summaryrefslogtreecommitdiff
path: root/src/core/hle/service/ldn
diff options
context:
space:
mode:
authorGravatar FearlessTobi2022-09-12 22:39:18 +0200
committerGravatar FearlessTobi2022-09-20 19:36:32 +0200
commit4213f1c126afda9c5235c868ded4e7d95438bffc (patch)
treeafc604f144281afbd45ce8a757f1d1fbb020018b /src/core/hle/service/ldn
parentdedicated_room: fix token padding ... (diff)
downloadyuzu-4213f1c126afda9c5235c868ded4e7d95438bffc.tar.gz
yuzu-4213f1c126afda9c5235c868ded4e7d95438bffc.tar.xz
yuzu-4213f1c126afda9c5235c868ded4e7d95438bffc.zip
Address some review comments
Diffstat (limited to 'src/core/hle/service/ldn')
-rw-r--r--src/core/hle/service/ldn/lan_discovery.cpp49
-rw-r--r--src/core/hle/service/ldn/lan_discovery.h17
-rw-r--r--src/core/hle/service/ldn/ldn.cpp2
-rw-r--r--src/core/hle/service/ldn/ldn_types.h14
4 files changed, 34 insertions, 48 deletions
diff --git a/src/core/hle/service/ldn/lan_discovery.cpp b/src/core/hle/service/ldn/lan_discovery.cpp
index b04c99077..8f3c04550 100644
--- a/src/core/hle/service/ldn/lan_discovery.cpp
+++ b/src/core/hle/service/ldn/lan_discovery.cpp
@@ -35,12 +35,9 @@ void LanStation::OverrideInfo() {
35 35
36LANDiscovery::LANDiscovery(Network::RoomNetwork& room_network_) 36LANDiscovery::LANDiscovery(Network::RoomNetwork& room_network_)
37 : stations({{{1, this}, {2, this}, {3, this}, {4, this}, {5, this}, {6, this}, {7, this}}}), 37 : stations({{{1, this}, {2, this}, {3, this}, {4, this}, {5, this}, {6, this}, {7, this}}}),
38 room_network{room_network_} { 38 room_network{room_network_} {}
39 LOG_INFO(Service_LDN, "LANDiscovery");
40}
41 39
42LANDiscovery::~LANDiscovery() { 40LANDiscovery::~LANDiscovery() {
43 LOG_INFO(Service_LDN, "~LANDiscovery");
44 if (inited) { 41 if (inited) {
45 Result rc = Finalize(); 42 Result rc = Finalize();
46 LOG_INFO(Service_LDN, "Finalize: {}", rc.raw); 43 LOG_INFO(Service_LDN, "Finalize: {}", rc.raw);
@@ -62,7 +59,7 @@ void LANDiscovery::InitNetworkInfo() {
62} 59}
63 60
64void LANDiscovery::InitNodeStateChange() { 61void LANDiscovery::InitNodeStateChange() {
65 for (auto& node_update : nodeChanges) { 62 for (auto& node_update : node_changes) {
66 node_update.state_change = NodeStateChange::None; 63 node_update.state_change = NodeStateChange::None;
67 } 64 }
68 for (auto& node_state : node_last_states) { 65 for (auto& node_state : node_last_states) {
@@ -97,8 +94,8 @@ Result LANDiscovery::GetNetworkInfo(NetworkInfo& out_network,
97 if (state == State::AccessPointCreated || state == State::StationConnected) { 94 if (state == State::AccessPointCreated || state == State::StationConnected) {
98 std::memcpy(&out_network, &network_info, sizeof(network_info)); 95 std::memcpy(&out_network, &network_info, sizeof(network_info));
99 for (std::size_t i = 0; i < buffer_count; i++) { 96 for (std::size_t i = 0; i < buffer_count; i++) {
100 out_updates[i].state_change = nodeChanges[i].state_change; 97 out_updates[i].state_change = node_changes[i].state_change;
101 nodeChanges[i].state_change = NodeStateChange::None; 98 node_changes[i].state_change = NodeStateChange::None;
102 } 99 }
103 return ResultSuccess; 100 return ResultSuccess;
104 } 101 }
@@ -168,9 +165,9 @@ Result LANDiscovery::Scan(std::vector<NetworkInfo>& networks, u16& count,
168 return ResultSuccess; 165 return ResultSuccess;
169} 166}
170 167
171Result LANDiscovery::SetAdvertiseData(std::vector<u8>& data) { 168Result LANDiscovery::SetAdvertiseData(std::span<const u8> data) {
172 std::scoped_lock lock{packet_mutex}; 169 std::scoped_lock lock{packet_mutex};
173 std::size_t size = data.size(); 170 const std::size_t size = data.size();
174 if (size > AdvertiseDataSizeMax) { 171 if (size > AdvertiseDataSizeMax) {
175 return ResultAdvertiseDataTooLarge; 172 return ResultAdvertiseDataTooLarge;
176 } 173 }
@@ -288,7 +285,7 @@ Result LANDiscovery::DestroyNetwork() {
288 ResetStations(); 285 ResetStations();
289 286
290 SetState(State::AccessPointOpened); 287 SetState(State::AccessPointOpened);
291 LanEvent(); 288 lan_event();
292 289
293 return ResultSuccess; 290 return ResultSuccess;
294} 291}
@@ -323,12 +320,12 @@ Result LANDiscovery::Disconnect() {
323 } 320 }
324 321
325 SetState(State::StationOpened); 322 SetState(State::StationOpened);
326 LanEvent(); 323 lan_event();
327 324
328 return ResultSuccess; 325 return ResultSuccess;
329} 326}
330 327
331Result LANDiscovery::Initialize(LanEventFunc lan_event, bool listening) { 328Result LANDiscovery::Initialize(LanEventFunc lan_event_, bool listening) {
332 std::scoped_lock lock{packet_mutex}; 329 std::scoped_lock lock{packet_mutex};
333 if (inited) { 330 if (inited) {
334 return ResultSuccess; 331 return ResultSuccess;
@@ -341,7 +338,7 @@ Result LANDiscovery::Initialize(LanEventFunc lan_event, bool listening) {
341 } 338 }
342 339
343 connected_clients.clear(); 340 connected_clients.clear();
344 LanEvent = lan_event; 341 lan_event = lan_event_;
345 342
346 SetState(State::Initialized); 343 SetState(State::Initialized);
347 344
@@ -408,13 +405,13 @@ void LANDiscovery::OnDisconnectFromHost() {
408 host_ip = std::nullopt; 405 host_ip = std::nullopt;
409 if (state == State::StationConnected) { 406 if (state == State::StationConnected) {
410 SetState(State::StationOpened); 407 SetState(State::StationOpened);
411 LanEvent(); 408 lan_event();
412 } 409 }
413} 410}
414 411
415void LANDiscovery::OnNetworkInfoChanged() { 412void LANDiscovery::OnNetworkInfoChanged() {
416 if (IsNodeStateChanged()) { 413 if (IsNodeStateChanged()) {
417 LanEvent(); 414 lan_event();
418 } 415 }
419 return; 416 return;
420} 417}
@@ -439,7 +436,6 @@ void LANDiscovery::SendPacket(Network::LDNPacketType type, const Data& data,
439 packet.local_ip = GetLocalIp(); 436 packet.local_ip = GetLocalIp();
440 packet.remote_ip = remote_ip; 437 packet.remote_ip = remote_ip;
441 438
442 packet.data.clear();
443 packet.data.resize(sizeof(data)); 439 packet.data.resize(sizeof(data));
444 std::memcpy(packet.data.data(), &data, sizeof(data)); 440 std::memcpy(packet.data.data(), &data, sizeof(data));
445 SendPacket(packet); 441 SendPacket(packet);
@@ -453,7 +449,6 @@ void LANDiscovery::SendPacket(Network::LDNPacketType type, Ipv4Address remote_ip
453 packet.local_ip = GetLocalIp(); 449 packet.local_ip = GetLocalIp();
454 packet.remote_ip = remote_ip; 450 packet.remote_ip = remote_ip;
455 451
456 packet.data.clear();
457 SendPacket(packet); 452 SendPacket(packet);
458} 453}
459 454
@@ -465,7 +460,6 @@ void LANDiscovery::SendBroadcast(Network::LDNPacketType type, const Data& data)
465 packet.broadcast = true; 460 packet.broadcast = true;
466 packet.local_ip = GetLocalIp(); 461 packet.local_ip = GetLocalIp();
467 462
468 packet.data.clear();
469 packet.data.resize(sizeof(data)); 463 packet.data.resize(sizeof(data));
470 std::memcpy(packet.data.data(), &data, sizeof(data)); 464 std::memcpy(packet.data.data(), &data, sizeof(data));
471 SendPacket(packet); 465 SendPacket(packet);
@@ -478,7 +472,6 @@ void LANDiscovery::SendBroadcast(Network::LDNPacketType type) {
478 packet.broadcast = true; 472 packet.broadcast = true;
479 packet.local_ip = GetLocalIp(); 473 packet.local_ip = GetLocalIp();
480 474
481 packet.data.clear();
482 SendPacket(packet); 475 SendPacket(packet);
483} 476}
484 477
@@ -581,9 +574,9 @@ bool LANDiscovery::IsNodeStateChanged() {
581 for (int i = 0; i < NodeCountMax; i++) { 574 for (int i = 0; i < NodeCountMax; i++) {
582 if (nodes[i].is_connected != node_last_states[i]) { 575 if (nodes[i].is_connected != node_last_states[i]) {
583 if (nodes[i].is_connected) { 576 if (nodes[i].is_connected) {
584 nodeChanges[i].state_change |= NodeStateChange::Connect; 577 node_changes[i].state_change |= NodeStateChange::Connect;
585 } else { 578 } else {
586 nodeChanges[i].state_change |= NodeStateChange::Disconnect; 579 node_changes[i].state_change |= NodeStateChange::Disconnect;
587 } 580 }
588 node_last_states[i] = nodes[i].is_connected; 581 node_last_states[i] = nodes[i].is_connected;
589 changed = true; 582 changed = true;
@@ -598,15 +591,11 @@ bool LANDiscovery::IsFlagSet(ScanFilterFlag flag, ScanFilterFlag search_flag) co
598 return (flag_value & search_flag_value) == search_flag_value; 591 return (flag_value & search_flag_value) == search_flag_value;
599} 592}
600 593
601int LANDiscovery::GetStationCount() { 594int LANDiscovery::GetStationCount() const {
602 int count = 0; 595 return static_cast<int>(
603 for (const auto& station : stations) { 596 std::count_if(stations.begin(), stations.end(), [](const auto& station) {
604 if (station.GetStatus() != NodeStatus::Disconnected) { 597 return station.GetStatus() != NodeStatus::Disconnected;
605 count++; 598 }));
606 }
607 }
608
609 return count;
610} 599}
611 600
612MacAddress LANDiscovery::GetFakeMac() const { 601MacAddress LANDiscovery::GetFakeMac() const {
diff --git a/src/core/hle/service/ldn/lan_discovery.h b/src/core/hle/service/ldn/lan_discovery.h
index 255342456..3833cd764 100644
--- a/src/core/hle/service/ldn/lan_discovery.h
+++ b/src/core/hle/service/ldn/lan_discovery.h
@@ -10,6 +10,7 @@
10#include <mutex> 10#include <mutex>
11#include <optional> 11#include <optional>
12#include <random> 12#include <random>
13#include <span>
13#include <thread> 14#include <thread>
14#include <unordered_map> 15#include <unordered_map>
15 16
@@ -44,7 +45,7 @@ protected:
44 45
45class LANDiscovery { 46class LANDiscovery {
46public: 47public:
47 typedef std::function<void()> LanEventFunc; 48 using LanEventFunc = std::function<void()>;
48 49
49 LANDiscovery(Network::RoomNetwork& room_network_); 50 LANDiscovery(Network::RoomNetwork& room_network_);
50 ~LANDiscovery(); 51 ~LANDiscovery();
@@ -58,7 +59,7 @@ public:
58 59
59 DisconnectReason GetDisconnectReason() const; 60 DisconnectReason GetDisconnectReason() const;
60 Result Scan(std::vector<NetworkInfo>& networks, u16& count, const ScanFilter& filter); 61 Result Scan(std::vector<NetworkInfo>& networks, u16& count, const ScanFilter& filter);
61 Result SetAdvertiseData(std::vector<u8>& data); 62 Result SetAdvertiseData(std::span<const u8> data);
62 63
63 Result OpenAccessPoint(); 64 Result OpenAccessPoint();
64 Result CloseAccessPoint(); 65 Result CloseAccessPoint();
@@ -74,7 +75,7 @@ public:
74 u16 local_communication_version); 75 u16 local_communication_version);
75 Result Disconnect(); 76 Result Disconnect();
76 77
77 Result Initialize(LanEventFunc lan_event = empty_func, bool listening = true); 78 Result Initialize(LanEventFunc lan_event_ = empty_func, bool listening = true);
78 Result Finalize(); 79 Result Finalize();
79 80
80 void ReceivePacket(const Network::LDNPacket& packet); 81 void ReceivePacket(const Network::LDNPacket& packet);
@@ -94,7 +95,7 @@ protected:
94 95
95 bool IsNodeStateChanged(); 96 bool IsNodeStateChanged();
96 bool IsFlagSet(ScanFilterFlag flag, ScanFilterFlag search_flag) const; 97 bool IsFlagSet(ScanFilterFlag flag, ScanFilterFlag search_flag) const;
97 int GetStationCount(); 98 int GetStationCount() const;
98 MacAddress GetFakeMac() const; 99 MacAddress GetFakeMac() const;
99 Result GetNodeInfo(NodeInfo& node, const UserConfig& user_config, 100 Result GetNodeInfo(NodeInfo& node, const UserConfig& user_config,
100 u16 local_communication_version); 101 u16 local_communication_version);
@@ -109,12 +110,12 @@ protected:
109 void SendPacket(const Network::LDNPacket& packet); 110 void SendPacket(const Network::LDNPacket& packet);
110 111
111 static const LanEventFunc empty_func; 112 static const LanEventFunc empty_func;
112 const Ssid fake_ssid{"YuzuFakeSsidForLdn"}; 113 static constexpr Ssid fake_ssid{"YuzuFakeSsidForLdn"};
113 114
114 bool inited{}; 115 bool inited{};
115 std::mutex packet_mutex; 116 std::mutex packet_mutex;
116 std::array<LanStation, StationCountMax> stations; 117 std::array<LanStation, StationCountMax> stations;
117 std::array<NodeLatestUpdate, NodeCountMax> nodeChanges{}; 118 std::array<NodeLatestUpdate, NodeCountMax> node_changes{};
118 std::array<u8, NodeCountMax> node_last_states{}; 119 std::array<u8, NodeCountMax> node_last_states{};
119 std::unordered_map<MacAddress, NetworkInfo, MACAddressHash> scan_results{}; 120 std::unordered_map<MacAddress, NetworkInfo, MACAddressHash> scan_results{};
120 NodeInfo node_info{}; 121 NodeInfo node_info{};
@@ -124,9 +125,9 @@ protected:
124 125
125 // TODO (flTobi): Should this be an std::set? 126 // TODO (flTobi): Should this be an std::set?
126 std::vector<Ipv4Address> connected_clients; 127 std::vector<Ipv4Address> connected_clients;
127 std::optional<Ipv4Address> host_ip = std::nullopt; 128 std::optional<Ipv4Address> host_ip;
128 129
129 LanEventFunc LanEvent; 130 LanEventFunc lan_event;
130 131
131 Network::RoomNetwork& room_network; 132 Network::RoomNetwork& room_network;
132}; 133};
diff --git a/src/core/hle/service/ldn/ldn.cpp b/src/core/hle/service/ldn/ldn.cpp
index 6537f49cf..ea3e7e55a 100644
--- a/src/core/hle/service/ldn/ldn.cpp
+++ b/src/core/hle/service/ldn/ldn.cpp
@@ -205,8 +205,6 @@ public:
205 } 205 }
206 206
207 void GetIpv4Address(Kernel::HLERequestContext& ctx) { 207 void GetIpv4Address(Kernel::HLERequestContext& ctx) {
208 LOG_CRITICAL(Service_LDN, "called");
209
210 const auto network_interface = Network::GetSelectedNetworkInterface(); 208 const auto network_interface = Network::GetSelectedNetworkInterface();
211 209
212 if (!network_interface) { 210 if (!network_interface) {
diff --git a/src/core/hle/service/ldn/ldn_types.h b/src/core/hle/service/ldn/ldn_types.h
index d6609fff5..44c2c773b 100644
--- a/src/core/hle/service/ldn/ldn_types.h
+++ b/src/core/hle/service/ldn/ldn_types.h
@@ -31,13 +31,7 @@ enum class NodeStateChange : u8 {
31 DisconnectAndConnect, 31 DisconnectAndConnect,
32}; 32};
33 33
34inline NodeStateChange operator|(NodeStateChange a, NodeStateChange b) { 34DECLARE_ENUM_FLAG_OPERATORS(NodeStateChange)
35 return static_cast<NodeStateChange>(static_cast<u8>(a) | static_cast<u8>(b));
36}
37
38inline NodeStateChange operator|=(NodeStateChange& a, NodeStateChange b) {
39 return a = a | b;
40}
41 35
42enum class ScanFilterFlag : u32 { 36enum class ScanFilterFlag : u32 {
43 None = 0, 37 None = 0,
@@ -163,7 +157,7 @@ struct Ssid {
163 157
164 Ssid() = default; 158 Ssid() = default;
165 159
166 explicit Ssid(std::string_view data) { 160 constexpr explicit Ssid(std::string_view data) {
167 length = static_cast<u8>(std::min(data.size(), SsidLengthMax)); 161 length = static_cast<u8>(std::min(data.size(), SsidLengthMax));
168 data.copy(raw.data(), length); 162 data.copy(raw.data(), length);
169 raw[length] = 0; 163 raw[length] = 0;
@@ -176,6 +170,10 @@ struct Ssid {
176 bool operator==(const Ssid& b) const { 170 bool operator==(const Ssid& b) const {
177 return (length == b.length) && (std::memcmp(raw.data(), b.raw.data(), length) == 0); 171 return (length == b.length) && (std::memcmp(raw.data(), b.raw.data(), length) == 0);
178 } 172 }
173
174 bool operator!=(const Ssid& b) const {
175 return !operator==(b);
176 }
179}; 177};
180static_assert(sizeof(Ssid) == 0x22, "Ssid is an invalid size"); 178static_assert(sizeof(Ssid) == 0x22, "Ssid is an invalid size");
181 179