Nuke TIMESYNC from orbit \o/

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8998 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
w00t 2008-02-22 16:40:02 +00:00
parent 6dd148749f
commit 29b51086b9
25 changed files with 24 additions and 179 deletions

View File

@ -994,28 +994,6 @@
moronbanner="You're banned! Email haha@abuse.com with the ERROR line below for help."
exemptchanops="">
#-#-#-#-#-#-#-#-#-#-#-#-#-#- TIME SYNC OPTIONS -#-#-#-#-#-#-#-#-#-#-#-#
# Time synchronisation options for m_spanningtree linking. #
# #
# Because IRC is very time and clock dependent, InspIRCd provides its #
# own methods for synchronisation of time between servers as shown #
# in the example below, for servers that don't have ntpd running. #
# #
# enable - If this value is 'yes', 'true', or '1', time #
# synchronisation is enabled on this server. This #
# means any servers you are linked to will #
# automatically synchronise time, however you should #
# use ntpd instead where possible, NOT this option. #
# #
# master - If this value is set to yes, then this server will #
# act as the authoritative time source for the whole #
# network. All other servers will respect its time #
# without question, and match their times to it. #
# only one server should have the master value set #
# to 'yes'. #
# #
<timesync enable="no" master="no">
#-#-#-#-#-#-#-#-#-#-#-#-#- WHOWAS OPTIONS -#-#-#-#-#-#-#-#-#-#-#-#-#
# #
# This tag lets you define the behaviour of the /whowas command of #

View File

