summaryrefslogtreecommitdiff
path: root/src/connect_session.cpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-03-16 13:26:23 +0100
committerMartin Sustrik <sustrik@250bpm.com>2011-03-16 13:26:23 +0100
commit32ded2b457b2102dba4c15e00363f031d212b1c4 (patch)
tree163f0540f5f26277ba934bc80671a7c4fc73b7ad /src/connect_session.cpp
parentb79d07b8bc844135c44c1ff8b84b50dc08f56925 (diff)
Duplicate identities now checked with zmq_connect
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/connect_session.cpp')
-rw-r--r--src/connect_session.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/connect_session.cpp b/src/connect_session.cpp
index 0df9854..c0951cb 100644
--- a/src/connect_session.cpp
+++ b/src/connect_session.cpp
@@ -28,12 +28,15 @@ zmq::connect_session_t::connect_session_t (class io_thread_t *io_thread_,
const char *protocol_, const char *address_) :
session_t (io_thread_, socket_, options_),
protocol (protocol_),
- address (address_)
+ address (address_),
+ connected (false)
{
}
zmq::connect_session_t::~connect_session_t ()
{
+ if (connected && !peer_identity.empty ())
+ unregister_session (peer_identity);
}
void zmq::connect_session_t::process_plug ()
@@ -107,8 +110,46 @@ void zmq::connect_session_t::start_connecting (bool wait_)
zmq_assert (false);
}
-void zmq::connect_session_t::attached (const blob_t &peer_identity_)
+bool zmq::connect_session_t::attached (const blob_t &peer_identity_)
{
+ // If there was no previous connection...
+ if (!connected) {
+
+ // Peer has transient identity.
+ if (peer_identity_.empty () || peer_identity_ [0] == 0) {
+ connected = true;
+ return true;
+ }
+
+ // Peer has strong identity. Let's register it and check whether noone
+ // else is using the same identity.
+ if (!register_session (peer_identity_, this)) {
+ log ("DPID: duplicate peer identity - disconnecting peer");
+ return false;
+ }
+ connected = true;
+ peer_identity = peer_identity_;
+ return true;
+ }
+
+ // New engine from listener can conflict with existing engine.
+ // Alternatively, new engine created by reconnection process can
+ // conflict with engine supplied by listener in the meantime.
+ if (has_engine ()) {
+ log ("DPID: duplicate peer identity - disconnecting peer");
+ return false;
+ }
+
+ // If there have been a connection before, we have to check whether
+ // peer's identity haven't changed in the meantime.
+ if ((peer_identity_.empty () || peer_identity_ [0] == 0) &&
+ peer_identity.empty ())
+ return true;
+ if (peer_identity != peer_identity_) {
+ log ("CHID: peer have changed identity - disconnecting peer");
+ return false;
+ }
+ return true;
}
void zmq::connect_session_t::detached ()