The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

SpanningTreeUtilities Class Reference

Contains helper functions and variables for this module, and keeps them out of the global namespace. More...

#include <utils.h>

Collaboration diagram for SpanningTreeUtilities:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SpanningTreeUtilities (InspIRCd *Instance, ModuleSpanningTree *Creator)
 Initialise utility class.
 ~SpanningTreeUtilities ()
 Destroy class and free listeners etc.
bool DoOneToOne (const std::string &prefix, const std::string &command, std::deque< std::string > &params, std::string target)
 Send a message from this server to one other local or remote.
bool DoOneToAllButSender (const std::string &prefix, const std::string &command, std::deque< std::string > &params, std::string omit)
 Send a message from this server to all but one other, local or remote.
bool DoOneToAllButSender (const char *prefix, const char *command, std::deque< std::string > &params, std::string omit)
 Send a message from this server to all but one other, local or remote.
bool DoOneToMany (const std::string &prefix, const std::string &command, std::deque< std::string > &params)
 Send a message from this server to all others.
bool DoOneToMany (const char *prefix, const char *command, std::deque< std::string > &params)
 Send a message from this server to all others.
bool DoOneToAllButSenderRaw (const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque< std::string > &params)
 Send a message from this server to all others, without doing any processing on the command (e.g.
void ReadConfiguration (bool rebind)
 Read the spanningtree module's tags from the config file.
void AddThisServer (TreeServer *server, TreeServerList &list)
 Add a server to the server list for GetListOfServersForChannel.
void GetListOfServersForChannel (chanrec *c, TreeServerList &list, char status, const CUList &exempt_list)
 Compile a list of servers which contain members of channel c.
TreeServerFindServer (const std::string &ServerName)
 Find a server by name.
TreeServerFindRemoteBurstServer (TreeServer *Server)
 Find a remote bursting server by name.
void SetRemoteBursting (TreeServer *Server, bool bursting)
 Set a remote server to bursting or not bursting.
TreeServerBestRouteTo (const std::string &ServerName)
 Find a route to a server by name.
TreeServerFindServerMask (const std::string &ServerName)
 Find a server by glob mask.
bool IsServer (const std::string &ServerName)
 Returns true if this is a server name we recognise.
void DoFailOver (Link *x)
 Attempt to connect to the failover link of link x.
LinkFindLink (const std::string &name)
 Find a link tag from a server name.
void RefreshIPCache ()
 Refresh the IP cache used for allowing inbound connections.
TreeSocketFindBurstingServer (const std::string &ServerName)
void AddBurstingServer (const std::string &ServerName, TreeSocket *s)
void DelBurstingServer (TreeSocket *s)

Public Attributes

ModuleSpanningTreeCreator
 Creator module.
server_hash RemoteServersBursting
 Remote servers that are currently bursting.
bool FlatLinks
 Flatten links and /MAP for non-opers.
bool HideULines
 Hide U-Lined servers in /MAP and /LINKS.
bool AnnounceTSChange
 Announce TS changes to channels on merge.
bool EnableTimeSync
 Synchronize timestamps between servers.
bool quiet_bursts
 Make snomasks +CQ quiet during bursts and splits.
std::vector< TreeSocket * > Bindings
 Socket bindings for listening sockets.
int PingWarnTime
TreeServerTreeRoot
 This variable represents the root of the server tree.
std::vector< std::stringValidIPs
 IPs allowed to link to us.
server_hash serverlist
 Hash of currently connected servers by name.
std::map< irc::string, TreeSocket * > burstingserverlist
 Hash of servers currently bursting but not initialized as connected.
std::vector< LinkLinkBlocks
 Holds the data from the <link> tags in the conf.
int lines_to_apply
 Holds a bitmask of queued xline types waiting to be applied.
bool MasterTime
 If this is true, this server is the master sync server for time synching - e.g.
hookmodules hooks
 List of module pointers which can provide I/O abstraction.
std::vector< std::stringhooknames
 List of module names which can provide I/O abstraction.
bool ChallengeResponse
 True (default) if we are to use challenge-response HMAC to authenticate passwords.
int PingFreq
 Ping frequency of server to server links.

Private Attributes

InspIRCdServerInstance
 Creator server.

Detailed Description

Contains helper functions and variables for this module, and keeps them out of the global namespace.

Definition at line 48 of file utils.h.


Constructor & Destructor Documentation

SpanningTreeUtilities::SpanningTreeUtilities InspIRCd Instance,
ModuleSpanningTree Creator
 

Initialise utility class.

Definition at line 158 of file utils.cpp.

References Bindings, InspIRCd::Config, Creator, InspIRCd::FindInterface(), hooknames, hooks, lines_to_apply, ReadConfiguration(), ServerConfig::ServerDesc, ServerInstance, ServerConfig::ServerName, and TreeRoot.

00158                                                                                       : ServerInstance(Instance), Creator(C)
00159 {
00160         Bindings.clear();
00161 
00162         lines_to_apply = 0;
00163 
00164         this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc);
00165 
00166         modulelist* ml = ServerInstance->FindInterface("InspSocketHook");
00167 
00168         /* Did we find any modules? */
00169         if (ml)
00170         {
00171                 /* Yes, enumerate them all to find out the hook name */
00172                 for (modulelist::iterator m = ml->begin(); m != ml->end(); m++)
00173                 {
00174                         /* Make a request to it for its name, its implementing
00175                          * InspSocketHook so we know its safe to do this
00176                          */
00177                         std::string name = InspSocketNameRequest((Module*)Creator, *m).Send();
00178                         /* Build a map of them */
00179                         hooks[name.c_str()] = *m;
00180                         hooknames.push_back(name);
00181                 }
00182         }
00183 
00184         this->ReadConfiguration(true);
00185 }

SpanningTreeUtilities::~SpanningTreeUtilities  ) 
 

Destroy class and free listeners etc.

Definition at line 187 of file utils.cpp.

