diff options
Diffstat (limited to 'docs/module-doc/servers_8cpp-source.html')
-rw-r--r-- | docs/module-doc/servers_8cpp-source.html | 575 |
1 files changed, 0 insertions, 575 deletions
diff --git a/docs/module-doc/servers_8cpp-source.html b/docs/module-doc/servers_8cpp-source.html deleted file mode 100644 index 297f887fa..000000000 --- a/docs/module-doc/servers_8cpp-source.html +++ /dev/null @@ -1,575 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> -<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> -<title>InspIRCd: servers.cpp Source File</title> -<link href="inspircd.doxygen.css" rel="stylesheet" type="text/css"> -</head><body> -<!-- Generated by Doxygen 1.3.3 --> -<div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Compound List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Compound Members</a> | <a class="qindex" href="globals.html">File Members</a></div> -<h1>servers.cpp</h1><a href="servers_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/* +------------------------------------+</span> -00002 <span class="comment"> * | Inspire Internet Relay Chat Daemon |</span> -00003 <span class="comment"> * +------------------------------------+</span> -00004 <span class="comment"> *</span> -00005 <span class="comment"> * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.</span> -00006 <span class="comment"> * E-mail:</span> -00007 <span class="comment"> * <brain@chatspike.net></span> -00008 <span class="comment"> * <Craig@chatspike.net></span> -00009 <span class="comment"> * </span> -00010 <span class="comment"> * Written by Craig Edwards, Craig McLure, and others.</span> -00011 <span class="comment"> * This program is free but copyrighted software; see</span> -00012 <span class="comment"> * the file COPYING for details.</span> -00013 <span class="comment"> *</span> -00014 <span class="comment"> * ---------------------------------------------------</span> -00015 <span class="comment"> */</span> -00016 -00017 <span class="keyword">using</span> <span class="keyword">namespace </span>std; -00018 -00019 <span class="preprocessor">#include "inspircd_config.h"</span> -00020 <span class="preprocessor">#include "<a class="code" href="servers_8h.html">servers.h</a>"</span> -00021 <span class="preprocessor">#include "inspircd.h"</span> -00022 <span class="preprocessor">#include <unistd.h></span> -00023 <span class="preprocessor">#include <fcntl.h></span> -00024 <span class="preprocessor">#include <poll.h></span> -00025 <span class="preprocessor">#include <sys/errno.h></span> -00026 <span class="preprocessor">#include <sys/ioctl.h></span> -00027 <span class="preprocessor">#include <sys/utsname.h></span> -00028 <span class="preprocessor">#include <vector></span> -00029 <span class="preprocessor">#include <string></span> -00030 <span class="preprocessor">#include <deque></span> -00031 <span class="preprocessor">#include <sstream></span> -00032 <span class="preprocessor">#include <map></span> -00033 <span class="preprocessor">#include "inspstring.h"</span> -00034 <span class="preprocessor">#include "helperfuncs.h"</span> -00035 <span class="preprocessor">#include "<a class="code" href="connection_8h.html">connection.h</a>"</span> -00036 -<a name="l00037"></a><a class="code" href="servers_8cpp.html#a0">00037</a> <span class="keyword">extern</span> time_t <a class="code" href="channels_8cpp.html#a36">TIME</a>; -<a name="l00038"></a><a class="code" href="servers_8cpp.html#a1">00038</a> <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="servers_8cpp.html#a1">MaxConn</a>; -00039 -<a name="l00040"></a><a class="code" href="servers_8cpp.html#a2">00040</a> <span class="keyword">extern</span> <a class="code" href="classserverrec.html">serverrec</a>* <a class="code" href="channels_8cpp.html#a34">me</a>[32]; -00041 -<a name="l00042"></a><a class="code" href="servers_8cpp.html#a3">00042</a> <span class="keyword">extern</span> <span class="keywordtype">bool</span> <a class="code" href="servers_8cpp.html#a3">has_been_netsplit</a>; -00043 -<a name="l00044"></a><a class="code" href="servers_8cpp.html#a4">00044</a> std::deque<std::string> <a class="code" href="servers_8cpp.html#a4">xsums</a>; -00045 -<a name="l00046"></a><a class="code" href="classserverrec.html#a0">00046</a> <a class="code" href="classserverrec.html#a0">serverrec::serverrec</a>() -00047 { -00048 strlcpy(<a class="code" href="classserverrec.html#o0">name</a>,<span class="stringliteral">""</span>,256); -00049 <a class="code" href="classserverrec.html#o1">pingtime</a> = 0; -00050 <a class="code" href="classconnection.html#o10">lastping</a> = <a class="code" href="channels_8cpp.html#a36">TIME</a>; -00051 <a class="code" href="classserverrec.html#o2">usercount_i</a> = <a class="code" href="classserverrec.html#o3">usercount</a> = <a class="code" href="classserverrec.html#o4">opercount</a> = <a class="code" href="classserverrec.html#o6">version</a> = 0; -00052 <a class="code" href="classserverrec.html#o5">hops_away</a> = 1; -00053 <a class="code" href="classconnection.html#o11">signon</a> = <a class="code" href="channels_8cpp.html#a36">TIME</a>; -00054 <a class="code" href="classserverrec.html#o7">jupiter</a> = <span class="keyword">false</span>; -00055 <a class="code" href="classconnection.html#o0">fd</a> = 0; -00056 <a class="code" href="classserverrec.html#o10">sync_soon</a> = <span class="keyword">false</span>; -00057 strlcpy(<a class="code" href="classserverrec.html#o9">nickserv</a>,<span class="stringliteral">""</span>,NICKMAX); -00058 <a class="code" href="classserverrec.html#o11">connectors</a>.clear(); -00059 } -00060 -00061 -<a name="l00062"></a><a class="code" href="classserverrec.html#a2">00062</a> <a class="code" href="classserverrec.html#a2">serverrec::~serverrec</a>() -00063 { -00064 } -00065 -<a name="l00066"></a><a class="code" href="classserverrec.html#a1">00066</a> <a class="code" href="classserverrec.html#a0">serverrec::serverrec</a>(<span class="keywordtype">char</span>* n, <span class="keywordtype">long</span> ver, <span class="keywordtype">bool</span> jupe) -00067 { -00068 strlcpy(<a class="code" href="classserverrec.html#o0">name</a>,n,256); -00069 <a class="code" href="classconnection.html#o10">lastping</a> = <a class="code" href="channels_8cpp.html#a36">TIME</a>; -00070 <a class="code" href="classserverrec.html#o2">usercount_i</a> = <a class="code" href="classserverrec.html#o3">usercount</a> = <a class="code" href="classserverrec.html#o4">opercount</a> = 0; -00071 <a class="code" href="classserverrec.html#o6">version</a> = ver; -00072 <a class="code" href="classserverrec.html#o5">hops_away</a> = 1; -00073 <a class="code" href="classconnection.html#o11">signon</a> = <a class="code" href="channels_8cpp.html#a36">TIME</a>; -00074 <a class="code" href="classserverrec.html#o7">jupiter</a> = jupe; -00075 <a class="code" href="classconnection.html#o0">fd</a> = 0; -00076 <a class="code" href="classserverrec.html#o10">sync_soon</a> = <span class="keyword">false</span>; -00077 strlcpy(<a class="code" href="classserverrec.html#o9">nickserv</a>,<span class="stringliteral">""</span>,NICKMAX); -00078 <a class="code" href="classserverrec.html#o11">connectors</a>.clear(); -00079 } -00080 -<a name="l00081"></a><a class="code" href="classserverrec.html#a3">00081</a> <span class="keywordtype">bool</span> <a class="code" href="classserverrec.html#a3">serverrec::CreateListener</a>(<span class="keywordtype">char</span>* newhost, <span class="keywordtype">int</span> p) -00082 { -00083 sockaddr_in host_address; -00084 <span class="keywordtype">int</span> flags; -00085 in_addr addy; -00086 <span class="keywordtype">int</span> on = 0; -00087 <span class="keyword">struct </span>linger linger = { 0 }; -00088 -00089 this-><a class="code" href="classconnection.html#o8">port</a> = p; -00090 -00091 <a class="code" href="classconnection.html#o0">fd</a> = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); -00092 <span class="keywordflow">if</span> (<a class="code" href="classconnection.html#o0">fd</a> <= 0) -00093 { -00094 <span class="keywordflow">return</span> <span class="keyword">false</span>; -00095 } -00096 -00097 setsockopt(<a class="code" href="classconnection.html#o0">fd</a>,SOL_SOCKET,SO_REUSEADDR,(<span class="keyword">const</span> <span class="keywordtype">char</span>*)&on,<span class="keyword">sizeof</span>(on)); -00098 linger.l_onoff = 1; -00099 linger.l_linger = 1; -00100 setsockopt(<a class="code" href="classconnection.html#o0">fd</a>,SOL_SOCKET,SO_LINGER,(<span class="keyword">const</span> <span class="keywordtype">char</span>*)&linger,<span class="keyword">sizeof</span>(linger)); -00101 -00102 <span class="comment">// attempt to increase socket sendq and recvq as high as its possible</span> -00103 <span class="comment">// to get them on linux.</span> -00104 <span class="keywordtype">int</span> sendbuf = 32768; -00105 <span class="keywordtype">int</span> recvbuf = 32768; -00106 setsockopt(<a class="code" href="classconnection.html#o0">fd</a>,SOL_SOCKET,SO_SNDBUF,(<span class="keyword">const</span> <span class="keywordtype">void</span> *)&sendbuf,<span class="keyword">sizeof</span>(sendbuf)); -00107 setsockopt(<a class="code" href="classconnection.html#o0">fd</a>,SOL_SOCKET,SO_RCVBUF,(<span class="keyword">const</span> <span class="keywordtype">void</span> *)&recvbuf,<span class="keyword">sizeof</span>(sendbuf)); -00108 -00109 memset((<span class="keywordtype">void</span>*)&host_address, 0, <span class="keyword">sizeof</span>(host_address)); -00110 -00111 host_address.sin_family = AF_INET; -00112 -00113 <span class="keywordflow">if</span> (!strcmp(newhost,<span class="stringliteral">""</span>)) -00114 { -00115 host_address.sin_addr.s_addr = htonl(INADDR_ANY); -00116 } -00117 <span class="keywordflow">else</span> -00118 { -00119 inet_aton(newhost,&addy); -00120 host_address.sin_addr = addy; -00121 } -00122 -00123 host_address.sin_port = htons(p); -00124 -00125 <span class="keywordflow">if</span> (bind(<a class="code" href="classconnection.html#o0">fd</a>,(sockaddr*)&host_address,<span class="keyword">sizeof</span>(host_address))<0) -00126 { -00127 <span class="keywordflow">return</span> <span class="keyword">false</span>; -00128 } -00129 -00130 <span class="comment">// make the socket non-blocking</span> -00131 flags = fcntl(<a class="code" href="classconnection.html#o0">fd</a>, F_GETFL, 0); -00132 fcntl(<a class="code" href="classconnection.html#o0">fd</a>, F_SETFL, flags | O_NONBLOCK); -00133 -00134 this-><a class="code" href="classconnection.html#o8">port</a> = p; -00135 -00136 listen(this->fd, <a class="code" href="servers_8cpp.html#a1">MaxConn</a>); -00137 -00138 <span class="keywordflow">return</span> <span class="keyword">true</span>; -00139 } -00140 -00141 -<a name="l00142"></a><a class="code" href="classserverrec.html#a4">00142</a> <span class="keywordtype">bool</span> <a class="code" href="classserverrec.html#a4">serverrec::BeginLink</a>(<span class="keywordtype">char</span>* targethost, <span class="keywordtype">int</span> newport, <span class="keywordtype">char</span>* password, <span class="keywordtype">char</span>* servername, <span class="keywordtype">int</span> myport) -00143 { -00144 <span class="keywordtype">char</span> connect[MAXBUF]; -00145 -00146 <a class="code" href="classircd__connector.html">ircd_connector</a> connector; -00147 <a class="code" href="classircd__connector.html">ircd_connector</a> *cn = this-><a class="code" href="classserverrec.html#a9">FindHost</a>(servername); -00148 -00149 -00150 <span class="keywordflow">if</span> (cn) -00151 { -00152 WriteOpers(<span class="stringliteral">"CONNECT aborted: Server %s already exists"</span>,servername); -00153 <span class="keywordflow">return</span> <span class="keyword">false</span>; -00154 } -00155 -00156 -00157 <span class="keywordflow">if</span> (this-><a class="code" href="classconnection.html#o0">fd</a>) -00158 { -00159 <span class="keywordflow">if</span> (connector.<a class="code" href="classircd__connector.html#a1">MakeOutboundConnection</a>(targethost,newport)) -00160 { -00161 <span class="comment">// targethost has been turned into an ip...</span> -00162 <span class="comment">// we dont want this as the server name.</span> -00163 connector.<a class="code" href="classircd__connector.html#a3">SetServerName</a>(servername); -00164 snprintf(connect,MAXBUF,<span class="stringliteral">"S %s %s %lu %s :%s"</span>,getservername().c_str(),password,(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)myport,GetRevision().c_str(),getserverdesc().c_str()); -00165 connector.<a class="code" href="classircd__connector.html#a7">SetState</a>(<a class="code" href="connection_8h.html#a4">STATE_NOAUTH_OUTBOUND</a>); -00166 connector.<a class="code" href="classircd__connector.html#a13">SetHostAndPort</a>(targethost, newport); -00167 this-><a class="code" href="classserverrec.html#o11">connectors</a>.push_back(connector); -00168 <span class="comment">// this packet isn't actually sent until the socket connects -- the STATE_NOAUTH_OUTBOUND state</span> -00169 <span class="comment">// queues outbound data until the socket is polled as writeable (e.g. the connection is established)</span> -00170 <span class="keywordflow">return</span> this-><a class="code" href="classserverrec.html#a7">SendPacket</a>(connect, servername); -00171 } -00172 <span class="keywordflow">else</span> -00173 { -00174 connector.<a class="code" href="classircd__connector.html#a7">SetState</a>(<a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>); -00175 WriteOpers(<span class="stringliteral">"Could not create outbound connection to %s:%d"</span>,targethost,newport); -00176 } -00177 } -00178 <span class="keywordflow">return</span> <span class="keyword">false</span>; -00179 } -00180 -00181 -<a name="l00182"></a><a class="code" href="classserverrec.html#a5">00182</a> <span class="keywordtype">bool</span> <a class="code" href="classserverrec.html#a5">serverrec::MeshCookie</a>(<span class="keywordtype">char</span>* targethost, <span class="keywordtype">int</span> newport, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> cookie, <span class="keywordtype">char</span>* servername) -00183 { -00184 <span class="keywordtype">char</span> connect[MAXBUF]; -00185 -00186 <a class="code" href="classircd__connector.html">ircd_connector</a> connector; -00187 -00188 WriteOpers(<span class="stringliteral">"Establishing meshed link to %s:%d"</span>,servername,newport); -00189 -00190 <span class="keywordflow">if</span> (this-><a class="code" href="classconnection.html#o0">fd</a>) -00191 { -00192 <span class="keywordflow">if</span> (connector.<a class="code" href="classircd__connector.html#a1">MakeOutboundConnection</a>(targethost,newport)) -00193 { -00194 <span class="comment">// targethost has been turned into an ip...</span> -00195 <span class="comment">// we dont want this as the server name.</span> -00196 connector.<a class="code" href="classircd__connector.html#a3">SetServerName</a>(servername); -00197 snprintf(connect,MAXBUF,<span class="stringliteral">"- %lu %s :%s"</span>,cookie,getservername().c_str(),getserverdesc().c_str()); -00198 connector.<a class="code" href="classircd__connector.html#a7">SetState</a>(<a class="code" href="connection_8h.html#a4">STATE_NOAUTH_OUTBOUND</a>); -00199 connector.<a class="code" href="classircd__connector.html#a13">SetHostAndPort</a>(targethost, newport); -00200 this-><a class="code" href="classserverrec.html#o11">connectors</a>.push_back(connector); -00201 <span class="keywordflow">return</span> this-><a class="code" href="classserverrec.html#a7">SendPacket</a>(connect, servername); -00202 } -00203 <span class="keywordflow">else</span> -00204 { -00205 connector.<a class="code" href="classircd__connector.html#a7">SetState</a>(<a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>); -00206 WriteOpers(<span class="stringliteral">"Could not create outbound connection to %s:%d"</span>,targethost,newport); -00207 } -00208 } -00209 <span class="keywordflow">return</span> <span class="keyword">false</span>; -00210 } -00211 -<a name="l00212"></a><a class="code" href="classserverrec.html#a10">00212</a> <span class="keywordtype">bool</span> <a class="code" href="classserverrec.html#a10">serverrec::AddIncoming</a>(<span class="keywordtype">int</span> newfd, <span class="keywordtype">char</span>* targethost, <span class="keywordtype">int</span> sourceport) -00213 { -00214 <a class="code" href="classircd__connector.html">ircd_connector</a> connector; -00215 -00216 <span class="comment">// targethost has been turned into an ip...</span> -00217 <span class="comment">// we dont want this as the server name.</span> -00218 connector.<a class="code" href="classircd__connector.html#a3">SetServerName</a>(targethost); -00219 connector.<a class="code" href="classircd__connector.html#a5">SetDescriptor</a>(newfd); -00220 connector.<a class="code" href="classircd__connector.html#a7">SetState</a>(<a class="code" href="connection_8h.html#a3">STATE_NOAUTH_INBOUND</a>); -00221 <span class="keywordtype">int</span> flags = fcntl(newfd, F_GETFL, 0); -00222 fcntl(newfd, F_SETFL, flags | O_NONBLOCK); -00223 <span class="keywordtype">int</span> sendbuf = 32768; -00224 <span class="keywordtype">int</span> recvbuf = 32768; -00225 setsockopt(newfd,SOL_SOCKET,SO_SNDBUF,(<span class="keyword">const</span> <span class="keywordtype">void</span> *)&sendbuf,<span class="keyword">sizeof</span>(sendbuf)); -00226 setsockopt(newfd,SOL_SOCKET,SO_RCVBUF,(<span class="keyword">const</span> <span class="keywordtype">void</span> *)&recvbuf,<span class="keyword">sizeof</span>(sendbuf)); -00227 connector.<a class="code" href="classircd__connector.html#a13">SetHostAndPort</a>(targethost, sourceport); -00228 connector.<a class="code" href="classircd__connector.html#a7">SetState</a>(<a class="code" href="connection_8h.html#a3">STATE_NOAUTH_INBOUND</a>); -00229 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"serverrec::AddIncoming() Added connection: %s:%d"</span>,targethost,sourceport); -00230 this-><a class="code" href="classserverrec.html#o11">connectors</a>.push_back(connector); -00231 <span class="keywordflow">return</span> <span class="keyword">true</span>; -00232 } -00233 -<a name="l00234"></a><a class="code" href="classserverrec.html#a6">00234</a> <span class="keywordtype">void</span> <a class="code" href="classserverrec.html#a6">serverrec::TerminateLink</a>(<span class="keywordtype">char</span>* targethost) -00235 { -00236 <span class="comment">// this locates the targethost in the serverrec::connectors vector of the class,</span> -00237 <span class="comment">// and terminates it by sending it an SQUIT token and closing its descriptor.</span> -00238 <span class="comment">// TerminateLink with a null string causes a terminate of ALL links</span> -00239 } -00240 -00241 <span class="comment">// Returns a pointer to the connector for 'host'</span> -<a name="l00242"></a><a class="code" href="classserverrec.html#a9">00242</a> <a class="code" href="classircd__connector.html">ircd_connector</a>* <a class="code" href="classserverrec.html#a9">serverrec::FindHost</a>(std::string findhost) -00243 { -00244 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < this-><a class="code" href="classserverrec.html#o11">connectors</a>.size(); i++) -00245 { -00246 <span class="keywordflow">if</span> (this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].GetServerName() == findhost) -00247 { -00248 <span class="keywordflow">return</span> &this-><a class="code" href="classserverrec.html#o11">connectors</a>[i]; -00249 } -00250 } -00251 <span class="keywordflow">return</span> NULL; -00252 } -00253 -00254 -00255 <span class="comment">// Checks to see if we can still reach a server at all (e.g. is it in ANY routing table?)</span> -<a name="l00256"></a><a class="code" href="servers_8cpp.html#a5">00256</a> <span class="keywordtype">bool</span> <a class="code" href="servers_8cpp.html#a5">IsRoutable</a>(std::string servername) -00257 { -00258 <span class="keywordtype">int</span> c = 0; -00259 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> x = 0; x < 32; x++) -00260 <span class="keywordflow">if</span> (<a class="code" href="channels_8cpp.html#a34">me</a>[x]) -00261 { -00262 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="channels_8cpp.html#a34">me</a>[x]-><a class="code" href="classserverrec.html#o11">connectors</a>.size(); i++) -00263 { -00264 <span class="keywordflow">if</span> ((<a class="code" href="channels_8cpp.html#a34">me</a>[x]-><a class="code" href="classserverrec.html#o11">connectors</a>[i].GetServerName() == servername) && (<a class="code" href="channels_8cpp.html#a34">me</a>[x]-><a class="code" href="classserverrec.html#o11">connectors</a>[i].GetState() != <a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>)) -00265 { -00266 c++; -00267 } -00268 } -00269 } -00270 <span class="keywordflow">return</span> (c != 0); -00271 } -00272 -00273 -<a name="l00274"></a><a class="code" href="classserverrec.html#a11">00274</a> <span class="keywordtype">void</span> <a class="code" href="classserverrec.html#a11">serverrec::FlushWriteBuffers</a>() -00275 { -00276 <span class="keywordtype">char</span> buffer[MAXBUF]; -00277 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < this-><a class="code" href="classserverrec.html#o11">connectors</a>.size(); i++) -00278 { -00279 <span class="comment">// don't try and ping a NOAUTH_OUTBOUND state, its not authed yet!</span> -00280 <span class="keywordflow">if</span> ((this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].GetState() == <a class="code" href="connection_8h.html#a4">STATE_NOAUTH_OUTBOUND</a>) && (<a class="code" href="channels_8cpp.html#a36">TIME</a> > this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].age+30)) -00281 { -00282 <span class="comment">// however if we reach this timer its connected timed out :)</span> -00283 WriteOpers(<span class="stringliteral">"*** Connection to %s timed out"</span>,this->connectors[i].GetServerName().c_str()); -00284 snprintf(buffer,MAXBUF,<span class="stringliteral">"& %s"</span>,this->connectors[i].GetServerName().c_str()); -00285 NetSendToAllExcept(this->connectors[i].GetServerName().c_str(),buffer); -00286 DoSplit(this->connectors[i].GetServerName().c_str()); -00287 <span class="keywordflow">return</span>; -00288 } -00289 <span class="keywordflow">if</span> ((this->connectors[i].GetState() == <a class="code" href="connection_8h.html#a3">STATE_NOAUTH_INBOUND</a>) && (<a class="code" href="channels_8cpp.html#a36">TIME</a> > this->connectors[i].age+30)) -00290 { -00291 WriteOpers(<span class="stringliteral">"*** Connection from %s timed out"</span>,this->connectors[i].GetServerName().c_str()); -00292 snprintf(buffer,MAXBUF,<span class="stringliteral">"& %s"</span>,this->connectors[i].GetServerName().c_str()); -00293 NetSendToAllExcept(this->connectors[i].GetServerName().c_str(),buffer); -00294 DoSplit(this->connectors[i].GetServerName().c_str()); -00295 <span class="keywordflow">return</span>; -00296 } -00297 <span class="keywordflow">if</span> (this->connectors[i].GetState() != <a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>) -00298 { -00299 <span class="keywordflow">if</span> (!this->connectors[i].CheckPing()) -00300 { -00301 WriteOpers(<span class="stringliteral">"*** Lost single connection to %s: Ping timeout"</span>,this->connectors[i].GetServerName().c_str()); -00302 this->connectors[i].CloseConnection(); -00303 this->connectors[i].SetState(<a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>); -00304 <span class="keywordflow">if</span> (!<a class="code" href="servers_8cpp.html#a5">IsRoutable</a>(this->connectors[i].GetServerName())) -00305 { -00306 WriteOpers(<span class="stringliteral">"*** Server %s is no longer routable, disconnecting."</span>,this->connectors[i].GetServerName().c_str()); -00307 snprintf(buffer,MAXBUF,<span class="stringliteral">"& %s"</span>,this->connectors[i].GetServerName().c_str()); -00308 NetSendToAllExcept(this->connectors[i].GetServerName().c_str(),buffer); -00309 DoSplit(this->connectors[i].GetServerName().c_str()); -00310 } -00311 <a class="code" href="servers_8cpp.html#a3">has_been_netsplit</a> = <span class="keyword">true</span>; -00312 } -00313 } -00314 <span class="keywordflow">if</span> ((this->connectors[i].GetWriteError() !=<span class="stringliteral">""</span>) && (this->connectors[i].GetState() != <a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>)) -00315 { -00316 <span class="comment">// if we're here the write() caused an error, we cannot proceed</span> -00317 WriteOpers(<span class="stringliteral">"*** Lost single connection to %s, link inactive and retrying: %s"</span>,this->connectors[i].GetServerName().c_str(),this->connectors[i].GetWriteError().c_str()); -00318 this->connectors[i].CloseConnection(); -00319 this->connectors[i].SetState(<a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>); -00320 <span class="keywordflow">if</span> (!<a class="code" href="servers_8cpp.html#a5">IsRoutable</a>(this->connectors[i].GetServerName())) -00321 { -00322 WriteOpers(<span class="stringliteral">"*** Server %s is no longer routable, disconnecting."</span>,this->connectors[i].GetServerName().c_str()); -00323 snprintf(buffer,MAXBUF,<span class="stringliteral">"& %s"</span>,this->connectors[i].GetServerName().c_str()); -00324 NetSendToAllExcept(this->connectors[i].GetServerName().c_str(),buffer); -00325 DoSplit(this->connectors[i].GetServerName().c_str()); -00326 } -00327 <a class="code" href="servers_8cpp.html#a3">has_been_netsplit</a> = <span class="keyword">true</span>; -00328 } -00329 <span class="keywordflow">if</span> ((this->connectors[i].HasBufferedOutput()) && (this->connectors[i].GetState() != <a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>)) -00330 { -00331 <span class="keywordflow">if</span> (!this->connectors[i].FlushWriteBuf()) -00332 { -00333 <span class="comment">// if we're here the write() caused an error, we cannot proceed</span> -00334 WriteOpers(<span class="stringliteral">"*** Lost single connection to %s, link inactive and retrying: %s"</span>,this->connectors[i].GetServerName().c_str(),this->connectors[i].GetWriteError().c_str()); -00335 this->connectors[i].CloseConnection(); -00336 this->connectors[i].SetState(<a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>); -00337 <span class="keywordflow">if</span> (!<a class="code" href="servers_8cpp.html#a5">IsRoutable</a>(this->connectors[i].GetServerName())) -00338 { -00339 WriteOpers(<span class="stringliteral">"*** Server %s is no longer routable, disconnecting."</span>,this->connectors[i].GetServerName().c_str()); -00340 snprintf(buffer,MAXBUF,<span class="stringliteral">"& %s"</span>,this->connectors[i].GetServerName().c_str()); -00341 NetSendToAllExcept(this->connectors[i].GetServerName().c_str(),buffer); -00342 DoSplit(this->connectors[i].GetServerName().c_str()); -00343 } -00344 <a class="code" href="servers_8cpp.html#a3">has_been_netsplit</a> = <span class="keyword">true</span>; -00345 } -00346 } -00347 } -00348 } -00349 -<a name="l00350"></a><a class="code" href="classserverrec.html#a7">00350</a> <span class="keywordtype">bool</span> <a class="code" href="classserverrec.html#a7">serverrec::SendPacket</a>(<span class="keywordtype">char</span> *message, <span class="keyword">const</span> <span class="keywordtype">char</span>* sendhost) -00351 { -00352 <span class="keywordflow">if</span> ((!message) || (!sendhost)) -00353 <span class="keywordflow">return</span> <span class="keyword">true</span>; -00354 -00355 <a class="code" href="classircd__connector.html">ircd_connector</a>* cn = this-><a class="code" href="classserverrec.html#a9">FindHost</a>(sendhost); -00356 -00357 <span class="keywordflow">if</span> (!strchr(message,<span class="charliteral">'\n'</span>)) -00358 { -00359 strlcat(message,<span class="stringliteral">"\n"</span>,MAXBUF); -00360 } -00361 -00362 <span class="keywordflow">if</span> (cn) -00363 { -00364 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"main: serverrec::SendPacket() sent '%s' to %s"</span>,message,cn-><a class="code" href="classircd__connector.html#a2">GetServerName</a>().c_str()); -00365 -00366 <span class="keywordflow">if</span> (cn-><a class="code" href="classircd__connector.html#a6">GetState</a>() == <a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>) -00367 { -00368 <span class="comment">// fix: can only route one hop to avoid a loop</span> -00369 <span class="keywordflow">if</span> (strncmp(message,<span class="stringliteral">"R "</span>,2)) -00370 { -00371 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Not a double reroute"</span>); -00372 <span class="comment">// this route is down, we must re-route the packet through an available point in the mesh.</span> -00373 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0; k < this-><a class="code" href="classserverrec.html#o11">connectors</a>.size(); k++) -00374 { -00375 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Check connector %d: %s"</span>,k,this->connectors[k].GetServerName().c_str()); -00376 <span class="comment">// search for another point in the mesh which can 'reach' where we want to go</span> -00377 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> m = 0; m < this-><a class="code" href="classserverrec.html#o11">connectors</a>[k].routes.size(); m++) -00378 { -00379 <span class="keywordflow">if</span> (!strcasecmp(this->connectors[k].routes[m].c_str(),sendhost)) -00380 { -00381 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Found alternative route for packet: %s"</span>,this->connectors[k].GetServerName().c_str()); -00382 <span class="keywordtype">char</span> buffer[MAXBUF]; -00383 snprintf(buffer,MAXBUF,<span class="stringliteral">"R %s %s"</span>,sendhost,message); -00384 this-><a class="code" href="classserverrec.html#a7">SendPacket</a>(buffer,this->connectors[k].GetServerName().c_str()); -00385 <span class="keywordflow">return</span> <span class="keyword">true</span>; -00386 } -00387 } -00388 } -00389 } -00390 <span class="keywordtype">char</span> buffer[MAXBUF]; -00391 snprintf(buffer,MAXBUF,<span class="stringliteral">"& %s"</span>,sendhost); -00392 WriteOpers(<span class="stringliteral">"*** All connections to %s lost."</span>,sendhost); -00393 NetSendToAllExcept(sendhost,buffer); -00394 DoSplit(sendhost); -00395 <span class="keywordflow">return</span> <span class="keyword">false</span>; -00396 } -00397 -00398 <span class="comment">// returns false if the packet could not be sent (e.g. target host down)</span> -00399 <span class="keywordflow">if</span> (!cn-><a class="code" href="classircd__connector.html#a21">AddWriteBuf</a>(message)) -00400 { -00401 <span class="comment">// if we're here, there was an error pending, and the send cannot proceed</span> -00402 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"cn->AddWriteBuf() failed for serverrec::SendPacket(): %s"</span>,cn-><a class="code" href="classircd__connector.html#a24">GetWriteError</a>().c_str()); -00403 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Disabling connector: %s"</span>,cn-><a class="code" href="classircd__connector.html#a2">GetServerName</a>().c_str()); -00404 cn-><a class="code" href="classircd__connector.html#a14">CloseConnection</a>(); -00405 cn-><a class="code" href="classircd__connector.html#a7">SetState</a>(<a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>); -00406 WriteOpers(<span class="stringliteral">"*** Lost single connection to %s, link inactive and retrying: %s"</span>,cn-><a class="code" href="classircd__connector.html#a2">GetServerName</a>().c_str(),cn-><a class="code" href="classircd__connector.html#a24">GetWriteError</a>().c_str()); -00407 <span class="comment">// retry the packet along a new route so either arrival OR failure are gauranteed (bugfix)</span> -00408 <span class="keywordflow">return</span> this-><a class="code" href="classserverrec.html#a7">SendPacket</a>(message,sendhost); -00409 } -00410 <span class="keywordflow">if</span> (!cn-><a class="code" href="classircd__connector.html#a22">FlushWriteBuf</a>()) -00411 { -00412 <span class="comment">// if we're here the write() caused an error, we cannot proceed</span> -00413 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"cn->FlushWriteBuf() failed for serverrec::SendPacket(): %s"</span>,cn-><a class="code" href="classircd__connector.html#a24">GetWriteError</a>().c_str()); -00414 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Disabling connector: %s"</span>,cn-><a class="code" href="classircd__connector.html#a2">GetServerName</a>().c_str()); -00415 cn-><a class="code" href="classircd__connector.html#a14">CloseConnection</a>(); -00416 cn-><a class="code" href="classircd__connector.html#a7">SetState</a>(<a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>); -00417 WriteOpers(<span class="stringliteral">"*** Lost single connection to %s, link inactive and retrying: %s"</span>,cn-><a class="code" href="classircd__connector.html#a2">GetServerName</a>().c_str(),cn-><a class="code" href="classircd__connector.html#a24">GetWriteError</a>().c_str()); -00418 <span class="comment">// retry the packet along a new route so either arrival OR failure are gauranteed</span> -00419 <span class="keywordflow">return</span> this-><a class="code" href="classserverrec.html#a7">SendPacket</a>(message,sendhost); -00420 } -00421 <span class="keywordflow">return</span> <span class="keyword">true</span>; -00422 } -00423 } -00424 -<a name="l00425"></a><a class="code" href="servers_8cpp.html#a6">00425</a> <span class="keywordtype">bool</span> <a class="code" href="servers_8cpp.html#a6">already_have_sum</a>(std::string sum) -00426 { -00427 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="servers_8cpp.html#a4">xsums</a>.size(); i++) -00428 { -00429 <span class="keywordflow">if</span> (<a class="code" href="servers_8cpp.html#a4">xsums</a>[i] == sum) -00430 { -00431 <span class="keywordflow">return</span> <span class="keyword">true</span>; -00432 } -00433 } -00434 <span class="keywordflow">if</span> (<a class="code" href="servers_8cpp.html#a4">xsums</a>.size() >= 128) -00435 { -00436 <a class="code" href="servers_8cpp.html#a4">xsums</a>.pop_front(); -00437 } -00438 <a class="code" href="servers_8cpp.html#a4">xsums</a>.push_back(sum); -00439 <span class="keywordflow">return</span> <span class="keyword">false</span>; -00440 } -00441 -00442 <span class="comment">// receives a packet from any where there is data waiting, first come, first served</span> -00443 <span class="comment">// fills the message and host values with the host where the data came from.</span> -00444 -<a name="l00445"></a><a class="code" href="classserverrec.html#a8">00445</a> <span class="keywordtype">bool</span> <a class="code" href="classserverrec.html#a8">serverrec::RecvPacket</a>(std::deque<std::string> &messages, <span class="keywordtype">char</span>* recvhost,std::deque<std::string> &sums) -00446 { -00447 <span class="keywordtype">char</span> data[65536],buffer[MAXBUF]; -00448 memset(data, 0, 65536); -00449 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < this-><a class="code" href="classserverrec.html#o11">connectors</a>.size(); i++) -00450 { -00451 <span class="keywordflow">if</span> (this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].GetState() != <a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>) -00452 { -00453 <span class="comment">// returns false if the packet could not be sent (e.g. target host down)</span> -00454 <span class="keywordtype">int</span> rcvsize = 0; -00455 -00456 <span class="comment">// check if theres any data on this socket</span> -00457 <span class="comment">// if not, continue onwards to the next.</span> -00458 pollfd polls; -00459 polls.fd = this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].GetDescriptor(); -00460 polls.events = POLLIN; -00461 <span class="keywordtype">int</span> ret = poll(&polls,1,1); -00462 <span class="keywordflow">if</span> (ret <= 0) <span class="keywordflow">continue</span>; -00463 -00464 rcvsize = recv(this->connectors[i].GetDescriptor(),data,65000,0); -00465 data[rcvsize] = <span class="charliteral">'\0'</span>; -00466 <span class="keywordflow">if</span> (rcvsize == 0) -00467 { -00468 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"recv() failed for serverrec::RecvPacket(): EOF"</span>); -00469 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Disabling connector: %s"</span>,this->connectors[i].GetServerName().c_str()); -00470 this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].CloseConnection(); -00471 this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].SetState(<a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>); -00472 <span class="keywordflow">if</span> (!<a class="code" href="servers_8cpp.html#a5">IsRoutable</a>(this->connectors[i].GetServerName())) -00473 { -00474 WriteOpers(<span class="stringliteral">"*** Server %s is no longer routable, disconnecting (EOF)"</span>,this->connectors[i].GetServerName().c_str()); -00475 snprintf(buffer,MAXBUF,<span class="stringliteral">"& %s"</span>,this->connectors[i].GetServerName().c_str()); -00476 NetSendToAllExcept(this->connectors[i].GetServerName().c_str(),buffer); -00477 DoSplit(this->connectors[i].GetServerName().c_str()); -00478 } -00479 <a class="code" href="servers_8cpp.html#a3">has_been_netsplit</a> = <span class="keyword">true</span>; -00480 } -00481 <span class="keywordflow">if</span> (rcvsize == -1) -00482 { -00483 <span class="keywordflow">if</span> (errno != EAGAIN) -00484 { -00485 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"recv() failed for serverrec::RecvPacket(): %s"</span>,strerror(errno)); -00486 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Disabling connector: %s"</span>,this->connectors[i].GetServerName().c_str()); -00487 this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].CloseConnection(); -00488 this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].SetState(<a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>); -00489 <span class="keywordflow">if</span> (!<a class="code" href="servers_8cpp.html#a5">IsRoutable</a>(this->connectors[i].GetServerName())) -00490 { -00491 WriteOpers(<span class="stringliteral">"*** Server %s is no longer routable, disconnecting."</span>,this->connectors[i].GetServerName().c_str()); -00492 snprintf(buffer,MAXBUF,<span class="stringliteral">"& %s"</span>,this->connectors[i].GetServerName().c_str()); -00493 NetSendToAllExcept(this->connectors[i].GetServerName().c_str(),buffer); -00494 DoSplit(this->connectors[i].GetServerName().c_str()); -00495 } -00496 <a class="code" href="servers_8cpp.html#a3">has_been_netsplit</a> = <span class="keyword">true</span>; -00497 } -00498 } -00499 <span class="keywordtype">int</span> pushed = 0; -00500 <span class="keywordflow">if</span> (rcvsize > 0) -00501 { -00502 <span class="keywordflow">if</span> (!this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].AddBuffer(data)) -00503 { -00504 WriteOpers(<span class="stringliteral">"*** Read buffer for %s exceeds maximum, closing connection!"</span>,this->connectors[i].GetServerName().c_str()); -00505 this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].CloseConnection(); -00506 this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].SetState(<a class="code" href="connection_8h.html#a0">STATE_DISCONNECTED</a>); -00507 <span class="keywordflow">if</span> (!<a class="code" href="servers_8cpp.html#a5">IsRoutable</a>(this->connectors[i].GetServerName())) -00508 { -00509 WriteOpers(<span class="stringliteral">"*** Server %s is no longer routable, disconnecting."</span>,this->connectors[i].GetServerName().c_str()); -00510 snprintf(buffer,MAXBUF,<span class="stringliteral">"& %s"</span>,this->connectors[i].GetServerName().c_str()); -00511 NetSendToAllExcept(this->connectors[i].GetServerName().c_str(),buffer); -00512 DoSplit(this->connectors[i].GetServerName().c_str()); -00513 } -00514 <a class="code" href="servers_8cpp.html#a3">has_been_netsplit</a> = <span class="keyword">true</span>; -00515 } -00516 <span class="keywordflow">if</span> (this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].BufferIsComplete()) -00517 { -00518 this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].ResetPing(); -00519 <span class="keywordflow">while</span> (this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].BufferIsComplete()) -00520 { -00521 std::string text = this-><a class="code" href="classserverrec.html#o11">connectors</a>[i].GetBuffer(); -00522 <span class="keywordflow">if</span> (text != <span class="stringliteral">""</span>) -00523 { -00524 <span class="keywordflow">if</span> ((text[0] == <span class="charliteral">':'</span>) && (text.find(<span class="stringliteral">" "</span>) != std::string::npos)) -00525 { -00526 std::string orig = text; -00527 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Original: %s"</span>,text.c_str()); -00528 std::string sum = text.substr(1,text.find(<span class="stringliteral">" "</span>)-1); -00529 text = text.substr(text.find(<span class="stringliteral">" "</span>)+1,text.length()); -00530 std::string possible_token = text.substr(1,text.find(<span class="stringliteral">" "</span>)-1); -00531 <span class="keywordflow">if</span> (possible_token.length() > 1) -00532 { -00533 sums.push_back(<span class="stringliteral">"*"</span>); -00534 text = orig; -00535 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Non-mesh, non-tokenized string passed up the chain"</span>); -00536 } -00537 <span class="keywordflow">else</span> -00538 { -00539 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"Packet sum: '%s'"</span>,sum.c_str()); -00540 <span class="keywordflow">if</span> ((<a class="code" href="servers_8cpp.html#a6">already_have_sum</a>(sum)) && (sum != <span class="stringliteral">"*"</span>)) -00541 { -00542 <span class="comment">// we don't accept dupes</span> -00543 <span class="keywordflow">continue</span>; -00544 } -00545 sums.push_back(sum.c_str()); -00546 } -00547 } -00548 <span class="keywordflow">else</span> sums.push_back(<span class="stringliteral">"*"</span>); -00549 messages.push_back(text.c_str()); -00550 strlcpy(recvhost,this->connectors[i].GetServerName().c_str(),160); -00551 log(<a class="code" href="modules_8h.html#a0">DEBUG</a>,<span class="stringliteral">"serverrec::RecvPacket() %d:%s->%s"</span>,pushed++,recvhost,text.c_str()); -00552 } -00553 } -00554 <span class="keywordflow">return</span> <span class="keyword">true</span>; -00555 } -00556 } -00557 } -00558 } -00559 <span class="comment">// nothing new yet -- message and host will be undefined</span> -00560 <span class="keywordflow">return</span> <span class="keyword">false</span>; -00561 } -00562 -</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon May 30 05:15:21 2005 for InspIRCd by -<a href="http://www.doxygen.org/index.html"> -<img src="doxygen.png" alt="doxygen" align="middle" border=0 > -</a>1.3.3 </small></address> -</body> -</html> |