diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/anope.h | 7 | ||||
| -rw-r--r-- | include/config.h | 4 | ||||
| -rw-r--r-- | include/dns.h | 4 | ||||
| -rw-r--r-- | include/extern.h | 16 | ||||
| -rw-r--r-- | include/modules.h | 12 | ||||
| -rw-r--r-- | include/services.h | 13 | ||||
| -rw-r--r-- | include/sockets.h | 56 |
7 files changed, 73 insertions, 39 deletions
diff --git a/include/anope.h b/include/anope.h index 0e25bbb93..83f45d39b 100644 --- a/include/anope.h +++ b/include/anope.h @@ -368,7 +368,12 @@ namespace Anope */ extern CoreExport string printf(const char *fmt, ...); - /** Return the last error, uses errno/GetLastError() to determin this + /** Return the last error code + * @return The error code + */ + extern CoreExport int LastErrorCode(); + + /** Return the last error, uses errno/GetLastError() to determine this * @return An error message */ extern CoreExport const Anope::string LastError(); diff --git a/include/config.h b/include/config.h index b06aa60d8..07815466e 100644 --- a/include/config.h +++ b/include/config.h @@ -345,7 +345,7 @@ class CoreExport ServerConfig /* Host to connect to **/ Anope::string LocalHost; /* List of uplink servers to try and connect to */ - std::list<Uplink *> Uplinks; + std::vector<Uplink *> Uplinks; /* Our server name */ Anope::string ServerName; @@ -453,8 +453,6 @@ class CoreExport ServerConfig Anope::string BotModes; /* THe actual modes */ ChannelStatus BotModeList; - /* How many times to try and reconnect to the uplink before giving up */ - unsigned MaxRetries; /* How long to wait between connection attempts */ int RetryWait; /* If services should hide unprivileged commands */ diff --git a/include/dns.h b/include/dns.h index 6e79603d7..cb6d6b5c7 100644 --- a/include/dns.h +++ b/include/dns.h @@ -152,6 +152,10 @@ class DNSSocket : public ConnectionSocket bool ProcessRead(); bool ProcessWrite(); + + void OnConnect(); + + void OnError(const Anope::string &error); }; /** DNS manager, manages the connection and all requests diff --git a/include/extern.h b/include/extern.h index 0b319ceaf..7774c104f 100644 --- a/include/extern.h +++ b/include/extern.h @@ -85,7 +85,6 @@ E void introduce_user(const Anope::string &user); E bool GetCommandLineArgument(const Anope::string &name, char shortname = 0); E bool GetCommandLineArgument(const Anope::string &name, char shortname, Anope::string ¶m); E void Init(int ac, char **av); -E Uplink *uplink_server; /**** ircd.c ****/ E void pmodule_ircd_proto(IRCDProto *); @@ -114,27 +113,16 @@ E bool noexpire; E bool protocoldebug; E bool quitting; -E bool shutting_down; +E bool restarting; E Anope::string quitmsg; E bool save_data; E time_t start_time; E ConnectionSocket *UplinkSock; +E int CurrentUplink; E void save_databases(); E void sighandler(int signum); -E void do_restart_services(); - -/* The socket to our uplink */ -class CoreExport UplinkSocket : public ConnectionSocket -{ - public: - UplinkSocket(bool ipv6 = false); - - virtual ~UplinkSocket(); - - bool Read(const Anope::string &buf); -}; /**** messages.cpp ****/ diff --git a/include/modules.h b/include/modules.h index d24348b48..ff0c576a0 100644 --- a/include/modules.h +++ b/include/modules.h @@ -481,12 +481,9 @@ class CoreExport Module : public Extensible */ virtual void OnChanExpire(ChannelInfo *ci) { } - /** Called before Anope connects to its uplink - * @param u The uplink we're going to connect to - * @param Number What number the uplink is - * @return Other than EVENT_CONTINUE to stop attempting to connect + /** Called before Anope connecs to its uplink */ - virtual EventReturn OnPreServerConnect(Uplink *u, int Number) { return EVENT_CONTINUE; } + virtual void OnPreServerConnect() { } /** Called when Anope connects to its uplink */ @@ -1079,7 +1076,7 @@ enum Implementation I_OnModuleLoad, I_OnModuleUnload, /* Other */ - I_OnReload, I_OnPreServerConnect, I_OnNewServer, I_OnServerConnect, I_OnPreUplinkSync, I_OnServerDisconnect, I_OnPreCommandRun, + I_OnReload, I_OnNewServer, I_OnPreServerConnect, I_OnServerConnect, I_OnPreUplinkSync, I_OnServerDisconnect, I_OnPreCommandRun, I_OnPreCommand, I_OnPostCommand, I_OnRestart, I_OnShutdown, I_OnSignal, I_OnServerQuit, I_OnTopicUpdated, I_OnEncrypt, I_OnDecrypt, @@ -1205,8 +1202,7 @@ class CoreExport ModuleManager */ static void ClearCallBacks(Module *m); - /** Unloading all modules, NEVER call this when Anope isn't shutting down. - * Ever. + /** Unloading all modules except the protocol module. */ static void UnloadAll(); diff --git a/include/services.h b/include/services.h index 896f7bf83..f329f99ef 100644 --- a/include/services.h +++ b/include/services.h @@ -937,6 +937,19 @@ struct Uplink bool ipv6; Uplink(const Anope::string &_host, int _port, const Anope::string &_password, bool _ipv6) : host(_host), port(_port), password(_password), ipv6(_ipv6) { } + bool operator==(const Uplink &other) const + { + if (this->host != other.host) + return false; + if (this->port != other.port) + return false; + if (this->password != other.password) + return false; + if (this->ipv6 != other.ipv6) + return false; + return true; + } + inline bool operator!=(const Uplink &other) const { return !(*this == other); } }; /** A class to process numbered lists (passed to most DEL/LIST/VIEW commands). diff --git a/include/sockets.h b/include/sockets.h index bc0c831bf..eca2635e8 100644 --- a/include/sockets.h +++ b/include/sockets.h @@ -137,27 +137,34 @@ class CoreExport SocketIO * @param sz How much to read * @return Number of bytes received */ - virtual int Recv(Socket *s, char *buf, size_t sz) const; + virtual int Recv(Socket *s, char *buf, size_t sz); /** Write something to the socket * @param s The socket * @param buf What to write * @return Number of bytes written */ - virtual int Send(Socket *s, const Anope::string &buf) const; + virtual int Send(Socket *s, const Anope::string &buf); /** Accept a connection from a socket * @param s The socket + * @return The new socket + */ + virtual ClientSocket *Accept(ListenSocket *s); + + /** Bind a socket + * @param s The socket + * @param ip The IP to bind to + * @param port The optional port to bind to */ - virtual void Accept(ListenSocket *s); + virtual void Bind(Socket *s, const Anope::string &ip, int port = 0); /** Connect the socket * @param s THe socket * @param target IP to connect to * @param port to connect to - * @param bindip IP to bind to, if any */ - virtual void Connect(ConnectionSocket *s, const Anope::string &target, int port, const Anope::string &bindip = ""); + virtual void Connect(ConnectionSocket *s, const Anope::string &target, int port); /** Called when the socket is destructing */ @@ -173,6 +180,9 @@ class CoreExport Socket : public Flags<SocketFlag, 2> bool IPv6; public: + /* Sockaddrs for bind() (if it's bound) */ + sockaddrs bindaddr; + /* I/O functions used for this socket */ SocketIO *IO; @@ -214,6 +224,12 @@ class CoreExport Socket : public Flags<SocketFlag, 2> */ bool SetNonBlocking(); + /** Bind the socket to an ip and port + * @param ip The ip + * @param port The port + */ + void Bind(const Anope::string &ip, int port = 0); + /** Called when there is something to be received for this socket * @return true on success, false to drop this socket */ @@ -291,10 +307,6 @@ class CoreExport BufferedSocket : public Socket class CoreExport ListenSocket : public Socket { - protected: - /* Sockaddrs for bindip/port */ - sockaddrs listenaddrs; - public: /** Constructor * @param bindip The IP to bind to @@ -323,10 +335,10 @@ class CoreExport ListenSocket : public Socket class CoreExport ConnectionSocket : public BufferedSocket { public: - /* Sockaddrs for bindip (if there is one) */ - sockaddrs bindaddr; /* Sockaddrs for connection ip/port */ sockaddrs conaddr; + /* True if connected */ + bool connected; /** Constructor * @param ipv6 true to use IPv6 @@ -337,9 +349,27 @@ class CoreExport ConnectionSocket : public BufferedSocket /** Connect the socket * @param TargetHost The target host to connect to * @param Port The target port to connect to - * @param BindHost The host to bind to for connecting */ - void Connect(const Anope::string &TargetHost, int Port, const Anope::string &BindHost = ""); + void Connect(const Anope::string &TargetHost, int Port); + + /** Called when the socket is ready to be written to + * @return true on success, false to drop this socket + */ + bool ProcessWrite(); + + /** Called when there is an error for this socket + * @return true on success, false to drop this socket + */ + void ProcessError(); + + /** Called on a successful connect + */ + virtual void OnConnect(); + + /** Called when a connection is not successful + * @param error The error + */ + virtual void OnError(const Anope::string &error); }; class CoreExport ClientSocket : public BufferedSocket |