References Bindings, TreeServer::ChildCount(), InspSocket::Close(), SocketEngine::DelFd(), TreeServer::GetChild(), TreeServer::GetSocket(), InspIRCd::InspSocketCull(), InspIRCd::SE, ServerInstance, and TreeRoot.

00188 {
00189         for (unsigned int i = 0; i < Bindings.size(); i++)
00190         {
00191                 ServerInstance->SE->DelFd(Bindings[i]);
00192                 Bindings[i]->Close();
00193         }
00194         while (TreeRoot->ChildCount())
00195         {
00196                 TreeServer* child_server = TreeRoot->GetChild(0);
00197                 if (child_server)
00198                 {
00199                         TreeSocket* sock = child_server->GetSocket();
00200                         ServerInstance->SE->DelFd(sock);
00201                         sock->Close();
00202                 }
00203         }
00204         delete TreeRoot;
00205         ServerInstance->InspSocketCull();
00206 }


Member Function Documentation

void SpanningTreeUtilities::AddBurstingServer const std::string ServerName,
TreeSocket s
 

Definition at line 96 of file utils.cpp.

References burstingserverlist.

Referenced by TreeSocket::Inbound_Server().

00097 {
00098         std::map<irc::string,TreeSocket*>::iterator iter = burstingserverlist.find(ServerName.c_str());
00099         if (iter == burstingserverlist.end())
00100                 burstingserverlist[ServerName.c_str()] = s;
00101 }

void SpanningTreeUtilities::AddThisServer TreeServer server,
TreeServerList list
 

Add a server to the server list for GetListOfServersForChannel.

Definition at line 208 of file utils.cpp.

Referenced by GetListOfServersForChannel().

00209 {
00210         if (list.find(server) == list.end())
00211                 list[server] = server;
00212 }

TreeServer * SpanningTreeUtilities::BestRouteTo const std::string ServerName  ) 
 

Find a route to a server by name.

This only applies to one-to-one and not one-to-many routing. See the comments for the constructor of TreeServer for more details.

Definition at line 121 of file utils.cpp.

References FindServer(), TreeServer::GetName(), TreeServer::GetRoute(), and TreeRoot.

Referenced by DoOneToAllButSender(), DoOneToAllButSenderRaw(), DoOneToOne(), TreeSocket::ForceJoin(), GetListOfServersForChannel(), and TreeSocket::ProcessLine().

00122 {
00123         if (ServerName.c_str() == TreeRoot->GetName())
00124                 return NULL;
00125         TreeServer* Found = FindServer(ServerName);
00126         if (Found)
00127         {
00128                 return Found->GetRoute();
00129         }
00130         else
00131         {
00132                 return NULL;
00133         }
00134 }

void SpanningTreeUtilities::DelBurstingServer TreeSocket s  ) 
 

Definition at line 103 of file utils.cpp.

References burstingserverlist.

Referenced by TreeSocket::ProcessLine(), and TreeSocket::~TreeSocket().

00104 {
00105          for (std::map<irc::string,TreeSocket*>::iterator iter = burstingserverlist.begin(); iter != burstingserverlist.end(); iter++)
00106          {
00107                  if (iter->second == s)
00108                  {
00109                          burstingserverlist.erase(iter);
00110                          return;
00111                  }
00112          }
00113 }

void SpanningTreeUtilities::DoFailOver Link x  ) 
 

Attempt to connect to the failover link of link x.

Definition at line 628 of file utils.cpp.

References ModuleSpanningTree::ConnectServer(), Creator, DEBUG, Link::FailOver, FindLink(), FindServer(), InspIRCd::Log(), Link::Name, ModuleSpanningTree::RemoteMessage(), and ServerInstance.

Referenced by ModuleSpanningTree::ConnectServer(), TreeSocket::OnError(), ServernameResolver::OnError(), ServernameResolver::OnLookupComplete(), and TreeSocket::OnTimeout().

00629 {
00630         if (x->FailOver.length())
00631         {
00632                 if (x->FailOver == x->Name)
00633                 {
00634                         Creator->RemoteMessage(NULL,"FAILOVER: Some muppet configured the failover for server \002%s\002 to point at itself. Not following it!", x->Name.c_str());
00635                         return;
00636                 }
00637                 Link* TryThisOne = this->FindLink(x->FailOver.c_str());
00638                 if (TryThisOne)
00639                 {
00640                         TreeServer* CheckDupe = this->FindServer(x->FailOver.c_str());
00641                         if (CheckDupe)
00642                         {
00643                                 ServerInstance->Log(DEBUG,"Skipping existing failover: %s", x->FailOver.c_str());
00644                         }
00645                         else
00646                         {
00647                                 Creator->RemoteMessage(NULL,"FAILOVER: Trying failover link for \002%s\002: \002%s\002...", x->Name.c_str(), TryThisOne->Name.c_str());
00648                                 Creator->ConnectServer(TryThisOne);
00649                         }
00650                 }
00651                 else
00652                 {
00653                         Creator->RemoteMessage(NULL,"FAILOVER: Invalid failover server specified for server \002%s\002, will not follow!", x->Name.c_str());
00654                 }
00655         }
00656 }

bool SpanningTreeUtilities::DoOneToAllButSender const char *  prefix,
const char *  command,
std::deque< std::string > &  params,
std::string  omit
 

Send a message from this server to all but one other, local or remote.

Definition at line 374 of file utils.cpp.

References DoOneToAllButSender().

00375 {
00376         std::string spfx = prefix;
00377         std::string scmd = command;
00378         return this->DoOneToAllButSender(spfx, scmd, params, omit);
00379 }

bool SpanningTreeUtilities::DoOneToAllButSender const std::string prefix,
const std::string command,
std::deque< std::string > &  params,
std::string  omit
 

Send a message from this server to all but one other, local or remote.

Definition at line 318 of file utils.cpp.

References BestRouteTo(), TreeServer::ChildCount(), TreeServer::GetChild(), TreeServer::GetName(), TreeServer::GetSocket(), TreeRoot, and TreeSocket::WriteLine().

