Author: aconway Date: Tue Feb 1 21:26:00 2011 New Revision: 1066220 URL: http://svn.apache.org/viewvc?rev=1066220&view=rev Log: QPID-3007: Unique management identifier for connections.
Management was using remote socket address (host:port) to identify connections, but this is not a unique identifier. Both the local and remote addresses are needed to uniquely identify a connection - see http://www.faqs.org/rfcs/rfc793.html. This was causing management errors (multiple objects using same identifier) and cluster failures (invalid-arg exception) due to inconsistencies caused by the incorrect management map. This commit uses "localhost:localport-remotehost:remoteport" as a unique identifier. Modified: qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp qpid/trunk/qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h qpid/trunk/qpid/cpp/src/qpid/sys/SslPlugin.cpp qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp qpid/trunk/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h qpid/trunk/qpid/cpp/src/qpid/sys/ssl/SslSocket.h Modified: qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp?rev=1066220&r1=1066219&r2=1066220&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp Tue Feb 1 21:26:00 2011 @@ -255,8 +255,17 @@ MessageStore* LinkRegistry::getStore() c return store; } -Link::shared_ptr LinkRegistry::findLink(const std::string& key) +Link::shared_ptr LinkRegistry::findLink(const std::string& keyOrMgmtId) { + // Convert keyOrMgmtId to a host:port key. + // + // TODO aconway 2011-02-01: centralize code that constructs/parses + // connection management IDs. Currently sys:: protocol factories + // and IO plugins construct the IDs and LinkRegistry parses them. + size_t separator = keyOrMgmtId.find('-'); + if (separator == std::string::npos) separator = 0; + std::string key = keyOrMgmtId.substr(separator+1, std::string::npos); + Mutex::ScopedLock locker(lock); LinkMap::iterator l = links.find(key); if (l != links.end()) return l->second; Modified: qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp?rev=1066220&r1=1066219&r2=1066220&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp Tue Feb 1 21:26:00 2011 @@ -194,7 +194,7 @@ void SslProtocolFactory::established(sys const qpid::sys::Socket& s, sys::ConnectionCodec::Factory* f, bool isClient) { - sys::AsynchIOHandler* async = new sys::AsynchIOHandler(s.getPeerAddress(), f); + sys::AsynchIOHandler* async = new sys::AsynchIOHandler(s.getFullAddress(), f); if (tcpNoDelay) { s.setTcpNoDelay(); Modified: qpid/trunk/qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp?rev=1066220&r1=1066219&r2=1066220&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/RdmaIOPlugin.cpp Tue Feb 1 21:26:00 2011 @@ -84,7 +84,7 @@ class RdmaIOHandler : public OutputContr }; RdmaIOHandler::RdmaIOHandler(Rdma::Connection::intrusive_ptr c, qpid::sys::ConnectionCodec::Factory* f) : - identifier(c->getPeerName()), + identifier(c->getFullName()), factory(f), codec(0), readError(false), Modified: qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h?rev=1066220&r1=1066219&r2=1066220&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/Socket.h Tue Feb 1 21:26:00 2011 @@ -10,9 +10,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -60,27 +60,32 @@ public: QPID_COMMON_EXTERN int listen(uint16_t port = 0, int backlog = 10) const; QPID_COMMON_EXTERN int listen(const SocketAddress&, int backlog = 10) const; - /** Returns the "socket name" ie the address bound to + /** Returns the "socket name" ie the address bound to * the near end of the socket */ QPID_COMMON_EXTERN std::string getSockname() const; - /** Returns the "peer name" ie the address bound to + /** Returns the "peer name" ie the address bound to * the remote end of the socket */ std::string getPeername() const; - /** + /** * Returns an address (host and port) for the remote end of the * socket */ QPID_COMMON_EXTERN std::string getPeerAddress() const; - /** + /** * Returns an address (host and port) for the local end of the * socket */ std::string getLocalAddress() const; + /** + * Returns the full address of the connection: local and remote host and port. + */ + std::string getFullAddress() const { return getLocalAddress()+"-"+getPeerAddress(); } + QPID_COMMON_EXTERN uint16_t getLocalPort() const; uint16_t getRemotePort() const; @@ -95,7 +100,7 @@ public: */ QPID_COMMON_EXTERN Socket* accept() const; - // TODO The following are raw operations, maybe they need better wrapping? + // TODO The following are raw operations, maybe they need better wrapping? QPID_COMMON_EXTERN int read(void *buf, size_t count) const; QPID_COMMON_EXTERN int write(const void *buf, size_t count) const; Modified: qpid/trunk/qpid/cpp/src/qpid/sys/SslPlugin.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/SslPlugin.cpp?rev=1066220&r1=1066219&r2=1066220&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/SslPlugin.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/SslPlugin.cpp Tue Feb 1 21:26:00 2011 @@ -121,7 +121,7 @@ SslProtocolFactory::SslProtocolFactory(c void SslProtocolFactory::established(Poller::shared_ptr poller, const qpid::sys::ssl::SslSocket& s, ConnectionCodec::Factory* f, bool isClient) { - qpid::sys::ssl::SslHandler* async = new qpid::sys::ssl::SslHandler(s.getPeerAddress(), f, nodict); + qpid::sys::ssl::SslHandler* async = new qpid::sys::ssl::SslHandler(s.getFullAddress(), f, nodict); if (tcpNoDelay) { s.setTcpNoDelay(tcpNoDelay); Modified: qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp?rev=1066220&r1=1066219&r2=1066220&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/TCPIOPlugin.cpp Tue Feb 1 21:26:00 2011 @@ -81,7 +81,7 @@ AsynchIOProtocolFactory::AsynchIOProtoco void AsynchIOProtocolFactory::established(Poller::shared_ptr poller, const Socket& s, ConnectionCodec::Factory* f, bool isClient) { - AsynchIOHandler* async = new AsynchIOHandler(s.getPeerAddress(), f); + AsynchIOHandler* async = new AsynchIOHandler(s.getFullAddress(), f); if (tcpNoDelay) { s.setTcpNoDelay(); Modified: qpid/trunk/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h?rev=1066220&r1=1066219&r2=1066220&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/rdma/rdma_wrap.h Tue Feb 1 21:26:00 2011 @@ -274,6 +274,7 @@ namespace Rdma { QueuePair::intrusive_ptr getQueuePair(); std::string getLocalName() const; std::string getPeerName() const; + std::string getFullName() const { return getLocalName()+"-"+getPeerName(); } }; } Modified: qpid/trunk/qpid/cpp/src/qpid/sys/ssl/SslSocket.h URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/ssl/SslSocket.h?rev=1066220&r1=1066219&r2=1066220&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/ssl/SslSocket.h (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/ssl/SslSocket.h Tue Feb 1 21:26:00 2011 @@ -91,6 +91,11 @@ public: */ std::string getLocalAddress() const; + /** + * Returns the full address of the connection: local and remote host and port. + */ + std::string getFullAddress() const { return getLocalAddress()+"-"+getPeerAddress(); } + uint16_t getLocalPort() const; uint16_t getRemotePort() const; --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:[email protected]
