1 #include "configreader.h"
5 #include "commands/cmd_whois.h"
6 #include "commands/cmd_stats.h"
11 #include "transport.h"
13 #include "m_spanningtree/resolvers.h"
14 #include "m_spanningtree/main.h"
15 #include "m_spanningtree/utils.h"
16 #include "m_spanningtree/treeserver.h"
17 #include "m_spanningtree/link.h"
18 #include "m_spanningtree/treesocket.h"
20 /* $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 */
22 /** This class is used to resolve server hostnames during /connect and autoconnect.
23 * As of 1.1, the resolver system is seperated out from InspSocket, so we must do this
24 * resolver step first ourselves if we need it. This is totally nonblocking, and will
25 * callback to OnLookupComplete or OnError when completed. Once it has completed we
26 * will have an IP address which we can then use to continue our connection.
28 ServernameResolver::ServernameResolver(Module* me, SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &hostname, Link x, bool &cached, QueryType qt) : Resolver(Instance, hostname, qt, cached, me), MyLink(x), Utils(Util), query(qt), host(hostname), mine(me)
30 /* Nothing in here, folks */
33 void ServernameResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
35 /* Initiate the connection, now that we have an IP to use.
36 * Passing a hostname directly to InspSocket causes it to
37 * just bail and set its FD to -1.
39 TreeServer* CheckDupe = Utils->FindServer(MyLink.Name.c_str());
40 if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
43 if ((!MyLink.Hook.empty()) && (Utils->hooks.find(MyLink.Hook.c_str()) == Utils->hooks.end()))
46 TreeSocket* newsocket = new TreeSocket(this->Utils, ServerInstance, result,MyLink.Port,false,MyLink.Timeout ? MyLink.Timeout : 10,MyLink.Name.c_str(),
47 MyLink.Bind, MyLink.Hook.empty() ? NULL : Utils->hooks[MyLink.Hook.c_str()]);
48 if (newsocket->GetFd() > -1)
54 /* Something barfed, show the opers */
55 ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: %s.",MyLink.Name.c_str(),strerror(errno));
57 Utils->DoFailOver(&MyLink);
62 void ServernameResolver::OnError(ResolverError e, const std::string &errormessage)
65 if (query == DNS_QUERY_AAAA)
68 ServernameResolver* snr = new ServernameResolver(mine, Utils, ServerInstance, host, MyLink, cached, DNS_QUERY_A);
69 ServerInstance->AddResolver(snr, cached);
72 ServerInstance->SNO->WriteToSnoMask('l',"CONNECT: Error connecting \002%s\002: Unable to resolve hostname - %s",MyLink.Name.c_str(),errormessage.c_str());
73 Utils->DoFailOver(&MyLink);