Referenced by TreeSocket::AddLine(), TreeSocket::ChangeHost(), TreeSocket::ChangeName(), DoOneToAllButSender(), DoOneToAllButSenderRaw(), TreeSocket::ForceJoin(), TreeSocket::ForceMode(), TreeSocket::ForceNick(), TreeSocket::ForceTopic(), TreeSocket::HandleSetTime(), TreeSocket::IntroduceClient(), TreeSocket::MetaData(), TreeSocket::OperQuit(), TreeSocket::OperType(), TreeSocket::Outbound_Reply_Server(), TreeSocket::ProcessLine(), TreeSocket::RemoteKill(), TreeSocket::RemoteRehash(), TreeSocket::RemoteServer(), TreeSocket::ServerVersion(), TreeSocket::ServiceJoin(), TreeSocket::ServicePart(), and TreeSocket::Squit().

00319 {
00320         TreeServer* omitroute = this->BestRouteTo(omit);
00321         std::string FullLine = ":" + prefix + " " + command;
00322         unsigned int words = params.size();
00323         for (unsigned int x = 0; x < words; x++)
00324         {
00325                 FullLine = FullLine + " " + params[x];
00326         }
00327         unsigned int items = this->TreeRoot->ChildCount();
00328         for (unsigned int x = 0; x < items; x++)
00329         {
00330                 TreeServer* Route = this->TreeRoot->GetChild(x);
00331                 // Send the line IF:
00332                 // The route has a socket (its a direct connection)
00333                 // The route isnt the one to be omitted
00334                 // The route isnt the path to the one to be omitted
00335                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
00336                 {
00337                         TreeSocket* Sock = Route->GetSocket();
00338                         if (Sock)
00339                                 Sock->WriteLine(FullLine);
00340                 }
00341         }
00342         return true;
00343 }

bool SpanningTreeUtilities::DoOneToAllButSenderRaw const std::string data,
const std::string omit,
const std::string prefix,
const irc::string command,
std::deque< std::string > &  params
 

Send a message from this server to all others, without doing any processing on the command (e.g.

send it as-is with colons and all)

Definition at line 245 of file utils.cpp.

References BestRouteTo(), TreeServer::ChildCount(), DoOneToAllButSender(), DoOneToOne(), InspIRCd::FindChan(), InspIRCd::FindNick(), FOREACH_MOD, TreeServer::GetChild(), GetListOfServersForChannel(), TreeServer::GetName(), TreeServer::GetSocket(), I_OnBuildExemptList, MSG_NOTICE, MSG_PRIVMSG, userrec::server, ServerInstance, TreeRoot, and TreeSocket::WriteLine().

Referenced by TreeSocket::ProcessLine().

00246 {
00247         char pfx = 0;
00248         TreeServer* omitroute = this->BestRouteTo(omit);
00249         if ((command == "NOTICE") || (command == "PRIVMSG"))
00250         {
00251                 if (params.size() >= 2)
00252                 {
00253                         /* Prefixes */
00254                         if ((*(params[0].c_str()) == '@') || (*(params[0].c_str()) == '%') || (*(params[0].c_str()) == '+'))
00255                         {
00256                                 pfx = params[0][0];
00257                                 params[0] = params[0].substr(1, params[0].length()-1);
00258                         }
00259                         if ((*(params[0].c_str()) != '#') && (*(params[0].c_str()) != '$'))
00260                         {
00261                                 // special routing for private messages/notices
00262                                 userrec* d = ServerInstance->FindNick(params[0]);
00263                                 if (d)
00264                                 {
00265                                         std::deque<std::string> par;
00266                                         par.push_back(params[0]);
00267                                         par.push_back(":"+params[1]);
00268                                         this->DoOneToOne(prefix,command.c_str(),par,d->server);
00269                                         return true;
00270                                 }
00271                         }
00272                         else if (*(params[0].c_str()) == '$')
00273                         {
00274                                 std::deque<std::string> par;
00275                                 par.push_back(params[0]);
00276                                 par.push_back(":"+params[1]);
00277                                 this->DoOneToAllButSender(prefix,command.c_str(),par,omitroute->GetName());
00278                                 return true;
00279                         }
00280                         else
00281                         {
00282                                 chanrec* c = ServerInstance->FindChan(params[0]);
00283                                 userrec* u = ServerInstance->FindNick(prefix);
00284                                 if (c && u)
00285                                 {
00286                                         CUList elist;
00287                                         TreeServerList list;
00288                                         FOREACH_MOD(I_OnBuildExemptList, OnBuildExemptList((command == "PRIVMSG" ? MSG_PRIVMSG : MSG_NOTICE), c, u, pfx, elist));
00289                                         GetListOfServersForChannel(c,list,pfx,elist);
00290 
00291                                         for (TreeServerList::iterator i = list.begin(); i != list.end(); i++)
00292                                         {
00293                                                 TreeSocket* Sock = i->second->GetSocket();
00294                                                 if ((Sock) && (i->second->GetName() != omit) && (omitroute != i->second))
00295                                                 {
00296                                                         Sock->WriteLine(data);
00297                                                 }
00298                                         }
00299                                         return true;
00300                                 }
00301                         }
00302                 }
00303         }
00304         unsigned int items =this->TreeRoot->ChildCount();
00305         for (unsigned int x = 0; x < items; x++)
00306         {
00307                 TreeServer* Route = this->TreeRoot->GetChild(x);
00308                 if ((Route) && (Route->GetSocket()) && (Route->GetName() != omit) && (omitroute != Route))
00309                 {
00310                         TreeSocket* Sock = Route->GetSocket();
00311                         if (Sock)
00312                                 Sock->WriteLine(data);
00313                 }
00314         }
00315         return true;
00316 }

bool SpanningTreeUtilities::DoOneToMany const char *  prefix,
const char *  command,
std::deque< std::string > &  params
 

Send a message from this server to all others.

Definition at line 367 of file utils.cpp.

References DoOneToMany().

00368 {
00369         std::string spfx = prefix;
00370         std::string scmd = command;
00371         return this->DoOneToMany(spfx, scmd, params);
00372 }

