1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "commands/cmd_whois.h"
16 #include "commands/cmd_stats.h"
20 #include "transport.h"
21 #include "socketengine.h"
23 #include "m_spanningtree/main.h"
24 #include "m_spanningtree/utils.h"
25 #include "m_spanningtree/treeserver.h"
26 #include "m_spanningtree/link.h"
27 #include "m_spanningtree/treesocket.h"
28 #include "m_spanningtree/resolvers.h"
29 #include "m_spanningtree/handshaketimer.h"
31 /* $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 */
33 static std::map<std::string, std::string> warned; /* Server names that have had protocol violation warnings displayed for them */
35 int TreeSocket::WriteLine(std::string line)
37 Instance->Log(DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
39 return this->Write(line);
43 /* Handle ERROR command */
44 bool TreeSocket::Error(std::deque<std::string> ¶ms)
46 if (params.size() < 1)
48 this->Instance->SNO->WriteToSnoMask('l',"ERROR from %s: %s",(!InboundServerName.empty() ? InboundServerName.c_str() : myhost.c_str()),params[0].c_str());
49 /* we will return false to cause the socket to close. */
53 /** TODO: This creates a total mess of output and needs to really use irc::modestacker.
55 bool TreeSocket::RemoveStatus(const std::string &prefix, std::deque<std::string> ¶ms)
57 if (params.size() < 1)
59 Channel* c = Instance->FindChan(params[0]);
62 for (char modeletter = 'A'; modeletter <= 'z'; modeletter++)
64 ModeHandler* mh = Instance->Modes->FindMode(modeletter, MODETYPE_CHANNEL);
72 bool TreeSocket::RemoteServer(const std::string &prefix, std::deque<std::string> ¶ms)
74 if (params.size() < 5)
76 SendError("Protocol error - Missing SID");
80 std::string servername = params[0];
81 std::string password = params[1];
82 // hopcount is not used for a remote server, we calculate this ourselves
83 std::string sid = params[3];
84 std::string description = params[4];
85 TreeServer* ParentOfThis = Utils->FindServer(prefix);
88 this->SendError("Protocol error - Introduced remote server from unknown server "+prefix);
91 if (!this->Instance->IsSID(sid))
93 this->SendError("Invalid format server ID: "+sid+"!");
96 TreeServer* CheckDupe = Utils->FindServer(servername);
99 this->SendError("Server "+servername+" already exists!");
100 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, already exists. Closing link with " + prefix);
104 Link* lnk = Utils->FindLink(servername);
106 TreeServer *Node = new TreeServer(this->Utils, this->Instance, servername, description, sid, ParentOfThis,NULL, lnk ? lnk->Hidden : false);
108 if (Node->DuplicateID())
110 this->SendError("Server ID "+sid+" already exists on the network!");
111 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, server ID already exists on the network. Closing link with " + prefix);
115 ParentOfThis->AddChild(Node);
116 params[4] = ":" + params[4];
117 Utils->DoOneToAllButSender(prefix,"SERVER",params,prefix);
118 this->Instance->SNO->WriteToSnoMask('l',"Server \002"+prefix+"\002 introduced server \002"+servername+"\002 ("+description+")");
122 bool TreeSocket::ComparePass(const std::string &ours, const std::string &theirs)
124 if ((!strncmp(ours.c_str(), "HMAC-SHA256:", 12)) || (!strncmp(theirs.c_str(), "HMAC-SHA256:", 12)))
126 /* One or both of us specified hmac sha256, but we don't have sha256 module loaded!
127 * We can't allow this password as valid.
129 if (!Instance->Modules->Find("m_sha256.so") || !Utils->ChallengeResponse)
132 /* Straight string compare of hashes */
133 return ours == theirs;
136 /* Straight string compare of plaintext */
137 return ours == theirs;
140 bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> ¶ms)
142 if (params.size() < 5)
144 SendError("Protocol error - Missing SID");
148 irc::string servername = params[0].c_str();
149 std::string sname = params[0];
150 std::string password = params[1];
151 std::string sid = params[3];
152 std::string description = params[4];
153 int hops = atoi(params[2].c_str());
155 this->InboundServerName = sname;
156 this->InboundDescription = description;
157 this->InboundSID = sid;
160 this->SendCapabilities();
164 this->SendError("Server too far away for authentication");
165 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
169 if (!this->Instance->IsSID(sid))
171 this->SendError("Invalid format server ID: "+sid+"!");
175 for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
177 if ((x->Name == servername) && ((ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password)) || (x->RecvPass == password && (this->GetTheirChallenge().empty()))))
179 TreeServer* CheckDupe = Utils->FindServer(sname);
182 this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!");
183 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName());
186 // Begin the sync here. this kickstarts the
187 // other side, waiting in WAIT_AUTH_2 state,
188 // into starting their burst, as it shows
190 this->LinkState = CONNECTED;
191 // we should add the details of this server now
192 // to the servers tree, as a child of the root
195 TreeServer *Node = new TreeServer(this->Utils, this->Instance, sname, description, sid, Utils->TreeRoot, this, x->Hidden);
197 if (Node->DuplicateID())
199 this->SendError("Server ID "+sid+" already exists on the network!");
200 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+assign(servername)+"\2 being introduced denied, server ID already exists on the network. Closing link.");
204 Utils->TreeRoot->AddChild(Node);
205 params[4] = ":" + params[4];
206 Utils->DoOneToAllButSender(Instance->Config->GetSID(),"SERVER",params,sname);
207 Node->bursting = true;
212 this->SendError("Invalid credentials");
213 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials");
217 bool TreeSocket::Inbound_Server(std::deque<std::string> ¶ms)
219 if (params.size() < 5)
221 SendError("Protocol error - Missing SID");
225 irc::string servername = params[0].c_str();
226 std::string sname = params[0];
227 std::string password = params[1];
228 std::string sid = params[3];
229 std::string description = params[4];
230 int hops = atoi(params[2].c_str());
232 this->InboundServerName = sname;
233 this->InboundDescription = description;
234 this->InboundSID = sid;
237 this->SendCapabilities();
241 this->SendError("Server too far away for authentication");
242 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
246 if (!this->Instance->IsSID(sid))
248 this->SendError("Invalid format server ID: "+sid+"!");
252 for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
254 if ((x->Name == servername) && ((ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password) || x->RecvPass == password && (this->GetTheirChallenge().empty()))))
256 /* Check for fully initialized instances of the server by id */
257 Instance->Log(DEBUG,"Looking for dupe SID %s", sid.c_str());
258 TreeServer* CheckDupeSID = Utils->FindServerID(sid);
261 this->SendError("Server ID "+CheckDupeSID->GetID()+" already exists on server "+CheckDupeSID->GetName()+"!");
262 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupeSID->GetID()+
263 "' already exists on server "+CheckDupeSID->GetName());
266 /* Now check for fully initialized instances of the server by name */
267 TreeServer* CheckDupe = Utils->FindServer(sname);
270 this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!");
271 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName());
274 this->Instance->SNO->WriteToSnoMask('l',"Verified incoming server connection from \002"+sname+"\002["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] ("+description+")");
277 std::string name = BufferedSocketNameRequest((Module*)Utils->Creator, this->Hook).Send();
278 this->Instance->SNO->WriteToSnoMask('l',"Connection from \2"+sname+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] using transport \2"+name+"\2");
281 // this is good. Send our details: Our server name and description and hopcount of 0,
282 // along with the sendpass from this block.
283 this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+Instance->Config->GetSID()+" :"+this->Instance->Config->ServerDesc);
284 // move to the next state, we are now waiting for THEM.
285 this->LinkState = WAIT_AUTH_2;
289 this->SendError("Invalid credentials");
290 this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials");
294 void TreeSocket::Split(const std::string &line, std::deque<std::string> &n)
297 irc::tokenstream tokens(line);
299 while (tokens.GetToken(param))
306 bool TreeSocket::ProcessLine(std::string &line)
308 std::deque<std::string> params;
312 line = line.substr(0, line.find_first_of("\r\n"));
317 Instance->Log(DEBUG, "S[%d] I %s", this->GetFd(), line.c_str());
319 this->Split(line.c_str(),params);
324 if ((params[0][0] == ':') && (params.size() > 1))
326 prefix = params[0].substr(1);
331 this->SendError("BUG (?) Empty prefix recieved.");
336 command = params[0].c_str();
339 switch (this->LinkState)
346 * Waiting for SERVER command from remote server. Server initiating
347 * the connection sends the first SERVER command, listening server
348 * replies with theirs if its happy, then if the initiator is happy,
349 * it starts to send its net sync, which starts the merge, otherwise
352 if (command == "PASS")
355 * Ignore this silently. Some services packages insist on sending PASS, even
356 * when it is not required (i.e. by us). We have to ignore this here, otherwise
357 * as it's an unknown command (effectively), it will cause the connection to be
358 * closed, which probably isn't what people want. -- w00t
361 else if (command == "SERVER")
363 return this->Inbound_Server(params);
365 else if (command == "ERROR")
367 return this->Error(params);
369 else if (command == "USER")
371 this->SendError("Client connections to this port are prohibited.");
374 else if (command == "CAPAB")
376 return this->Capab(params);
381 irc::string error = "Invalid command in negotiation phase: " + command;
382 this->SendError(assign(error));
389 * We have sent SERVER to the other side of the connection. Now we're waiting for them to start BURST.
390 * The other option at this stage of things, of course, is for them to close our connection thanks
391 * to invalid credentials.. -- w
393 if (command == "SERVER")
396 * Connection is either attempting to re-auth itself (stupid) or sending netburst without sending BURST.
397 * Both of these aren't allowable, so block them here. -- w
399 this->SendError("You may not re-authenticate or commence netburst without sending BURST.");
402 else if (command == "BURST")
404 if (params.size() && Utils->EnableTimeSync)
406 bool we_have_delta = (Instance->Time(false) != Instance->Time(true));
407 time_t them = atoi(params[0].c_str());
408 time_t delta = them - Instance->Time(false);
409 if ((delta < -600) || (delta > 600))
411 Instance->SNO->WriteToSnoMask('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs(delta));
412 SendError("Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!");
415 else if ((delta < -30) || (delta > 30))
417 Instance->SNO->WriteToSnoMask('l',"\2WARNING\2: Your clocks are out by %d seconds. Please consider synching your clocks.", abs(delta));
420 if (!Utils->MasterTime && !we_have_delta)
422 this->Instance->SetTimeDelta(delta);
423 // Send this new timestamp to any other servers
424 Utils->DoOneToMany(Instance->Config->GetSID(), "TIMESET", params);
427 this->LinkState = CONNECTED;
428 Link* lnk = Utils->FindLink(InboundServerName);
430 Node = new TreeServer(this->Utils, this->Instance, InboundServerName, InboundDescription, InboundSID, Utils->TreeRoot, this, lnk ? lnk->Hidden : false);
432 if (Node->DuplicateID())
434 this->SendError("Server ID "+InboundSID+" already exists on the network!");
435 this->Instance->SNO->WriteToSnoMask('l',"Server \2"+InboundServerName+"\2 being introduced from \2" + prefix + "\2 denied, server ID already exists on the network. Closing link.");
439 Utils->TreeRoot->AddChild(Node);
441 params.push_back(InboundServerName);
442 params.push_back("*");
443 params.push_back("1");
444 params.push_back(InboundSID);
445 params.push_back(":"+InboundDescription);
446 Utils->DoOneToAllButSender(Instance->Config->GetSID(),"SERVER",params,InboundServerName);
447 Node->bursting = true;
450 else if (command == "ERROR")
452 return this->Error(params);
454 else if (command == "CAPAB")
456 return this->Capab(params);
462 * This really shouldn't happen.
464 this->SendError("Internal error -- listening socket accepted its own descriptor!!!");
470 * We're connecting (OUTGOING) to another server. They are in state WAIT_AUTH_1 until they verify
471 * our credentials, when they proceed into WAIT_AUTH_2 and send SERVER to us. We then send BURST
472 * + our netburst, which will put them into CONNECTED state. -- w
474 if (command == "SERVER")
476 // Our credentials have been accepted, send netburst. (this puts US into the CONNECTED state)
477 return this->Outbound_Reply_Server(params);
479 else if (command == "ERROR")
481 return this->Error(params);
483 else if (command == "CAPAB")
485 return this->Capab(params);
491 * Credentials have been exchanged, we've gotten their 'BURST' (or sent ours).
492 * Anything from here on should be accepted a little more reasonably.
497 * Check for fake direction here, and drop any instances that are found.
498 * What is fake direction? Imagine the following server setup:
499 * 0AA <-> 0AB <-> 0AC
500 * Fake direction would be 0AC sending a message to 0AB claiming to be from
501 * 0AA, or something similar. Basically, a message taking a path that *cannot*
504 * When would this be seen?
505 * Well, hopefully never. It could be caused by race conditions, bugs, or
506 * "miscreant" servers, though, so let's check anyway. -- w
508 std::string direction = prefix;
510 User *t = this->Instance->FindUUID(prefix);
513 direction = t->server;
516 TreeServer* route_back_again = Utils->BestRouteTo(direction);
517 if ((!route_back_again) || (route_back_again->GetSocket() != this))
519 if (route_back_again)
520 Instance->Log(DEBUG,"Protocol violation: Fake direction in command '%s' from connection '%s'",line.c_str(),this->GetName().c_str());
524 * When there is activity on the socket, reset the ping counter so
525 * that we're not wasting bandwidth pinging an active server.
527 route_back_again->SetNextPingTime(time(NULL) + Utils->PingFreq);
528 route_back_again->SetPingFlag();
533 * Empty prefix from a server to server link:
534 * This is somewhat bad/naughty, so let's set the prefix
535 * to be the link that we got it from, so we don't break anything. -- w
537 TreeServer* n = Utils->FindServer(GetName());
545 * First up, check for any malformed commands (e.g. MODE without a timestamp)
546 * and rewrite commands where necessary (SVSMODE -> MODE for services). -- w
548 if (command == "MODE")
550 if (params.size() >= 2)
552 Channel* channel = Instance->FindChan(params[0]);
555 User* x = Instance->FindNick(prefix);
558 if (warned.find(x->server) == warned.end())
560 Instance->Log(DEFAULT,"WARNING: I revceived modes '%s' from another server '%s'. This is not compliant with InspIRCd. Please check that server for bugs.", params[1].c_str(), x->server);
561 Instance->SNO->WriteToSnoMask('d', "WARNING: The server %s is sending nonstandard modes: '%s MODE %s' where FMODE should be used, and may cause desyncs.", x->server, x->nick, params[1].c_str());
562 warned[x->server] = x->nick;
568 else if (command == "SVSMODE")
575 * Now, check for (and parse) commands as appropriate. -- w
578 /* Find the server that this command originated from, used in the handlers below */
579 TreeServer *ServerSource = Utils->FindServer(prefix);
581 /* Find the link we just got this from so we don't bounce it back incorrectly */
582 std::string sourceserv = this->myhost;
583 if (!this->InboundServerName.empty())
585 sourceserv = this->InboundServerName;
589 * XXX one of these days, this needs to be moved into class Commands.
591 if (command == "UID")
593 return this->ParseUID(prefix, params);
595 else if (command == "FJOIN")
597 return this->ForceJoin(prefix,params);
599 else if (command == "STATS")
601 return this->Stats(prefix, params);
603 else if (command == "MOTD")
605 return this->Motd(prefix, params);
607 else if (command == "KILL" && ServerSource)
609 // Kill from a server
610 return this->RemoteKill(prefix,params);
612 else if (command == "MODULES")
614 return this->Modules(prefix, params);
616 else if (command == "ADMIN")
618 return this->Admin(prefix, params);
620 else if (command == "SERVER")
622 return this->RemoteServer(prefix,params);
624 else if (command == "ERROR")
626 return this->Error(params);
628 else if (command == "OPERTYPE")
630 return this->OperType(prefix,params);
632 else if (command == "FMODE")
634 return this->ForceMode(prefix,params);
636 else if (command == "FTOPIC")
638 return this->ForceTopic(prefix,params);
640 else if (command == "REHASH")
642 return this->RemoteRehash(prefix,params);
644 else if (command == "METADATA")
646 return this->MetaData(prefix,params);
648 else if (command == "REMSTATUS")
650 return this->RemoveStatus(prefix,params);
652 else if (command == "PING")
654 return this->LocalPing(prefix,params);
656 else if (command == "PONG")
658 return this->LocalPong(prefix,params);
660 else if (command == "VERSION")
662 return this->ServerVersion(prefix,params);
664 else if (command == "FHOST")
666 return this->ChangeHost(prefix,params);
668 else if (command == "FNAME")
670 return this->ChangeName(prefix,params);
672 else if (command == "ADDLINE")
674 return this->AddLine(prefix,params);
676 else if (command == "DELLINE")
678 return this->DelLine(prefix,params);
680 else if (command == "SVSNICK")
682 return this->ForceNick(prefix,params);
684 else if (command == "OPERQUIT")
686 return this->OperQuit(prefix,params);
688 else if (command == "IDLE")
690 return this->Whois(prefix,params);
692 else if (command == "PUSH")
694 return this->Push(prefix,params);
696 else if (command == "TIMESET")
698 return this->HandleSetTime(prefix, params);
700 else if (command == "TIME")
702 return this->Time(prefix,params);
704 else if ((command == "KICK") && (Utils->IsServer(prefix)))
706 if (params.size() == 3)
708 User* user = this->Instance->FindNick(params[1]);
709 Channel* chan = this->Instance->FindChan(params[0]);
712 if (!chan->ServerKickUser(user, params[2].c_str(), false))
713 /* Yikes, the channels gone! */
718 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
720 else if (command == "SVSJOIN")
722 return this->ServiceJoin(prefix,params);
724 else if (command == "SVSPART")
726 return this->ServicePart(prefix,params);
728 else if (command == "SQUIT")
730 if (params.size() == 2)
732 this->Squit(Utils->FindServer(params[0]),params[1]);
736 else if (command == "OPERNOTICE")
738 if (params.size() >= 1)
739 Instance->SNO->WriteToSnoMask('A', "From " + prefix + ": " + params[0]);
740 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
742 else if (command == "MODENOTICE")
744 if (params.size() >= 2)
746 Instance->Users->WriteMode(params[0].c_str(), WM_AND, "*** From %s: %s", prefix.c_str(), params[1].c_str());
748 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
750 else if (command == "SNONOTICE")
752 if (params.size() >= 2)
754 Instance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + prefix + ": "+ params[1]);
756 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
758 else if (command == "BURST")
760 // Set prefix server as bursting
763 this->Instance->SNO->WriteToSnoMask('l', "WTF: Got BURST from a nonexistant server(?): %s", prefix.c_str());
767 ServerSource->bursting = true;
768 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
770 else if (command == "ENDBURST")
774 this->Instance->SNO->WriteToSnoMask('l', "WTF: Got ENDBURST from a nonexistant server(?): %s", prefix.c_str());
778 ServerSource->FinishBurst();
779 return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
781 else if (command == "MODE")
783 // Server-prefix MODE.
784 const char* modelist[MAXPARAMETERS];
785 for (size_t i = 0; i < params.size(); i++)
786 modelist[i] = params[i].c_str();
788 // Insert into the parser
789 this->Instance->SendMode(modelist, params.size(), this->Instance->FakeClient);
791 // Pass out to the network
792 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
797 * Not a special s2s command. Emulate the user doing it.
798 * This saves us having a huge ugly command parser again.
800 User *who = this->Instance->FindUUID(prefix);
804 // this looks ugly because command is an irc::string
805 this->SendError("Command (" + std::string(command.c_str()) + ") from unknown prefix (" + prefix + ")! Dropping link.");
809 if (command == "NICK")
811 if (params.size() != 2)
813 SendError("Protocol violation: NICK message without TS - :"+std::string(who->uuid)+" NICK "+params[0]);
816 /* Update timestamp on user when they change nicks */
817 who->age = atoi(params[1].c_str());
820 * On nick messages, check that the nick doesnt already exist here.
821 * If it does, perform collision logic.
823 User* x = this->Instance->FindNickOnly(params[0]);
824 if ((x) && (x != who))
827 /* x is local, who is remote */
828 collideret = this->DoCollision(x, who->age, who->ident, who->GetIPString(), who->uuid);
832 * Remote client lost, or both lost, parsing this nickchange would be
833 * pointless, as the incoming client's server will soon recieve SVSNICK to
834 * change its nick to its UID. :) -- w00t
842 const char* strparams[127];
843 for (unsigned int q = 0; q < params.size(); q++)
845 strparams[q] = params[q].c_str();
848 switch (this->Instance->CallCommandHandler(command.c_str(), strparams, params.size(), who))
851 // command is irc::string, hence ugliness
852 this->SendError("Unrecognised or malformed command '" + std::string(command.c_str()) + "' -- possibly loaded mismatched modules");
856 * CMD_LOCALONLY is aliased to CMD_FAILURE, so this won't go out onto the network.
862 /* CMD_SUCCESS and CMD_USER_DELETED fall through here */
866 return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
870 break; // end of state CONNECTED (phew).
875 std::string TreeSocket::GetName()
877 std::string sourceserv = this->myhost;
878 if (!this->InboundServerName.empty())
880 sourceserv = this->InboundServerName;
885 void TreeSocket::OnTimeout()
887 if (this->LinkState == CONNECTING)
889 Utils->Creator->RemoteMessage(NULL, "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
890 Link* MyLink = Utils->FindLink(myhost);
892 Utils->DoFailOver(MyLink);
896 void TreeSocket::OnClose()
898 // Test fix for big fuckup
899 if (this->LinkState != CONNECTED)
902 // Connection closed.
903 // If the connection is fully up (state CONNECTED)
904 // then propogate a netsplit to all peers.
905 std::string quitserver = this->myhost;
906 if (!this->InboundServerName.empty())
908 quitserver = this->InboundServerName;
910 TreeServer* s = Utils->FindServer(quitserver);
913 Squit(s,"Remote host closed the connection");
916 if (!quitserver.empty())
918 Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' failed.",quitserver.c_str());
919 time_t server_uptime = Instance->Time() - this->age;
921 Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
925 int TreeSocket::OnIncomingConnection(int newsock, char* ip)
927 /* To prevent anyone from attempting to flood opers/DDoS by connecting to the server port,
928 * or discovering if this port is the server port, we don't allow connections from any
929 * IPs for which we don't have a link block.
933 found = (std::find(Utils->ValidIPs.begin(), Utils->ValidIPs.end(), ip) != Utils->ValidIPs.end());
936 for (std::vector<std::string>::iterator i = Utils->ValidIPs.begin(); i != Utils->ValidIPs.end(); i++)
937 if (irc::sockets::MatchCIDR(ip, (*i).c_str()))
942 Utils->Creator->RemoteMessage(NULL,"Server connection from %s denied (no link blocks with that IP address)", ip);
943 Instance->SE->Close(newsock);
948 TreeSocket* s = new TreeSocket(this->Utils, this->Instance, newsock, ip, this->Hook);
949 s = s; /* Whinge whinge whinge, thats all GCC ever does. */