diff options
Diffstat (limited to 'cpp/src/qpid/ha/ConnectionObserver.cpp')
-rw-r--r-- | cpp/src/qpid/ha/ConnectionObserver.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/cpp/src/qpid/ha/ConnectionObserver.cpp b/cpp/src/qpid/ha/ConnectionObserver.cpp index 3f7a1710d9..81ba3e4301 100644 --- a/cpp/src/qpid/ha/ConnectionObserver.cpp +++ b/cpp/src/qpid/ha/ConnectionObserver.cpp @@ -32,7 +32,7 @@ namespace ha { ConnectionObserver::ConnectionObserver(HaBroker& hb, const types::Uuid& uuid) : haBroker(hb), logPrefix("Connections: "), self(uuid) {} -bool ConnectionObserver::getBrokerInfo(broker::Connection& connection, BrokerInfo& info) { +bool ConnectionObserver::getBrokerInfo(const broker::Connection& connection, BrokerInfo& info) { framing::FieldTable ft; if (connection.getClientProperties().getTable(ConnectionObserver::BACKUP_TAG, ft)) { info = BrokerInfo(ft); @@ -51,21 +51,23 @@ ConnectionObserver::ObserverPtr ConnectionObserver::getObserver() { return observer; } +bool ConnectionObserver::isSelf(const broker::Connection& connection) { + BrokerInfo info; + return getBrokerInfo(connection, info) && info.getSystemId() == self; +} + void ConnectionObserver::opened(broker::Connection& connection) { try { if (connection.isLink()) return; // Allow outgoing links. if (connection.getClientProperties().isSet(ADMIN_TAG)) { - QPID_LOG(debug, logPrefix << "Allowing admin connection: " + QPID_LOG(debug, logPrefix << "Accepted admin connection: " << connection.getMgmtId()); return; // No need to call observer, always allow admins. } - BrokerInfo info; // Avoid self connections. - if (getBrokerInfo(connection, info)) { - if (info.getSystemId() == self) { - QPID_LOG(debug, "HA broker rejected self connection "+connection.getMgmtId()); - connection.abort(); - } - + if (isSelf(connection)) { // Reject self connections + QPID_LOG(debug, logPrefix << "Rejected self connection "+connection.getMgmtId()); + connection.abort(); + return; } ObserverPtr o(getObserver()); if (o) o->opened(connection); @@ -77,8 +79,8 @@ void ConnectionObserver::opened(broker::Connection& connection) { } void ConnectionObserver::closed(broker::Connection& connection) { + if (isSelf(connection)) return; // Ignore closing of self connections. try { - BrokerInfo info; ObserverPtr o(getObserver()); if (o) o->closed(connection); } |