diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2012-03-26 13:08:00 +0200 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2012-03-26 13:08:00 +0200 |
commit | e440e55d45a571c221af9c1657a2006597a6b88f (patch) | |
tree | e377975399948896d2fe797a1dd4649aca0e727a /src | |
parent | 757f569715ad53760b5853c36d6ac5164c07b442 (diff) |
Handle duplicate identities decently
When connection with duplicate identity arrives it is ignored.
Till now it resulted in assertion.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/xrep.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/xrep.cpp b/src/xrep.cpp index f8565de..f0f2cde 100644 --- a/src/xrep.cpp +++ b/src/xrep.cpp @@ -217,23 +217,25 @@ int xs::xrep_t::xrecv (msg_t *msg_, int flags_) // Empty identity means we can preserve the auto-generated identity. if (msg_->size () != 0) { + // Check whether this is a duplicate identity. If so, drop the + // corresponding connection. + blob_t identity ((unsigned char*) msg_->data (), msg_->size ()); + if (outpipes.find (identity) != outpipes.end ()) { + pipe->terminate (false); + continue; + } + // Actual change of the identity. bool changed = false; outpipes_t::iterator it = outpipes.begin (); while (it != outpipes.end ()) { if (it->second.pipe == pipe) { - blob_t identity ((unsigned char*) msg_->data (), - msg_->size ()); pipe->set_identity (identity); outpipes.erase (it); outpipe_t outpipe = {pipe, true}; - if (!outpipes.insert (outpipes_t::value_type (identity, - outpipe)).second) { - - // Duplicate identity. - // TODO: Drop the new connection. - xs_assert (false); - } + bool ok = outpipes.insert (outpipes_t::value_type (identity, + outpipe)).second; + xs_assert (ok); changed = true; break; } |