From: Loic Blot Date: Sun, 3 Sep 2017 17:01:53 +0000 (+0200) Subject: Network part requires SharedBuffers to be pass as value X-Git-Tag: 5.0.0~863 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=eabf04bd34b840ee3359609fc977cf4795b33a3a;p=oweals%2Fminetest.git Network part requires SharedBuffers to be pass as value This can trigger unreproductible crashes due to concurrency problem on SharedBuffers This fixes #6354 --- diff --git a/src/network/connection.cpp b/src/network/connection.cpp index 01f1a7e63..b2e443901 100644 --- a/src/network/connection.cpp +++ b/src/network/connection.cpp @@ -55,7 +55,7 @@ std::mutex log_message_mutex; #define PING_TIMEOUT 5.0 -BufferedPacket makePacket(Address &address, const SharedBuffer &data, +BufferedPacket makePacket(Address &address, SharedBuffer data, u32 protocol_id, u16 sender_peer_id, u8 channel) { u32 packet_size = data.getSize() + BASE_HEADER_SIZE; @@ -125,7 +125,7 @@ void makeSplitPacket(const SharedBuffer &data, u32 chunksize_max, u16 seqnum } } -void makeAutoSplitPacket(const SharedBuffer &data, u32 chunksize_max, +void makeAutoSplitPacket(SharedBuffer data, u32 chunksize_max, u16 &split_seqnum, std::list> *list) { u32 original_header_size = 1; @@ -139,9 +139,7 @@ void makeAutoSplitPacket(const SharedBuffer &data, u32 chunksize_max, list->push_back(makeOriginalPacket(data)); } -SharedBuffer makeReliablePacket( - const SharedBuffer &data, - u16 seqnum) +SharedBuffer makeReliablePacket(SharedBuffer data, u16 seqnum) { u32 header_size = 3; u32 packet_size = data.getSize() + header_size; diff --git a/src/network/connection.h b/src/network/connection.h index c54161cc9..e1bb613f0 100644 --- a/src/network/connection.h +++ b/src/network/connection.h @@ -102,16 +102,16 @@ struct BufferedPacket }; // This adds the base headers to the data and makes a packet out of it -BufferedPacket makePacket(Address &address, const SharedBuffer &data, +BufferedPacket makePacket(Address &address, SharedBuffer data, u32 protocol_id, u16 sender_peer_id, u8 channel); // Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet // Increments split_seqnum if a split packet is made -void makeAutoSplitPacket(const SharedBuffer &data, u32 chunksize_max, +void makeAutoSplitPacket(SharedBuffer data, u32 chunksize_max, u16 &split_seqnum, std::list> *list); // Add the TYPE_RELIABLE header to the data -SharedBuffer makeReliablePacket(const SharedBuffer &data, u16 seqnum); +SharedBuffer makeReliablePacket(SharedBuffer data, u16 seqnum); struct IncomingSplitPacket { diff --git a/src/network/connectionthreads.cpp b/src/network/connectionthreads.cpp index 63c1855c5..ec09e9d3e 100644 --- a/src/network/connectionthreads.cpp +++ b/src/network/connectionthreads.cpp @@ -330,7 +330,7 @@ void ConnectionSendThread::sendAsPacketReliable(BufferedPacket &p, Channel *chan } bool ConnectionSendThread::rawSendAsPacket(u16 peer_id, u8 channelnum, - const SharedBuffer &data, bool reliable) + SharedBuffer data, bool reliable) { PeerHelper peer = m_connection->getPeerNoEx(peer_id); if (!peer) { diff --git a/src/network/connectionthreads.h b/src/network/connectionthreads.h index c2314f87f..906866468 100644 --- a/src/network/connectionthreads.h +++ b/src/network/connectionthreads.h @@ -52,7 +52,7 @@ public: private: void runTimeouts(float dtime); void rawSend(const BufferedPacket &packet); - bool rawSendAsPacket(u16 peer_id, u8 channelnum, const SharedBuffer &data, + bool rawSendAsPacket(u16 peer_id, u8 channelnum, SharedBuffer data, bool reliable); void processReliableCommand(ConnectionCommand &c);