#include "util/thread.h"
#include <iostream>
#include <fstream>
+#include <list>
+#include <map>
namespace con
{
SharedBuffer<u8> data);
// Split data in chunks and add TYPE_SPLIT headers to them
-core::list<SharedBuffer<u8> > makeSplitPacket(
+std::list<SharedBuffer<u8> > makeSplitPacket(
SharedBuffer<u8> data,
u32 chunksize_max,
u16 seqnum);
// Depending on size, make a TYPE_ORIGINAL or TYPE_SPLIT packet
// Increments split_seqnum if a split packet is made
-core::list<SharedBuffer<u8> > makeAutoSplitPacket(
+std::list<SharedBuffer<u8> > makeAutoSplitPacket(
SharedBuffer<u8> data,
u32 chunksize_max,
u16 &split_seqnum);
reliable = false;
}
// Key is chunk number, value is data without headers
- core::map<u16, SharedBuffer<u8> > chunks;
+ std::map<u16, SharedBuffer<u8> > chunks;
u32 chunk_count;
float time; // Seconds from adding
bool reliable; // If true, isn't deleted on timeout
[6] u8 channel
sender_peer_id:
Unique to each peer.
- value 0 is reserved for making new connections
- value 1 is reserved for server
+ value 0 (PEER_ID_INEXISTENT) is reserved for making new connections
+ value 1 (PEER_ID_SERVER) is reserved for server
+ these constants are defined in constants.h
channel:
The lower the number, the higher the priority is.
Only channels 0, 1 and 2 exist.
*/
#define BASE_HEADER_SIZE 7
-#define PEER_ID_INEXISTENT 0
-#define PEER_ID_SERVER 1
#define CHANNEL_COUNT 3
/*
Packet types:
for fast access to the smallest one.
*/
-typedef core::list<BufferedPacket>::Iterator RPBSearchResult;
+typedef std::list<BufferedPacket>::iterator RPBSearchResult;
class ReliablePacketBuffer
{
public:
-
+ ReliablePacketBuffer();
void print();
bool empty();
u32 size();
RPBSearchResult findPacket(u16 seqnum);
RPBSearchResult notFound();
- u16 getFirstSeqnum();
+ bool getFirstSeqnum(u16 *result);
BufferedPacket popFirst();
BufferedPacket popSeqnum(u16 seqnum);
void insert(BufferedPacket &p);
void incrementTimeouts(float dtime);
void resetTimedOuts(float timeout);
bool anyTotaltimeReached(float timeout);
- core::list<BufferedPacket> getTimedOuts(float timeout);
+ std::list<BufferedPacket> getTimedOuts(float timeout);
private:
- core::list<BufferedPacket> m_list;
+ std::list<BufferedPacket> m_list;
+ u16 m_list_size;
};
/*
private:
// Key is seqnum
- core::map<u16, IncomingSplitPacket*> m_buf;
+ std::map<u16, IncomingSplitPacket*> m_buf;
};
class Connection;
class Connection: public SimpleThread
{
public:
- Connection(u32 protocol_id, u32 max_packet_size, float timeout);
- Connection(u32 protocol_id, u32 max_packet_size, float timeout,
+ Connection(u32 protocol_id, u32 max_packet_size, float timeout, bool ipv6);
+ Connection(u32 protocol_id, u32 max_packet_size, float timeout, bool ipv6,
PeerHandler *peerhandler);
~Connection();
void * Thread();
void rawSend(const BufferedPacket &packet);
Peer* getPeer(u16 peer_id);
Peer* getPeerNoEx(u16 peer_id);
- core::list<Peer*> getPeers();
+ std::list<Peer*> getPeers();
bool getFromBuffers(u16 &peer_id, SharedBuffer<u8> &dst);
// Returns next data from a buffer if possible
// If found, returns true; if not, false.
UDPSocket m_socket;
u16 m_peer_id;
- core::map<u16, Peer*> m_peers;
+ std::map<u16, Peer*> m_peers;
JMutex m_peers_mutex;
// Backwards compatibility