From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: kostja@tarantool.org, vdavydov.dev@gmail.com Subject: [PATCH v4 12/12] [RAW] swim: allow to use broadcast tasks to send pings Date: Thu, 31 Jan 2019 00:28:30 +0300 [thread overview] Message-ID: <2f45977773923cf233ad2b51bed1de5f8d09d98e.1548883137.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1548883137.git.v.shpilevoy@tarantool.org> In-Reply-To: <cover.1548883137.git.v.shpilevoy@tarantool.org> Part of #3234 --- src/lib/swim/swim.c | 15 +++++++++++++++ src/lib/swim/swim.h | 7 +++++++ src/lua/swim.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c index b377f154f..f67acc5b3 100644 --- a/src/lib/swim/swim.c +++ b/src/lib/swim/swim.c @@ -1626,6 +1626,21 @@ swim_probe_member(struct swim *swim, const char *uri) return 0; } +int +swim_broadcast(struct swim *swim, int port) +{ + const char *msg_pref = "swim.broadcast:"; + if (swim_check_is_configured(swim, msg_pref) != 0) + return -1; + if (port < 0) + port = ntohs(swim->self->addr.sin_port); + struct swim_bcast_task *t = swim_bcast_task_new(port); + if (t == NULL) + return -1; + swim_send_ping(swim, &t->base, &t->base.dst, NULL); + return 0; +} + void swim_info(struct swim *swim, struct info_handler *info) { diff --git a/src/lib/swim/swim.h b/src/lib/swim/swim.h index 24f3a4b33..8f30d58d0 100644 --- a/src/lib/swim/swim.h +++ b/src/lib/swim/swim.h @@ -93,6 +93,13 @@ swim_remove_member(struct swim *swim, const struct tt_uuid *uuid); int swim_probe_member(struct swim *swim, const char *uri); +/** + * Broadcast a ping to all interfaces on a specified port. If a + * port is < 0, then a port of the SWIM instance is used. + */ +int +swim_broadcast(struct swim *swim, int port); + /** Dump member statuses into @a info. */ void swim_info(struct swim *swim, struct info_handler *info); diff --git a/src/lua/swim.c b/src/lua/swim.c index 7df4e5c85..1be8e7595 100644 --- a/src/lua/swim.c +++ b/src/lua/swim.c @@ -403,6 +403,44 @@ lua_swim_quit(struct lua_State *L) return 0; } +/** + * Broadcast a ping over all network interfaces with a speicifed + * port. Port is optional and in a case of absence it is set to + * a port of the current instance. The Lua stack should contain a + * SWIM instance to broadcast from, and optionally a port. + * @param L Lua state. + * @retval 1 True. + * @retval 2 Nil and an error object. On invalid Lua parameters + * and OOM it throws. + */ +static int +lua_swim_broadcast(struct lua_State *L) +{ + struct swim *swim = lua_swim_ptr(L, 1); + if (swim == NULL) + return luaL_error(L, "Usage: swim:broadcast([port])"); + int port = -1; + if (lua_gettop(L) > 1) { + if (! lua_isnumber(L, 2)) { + return luaL_error(L, "swim.broadcast: port should be "\ + "a number"); + } + double dport = lua_tonumber(L, 2); + port = dport; + if (dport != (double) port) { + return luaL_error(L, "swim.broadcast: port should be "\ + "an integer"); + } + } + if (swim_broadcast(swim, port) != 0) { + lua_pushnil(L); + luaT_pusherror(L, diag_last_error(diag_get())); + return 2; + } + lua_pushboolean(L, true); + return 1; +} + void tarantool_lua_swim_init(struct lua_State *L) { @@ -415,6 +453,7 @@ tarantool_lua_swim_init(struct lua_State *L) {"info", lua_swim_info}, {"probe_member", lua_swim_probe_member}, {"quit", lua_swim_quit}, + {"broadcast", lua_swim_broadcast}, {NULL, NULL} }; luaL_register_module(L, "swim", lua_swim_methods); -- 2.17.2 (Apple Git-113)
next prev parent reply other threads:[~2019-01-30 21:28 UTC|newest] Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-01-30 21:28 [PATCH v4 00/12] SWIM draft Vladislav Shpilevoy 2019-01-30 21:28 ` [PATCH v4 01/12] sio: introduce sio_uri_to_addr Vladislav Shpilevoy 2019-02-15 13:21 ` [tarantool-patches] " Konstantin Osipov 2019-02-15 21:22 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-30 21:28 ` [PATCH v4 10/12] [RAW] swim: introduce 'quit' message Vladislav Shpilevoy 2019-02-21 12:13 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-30 21:28 ` [PATCH v4 11/12] [RAW] swim: introduce broadcast tasks Vladislav Shpilevoy 2019-01-30 21:28 ` Vladislav Shpilevoy [this message] 2019-01-30 21:28 ` [PATCH v4 02/12] evio: expose evio_setsockopt_server function Vladislav Shpilevoy 2019-02-15 13:21 ` [tarantool-patches] " Konstantin Osipov 2019-02-15 21:22 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-30 21:28 ` [PATCH v4 03/12] rlist: introduce rlist_add_tail_entry_sorted Vladislav Shpilevoy 2019-02-15 13:26 ` [tarantool-patches] " Konstantin Osipov 2019-02-15 13:34 ` [tarantool-patches] " Vladislav Shpilevoy 2019-02-15 18:07 ` Konstantin Osipov 2019-01-30 21:28 ` [PATCH v4 04/12] [RAW] swim: introduce SWIM's anti-entropy component Vladislav Shpilevoy 2019-02-21 18:35 ` [tarantool-patches] " Konstantin Osipov 2019-02-26 18:28 ` [tarantool-patches] " Vladislav Shpilevoy 2019-01-30 21:28 ` [PATCH v4 05/12] [RAW] swim: introduce failure detection component Vladislav Shpilevoy 2019-01-30 21:28 ` [PATCH v4 06/12] [RAW] swim: introduce dissemination component Vladislav Shpilevoy 2019-01-30 21:28 ` [PATCH v4 07/12] [RAW] swim: keep encoded round message cached Vladislav Shpilevoy 2019-01-30 21:28 ` [PATCH v4 08/12] [RAW] swim: introduce payload Vladislav Shpilevoy 2019-01-30 21:28 ` [PATCH v4 09/12] [RAW] swim: introduce routing Vladislav Shpilevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=2f45977773923cf233ad2b51bed1de5f8d09d98e.1548883137.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [PATCH v4 12/12] [RAW] swim: allow to use broadcast tasks to send pings' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox