-
Notifications
You must be signed in to change notification settings - Fork 681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor of PcapRemoteDeviceList
's factory functions.
#1476
Refactor of PcapRemoteDeviceList
's factory functions.
#1476
Conversation
- Introduced `createRemoteDeviceList` static methods in `PcapRemoteDeviceList` for creating and managing remote device lists using `std::unique_ptr`, enhancing memory management and safety. - Modified existing `getRemoteDeviceList` methods to utilize new `createRemoteDeviceList` methods, maintaining backward compatibility by returning raw pointers through `.release()`. - Adopted smart pointers (`std::unique_ptr`) in the implementation for automatic memory cleanup, reducing the risk of memory leaks and improving code maintainability. - Modernized the codebase by leveraging C++11 smart pointers, simplifying resource management and providing a clearer, more flexible API for handling remote device lists with and without authentication.
Modernized the syntax for defining iterator and const iterator type aliases in `PcapRemoteDeviceList.h` within the `pcpp` namespace. Replaced traditional `typedef` with the `using` syntax for `RemoteDeviceListIterator` and `ConstRemoteDeviceListIterator`. These changes enhance code readability and align with modern C++ best practices without altering functionality.
- Removed the default constructor of 'PcapRemoteDeviceList'. - Added a new constructor to `PcapRemoteDeviceList` for initializing with detailed remote machine info and authentication. - Corrected typographical errors in comments for better documentation clarity. - Improved const-correctness in `createRemoteDeviceList` by changing `remoteAuth` parameter type. - Refactored device creation logic in `createRemoteDeviceList` for clearer error handling and separation of concerns. - Enhanced error handling in device creation to prevent memory leaks on exceptions. - Transitioned to using `std::shared_ptr<PcapRemoteAuthentication>` for better memory management in device creation. - Simplified authentication object handling by converting to `std::shared_ptr` early in the device creation process.
- Included DeprecationUtils.h in PcapRemoteDeviceList.h to mark certain functionalities as deprecated, indicating a move towards newer alternatives. - Updated the private constructor comment in PcapRemoteDeviceList to recommend using `createRemoteDeviceList` for instance creation, reflecting a shift to a new factory method. - Deprecated two static factory functions, `getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port)` and `getRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication* remoteAuth)`, in favor of `createRemoteDeviceList`, enhancing memory safety and functionality.
Pcap++/src/PcapRemoteDeviceList.cpp
Outdated
|
||
std::unique_ptr<PcapRemoteDeviceList> PcapRemoteDeviceList::createRemoteDeviceList(const IPAddress& ipAddress, uint16_t port, PcapRemoteAuthentication const* remoteAuth) | ||
{ | ||
std::shared_ptr<PcapRemoteAuthentication> sRemoteAuth; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the naming sRemoteAuth
, it's not the convention in this project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
however, we don't have many std::shared_ptr
currently. So if other people agree with this, this can become the official coding style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, I had a private overload where remoteAuth
was a shared ptr to avoid that, but scrapped it as it was not strictly nessesary.
Perhaps that would be a better solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh, I just named it that way coz i needed the variable to not conflict. If there are suggestions on a potential name, i'm happy to hear them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to remoteAuthCopy
to be more explicit that its a copy in 4f66704. Not sure if it should be remoteAuthCopy
or pRemoteAuthCopy
tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am fine with either, but seems pXXX
is more common in the codebase?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated cf3d1c2
Part of #1431. implements point 6.
createRemoteDeviceList
with overloads with/without authentication returningunique_ptr
.getRemoteDeviceList
due to the functions returning raw pointers.PcapRemoteDeviceList
PcapRemoteDeviceList
for detailed initialization.setRemoteMachineIpAddress
setRemoteMachinePort
setRemoteAuthentication