The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TreeSocket Class Reference

Every SERVER connection inbound or outbound is represented by an object of type TreeSocket. More...

#include <treesocket.h>

Inheritance diagram for TreeSocket:

Inheritance graph
[legend]
Collaboration diagram for TreeSocket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 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)
 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, int newfd, char *ip, Module *HookMod=NULL)
 When a listening socket gives us a new file descriptor, we must associate it with a socket without creating a new connection.
ServerState GetLinkState ()
 Get link state.
const std::stringGetOurChallenge ()
 Get challenge set in our CAPAB for challenge/response.
void SetOurChallenge (const std::string &c)
 Get challenge set in our CAPAB for challenge/response.
const std::stringGetTheirChallenge ()
 Get challenge set in their CAPAB for challenge/response.
void SetTheirChallenge (const std::string &c)
 Get challenge set in their CAPAB for challenge/response.
bool ComparePass (const std::string &ours, const std::string &theirs)
 Compare two passwords based on authentication scheme.
ModuleGetHook ()
 Return the module which we are hooking to for I/O encapsulation.
 ~TreeSocket ()
 Destructor.
std::string RandString (unsigned int length)
 Generate random string used for challenge-response auth.
std::string MakePass (const std::string &password, const std::string &challenge)
 Construct a password, optionally hashed with the other side's challenge string.
virtual bool OnConnected ()
 When an outbound connection finishes connecting, we receive this event, and must send our SERVER string to the other side.
virtual void OnError (BufferedSocketError e)
 Handle socket error event.
void SendError (const std::string &errormessage)
 Sends an error to the remote server, and displays it locally to show that it was sent.
virtual int OnDisconnect ()
 Handle socket disconnect event.
void SendServers (TreeServer *Current, TreeServer *s, int hops)
 Recursively send the server tree with distances as hops.
std::string MyCapabilities ()
 Returns my capabilities as a string.
void SendCapabilities ()
 Send my capabilities to the remote side.
bool HasItem (const std::string &list, const std::string &item)
std::string ListDifference (const std::string &one, const std::string &two)
bool Capab (const std::deque< std::string > &params)
void SquitServer (std::string &from, TreeServer *Current)
 This function forces this server to quit, removing this server and any users on it (and servers and users below that, etc etc).
void Squit (TreeServer *Current, const std::string &reason)
 This is a wrapper function for SquitServer above, which does some validation first and passes on the SQUIT to all other remaining servers.
bool ForceMode (const std::string &source, std::deque< std::string > &params)
 FMODE command - server mode with timestamp checks.
bool ForceTopic (const std::string &source, std::deque< std::string > &params)
 FTOPIC command.
bool ForceJoin (const std::string &source, std::deque< std::string > &params)
 FJOIN, similar to TS6 SJOIN, but not quite.
int DoCollision (User *u, time_t remotets, const std::string &remoteident, const std::string &remoteip, const std::string &remoteuid)
bool ParseUID (const std::string &source, std::deque< std::string > &params)
 UID command.
void SendFJoins (TreeServer *Current, Channel *c)
 Send one or more FJOINs for a channel of users.
void SendXLines (TreeServer *Current)
 Send G, Q, Z and E lines.
void SendChannelModes (TreeServer *Current)
 Send channel modes and topics.
void SendUsers (TreeServer *Current)
 send all users and their oper state/modes
void DoBurst (TreeServer *s)
 This function is called when we want to send a netburst to a local server.
virtual bool OnDataReady ()
 This function is called when we receive data from a remote server.
void WriteLine (std::string line)
 Send one or more complete lines down the socket.
bool Error (std::deque< std::string > &params)
 Handle ERROR command.
bool Motd (const std::string &prefix, std::deque< std::string > &params)
 remote MOTD.
bool Admin (const std::string &prefix, std::deque< std::string > &params)
 remote ADMIN.
bool Modules (const std::string &prefix, std::deque< std::string > &params)
 Remote MODULES.
bool Stats (const std::string &prefix, std::deque< std::string > &params)
bool OperType (const std::string &prefix, std::deque< std::string > &params)
 Because the core won't let users or even SERVERS set +o, we use the OPERTYPE command to do this.
bool ForceNick (const std::string &prefix, std::deque< std::string > &params)
 Because Andy insists that services-compatible servers must implement SVSNICK and SVSJOIN, that's exactly what we do :p.
