summaryrefslogtreecommitdiff
path: root/src/modules/m_spanningtree/treesocket2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/m_spanningtree/treesocket2.cpp')
-rw-r--r--src/modules/m_spanningtree/treesocket2.cpp44
1 files changed, 12 insertions, 32 deletions
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);