Remove legacy client handling code.

This commit is contained in:
Lars Hofhansl 2018-07-14 11:38:52 -07:00
parent b38c121856
commit ca8ec46843
3 changed files with 57 additions and 127 deletions

@ -600,7 +600,7 @@ void Channel::UpdateBytesSent(unsigned int bytes, unsigned int packets)
{
MutexAutoLock internal(m_internal_mutex);
current_bytes_transfered += bytes;
current_packet_successfull += packets;
current_packet_successful += packets;
}
void Channel::UpdateBytesReceived(unsigned int bytes) {
@ -627,17 +627,16 @@ void Channel::UpdatePacketTooLateCounter()
current_packet_too_late++;
}
void Channel::UpdateTimers(float dtime,bool legacy_peer)
void Channel::UpdateTimers(float dtime)
{
bpm_counter += dtime;
packet_loss_counter += dtime;
if (packet_loss_counter > 1.0)
{
packet_loss_counter -= 1.0;
if (packet_loss_counter > 1.0f) {
packet_loss_counter -= 1.0f;
unsigned int packet_loss = 11; /* use a neutral value for initialization */
unsigned int packets_successfull = 0;
unsigned int packets_successful = 0;
//unsigned int packet_too_late = 0;
bool reasonable_amount_of_data_transmitted = false;
@ -646,94 +645,78 @@ void Channel::UpdateTimers(float dtime,bool legacy_peer)
MutexAutoLock internal(m_internal_mutex);
packet_loss = current_packet_loss;
//packet_too_late = current_packet_too_late;
packets_successfull = current_packet_successfull;
packets_successful = current_packet_successful;
if (current_bytes_transfered > (unsigned int) (window_size*512/2))
{
if (current_bytes_transfered > (unsigned int) (window_size*512/2)) {
reasonable_amount_of_data_transmitted = true;
}
current_packet_loss = 0;
current_packet_too_late = 0;
current_packet_successfull = 0;
current_packet_successful = 0;
}
/* dynamic window size is only available for non legacy peers */
if (!legacy_peer) {
float successfull_to_lost_ratio = 0.0;
/* dynamic window size */
float successful_to_lost_ratio = 0.0f;
bool done = false;
if (packets_successfull > 0) {
successfull_to_lost_ratio = packet_loss/packets_successfull;
}
else if (packet_loss > 0)
{
window_size = MYMAX(
if (packets_successful > 0) {
successful_to_lost_ratio = packet_loss/packets_successful;
} else if (packet_loss > 0) {
window_size = std::max(
(window_size - 10),
MIN_RELIABLE_WINDOW_SIZE);
done = true;
}
if (!done)
{
if ((successfull_to_lost_ratio < 0.01) &&
(window_size < MAX_RELIABLE_WINDOW_SIZE))
{
if (!done) {
if ((successful_to_lost_ratio < 0.01f) &&
(window_size < MAX_RELIABLE_WINDOW_SIZE)) {
/* don't even think about increasing if we didn't even
* use major parts of our window */
if (reasonable_amount_of_data_transmitted)
window_size = MYMIN(
window_size = std::min(
(window_size + 100),
MAX_RELIABLE_WINDOW_SIZE);
}
else if ((successfull_to_lost_ratio < 0.05) &&
(window_size < MAX_RELIABLE_WINDOW_SIZE))
{
} else if ((successful_to_lost_ratio < 0.05f) &&
(window_size < MAX_RELIABLE_WINDOW_SIZE)) {
/* don't even think about increasing if we didn't even
* use major parts of our window */
if (reasonable_amount_of_data_transmitted)
window_size = MYMIN(
window_size = std::min(
(window_size + 50),
MAX_RELIABLE_WINDOW_SIZE);
}
else if (successfull_to_lost_ratio > 0.15)
{
window_size = MYMAX(
} else if (successful_to_lost_ratio > 0.15f) {
window_size = std::max(
(window_size - 100),
MIN_RELIABLE_WINDOW_SIZE);
}
else if (successfull_to_lost_ratio > 0.1)
{
window_size = MYMAX(
} else if (successful_to_lost_ratio > 0.1f) {
window_size = std::max(
(window_size - 50),
MIN_RELIABLE_WINDOW_SIZE);
}
}
}
}
if (bpm_counter > 10.0)
{
if (bpm_counter > 10.0f) {
{
MutexAutoLock internal(m_internal_mutex);
cur_kbps =
(((float) current_bytes_transfered)/bpm_counter)/1024.0;
(((float) current_bytes_transfered)/bpm_counter)/1024.0f;
current_bytes_transfered = 0;
cur_kbps_lost =
(((float) current_bytes_lost)/bpm_counter)/1024.0;
(((float) current_bytes_lost)/bpm_counter)/1024.0f;
current_bytes_lost = 0;
cur_incoming_kbps =
(((float) current_bytes_received)/bpm_counter)/1024.0;
(((float) current_bytes_received)/bpm_counter)/1024.0f;
current_bytes_received = 0;
bpm_counter = 0;
bpm_counter = 0.0f;
}
if (cur_kbps > max_kbps)
{
if (cur_kbps > max_kbps) {
max_kbps = cur_kbps;
}
if (cur_kbps_lost > max_kbps_lost)
{
if (cur_kbps_lost > max_kbps_lost) {
max_kbps_lost = cur_kbps_lost;
}
@ -903,6 +886,8 @@ void Peer::Drop()
UDPPeer::UDPPeer(u16 a_id, Address a_address, Connection* connection) :
Peer(a_address,a_id,connection)
{
for (Channel &channel : channels)
channel.setWindowSize(g_settings->getU16("max_packets_per_iteration"));
}
bool UDPPeer::getAddress(MTProtocols type,Address& toset)
@ -916,15 +901,6 @@ bool UDPPeer::getAddress(MTProtocols type,Address& toset)
return false;
}
void UDPPeer::setNonLegacyPeer()
{
m_legacy_peer = false;
for(unsigned int i=0; i< CHANNEL_COUNT; i++)
{
channels[i].setWindowSize(g_settings->getU16("max_packets_per_iteration"));
}
}
void UDPPeer::reportRTT(float rtt)
{
assert(rtt >= 0.0f);

@ -176,7 +176,6 @@ controltype and data description:
#define CONTROLTYPE_SET_PEER_ID 1
#define CONTROLTYPE_PING 2
#define CONTROLTYPE_DISCO 3
#define CONTROLTYPE_ENABLE_BIG_SEND_WINDOW 4
/*
ORIGINAL: This is a plain packet with no control and no error
@ -316,8 +315,7 @@ enum ConnectionCommandType{
CONNCMD_SEND,
CONNCMD_SEND_TO_ALL,
CONCMD_ACK,
CONCMD_CREATE_PEER,
CONCMD_DISABLE_LEGACY
CONCMD_CREATE_PEER
};
struct ConnectionCommand
@ -384,16 +382,6 @@ struct ConnectionCommand
reliable = true;
raw = true;
}
void disableLegacy(session_t peer_id_, const SharedBuffer<u8> &data_)
{
type = CONCMD_DISABLE_LEGACY;
peer_id = peer_id_;
data = data_;
channelnum = 0;
reliable = true;
raw = true;
}
};
/* maximum window size to use, 0xFFFF is theoretical maximum don't think about
@ -442,7 +430,7 @@ public:
void UpdateBytesLost(unsigned int bytes);
void UpdateBytesReceived(unsigned int bytes);
void UpdateTimers(float dtime, bool legacy_peer);
void UpdateTimers(float dtime);
const float getCurrentDownloadRateKB()
{ MutexAutoLock lock(m_internal_mutex); return cur_kbps; };
@ -480,7 +468,7 @@ private:
unsigned int current_packet_loss = 0;
unsigned int current_packet_too_late = 0;
unsigned int current_packet_successfull = 0;
unsigned int current_packet_successful = 0;
float packet_loss_counter = 0.0f;
unsigned int current_bytes_transfered = 0;
@ -659,11 +647,6 @@ public:
bool getAddress(MTProtocols type, Address& toset);
void setNonLegacyPeer();
bool getLegacyPeer()
{ return m_legacy_peer; }
u16 getNextSplitSequenceNumber(u8 channel);
void setNextSplitSequenceNumber(u8 channel, u16 seqnum);
@ -698,8 +681,6 @@ private:
bool processReliableSendCommand(
ConnectionCommand &c,
unsigned int max_packet_size);
bool m_legacy_peer = true;
};
/*

@ -206,9 +206,6 @@ void ConnectionSendThread::runTimeouts(float dtime)
for (Channel &channel : udpPeer->channels) {
std::list<BufferedPacket> timed_outs;
if (udpPeer->getLegacyPeer())
channel.setWindowSize(WINDOW_SIZE);
// Remove timed out incomplete unreliable split packets
channel.incoming_splits.removeUnreliableTimedOuts(dtime, m_timeout);
@ -264,7 +261,7 @@ void ConnectionSendThread::runTimeouts(float dtime)
break; /* no need to check other channels if we already did timeout */
}
channel.UpdateTimers(dtime, udpPeer->getLegacyPeer());
channel.UpdateTimers(dtime);
}
/* skip to next peer if we did timeout */
@ -428,15 +425,6 @@ void ConnectionSendThread::processReliableCommand(ConnectionCommand &c)
}
return;
case CONCMD_DISABLE_LEGACY:
LOG(dout_con << m_connection->getDesc()
<< "UDP processing reliable CONCMD_DISABLE_LEGACY" << std::endl);
if (!rawSendAsPacket(c.peer_id, c.channelnum, c.data, c.reliable)) {
/* put to queue if we couldn't send it immediately */
sendReliable(c);
}
return;
case CONNCMD_SERVE:
case CONNCMD_CONNECT:
case CONNCMD_DISCONNECT:
@ -1208,18 +1196,6 @@ SharedBuffer<u8> ConnectionReceiveThread::handlePacketType_Control(Channel *chan
m_connection->SetPeerID(peer_id_new);
}
// set non legacy mode locally
dynamic_cast<UDPPeer *>(peer)->setNonLegacyPeer();
// request the same from the remote side
ConnectionCommand cmd;
SharedBuffer<u8> reply(2);
writeU8(&reply[0], PACKET_TYPE_CONTROL);
writeU8(&reply[1], CONTROLTYPE_ENABLE_BIG_SEND_WINDOW);
cmd.disableLegacy(PEER_ID_SERVER, reply);
m_connection->putCommand(cmd);
throw ProcessedSilentlyException("Got a SET_PEER_ID");
} else if (controltype == CONTROLTYPE_PING) {
// Just ignore it, the incoming data already reset
@ -1237,9 +1213,6 @@ SharedBuffer<u8> ConnectionReceiveThread::handlePacketType_Control(Channel *chan
}
throw ProcessedSilentlyException("Got a DISCO");
} else if (controltype == CONTROLTYPE_ENABLE_BIG_SEND_WINDOW) {
dynamic_cast<UDPPeer *>(peer)->setNonLegacyPeer();
throw ProcessedSilentlyException("Got non legacy control");
} else {
LOG(derr_con << m_connection->getDesc()
<< "INVALID TYPE_CONTROL: invalid controltype="