connection: Remove unused timeout feature

Was only used for a unit test and incorrectly at that.
This commit is contained in:
red-001 2024-08-31 16:44:12 +01:00 committed by sfan5
parent 6608057971
commit 1b8b84bee8
7 changed files with 24 additions and 50 deletions

@ -398,8 +398,6 @@ void Client::connect(const Address &address, const std::string &address_name,
address.print(infostream);
infostream << std::endl;
// Since we use TryReceive() a timeout here would be ineffective anyway
m_con->SetTimeoutMs(0);
m_con->Connect(address);
initLocalMapSaving(address, m_address_name, is_local_server);

@ -48,7 +48,6 @@ class IConnection
public:
virtual ~IConnection() = default;
virtual void SetTimeoutMs(u32 timeout) = 0;
virtual void Serve(Address bind_addr) = 0;
virtual void Connect(Address address) = 0;
virtual bool Connected() = 0;
@ -56,7 +55,6 @@ public:
virtual void DisconnectPeer(session_t peer_id) = 0;
virtual bool ReceiveTimeoutMs(NetworkPacket *pkt, u32 timeout_ms) = 0;
virtual void Receive(NetworkPacket *pkt) = 0;
bool TryReceive(NetworkPacket *pkt) {
return ReceiveTimeoutMs(pkt, 0);
}

@ -1486,13 +1486,6 @@ bool Connection::ReceiveTimeoutMs(NetworkPacket *pkt, u32 timeout_ms)
return false;
}
void Connection::Receive(NetworkPacket *pkt)
{
bool any = ReceiveTimeoutMs(pkt, m_bc_receive_timeout);
if (!any)
throw NoIncomingDataException("No incoming data");
}
void Connection::Send(session_t peer_id, u8 channelnum,
NetworkPacket *pkt, bool reliable)
{

@ -249,13 +249,11 @@ public:
void putCommand(ConnectionCommandPtr c);
void SetTimeoutMs(u32 timeout) { m_bc_receive_timeout = timeout; }
void Serve(Address bind_addr);
void Connect(Address address);
bool Connected();
void Disconnect();
bool ReceiveTimeoutMs(NetworkPacket *pkt, u32 timeout_ms);
void Receive(NetworkPacket *pkt);
void Send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable);
session_t GetPeerID() const { return m_peer_id; }
Address GetPeerAddress(session_t peer_id);
@ -317,7 +315,6 @@ private:
// Backwards compatibility
PeerHandler *m_bc_peerhandler;
u32 m_bc_receive_timeout = 0;
bool m_shutting_down = false;
};

@ -51,12 +51,6 @@ public:
InvalidIncomingDataException(const char *s) : BaseException(s) {}
};
class NoIncomingDataException : public BaseException
{
public:
NoIncomingDataException(const char *s) : BaseException(s) {}
};
}
class SocketException : public BaseException

@ -551,7 +551,6 @@ void Server::start()
m_thread->stop();
// Initialize connection
m_con->SetTimeoutMs(30);
m_con->Serve(m_bind_addr);
// Start thread

@ -160,6 +160,9 @@ void TestConnection::testHelpers()
void TestConnection::testConnectSendReceive()
{
constexpr u32 timeout_ms = 100;
/*
Test some real connections
@ -210,13 +213,11 @@ void TestConnection::testConnectSendReceive()
// Client should not have added client yet
UASSERT(hand_client.count == 0);
try {
NetworkPacket pkt;
infostream << "** running client.Receive()" << std::endl;
client.Receive(&pkt);
NetworkPacket pkt;
infostream << "** running client.Receive()" << std::endl;
if (client.ReceiveTimeoutMs(&pkt, timeout_ms)) {
infostream << "** Client received: peer_id=" << pkt.getPeerId()
<< ", size=" << pkt.getSize() << std::endl;
} catch (con::NoIncomingDataException &e) {
}
// Client should have added server now
@ -227,14 +228,14 @@ void TestConnection::testConnectSendReceive()
sleep_ms(100);
try {
NetworkPacket pkt;
infostream << "** running server.Receive()" << std::endl;
server.Receive(&pkt);
NetworkPacket pkt1;
infostream << "** running server.Receive()" << std::endl;
if (server.ReceiveTimeoutMs(&pkt, timeout_ms)) {
infostream << "** Server received: peer_id=" << pkt.getPeerId()
<< ", size=" << pkt.getSize()
<< std::endl;
} catch (con::NoIncomingDataException &e) {
<< ", size=" << pkt.getSize()
<< std::endl;
}
else {
// No actual data received, but the client has
// probably been connected
}
@ -249,27 +250,23 @@ void TestConnection::testConnectSendReceive()
//sleep_ms(50);
while (client.Connected() == false) {
try {
NetworkPacket pkt;
infostream << "** running client.Receive()" << std::endl;
client.Receive(&pkt);
NetworkPacket pkt;
infostream << "** running client.Receive()" << std::endl;
if (client.TryReceive(&pkt)) {
infostream << "** Client received: peer_id=" << pkt.getPeerId()
<< ", size=" << pkt.getSize() << std::endl;
} catch (con::NoIncomingDataException &e) {
}
sleep_ms(50);
}
sleep_ms(50);
try {
NetworkPacket pkt;
infostream << "** running server.Receive()" << std::endl;
server.Receive(&pkt);
NetworkPacket pkt2;
infostream << "** running server.Receive()" << std::endl;
if (server.ReceiveTimeoutMs(&pkt, timeout_ms)) {
infostream << "** Server received: peer_id=" << pkt.getPeerId()
<< ", size=" << pkt.getSize()
<< std::endl;
} catch (con::NoIncomingDataException &e) {
<< ", size=" << pkt.getSize()
<< std::endl;
}
/*
@ -288,7 +285,7 @@ void TestConnection::testConnectSendReceive()
NetworkPacket recvpacket;
infostream << "** running server.Receive()" << std::endl;
server.Receive(&recvpacket);
UASSERT(server.ReceiveTimeoutMs(&recvpacket, timeout_ms));
infostream << "** Server received: peer_id=" << pkt.getPeerId()
<< ", size=" << pkt.getSize()
<< ", data=" << (const char*)pkt.getU8Ptr(0)
@ -338,14 +335,12 @@ void TestConnection::testConnectSendReceive()
for (;;) {
if (porting::getTimeMs() - timems0 > 5000 || received)
break;
try {
NetworkPacket pkt;
client.Receive(&pkt);
NetworkPacket pkt;
if (client.ReceiveTimeoutMs(&pkt, timeout_ms)) {
size = pkt.getSize();
peer_id = pkt.getPeerId();
recvdata = pkt.oldForgePacket();
received = true;
} catch (con::NoIncomingDataException &e) {
}
sleep_ms(10);
}