bool SpanningTreeUtilities::DoOneToMany const std::string prefix,
const std::string command,
std::deque< std::string > &  params
 

Send a message from this server to all others.

Definition at line 345 of file utils.cpp.

References TreeServer::ChildCount(), TreeServer::GetChild(), TreeServer::GetSocket(), TreeRoot, and TreeSocket::WriteLine().

Referenced by ModuleSpanningTree::BroadcastTimeSync(), DoOneToMany(), ModuleSpanningTree::OnCancelAway(), ModuleSpanningTree::OnChangeHost(), ModuleSpanningTree::OnChangeName(), ModuleSpanningTree::OnEvent(), ModuleSpanningTree::OnLine(), ModuleSpanningTree::OnMode(), ModuleSpanningTree::OnOper(), ModuleSpanningTree::OnPostCommand(), ModuleSpanningTree::OnPostLocalTopicChange(), ModuleSpanningTree::OnRehash(), ModuleSpanningTree::OnRemoteKill(), ModuleSpanningTree::OnSetAway(), ModuleSpanningTree::OnUserConnect(), ModuleSpanningTree::OnUserInvite(), ModuleSpanningTree::OnUserJoin(), ModuleSpanningTree::OnUserKick(), ModuleSpanningTree::OnUserMessage(), ModuleSpanningTree::OnUserNotice(), ModuleSpanningTree::OnUserPart(), ModuleSpanningTree::OnUserPostNick(), ModuleSpanningTree::OnUserQuit(), ModuleSpanningTree::OnWallops(), TreeSocket::ProcessLine(), and ModuleSpanningTree::RemoteMessage().

00346 {
00347         std::string FullLine = ":" + prefix + " " + command;
00348         unsigned int words = params.size();
00349         for (unsigned int x = 0; x < words; x++)
00350         {
00351                 FullLine = FullLine + " " + params[x];
00352         }
00353         unsigned int items = this->TreeRoot->ChildCount();
00354         for (unsigned int x = 0; x < items; x++)
00355         {
00356                 TreeServer* Route = this->TreeRoot->GetChild(x);
00357                 if (Route && Route->GetSocket())
00358                 {
00359                         TreeSocket* Sock = Route->GetSocket();
00360                         if (Sock)
00361                                 Sock->WriteLine(FullLine);
00362                 }
00363         }
00364         return true;
00365 }

bool SpanningTreeUtilities::DoOneToOne const std::string prefix,
const std::string command,
std::deque< std::string > &  params,
std::string  target
 

Send a message from this server to one other local or remote.

Definition at line 381 of file utils.cpp.

References BestRouteTo(), TreeServer::GetSocket(), and TreeSocket::WriteLine().

Referenced by TreeSocket::Admin(), DoOneToAllButSenderRaw(), ModuleSpanningTree::HandleAdmin(), ModuleSpanningTree::HandleModules(), ModuleSpanningTree::HandleMotd(), ModuleSpanningTree::HandleRemoteWhois(), ModuleSpanningTree::HandleStats(), ModuleSpanningTree::HandleTime(), TreeSocket::LocalPing(), TreeSocket::LocalPong(), TreeSocket::Modules(), TreeSocket::Motd(), cmd_rsquit::NoticeUser(), ModuleSpanningTree::OnEvent(), ModuleSpanningTree::OnUserMessage(), ModuleSpanningTree::OnUserNotice(), TreeSocket::Push(), TreeSocket::Stats(), TreeSocket::Time(), and TreeSocket::Whois().

00382 {
00383         TreeServer* Route = this->BestRouteTo(target);
00384         if (Route)
00385         {
00386                 std::string FullLine = ":" + prefix + " " + command;
00387                 unsigned int words = params.size();
00388                 for (unsigned int x = 0; x < words; x++)
00389                 {
00390                         FullLine = FullLine + " " + params[x];
00391                 }
00392                 if (Route && Route->GetSocket())
00393                 {
00394                         TreeSocket* Sock = Route->GetSocket();
00395                         if (Sock)
00396                                 Sock->WriteLine(FullLine);
00397                 }
00398                 return true;
00399         }
00400         else
00401         {
00402                 return false;
00403         }
00404 }

TreeSocket * SpanningTreeUtilities::FindBurstingServer const std::string ServerName  ) 
 

Definition at line 64 of file utils.cpp.

References burstingserverlist.

Referenced by TreeSocket::Inbound_Server().

00065 {
00066         std::map<irc::string,TreeSocket*>::iterator iter;
00067         iter = burstingserverlist.find(ServerName.c_str());
00068         if (iter != burstingserverlist.end())
00069         {
00070                 return iter->second;
00071         }
00072         else
00073         {
00074                 return NULL;
00075         }
00076 }

Link * SpanningTreeUtilities::FindLink const std::string name  ) 
 

Find a link tag from a server name.

Definition at line 658 of file utils.cpp.

References LinkBlocks, InspIRCd::MatchText(), and ServerInstance.

Referenced by DoFailOver(), TreeSocket::OnError(), TreeSocket::OnTimeout(), TreeSocket::ProcessLine(), and TreeSocket::RemoteServer().

00659 {
00660         for (std::vector<Link>::iterator x = LinkBlocks.begin(); x < LinkBlocks.end(); x++)
00661         {
00662                 if (ServerInstance->MatchText(x->Name.c_str(), name.c_str()))
00663                 {
00664                         return &(*x);
00665                 }
00666         }
00667         return NULL;
00668 }

TreeServer * SpanningTreeUtilities::FindRemoteBurstServer TreeServer Server  ) 
 

Find a remote bursting server by name.

Definition at line 55 of file utils.cpp.

References TreeServer::GetName(), and RemoteServersBursting.

Referenced by TreeSocket::IntroduceClient().

00056 {
00057         server_hash::iterator iter = RemoteServersBursting.find(Server->GetName().c_str());
00058         if (iter != RemoteServersBursting.end())
00059                 return iter->second;
00060         else
00061                 return NULL;
00062 }

TreeServer * SpanningTreeUtilities::FindServer const std::string ServerName  ) 
 

Find a server by name.

