diff options
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/connection.cpp | 74 | ||||
-rw-r--r-- | src/network/connection.h | 6 | ||||
-rw-r--r-- | src/network/packethandlers/client.cpp | 8 |
3 files changed, 41 insertions, 47 deletions
diff --git a/src/network/connection.cpp b/src/network/connection.cpp index b73981ccc..fb31a07f0 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -312,16 +312,16 @@ BufferedPacket ReliablePacketBuffer::popSeqnum(u16 seqnum) void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected) { JMutexAutoLock listlock(m_list_mutex); - assert(p.data.getSize() >= BASE_HEADER_SIZE+3); + FATAL_ERROR_IF(p.data.getSize() < BASE_HEADER_SIZE+3, "Invalid data size"); u8 type = readU8(&p.data[BASE_HEADER_SIZE+0]); - assert(type == TYPE_RELIABLE); + sanity_check(type == TYPE_RELIABLE); u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]); - assert(seqnum_in_window(seqnum,next_expected,MAX_RELIABLE_WINDOW_SIZE)); - assert(seqnum != next_expected); + sanity_check(seqnum_in_window(seqnum, next_expected, MAX_RELIABLE_WINDOW_SIZE)); + sanity_check(seqnum != next_expected); ++m_list_size; - assert(m_list_size <= SEQNUM_MAX+1); + sanity_check(m_list_size <= SEQNUM_MAX+1); // FIXME: Handle the error? // Find the right place for the packet and insert it there // If list is empty, just add it @@ -377,9 +377,9 @@ void ReliablePacketBuffer::insert(BufferedPacket &p,u16 next_expected) throw IncomingDataCorruption("duplicated packet isn't same as original one"); } - assert(readU16(&(i->data[BASE_HEADER_SIZE+1])) == seqnum); - assert(i->data.getSize() == p.data.getSize()); - assert(i->address == p.address); + sanity_check(readU16(&(i->data[BASE_HEADER_SIZE+1])) == seqnum); + sanity_check(i->data.getSize() == p.data.getSize()); + sanity_check(i->address == p.address); /* nothing to do this seems to be a resent packet */ /* for paranoia reason data should be compared */ @@ -449,9 +449,9 @@ SharedBuffer<u8> IncomingSplitBuffer::insert(BufferedPacket &p, bool reliable) { JMutexAutoLock listlock(m_map_mutex); u32 headersize = BASE_HEADER_SIZE + 7; - assert(p.data.getSize() >= headersize); + FATAL_ERROR_IF(p.data.getSize() < headersize, "Invalid data size"); u8 type = readU8(&p.data[BASE_HEADER_SIZE+0]); - assert(type == TYPE_SPLIT); + sanity_check(type == TYPE_SPLIT); u16 seqnum = readU16(&p.data[BASE_HEADER_SIZE+1]); u16 chunk_count = readU16(&p.data[BASE_HEADER_SIZE+3]); u16 chunk_num = readU16(&p.data[BASE_HEADER_SIZE+5]); @@ -898,7 +898,7 @@ void Peer::DecUseCount() { { JMutexAutoLock lock(m_exclusive_access_mutex); - assert(m_usage > 0); + sanity_check(m_usage > 0); m_usage--; if (!((m_pending_deletion) && (m_usage == 0))) @@ -1085,7 +1085,7 @@ bool UDPPeer::processReliableSendCommand( - BASE_HEADER_SIZE - RELIABLE_HEADER_SIZE; - assert(c.data.getSize() < MAX_RELIABLE_WINDOW_SIZE*512); + sanity_check(c.data.getSize() < MAX_RELIABLE_WINDOW_SIZE*512); std::list<SharedBuffer<u8> > originals; u16 split_sequence_number = channels[c.channelnum].readNextSplitSeqNum(); @@ -1142,7 +1142,7 @@ bool UDPPeer::processReliableSendCommand( channels[c.channelnum].queued_reliables.push(p); pcount++; } - assert(channels[c.channelnum].queued_reliables.size() < 0xFFFF); + sanity_check(channels[c.channelnum].queued_reliables.size() < 0xFFFF); return true; } else { @@ -1160,7 +1160,7 @@ bool UDPPeer::processReliableSendCommand( = channels[c.channelnum].putBackSequenceNumber( (initial_sequence_number+toadd.size() % (SEQNUM_MAX+1))); - assert(successfully_put_back_sequence_number); + FATAL_ERROR_IF(!successfully_put_back_sequence_number, "error"); } LOG(dout_con<<m_connection->getDesc() << " Windowsize exceeded on reliable sending " @@ -1212,13 +1212,13 @@ void UDPPeer::RunCommandQueues( u16 UDPPeer::getNextSplitSequenceNumber(u8 channel) { - assert(channel < CHANNEL_COUNT); + assert(channel < CHANNEL_COUNT); // Pre-condition return channels[channel].readNextIncomingSeqNum(); } void UDPPeer::setNextSplitSequenceNumber(u8 channel, u16 seqnum) { - assert(channel < CHANNEL_COUNT); + assert(channel < CHANNEL_COUNT); // Pre-condition channels[channel].setNextSplitSeqNum(seqnum); } @@ -1226,7 +1226,7 @@ SharedBuffer<u8> UDPPeer::addSpiltPacket(u8 channel, BufferedPacket toadd, bool reliable) { - assert(channel < CHANNEL_COUNT); + assert(channel < CHANNEL_COUNT); // Pre-condition return channels[channel].incoming_splits.insert(toadd,reliable); } @@ -1496,7 +1496,6 @@ void ConnectionSendThread::sendAsPacketReliable(BufferedPacket& p, Channel* chan LOG(derr_con<<m_connection->getDesc() <<"WARNING: Going to send a reliable packet" <<" in outgoing buffer" <<std::endl); - //assert(0); } // Send the packet @@ -1511,7 +1510,7 @@ bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum, LOG(dout_con<<m_connection->getDesc() <<" INFO: dropped packet for non existent peer_id: " << peer_id << std::endl); - assert(reliable && "trying to send raw packet reliable but no peer found!"); + FATAL_ERROR_IF(!reliable, "Trying to send raw packet reliable but no peer found!"); return false; } Channel *channel = &(dynamic_cast<UDPPeer*>(&peer)->channels[channelnum]); @@ -1582,7 +1581,7 @@ bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum, void ConnectionSendThread::processReliableCommand(ConnectionCommand &c) { - assert(c.reliable); + assert(c.reliable); // Pre-condition switch(c.type) { case CONNCMD_NONE: @@ -1626,7 +1625,7 @@ void ConnectionSendThread::processReliableCommand(ConnectionCommand &c) case CONNCMD_CONNECT: case CONNCMD_DISCONNECT: case CONCMD_ACK: - assert("Got command that shouldn't be reliable as reliable command" == 0); + FATAL_ERROR("Got command that shouldn't be reliable as reliable command"); default: LOG(dout_con<<m_connection->getDesc() <<" Invalid reliable command type: " << c.type <<std::endl); @@ -1636,7 +1635,7 @@ void ConnectionSendThread::processReliableCommand(ConnectionCommand &c) void ConnectionSendThread::processNonReliableCommand(ConnectionCommand &c) { - assert(!c.reliable); + assert(!c.reliable); // Pre-condition switch(c.type) { case CONNCMD_NONE: @@ -1680,7 +1679,7 @@ void ConnectionSendThread::processNonReliableCommand(ConnectionCommand &c) sendAsPacket(c.peer_id,c.channelnum,c.data,true); return; case CONCMD_CREATE_PEER: - assert("Got command that should be reliable as unreliable command" == 0); + FATAL_ERROR("Got command that should be reliable as unreliable command"); default: LOG(dout_con<<m_connection->getDesc() <<" Invalid command type: " << c.type <<std::endl); @@ -1778,7 +1777,7 @@ void ConnectionSendThread::disconnect_peer(u16 peer_id) void ConnectionSendThread::send(u16 peer_id, u8 channelnum, SharedBuffer<u8> data) { - assert(channelnum < CHANNEL_COUNT); + assert(channelnum < CHANNEL_COUNT); // Pre-condition PeerHelper peer = m_connection->getPeerNoEx(peer_id); if (!peer) @@ -2331,7 +2330,7 @@ SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel, if (MAX_UDP_PEERS <= 65535 && peer_id >= MAX_UDP_PEERS) { errorstream << "Something is wrong with peer_id" << std::endl; - assert(0); + FATAL_ERROR(""); } if (type == TYPE_CONTROL) @@ -2343,7 +2342,7 @@ SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel, if (controltype == CONTROLTYPE_ACK) { - assert(channel != 0); + FATAL_ERROR_IF(channel == 0, "Invalid channel (0)"); if (packetdata.getSize() < 4) throw InvalidIncomingDataException ("packetdata.getSize() < 4 (ACK header size)"); @@ -2511,7 +2510,7 @@ SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel, } else if (type == TYPE_RELIABLE) { - assert(channel != 0); + FATAL_ERROR_IF(channel == 0, "Invalid channel (0)"); // Recursive reliable packets not allowed if (reliable) throw InvalidIncomingDataException("Found nested reliable packets"); @@ -2635,10 +2634,7 @@ SharedBuffer<u8> ConnectionReceiveThread::processPacket(Channel *channel, } // We should never get here. - // If you get here, add an exception or a return to some of the - // above conditionals. - assert(0); - throw BaseException("Error in Channel::ProcessPacket()"); + FATAL_ERROR("Invalid execution point"); } /* @@ -2724,7 +2720,7 @@ Connection::~Connection() /* Internal stuff */ void Connection::putEvent(ConnectionEvent &e) { - assert(e.type != CONNEVENT_NONE); + assert(e.type != CONNEVENT_NONE); // Pre-condition m_event_queue.push_back(e); } @@ -2738,7 +2734,7 @@ PeerHelper Connection::getPeer(u16 peer_id) } // Error checking - assert(node->second->id == peer_id); + FATAL_ERROR_IF(node->second->id != peer_id, "Invalid peer id"); return PeerHelper(node->second); } @@ -2753,7 +2749,7 @@ PeerHelper Connection::getPeerNoEx(u16 peer_id) } // Error checking - assert(node->second->id == peer_id); + FATAL_ERROR_IF(node->second->id != peer_id, "Invalid peer id"); return PeerHelper(node->second); } @@ -2925,7 +2921,7 @@ u32 Connection::Receive(u16 &peer_id, SharedBuffer<u8> &data) void Connection::Send(u16 peer_id, u8 channelnum, NetworkPacket* pkt, bool reliable) { - assert(channelnum < CHANNEL_COUNT); + assert(channelnum < CHANNEL_COUNT); // Pre-condition ConnectionCommand c; @@ -2955,9 +2951,7 @@ float Connection::getLocalStat(rate_stat_type type) { PeerHelper peer = getPeerNoEx(PEER_ID_SERVER); - if (!peer) { - assert("Connection::getLocalStat we couldn't get our own peer? are you serious???" == 0); - } + FATAL_ERROR_IF(!peer, "Connection::getLocalStat we couldn't get our own peer? are you serious???"); float retval = 0.0; @@ -2982,7 +2976,7 @@ float Connection::getLocalStat(rate_stat_type type) retval += dynamic_cast<UDPPeer*>(&peer)->channels[j].getCurrentLossRateKB(); break; default: - assert("Connection::getLocalStat Invalid stat type" == 0); + FATAL_ERROR("Connection::getLocalStat Invalid stat type"); } } return retval; @@ -3075,7 +3069,7 @@ void Connection::DisconnectPeer(u16 peer_id) void Connection::sendAck(u16 peer_id, u8 channelnum, u16 seqnum) { - assert(channelnum < CHANNEL_COUNT); + assert(channelnum < CHANNEL_COUNT); // Pre-condition LOG(dout_con<<getDesc() <<" Queuing ACK command to peer_id: " << peer_id << diff --git a/src/network/connection.h b/src/network/connection.h index 77d7edac0..33b7d0f7f 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -681,7 +681,7 @@ class Peer { virtual ~Peer() { JMutexAutoLock usage_lock(m_exclusive_access_mutex); - assert(m_usage == 0); + FATAL_ERROR_IF(m_usage != 0, "Reference counting failure"); }; // Unique id of the peer @@ -926,7 +926,7 @@ public: void Trigger(); void setParent(Connection* parent) { - assert(parent != NULL); + assert(parent != NULL); // Pre-condition m_connection = parent; } @@ -980,7 +980,7 @@ public: void * Thread (); void setParent(Connection* parent) { - assert(parent != NULL); + assert(parent != NULL); // Pre-condition m_connection = parent; } diff --git a/src/network/packethandlers/client.cpp b/src/network/packethandlers/client.cpp index 82f8b61b7..69f39d1f3 100644 --- a/src/network/packethandlers/client.cpp +++ b/src/network/packethandlers/client.cpp @@ -476,7 +476,7 @@ void Client::handleCommand_AnnounceMedia(NetworkPacket* pkt) // Mesh update thread must be stopped while // updating content definitions - assert(!m_mesh_update_thread.IsRunning()); + sanity_check(!m_mesh_update_thread.IsRunning()); for (u16 i = 0; i < num_files; i++) { std::string name, sha1_base64; @@ -549,7 +549,7 @@ void Client::handleCommand_Media(NetworkPacket* pkt) // Mesh update thread must be stopped while // updating content definitions - assert(!m_mesh_update_thread.IsRunning()); + sanity_check(!m_mesh_update_thread.IsRunning()); for (u32 i=0; i < num_files; i++) { std::string name; @@ -575,7 +575,7 @@ void Client::handleCommand_NodeDef(NetworkPacket* pkt) // Mesh update thread must be stopped while // updating content definitions - assert(!m_mesh_update_thread.IsRunning()); + sanity_check(!m_mesh_update_thread.IsRunning()); // Decompress node definitions std::string datastring(pkt->getString(0), pkt->getSize()); @@ -602,7 +602,7 @@ void Client::handleCommand_ItemDef(NetworkPacket* pkt) // Mesh update thread must be stopped while // updating content definitions - assert(!m_mesh_update_thread.IsRunning()); + sanity_check(!m_mesh_update_thread.IsRunning()); // Decompress item definitions std::string datastring(pkt->getString(0), pkt->getSize()); |