/** Allows modules to synchronize data which relates to users during a netburst.
* When this function is called, it will be called from the module which implements
- * the linking protocol. This currently is m_spanningtree.so. A pointer to this module
- * is given in Module* proto, so that you may call its methods such as ProtoSendMode
- * (see below). This function will be called for every user visible on your side
- * of the burst, allowing you to for example set modes, etc. Do not use this call to
- * synchronize data which you have stored using class Extensible -- There is a specialist
- * function OnSyncUserMetaData and OnSyncChannelMetaData for this!
+ * the linking protocol. This currently is m_spanningtree.so.
+ * This function will be called for every user visible on your side
+ * of the burst, allowing you to for example set modes, etc.
* @param user The user being syncronized
- * @param proto A pointer to the module handling network protocol
- * @param opaque An opaque pointer set by the protocol module, should not be modified!
+ * @param server The target of the burst
*/
- virtual void OnSyncUser(User* user, Module* proto, void* opaque);
+ virtual void OnSyncUser(User* user, ProtocolServer& server);
/** Allows modules to synchronize data which relates to channels during a netburst.
* When this function is called, it will be called from the module which implements
- * the linking protocol. This currently is m_spanningtree.so. A pointer to this module
- * is given in Module* proto, so that you may call its methods such as ProtoSendMode
- * (see below). This function will be called for every user visible on your side
- * of the burst, allowing you to for example set modes, etc.
+ * the linking protocol. This currently is m_spanningtree.so.
+ * This function will be called for every channel visible on your side of the burst,
+ * allowing you to for example set modes, etc.
*
* @param chan The channel being syncronized
- * @param proto A pointer to the module handling network protocol
- * @param opaque An opaque pointer set by the protocol module, should not be modified!
+ * @param server The target of the burst
*/
- virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque);
+ virtual void OnSyncChannel(Channel* chan, ProtocolServer& server);
- /* Allows modules to syncronize metadata not related to users or channels, over the network during a netburst.
- * Whenever the linking module wants to send out data, but doesnt know what the data
- * represents (e.g. it is Extensible metadata, added to a User or Channel by a module) then
- * this method is called. You should use the ProtoSendMetaData function after you've
- * correctly decided how the data should be represented, to send the metadata on its way if
- * if it belongs to your module.
- * @param proto A pointer to the module handling network protocol
- * @param opaque An opaque pointer set by the protocol module, should not be modified!
- * @param displayable If this value is true, the data is going to be displayed to a user,
- * and not sent across the network. Use this to determine wether or not to show sensitive data.
+ /** Allows modules to syncronize metadata not related to users or channels, over the network during a netburst.
+ * When the linking module has finished sending all data it wanted to send during a netburst, then
+ * this method is called. You should use the SendMetaData() function after you've
+ * correctly decided how the data should be represented, to send the data.
+ * @param server The target of the burst
*/
- virtual void OnSyncNetwork(Module* proto, void* opaque);
+ virtual void OnSyncNetwork(ProtocolServer& server);
/** Allows module data, sent via ProtoSendMetaData, to be decoded again by a receiving module.
* Please see src/modules/m_swhois.cpp for a working example of how to use this method call.
*/
virtual void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata);
- /** Implemented by modules which provide the ability to link servers.
- * These modules will implement this method, which allows metadata (extra data added to
- * user and channel records using class Extensible, Extensible::Extend, etc) to be sent
- * to other servers on a netburst and decoded at the other end by the same module on a
- * different server.
- *
- * More documentation to follow soon. Please see src/modules/m_swhois.cpp for example of
- * how to use this function.
- * @param opaque An opaque pointer set by the protocol module, should not be modified!
- * @param target The Channel* or User* that metadata should be sent for
- * @param extname The extension name to send metadata for
- * @param extdata Encoded data for this extension name, which will be encoded at the oppsite end by an identical module using OnDecodeMetaData
- */
- virtual void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata);
-
/** Called whenever a user's hostname is changed.
* This event triggers after the host has been set.
* @param user The user whos host is being changed
typedef std::vector<std::string> parameterlist;
+class ProtocolServer
+{
+ public:
+ /** Send metadata related to this server to the target server
+ * @param key The 'key' of the data
+ * @param data The string representation of the data
+ */
+ virtual void SendMetaData(const std::string& key, const std::string& data) = 0;
+};
+
class CoreExport ProtocolInterface
{
public:
+ typedef ProtocolServer Server;
+
class ServerInfo
{
public:
class Membership;
class Module;
class OperInfo;
+class ProtocolServer;
class RemoteUser;
class ServerConfig;
class ServerLimits;
void Module::OnUserInvite(User*, User*, Channel*, time_t) { DetachEvent(I_OnUserInvite); }
void Module::OnPostTopicChange(User*, Channel*, const std::string&) { DetachEvent(I_OnPostTopicChange); }
void Module::OnGetServerDescription(const std::string&, std::string&) { DetachEvent(I_OnGetServerDescription); }
-void Module::OnSyncUser(User*, Module*, void*) { DetachEvent(I_OnSyncUser); }
-void Module::OnSyncChannel(Channel*, Module*, void*) { DetachEvent(I_OnSyncChannel); }
-void Module::OnSyncNetwork(Module*, void*) { DetachEvent(I_OnSyncNetwork); }
+void Module::OnSyncUser(User*, ProtocolInterface::Server&) { DetachEvent(I_OnSyncUser); }
+void Module::OnSyncChannel(Channel*, ProtocolInterface::Server&) { DetachEvent(I_OnSyncChannel); }
+void Module::OnSyncNetwork(ProtocolInterface::Server&) { DetachEvent(I_OnSyncNetwork); }
void Module::OnDecodeMetaData(Extensible*, const std::string&, const std::string&) { DetachEvent(I_OnDecodeMetaData); }
-void Module::ProtoSendMetaData(void*, Extensible*, const std::string&, const std::string&) { }
void Module::OnChangeHost(User*, const std::string&) { DetachEvent(I_OnChangeHost); }
void Module::OnChangeName(User*, const std::string&) { DetachEvent(I_OnChangeName); }
void Module::OnChangeIdent(User*, const std::string&) { DetachEvent(I_OnChangeIdent); }
Version GetVersion() CXX11_OVERRIDE;
std::string EncodeFilter(FilterResult* filter);
FilterResult DecodeFilter(const std::string &data);
- void OnSyncNetwork(Module* proto, void* opaque) CXX11_OVERRIDE;
+ void OnSyncNetwork(ProtocolInterface::Server& server) CXX11_OVERRIDE;
void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata) CXX11_OVERRIDE;
ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE;
ModResult OnPreCommand(std::string &command, std::vector<std::string> ¶meters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE;
return res;
}
-void ModuleFilter::OnSyncNetwork(Module* proto, void* opaque)
+void ModuleFilter::OnSyncNetwork(ProtocolInterface::Server& server)
{
for (std::vector<ImplFilter>::iterator i = filters.begin(); i != filters.end(); ++i)
{
- proto->ProtoSendMetaData(opaque, NULL, "filter", EncodeFilter(&(*i)));
+ server.SendMetaData("filter", EncodeFilter(&(*i)));
}
}
return MOD_RES_PASSTHRU;
}
-void ModuleSpanningTree::ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata)
-{
- TreeSocket* s = static_cast<TreeSocket*>(opaque);
- User* u = dynamic_cast<User*>(target);
- Channel* c = dynamic_cast<Channel*>(target);
- if (u)
- s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+u->uuid+" "+extname+" :"+extdata);
- else if (c)
- s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA "+c->name+" "+ConvToStr(c->age)+" "+extname+" :"+extdata);
- else if (!target)
- s->WriteLine(":"+ServerInstance->Config->GetSID()+" METADATA * "+extname+" :"+extdata);
-}
-
CullResult ModuleSpanningTree::cull()
{
if (Utils)
void OnDelLine(User *u, XLine *x) CXX11_OVERRIDE;
ModResult OnStats(char statschar, User* user, string_list &results) CXX11_OVERRIDE;
ModResult OnSetAway(User* user, const std::string &awaymsg) CXX11_OVERRIDE;
- void ProtoSendMetaData(void* opaque, Extensible* target, const std::string &extname, const std::string &extdata);
void OnLoadModule(Module* mod) CXX11_OVERRIDE;
void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE;
#include "treeserver.h"
#include "main.h"
#include "commands.h"
+#include "protocolinterface.h"
/**
* Creates FMODE messages, used only when syncing channels
}
};
+struct TreeSocket::BurstState
+{
+ SpanningTreeProtocolInterface::Server server;
+ BurstState(TreeSocket* sock) : server(sock) { }
+};
+
/** 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
this->WriteLine(":" + ServerInstance->Config->GetSID() + " VERSION :"+ServerInstance->GetVersionString());
/* Send server tree */
this->SendServers(Utils->TreeRoot, s);
+
+ BurstState bs(this);
/* Send users and their oper status */
- this->SendUsers();
+ this->SendUsers(bs);
for (chan_hash::const_iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); ++i)
- SyncChannel(i->second);
+ SyncChannel(i->second, bs);
this->SendXLines();
- FOREACH_MOD(OnSyncNetwork, (Utils->Creator,(void*)this));
+ FOREACH_MOD(OnSyncNetwork, (bs.server));
this->WriteLine(":" + ServerInstance->Config->GetSID() + " ENDBURST");
ServerInstance->SNO->WriteToSnoMask('l',"Finished bursting to \2"+ s->GetName()+"\2.");
}
}
/** Send channel topic, modes and metadata */
-void TreeSocket::SyncChannel(Channel* chan)
+void TreeSocket::SyncChannel(Channel* chan, BurstState& bs)
{
SendFJoins(chan);
ExtensionItem* item = i->first;
std::string value = item->serialize(FORMAT_NETWORK, chan, i->second);
if (!value.empty())
- Utils->Creator->ProtoSendMetaData(this, chan, item->name, value);
+ this->WriteLine(CommandMetadata::Builder(chan, item->name, value));
}
- FOREACH_MOD(OnSyncChannel, (chan, Utils->Creator, this));
+ FOREACH_MOD(OnSyncChannel, (chan, bs.server));
+}
+
+void TreeSocket::SyncChannel(Channel* chan)
+{
+ BurstState bs(this);
+ SyncChannel(chan, bs);
}
/** send all users and their oper state/modes */
-void TreeSocket::SendUsers()
+void TreeSocket::SendUsers(BurstState& bs)
{
+ ProtocolInterface::Server& piserver = bs.server;
for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
{
User* user = u->second;
ExtensionItem* item = i->first;
std::string value = item->serialize(FORMAT_NETWORK, u->second, i->second);
if (!value.empty())
- Utils->Creator->ProtoSendMetaData(this, u->second, item->name, value);
+ this->WriteLine(CommandMetadata::Builder(user, item->name, value));
}
- FOREACH_MOD(OnSyncUser, (user, Utils->Creator, this));
+ FOREACH_MOD(OnSyncUser, (user, piserver));
}
}
CommandMetadata::Builder(key, data).Broadcast();
}
+void SpanningTreeProtocolInterface::Server::SendMetaData(const std::string& key, const std::string& data)
+{
+ sock->WriteLine(CommandMetadata::Builder(key, data));
+}
+
void SpanningTreeProtocolInterface::SendTopic(Channel* channel, std::string &topic)
{
CommandFTopic::Builder(ServerInstance->FakeClient, channel).Broadcast();
class SpanningTreeProtocolInterface : public ProtocolInterface
{
public:
+ class Server : public ProtocolInterface::Server
+ {
+ TreeSocket* const sock;
+
+ public:
+ Server(TreeSocket* s) : sock(s) { }
+ void SendMetaData(const std::string& key, const std::string& data) CXX11_OVERRIDE;
+ };
+
bool SendEncapsulatedData(const parameterlist &encap);
void SendMetaData(User* user, const std::string& key, const std::string& data) CXX11_OVERRIDE;
void SendMetaData(Channel* chan, const std::string& key, const std::string& data) CXX11_OVERRIDE;
*/
class TreeSocket : public BufferedSocket
{
+ class BurstState;
+
std::string linkID; /* Description for this link */
ServerState LinkState; /* Link state */
CapabData* capab; /* Link setup data (held until burst is sent) */
*/
void SendListModes(Channel* chan);
+ /** Send all known information about a channel */
+ void SyncChannel(Channel* chan, BurstState& bs);
+
+ /** Send all users and their oper state, away state and metadata */
+ void SendUsers(BurstState& bs);
+
public:
const time_t age;
/** Send all known information about a channel */
void SyncChannel(Channel* chan);
- /** send all users and their oper state/modes */
- void SendUsers();
-
/** 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