2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author : Maxim Mamontov <faust@stargazer.dp.ua>
23 $Date: 2010/03/04 12:07:03 $
27 #ifndef __UR_FUNCTOR_H__
28 #define __UR_FUNCTOR_H__
39 class UpdateRouter : public std::unary_function<std::pair<const uint32_t, RS_USER>, void>
42 UpdateRouter(REMOTE_SCRIPT & t)
45 void operator() (std::pair<const uint32_t, RS_USER> & val)
47 std::vector<uint32_t> newRouters = obj.IP2Routers(val.first);
48 std::vector<uint32_t>::const_iterator oldIt(val.second.routers.begin());
49 std::vector<uint32_t>::const_iterator newIt(newRouters.begin());
50 val.second.shortPacketsCount = 0;
51 while (oldIt != val.second.routers.end() ||
52 newIt != newRouters.end())
54 if (oldIt == val.second.routers.end())
56 if (newIt != newRouters.end())
58 obj.SendDirect(val.first, val.second, *newIt); // Connect on new router
62 else if (newIt == newRouters.end())
64 //if (oldIt != newRouters.end())
65 //{ // Already checked it
66 obj.SendDirect(val.first, val.second, *oldIt, true); // Disconnect on old router
70 else if (*oldIt < *newIt)
72 obj.SendDirect(val.first, val.second, *oldIt, true); // Disconnect on old router
75 else if (*oldIt > *newIt)
77 obj.SendDirect(val.first, val.second, *newIt); // Connect on new router
82 if (oldIt != val.second.routers.end())
84 if (newIt != newRouters.end())
88 val.second.routers = newRouters;
89 /*if (val.second.souters != newRouters)
91 obj.Send(val.first, val.second, true); // Disconnect on old router
92 val.second.routerIP = obj.IP2Router(val.first); // Change router
93 val.second.shortPacketsCount = 0; // Reset packets count (to prevent alive send)
94 obj.Send(val.first, val.second); // Connect on new router