@ -304,11 +304,6 @@ class CoreExport InspIRCd : public classbase
*/
socklen_t length;
/** Time offset in seconds
* This offset is added to all calls to Time(). Use SetTimeDelta() to update
*/
int time_delta;
#ifdef WIN32
IPC* WindowsIPC;
#endif
@ -440,23 +435,9 @@ class CoreExport InspIRCd : public classbase
/** Get the current time
* Because this only calls time() once every time around the mainloop,
* it is much faster than calling time() directly.
* @param delta True to use the delta as an offset, false otherwise
* @return The current time as an epoch value (time_t)
*/
time_t Time(bool delta = false);
/** Set the time offset in seconds
* This offset is added to Time() to offset the system time by the specified
* number of seconds.
* @param delta The number of seconds to offset
* @return The old time delta
*/
int SetTimeDelta(int delta);
/** Get the time offset in seconds
* @return The current time delta (in seconds)
*/
int GetTimeDelta();
time_t Time();
/** Process a user whos socket has been flagged as active
* @param cu The user to process

View File

@ -26,7 +26,7 @@ Channel::Channel(InspIRCd* Instance, const std::string &cname, time_t ts) : Serv
(*(ServerInstance->chanlist))[cname.c_str()] = this;
strlcpy(this->name, cname.c_str(), CHANMAX);
this->created = ts ? ts : ServerInstance->Time(true);
this->created = ts ? ts : ServerInstance->Time();
this->age = this->created;

View File

@ -339,7 +339,6 @@ InspIRCd::InspIRCd(int argc, char** argv)
this->Config->operclass.clear();
this->TIME = this->OLDTIME = this->startup_time = time(NULL);
this->time_delta = 0;
srand(this->TIME);
*this->LogFileName = 0;
@ -740,26 +739,11 @@ bool InspIRCd::AllModulesReportReady(User* user)
return true;
}
time_t InspIRCd::Time(bool delta)
time_t InspIRCd::Time()
{
if (delta)
return TIME + time_delta;
return TIME;
}
int InspIRCd::SetTimeDelta(int delta)
{
int old = time_delta;
time_delta = delta;
this->Log(DEBUG, "Time delta set to %d (was %d)", time_delta, old);
return old;
}
int InspIRCd::GetTimeDelta()
{
return time_delta;
}
void InspIRCd::SetSignal(int signal)
{
*mysig = signal;

View File

@ -28,16 +28,11 @@ class CommandAlltime : public Command
CmdResult Handle(const char* const* parameters, int pcnt, User *user)
{
char fmtdate[64];
char fmtdate2[64];
time_t now = ServerInstance->Time(false);
time_t now = ServerInstance->Time();
strftime(fmtdate, sizeof(fmtdate), "%F %T", gmtime(&now));
now = ServerInstance->Time(true);
strftime(fmtdate2, sizeof(fmtdate2), "%F %T", gmtime(&now));
int delta = ServerInstance->GetTimeDelta();
std::string msg = ":" + std::string(ServerInstance->Config->ServerName) + " NOTICE " + user->nick + " :System time for " +
ServerInstance->Config->ServerName + " is: " + fmtdate + " (delta " + ConvToStr(delta) + " seconds): Time with delta: "+ fmtdate2;
ServerInstance->Config->ServerName + " is: " + fmtdate;
if (IS_LOCAL(user))
{

View File

@ -307,7 +307,7 @@ class ModuleBanRedirect : public Module
user->WriteServ("474 %s %s :Cannot join channel (You are banned)", user->nick, chan->name);
user->WriteServ("470 %s :You are being automatically redirected to %s", user->nick, redir->targetchan.c_str());
nofollow = true;
Channel::JoinUser(ServerInstance, user, redir->targetchan.c_str(), false, "", false, ServerInstance->Time(true));
Channel::JoinUser(ServerInstance, user, redir->targetchan.c_str(), false, "", false, ServerInstance->Time());
nofollow = false;
return 1;
}

View File

@ -82,7 +82,7 @@ class ModuleConnJoin : public Module
for(std::vector<std::string>::iterator it = Joinchans.begin(); it != Joinchans.end(); it++)
if (ServerInstance->IsChannel(it->c_str()))
Channel::JoinUser(ServerInstance, user, it->c_str(), false, "", false, ServerInstance->Time(true));
Channel::JoinUser(ServerInstance, user, it->c_str(), false, "", false, ServerInstance->Time());
}
};

View File

@ -62,7 +62,7 @@ class CommandCycle : public Command
if (!channel->PartUser(user, reason.c_str()))
delete channel;
Channel::JoinUser(ServerInstance, user, parameters[0], true, "", false, ServerInstance->Time(true));
Channel::JoinUser(ServerInstance, user, parameters[0], true, "", false, ServerInstance->Time());
}
return CMD_LOCALONLY;

View File

@ -117,7 +117,7 @@ class ModuleDenyChannels : public Module
if ((!newchan) || (!(newchan->IsModeSet('L'))))
{
user->WriteServ("926 %s %s :Channel %s is forbidden, redirecting to %s: %s",user->nick,cname,cname,redirect.c_str(), reason.c_str());
Channel::JoinUser(ServerInstance,user,redirect.c_str(),false,"",false,ServerInstance->Time(true));
Channel::JoinUser(ServerInstance,user,redirect.c_str(),false,"",false,ServerInstance->Time());
return 1;
}
}

View File

@ -77,7 +77,7 @@ class ModuleOperjoin : public Module
for(std::vector<std::string>::iterator it = operChans.begin(); it != operChans.end(); it++)
if (ServerInstance->IsChannel(it->c_str()))
Channel::JoinUser(ServerInstance, user, it->c_str(), false, "", false, ServerInstance->Time(true));
Channel::JoinUser(ServerInstance, user, it->c_str(), false, "", false, ServerInstance->Time());
}
};

View File

@ -132,7 +132,7 @@ class ModuleRedirect : public Module
}
user->WriteServ("470 %s :%s has become full, so you are automatically being transferred to the linked channel %s", user->nick, cname, channel.c_str());
Channel::JoinUser(ServerInstance, user, channel.c_str(), false, "", false, ServerInstance->Time(true));
Channel::JoinUser(ServerInstance, user, channel.c_str(), false, "", false, ServerInstance->Time());
return 1;
}
}

View File

@ -50,7 +50,7 @@ class CommandSajoin : public Command
*/
if (IS_LOCAL(dest))
{
Channel::JoinUser(ServerInstance, dest, parameters[1], true, "", false, ServerInstance->Time(true));
Channel::JoinUser(ServerInstance, dest, parameters[1], true, "", false, ServerInstance->Time());
/* Fix for dotslasher and w00t - if the join didnt succeed, return CMD_FAILURE so that it doesnt propagate */
Channel* n = ServerInstance->FindChan(parameters[1]);
if (n)

View File

@ -68,7 +68,7 @@ bool TreeSocket::ForceJoin(const std::string &source, std::deque<std::string> &p
irc::tokenstream users((params.size() > 2) ? params[2] : ""); /* users from the user list */
bool apply_other_sides_modes = true; /* True if we are accepting the other side's modes */
Channel* chan = this->Instance->FindChan(channel); /* The channel we're sending joins to */
time_t ourTS = chan ? chan->age : Instance->Time(true)+600; /* The TS of our side of the link */
time_t ourTS = chan ? chan->age : Instance->Time()+600; /* The TS of our side of the link */
bool created = !chan; /* True if the channel doesnt exist here yet */
std::string item; /* One item in the list of nicks */

View File

@ -42,14 +42,6 @@ ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me)
ServerInstance->AddCommand(command_rconnect);
command_rsquit = new cmd_rsquit(ServerInstance, this, Utils);
ServerInstance->AddCommand(command_rsquit);
if (Utils->EnableTimeSync)
{
SyncTimer = new TimeSyncTimer(ServerInstance, this);
ServerInstance->Timers->AddTimer(SyncTimer);
}
else
SyncTimer = NULL;
RefreshTimer = new CacheRefreshTimer(ServerInstance, Utils);
ServerInstance->Timers->AddTimer(RefreshTimer);
@ -416,17 +408,6 @@ int ModuleSpanningTree::HandleConnect(const char* const* parameters, int pcnt, U
return 1;
}
void ModuleSpanningTree::BroadcastTimeSync()
{
if (Utils->MasterTime)
{
std::deque<std::string> params;
params.push_back(ConvToStr(ServerInstance->Time(false)));
params.push_back("FORCE");
Utils->DoOneToMany(ServerInstance->Config->GetSID(), "TIMESET", params);
}
}
void ModuleSpanningTree::OnGetServerDescription(const std::string &servername,std::string &description)
{
TreeServer* s = Utils->FindServer(servername);
@ -691,7 +672,7 @@ void ModuleSpanningTree::OnUserPostNick(User* user, const std::string &oldnick)
/** IMPORTANT: We don't update the TS if the oldnick is just a case change of the newnick!
*/
if (irc::string(user->nick) != assign(oldnick))
user->age = ServerInstance->Time(true);
user->age = ServerInstance->Time();
params.push_back(ConvToStr(user->age));
Utils->DoOneToMany(user->uuid,"NICK",params);
@ -916,7 +897,7 @@ void ModuleSpanningTree::OnEvent(Event* event)
return;
(*params)[1] = ":" + (*params)[1];
params->insert(params->begin() + 1,ServerInstance->Config->ServerName);
params->insert(params->begin() + 1,ConvToStr(ServerInstance->Time(true)));
params->insert(params->begin() + 1,ConvToStr(ServerInstance->Time()));
Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC",*params);
}
else if (event->GetEventID() == "send_mode")
@ -1002,8 +983,6 @@ ModuleSpanningTree::~ModuleSpanningTree()
{
/* This will also free the listeners */
delete Utils;
if (SyncTimer)
ServerInstance->Timers->DelTimer(SyncTimer);
ServerInstance->Timers->DelTimer(RefreshTimer);

View File

@ -33,7 +33,6 @@ const long ProtocolVersion = 1200;
class cmd_rconnect;
class cmd_rsquit;
class SpanningTreeUtilities;
class TimeSyncTimer;
class CacheRefreshTimer;
class TreeServer;
class Link;
@ -51,10 +50,6 @@ class ModuleSpanningTree : public Module
SpanningTreeUtilities* Utils;
public:
/** Timer for clock syncs
*/
TimeSyncTimer *SyncTimer;
CacheRefreshTimer *RefreshTimer;
/** Constructor
@ -137,10 +132,6 @@ class ModuleSpanningTree : public Module
*/
int HandleConnect(const char* const* parameters, int pcnt, User* user);
/** Send out time sync to all servers
*/
void BroadcastTimeSync();
/** Attempt to send a message to a user
*/
void RemoteMessage(User* user, const char* format, ...);

View File

@ -29,7 +29,7 @@
void TreeSocket::DoBurst(TreeServer* s)
{
std::string name = s->GetName();
std::string burst = ":" + this->Instance->Config->GetSID() + " BURST " +ConvToStr(Instance->Time(true));
std::string burst = ":" + this->Instance->Config->GetSID() + " BURST " +ConvToStr(Instance->Time());
std::string endburst = ":" + this->Instance->Config->GetSID() + " ENDBURST";
this->Instance->SNO->WriteToSnoMask('l',"Bursting to \2%s\2 (Authentication: %s).", name.c_str(), this->GetTheirChallenge().empty() ? "plaintext password" : "SHA256-HMAC challenge-response");
this->WriteLine(burst);

View File

@ -30,32 +30,6 @@
/* $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 */
bool TreeSocket::HandleSetTime(const std::string &prefix, std::deque<std::string> &params)
{
if (!params.size() || !Utils->EnableTimeSync)
return true;
bool force = false;
if ((params.size() == 2) && (params[1] == "FORCE"))
force = true;
time_t them = atoi(params[0].c_str());
time_t us = Instance->Time(false);
time_t diff = them - us;
Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix);
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;
}
bool TreeSocket::Time(const std::string &prefix, std::deque<std::string> &params)
{
// :source.server TIME remote.server sendernick
@ -68,7 +42,7 @@ bool TreeSocket::Time(const std::string &prefix, std::deque<std::string> &params
User* u = this->Instance->FindNick(params[1]);
if (u)
{
params.push_back(ConvToStr(Instance->Time(false)));
params.push_back(ConvToStr(Instance->Time()));
params[0] = prefix;
Utils->DoOneToOne(this->Instance->Config->GetSID(),"TIME",params,params[0]);
}

View File

@ -28,15 +28,6 @@
/* $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) : Timer(600, Inst->Time(), true), Instance(Inst), Module(Mod)
{
}
void TimeSyncTimer::Tick(time_t TIME)
{
Module->BroadcastTimeSync();
}
CacheRefreshTimer::CacheRefreshTimer(InspIRCd *Inst, SpanningTreeUtilities *Util) : Timer(3600, Inst->Time(), true), Instance(Inst), Utils(Util)
{
}

View File

@ -24,16 +24,6 @@ class InspIRCd;
* Timer is only one-shot however, so at the end of each Tick() we simply
* insert another of ourselves into the pending queue :)
*/
class TimeSyncTimer : public Timer
{
private:
InspIRCd *Instance;
ModuleSpanningTree *Module;
public:
TimeSyncTimer(InspIRCd *Instance, ModuleSpanningTree *Mod);
virtual void Tick(time_t TIME);
};
class CacheRefreshTimer : public Timer
{
private:

View File

@ -160,11 +160,10 @@ bool TreeSocket::ProcessLine(std::string &line)
}
else if (command == "BURST")
{
if (params.size() && Utils->EnableTimeSync)
if (params.size())
{
bool we_have_delta = (Instance->Time(false) != Instance->Time(true));
time_t them = atoi(params[0].c_str());
time_t delta = them - Instance->Time(false);
time_t delta = them - Instance->Time();
if ((delta < -600) || (delta > 600))
{
Instance->SNO->WriteToSnoMask('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs(delta));
@ -175,13 +174,6 @@ bool TreeSocket::ProcessLine(std::string &line)
{
Instance->SNO->WriteToSnoMask('l',"\2WARNING\2: Your clocks are out by %d seconds. Please consider synching your clocks.", abs(delta));
}
if (!Utils->MasterTime && !we_have_delta)
{
this->Instance->SetTimeDelta(delta);
// Send this new timestamp to any other servers
Utils->DoOneToMany(Instance->Config->GetSID(), "TIMESET", params);
}
}
this->LinkState = CONNECTED;
Link* lnk = Utils->FindLink(InboundServerName);
@ -283,7 +275,7 @@ bool TreeSocket::ProcessLine(std::string &line)
* When there is activity on the socket, reset the ping counter so
* that we're not wasting bandwidth pinging an active server.
*/
route_back_again->SetNextPingTime(time(NULL) + Utils->PingFreq);
route_back_again->SetNextPingTime(Instance->Time() + Utils->PingFreq);
route_back_again->SetPingFlag();
}
else

View File

@ -448,8 +448,6 @@ 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("timesync","enable",0);
MasterTime = Conf->ReadFlag("timesync", "master", 0);
ChallengeResponse = !Conf->ReadFlag("options", "disablehmac", 0);
quiet_bursts = Conf->ReadFlag("options", "quietbursts", 0);
PingWarnTime = Conf->ReadInteger("options", "pingwarning", 0, true);

View File

@ -61,9 +61,7 @@ class SpanningTreeUtilities
/** Announce TS changes to channels on merge
*/
bool AnnounceTSChange;
/** Synchronize timestamps between servers
*/
bool EnableTimeSync;
/** Make snomasks +CQ quiet during bursts and splits
*/
bool quiet_bursts;
@ -93,12 +91,6 @@ class SpanningTreeUtilities
*/
std::vector<Link> LinkBlocks;
/** 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;

View File

@ -46,7 +46,7 @@ bool TreeSocket::Whois(const std::string &prefix, std::deque<std::string> &param
char signon[MAXBUF];
char idle[MAXBUF];
snprintf(signon, MAXBUF, "%lu", (unsigned long)x->signon);
snprintf(idle, MAXBUF, "%lu", (unsigned long)abs((x->idle_lastmsg) - Instance->Time(true)));
snprintf(idle, MAXBUF, "%lu", (unsigned long)abs((x->idle_lastmsg) - Instance->Time()));
std::deque<std::string> par;
par.push_back(prefix);
par.push_back(signon);

View File

@ -216,7 +216,7 @@ void InspIRCd::DoBackgroundUserStuff()
// This user didn't answer the last ping, remove them
if (!curr->lastping)
{
time_t time = this->Time(false) - (curr->nping - curr->MyClass->GetPingTime());
time_t time = this->Time() - (curr->nping - curr->MyClass->GetPingTime());
char message[MAXBUF];
snprintf(message, MAXBUF, "Ping timeout: %ld second%s", (long)time, time > 1 ? "s" : "");
curr->lastping = 1;

View File

@ -177,7 +177,7 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
*password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = *uuid = 0;
server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
reset_due = ServerInstance->Time();
age = ServerInstance->Time(true);
age = ServerInstance->Time();
Penalty = 0;
lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
ChannelCount = timeout = bytes_in = bytes_out = cmds_in = cmds_out = 0;