diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-03-16 17:42:51 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-03-16 17:42:51 +0000 |
commit | 5bbc794c7db6363e8f43b69a6f19307dfc411a04 (patch) | |
tree | 6537e127b73b3011166f19d38567a7d938131f8b | |
parent | 49b81e83328aedaa7d380f0f9413ce4fb3516578 (diff) |
Different timesync, dont use yet
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6683 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/modules/m_spanningtree/main.cpp | 10 | ||||
-rw-r--r-- | src/modules/m_spanningtree/timesynctimer.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treesocket2.cpp | 44 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_spanningtree/utils.h | 6 |
5 files changed, 28 insertions, 37 deletions
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp index 1f2509d4e..1fd33b946 100644 --- a/src/modules/m_spanningtree/main.cpp +++ b/src/modules/m_spanningtree/main.cpp @@ -566,9 +566,13 @@ int ModuleSpanningTree::HandleConnect(const char** parameters, int pcnt, userrec void ModuleSpanningTree::BroadcastTimeSync() { - std::deque<std::string> params; - params.push_back(ConvToStr(ServerInstance->Time(true))); - Utils->DoOneToMany(Utils->TreeRoot->GetName(), "TIMESET", params); + if (Utils->MasterTime) + { + std::deque<std::string> params; + params.push_back(ConvToStr(ServerInstance->Time(false))); + params.push_back("FORCE"); + Utils->DoOneToMany(Utils->TreeRoot->GetName(), "TIMESET", params); + } } int ModuleSpanningTree::OnStats(char statschar, userrec* user, string_list &results) diff --git a/src/modules/m_spanningtree/timesynctimer.cpp b/src/modules/m_spanningtree/timesynctimer.cpp index 908bbc62c..f374f9ac9 100644 --- a/src/modules/m_spanningtree/timesynctimer.cpp +++ b/src/modules/m_spanningtree/timesynctimer.cpp @@ -19,7 +19,7 @@ /* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */ -TimeSyncTimer::TimeSyncTimer(InspIRCd *Inst, ModuleSpanningTree *Mod) : InspTimer(43200, Inst->Time(), true), Instance(Inst), Module(Mod) +TimeSyncTimer::TimeSyncTimer(InspIRCd *Inst, ModuleSpanningTree *Mod) : InspTimer(3600, Inst->Time(), true), Instance(Inst), Module(Mod) { } diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 8bb404a45..db06a47c5 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -602,28 +602,17 @@ bool TreeSocket::HandleSetTime(const std::string &prefix, std::deque<std::string if ((params.size() == 2) && (params[1] == "FORCE")) force = true; - time_t rts = atoi(params[0].c_str()); - time_t us = Instance->Time(true); + time_t them = atoi(params[0].c_str()); + time_t us = Instance->Time(false); - if (rts == us) - { - Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix); - } - else if (force || (rts < us)) - { - int old = Instance->SetTimeDelta(rts - us); - Instance->Log(DEBUG, "%s TS (diff %d) from %s applied (old delta was %d)", (force) ? "Forced" : "Lower", rts - us, prefix.c_str(), old); + time_t diff = them - us; - Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix); - } - else - { - Instance->Log(DEBUG, "Higher TS (diff %d) from %s overridden", us - rts, prefix.c_str()); + Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix); - std::deque<std::string> oparams; - oparams.push_back(ConvToStr(us)); - - Utils->DoOneToMany(prefix, "TIMESET", oparams); + if (force || (them != us)) + { + time_t old = Instance->SetTimeDelta(diff); + Instance->Log(DEBUG, "TS (diff %d) from %s applied (old delta was %d)", diff, prefix.c_str(), old); } return true; @@ -947,13 +936,9 @@ bool TreeSocket::ProcessLine(std::string &line) { if (params.size() && Utils->EnableTimeSync) { - /* If a time stamp is provided, apply synchronization */ - bool force = false; + bool we_have_delta = (Instance->Time(false) != Instance->Time(true)); time_t them = atoi(params[0].c_str()); - time_t us = Instance->Time(false); - int delta = them - us; - if ((params.size() == 2) && (params[1] == "FORCE")) - force = true; + time_t delta = them - Instance->Time(false); if ((delta < -600) || (delta > 600)) { this->Instance->SNO->WriteToSnoMask('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than ten minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs(delta)); @@ -961,17 +946,12 @@ bool TreeSocket::ProcessLine(std::string &line) return false; } - if (force || (us > them)) + if (!Utils->MasterTime && !we_have_delta) { - this->Instance->SetTimeDelta(them - us); + this->Instance->SetTimeDelta(delta); // Send this new timestamp to any other servers Utils->DoOneToMany(Utils->TreeRoot->GetName(), "TIMESET", params); } - else - { - // Override the timestamp - this->WriteLine(":" + Utils->TreeRoot->GetName() + " TIMESET " + ConvToStr(us)); - } } this->LinkState = CONNECTED; Node = new TreeServer(this->Utils,this->Instance,InboundServerName,InboundDescription,Utils->TreeRoot,this); diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index eb4e8bb3a..c03839a19 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -377,7 +377,8 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind) FlatLinks = Conf->ReadFlag("options","flatlinks",0); HideULines = Conf->ReadFlag("options","hideulines",0); AnnounceTSChange = Conf->ReadFlag("options","announcets",0); - EnableTimeSync = Conf->ReadFlag("options","timesync",0); + EnableTimeSync = Conf->ReadFlag("timesync","enable",0); + MasterTime = Conf->ReadFlag("timesync", "master", 0); LinkBlocks.clear(); ValidIPs.clear(); for (int j =0; j < Conf->Enumerate("link"); j++) diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h index 97c617e0a..0194d461c 100644 --- a/src/modules/m_spanningtree/utils.h +++ b/src/modules/m_spanningtree/utils.h @@ -71,6 +71,12 @@ class SpanningTreeUtilities */ int lines_to_apply; + /** If this is true, this server is the master sync server for time + * synching - e.g. it is the server with its clock correct. It will + * send out the correct time at intervals. + */ + bool MasterTime; + /** List of module pointers which can provide I/O abstraction */ hookmodules hooks; |