bool ServerMessage (const std::string &messagetype, const std::string &prefix, std::deque< std::string > &params, const std::string &sourceserv)
 PRIVMSG or NOTICE with server origin ONLY.
bool Encap (const std::string &prefix, std::deque< std::string > &params)
 ENCAP command.
bool OperQuit (const std::string &prefix, std::deque< std::string > &params)
 OPERQUIT command.
bool ServiceJoin (const std::string &prefix, std::deque< std::string > &params)
 SVSJOIN.
bool ServicePart (const std::string &prefix, std::deque< std::string > &params)
 SVSPART.
bool RemoteKill (const std::string &prefix, std::deque< std::string > &params)
 KILL.
bool LocalPong (const std::string &prefix, std::deque< std::string > &params)
 PONG.
bool MetaData (const std::string &prefix, std::deque< std::string > &params)
 METADATA.
bool ServerVersion (const std::string &prefix, std::deque< std::string > &params)
 VERSION.
bool ChangeHost (const std::string &prefix, std::deque< std::string > &params)
 CHGHOST.
bool AddLine (const std::string &prefix, std::deque< std::string > &params)
 ADDLINE.
bool DelLine (const std::string &prefix, std::deque< std::string > &params)
 DELLINE.
bool ChangeName (const std::string &prefix, std::deque< std::string > &params)
 CHGNAME.
bool Whois (const std::string &prefix, std::deque< std::string > &params)
 WHOIS.
bool Push (const std::string &prefix, std::deque< std::string > &params)
 PUSH.
bool Time (const std::string &prefix, std::deque< std::string > &params)
 TIME.
bool LocalPing (const std::string &prefix, std::deque< std::string > &params)
 PING.
bool RemoveStatus (const std::string &prefix, std::deque< std::string > &params)
 Remove all modes from a channel, including statusmodes (+qaovh etc), simplemodes, parameter modes.
bool RemoteServer (const std::string &prefix, std::deque< std::string > &params)
 <- (remote) <- SERVER
bool Outbound_Reply_Server (std::deque< std::string > &params)
 (local) -> SERVER
bool Inbound_Server (std::deque< std::string > &params)
 (local) <- SERVER
void Split (const std::string &line, std::deque< std::string > &n)
 Handle netsplit.
bool ProcessLine (std::string &line)
 Process complete line from buffer.
virtual std::string GetName ()
 Get this server's name.
virtual void OnTimeout ()
 Handle socket timeout from connect().
virtual void OnClose ()
 Handle socket close event.
virtual int OnIncomingConnection (int newsock, char *ip)
 Handle incoming connection event.

Private Attributes

SpanningTreeUtilitiesUtils
std::string myhost
std::string in_buffer
ServerState LinkState
std::string InboundServerName
std::string InboundDescription
std::string InboundSID
int num_lost_users
int num_lost_servers
time_t NextPing
bool LastPingWasGood
unsigned int keylength
std::string ModuleList
std::map< std::string, std::stringCapKeys
ModuleHook
std::string ourchallenge
std::string theirchallenge
std::string OutboundPass
bool sentcapab

Detailed Description

Every SERVER connection inbound or outbound is represented by an object of type TreeSocket.

TreeSockets, being inherited from BufferedSocket, can be tied into the core socket engine, and we cn therefore receive activity events for them, just like activex objects on speed. (yes really, that is a technical term!) Each of these which relates to a locally connected server is assocated with it, by hooking it onto a TreeSocket class using its constructor. In this way, we can maintain a list of servers, some of which are directly connected, some of which are not.

Definition at line 73 of file treesocket.h.


Constructor & Destructor Documentation

TreeSocket::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.

Definition at line 39 of file treesocket1.cpp.

References SpanningTreeUtilities::Creator, Hook, BufferedSocket::host, LinkState, LISTENER, myhost, ourchallenge, theirchallenge, and Utils.

Referenced by OnIncomingConnection().

TreeSocket::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
 

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.

Definition at line 50 of file treesocket1.cpp.

References CONNECTING, SpanningTreeUtilities::Creator, Hook, LinkState, myhost, ourchallenge, theirchallenge, and Utils.

TreeSocket::TreeSocket SpanningTreeUtilities Util,
InspIRCd SI,
int  newfd,
char *  ip,
Module HookMod = NULL
 

