Skip to content

Commit

Permalink
Merge pull request #607 from wesyoung/fix/gossip-unpublish
Browse files Browse the repository at this point in the history
problem: zyre missing GOSSIP UNPUBLISH command
  • Loading branch information
bluca committed Oct 4, 2018
2 parents 00fe5fa + 37356e1 commit 067c9ec
Show file tree
Hide file tree
Showing 21 changed files with 132 additions and 1 deletion.
4 changes: 4 additions & 0 deletions api/python_cffi.slurp
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions api/zyre.api
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions bindings/jni/src/main/c/org_zeromq_zyre_Zyre.c
Expand Up @@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions bindings/jni/src/main/java/org/zeromq/zyre/Zyre.java
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions bindings/lua_ffi/zyre_ffi.lua
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions bindings/nodejs/README.md
Expand Up @@ -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 ()
```
Expand Down
16 changes: 16 additions & 0 deletions bindings/nodejs/binding.cc
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions bindings/nodejs/binding.h
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions bindings/python/zyre/_zyre_ctypes.py
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions bindings/python_cffi/zyre_cffi/Zyre.py
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions bindings/python_cffi/zyre_cffi/cdefs.py
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions bindings/qml/src/QmlZyre.cpp
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions bindings/qml/src/QmlZyre.h
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions bindings/qt/src/qzyre.cpp
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions bindings/ruby/lib/zyre/ffi.rb
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions bindings/ruby/lib/zyre/ffi/zyre.rb
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions include/zyre.h
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/.gitignore
Expand Up @@ -10,7 +10,6 @@ libzyre.pc

# + config files for mains (if any):


# location designated for writing self-tests:
selftest-rw/

Expand Down
13 changes: 13 additions & 0 deletions src/zyre.c
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/zyre_classes.h
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/zyre_node.c
Expand Up @@ -579,6 +579,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));
Expand Down Expand Up @@ -860,6 +869,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));


}


Expand Down

0 comments on commit 067c9ec

Please sign in to comment.