From e440e55d45a571c221af9c1657a2006597a6b88f Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Mon, 26 Mar 2012 13:08:00 +0200 Subject: Handle duplicate identities decently When connection with duplicate identity arrives it is ignored. Till now it resulted in assertion. Signed-off-by: Martin Sustrik --- src/xrep.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3