mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-10 14:39:01 +01:00
BBA/HLE: Move GetSlot methods
This commit is contained in:
parent
5388f35cc4
commit
9e0bf29329
@ -190,36 +190,6 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleDHCP(const Common::UDPPacket& pack
|
|||||||
WriteToQueue(response.Build());
|
WriteToQueue(response.Build());
|
||||||
}
|
}
|
||||||
|
|
||||||
StackRef* CEXIETHERNET::BuiltInBBAInterface::GetAvailableSlot(u16 port)
|
|
||||||
{
|
|
||||||
if (port > 0) // existing connection?
|
|
||||||
{
|
|
||||||
for (auto& ref : network_ref)
|
|
||||||
{
|
|
||||||
if (ref.ip != 0 && ref.local == port)
|
|
||||||
return &ref;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (auto& ref : network_ref)
|
|
||||||
{
|
|
||||||
if (ref.ip == 0)
|
|
||||||
return &ref;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
StackRef* CEXIETHERNET::BuiltInBBAInterface::GetTCPSlot(u16 src_port, u16 dst_port, u32 ip)
|
|
||||||
{
|
|
||||||
for (auto& ref : network_ref)
|
|
||||||
{
|
|
||||||
if (ref.ip == ip && ref.remote == dst_port && ref.local == src_port)
|
|
||||||
{
|
|
||||||
return &ref;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<std::vector<u8>>
|
std::optional<std::vector<u8>>
|
||||||
CEXIETHERNET::BuiltInBBAInterface::TryGetDataFromSocket(StackRef* ref)
|
CEXIETHERNET::BuiltInBBAInterface::TryGetDataFromSocket(StackRef* ref)
|
||||||
{
|
{
|
||||||
@ -301,8 +271,8 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket&
|
|||||||
{
|
{
|
||||||
const auto& [hwdata, ip_header, tcp_header, ip_options, tcp_options, data] = packet;
|
const auto& [hwdata, ip_header, tcp_header, ip_options, tcp_options, data] = packet;
|
||||||
sf::IpAddress target;
|
sf::IpAddress target;
|
||||||
StackRef* ref = GetTCPSlot(tcp_header.source_port, tcp_header.destination_port,
|
StackRef* ref = network_ref.GetTCPSlot(tcp_header.source_port, tcp_header.destination_port,
|
||||||
Common::BitCast<u32>(ip_header.destination_addr));
|
Common::BitCast<u32>(ip_header.destination_addr));
|
||||||
const u16 flags = ntohs(tcp_header.properties) & 0xfff;
|
const u16 flags = ntohs(tcp_header.properties) & 0xfff;
|
||||||
if (flags & (TCP_FLAG_FIN | TCP_FLAG_RST))
|
if (flags & (TCP_FLAG_FIN | TCP_FLAG_RST))
|
||||||
{
|
{
|
||||||
@ -331,7 +301,7 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket&
|
|||||||
// new connection
|
// new connection
|
||||||
if (ref != nullptr)
|
if (ref != nullptr)
|
||||||
return;
|
return;
|
||||||
ref = GetAvailableSlot(0);
|
ref = network_ref.GetAvailableSlot(0);
|
||||||
|
|
||||||
ref->delay = GetTickCountStd();
|
ref->delay = GetTickCountStd();
|
||||||
ref->local = tcp_header.source_port;
|
ref->local = tcp_header.source_port;
|
||||||
@ -421,7 +391,7 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleTCPFrame(const Common::TCPPacket&
|
|||||||
// and listen to it. We open it on our side manually.
|
// and listen to it. We open it on our side manually.
|
||||||
void CEXIETHERNET::BuiltInBBAInterface::InitUDPPort(u16 port)
|
void CEXIETHERNET::BuiltInBBAInterface::InitUDPPort(u16 port)
|
||||||
{
|
{
|
||||||
StackRef* ref = GetAvailableSlot(htons(port));
|
StackRef* ref = network_ref.GetAvailableSlot(htons(port));
|
||||||
if (ref == nullptr || ref->ip != 0)
|
if (ref == nullptr || ref->ip != 0)
|
||||||
return;
|
return;
|
||||||
ref->ip = m_router_ip; // change for ip
|
ref->ip = m_router_ip; // change for ip
|
||||||
@ -451,7 +421,7 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleUDPFrame(const Common::UDPPacket&
|
|||||||
m_router_ip : // dns request
|
m_router_ip : // dns request
|
||||||
Common::BitCast<u32>(ip_header.destination_addr);
|
Common::BitCast<u32>(ip_header.destination_addr);
|
||||||
|
|
||||||
StackRef* ref = GetAvailableSlot(udp_header.source_port);
|
StackRef* ref = network_ref.GetAvailableSlot(udp_header.source_port);
|
||||||
if (ref->ip == 0)
|
if (ref->ip == 0)
|
||||||
{
|
{
|
||||||
ref->ip = destination_addr; // change for ip
|
ref->ip = destination_addr; // change for ip
|
||||||
@ -496,7 +466,7 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleUDPFrame(const Common::UDPPacket&
|
|||||||
|
|
||||||
void CEXIETHERNET::BuiltInBBAInterface::HandleUPnPClient()
|
void CEXIETHERNET::BuiltInBBAInterface::HandleUPnPClient()
|
||||||
{
|
{
|
||||||
StackRef* ref = GetAvailableSlot(0);
|
StackRef* ref = network_ref.GetAvailableSlot(0);
|
||||||
if (ref == nullptr || m_upnp_httpd.accept(ref->tcp_socket) != sf::Socket::Done)
|
if (ref == nullptr || m_upnp_httpd.accept(ref->tcp_socket) != sf::Socket::Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -967,6 +937,36 @@ sf::Socket::Status BbaUdpSocket::Bind(u16 port, u32 net_ip)
|
|||||||
return sf::Socket::Status::Done;
|
return sf::Socket::Status::Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StackRef* NetworkRef::GetAvailableSlot(u16 port)
|
||||||
|
{
|
||||||
|
if (port > 0) // existing connection?
|
||||||
|
{
|
||||||
|
for (auto& ref : m_stacks)
|
||||||
|
{
|
||||||
|
if (ref.ip != 0 && ref.local == port)
|
||||||
|
return &ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto& ref : m_stacks)
|
||||||
|
{
|
||||||
|
if (ref.ip == 0)
|
||||||
|
return &ref;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
StackRef* NetworkRef::GetTCPSlot(u16 src_port, u16 dst_port, u32 ip)
|
||||||
|
{
|
||||||
|
for (auto& ref : m_stacks)
|
||||||
|
{
|
||||||
|
if (ref.ip == ip && ref.remote == dst_port && ref.local == src_port)
|
||||||
|
{
|
||||||
|
return &ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void NetworkRef::Clear()
|
void NetworkRef::Clear()
|
||||||
{
|
{
|
||||||
for (auto& ref : m_stacks)
|
for (auto& ref : m_stacks)
|
||||||
|
@ -107,6 +107,9 @@ public:
|
|||||||
auto end() { return m_stacks.end(); }
|
auto end() { return m_stacks.end(); }
|
||||||
auto end() const { return m_stacks.cend(); }
|
auto end() const { return m_stacks.cend(); }
|
||||||
|
|
||||||
|
StackRef* GetAvailableSlot(u16 port);
|
||||||
|
StackRef* GetTCPSlot(u16 src_port, u16 dst_port, u32 ip);
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -463,8 +463,6 @@ private:
|
|||||||
static void ReadThreadHandler(BuiltInBBAInterface* self);
|
static void ReadThreadHandler(BuiltInBBAInterface* self);
|
||||||
#endif
|
#endif
|
||||||
void WriteToQueue(const std::vector<u8>& data);
|
void WriteToQueue(const std::vector<u8>& data);
|
||||||
StackRef* GetAvailableSlot(u16 port);
|
|
||||||
StackRef* GetTCPSlot(u16 src_port, u16 dst_port, u32 ip);
|
|
||||||
std::optional<std::vector<u8>> TryGetDataFromSocket(StackRef* ref);
|
std::optional<std::vector<u8>> TryGetDataFromSocket(StackRef* ref);
|
||||||
|
|
||||||
void HandleARP(const Common::ARPPacket& packet);
|
void HandleARP(const Common::ARPPacket& packet);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user