25 #ifndef NRG_CONNECTION_H
26 #define NRG_CONNECTION_H
29 #include "nrg_packet.h"
38 enum PacketFlags : uint8_t {
42 PKTFLAG_OUT_OF_ORDER = 0x01,
45 PKTFLAG_CONTINUED = 0x02,
48 PKTFLAG_FINISHED = 0x04,
49 PKTFLAG_RETRANSMISSION = 0x08,
50 PKTFLAG_STATE_CHANGE = 0x10,
51 PKTFLAG_STATE_CHANGE_ACK = 0x20,
85 bool new_packet, full_packet;
86 std::bitset<NRG_CONN_PACKET_HISTORY> packet_history;
87 PacketFlags latest_flags;
89 struct ReassemblyInfo {
90 ReassemblyInfo() : data(), age(-1), continued(
false){}
95 std::array<ReassemblyInfo, NRG_CONN_PACKET_HISTORY> reassembly_buf;
123 Packet buffer, buffer2, last;
132 : in(), out(remote_addr, sock_out){}
Common connection functionality that is used by both ConnectionIn and ConnectionOut.
Definition: nrg_connection.h:55
bool hasNewPacket() const
Returns true if there is a packet ready to be taken.
ConnectionOut(const NetAddress &remote_addr, const Socket &sock_out)
Create a new ConnectionOut that will send packets to remote_addr using the Socket sock_out...
Class for storing data to be sent / received across the network.
Definition: nrg_packet.h:58
ConnectionCommon()
Default Constructor.
Contains the NetAddress class for wrapping POSIX sockaddr structures and resolving hostnames to IP ad...
Status getLastStatus() const
Gets the Status that the last sending operation returned.
Status resendLastPacket(void)
Resends the last packet that was sent via this ConnectionOut instance.
Outgoing connection class.
Definition: nrg_connection.h:99
Status sendPacket(Packet &p, PacketFlags f=PKTFLAG_NONE)
Send Packet p, prepending header information including the given flags f, and applying any transforma...
bool addPacket(Packet &p)
Add a received packet with connection header information to be processed.
Incoming connection class.
Definition: nrg_connection.h:67
Connection(const NetAddress &remote_addr, const Socket &sock_out)
Standard Constructor.
Definition: nrg_connection.h:131
Classes to wrap POSIX sockets.
void setTransform(PacketTransformation *transform)
Set a PacketTransformation to be removed from packets added to the connection.
Class to wrap system and internal errors.
Definition: nrg_status.h:34
Combines both ConnectionIn and ConnectionOut into a single class.
Definition: nrg_connection.h:129
Base socket class.
Definition: nrg_socket.h:35
PacketFlags getLatestPacket(Packet &p)
Placed the latest packet into p, and returns its associated PacketFlags.
Status sendDisconnect(Packet &extra_data)
Send a Packet informing the remote host that the connection is over, extra_data can be a message expl...
Common defines and includes used by all the other nrg header files.
Class to wrap the various POSIX sockaddrs and resolve hostnames.
Definition: nrg_netaddress.h:32
void setTransform(PacketTransformation *transform)
Set a PacketTransformation to be removed from packets added to the connection.
ConnectionIn()
Default Constructor.
void setTransform(PacketTransformation *transform)
Add a PacketTransformation that will be applied to packets, or nullptr to disable.