51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef CONNECTION_HEADER
-#define CONNECTION_HEADER
+#pragma once
#include "irrlichttypes_bloated.h"
+#include "peerhandler.h"
#include "socket.h"
-#include "exceptions.h"
#include "constants.h"
#include "util/pointer.h"
#include "util/container.h"
namespace con
{
-/*
- Exceptions
-*/
-class NotFoundException : public BaseException
-{
-public:
- NotFoundException(const char *s):
- BaseException(s)
- {}
-};
-
-class PeerNotFoundException : public BaseException
-{
-public:
- PeerNotFoundException(const char *s):
- BaseException(s)
- {}
-};
-
-class ConnectionException : public BaseException
-{
-public:
- ConnectionException(const char *s):
- BaseException(s)
- {}
-};
-
-class ConnectionBindFailed : public BaseException
-{
-public:
- ConnectionBindFailed(const char *s):
- BaseException(s)
- {}
-};
-
-class InvalidIncomingDataException : public BaseException
-{
-public:
- InvalidIncomingDataException(const char *s):
- BaseException(s)
- {}
-};
-
-class InvalidOutgoingDataException : public BaseException
-{
-public:
- InvalidOutgoingDataException(const char *s):
- BaseException(s)
- {}
-};
-
-class NoIncomingDataException : public BaseException
-{
-public:
- NoIncomingDataException(const char *s):
- BaseException(s)
- {}
-};
-
-class ProcessedSilentlyException : public BaseException
-{
-public:
- ProcessedSilentlyException(const char *s):
- BaseException(s)
- {}
-};
-
-class ProcessedQueued : public BaseException
-{
-public:
- ProcessedQueued(const char *s):
- BaseException(s)
- {}
-};
-
-class IncomingDataCorruption : public BaseException
-{
-public:
- IncomingDataCorruption(const char *s):
- BaseException(s)
- {}
-};
-
typedef enum MTProtocols {
MTP_PRIMARY,
MTP_UDP,
{
if ((totest - base) > (SEQNUM_MAX/2))
return false;
- else
- return true;
- }
- else
- {
- if ((base - totest) > (SEQNUM_MAX/2))
- return true;
- else
- return false;
+
+ return true;
}
+
+ if ((base - totest) > (SEQNUM_MAX/2))
+ return true;
+
+ return false;
}
inline bool seqnum_in_window(u16 seqnum, u16 next,u16 window_size)
u16 window_start = next;
u16 window_end = ( next + window_size ) % (SEQNUM_MAX+1);
- if (window_start < window_end)
- {
+ if (window_start < window_end) {
return ((seqnum >= window_start) && (seqnum < window_end));
}
- else
- {
- return ((seqnum < window_end) || (seqnum >= window_start));
- }
+
+
+ return ((seqnum < window_end) || (seqnum >= window_start));
}
struct BufferedPacket
data(a_data, a_size)
{}
BufferedPacket(u32 a_size):
- data(a_size), time(0.0), totaltime(0.0), absolute_send_time(-1),
- resend_count(0)
+ data(a_size)
{}
Buffer<u8> data; // Data of the packet, including headers
float time = 0.0f; // Seconds from buffering the packet or re-sending
// Add the TYPE_RELIABLE header to the data
SharedBuffer<u8> makeReliablePacket(
- SharedBuffer<u8> data,
+ const SharedBuffer<u8> &data,
u16 seqnum);
struct IncomingSplitPacket
{
- IncomingSplitPacket() {}
+ IncomingSplitPacket() = default;
+
// Key is chunk number, value is data without headers
std::map<u16, SharedBuffer<u8> > chunks;
u32 chunk_count;
class ReliablePacketBuffer
{
public:
- ReliablePacketBuffer() {};
+ ReliablePacketBuffer() = default;
bool getFirstSeqnum(u16& result);
bool reliable = false;
bool raw = false;
- ConnectionCommand() {}
+ ConnectionCommand() = default;
void serve(Address address_)
{
IncomingSplitBuffer incoming_splits;
- Channel() {};
- ~Channel() {};
+ Channel() = default;
+ ~Channel() = default;
void UpdatePacketLossCounter(unsigned int count);
void UpdatePacketTooLateCounter();
class Peer;
-enum PeerChangeType
-{
- PEER_ADDED,
- PEER_REMOVED
-};
-struct PeerChange
-{
- PeerChange(PeerChangeType t, u16 _peer_id, bool _timeout):
- type(t), peer_id(_peer_id), timeout(_timeout) {}
- PeerChange() = delete;
-
- PeerChangeType type;
- u16 peer_id;
- bool timeout;
-};
-
-class PeerHandler
-{
-public:
-
- PeerHandler()
- {
- }
- virtual ~PeerHandler()
- {
- }
-
- /*
- This is called after the Peer has been inserted into the
- Connection's peer container.
- */
- virtual void peerAdded(Peer *peer) = 0;
- /*
- This is called before the Peer has been removed from the
- Connection's peer container.
- */
- virtual void deletingPeer(Peer *peer, bool timeout) = 0;
-};
-
class PeerHelper
{
public:
- PeerHelper() {};
+ PeerHelper() = default;
PeerHelper(Peer* peer);
~PeerHelper();
class Connection;
-typedef enum {
- MIN_RTT,
- MAX_RTT,
- AVG_RTT,
- MIN_JITTER,
- MAX_JITTER,
- AVG_JITTER
-} rtt_stat_type;
-
typedef enum {
CUR_DL_RATE,
AVG_DL_RATE,
float max_rtt = 0.0f;
float avg_rtt = -1.0f;
- rttstats() {};
+ rttstats() = default;
};
rttstats m_rtt;
friend class Connection;
UDPPeer(u16 a_id, Address a_address, Connection* connection);
- virtual ~UDPPeer() {};
+ virtual ~UDPPeer() = default;
void PutReliableSendCommand(ConnectionCommand &c,
unsigned int max_packet_size);
bool timeout = false;
Address address;
- ConnectionEvent() {}
+ ConnectionEvent() = default;
std::string describe()
{
Connection *m_connection = nullptr;
};
+class PeerHandler;
+
class Connection
{
public:
};
} // namespace
-
-#endif