Permalink
Browse files

problem: missing support for GOSSIP UNPUBLISH command

  • Loading branch information...
wesyoung committed Oct 4, 2018
1 parent 00fe5fa commit 7af3a8a5755721f52864b868529e1f027883b761
View
@@ -139,6 +139,10 @@ void
void
zyre_gossip_connect_curve (zyre_t *self, const char *public_key, const char *format, ...);
// Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
void
zyre_gossip_unpublish (zyre_t *self, const char *node);
// Start node, after setting header values. When you start a node it
// begins discovery and connection. Returns 0 if OK, -1 if it wasn't
// possible to start the node.
View
@@ -156,6 +156,11 @@
<argument name = "format" type = "format" />
</method>
<method name = "gossip unpublish" state = "draft">
Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
<argument name = "node" type = "string" />
</method>
<method name = "start">
Start node, after setting header values. When you start a node it
begins discovery and connection. Returns 0 if OK, -1 if it wasn't
@@ -170,6 +170,14 @@ Java_org_zeromq_zyre_Zyre__1_1gossipConnectCurve (JNIEnv *env, jclass c, jlong s
(*env)->ReleaseStringUTFChars (env, format, format_);
}
JNIEXPORT void JNICALL
Java_org_zeromq_zyre_Zyre__1_1gossipUnpublish (JNIEnv *env, jclass c, jlong self, jstring node)
{
char *node_ = (char *) (*env)->GetStringUTFChars (env, node, NULL);
zyre_gossip_unpublish ((zyre_t *) (intptr_t) self, node_);
(*env)->ReleaseStringUTFChars (env, node, node_);
}
JNIEXPORT jint JNICALL
Java_org_zeromq_zyre_Zyre__1_1start (JNIEnv *env, jclass c, jlong self)
{
@@ -210,6 +210,13 @@ public void gossipConnectCurve (String publicKey, String format) {
__gossipConnectCurve (self, publicKey, format);
}
/*
Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
*/
native static void __gossipUnpublish (long self, String node);
public void gossipUnpublish (String node) {
__gossipUnpublish (self, node);
}
/*
Start node, after setting header values. When you start a node it
begins discovery and connection. Returns 0 if OK, -1 if it wasn't
possible to start the node.
@@ -151,6 +151,10 @@ void
void
zyre_gossip_connect_curve (zyre_t *self, const char *public_key, const char *format, ...);
// Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
void
zyre_gossip_unpublish (zyre_t *self, const char *node);
// Start node, after setting header values. When you start a node it
// begins discovery and connection. Returns 0 if OK, -1 if it wasn't
// possible to start the node.
@@ -209,6 +209,12 @@ nothing my_zyre.gossipConnectCurve (String, String)
Set-up gossip discovery with CURVE enabled.
```
nothing my_zyre.gossipUnpublish (String)
```
Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
```
integer my_zyre.start ()
```
View
@@ -52,6 +52,7 @@ NAN_MODULE_INIT (Zyre::Init) {
Nan::SetPrototypeMethod (tpl, "gossipBind", _gossip_bind);
Nan::SetPrototypeMethod (tpl, "gossipConnect", _gossip_connect);
Nan::SetPrototypeMethod (tpl, "gossipConnectCurve", _gossip_connect_curve);
Nan::SetPrototypeMethod (tpl, "gossipUnpublish", _gossip_unpublish);
Nan::SetPrototypeMethod (tpl, "start", _start);
Nan::SetPrototypeMethod (tpl, "stop", _stop);
Nan::SetPrototypeMethod (tpl, "join", _join);
@@ -396,6 +397,21 @@ NAN_METHOD (Zyre::_gossip_connect_curve) {
zyre_gossip_connect_curve (zyre->self, (const char *)public_key, "%s", format);
}
NAN_METHOD (Zyre::_gossip_unpublish) {
Zyre *zyre = Nan::ObjectWrap::Unwrap <Zyre> (info.Holder ());
char *node;
if (info [0]->IsUndefined ())
return Nan::ThrowTypeError ("method requires a `node`");
else
if (!info [0]->IsString ())
return Nan::ThrowTypeError ("`node` must be a string");
//else { // bjornw: remove brackets to keep scope
Nan::Utf8String node_utf8 (info [0].As<String>());
node = *node_utf8;
//} //bjornw end
zyre_gossip_unpublish (zyre->self, (const char *)node);
}
NAN_METHOD (Zyre::_start) {
Zyre *zyre = Nan::ObjectWrap::Unwrap <Zyre> (info.Holder ());
int result = zyre_start (zyre->self);
@@ -61,6 +61,7 @@ class Zyre: public Nan::ObjectWrap {
static NAN_METHOD (_gossip_bind);
static NAN_METHOD (_gossip_connect);
static NAN_METHOD (_gossip_connect_curve);
static NAN_METHOD (_gossip_unpublish);
static NAN_METHOD (_start);
static NAN_METHOD (_stop);
static NAN_METHOD (_join);
@@ -108,6 +108,8 @@ class zyre_event_t(Structure):
lib.zyre_gossip_connect.argtypes = [zyre_p, c_char_p]
lib.zyre_gossip_connect_curve.restype = None
lib.zyre_gossip_connect_curve.argtypes = [zyre_p, c_char_p, c_char_p]
lib.zyre_gossip_unpublish.restype = None
lib.zyre_gossip_unpublish.argtypes = [zyre_p, c_char_p]
lib.zyre_start.restype = c_int
lib.zyre_start.argtypes = [zyre_p]
lib.zyre_stop.restype = None
@@ -350,6 +352,12 @@ def gossip_connect_curve(self, public_key, format, *args):
"""
return lib.zyre_gossip_connect_curve(self._as_parameter_, public_key, format, *args)
def gossip_unpublish(self, node):
"""
Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
"""
return lib.zyre_gossip_unpublish(self._as_parameter_, node)
def start(self):
"""
Start node, after setting header values. When you start a node it
@@ -176,6 +176,12 @@ def gossip_connect_curve(self, public_key, format, ):
"""
utils.lib.zyre_gossip_connect_curve(self._p, utils.to_bytes(public_key), format, )
def gossip_unpublish(self, node):
"""
Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
"""
utils.lib.zyre_gossip_unpublish(self._p, utils.to_bytes(node))
def start(self):
"""
Start node, after setting header values. When you start a node it
@@ -4218,6 +4218,10 @@
void
zyre_gossip_connect_curve (zyre_t *self, const char *public_key, const char *format, ...);
// Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
void
zyre_gossip_unpublish (zyre_t *self, const char *node);
// Start node, after setting header values. When you start a node it
// begins discovery and connection. Returns 0 if OK, -1 if it wasn't
// possible to start the node.
@@ -157,6 +157,12 @@ void QmlZyre::gossipConnectCurve (const QString &publicKey, const QString &forma
zyre_gossip_connect_curve (self, publicKey.toUtf8().data(), "%s", format.toUtf8().data());
};
///
// Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
void QmlZyre::gossipUnpublish (const QString &node) {
zyre_gossip_unpublish (self, node.toUtf8().data());
};
///
// Start node, after setting header values. When you start a node it
// begins discovery and connection. Returns 0 if OK, -1 if it wasn't
@@ -120,6 +120,9 @@ public slots:
// Set-up gossip discovery with CURVE enabled.
void gossipConnectCurve (const QString &publicKey, const QString &format);
// Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
void gossipUnpublish (const QString &node);
// Start node, after setting header values. When you start a node it
// begins discovery and connection. Returns 0 if OK, -1 if it wasn't
// possible to start the node.
@@ -220,6 +220,14 @@ void QZyre::gossipConnectCurve (const QString &publicKey, const QString &param)
}
///
// Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
void QZyre::gossipUnpublish (const QString &node)
{
zyre_gossip_unpublish (self, node.toUtf8().data());
}
///
// Start node, after setting header values. When you start a node it
// begins discovery and connection. Returns 0 if OK, -1 if it wasn't
@@ -74,6 +74,7 @@ def self.attach_function(name, *rest)
attach_function :zyre_gossip_bind, [:pointer, :string, :varargs], :void, **opts
attach_function :zyre_gossip_connect, [:pointer, :string, :varargs], :void, **opts
attach_function :zyre_gossip_connect_curve, [:pointer, :string, :string, :varargs], :void, **opts
attach_function :zyre_gossip_unpublish, [:pointer, :string], :void, **opts
attach_function :zyre_start, [:pointer], :int, **opts
attach_function :zyre_stop, [:pointer], :void, **opts
attach_function :zyre_join, [:pointer, :string], :int, **opts
@@ -348,6 +348,17 @@ def gossip_connect_curve(public_key, format, *args)
result
end
# Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
#
# @param node [String, #to_s, nil]
# @return [void]
def gossip_unpublish(node)
raise DestroyedError unless @ptr
self_p = @ptr
result = ::Zyre::FFI.zyre_gossip_unpublish(self_p, node)
result
end
# Start node, after setting header values. When you start a node it
# begins discovery and connection. Returns 0 if OK, -1 if it wasn't
# possible to start the node.
View
@@ -254,6 +254,11 @@ ZYRE_EXPORT void
ZYRE_EXPORT void
zyre_gossip_connect_curve (zyre_t *self, const char *public_key, const char *format, ...) CHECK_PRINTF (3);
// *** Draft method, for development use, may change without warning ***
// Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
ZYRE_EXPORT void
zyre_gossip_unpublish (zyre_t *self, const char *node);
// *** Draft method, for development use, may change without warning ***
// Explicitly connect to a peer
ZYRE_EXPORT int
View
@@ -10,7 +10,6 @@ libzyre.pc
# + config files for mains (if any):
# location designated for writing self-tests:
selftest-rw/
View
@@ -414,6 +414,19 @@ zyre_gossip_connect_curve (zyre_t *self, const char *public_key, const char *for
free (string);
}
// --------------------------------------------------------------------------
// Inform gossip to remove a node from it's master (tuples) list
// Useful when tracking nodes activity across the mesh
void
zyre_gossip_unpublish (zyre_t *self, const char *node)
{
assert (self);
assert (node);
zstr_sendx (self->actor, "GOSSIP UNPUBLISH", node, NULL);
}
// --------------------------------------------------------------------------
// Start node, after setting header values. When you start a node it
View
@@ -101,6 +101,11 @@ ZYRE_PRIVATE void
ZYRE_PRIVATE void
zyre_gossip_connect_curve (zyre_t *self, const char *public_key, const char *format, ...) CHECK_PRINTF (3);
// *** Draft method, defined for internal use only ***
// Unpublish a GOSSIP node from local list, useful in removing nodes from list when they EXIT
ZYRE_PRIVATE void
zyre_gossip_unpublish (zyre_t *self, const char *node);
// *** Draft method, defined for internal use only ***
// Explicitly connect to a peer
ZYRE_PRIVATE int
View
@@ -179,6 +179,8 @@ zyre_node_gossip_start (zyre_node_t *self)
self->gossip = zactor_new (zgossip, self->name);
if (self->verbose)
zstr_send (self->gossip, "VERBOSE");
zstr_sendx (self->gossip, "SET server/timeout", "60000", NULL);
assert (self->gossip);
}
}
@@ -579,6 +581,15 @@ zyre_node_recv_api (zyre_node_t *self)
zstr_sendx (self->gossip, "CONNECT", self->gossip_connect, server_public_key, NULL);
zstr_free (&server_public_key);
}
#ifdef ZYRE_BUILD_DRAFT_API
// DRAFT-API: GOSSIP TTL
else
if (streq (command, "GOSSIP UNPUBLISH")) {
char *msg = zmsg_popstr (request);
zstr_sendx (self->gossip, "UNPUBLISH", msg, NULL);
zstr_free (&msg);
}
#endif
else
if (streq (command, "START"))
zsock_signal (self->pipe, zyre_node_start (self));
@@ -860,6 +871,8 @@ zyre_node_remove_peer (zyre_node_t *self, zyre_peer_t *peer)
zyre_node_delete_peer (zhash_cursor (self->peer_groups), item, peer);
// To destroy peer, we remove from peers hash table
zhash_delete (self->peers, zyre_peer_identity (peer));
}

0 comments on commit 7af3a8a

Please sign in to comment.