When a listening socket gives us a new file descriptor, we must associate it with a socket without creating a new connection.

This constructor is used for this purpose.

Definition at line 65 of file treesocket1.cpp.

References TimerManager::AddTimer(), SpanningTreeUtilities::Creator, Hook, BufferedSocket::Instance, SpanningTreeUtilities::LinkBlocks, LinkState, ourchallenge, sentcapab, theirchallenge, InspIRCd::Timers, Utils, and WAIT_AUTH_1.

TreeSocket::~TreeSocket  ) 
 

Destructor.

Definition at line 91 of file treesocket1.cpp.

References SpanningTreeUtilities::Creator, Hook, and Utils.


Member Function Documentation

bool TreeSocket::AddLine const std::string prefix,
std::deque< std::string > &  params
 

ADDLINE.

Definition at line 23 of file addline.cpp.

References XLineManager::AddLine(), XLineManager::ApplyLines(), TreeServer::bursting, SpanningTreeUtilities::DoOneToAllButSender(), XLine::duration, XLine::expiry, InspIRCd::FindNick(), SpanningTreeUtilities::FindServer(), XLineFactory::Generate(), XLineManager::GetFactory(), TreeServer::GetName(), BufferedSocket::Instance, User::nick, User::server, XLine::SetCreateTime(), InspIRCd::SNO, InspIRCd::Time(), InspIRCd::TimeString(), Utils, SnomaskManager::WriteToSnoMask(), and InspIRCd::XLines.

Referenced by ProcessLine().

bool TreeSocket::Admin const std::string prefix,
std::deque< std::string > &  params
 

remote ADMIN.

leet, huh?

Definition at line 24 of file admin.cpp.

References ServerConfig::AdminEmail, ServerConfig::AdminName, ServerConfig::AdminNick, InspIRCd::Config, SpanningTreeUtilities::DoOneToOne(), InspIRCd::FindNick(), BufferedSocket::Instance, InspIRCd::Match(), User::nick, User::server, ServerConfig::ServerName, and Utils.

Referenced by ProcessLine().

bool TreeSocket::Capab const std::deque< std::string > &  params  ) 
 

Definition at line 135 of file capab.cpp.

References ServerConfig::AllowHalfop, ModeParser::BuildPrefixes(), CapKeys, SpanningTreeUtilities::ChallengeResponse, InspIRCd::Config, CONNECTING, ConvToStr(), ModuleManager::Find(), ServerConfig::GetSID(), irc::tokenstream::GetToken(), BufferedSocket::Instance, LinkState, ListDifference(), InspIRCd::Modes, ModuleList, InspIRCd::Modules, OutboundPass, ProtocolVersion, SendCapabilities(), SendError(), ServerConfig::ServerDesc, SetTheirChallenge(), Utils, and WriteLine().

Referenced by ProcessLine().

bool TreeSocket::ChangeHost const std::string prefix,
std::deque< std::string > &  params
 

CHGHOST.

Definition at line 24 of file fhost.cpp.

References User::ChangeDisplayedHost(), SpanningTreeUtilities::DoOneToAllButSender(), InspIRCd::FindNick(), BufferedSocket::Instance, User::server, and Utils.

Referenced by ProcessLine().

bool TreeSocket::ChangeName const std::string prefix,
std::deque< std::string > &  params
 

CHGNAME.

Definition at line 24 of file fname.cpp.

References User::ChangeName(), SpanningTreeUtilities::DoOneToAllButSender(), InspIRCd::FindNick(), BufferedSocket::Instance, User::server, and Utils.

Referenced by ProcessLine().

bool TreeSocket::ComparePass const std::string ours,
const std::string theirs
 

Compare two passwords based on authentication scheme.

Definition at line 131 of file hmac.cpp.

References SpanningTreeUtilities::ChallengeResponse, ModuleManager::Find(), BufferedSocket::Instance, InspIRCd::Modules, and Utils.

Referenced by Inbound_Server(), and Outbound_Reply_Server().

bool TreeSocket::DelLine const std::string prefix,
std::deque< std::string > &  params
 

DELLINE.

Definition at line 24 of file delline.cpp.

References XLineManager::DelLine(), SpanningTreeUtilities::DoOneToAllButSender(), InspIRCd::FindNick(), SpanningTreeUtilities::FindServer(), TreeServer::GetName(), BufferedSocket::Instance, User::nick, InspIRCd::SNO, Utils, SnomaskManager::WriteToSnoMask(), and InspIRCd::XLines.

