mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ucentralgw.git
				synced 2025-11-03 20:27:45 +00:00 
			
		
		
		
	Compare commits
	
		
			3 Commits
		
	
	
		
			add_enroll
			...
			fix_deadlo
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					115f8c1df9 | ||
| 
						 | 
					8e5eebec67 | ||
| 
						 | 
					b3d55d38d5 | 
@@ -561,14 +561,14 @@ namespace OpenWifi {
 | 
				
			|||||||
	void AP_WS_Connection::OnSocketShutdown(
 | 
						void AP_WS_Connection::OnSocketShutdown(
 | 
				
			||||||
		[[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
 | 
							[[maybe_unused]] const Poco::AutoPtr<Poco::Net::ShutdownNotification> &pNf) {
 | 
				
			||||||
		poco_trace(Logger_, fmt::format("SOCKET-SHUTDOWN({}): Closing.", CId_));
 | 
							poco_trace(Logger_, fmt::format("SOCKET-SHUTDOWN({}): Closing.", CId_));
 | 
				
			||||||
//		std::lock_guard	G(ConnectionMutex_);
 | 
							std::lock_guard	G(ConnectionMutex_);
 | 
				
			||||||
		return EndConnection();
 | 
							return EndConnection();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void AP_WS_Connection::OnSocketError(
 | 
						void AP_WS_Connection::OnSocketError(
 | 
				
			||||||
		[[maybe_unused]] const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf) {
 | 
							[[maybe_unused]] const Poco::AutoPtr<Poco::Net::ErrorNotification> &pNf) {
 | 
				
			||||||
		poco_trace(Logger_, fmt::format("SOCKET-ERROR({}): Closing.", CId_));
 | 
							poco_trace(Logger_, fmt::format("SOCKET-ERROR({}): Closing.", CId_));
 | 
				
			||||||
//		std::lock_guard	G(ConnectionMutex_);
 | 
							std::lock_guard	G(ConnectionMutex_);
 | 
				
			||||||
		return EndConnection();
 | 
							return EndConnection();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -652,9 +652,10 @@ namespace OpenWifi {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
				case Poco::Net::WebSocket::FRAME_OP_TEXT: {
 | 
									case Poco::Net::WebSocket::FRAME_OP_TEXT: {
 | 
				
			||||||
					poco_trace(Logger_,
 | 
										poco_trace(Logger_,
 | 
				
			||||||
							   fmt::format("FRAME({}): Frame received (length={}, flags={}). Msg={}",
 | 
											fmt::format("FRAME({}): Frame received (length={}, flags={}). Msg={}",
 | 
				
			||||||
										   CId_, IncomingSize, flags, IncomingFrame.begin()));
 | 
														CId_, IncomingSize, flags, IncomingFrame.begin()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
										
 | 
				
			||||||
					Poco::JSON::Parser parser;
 | 
										Poco::JSON::Parser parser;
 | 
				
			||||||
					auto ParsedMessage = parser.parse(IncomingFrame.begin());
 | 
										auto ParsedMessage = parser.parse(IncomingFrame.begin());
 | 
				
			||||||
					auto IncomingJSON = ParsedMessage.extract<Poco::JSON::Object::Ptr>();
 | 
										auto IncomingJSON = ParsedMessage.extract<Poco::JSON::Object::Ptr>();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,8 +57,9 @@ namespace OpenWifi {
 | 
				
			|||||||
			if (request.find("Upgrade") != request.end() &&
 | 
								if (request.find("Upgrade") != request.end() &&
 | 
				
			||||||
				Poco::icompare(request["Upgrade"], "websocket") == 0) {
 | 
									Poco::icompare(request["Upgrade"], "websocket") == 0) {
 | 
				
			||||||
				Utils::SetThreadName("ws:conn-init");
 | 
									Utils::SetThreadName("ws:conn-init");
 | 
				
			||||||
				session_id_++;
 | 
									//session_id_++;
 | 
				
			||||||
				return new AP_WS_RequestHandler(Logger_, session_id_);
 | 
									auto new_session_id =  session_id_.fetch_add(1, std::memory_order_seq_cst) + 1;
 | 
				
			||||||
 | 
									return new AP_WS_RequestHandler(Logger_, new_session_id);
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				return nullptr;
 | 
									return nullptr;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -514,10 +515,27 @@ namespace OpenWifi {
 | 
				
			|||||||
			Connection = SessionHint->second;
 | 
								Connection = SessionHint->second;
 | 
				
			||||||
			Sessions_[sessionHash].erase(SessionHint);
 | 
								Sessions_[sessionHash].erase(SessionHint);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							std::atomic_bool duplicate_session = false;
 | 
				
			||||||
		auto deviceHash = MACHash::Hash(SerialNumber);
 | 
							{
 | 
				
			||||||
		std::lock_guard DeviceLock(SerialNumbersMutex_[deviceHash]);
 | 
								auto deviceHash = MACHash::Hash(SerialNumber);
 | 
				
			||||||
		SerialNumbers_[deviceHash][SerialNumber] = Connection;
 | 
								std::lock_guard DeviceLock(SerialNumbersMutex_[deviceHash]);
 | 
				
			||||||
 | 
								auto DeviceHint = SerialNumbers_[deviceHash].find(SerialNumber);
 | 
				
			||||||
 | 
					            if (DeviceHint == SerialNumbers_[deviceHash].end()) {
 | 
				
			||||||
 | 
					                // No duplicate connection go ahead and add new connection
 | 
				
			||||||
 | 
							        SerialNumbers_[deviceHash][SerialNumber] = Connection;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else {
 | 
				
			||||||
 | 
					                // Mark a duplicate session
 | 
				
			||||||
 | 
					                duplicate_session = true;
 | 
				
			||||||
 | 
									poco_information(Logger(), fmt::format("[session ID: {}] Found a duplicate connection for device serial: {}", session_id, Utils::IntToSerialNumber(SerialNumber)));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (duplicate_session.load()){
 | 
				
			||||||
 | 
					            // This is only called if we have a duplicate session
 | 
				
			||||||
 | 
					            // We remove the new incoming session that we just added a few lines above, forcing the destructor for this new session while not impacting the pointers to the old session.
 | 
				
			||||||
 | 
					            std::lock_guard SessionLock(SessionMutex_[sessionHash]);
 | 
				
			||||||
 | 
								Sessions_[sessionHash].erase(session_id);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool AP_WS_Server::EndSession(uint64_t session_id, uint64_t SerialNumber) {
 | 
						bool AP_WS_Server::EndSession(uint64_t session_id, uint64_t SerialNumber) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user