(read as: lots).

Definition at line 42 of file utils.cpp.

References serverlist.

Referenced by ModuleSpanningTree::AutoConnectServers(), BestRouteTo(), DoFailOver(), ModuleSpanningTree::HandleConnect(), TreeSocket::Inbound_Server(), TreeSocket::IntroduceClient(), IsServer(), TreeSocket::LocalPong(), TreeSocket::MetaData(), TreeSocket::OnClose(), ModuleSpanningTree::OnGetServerDescription(), ServernameResolver::OnLookupComplete(), ModuleSpanningTree::OnUserConnect(), ModuleSpanningTree::OnUserQuit(), TreeSocket::Outbound_Reply_Server(), TreeSocket::ProcessLine(), TreeSocket::RemoteServer(), and TreeSocket::ServerVersion().

00043 {
00044         server_hash::iterator iter = serverlist.find(ServerName.c_str());
00045         if (iter != serverlist.end())
00046         {
00047                 return iter->second;
00048         }
00049         else
00050         {
00051                 return NULL;
00052         }
00053 }

TreeServer * SpanningTreeUtilities::FindServerMask const std::string ServerName  ) 
 

Find a server by glob mask.

Theres no find-using-glob method of hash_map [awwww :-(] so instead, we iterate over the list using an iterator and match each one until we get a hit. Yes its slow, deal with it.

Definition at line 142 of file utils.cpp.

References match(), and serverlist.

Referenced by cmd_rsquit::Handle(), cmd_rconnect::Handle(), ModuleSpanningTree::HandleAdmin(), ModuleSpanningTree::HandleModules(), ModuleSpanningTree::HandleMotd(), ModuleSpanningTree::HandleSquit(), ModuleSpanningTree::HandleStats(), ModuleSpanningTree::HandleTime(), and ModuleSpanningTree::HandleVersion().

00143 {
00144         for (server_hash::iterator i = serverlist.begin(); i != serverlist.end(); i++)
00145         {
00146                 if (match(i->first.c_str(),ServerName.c_str()))
00147                         return i->second;
00148         }
00149         return NULL;
00150 }

void SpanningTreeUtilities::GetListOfServersForChannel chanrec c,
TreeServerList list,
char  status,
const CUList exempt_list
 

Compile a list of servers which contain members of channel c.

Definition at line 215 of file utils.cpp.

References AddThisServer(), BestRouteTo(), chanrec::GetHalfoppedUsers(), chanrec::GetOppedUsers(), chanrec::GetUsers(), and chanrec::GetVoicedUsers().

Referenced by DoOneToAllButSenderRaw(), ModuleSpanningTree::OnUserMessage(), and ModuleSpanningTree::OnUserNotice().

00216 {
00217         CUList *ulist;
00218         switch (status)
00219         {
00220                 case '@':
00221                         ulist = c->GetOppedUsers();
00222                 break;
00223                 case '%':
00224                         ulist = c->GetHalfoppedUsers();
00225                 break;
00226                 case '+':
00227                         ulist = c->GetVoicedUsers();
00228                 break;
00229                 default:
00230                         ulist = c->GetUsers();
00231                 break;
00232         }
00233         for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
00234         {
00235                 if ((i->first->GetFd() < 0) && (exempt_list.find(i->first) == exempt_list.end()))
00236                 {
00237                         TreeServer* best = this->BestRouteTo(i->first->server);
00238                         if (best)
00239                                 AddThisServer(best,list);
00240                 }
00241         }
00242         return;
00243 }

bool SpanningTreeUtilities::IsServer const std::string ServerName  ) 
 

Returns true if this is a server name we recognise.

Definition at line 153 of file utils.cpp.

References FindServer().

Referenced by TreeSocket::ProcessLine().

00154 {
00155         return (FindServer(ServerName) != NULL);
00156 }

void SpanningTreeUtilities::ReadConfiguration bool  rebind  ) 
 

Read the spanningtree module's tags from the config file.

Definition at line 452 of file utils.cpp.

References InspIRCd::AddResolver(), Link::AllowMask, AnnounceTSChange, Link::AutoConnect, Link::Bind, Bindings, ChallengeResponse, InspSocket::Close(), Conf, InspIRCd::Config, DEFAULT, DELETE(), SocketEngine::DelFd(), DNS_QUERY_A, DNS_QUERY_AAAA, EnableTimeSync, Link::FailOver, FlatLinks, InspSocket::GetState(), irc::portparser::GetToken(), Link::Hidden, Link::HiddenFromStats, HideULines, Link::Hook, hooks, I_LISTENING, InspIRCd::InspSocketCull(), Link::IPAddr, LinkBlocks, InspIRCd::Log(), MasterTime, Link::Name, Link::NextConnectTime, PingFreq, PingWarnTime, Link::Port, quiet_bursts, ConfigReader::ReadFlag(), ConfigReader::ReadInteger(), ConfigReader::ReadValue(), Link::RecvPass, InspIRCd::SE, Link::SendPass, ServerInstance, ServerConfig::ServerName, Link::Timeout, and ValidIPs.

Referenced by ModuleSpanningTree::OnRehash(), TreeSocket::RemoteRehash(), and SpanningTreeUtilities().

