summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_spanningtree/main.cpp4
-rw-r--r--src/modules/m_spanningtree/override_stats.cpp8
-rw-r--r--src/modules/m_spanningtree/resolvers.cpp2
-rw-r--r--src/modules/m_spanningtree/treesocket.h35
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp18
-rw-r--r--src/modules/m_spanningtree/treesocket2.cpp34
-rw-r--r--src/modules/m_spanningtree/utils.cpp56
-rw-r--r--src/modules/m_spanningtree/utils.h20
8 files changed, 84 insertions, 93 deletions
diff --git a/src/modules/m_spanningtree/main.cpp b/src/modules/m_spanningtree/main.cpp
index 43f3c9b64..caaac5ebe 100644
--- a/src/modules/m_spanningtree/main.cpp
+++ b/src/modules/m_spanningtree/main.cpp
@@ -274,7 +274,7 @@ void ModuleSpanningTree::ConnectServer(Link* x)
/* Gave a hook, but it wasnt one we know */
if ((!x->Hook.empty()) && (Utils->hooks.find(x->Hook.c_str()) == Utils->hooks.end()))
return;
- TreeSocket* newsocket = new TreeSocket(Utils, ServerInstance, x->IPAddr,x->Port,false,x->Timeout ? x->Timeout : 10,x->Name.c_str(), x->Bind, x->Hook.empty() ? NULL : Utils->hooks[x->Hook.c_str()]);
+ TreeSocket* newsocket = new TreeSocket(Utils, ServerInstance, x->IPAddr,x->Port, x->Timeout ? x->Timeout : 10,x->Name.c_str(), x->Bind, x->Hook.empty() ? NULL : Utils->hooks[x->Hook.c_str()]);
if (newsocket->GetFd() > -1)
{
/* Handled automatically on success */
@@ -878,10 +878,10 @@ void ModuleSpanningTree::OnEvent(Event* event)
ModuleSpanningTree::~ModuleSpanningTree()
{
- /* This will also free the listeners */
delete ServerInstance->PI;
ServerInstance->PI = new ProtocolInterface(ServerInstance);
+ /* This will also free the listeners */
delete Utils;
ServerInstance->Timers->DelTimer(RefreshTimer);
diff --git a/src/modules/m_spanningtree/override_stats.cpp b/src/modules/m_spanningtree/override_stats.cpp
index a7e5c704b..1b0ca938a 100644
--- a/src/modules/m_spanningtree/override_stats.cpp
+++ b/src/modules/m_spanningtree/override_stats.cpp
@@ -76,15 +76,15 @@ int ModuleSpanningTree::OnStats(char statschar, User* user, string_list &results
for (unsigned int i = 0; i < Utils->Bindings.size(); i++)
{
- std::string ip = Utils->Bindings[i]->IP;
+ std::string ip = Utils->Bindings[i]->GetIP();
if (ip.empty())
ip = "*";
std::string transport("plaintext");
- if (Utils->Bindings[i]->GetHook())
- transport = BufferedSocketNameRequest(this, Utils->Bindings[i]->GetHook()).Send();
+ if (Utils->Bindings[i]->GetIOHook())
+ transport = BufferedSocketNameRequest(this, Utils->Bindings[i]->GetIOHook()).Send();
- results.push_back(ConvToStr(ServerInstance->Config->ServerName) + " 249 "+user->nick+" :" + ip + ":" + ConvToStr(Utils->Bindings[i]->port)+
+ results.push_back(ConvToStr(ServerInstance->Config->ServerName) + " 249 "+user->nick+" :" + ip + ":" + ConvToStr(Utils->Bindings[i]->GetPort())+
" (server, " + transport + ")");
}
}
diff --git a/src/modules/m_spanningtree/resolvers.cpp b/src/modules/m_spanningtree/resolvers.cpp
index 3ea6e2bdf..4a33cd216 100644
--- a/src/modules/m_spanningtree/resolvers.cpp
+++ b/src/modules/m_spanningtree/resolvers.cpp
@@ -54,7 +54,7 @@ void ServernameResolver::OnLookupComplete(const std::string &result, unsigned in
if ((!MyLink.Hook.empty()) && (Utils->hooks.find(MyLink.Hook.c_str()) == Utils->hooks.end()))
return;
- TreeSocket* newsocket = new TreeSocket(this->Utils, ServerInstance, result,MyLink.Port,false,MyLink.Timeout ? MyLink.Timeout : 10,MyLink.Name.c_str(),
+ TreeSocket* newsocket = new TreeSocket(this->Utils, ServerInstance, result,MyLink.Port,MyLink.Timeout ? MyLink.Timeout : 10,MyLink.Name.c_str(),
MyLink.Bind, MyLink.Hook.empty() ? NULL : Utils->hooks[MyLink.Hook.c_str()]);
if (newsocket->GetFd() > -1)
{
diff --git a/src/modules/m_spanningtree/treesocket.h b/src/modules/m_spanningtree/treesocket.h
index fb0fe1c31..0026b6b6a 100644
--- a/src/modules/m_spanningtree/treesocket.h
+++ b/src/modules/m_spanningtree/treesocket.h
@@ -43,21 +43,19 @@
* to apply an operation to a server, and any of its child objects
* we can resort to recursion to walk the tree structure.
* Any socket can have one of five states at any one time.
- * The LISTENER state indicates a socket which is listening
- * for connections. It cannot receive data itself, only incoming
- * sockets.
- * The CONNECTING state indicates an outbound socket which is
- * waiting to be writeable.
- * The WAIT_AUTH_1 state indicates the socket is outbound and
- * has successfully connected, but has not yet sent and received
- * SERVER strings.
- * The WAIT_AUTH_2 state indicates that the socket is inbound
- * (allocated by a LISTENER) but has not yet sent and received
- * SERVER strings.
- * The CONNECTED state represents a fully authorized, fully
- * connected server.
+ *
+ * CONNECTING: indicates an outbound socket which is
+ * waiting to be writeable.
+ * WAIT_AUTH_1: indicates the socket is outbound and
+ * has successfully connected, but has not
+ * yet sent and received SERVER strings.
+ * WAIT_AUTH_2: indicates that the socket is inbound
+ * but has not yet sent and received
+ * SERVER strings.
+ * CONNECTED: represents a fully authorized, fully
+ * connected server.
*/
-enum ServerState { LISTENER, CONNECTING, WAIT_AUTH_1, WAIT_AUTH_2, CONNECTED };
+enum ServerState { CONNECTING, WAIT_AUTH_1, WAIT_AUTH_2, CONNECTED };
/** Every SERVER connection inbound or outbound is represented by
* an object of type TreeSocket.
@@ -98,14 +96,7 @@ class TreeSocket : public BufferedSocket
* most of the action, and append a few of our own values
* to it.
*/
- TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string host, int port, bool listening, unsigned long maxtime, Module* HookMod = NULL);
-
- /** Because most of the I/O gubbins are encapsulated within
- * BufferedSocket, we just call the superclass constructor for
- * most of the action, and append a few of our own values
- * to it.
- */
- TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string host, int port, bool listening, unsigned long maxtime, const std::string &ServerName, const std::string &bindto, Module* HookMod = NULL);
+ TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string host, int port, unsigned long maxtime, const std::string &ServerName, const std::string &bindto, Module* HookMod = NULL);
/** When a listening socket gives us a new file descriptor,
* we must associate it with a socket without creating a new
diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp
index 1f0288a66..589e05bcd 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -36,19 +36,8 @@
* most of the action, and append a few of our own values
* to it.
*/
-TreeSocket::TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string shost, int iport, bool listening, unsigned long maxtime, Module* HookMod)
- : BufferedSocket(SI, shost, iport, listening, maxtime), Utils(Util), Hook(HookMod)
-{
- myhost = host;
- this->LinkState = LISTENER;
- theirchallenge.clear();
- ourchallenge.clear();
- if (listening && Hook)
- BufferedSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send();
-}
-
-TreeSocket::TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string shost, int iport, bool listening, unsigned long maxtime, const std::string &ServerName, const std::string &bindto, Module* HookMod)
- : BufferedSocket(SI, shost, iport, listening, maxtime, bindto), Utils(Util), Hook(HookMod)
+TreeSocket::TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string shost, int iport, unsigned long maxtime, const std::string &ServerName, const std::string &bindto, Module* HookMod)
+ : BufferedSocket(SI, shost, iport, maxtime, bindto), Utils(Util), Hook(HookMod)
{
myhost = ServerName;
theirchallenge.clear();
@@ -142,9 +131,6 @@ void TreeSocket::OnError(BufferedSocketError e)
{
Link* MyLink;
- if (this->LinkState == LISTENER)
- return;
-
switch (e)
{
case I_ERR_CONNECT:
diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp
index dd55e3ee6..c2664a65e 100644
--- a/src/modules/m_spanningtree/treesocket2.cpp
+++ b/src/modules/m_spanningtree/treesocket2.cpp
@@ -205,13 +205,6 @@ bool TreeSocket::ProcessLine(std::string &line)
}
break;
- case LISTENER:
- /*
- * This really shouldn't happen.
- */
- this->SendError("Internal error -- listening socket accepted its own descriptor!!!");
- return false;
- break;
case CONNECTING:
/*
* State CONNECTING:
@@ -661,31 +654,4 @@ void TreeSocket::OnClose()
}
}
-int TreeSocket::OnIncomingConnection(int newsock, char* ip)
-{
- bool found = false;
-
- found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), ip) != Utils->ValidIPs.end());
- if (!found)
- {
- for (std::vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
- {
- if (*i == "*" || irc::sockets::MatchCIDR(ip, *i))
- {
- found = true;
- break;
- }
- }
-
- if (!found)
- {
- Utils->Creator->RemoteMessage(NULL,"Server connection from %s denied (no link blocks with that IP address)", ip);
- Instance->SE->Close(newsock);
- return false;
- }
- }
- /* we don't need a pointer to this, creating it stores it in the necessary places */
- new TreeSocket(this->Utils, this->Instance, newsock, ip, this->Hook);
- return true;
-}
diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp
index c0692f542..0b610404f 100644
--- a/src/modules/m_spanningtree/utils.cpp
+++ b/src/modules/m_spanningtree/utils.cpp
@@ -28,6 +28,37 @@
/* $ModDep: m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */
+/* Create server sockets off a listener. */
+void ServerSocketListener::OnAcceptReady(const std::string &ipconnectedto, int newsock, const std::string &incomingip)
+{
+ bool found = false;
+ char *ip = (char *)incomingip.c_str(); // XXX ugly cast
+
+ found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), ip) != Utils->ValidIPs.end());
+ if (!found)
+ {
+ for (std::vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
+ {
+ if (*i == "*" || irc::sockets::MatchCIDR(ip, *i))
+ {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ {
+ Utils->Creator->RemoteMessage(NULL,"Server connection from %s denied (no link blocks with that IP address)", ip);
+ ServerInstance->SE->Close(newsock);
+ return;
+ }
+ }
+
+ /* we don't need a pointer to this, creating it stores it in the necessary places */
+ new TreeSocket(this->Utils, this->ServerInstance, newsock, ip, this->GetIOHook());
+ return;
+}
+
/** Yay for fast searches!
* This is hundreds of times faster than recursion
* or even scanning a linked list, especially when
@@ -144,9 +175,9 @@ SpanningTreeUtilities::~SpanningTreeUtilities()
{
for (unsigned int i = 0; i < Bindings.size(); i++)
{
- ServerInstance->SE->DelFd(Bindings[i]);
- Bindings[i]->Close();
+ delete Bindings[i];
}
+
while (TreeRoot->ChildCount())
{
TreeServer* child_server = TreeRoot->GetChild(0);
@@ -417,8 +448,7 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
{
for (unsigned int i = 0; i < Bindings.size(); i++)
{
- ServerInstance->SE->DelFd(Bindings[i]);
- Bindings[i]->Close();
+ delete Bindings[i];
}
ServerInstance->BufferedSocketCull();
Bindings.clear();
@@ -445,17 +475,17 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
break;
}
- TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10, transport.empty() ? NULL : hooks[transport.c_str()]);
- if (listener->GetState() == I_LISTENING)
- {
- ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"m_spanningtree: Binding server port %s:%d successful!", IP.c_str(), portno);
- Bindings.push_back(listener);
- }
- else
+ ServerSocketListener *listener = new ServerSocketListener(ServerInstance, this, portno, (char *)IP.c_str());
+ if (listener->GetFd() == -1)
{
- ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"m_spanningtree: Warning: Failed to bind server port: %s:%d: %s",IP.c_str(), portno, strerror(errno));
- listener->Close();
+ delete listener;
+ continue;
}
+
+ if (!transport.empty())
+ listener->AddIOHook(hooks[transport.c_str()]);
+
+ Bindings.push_back(listener);
}
}
}
diff --git a/src/modules/m_spanningtree/utils.h b/src/modules/m_spanningtree/utils.h
index 27df8ddbf..1022c1796 100644
--- a/src/modules/m_spanningtree/utils.h
+++ b/src/modules/m_spanningtree/utils.h
@@ -21,6 +21,7 @@ class TreeServer;
class TreeSocket;
class Link;
class ModuleSpanningTree;
+class SpanningTreeUtilities;
/* This hash_map holds the hash equivalent of the server
* tree, used for rapid linear lookups.
@@ -35,6 +36,22 @@ class ModuleSpanningTree;
#endif
#endif
+/*
+ * Initialises server connections
+ */
+class ServerSocketListener : public ListenSocketBase
+{
+ SpanningTreeUtilities *Utils;
+
+ public:
+ ServerSocketListener(InspIRCd* Instance, SpanningTreeUtilities *u, int port, char* addr) : ListenSocketBase(Instance, port, addr)
+ {
+ this->Utils = u;
+ }
+
+ virtual void OnAcceptReady(const std::string &ipconnectedto, int nfd, const std::string &incomingip);
+};
+
typedef std::map<TreeServer*,TreeServer*> TreeServerList;
/** A group of modules that implement BufferedSocketHook
@@ -69,9 +86,10 @@ class SpanningTreeUtilities : public classbase
/** Make snomasks +CQ quiet during bursts and splits
*/
bool quiet_bursts;
+
/** Socket bindings for listening sockets
*/
- std::vector<TreeSocket*> Bindings;
+ std::vector<ServerSocketListener *> Bindings;
/* Number of seconds that a server can go without ping
* before opers are warned of high latency.
*/