Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-13147
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Nov 25, 2023
1 parent 3f60c5a commit 7d8e15b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 47 deletions.
38 changes: 5 additions & 33 deletions src/AP_WS_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ namespace OpenWifi {
Context->flushSessionCache();
Context->enableSessionCache(true);
Context->enableExtendedCertificateVerification(false);
// Context->disableStatelessSessionResumption();
Context->disableProtocols(Poco::Net::Context::PROTO_TLSV1 |
Poco::Net::Context::PROTO_TLSV1_1);

Expand Down Expand Up @@ -177,7 +176,7 @@ namespace OpenWifi {

{
{
std::lock_guard L1(WSServerMutex_);
std::lock_guard SessionLock(SessionMutex_);
if (!Garbage_.empty()) {
Garbage_.clear();
}
Expand Down Expand Up @@ -222,7 +221,7 @@ namespace OpenWifi {

if(SessionsToRemove.empty()) {
poco_information(Logger(), fmt::format("Removing {} sessions.", SessionsToRemove.size()));
std::lock_guard L1(WSServerMutex_);
std::lock_guard Lock(SessionMutex_);
for (const auto &Session : SessionsToRemove) {
Sessions_.erase(Session);
}
Expand All @@ -234,7 +233,7 @@ namespace OpenWifi {

poco_information(Logger(), fmt::format("Garbage collecting done..."));
} else {
std::lock_guard L1(WSServerMutex_);
std::lock_guard SessionLock(SessionMutex_);
NumberOfConnectedDevices_ = Sessions_.size();
AverageDeviceConnectionTime_ += 10;
}
Expand Down Expand Up @@ -320,7 +319,7 @@ namespace OpenWifi {
}

void AP_WS_Server::SetSessionDetails(uint64_t connection_id, uint64_t SerialNumber) {
std::lock_guard L(WSServerMutex_);
std::lock_guard SessionLock(SessionMutex_);
auto Conn = Sessions_.find(connection_id);
if (Conn == end(Sessions_))
return;
Expand All @@ -336,8 +335,7 @@ namespace OpenWifi {
}

bool AP_WS_Server::EndSession(uint64_t session_id, uint64_t SerialNumber) {
std::lock_guard G(WSServerMutex_);

std::lock_guard SessionLock(SessionMutex_);
auto Session = Sessions_.find(session_id);
if (Session == end(Sessions_))
return false;
Expand All @@ -363,32 +361,6 @@ namespace OpenWifi {
return false;
}

/* bool AP_WS_Server::EndSessionUnSafe(uint64_t session_id, uint64_t serial_number) {
auto Session = Sessions_.find(session_id);
if (Session == end(Sessions_))
return false;
Garbage_.push_back(Session->second);
auto Device = SerialNumbers_.find(serial_number);
if (Device == end(SerialNumbers_)) {
Sessions_.erase(Session);
return false;
}
if (Device->second.first == session_id) {
Sessions_.erase(Session);
SerialNumbers_.erase(Device);
return true;
}
Sessions_.erase(Session);
return false;
}
*/

bool AP_WS_Server::Connected(uint64_t SerialNumber,
GWObjects::DeviceRestrictions &Restrictions) const {
auto hashIndex = Utils::CalculateMacAddressHash(SerialNumber);
Expand Down
18 changes: 4 additions & 14 deletions src/AP_WS_Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,10 @@ namespace OpenWifi {

inline void AddConnection(uint64_t session_id,
std::shared_ptr<AP_WS_Connection> Connection) {
std::lock_guard Lock(WSServerMutex_);
std::lock_guard Lock(SessionMutex_);
Sessions_[session_id] = std::move(Connection);
}

inline std::shared_ptr<AP_WS_Connection> FindConnection(uint64_t session_id) const {
std::lock_guard Lock(WSServerMutex_);

auto Connection = Sessions_.find(session_id);
if (Connection != end(Sessions_))
return Connection->second;
return nullptr;
}

inline bool DeviceRequiresSecureRtty(uint64_t serialNumber) const {
auto hashIndex = Utils::CalculateMacAddressHash(serialNumber);
std::lock_guard G(SerialNumbersMutex_[hashIndex]);
Expand Down Expand Up @@ -203,8 +194,7 @@ namespace OpenWifi {

// TOD: move to hash based map.
inline bool GetHealthDevices(std::uint64_t lowLimit, std::uint64_t highLimit, std::vector<std::string> & SerialNumbers) {
std::lock_guard G(WSServerMutex_);

std::lock_guard Lock(SessionMutex_);
for(const auto &connection:Sessions_) {
if( connection.second->RawLastHealthcheck_.Sanity>=lowLimit &&
connection.second->RawLastHealthcheck_.Sanity<=highLimit) {
Expand Down Expand Up @@ -238,7 +228,8 @@ namespace OpenWifi {
}

private:
mutable std::recursive_mutex WSServerMutex_;
mutable std::mutex SessionMutex_;
mutable std::mutex StatsMutex_;
std::unique_ptr<Poco::Crypto::X509Certificate> IssuerCert_;
std::list<std::unique_ptr<Poco::Net::HTTPServer>> WebServers_;
Poco::Net::SocketReactor Reactor_;
Expand Down Expand Up @@ -266,7 +257,6 @@ namespace OpenWifi {
std::uint64_t NumberOfConnectingDevices_ = 0;
std::uint64_t SessionTimeOut_ = 10*60;

mutable std::mutex StatsMutex_;
std::atomic_uint64_t TX_=0,RX_=0;

std::vector<std::shared_ptr<AP_WS_Connection>> Garbage_;
Expand Down

0 comments on commit 7d8e15b

Please sign in to comment.