Referenced by ProcessLine().

void TreeSocket::DoBurst TreeServer s  ) 
 

This function is called when we want to send a netburst to a local server.

There is a set order we must do this, because for example users require their servers to exist, and channels require their users to exist. You get the idea.

Definition at line 29 of file netburst.cpp.

References InspIRCd::Config, ConvToStr(), SpanningTreeUtilities::Creator, FOREACH_MOD_I, TreeServer::GetName(), ServerConfig::GetSID(), GetTheirChallenge(), InspIRCd::GetVersionString(), I_OnSyncOtherMetaData, BufferedSocket::Instance, SendChannelModes(), SendServers(), SendUsers(), SendXLines(), InspIRCd::SNO, InspIRCd::Time(), SpanningTreeUtilities::TreeRoot, Utils, WriteLine(), and SnomaskManager::WriteToSnoMask().

Referenced by Outbound_Reply_Server(), and ProcessLine().

int TreeSocket::DoCollision User u,
time_t  remotets,
const std::string remoteident,
const std::string remoteip,
const std::string remoteuid
 

Definition at line 30 of file nickcollide.cpp.

References ConvToStr(), InspIRCd::FindUUID(), User::ForceNickChange(), BufferedSocket::Instance, localident, localip, localts, User::uuid, and WriteLine().

Referenced by ParseUID(), and ProcessLine().

bool TreeSocket::Encap const std::string prefix,
std::deque< std::string > &  params
 

ENCAP command.

leet, huh?

Definition at line 26 of file encap.cpp.

References InspIRCd::Config, SpanningTreeUtilities::DoOneToAllButSender(), SpanningTreeUtilities::DoOneToOne(), ServerConfig::GetSID(), BufferedSocket::Instance, InspIRCd::Match(), Event::Send(), and Utils.

Referenced by ProcessLine().

bool TreeSocket::Error std::deque< std::string > &  params  ) 
 

Handle ERROR command.

Definition at line 41 of file treesocket2.cpp.

References InboundServerName, BufferedSocket::Instance, myhost, InspIRCd::SNO, and SnomaskManager::WriteToSnoMask().

Referenced by ProcessLine().

bool TreeSocket::ForceJoin const std::string source,
std::deque< std::string > &  params
 

FJOIN, similar to TS6 SJOIN, but not quite.

Definition at line 25 of file fjoin.cpp.

References classbase::age, SpanningTreeUtilities::AnnounceTSChange, SpanningTreeUtilities::BestRouteTo(), InspIRCd::Config, DEFAULT, SpanningTreeUtilities::DoOneToAllButSender(), InspIRCd::FakeClient, InspIRCd::FindChan(), ModeParser::FindMode(), InspIRCd::FindUUID(), ServerConfig::GetSID(), TreeServer::GetSocket(), irc::modestacker::GetStackedLine(), irc::tokenstream::GetToken(), BufferedSocket::Instance, Channel::JoinUser(), LogManager::Log(), InspIRCd::Logs, InspIRCd::Modes, MODETYPE_CHANNEL, Channel::name, User::nick, irc::modestacker::Push(), RemoveStatus(), SendError(), InspIRCd::SendMode(), User::server, ServerConfig::ServerName, InspIRCd::SNO, SPARSE, InspIRCd::Time(), Utils, Channel::WriteChannelWithServ(), and SnomaskManager::WriteToSnoMask().

Referenced by ProcessLine().

bool TreeSocket::ForceMode const std::string source,
std::deque< std::string > &  params
 

FMODE command - server mode with timestamp checks.

Definition at line 25 of file fmode.cpp.

References classbase::age, InspIRCd::CallCommandHandler(), DEFAULT, SpanningTreeUtilities::DoOneToAllButSender(), InspIRCd::FakeClient, InspIRCd::FindChan(), InspIRCd::FindNick(), BufferedSocket::Instance, LogManager::Log(), InspIRCd::Logs, InspIRCd::SendMode(), User::server, InspIRCd::SNO, Utils, and SnomaskManager::WriteToSnoMask().

Referenced by ProcessLine().

bool TreeSocket::ForceNick const std::string prefix,
std::deque< std::string > &  params
 

Because Andy insists that services-compatible servers must implement SVSNICK and SVSJOIN, that's exactly what we do :p.