00453 {
00454         ConfigReader* Conf = new ConfigReader(ServerInstance);
00455         if (rebind)
00456         {
00457                 for (unsigned int i = 0; i < Bindings.size(); i++)
00458                 {
00459                         ServerInstance->SE->DelFd(Bindings[i]);
00460                         Bindings[i]->Close();
00461                 }
00462                 ServerInstance->InspSocketCull();
00463                 Bindings.clear();
00464 
00465                 for (int j = 0; j < Conf->Enumerate("bind"); j++)
00466                 {
00467                         std::string Type = Conf->ReadValue("bind","type",j);
00468                         std::string IP = Conf->ReadValue("bind","address",j);
00469                         std::string Port = Conf->ReadValue("bind","port",j);
00470                         std::string transport = Conf->ReadValue("bind","transport",j);
00471                         if (Type == "servers")
00472                         {
00473                                 irc::portparser portrange(Port, false);
00474                                 int portno = -1;
00475                                 while ((portno = portrange.GetToken()))
00476                                 {
00477                                         if (IP == "*")
00478                                                 IP.clear();
00479 
00480                                         if ((!transport.empty()) && (hooks.find(transport.c_str()) ==  hooks.end()))
00481                                         {
00482                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for port %s:%s - maybe you forgot to load it BEFORE m_spanningtree in your config file? - Skipping this port binding", transport.c_str(), IP.c_str(), Port.c_str());
00483                                                 break;
00484                                         }
00485 
00486                                         TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10, transport.empty() ? NULL : hooks[transport.c_str()]);
00487                                         if (listener->GetState() == I_LISTENING)
00488                                         {
00489                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: Binding server port %s:%d successful!", IP.c_str(), portno);
00490                                                 Bindings.push_back(listener);
00491                                         }
00492                                         else
00493                                         {
00494                                                 ServerInstance->Log(DEFAULT,"m_spanningtree: Warning: Failed to bind server port: %s:%d: %s",IP.c_str(), portno, strerror(errno));
00495                                                 listener->Close();
00496                                         }
00497                                 }
00498                         }
00499                 }
00500         }
00501         FlatLinks = Conf->ReadFlag("options","flatlinks",0);
00502         HideULines = Conf->ReadFlag("options","hideulines",0);
00503         AnnounceTSChange = Conf->ReadFlag("options","announcets",0);
00504         EnableTimeSync = Conf->ReadFlag("timesync","enable",0);
00505         MasterTime = Conf->ReadFlag("timesync", "master", 0);
00506         ChallengeResponse = !Conf->ReadFlag("options", "disablehmac", 0);
00507         quiet_bursts = Conf->ReadFlag("options", "quietbursts", 0);
00508         PingWarnTime = Conf->ReadInteger("options", "pingwarning", "0", 0, true);
00509         PingFreq = Conf->ReadInteger("options", "serverpingfreq", "0", 0, true);
00510 
00511         if (PingFreq == 0)
00512                 PingFreq = 60;
00513 
00514         if (PingWarnTime < 0 || PingWarnTime > PingFreq - 1)
00515                 PingWarnTime = 0;
00516 
00517         LinkBlocks.clear();
00518         ValidIPs.clear();
00519         for (int j = 0; j < Conf->Enumerate("link"); j++)
00520         {
00521                 Link L;
00522                 std::string Allow = Conf->ReadValue("link", "allowmask", j);
00523                 L.Name = (Conf->ReadValue("link", "name", j)).c_str();
00524                 L.AllowMask = Allow;
00525                 L.IPAddr = Conf->ReadValue("link", "ipaddr", j);
00526                 L.FailOver = Conf->ReadValue("link", "failover", j).c_str();
00527                 L.Port = Conf->ReadInteger("link", "port", j, true);
00528                 L.SendPass = Conf->ReadValue("link", "sendpass", j);
00529                 L.RecvPass = Conf->ReadValue("link", "recvpass", j);
00530                 L.AutoConnect = Conf->ReadInteger("link", "autoconnect", j, true);
00531                 L.HiddenFromStats = Conf->ReadFlag("link", "statshidden", j);
00532                 L.Timeout = Conf->ReadInteger("link", "timeout", j, true);
00533                 L.Hook = Conf->ReadValue("link", "transport", j);
00534                 L.Bind = Conf->ReadValue("link", "bind", j);
00535                 L.Hidden = Conf->ReadFlag("link", "hidden", j);
00536 
00537                 if ((!L.Hook.empty()) && (hooks.find(L.Hook.c_str()) ==  hooks.end()))
00538                 {
00539                         ServerInstance->Log(DEFAULT,"m_spanningtree: WARNING: Can't find transport type '%s' for link '%s' - maybe you forgot to load it BEFORE m_spanningtree in your config file? Skipping <link> tag completely.",
00540                         L.Hook.c_str(), L.Name.c_str());
00541                         continue;
00542 
00543                 }
00544 
00545                 // Fix: Only trip autoconnects if this wouldn't delay autoconnect..
00546                 if (L.NextConnectTime > ((time_t)(time(NULL) + L.AutoConnect)))
00547                         L.NextConnectTime = time(NULL) + L.AutoConnect;
00548                 /* Bugfix by brain, do not allow people to enter bad configurations */
00549                 if (L.Name != ServerInstance->Config->ServerName)
00550                 {
00551                         if ((!L.IPAddr.empty()) && (!L.RecvPass.empty()) && (!L.SendPass.empty()) && (!L.Name.empty()) && (L.Port))
00552                         {
00553                                 ValidIPs.push_back(L.IPAddr);
00554 
00555                                 if (Allow.length())
00556                                         ValidIPs.push_back(Allow);
00557 
00558                                 /* Needs resolving */
00559                                 bool ipvalid = true;
00560                                 QueryType start_type = DNS_QUERY_A;
00561 #ifdef IPV6
00562                                 start_type = DNS_QUERY_AAAA;
00563                                 if (strchr(L.IPAddr.c_str(),':'))
00564                                 {
00565                                         in6_addr n;
00566                                         if (inet_pton(AF_INET6, L.IPAddr.c_str(), &n) < 1)
00567                                                 ipvalid = false;
00568                                 }
00569                                 else
00570                                 {
00571                                         in_addr n;
00572                                         if (inet_aton(L.IPAddr.c_str(),&n) < 1)
00573                                                 ipvalid = false;
00574                                 }
00575 #else
00576                                 in_addr n;
00577                                 if (inet_aton(L.IPAddr.c_str(),&n) < 1)
00578                                         ipvalid = false;
00579 #endif
00580 
00581                                 if (!ipvalid)
00582                                 {
00583                                         try
00584                                         {
00585                                                 bool cached;
00586                                                 SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached, start_type);
00587                                                 ServerInstance->AddResolver(sr, cached);
00588                                         }
00589                                         catch (...)
00590                                         {
00591                                         }
00592                                 }
00593 
00594                                 LinkBlocks.push_back(L);
00595                         }
00596                         else
00597                         {
00598                                 if (L.IPAddr.empty())
00599                                 {
00600                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', IP address not defined!",L.Name.c_str());
00601                                 }
00602                                 else if (L.RecvPass.empty())
00603                                 {
00604                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', recvpass not defined!",L.Name.c_str());
00605                                 }
00606                                 else if (L.SendPass.empty())
00607                                 {
00608                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', sendpass not defined!",L.Name.c_str());
00609                                 }
00610                                 else if (L.Name.empty())
00611                                 {
00612                                         ServerInstance->Log(DEFAULT,"Invalid configuration, link tag without a name!");
00613                                 }
00614                                 else if (!L.Port)
00615                                 {
00616                                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', no port specified!",L.Name.c_str());
00617                                 }
00618                         }
00619                 }
00620                 else
00621                 {
00622                         ServerInstance->Log(DEFAULT,"Invalid configuration for server '%s', link tag has the same server name as the local server!",L.Name.c_str());
00623                 }
00624         }
00625         DELETE(Conf);
00626 }

