/* $ModDesc: Povides a spanning tree server link protocol */
-using namespace std;
-
#include "configreader.h"
#include "users.h"
#include "channels.h"
#include "inspircd.h"
#include "wildcard.h"
#include "xline.h"
-#include "cull_list.h"
#include "aes.h"
-using irc::sockets::MatchCIDR;
-
/** If you make a change which breaks the protocol, increment this.
* If you completely change the protocol, completely change the number.
*/
*/
typedef nspace::hash_map<std::string, TreeServer*, nspace::hash<string>, irc::StrHashComp> server_hash;
+
+/** The Link class might as well be a struct,
+ * but this is C++ and we don't believe in structs (!).
+ * It holds the entire information of one <link>
+ * tag from the main config file. We maintain a list
+ * of them, and populate the list on rehash/load.
+ */
+class Link : public classbase
+{
+ public:
+ irc::string Name;
+ std::string IPAddr;
+ int Port;
+ std::string SendPass;
+ std::string RecvPass;
+ unsigned long AutoConnect;
+ time_t NextConnectTime;
+ std::string EncryptionKey;
+ bool HiddenFromStats;
+ std::string FailOver;
+};
+
/** Contains helper functions and variables for this module,
* and keeps them out of the global namespace
*/
class SpanningTreeUtilities
{
private:
+ /** Creator server
+ */
InspIRCd* ServerInstance;
public:
+ /** Creator module
+ */
ModuleSpanningTree* Creator;
- 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 */
- std::vector<TreeSocket*> Bindings; /* Socket bindings */
- /* This variable represents the root of the server tree */
+ /** Flatten links and /MAP for non-opers
+ */
+ bool FlatLinks;
+ /** Hide U-Lined servers in /MAP and /LINKS
+ */
+ bool HideULines;
+ /** Announce TS changes to channels on merge
+ */
+ bool AnnounceTSChange;
+ /** Socket bindings for listening sockets
+ */
+ std::vector<TreeSocket*> Bindings;
+ /** This variable represents the root of the server tree
+ */
TreeServer *TreeRoot;
- /* IPs allowed to link to us */
+ /** IPs allowed to link to us
+ */
std::vector<std::string> ValidIPs;
- /* Hash of currently connected servers by name */
+ /** Hash of currently connected servers by name
+ */
server_hash serverlist;
- /* Holds the data from the <link> tags in the conf */
+ /** Holds the data from the <link> tags in the conf
+ */
std::vector<Link> LinkBlocks;
+ /** Initialise utility class
+ */
SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* Creator);
+ /** Destroy class and free listeners etc
+ */
~SpanningTreeUtilities();
+ /** Send a message from this server to one other local or remote
+ */
bool DoOneToOne(std::string prefix, std::string command, std::deque<std::string> ¶ms, std::string target);
+ /** Send a message from this server to all but one other, local or remote
+ */
bool DoOneToAllButSender(std::string prefix, std::string command, std::deque<std::string> ¶ms, 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> ¶ms, std::string omit);
+ /** Send a message from this server to all others
+ */
bool DoOneToMany(std::string prefix, std::string command, std::deque<std::string> ¶ms);
+ /** Send a message from this server to all others
+ */
bool DoOneToMany(const char* prefix, const char* command, std::deque<std::string> ¶ms);
+ /** 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)
+ */
bool DoOneToAllButSenderRaw(std::string data, std::string omit, std::string prefix, irc::string command, std::deque<std::string> ¶ms);
+ /** Read the spanningtree module's tags from the config file
+ */
void ReadConfiguration(bool rebind);
+ /** Add a server to the server list for GetListOfServersForChannel
+ */
void AddThisServer(TreeServer* server, std::deque<TreeServer*> &list);
+ /** Compile a list of servers which contain members of channel c
+ */
void GetListOfServersForChannel(chanrec* c, std::deque<TreeServer*> &list);
+ /** Find a server by name
+ */
TreeServer* FindServer(std::string ServerName);
+ /** Find a route to a server by name
+ */
TreeServer* BestRouteTo(std::string ServerName);
+ /** Find a server by glob mask
+ */
TreeServer* FindServerMask(std::string ServerName);
+ /** Returns true if this is a server name we recognise
+ */
bool IsServer(std::string ServerName);
+ /** Attempt to connect to the failover link of link x
+ */
void DoFailOver(Link* x);
+ /** Find a link tag from a server name
+ */
Link* FindLink(const std::string& name);
};
class TreeServer : public classbase
{
InspIRCd* ServerInstance; /* Creator */
- SpanningTreeUtilities* Utils; /* Utility class */
TreeServer* Parent; /* Parent entry */
TreeServer* Route; /* Route entry */
std::vector<TreeServer*> Children; /* List of child objects */
TreeSocket* Socket; /* For directly connected servers this points at the socket object */
time_t NextPing; /* After this time, the server should be PINGed*/
bool LastPingWasGood; /* True if the server responded to the last PING with a PONG */
+ SpanningTreeUtilities* Utils; /* Utility class */
public:
/** We don't use this constructor. Its a dummy, and won't cause any insertion
* of the TreeServer into the hash_map. See below for the two we DO use.
*/
- TreeServer(SpanningTreeUtilities* Utils, InspIRCd* Instance) : ServerInstance(Instance)
+ TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance) : ServerInstance(Instance), Utils(Util)
{
Parent = NULL;
ServerName = "";
* represents our own server. Therefore, it has no route, no parent, and
* no socket associated with it. Its version string is our own local version.
*/
- TreeServer(SpanningTreeUtilities* Utils, InspIRCd* Instance, std::string Name, std::string Desc) : ServerInstance(Instance), ServerName(Name.c_str()), ServerDesc(Desc)
+ TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc) : ServerInstance(Instance), ServerName(Name.c_str()), ServerDesc(Desc), Utils(Util)
{
Parent = NULL;
VersionString = "";
* This constructor initializes the server's Route and Parent, and sets up
* its ping counters so that it will be pinged one minute from now.
*/
- TreeServer(SpanningTreeUtilities* Utils, InspIRCd* Instance, std::string Name, std::string Desc, TreeServer* Above, TreeSocket* Sock)
- : ServerInstance(Instance), Parent(Above), ServerName(Name.c_str()), ServerDesc(Desc), Socket(Sock)
+ TreeServer(SpanningTreeUtilities* Util, InspIRCd* Instance, std::string Name, std::string Desc, TreeServer* Above, TreeSocket* Sock)
+ : ServerInstance(Instance), Parent(Above), ServerName(Name.c_str()), ServerDesc(Desc), Socket(Sock), Utils(Util)
{
VersionString = "";
UserCount = OperCount = 0;
}
};
-/** The Link class might as well be a struct,
- * but this is C++ and we don't believe in structs (!).
- * It holds the entire information of one <link>
- * tag from the main config file. We maintain a list
- * of them, and populate the list on rehash/load.
- */
-class Link : public classbase
-{
- public:
- irc::string Name;
- std::string IPAddr;
- int Port;
- std::string SendPass;
- std::string RecvPass;
- unsigned long AutoConnect;
- time_t NextConnectTime;
- std::string EncryptionKey;
- bool HiddenFromStats;
- irc::string FailOver;
-};
-
/** Yay for fast searches!
* This is hundreds of times faster than recursion
* or even scanning a linked list, especially when
if (!found)
{
for (vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
- if (MatchCIDR(ip, (*i).c_str()))
+ if (irc::sockets::MatchCIDR(ip, (*i).c_str()))
found = true;
if (!found)
SpanningTreeUtilities::SpanningTreeUtilities(InspIRCd* Instance, ModuleSpanningTree* C) : ServerInstance(Instance), Creator(C)
{
Bindings.clear();
- this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc);
this->ReadConfiguration(true);
+ this->TreeRoot = new TreeServer(this, ServerInstance, ServerInstance->Config->ServerName, ServerInstance->Config->ServerDesc);
}
SpanningTreeUtilities::~SpanningTreeUtilities()
DELETE(sock);
}
}
+ delete TreeRoot;
}
void SpanningTreeUtilities::AddThisServer(TreeServer* server, std::deque<TreeServer*> &list)