feat: RAII handles Peer & PacketPtr (#16)#33
Conversation
|
Warning Review limit reached
More reviews will be available in 9 minutes and 42 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review you lazy piece of rabbit |
|
(。•́︿•̀。) Sorry for the delay — reviewing now! ✅ Action performedReview finished.
|
Summary
Adds RAII wrappers around the two core MafiaNet lifetimes — wrap, don't remove the raw API (purely additive). Implements the keystone of issue #16.
MafiaNet::PacketPtr— owns aPacket*+ its owningRakPeerInterface*; callsDeallocatePacket()in its destructor. Movable, non-copyable, exception-safe (null-out on move; move-assign releases the held packet first + self-assignment guard). Exposesoperator->/operator*/get()/explicit operator bool, and anID_TIMESTAMP-awareid()(consolidates the sampleGetPacketIdentifierhelper; hardened against truncated-timestamp OOB reads in release builds).MafiaNet::Peer— owns theRakPeerInterface*(GetInstance()/DestroyInstance()); movable, non-copyable. Exposesoperator->/get()/explicit operator boolandPacketPtr receive().static_asserttrait checks pin the movable + non-copyable contract.mafianet.humbrella.GetInstance/DestroyInstance/DeallocatePacketand the copiedGetPacketIdentifierhelper).Naming note
The issue proposed
Peer.h, but a legacymafianet/peer.h(theRakPeerclass header) already exists and collides case-insensitively on macOS/Windows. The new header is thereforePeerHandle.h; the public class namesPeer/PacketPtrare unchanged.Test Plan
cmake --build build --target MafiaNetStatic.GetInstance/DeallocatePacketAPI still used by existing samples (acceptance Tier 1 modernization: sanitizer/format/Windows CI + UB & data-race fixes #2).build-asan/): chat client connects to a live chat server, processes real packets throughPacketPtr(ID_CONNECTION_REQUEST_ACCEPTED), sends a message, and quits cleanly — exit 0, no ASan use-after-free / double-free on the RAII move/destruct paths (acceptance chore(deps): update miniupnpc 2.2.8→2.3.3 & Opus 1.5.2→1.6.1 (+ test-suite fixes) #1 & feat(vcpkg): add MafiaNet vcpkg port + git registry #3). Note: LeakSanitizer'sdetect_leaksis unsupported on macOS; full leak detection should run in Linux CI.Tests SystemAddressAndGuidTestpasses.Closes #16