void SpanningTreeUtilities::RefreshIPCache  ) 
 

Refresh the IP cache used for allowing inbound connections.

Definition at line 406 of file utils.cpp.

References InspIRCd::AddResolver(), DNS_QUERY_A, DNS_QUERY_AAAA, LinkBlocks, ServerInstance, and ValidIPs.

Referenced by ModuleSpanningTree::OnBackgroundTimer(), and CacheRefreshTimer::Tick().

00407 {
00408         ValidIPs.clear();
00409         for (std::vector<Link>::iterator L = LinkBlocks.begin(); L != LinkBlocks.end(); L++)
00410         {
00411                 if ((!L->IPAddr.empty()) && (!L->RecvPass.empty()) && (!L->SendPass.empty()) && (!L->Name.empty()) && (L->Port))
00412                 {
00413                         ValidIPs.push_back(L->IPAddr);
00414 
00415                         if (L->AllowMask.length())
00416                                 ValidIPs.push_back(L->AllowMask);
00417 
00418                         /* Needs resolving */
00419                         bool ipvalid = true;
00420                         QueryType start_type = DNS_QUERY_A;
00421 #ifdef IPV6
00422                         start_type = DNS_QUERY_AAAA;
00423                         if (strchr(L->IPAddr.c_str(),':'))
00424                         {
00425                                 in6_addr n;
00426                                 if (inet_pton(AF_INET6, L->IPAddr.c_str(), &n) < 1)
00427                                         ipvalid = false;
00428                         }
00429                         else
00430 #endif
00431                         {
00432                                 in_addr n;
00433                                 if (inet_aton(L->IPAddr.c_str(),&n) < 1)
00434                                         ipvalid = false;
00435                         }
00436                         if (!ipvalid)
00437                         {
00438                                 try
00439                                 {
00440                                         bool cached;
00441                                         SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L->IPAddr, *L, cached, start_type);
00442                                         ServerInstance->AddResolver(sr, cached);
00443                                 }
00444                                 catch (...)
00445                                 {
00446                                 }
00447                         }
00448                 }
00449         }
00450 }

void SpanningTreeUtilities::SetRemoteBursting TreeServer Server,
bool  bursting
 

Set a remote server to bursting or not bursting.

Definition at line 78 of file utils.cpp.

References DEBUG, TreeServer::GetName(), InspIRCd::Log(), RemoteServersBursting, and ServerInstance.

Referenced by ModuleSpanningTree::DoPingChecks(), TreeSocket::MetaData(), TreeSocket::ProcessLine(), and TreeSocket::RemoteServer().

00079 {
00080         server_hash::iterator iter = RemoteServersBursting.find(Server->GetName().c_str());
00081         if (bursting)
00082         {
00083                 if (iter == RemoteServersBursting.end())
00084                         RemoteServersBursting.insert(make_pair(Server->GetName(), Server));
00085                 else return;
00086         }
00087         else
00088         {
00089                 if (iter != RemoteServersBursting.end())
00090                         RemoteServersBursting.erase(iter);
00091                 else return;
00092         }
00093         ServerInstance->Log(DEBUG,"Server %s is %sbursting nicknames", Server->GetName().c_str(), bursting ? "" : "no longer ");
00094 }


Member Data Documentation

bool SpanningTreeUtilities::AnnounceTSChange
 

Announce TS changes to channels on merge.

Definition at line 69 of file utils.h.

Referenced by TreeSocket::ForceJoin(), and ReadConfiguration().

std::vector<TreeSocket*> SpanningTreeUtilities::Bindings
 

Socket bindings for listening sockets.

Definition at line 78 of file utils.h.

Referenced by ModuleSpanningTree::OnStats(), ReadConfiguration(), SpanningTreeUtilities(), and ~SpanningTreeUtilities().

std::map<irc::string,TreeSocket*> SpanningTreeUtilities::burstingserverlist
 

Hash of servers currently bursting but not initialized as connected.

Definition at line 94 of file utils.h.

Referenced by AddBurstingServer(), DelBurstingServer(), and FindBurstingServer().

bool SpanningTreeUtilities::ChallengeResponse
 

True (default) if we are to use challenge-response HMAC to authenticate passwords.

NOTE: This defaults to on, but should be turned off if you are linking to an older version of inspircd.

Definition at line 124 of file utils.h.

Referenced by TreeSocket::Capab(), TreeSocket::ComparePass(), TreeSocket::MakePass(), ReadConfiguration(), and TreeSocket::SendCapabilities().

ModuleSpanningTree* SpanningTreeUtilities::Creator
 

Creator module.

Definition at line 57 of file utils.h.

