Merge tls into master: bring in subscription ownership, keep all TLS/stability work
tls and master diverged from a July 2024 fork point and never reconciled - tls carries ~19 months of real socket/TLS stability fixes (uninitialized tlsInfo, TCPServer::connectionRequest() unconditionally initializing TLS, the WANT_READ write busy-spin, the console authentication fix from this session), while master independently picked up a Subscription/SubscriptionManager rework (MString-based ownership tracking: owner/ownership/selection/time fields and a working subscriptionOwner() method) that tls never had. Every file both branches touched was resolved by keeping tls's side entirely (Command.h, Socket.cpp, TCPServer.h, TCPSession.cpp/h, TCPSocket.h were pure reformatting on master's side, or an alternate/superseded fix for a bug tls already fixed a different way - e.g. master's TCPSession uuid/alias handling vs tls's existing uuid_unparse-based fix), with two deliberate exceptions: - TCPServer.cpp's constructor was missing the commands.add(subscriptions, "publish"/"subscribe"/"catalog"/...) wiring master had - without it, SubscriptionManager existed but was completely unreachable through the normal command dispatch. Restored on top of tls's TLS-aware constructor. - SubscriptionManager.cpp's "invite" command handler had a real incompatibility: master's version assigned into an `invitee` member typed as coreutils::MString via a stray `(coreutils::MString *)` cast that doesn't match the member's actual (non-pointer) type, and called session.server.getSessionByAlias() against a TCPServer reference - tls made TCPSession::server a pointer (part of removing the separate TCPSession2 class), so that call site no longer compiles as written. Took tls's cleaner local-variable version instead (functionally identical - looks up a session by alias and forwards an invite message) and removed the now-unused `invitee` member from SubscriptionManager.h. One additional compile fix needed after resolving conflicts: Subscription::subscriptionOwners is an MString (master's ownership design), but TCPSession::alias is void* (tls's identity mechanism, unchanged and depended on elsewhere) - MString has an implicit constructor from void* already used successfully elsewhere in this same file (the "publish" handler's Subscription constructor call), but operator== doesn't accept the same implicit conversion, so removeSessionSubscriptions()'s ownership check needed an explicit coreutils::MString(session.alias) construction to compile. Also drops output/main (a stray checked-in compiled binary, already removed on tls) and the doxygen docs/html output (already removed on tls, was carried on master since the fork). Verified: full ServerCore rebuild (./compile) succeeds with zero errors or warnings beyond the one compile fix documented above.
This commit is contained in:
commit
3609ed603e
2883 files changed
+5296
-84468
No files matched your search
@@ -0,0 +1,151 @@
|
||||
#ifndef __TCPServer_h__
|
||||
# define __TCPServer_h__
|
||||
|
||||
# include "Command.h"
|
||||
# include "CommandList.h"
|
||||
# include "IPAddressList.h"
|
||||
# include "Socket.h"
|
||||
# include "SubscriptionManager.h"
|
||||
# include "TCPSession.h"
|
||||
# include "TCPSocket.h"
|
||||
# include "TLSInfo.h"
|
||||
|
||||
namespace core {
|
||||
|
||||
///
|
||||
/// TCPServer
|
||||
///
|
||||
/// Manage a socket connection as a TCP server type. Connections to the socket are processed through
|
||||
/// the accept functionality.
|
||||
///
|
||||
/// A list of connections is maintained in a vector object.
|
||||
///
|
||||
/// This object extends the Command object as well so it can be added to a Console object and
|
||||
/// process commands to display status information.
|
||||
///
|
||||
|
||||
class TCPServer : public TCPSocket, public Command {
|
||||
|
||||
public:
|
||||
|
||||
///
|
||||
/// The constructor for the TCPServer object.
|
||||
///
|
||||
/// @param ePoll the EPoll instance that manages the socket.
|
||||
/// @param url the IP address for the socket to receive connection requests.
|
||||
/// @param port the port number that the socket will listen on.
|
||||
/// @param commandName the name of the command used to invoke the status display for this object.
|
||||
///
|
||||
|
||||
TCPServer(EPoll &ePoll, IPAddress address, TLSInfo *tlsInfo, std::string delimiter = " ", int depth = 10, std::string text = "");
|
||||
|
||||
///
|
||||
/// The destructor for this object.
|
||||
///
|
||||
|
||||
virtual ~TCPServer();
|
||||
|
||||
virtual void sessionErrorHandler(std::string errorString, std::stringstream &out);
|
||||
|
||||
///
|
||||
/// getSocketAccept is designed to allow a polymorphic extension of this object to
|
||||
/// return a type of object that extends the definition of the server socket.
|
||||
/// Returning the appropriate session object that extends from Session provides
|
||||
/// the mechanism where the server can select the protocol dialog for the desired
|
||||
/// service.
|
||||
///
|
||||
|
||||
virtual TCPSession *getSocketAccept(EPoll &epoll);
|
||||
|
||||
///
|
||||
/// The list of sessions that are currently open and being maintained by this object.
|
||||
///
|
||||
|
||||
std::vector<TCPSession *> sessions;
|
||||
|
||||
///
|
||||
/// The commands object is a CommandList and is used to store Command objects to be
|
||||
/// parsed and run as data comes into the session.
|
||||
///
|
||||
|
||||
CommandList commands;
|
||||
|
||||
///
|
||||
/// If not NULL the blacklist object can be assigned to this server socket and the server
|
||||
/// IP addresses connecting to the server attempting to accept a socket are contained in
|
||||
/// this list then the connection is rejected and no accept is granted.
|
||||
///
|
||||
|
||||
IPAddressList *blackList;
|
||||
|
||||
///
|
||||
/// If not NULL the blacklist object can be assigned to this server socket and the server
|
||||
/// IP addresses connecting to the server attempting to accept a socket are contained in
|
||||
/// this list then the connection is rejected and no accept is granted.
|
||||
///
|
||||
|
||||
IPAddressList *whiteList;
|
||||
|
||||
void removeFromSessionList(TCPSession *session);
|
||||
|
||||
void output(std::stringstream &out); ///< Output the consoles array to the console.
|
||||
|
||||
///
|
||||
///
|
||||
///
|
||||
|
||||
void sendToAll(std::stringstream &out);
|
||||
|
||||
///
|
||||
/// Use this sendToAll method to output the contents of the out stream
|
||||
/// to all the connections on the server excluding the sender session.
|
||||
///
|
||||
|
||||
void sendToAll(std::stringstream &out, TCPSession &sender, SessionFilter filter);
|
||||
|
||||
///
|
||||
/// Use this sendToAll method to output the contents of the out stream
|
||||
/// to all the connections on the server excluding the sender session
|
||||
/// and the entries identified by the passed in filter object.
|
||||
///
|
||||
|
||||
void sendToAll(std::stringstream &out, TCPSession &sender);
|
||||
|
||||
///
|
||||
/// The Subscription Manager tracks all subscriptions on the server.
|
||||
///
|
||||
|
||||
SubscriptionManager subscriptions;
|
||||
|
||||
///
|
||||
/// Use the getSessionByAlias to retrieve a session pointer by the value
|
||||
/// of the alias pointer.
|
||||
///
|
||||
|
||||
TCPSession *getSessionByAlias(void *alias);
|
||||
|
||||
protected:
|
||||
///
|
||||
/// This method is called by the lower socket when a connection request comes into
|
||||
/// the listening and bound server port.
|
||||
///
|
||||
|
||||
void connectionRequest() override;
|
||||
|
||||
///
|
||||
/// This method is called when the Command associated with this object is requested
|
||||
/// because a user has typed in the associated command name on a command entry line.
|
||||
///
|
||||
/// @param the session object to write the output to.
|
||||
///
|
||||
|
||||
int processCommand(coreutils::ZString &request, TCPSession &session) override;
|
||||
|
||||
private:
|
||||
TCPSession *accept();
|
||||
std::mutex lock;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user