Definition at line 32 of file svsnick.cpp.

References classbase::age, SpanningTreeUtilities::DoOneToAllButSender(), InspIRCd::FindNick(), User::ForceNickChange(), BufferedSocket::Instance, IS_LOCAL, UserManager::QuitUser(), InspIRCd::Users, Utils, and User::uuid.

Referenced by ProcessLine().

bool TreeSocket::ForceTopic const std::string source,
std::deque< std::string > &  params
 

FTOPIC command.

Definition at line 25 of file ftopic.cpp.

References InspIRCd::Config, SpanningTreeUtilities::DoOneToAllButSender(), InspIRCd::FindChan(), InspIRCd::FindNick(), BufferedSocket::Instance, ServerConfig::Limits, ServerLimits::MaxTopic, Channel::name, ServerConfig::ServerName, Channel::setby, Channel::topic, Channel::topicset, Utils, Channel::WriteChannel(), and Channel::WriteChannelWithServ().

Referenced by ProcessLine().

Module * TreeSocket::GetHook  ) 
 

Return the module which we are hooking to for I/O encapsulation.

Definition at line 86 of file treesocket1.cpp.

References Hook.

Referenced by HandshakeTimer::Tick().

ServerState TreeSocket::GetLinkState  ) 
 

Get link state.

Definition at line 81 of file treesocket1.cpp.

References LinkState.

std::string TreeSocket::GetName  )  [virtual]
 

Get this server's name.

Definition at line 628 of file treesocket2.cpp.

References InboundServerName, and myhost.

Referenced by ProcessLine().

const std::string & TreeSocket::GetOurChallenge  ) 
 

Get challenge set in our CAPAB for challenge/response.

Definition at line 33 of file hmac.cpp.

References ourchallenge.

Referenced by SendCapabilities().

const std::string & TreeSocket::GetTheirChallenge  ) 
 

Get challenge set in their CAPAB for challenge/response.

Definition at line 43 of file hmac.cpp.

References theirchallenge.

Referenced by DoBurst(), Inbound_Server(), and Outbound_Reply_Server().

bool TreeSocket::HasItem const std::string list,
const std::string item
 

Definition at line 105 of file capab.cpp.

References irc::sepstream::GetToken().

Referenced by ListDifference().

bool TreeSocket::Inbound_Server std::deque< std::string > &  params  ) 
 

(local) <- SERVER

Definition at line 186 of file modules/m_spanningtree/server.cpp.

References ComparePass(), InspIRCd::Config, SpanningTreeUtilities::Creator, DEBUG, SpanningTreeUtilities::FindServer(), SpanningTreeUtilities::FindServerID(), TreeServer::GetID(), TreeServer::GetName(), TreeServer::GetParent(), ServerConfig::GetSID(), GetTheirChallenge(), InboundDescription, InboundServerName, InboundSID, BufferedSocket::Instance, SpanningTreeUtilities::LinkBlocks, LinkState, LogManager::Log(), InspIRCd::Logs, SendCapabilities(), SendError(), sentcapab, ServerConfig::ServerDesc, InspIRCd::SNO, Utils, WAIT_AUTH_2, WriteLine(), and SnomaskManager::WriteToSnoMask().

Referenced by ProcessLine().

std::string TreeSocket::ListDifference const std::string one,
const std::string two
 

Definition at line 119 of file capab.cpp.

References irc::sepstream::GetToken(), and HasItem().

Referenced by Capab().

bool TreeSocket::LocalPing const std::string prefix,
std::deque< std::string > &  params
 

PING.

Definition at line 29 of file ping.cpp.

References SpanningTreeUtilities::DoOneToOne(), Utils, and WriteLine().

Referenced by ProcessLine().

bool TreeSocket::LocalPong const std::string prefix,
std::deque< std::string > &  params
 

PONG.

Definition at line 29 of file pong.cpp.

References InspIRCd::Config, SpanningTreeUtilities::DoOneToOne(), InspIRCd::FindNick(), SpanningTreeUtilities::FindServer(), ServerConfig::GetSID(), BufferedSocket::Instance, TreeServer::LastPingMsec, TreeServer::rtt, ServerConfig::ServerName, TreeServer::SetPingFlag(), Utils, and User::WriteServ().

Referenced by ProcessLine().

std::string TreeSocket::MakePass const std::string