X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fconnection.cpp;h=ed5a752befc10e417e807b7892eb61c72e4781ad;hb=b29834ab02b47a120616b4c807a573a851b3ccd4;hp=8f308c99fe1321860f431e68109b58b07e9f0594;hpb=6a76c226e10e92c3e3339096f07f8ab065e2098b;p=dragonfireclient.git diff --git a/src/connection.cpp b/src/connection.cpp index 8f308c99f..ed5a752be 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -3,16 +3,16 @@ Minetest-c55 Copyright (C) 2010 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +GNU Lesser General Public License for more details. -You should have received a copy of the GNU General Public License along +You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ @@ -22,10 +22,23 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serialization.h" #include "log.h" #include "porting.h" +#include "util/serialize.h" +#include "util/numeric.h" +#include "util/string.h" +#include "settings.h" namespace con { +static u16 readPeerId(u8 *packetdata) +{ + return readU16(&packetdata[4]); +} +static u8 readChannel(u8 *packetdata) +{ + return readU8(&packetdata[6]); +} + BufferedPacket makePacket(Address &address, u8 *data, u32 datasize, u32 protocol_id, u16 sender_peer_id, u8 channel) { @@ -353,9 +366,11 @@ SharedBuffer IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) <<" != sp->reliable="<reliable <chunks.find(chunk_num) != NULL) - throw AlreadyExistsException("Chunk already in buffer"); + return SharedBuffer(); // Cut chunk data out of packet u32 chunkdatasize = p.data.getSize() - headersize; @@ -452,7 +467,10 @@ Peer::Peer(u16 a_id, Address a_address): m_sendtime_accu(0), m_max_packets_per_second(10), m_num_sent(0), - m_max_num_sent(0) + m_max_num_sent(0), + congestion_control_aim_rtt(0.2), + congestion_control_max_rate(400), + congestion_control_min_rate(10) { } Peer::~Peer() @@ -463,15 +481,15 @@ void Peer::reportRTT(float rtt) { if(rtt >= 0.0){ if(rtt < 0.01){ - if(m_max_packets_per_second < 100) + if(m_max_packets_per_second < congestion_control_max_rate) m_max_packets_per_second += 10; - } else if(rtt < 0.2){ - if(m_max_packets_per_second < 100) + } else if(rtt < congestion_control_aim_rtt){ + if(m_max_packets_per_second < congestion_control_max_rate) m_max_packets_per_second += 2; } else { m_max_packets_per_second *= 0.8; - if(m_max_packets_per_second < 10) - m_max_packets_per_second = 10; + if(m_max_packets_per_second < congestion_control_min_rate) + m_max_packets_per_second = congestion_control_min_rate; } } @@ -537,6 +555,14 @@ Connection::Connection(u32 protocol_id, u32 max_packet_size, float timeout, Connection::~Connection() { stop(); + // Delete peers + for(core::map::Iterator + j = m_peers.getIterator(); + j.atEnd() == false; j++) + { + Peer *peer = j.getNode()->getValue(); + delete peer; + } } /* Internal stuff */ @@ -869,12 +895,24 @@ void Connection::receive() void Connection::runTimeouts(float dtime) { + float congestion_control_aim_rtt + = g_settings->getFloat("congestion_control_aim_rtt"); + float congestion_control_max_rate + = g_settings->getFloat("congestion_control_max_rate"); + float congestion_control_min_rate + = g_settings->getFloat("congestion_control_min_rate"); + core::list timeouted_peers; core::map::Iterator j; j = m_peers.getIterator(); for(; j.atEnd() == false; j++) { Peer *peer = j.getNode()->getValue(); + + // Update congestion control values + peer->congestion_control_aim_rtt = congestion_control_aim_rtt; + peer->congestion_control_max_rate = congestion_control_max_rate; + peer->congestion_control_min_rate = congestion_control_min_rate; /* Check peer timeout @@ -986,8 +1024,16 @@ void Connection::runTimeouts(float dtime) void Connection::serve(u16 port) { dout_con< &data) if(m_bc_peerhandler) m_bc_peerhandler->deletingPeer(&tmp, e.timeout); continue; } + case CONNEVENT_BIND_FAILED: + throw ConnectionBindFailed("Failed to bind socket " + "(port already in use?)"); } } throw NoIncomingDataException("No incoming data");