Referenced by TreeSocket::DoBurst(), DoFailOver(), TreeSocket::Inbound_Server(), TreeSocket::MakePass(), TreeSocket::OnClose(), TreeSocket::OnConnected(), TreeSocket::OnError(), ServernameResolver::OnError(), ServernameResolver::OnLookupComplete(), TreeSocket::OnTimeout(), TreeSocket::ProcessLine(), TreeSocket::SendChannelModes(), TreeSocket::SendError(), TreeSocket::SendUsers(), SpanningTreeUtilities(), TreeSocket::Squit(), HandshakeTimer::Tick(), TreeSocket::TreeSocket(), and TreeSocket::~TreeSocket().

bool SpanningTreeUtilities::EnableTimeSync
 

Synchronize timestamps between servers.

Definition at line 72 of file utils.h.

Referenced by TreeSocket::HandleSetTime(), ModuleSpanningTree::OnBackgroundTimer(), TreeSocket::ProcessLine(), and ReadConfiguration().

bool SpanningTreeUtilities::FlatLinks
 

Flatten links and /MAP for non-opers.

Definition at line 63 of file utils.h.

Referenced by ReadConfiguration(), ModuleSpanningTree::ShowLinks(), and ModuleSpanningTree::ShowMap().

bool SpanningTreeUtilities::HideULines
 

Hide U-Lined servers in /MAP and /LINKS.

Definition at line 66 of file utils.h.

Referenced by ModuleSpanningTree::HandleLusers(), ReadConfiguration(), ModuleSpanningTree::ShowLinks(), and ModuleSpanningTree::ShowMap().

std::vector<std::string> SpanningTreeUtilities::hooknames
 

List of module names which can provide I/O abstraction.

Definition at line 116 of file utils.h.

Referenced by SpanningTreeUtilities().

hookmodules SpanningTreeUtilities::hooks
 

List of module pointers which can provide I/O abstraction.

Definition at line 112 of file utils.h.

Referenced by ModuleSpanningTree::ConnectServer(), ServernameResolver::OnLookupComplete(), ReadConfiguration(), and SpanningTreeUtilities().

int SpanningTreeUtilities::lines_to_apply
 

Holds a bitmask of queued xline types waiting to be applied.

Will be a mask containing values APPLY_GLINES, APPLY_KLINES, APPLY_QLINES and APPLY_ZLINES.

Definition at line 102 of file utils.h.

Referenced by TreeSocket::AddLine(), TreeSocket::ProcessLine(), and SpanningTreeUtilities().

std::vector<Link> SpanningTreeUtilities::LinkBlocks
 

Holds the data from the <link> tags in the conf.

Definition at line 97 of file utils.h.

Referenced by ModuleSpanningTree::AutoConnectServers(), FindLink(), ModuleSpanningTree::HandleConnect(), TreeSocket::Inbound_Server(), TreeSocket::OnConnected(), ModuleSpanningTree::OnStats(), TreeSocket::Outbound_Reply_Server(), ReadConfiguration(), RefreshIPCache(), and TreeSocket::TreeSocket().

bool SpanningTreeUtilities::MasterTime
 

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.

Definition at line 108 of file utils.h.

Referenced by ModuleSpanningTree::BroadcastTimeSync(), TreeSocket::ProcessLine(), and ReadConfiguration().

int SpanningTreeUtilities::PingFreq
 

Ping frequency of server to server links.

Definition at line 128 of file utils.h.

Referenced by ModuleSpanningTree::DoPingChecks(), TreeSocket::ProcessLine(), ReadConfiguration(), and TreeServer::TreeServer().

int SpanningTreeUtilities::PingWarnTime
 

Definition at line 82 of file utils.h.

Referenced by ModuleSpanningTree::DoPingChecks(), and ReadConfiguration().

bool SpanningTreeUtilities::quiet_bursts
 

Make snomasks +CQ quiet during bursts and splits.

Definition at line 75 of file utils.h.

Referenced by TreeSocket::IntroduceClient(), and ReadConfiguration().

server_hash SpanningTreeUtilities::RemoteServersBursting
 

Remote servers that are currently bursting.

Definition at line 60 of file utils.h.

Referenced by FindRemoteBurstServer(), and SetRemoteBursting().

InspIRCd* SpanningTreeUtilities::ServerInstance [private]
 

Creator server.

Definition at line 53 of file utils.h.

Referenced by DoFailOver(), DoOneToAllButSenderRaw(), FindLink(), ReadConfiguration(), RefreshIPCache(), SetRemoteBursting(), SpanningTreeUtilities(), and ~SpanningTreeUtilities().

server_hash SpanningTreeUtilities::serverlist
 

Hash of currently connected servers by name.

Definition at line 91 of file utils.h.

Referenced by TreeServer::AddHashEntry(), ModuleSpanningTree::CountServs(), TreeServer::DelHashEntry(), ModuleSpanningTree::DoPingChecks(), FindServer(), FindServerMask(), and ModuleSpanningTree::HandleLusers().

TreeServer* SpanningTreeUtilities::TreeRoot
 

This variable represents the root of the server tree.

Definition at line 85 of file utils.h.

Referenced by BestRouteTo(), ModuleSpanningTree::BroadcastTimeSync(), ModuleSpanningTree::CountLocalServs(), TreeSocket::DoBurst(), DoOneToAllButSender(), DoOneToAllButSenderRaw(), DoOneToMany(), ModuleSpanningTree::DoPingChecks(), cmd_rsquit::Handle(), ModuleSpanningTree::HandleLinks(), ModuleSpanningTree::HandleLusers(), ModuleSpanningTree::HandleMap(), ModuleSpanningTree::HandleSquit(), ModuleSpanningTree::HandleTime(), ModuleSpanningTree::HandleVersion(), TreeSocket::Outbound_Reply_Server(), TreeSocket::ProcessLine(), ModuleSpanningTree::ShowLinks(), SpanningTreeUtilities(), TreeSocket::Squit(), TreeServer::TreeServer(), and ~SpanningTreeUtilities().

std::vector<std::string> SpanningTreeUtilities::ValidIPs
 

IPs allowed to link to us.

Definition at line 88 of file utils.h.

Referenced by TreeSocket::OnIncomingConnection(), SecurityIPResolver::OnLookupComplete(), ReadConfiguration(), and RefreshIPCache().


The documentation for this class was generated from the following files: