Convert
Summary¶
srchybrid/Opcodes.h contains 100+ #define constants for protocol opcodes,
limits, and magic numbers. C-style #define bypasses the type system, pollutes
the global macro namespace, and is not debuggable. Replace with constexpr
values in a namespace (or enum class for opcode groups).
Current State¶
// Opcodes.h (excerpt):
#define OP_EDONKEYPROT 0xe3
#define OP_KADEMLIAHEADER 0xe4
#define OP_EMULEPROT 0xc5
#define PARTSIZE 9728000UL
#define EMBLOCKSIZE 180224UL
#define MAXCON5WIN9X 10 // dead Win9x constant — remove (see REF-017)
#define UPLOAD_CLIENT_MAXDATARATE (25*1024) // stale default — see FEAT-015/016
// ... 100+ more
Conversion Strategy¶
Protocol opcodes → enum class or constexpr uint8_t¶
namespace emule::protocol {
inline constexpr uint8_t OP_EDONKEYPROT = 0xe3;
inline constexpr uint8_t OP_KADEMLIAHEADER = 0xe4;
inline constexpr uint8_t OP_EMULEPROT = 0xc5;
// ...
}
Or as a typed enum:
enum class ProtocolHeader : uint8_t {
EDonkey = 0xe3,
Kademlia = 0xe4,
eMule = 0xc5,
// ...
};
Sizes and limits → inline constexpr¶
namespace emule::limits {
inline constexpr uint32_t PARTSIZE = 9'728'000UL;
inline constexpr uint32_t EMBLOCKSIZE = 180'224UL;
}
Dead / stale constants¶
Remove during this pass:
- MAXCON5WIN9X (dead Win9x — see REF-017)
- Constants superseded by FEAT-015/016 modern limits (coordinate with those issues)
Rollout Note¶
A full rename of 100+ defines is a large mechanical diff. Approach:
- Convert one logical group at a time (protocol headers, opcodes per protocol, size limits, timeout values)
- Use
using namespace emule::protocol;in.cppfiles temporarily to avoid mass call-site churn — removeusingdirectives as files are migrated - Keep
Opcodes.has the single include; just change the definitions inside
Files to Modify¶
| File | Change |
|---|---|
srchybrid/Opcodes.h |
Replace #define with constexpr / enum class |
All .cpp files that use opcode constants |
Update if namespace qualification required |
Acceptance Criteria¶
- [ ] No protocol-constant
#definemacros remain inOpcodes.h - [ ] Opcode values remain bitwise identical (no protocol change)
- [ ]
PARTSIZE,EMBLOCKSIZE,UDP_KAD_MAXFRAGMENTconverted to typedconstexpr(these are out of scope for FEAT-016 value changes) - [ ] Clean build with zero macro-vs-constexpr collision warnings