+void Connection::Received(const UDPpacket &udp_pack) {
+ Packet &pack = *reinterpret_cast<Packet *>(udp_pack.data);
+
+ int diff = std::int16_t(pack.header.ctrl.seq) - std::int16_t(ctrl.ack);
+
+ if (diff > 0) {
+ // incoming more recent than last acked
+
+ // TODO: packets considered lost are detected here
+ // this should have ones for all of them:
+ // ~hist & ((1 << dist) - 1) if dist is < 32
+
+ if (diff >= 32) {
+ // missed more than the last 32 oO
+ ctrl.hist = 0;
+ } else {
+ ctrl.hist >>= diff;
+ ctrl.hist |= 1 << (32 - diff);
+ }
+ } else if (diff < 0) {
+ // incoming older than acked
+ if (diff > -32) {
+ // too late :/
+ } else {
+ ctrl.hist |= 1 << (32 + diff);
+ }
+ } else {
+ // incoming the same as last acked oO
+ }
+
+ ctrl.ack = pack.header.ctrl.seq;
+
+ FlagRecv();
+}
+