You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2010/05/11 16:39:59 UTC
svn commit: r943130 - in /qpid/trunk/qpid/cpp: include/qpid/
include/qpid/sys/ src/qmf/engine/ src/qpid/ src/qpid/broker/
src/qpid/broker/windows/ src/qpid/client/ src/qpid/cluster/
src/qpid/sys/posix/ src/qpid/sys/solaris/ src/qpid/sys/ssl/ src/qpid/s...
Author: aconway
Date: Tue May 11 14:39:58 2010
New Revision: 943130
URL: http://svn.apache.org/viewvc?rev=943130&view=rev
Log:
Support for multiple protocols in qpid::Url.
- simplified qpid::Address to hold (protocol,host,port) triples.
- protocol plugins call Url:addProtocol to add tags to Url parser.
- use Address::protocol when establishing connections.
- ssl_test: tests using URL to connect.
Modified:
qpid/trunk/qpid/cpp/include/qpid/Address.h
qpid/trunk/qpid/cpp/include/qpid/Url.h
qpid/trunk/qpid/cpp/include/qpid/sys/SystemInfo.h
qpid/trunk/qpid/cpp/src/qmf/engine/BrokerProxyImpl.cpp
qpid/trunk/qpid/cpp/src/qpid/Address.cpp
qpid/trunk/qpid/cpp/src/qpid/Url.cpp
qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp
qpid/trunk/qpid/cpp/src/qpid/broker/Link.h
qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp
qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.h
qpid/trunk/qpid/cpp/src/qpid/broker/RetryList.cpp
qpid/trunk/qpid/cpp/src/qpid/broker/RetryList.h
qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp
qpid/trunk/qpid/cpp/src/qpid/client/Connection.cpp
qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.cpp
qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp
qpid/trunk/qpid/cpp/src/qpid/client/FailoverManager.cpp
qpid/trunk/qpid/cpp/src/qpid/cluster/MemberSet.cpp
qpid/trunk/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp
qpid/trunk/qpid/cpp/src/qpid/sys/solaris/SystemInfo.cpp
qpid/trunk/qpid/cpp/src/qpid/sys/ssl/util.cpp
qpid/trunk/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp
qpid/trunk/qpid/cpp/src/tests/ClusterFixture.cpp
qpid/trunk/qpid/cpp/src/tests/RetryList.cpp
qpid/trunk/qpid/cpp/src/tests/Url.cpp
qpid/trunk/qpid/cpp/src/tests/ssl_test
Modified: qpid/trunk/qpid/cpp/include/qpid/Address.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/Address.h?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/Address.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/Address.h Tue May 11 14:39:58 2010
@@ -21,64 +21,34 @@
#include "qpid/sys/IntegerTypes.h"
#include "qpid/CommonImportExport.h"
-#include <boost/variant.hpp>
#include <iosfwd>
#include <string>
-#include <vector>
namespace qpid {
+namespace client { class ConnectionSettings; }
-/** TCP address of a broker - host:port */
-struct TcpAddress {
- static const uint16_t DEFAULT_PORT=5672;
- QPID_COMMON_EXTERN explicit TcpAddress(const std::string& host_=std::string(),uint16_t port_=DEFAULT_PORT);
- std::string host;
- uint16_t port;
-};
-bool operator==(const TcpAddress& x, const TcpAddress& y);
-QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& os, const TcpAddress& a);
-
-/**@internal Not a real address type, this is a placeholder to
- * demonstrate and validate multi-protocol Urls for unit tests and
- * developer education only. An example address holds just a char.
- */
-struct ExampleAddress {
- explicit ExampleAddress(char data);
- char data;
-};
-bool operator==(const ExampleAddress& x, const ExampleAddress& y);
-std::ostream& operator<<(std::ostream& os, const ExampleAddress& a);
/**
- * Contains the address of an AMQP broker. Can any supported type of
- * broker address. Currently only TcpAddress is supported.
+ * Contains the protocol address of an AMQP broker.
*/
struct Address {
public:
- Address(const Address& a) : value(a.value) {}
- Address(const TcpAddress& tcp) : value(tcp) {}
- Address(const ExampleAddress& eg) : value(eg) {} ///<@internal
-
- template <class AddressType> Address& operator=(const AddressType& t) { value=t; return *this; }
-
- /** Get the address of type AddressType.
- *@return AddressType* pointing to the contained address or 0 if
- *contained address is not of type AddressType.
- */
- template <class AddressType> AddressType* get() { return boost::get<AddressType>(&value); }
-
- /** Get the address of type AddressType.
- *@return AddressType* pointing to the contained address or 0 if
- *contained address is not of type AddressType.
- */
- template <class AddressType> const AddressType* get() const { return boost::get<AddressType>(&value); }
-
-private:
- boost::variant<TcpAddress,ExampleAddress> value;
- friend std::ostream& operator<<(std::ostream& os, const Address& addr);
-};
+ static const std::string TCP; // Default TCP protocol tag.
+ static const uint16_t AMQP_PORT=5672; // Default AMQP port.
+
+ QPID_COMMON_EXTERN explicit Address(
+ const std::string& protocol_=std::string(),
+ const std::string& host_=std::string(),
+ uint16_t port_=0
+ ) : protocol(protocol_), host(host_), port(port_) {}
+ std::string protocol;
+ std::string host;
+ uint16_t port;
+};
+QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& os, const Address& addr);
+QPID_COMMON_EXTERN bool operator==(const Address& x, const Address& y);
} // namespace qpid
Modified: qpid/trunk/qpid/cpp/include/qpid/Url.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/Url.h?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/Url.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/Url.h Tue May 11 14:39:58 2010
@@ -29,13 +29,11 @@
namespace qpid {
-QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& os, const TcpAddress& a);
-
/** An AMQP URL contains a list of addresses */
struct Url : public std::vector<Address> {
/** Url with the hostname as returned by gethostname(2) */
- static Url getHostNameUrl(uint16_t port);
+ QPID_COMMON_EXTERN static Url getHostNameUrl(uint16_t port);
/** Url with local IP address(es), may be more than one address
* on a multi-homed host. */
@@ -65,21 +63,24 @@ struct Url : public std::vector<Address>
/** Throw Invalid if the URL does not contain any addresses. */
QPID_COMMON_EXTERN void throwIfEmpty() const;
- /** Replace contents with parsed URL as defined in
- * https://wiki.108.redhat.com/jira/browse/AMQP-95
+ /** Replace contents with parsed url
*@exception Invalid if the url is invalid.
*/
QPID_COMMON_EXTERN void parse(const char* url);
QPID_COMMON_EXTERN void parse(const std::string& url) { parse(url.c_str()); }
- /** Replace contesnts with parsed URL as defined in
- * https://wiki.108.redhat.com/jira/browse/AMQP-95
- * url.empty() will be true if url is invalid.
- */
+ /** Replace contesnts with parsed URL. Replace with empty URL if invalid. */
void parseNoThrow(const char* url);
+ /** Add a protocol tag to be recognzed in URLs.
+ * Only for use by protcol plug-in initializers.
+ */
+ static void addProtocol(const std::string& tag);
+
private:
mutable std::string cache; // cache string form for efficiency.
+ static std::vector<std::string> protocols;
+ friend class UrlParser;
};
inline bool operator==(const Url& a, const Url& b) { return a.str()==b.str(); }
Modified: qpid/trunk/qpid/cpp/include/qpid/sys/SystemInfo.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/sys/SystemInfo.h?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/sys/SystemInfo.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/sys/SystemInfo.h Tue May 11 14:39:58 2010
@@ -24,6 +24,7 @@
#include "qpid/sys/IntegerTypes.h"
#include "qpid/Address.h"
#include "qpid/CommonImportExport.h"
+#include <vector>
namespace qpid {
namespace sys {
@@ -40,10 +41,10 @@ namespace SystemInfo {
QPID_COMMON_EXTERN long concurrency();
/**
- * Get the local host name and set it in the specified TcpAddress.
+ * Get the local host name and set it in the specified.
* Returns false if it can't be obtained and sets errno to any error value.
*/
- QPID_COMMON_EXTERN bool getLocalHostname (TcpAddress &address);
+ QPID_COMMON_EXTERN bool getLocalHostname (Address &address);
QPID_COMMON_EXTERN void getLocalIpAddresses (uint16_t port, std::vector<Address> &addrList);
Modified: qpid/trunk/qpid/cpp/src/qmf/engine/BrokerProxyImpl.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qmf/engine/BrokerProxyImpl.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qmf/engine/BrokerProxyImpl.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qmf/engine/BrokerProxyImpl.cpp Tue May 11 14:39:58 2010
@@ -78,7 +78,7 @@ BrokerEvent BrokerEventImpl::copy()
BrokerProxyImpl::BrokerProxyImpl(BrokerProxy& pub, Console& _console) : publicObject(pub), console(_console)
{
stringstream qn;
- qpid::TcpAddress addr;
+ qpid::Address addr;
SystemInfo::getLocalHostname(addr);
qn << "qmfc-" << SystemInfo::getProcessName() << "-" << addr << "-" << SystemInfo::getProcessId();
Modified: qpid/trunk/qpid/cpp/src/qpid/Address.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/Address.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/Address.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/Address.cpp Tue May 11 14:39:58 2010
@@ -17,6 +17,7 @@
*/
#include "qpid/Address.h"
+#include "qpid/client/ConnectionSettings.h"
#include <ostream>
@@ -24,35 +25,14 @@ using namespace std;
namespace qpid {
-TcpAddress::TcpAddress(const std::string& h, uint16_t p): host(h), port(p) {}
+const string Address::TCP("tcp");
-struct AddressOstreamVisitor : public boost::static_visitor<ostream&> {
- ostream& out;
- AddressOstreamVisitor(ostream& o) : out(o) {}
- template <class T> ostream& operator()(const T& data) { return out << data; }
-};
-
-ostream& operator<<(ostream& os, const Address& addr) {
- AddressOstreamVisitor visitor(os);
- return boost::apply_visitor(visitor, addr.value);
+ostream& operator<<(ostream& os, const Address& a) {
+ return os << a.protocol << ":" << a.host << ":" << a.port;
}
-bool operator==(const TcpAddress& x, const TcpAddress& y) {
- return y.host==x.host && y.port == x.port;
-}
-
-ostream& operator<<(ostream& os, const TcpAddress& a) {
- return os << "tcp:" << a.host << ":" << a.port;
-}
-
-ExampleAddress::ExampleAddress(const char c) : data(c) {}
-
-bool operator==(const ExampleAddress& x, const ExampleAddress& y) {
- return x.data == y.data;
-}
-
-ostream& operator<<(ostream& os, const ExampleAddress& ex) {
- return os << "example:" << ex.data;
+bool operator==(const Address& x, const Address& y) {
+ return y.protocol==x.protocol && y.host==x.host && y.port == x.port;
}
} // namespace qpid
Modified: qpid/trunk/qpid/cpp/src/qpid/Url.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/Url.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/Url.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/Url.cpp Tue May 11 14:39:58 2010
@@ -21,6 +21,7 @@
#include "qpid/Msg.h"
#include "qpid/sys/SystemInfo.h"
#include "qpid/sys/StrError.h"
+#include "qpid/client/Connector.h"
#include <boost/lexical_cast.hpp>
@@ -36,7 +37,7 @@ namespace qpid {
Url::Invalid::Invalid(const string& s) : Exception(s) {}
Url Url::getHostNameUrl(uint16_t port) {
- TcpAddress address(std::string(), port);
+ Address address("tcp", std::string(), port);
if (!sys::SystemInfo::getLocalHostname(address))
throw Url::Invalid(QPID_MSG("Cannot get host name: " << qpid::sys::strError(errno)));
return Url(address);
@@ -68,50 +69,55 @@ ostream& operator<<(ostream& os, const U
return os;
}
+static const std::string TCP = "tcp";
+
+/** Simple recursive-descent parser for this grammar:
+ url = ["amqp:"] protocol_addr *("," protocol_addr)
+ protocol_addr = [ protocol_tag ":" ] host [":" port]
+ protocol_tag = "tcp" / "rdma" / "ssl"
-/** Simple recursive-descent parser for url grammar in AMQP 0-10 spec:
-
- amqp_url = "amqp:" prot_addr_list
- prot_addr_list = [prot_addr ","]* prot_addr
- prot_addr = tcp_prot_addr | tls_prot_addr
-
- tcp_prot_addr = tcp_id tcp_addr
- tcp_id = "tcp:" | ""
- tcp_addr = [host [":" port] ]
- host = <as per http://www.ietf.org/rfc/rfc3986.txt>
- port = number]]>
*/
class UrlParser {
public:
UrlParser(Url& u, const char* s) : url(u), text(s), end(s+strlen(s)), i(s) {}
- bool parse() { return literal("amqp:") && list(&UrlParser::protAddr, &UrlParser::comma) && i == end; }
+ bool parse() {
+ literal("amqp:"); // Optional
+ return list(&UrlParser::protocolAddr, &UrlParser::comma) && i == end;
+ }
private:
typedef bool (UrlParser::*Rule)();
bool comma() { return literal(","); }
- // NOTE: tcpAddr must be last since it is allowed to omit it's tcp: tag.
- bool protAddr() { return exampleAddr() || tcpAddr(); }
-
- bool tcpAddr() {
- TcpAddress addr;
- literal("tcp:"); // Don't check result, allowed to be absent.
- return addIf(host(addr.host) && (literal(":") ? port(addr.port) : true), addr);
- }
-
- // Placeholder address type till we have multiple address types. Address is a single char.
- bool exampleAddr () {
- if (literal("example:") && i < end) {
- ExampleAddress ex(*i++);
- url.push_back(ex);
- return true;
+ bool protocolAddr() {
+ Address addr(Address::TCP, "", Address::AMQP_PORT); // Set up defaults
+ protocolTag(addr.protocol); // Optional
+ bool ok = (host(addr.host) &&
+ (literal(":") ? port(addr.port) : true));
+ if (ok) url.push_back(addr);
+ return ok;
+ }
+
+ bool protocolTag(string& result) {
+ const char* j = std::find(i,end,':');
+ if (j != end) {
+ string tag(i,j);
+ if (std::find(Url::protocols.begin(), Url::protocols.end(), tag) !=
+ Url::protocols.end())
+ {
+ i = j+1;
+ result = tag;
+ return true;
+ }
}
return false;
}
- // FIXME aconway 2008-11-20: this does not implement http://www.ietf.org/rfc/rfc3986.txt.
- // Works for DNS names and ipv4 literals but won't handle ipv6.
+ // TODO aconway 2008-11-20: this does not fully implement
+ // http://www.ietf.org/rfc/rfc3986.txt. Works for DNS names and
+ // ipv4 literals but won't handle ipv6.
+ //
bool host(string& h) {
const char* start=i;
while (unreserved() || pctEncoded())
@@ -129,8 +135,6 @@ class UrlParser {
bool port(uint16_t& p) { return decimalInt(p); }
- template <class AddrType> bool addIf(bool ok, const AddrType& addr) { if (ok) url.push_back(addr); return ok; }
-
template <class IntType> bool decimalInt(IntType& n) {
const char* start = i;
while (decDigit())
@@ -209,4 +213,8 @@ std::istream& operator>>(std::istream& i
return is;
}
+std::vector<std::string> Url::protocols;
+
+void Url::addProtocol(const std::string& tag) { protocols.push_back(tag); }
+
} // namespace qpid
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Broker.cpp Tue May 11 14:39:58 2010
@@ -437,6 +437,7 @@ uint16_t Broker::getPort(const std::stri
void Broker::registerProtocolFactory(const std::string& name, ProtocolFactory::shared_ptr protocolFactory) {
protocolFactories[name] = protocolFactory;
+ Url::addProtocol(name);
}
void Broker::accept() {
@@ -461,8 +462,8 @@ void Broker::connect(
sys::ConnectionCodec::Factory* f)
{
url.throwIfEmpty();
- const TcpAddress* addr=url[0].get<TcpAddress>();
- connect(addr->host, addr->port, TCP_TRANSPORT, failed, f);
+ const Address& addr=url[0];
+ connect(addr.host, addr.port, addr.protocol, failed, f);
}
uint32_t Broker::queueMoveMessages(
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Link.cpp Tue May 11 14:39:58 2010
@@ -307,11 +307,12 @@ void Link::maintenanceVisit ()
connection->requestIOProcessing (boost::bind(&Link::ioThreadProcessing, this));
}
-void Link::reconnect(const qpid::TcpAddress& a)
+void Link::reconnect(const qpid::Address& a)
{
Mutex::ScopedLock mutex(lock);
host = a.host;
port = a.port;
+ transport = a.protocol;
startConnectionLH();
if (mgmtObject != 0) {
stringstream errorString;
@@ -322,11 +323,10 @@ void Link::reconnect(const qpid::TcpAddr
bool Link::tryFailover()
{
- //TODO: urls only work for TCP at present, update when that has changed
- TcpAddress next;
- if (transport == Broker::TCP_TRANSPORT && urls.next(next) &&
- (next.host != host || next.port != port)) {
- links->changeAddress(TcpAddress(host, port), next);
+ Address next;
+ if (urls.next(next) &&
+ (next.host != host || next.port != port || next.protocol != transport)) {
+ links->changeAddress(Address(transport, host, port), next);
QPID_LOG(debug, "Link failing over to " << host << ":" << port);
return true;
} else {
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Link.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Link.h?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Link.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Link.h Tue May 11 14:39:58 2010
@@ -115,7 +115,7 @@ namespace qpid {
void established(); // Called when connection is created
void closed(int, std::string); // Called when connection goes away
void setConnection(Connection*); // Set pointer to the AMQP Connection
- void reconnect(const TcpAddress&); //called by LinkRegistry
+ void reconnect(const Address&); //called by LinkRegistry
string getAuthMechanism() { return authMechanism; }
string getUsername() { return username; }
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=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.cpp Tue May 11 14:39:58 2010
@@ -95,14 +95,14 @@ void LinkRegistry::periodicMaintenance (
reMappings.clear();
}
-void LinkRegistry::changeAddress(const qpid::TcpAddress& oldAddress, const qpid::TcpAddress& newAddress)
+void LinkRegistry::changeAddress(const qpid::Address& oldAddress, const qpid::Address& newAddress)
{
//done on periodic maintenance thread; hold changes in separate
//map to avoid modifying the link map that is iterated over
reMappings[createKey(oldAddress)] = newAddress;
}
-bool LinkRegistry::updateAddress(const std::string& oldKey, const qpid::TcpAddress& newAddress)
+bool LinkRegistry::updateAddress(const std::string& oldKey, const qpid::Address& newAddress)
{
std::string newKey = createKey(newAddress);
if (links.find(newKey) != links.end()) {
@@ -133,9 +133,7 @@ pair<Link::shared_ptr, bool> LinkRegistr
{
Mutex::ScopedLock locker(lock);
- stringstream keystream;
- keystream << host << ":" << port;
- string key = string(keystream.str());
+ string key = createKey(host, port);
LinkMap::iterator i = links.find(key);
if (i == links.end())
@@ -168,12 +166,10 @@ pair<Bridge::shared_ptr, bool> LinkRegis
Mutex::ScopedLock locker(lock);
QPID_LOG(debug, "Bridge declared " << host << ": " << port << " from " << src << " to " << dest << " (" << key << ")");
- stringstream keystream;
- keystream << host << ":" << port;
- string linkKey = string(keystream.str());
-
- keystream << "!" << src << "!" << dest << "!" << key;
- string bridgeKey = string(keystream.str());
+ string linkKey = createKey(host, port);
+ stringstream keystream;
+ keystream << linkKey << "!" << src << "!" << dest << "!" << key;
+ string bridgeKey = keystream.str();
LinkMap::iterator l = links.find(linkKey);
if (l == links.end())
@@ -210,9 +206,7 @@ pair<Bridge::shared_ptr, bool> LinkRegis
void LinkRegistry::destroy(const string& host, const uint16_t port)
{
Mutex::ScopedLock locker(lock);
- stringstream keystream;
- keystream << host << ":" << port;
- string key = string(keystream.str());
+ string key = createKey(host, port);
LinkMap::iterator i = links.find(key);
if (i != links.end())
@@ -231,16 +225,15 @@ void LinkRegistry::destroy(const std::st
const std::string& key)
{
Mutex::ScopedLock locker(lock);
- stringstream keystream;
- keystream << host << ":" << port;
- string linkKey = string(keystream.str());
+ string linkKey = createKey(host, port);
+ stringstream keystream;
+ keystream << linkKey << "!" << src << "!" << dest << "!" << key;
+ string bridgeKey = keystream.str();
LinkMap::iterator l = links.find(linkKey);
if (l == links.end())
return;
- keystream << "!" << src << "!" << dest << "!" << key;
- string bridgeKey = string(keystream.str());
BridgeMap::iterator b = bridges.find(bridgeKey);
if (b == bridges.end())
return;
@@ -328,11 +321,18 @@ std::string LinkRegistry::getAuthIdentit
}
-std::string LinkRegistry::createKey(const qpid::TcpAddress& a)
-{
- stringstream keystream;
- keystream << a.host << ":" << a.port;
- return string(keystream.str());
+std::string LinkRegistry::createKey(const qpid::Address& a) {
+ // TODO aconway 2010-05-11: key should also include protocol/transport to
+ // be unique. Requires refactor of LinkRegistry interface.
+ return createKey(a.host, a.port);
+}
+
+std::string LinkRegistry::createKey(const std::string& host, uint16_t port) {
+ // TODO aconway 2010-05-11: key should also include protocol/transport to
+ // be unique. Requires refactor of LinkRegistry interface.
+ stringstream keystream;
+ keystream << host << ":" << port;
+ return keystream.str();
}
void LinkRegistry::setPassive(bool p)
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.h?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/LinkRegistry.h Tue May 11 14:39:58 2010
@@ -53,7 +53,7 @@ namespace broker {
typedef std::map<std::string, boost::shared_ptr<Link> > LinkMap;
typedef std::map<std::string, Bridge::shared_ptr> BridgeMap;
- typedef std::map<std::string, TcpAddress> AddressMap;
+ typedef std::map<std::string, Address> AddressMap;
LinkMap links;
LinkMap linksToDestroy;
@@ -72,9 +72,10 @@ namespace broker {
std::string realm;
void periodicMaintenance ();
- bool updateAddress(const std::string& oldKey, const TcpAddress& newAddress);
+ bool updateAddress(const std::string& oldKey, const Address& newAddress);
boost::shared_ptr<Link> findLink(const std::string& key);
- static std::string createKey(const TcpAddress& address);
+ static std::string createKey(const Address& address);
+ static std::string createKey(const std::string& host, uint16_t port);
public:
LinkRegistry (); // Only used in store tests
@@ -135,7 +136,7 @@ namespace broker {
/**
* Called by links failing over to new address
*/
- void changeAddress(const TcpAddress& oldAddress, const TcpAddress& newAddress);
+ void changeAddress(const Address& oldAddress, const Address& newAddress);
/**
* Called to alter passive state. In passive state the links
* and bridges managed by a link registry will be recorded and
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/RetryList.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/RetryList.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/RetryList.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/RetryList.cpp Tue May 11 14:39:58 2010
@@ -31,20 +31,16 @@ void RetryList::reset(const std::vector<
urlIndex = addressIndex = 0;//reset indices
}
-bool RetryList::next(TcpAddress& address)
+bool RetryList::next(Address& address)
{
while (urlIndex < urls.size()) {
- while (addressIndex < urls[urlIndex].size()) {
- const TcpAddress* tcp = urls[urlIndex][addressIndex++].get<TcpAddress>();
- if (tcp) {
- address = *tcp;
- return true;
- }
+ if (addressIndex < urls[urlIndex].size()) {
+ address = urls[urlIndex][addressIndex++];
+ return true;
}
urlIndex++;
addressIndex = 0;
}
-
urlIndex = addressIndex = 0;//reset indices
return false;
}
Modified: qpid/trunk/qpid/cpp/src/qpid/broker/RetryList.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/RetryList.h?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/RetryList.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/RetryList.h Tue May 11 14:39:58 2010
@@ -38,7 +38,7 @@ class RetryList
public:
QPID_BROKER_EXTERN RetryList();
QPID_BROKER_EXTERN void reset(const std::vector<Url>& urls);
- QPID_BROKER_EXTERN bool next(TcpAddress& address);
+ QPID_BROKER_EXTERN bool next(Address& address);
private:
std::vector<Url> urls;
size_t urlIndex;
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=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/windows/SslProtocolFactory.cpp Tue May 11 14:39:58 2010
@@ -52,7 +52,7 @@ struct SslServerOptions : qpid::Options
SslServerOptions() : qpid::Options("SSL Options"),
certStore("My"), port(5671), clientAuth(false)
{
- qpid::TcpAddress me;
+ qpid::Address me;
if (qpid::sys::SystemInfo::getLocalHostname(me))
certName = me.host;
else
Modified: qpid/trunk/qpid/cpp/src/qpid/client/Connection.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/Connection.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/Connection.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/Connection.cpp Tue May 11 14:39:58 2010
@@ -71,19 +71,18 @@ void Connection::open(const Url& url, co
throw Exception(QPID_MSG("Attempt to open URL with no addresses."));
Url::const_iterator i = url.begin();
do {
- const TcpAddress* tcp = i->get<TcpAddress>();
+ const Address& addr = *i;
i++;
- if (tcp) {
- try {
- ConnectionSettings cs(settings);
- cs.host = tcp->host;
- cs.port = tcp->port;
- open(cs);
- break;
- }
- catch (const Exception& /*e*/) {
- if (i == url.end()) throw;
- }
+ try {
+ ConnectionSettings cs(settings);
+ cs.protocol = addr.protocol;
+ cs.host = addr.host;
+ cs.port = addr.port;
+ open(cs);
+ break;
+ }
+ catch (const Exception& /*e*/) {
+ if (i == url.end()) throw;
}
} while (i != url.end());
}
Modified: qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/ConnectionSettings.cpp Tue May 11 14:39:58 2010
@@ -31,7 +31,7 @@ namespace client {
ConnectionSettings::ConnectionSettings() :
protocol("tcp"),
host("localhost"),
- port(TcpAddress::DEFAULT_PORT),
+ port(5672),
locale("en_US"),
heartbeat(0),
maxChannels(32767),
Modified: qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/Connector.cpp Tue May 11 14:39:58 2010
@@ -20,7 +20,7 @@
*/
#include "qpid/client/Connector.h"
-
+#include "qpid/Url.h"
#include "qpid/Exception.h"
#include "qpid/log/Statement.h"
#include "qpid/sys/SecurityLayer.h"
@@ -61,6 +61,7 @@ void Connector::registerFactory(const st
QPID_LOG(error, "Tried to register protocol: " << proto << " more than once");
}
theProtocolRegistry()[proto] = connectorFactory;
+ Url::addProtocol(proto);
}
void Connector::activateSecurityLayer(std::auto_ptr<qpid::sys::SecurityLayer>)
Modified: qpid/trunk/qpid/cpp/src/qpid/client/FailoverManager.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/FailoverManager.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/FailoverManager.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/FailoverManager.cpp Tue May 11 14:39:58 2010
@@ -104,12 +104,11 @@ void FailoverManager::attempt(Connection
} else {
for (std::vector<Url>::const_iterator i = urls.begin(); i != urls.end() && !c.isOpen(); ++i) {
for (Url::const_iterator j = i->begin(); j != i->end() && !c.isOpen(); ++j) {
- const TcpAddress* tcp = j->get<TcpAddress>();
- if (tcp) {
- s.host = tcp->host;
- s.port = tcp->port;
- attempt(c, s);
- }
+ const Address& addr = *j;
+ s.protocol = addr.protocol;
+ s.host = addr.host;
+ s.port = addr.port;
+ attempt(c, s);
}
}
}
Modified: qpid/trunk/qpid/cpp/src/qpid/cluster/MemberSet.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/cluster/MemberSet.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/cluster/MemberSet.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/cluster/MemberSet.cpp Tue May 11 14:39:58 2010
@@ -20,6 +20,7 @@
*/
#include "MemberSet.h"
#include <ostream>
+#include <iterator>
#include <algorithm>
namespace qpid {
Modified: qpid/trunk/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/posix/SystemInfo.cpp Tue May 11 14:39:58 2010
@@ -50,7 +50,7 @@ long SystemInfo::concurrency() {
#endif
}
-bool SystemInfo::getLocalHostname (TcpAddress &address) {
+bool SystemInfo::getLocalHostname (Address &address) {
char name[HOST_NAME_MAX];
if (::gethostname(name, sizeof(name)) != 0)
return false;
@@ -59,6 +59,7 @@ bool SystemInfo::getLocalHostname (TcpAd
}
static const string LOCALHOST("127.0.0.1");
+static const string TCP("tcp");
void SystemInfo::getLocalIpAddresses (uint16_t port,
std::vector<Address> &addrList) {
@@ -83,7 +84,7 @@ void SystemInfo::getLocalIpAddresses (ui
}
string addr(dispName);
if (addr != LOCALHOST) {
- addrList.push_back(TcpAddress(addr, port));
+ addrList.push_back(Address(TCP, addr, port));
}
break;
}
@@ -97,7 +98,7 @@ void SystemInfo::getLocalIpAddresses (ui
freeifaddrs(ifaddr);
if (addrList.empty()) {
- addrList.push_back(TcpAddress(LOCALHOST, port));
+ addrList.push_back(Address(TCP, LOCALHOST, port));
}
}
Modified: qpid/trunk/qpid/cpp/src/qpid/sys/solaris/SystemInfo.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/solaris/SystemInfo.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/solaris/SystemInfo.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/solaris/SystemInfo.cpp Tue May 11 14:39:58 2010
@@ -49,7 +49,7 @@ long SystemInfo::concurrency() {
return sysconf(_SC_NPROCESSORS_ONLN);
}
-bool SystemInfo::getLocalHostname(TcpAddress &address) {
+bool SystemInfo::getLocalHostname(Address &address) {
char name[MAXHOSTNAMELEN];
if (::gethostname(name, sizeof(name)) != 0)
return false;
@@ -58,6 +58,7 @@ bool SystemInfo::getLocalHostname(TcpAdd
}
static const string LOCALHOST("127.0.0.1");
+static const string TCP("tcp");
void SystemInfo::getLocalIpAddresses(uint16_t port,
std::vector<Address> &addrList) {
@@ -71,10 +72,10 @@ void SystemInfo::getLocalIpAddresses(uin
struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.lifr_addr;
std::string addr(inet_ntoa(sin->sin_addr));
if (addr != LOCALHOST)
- addrList.push_back(TcpAddress(addr, port));
+ addrList.push_back(Address(TCP, addr, port));
}
if (addrList.empty()) {
- addrList.push_back(TcpAddress(LOCALHOST, port));
+ addrList.push_back(Address(TCP, LOCALHOST, port));
}
close (s);
}
Modified: qpid/trunk/qpid/cpp/src/qpid/sys/ssl/util.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/ssl/util.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/ssl/util.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/ssl/util.cpp Tue May 11 14:39:58 2010
@@ -38,13 +38,15 @@ namespace qpid {
namespace sys {
namespace ssl {
+static const std::string LOCALHOST("127.0.0.1");
+
std::string defaultCertName()
{
- TcpAddress address;
+ Address address;
if (SystemInfo::getLocalHostname(address)) {
return address.host;
} else {
- return "localhost";
+ return LOCALHOST;
}
}
Modified: qpid/trunk/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/windows/SystemInfo.cpp Tue May 11 14:39:58 2010
@@ -51,7 +51,7 @@ long SystemInfo::concurrency() {
return activeProcessors;
}
-bool SystemInfo::getLocalHostname (TcpAddress &address) {
+bool SystemInfo::getLocalHostname (Address &address) {
char name[HOST_NAME_MAX];
if (::gethostname(name, sizeof(name)) != 0) {
errno = WSAGetLastError();
@@ -61,10 +61,12 @@ bool SystemInfo::getLocalHostname (TcpAd
return true;
}
+static const std::string LOCALHOST("127.0.0.1");
+static const std::string TCP("tcp");
+
void SystemInfo::getLocalIpAddresses (uint16_t port,
std::vector<Address> &addrList) {
enum { MAX_URL_INTERFACES = 100 };
- static const std::string LOCALHOST("127.0.0.1");
SOCKET s = socket (PF_INET, SOCK_STREAM, 0);
if (s != INVALID_SOCKET) {
@@ -84,7 +86,7 @@ void SystemInfo::getLocalIpAddresses (ui
if (interfaces[i].iiFlags & IFF_UP) {
std::string addr(inet_ntoa(interfaces[i].iiAddress.AddressIn.sin_addr));
if (addr != LOCALHOST)
- addrList.push_back(TcpAddress(addr, port));
+ addrList.push_back(Address(TCP, addr, port));
}
}
closesocket (s);
Modified: qpid/trunk/qpid/cpp/src/tests/ClusterFixture.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/ClusterFixture.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/ClusterFixture.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/ClusterFixture.cpp Tue May 11 14:39:58 2010
@@ -153,7 +153,7 @@ std::set<int> knownBrokerPorts(qpid::cli
}
std::set<int> s;
for (std::vector<qpid::Url>::const_iterator i = urls.begin(); i != urls.end(); ++i)
- s.insert((*i)[0].get<qpid::TcpAddress>()->port);
+ s.insert((*i)[0].port);
return s;
}
Modified: qpid/trunk/qpid/cpp/src/tests/RetryList.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/RetryList.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/RetryList.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/RetryList.cpp Tue May 11 14:39:58 2010
@@ -33,7 +33,7 @@ struct RetryListFixture
{
RetryList list;
std::vector<Url> urls;
- std::vector<TcpAddress> expected;
+ std::vector<Address> expected;
void addUrl(const std::string& s)
{
@@ -42,15 +42,15 @@ struct RetryListFixture
void addExpectation(const std::string& host, uint16_t port)
{
- expected.push_back(TcpAddress(host, port));
+ expected.push_back(Address("tcp", host, port));
}
void check()
{
list.reset(urls);
for (int t = 0; t < 2; t++) {
- TcpAddress next;
- for (std::vector<TcpAddress>::const_iterator i = expected.begin(); i != expected.end(); ++i) {
+ Address next;
+ for (std::vector<Address>::const_iterator i = expected.begin(); i != expected.end(); ++i) {
BOOST_CHECK(list.next(next));
BOOST_CHECK_EQUAL(i->host, next.host);
BOOST_CHECK_EQUAL(i->port, next.port);
Modified: qpid/trunk/qpid/cpp/src/tests/Url.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/Url.cpp?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/Url.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/Url.cpp Tue May 11 14:39:58 2010
@@ -37,38 +37,37 @@ QPID_AUTO_TEST_SUITE(UrlTestSuite)
QPID_AUTO_TEST_CASE(TestParseTcp) {
URL_CHECK_STR("amqp:tcp:host:42");
URL_CHECK_STR("amqp:tcp:host-._~%ff%23:42"); // unreserved chars and pct encoded hex.
-
// Check defaults
BOOST_CHECK_EQUAL(Url("amqp:host:42").str(), "amqp:tcp:host:42");
BOOST_CHECK_EQUAL(Url("amqp:tcp:host").str(), "amqp:tcp:host:5672");
+ BOOST_CHECK_EQUAL(Url("host").str(), "amqp:tcp:host:5672");
+}
+QPID_AUTO_TEST_CASE(TestParseInvalid) {
//host is required:
URL_CHECK_INVALID("amqp:tcp:");
URL_CHECK_INVALID("amqp:");
URL_CHECK_INVALID("amqp::42");
+ URL_CHECK_INVALID("");
- URL_CHECK_INVALID("amqp::badHost!#$#");
- URL_CHECK_INVALID("amqp::host:badPort");
+ // Port must be numeric
+ URL_CHECK_INVALID("host:badPort");
}
-QPID_AUTO_TEST_CASE(TestParseExample) {
- URL_CHECK_STR("amqp:example:x");
- URL_CHECK_INVALID("amqp:example:badExample");
+QPID_AUTO_TEST_CASE(TestParseXyz) {
+ Url::addProtocol("xyz");
+ URL_CHECK_STR("amqp:xyz:host:123");
+ BOOST_CHECK_EQUAL(Url("xyz:host").str(), "amqp:xyz:host:5672");
}
QPID_AUTO_TEST_CASE(TestParseMultiAddress) {
- URL_CHECK_STR("amqp:tcp:host:0,example:y,tcp:foo:0,example:1");
- URL_CHECK_STR("amqp:example:z,tcp:foo:0");
+ Url::addProtocol("xyz");
+ URL_CHECK_STR("amqp:tcp:host:0,xyz:foo:123,tcp:foo:0,xyz:bar:1");
+ URL_CHECK_STR("amqp:xyz:foo:222,tcp:foo:0");
URL_CHECK_INVALID("amqp:tcp:h:0,");
URL_CHECK_INVALID(",amqp:tcp:h");
}
-
-QPID_AUTO_TEST_CASE(TestInvalidAddress) {
- URL_CHECK_INVALID("xxxx");
- URL_CHECK_INVALID("");
-}
-
QPID_AUTO_TEST_SUITE_END()
}} // namespace qpid::tests
Modified: qpid/trunk/qpid/cpp/src/tests/ssl_test
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/ssl_test?rev=943130&r1=943129&r2=943130&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/ssl_test (original)
+++ qpid/trunk/qpid/cpp/src/tests/ssl_test Tue May 11 14:39:58 2010
@@ -78,5 +78,11 @@ export QPID_NO_MODULE_DIR=1
export QPID_LOAD_MODULE=$SSLCONNECTOR_LIB
export QPID_SSL_CERT_DB=${CERT_DIR}
export QPID_SSL_CERT_PASSWORD_FILE=${CERT_PW_FILE}
+# Test connection via connection settings
./perftest --count ${COUNT} --port ${PORT} -P ssl -b $TEST_HOSTNAME --summary
+# Test connection with a URL
+URL=amqp:ssl:$TEST_HOSTNAME:$PORT
+./qpid_send -b $URL --content-string=hello -a "foo;{create:always}"
+MSG=`./qpid_receive -b $URL -a "foo;{create:always}" --messages 1`
+test "$MSG" = "hello" || { echo "receive failed '$MSG' != 'hello'"; exit 1; }
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org