]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
m_spanningtree Update comments around collision handling
authorAttila Molnar <attilamolnar@hush.com>
Sat, 26 Jul 2014 13:47:52 +0000 (15:47 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Sat, 26 Jul 2014 13:47:52 +0000 (15:47 +0200)
src/modules/m_spanningtree/nick.cpp
src/modules/m_spanningtree/nickcollide.cpp
src/modules/m_spanningtree/uid.cpp

index c689a0fddb81ef3b2f0425f774ce71b4fcbff905..cdec280e1331af10255c61f405611149bbe17df5 100644 (file)
@@ -45,7 +45,8 @@ CmdResult CommandNick::HandleRemote(RemoteUser* user, std::vector<std::string>&
        User* x = ServerInstance->FindNickOnly(params[0]);
        if ((x) && (x != user) && (x->registered == REG_ALL))
        {
-               /* x is local, who is remote */
+               // 'x' is the already existing user using the same nick as params[0]
+               // 'user' is the user trying to change nick to the in use nick
                int collideret = Utils->DoCollision(x, TreeServer::Get(user), newts, user->ident, user->GetIPString(), user->uuid);
                if (collideret != 1)
                {
index 360014facfc520091e03567d7e5e4dcfa1f0bbc5..3b5944e9f92b475521de0aa2a2c9efedb00e74ae 100644 (file)
@@ -62,15 +62,10 @@ int SpanningTreeUtilities::DoCollision(User* u, TreeServer* server, time_t remot
        #define localident u->ident
        #define localip u->GetIPString()
 
-       /* mmk. let's do this again. */
-       if (remotets == localts)
+       // If the timestamps are not equal only one of the users has to change nick,
+       // otherwise both have to change
+       if (remotets != localts)
        {
-               /* equal. fuck them both! do nada, let the handler at the bottom figure this out. */
-       }
-       else
-       {
-               /* fuck. now it gets complex. */
-
                /* first, let's see if ident@host matches. */
                bool SamePerson = (localident == remoteident)
                                && (localip == remoteip);
@@ -82,19 +77,18 @@ int SpanningTreeUtilities::DoCollision(User* u, TreeServer* server, time_t remot
                if((SamePerson && remotets < localts) ||
                   (!SamePerson && remotets > localts))
                {
-                       /* remote needs to change */
+                       // Only remote needs to change
                        bChangeLocal = false;
                }
                else
                {
-                       /* ours needs to change */
+                       // Only ours needs to change
                        bChangeRemote = false;
                }
        }
 
        /*
-        * Cheat a little here. Instead of a dedicated command to change UID,
-        * use SAVE and accept the losing client with its UID (as we know the SAVE will
+        * Send SAVE and accept the losing client with its UID (as we know the SAVE will
         * not fail under any circumstances -- UIDs are netwide exclusive).
         *
         * This means that each side of a collide will generate one extra NICK back to where
@@ -108,7 +102,7 @@ int SpanningTreeUtilities::DoCollision(User* u, TreeServer* server, time_t remot
        {
                /*
                 * Local-side nick needs to change. Just in case we are hub, and
-                * this "local" nick is actually behind us, send an SAVE out.
+                * this "local" nick is actually behind us, send a SAVE out.
                 */
                CmdBuilder params("SAVE");
                params.push_back(u->uuid);
@@ -123,9 +117,8 @@ int SpanningTreeUtilities::DoCollision(User* u, TreeServer* server, time_t remot
        if (bChangeRemote)
        {
                /*
-                * remote side needs to change. If this happens, we will modify
-                * the UID or halt the propagation of the nick change command,
-                * so other servers don't need to see the SAVE
+                * Remote side needs to change. If this happens, we modify the UID or NICK and
+                * send back a SAVE to the source.
                 */
                TreeSocket* sock = server->GetSocket();
                sock->WriteLine(CmdBuilder("SAVE").push(remoteuid).push_int(remotets));
index 4d8f822037e5667298f89d8da3ea556585c71f82..cafaee4c077d015799419d6a2f0e5f8e97257157 100644 (file)
@@ -43,7 +43,7 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vector<std::st
        if (modestr[0] != '+')
                throw ProtocolException("Invalid mode string");
 
-       /* check for collision */
+       // See if there is a nick collision
        User* collideswith = ServerInstance->FindNickOnly(params[2]);
        if ((collideswith) && (collideswith->registered != REG_ALL))
        {
@@ -58,15 +58,14 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vector<std::st
        }
        else if (collideswith)
        {
-               /*
-                * Nick collision.
-                */
+               // The user on this side is registered, handle the collision
                int collide = Utils->DoCollision(collideswith, remoteserver, age_t, params[5], params[6], params[0]);
                ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "*** Collision on %s, collide=%d", params[2].c_str(), collide);
 
                if (collide != 1)
                {
-                       // Remote client lost, make sure we change their nick for the hash too
+                       // The client being introduced needs to change nick to uuid, change the nick in the message before
+                       // processing/forwarding it.
                        params[2] = params[0];
                }
        }