Permalink
Browse files

Merge pull request #563 from wesyoung/fix/zap2

problem: missing set_zap_domain support when using curve
  • Loading branch information...
keent committed Oct 12, 2017
2 parents 8abf3b3 + ab195e7 commit fd77b0f7c1f34bff7baa87992582736a6920c572
View
@@ -107,6 +107,11 @@
<argument name = "zcert" type = "zcert"></argument>
</method>
<method name = "set zap domain" state = "draft">
Specify the ZAP domain (for use with CURVE).
<argument name = "domain" type = "string"/>
</method>
<method name = "gossip bind">
Set-up gossip discovery of other nodes. At least one node in the cluster
must bind to a well-known gossip endpoint, so other nodes can connect to
@@ -114,6 +114,14 @@ Java_org_zeromq_zyre_Zyre__1_1setZcert (JNIEnv *env, jclass c, jlong self, jlong
zyre_set_zcert ((zyre_t *) (intptr_t) self, (zcert_t *) (intptr_t) zcert);
}
JNIEXPORT void JNICALL
Java_org_zeromq_zyre_Zyre__1_1setZapDomain (JNIEnv *env, jclass c, jlong self, jstring domain)
{
char *domain_ = (char *) (*env)->GetStringUTFChars (env, domain, NULL);
zyre_set_zap_domain ((zyre_t *) (intptr_t) self, domain_);
(*env)->ReleaseStringUTFChars (env, domain, domain_);
}
JNIEXPORT void JNICALL
Java_org_zeromq_zyre_Zyre__1_1gossipBind (JNIEnv *env, jclass c, jlong self, jstring format)
{
@@ -148,6 +148,13 @@ public void setZcert (Zcert zcert) {
__setZcert (self, zcert.self);
}
/*
Specify the ZAP domain (for use with CURVE).
*/
native static void __setZapDomain (long self, String domain);
public void setZapDomain (String domain) {
__setZapDomain (self, domain);
}
/*
Set-up gossip discovery of other nodes. At least one node in the cluster
must bind to a well-known gossip endpoint, so other nodes can connect to
it. Note that gossip endpoints are completely distinct from Zyre node
@@ -110,6 +110,10 @@ int
void
zyre_set_zcert (zyre_t *self, zcert_t *zcert);
// Specify the ZAP domain (for use with CURVE).
void
zyre_set_zap_domain (zyre_t *self, const char *domain);
// Set-up gossip discovery of other nodes. At least one node in the cluster
// must bind to a well-known gossip endpoint, so other nodes can connect to
// it. Note that gossip endpoints are completely distinct from Zyre node
@@ -154,6 +154,12 @@ nothing my_zyre.setZcert (Zcert)
Apply a azcert to a Zyre node.
```
nothing my_zyre.setZapDomain (String)
```
Specify the ZAP domain (for use with CURVE).
```
nothing my_zyre.gossipBind (String)
```
View
@@ -45,6 +45,7 @@ NAN_MODULE_INIT (Zyre::Init) {
Nan::SetPrototypeMethod (tpl, "setInterface", _set_interface);
Nan::SetPrototypeMethod (tpl, "setEndpoint", _set_endpoint);
Nan::SetPrototypeMethod (tpl, "setZcert", _set_zcert);
Nan::SetPrototypeMethod (tpl, "setZapDomain", _set_zap_domain);
Nan::SetPrototypeMethod (tpl, "gossipBind", _gossip_bind);
Nan::SetPrototypeMethod (tpl, "gossipConnect", _gossip_connect);
Nan::SetPrototypeMethod (tpl, "gossipConnectCurve", _gossip_connect_curve);
@@ -259,6 +260,21 @@ NAN_METHOD (Zyre::_set_zcert) {
zyre_set_zcert (zyre->self, zcert->self);
}
NAN_METHOD (Zyre::_set_zap_domain) {
Zyre *zyre = Nan::ObjectWrap::Unwrap <Zyre> (info.Holder ());
char *domain;
if (info [0]->IsUndefined ())
return Nan::ThrowTypeError ("method requires a `domain`");
else
if (!info [0]->IsString ())
return Nan::ThrowTypeError ("`domain` must be a string");
else {
Nan::Utf8String domain_utf8 (info [0].As<String>());
domain = *domain_utf8;
}
zyre_set_zap_domain (zyre->self, (const char *)domain);
}
NAN_METHOD (Zyre::_gossip_bind) {
Zyre *zyre = Nan::ObjectWrap::Unwrap <Zyre> (info.Holder ());
char *format;
@@ -54,6 +54,7 @@ class Zyre: public Nan::ObjectWrap {
static NAN_METHOD (_set_interface);
static NAN_METHOD (_set_endpoint);
static NAN_METHOD (_set_zcert);
static NAN_METHOD (_set_zap_domain);
static NAN_METHOD (_gossip_bind);
static NAN_METHOD (_gossip_connect);
static NAN_METHOD (_gossip_connect_curve);
@@ -94,6 +94,8 @@ class zyre_event_t(Structure):
lib.zyre_set_endpoint.argtypes = [zyre_p, c_char_p]
lib.zyre_set_zcert.restype = None
lib.zyre_set_zcert.argtypes = [zyre_p, czmq.zcert_p]
lib.zyre_set_zap_domain.restype = None
lib.zyre_set_zap_domain.argtypes = [zyre_p, c_char_p]
lib.zyre_gossip_bind.restype = None
lib.zyre_gossip_bind.argtypes = [zyre_p, c_char_p]
lib.zyre_gossip_connect.restype = None
@@ -287,6 +289,12 @@ def set_zcert(self, zcert):
"""
return lib.zyre_set_zcert(self._as_parameter_, zcert)
def set_zap_domain(self, domain):
"""
Specify the ZAP domain (for use with CURVE).
"""
return lib.zyre_set_zap_domain(self._as_parameter_, domain)
def gossip_bind(self, format, *args):
"""
Set-up gossip discovery of other nodes. At least one node in the cluster
@@ -124,6 +124,12 @@ def set_zcert(self, zcert):
"""
return libzyre.zyre_set_zcert(self._p, zcert._p)
def set_zap_domain(self, domain):
"""
Specify the ZAP domain (for use with CURVE).
"""
return libzyre.zyre_set_zap_domain(self._p, to_bytes(domain))
def gossip_bind(self, format, ):
"""
Set-up gossip discovery of other nodes. At least one node in the cluster
@@ -98,6 +98,10 @@ int
void
zyre_set_zcert (zyre_t *self, zcert_t *zcert);
// Specify the ZAP domain (for use with CURVE).
void
zyre_set_zap_domain (zyre_t *self, const char *domain);
// Set-up gossip discovery of other nodes. At least one node in the cluster
// must bind to a well-known gossip endpoint, so other nodes can connect to
// it. Note that gossip endpoints are completely distinct from Zyre node
@@ -4170,6 +4170,10 @@
void
zyre_set_zcert (zyre_t *self, zcert_t *zcert);
// Specify the ZAP domain (for use with CURVE).
void
zyre_set_zap_domain (zyre_t *self, const char *domain);
// Set-up gossip discovery of other nodes. At least one node in the cluster
// must bind to a well-known gossip endpoint, so other nodes can connect to
// it. Note that gossip endpoints are completely distinct from Zyre node
@@ -102,6 +102,12 @@ void QmlZyre::setZcert (zcert_t *zcert) {
zyre_set_zcert (self, zcert);
};
///
// Specify the ZAP domain (for use with CURVE).
void QmlZyre::setZapDomain (const QString &domain) {
zyre_set_zap_domain (self, domain.toUtf8().data());
};
///
// Set-up gossip discovery of other nodes. At least one node in the cluster
// must bind to a well-known gossip endpoint, so other nodes can connect to
@@ -86,6 +86,9 @@ public slots:
// Apply a azcert to a Zyre node.
void setZcert (zcert_t *zcert);
// Specify the ZAP domain (for use with CURVE).
void setZapDomain (const QString &domain);
// Set-up gossip discovery of other nodes. At least one node in the cluster
// must bind to a well-known gossip endpoint, so other nodes can connect to
// it. Note that gossip endpoints are completely distinct from Zyre node
@@ -151,6 +151,14 @@ void QZyre::setZcert (QZcert *zcert)
}
///
// Specify the ZAP domain (for use with CURVE).
void QZyre::setZapDomain (const QString &domain)
{
zyre_set_zap_domain (self, domain.toUtf8().data());
}
///
// Set-up gossip discovery of other nodes. At least one node in the cluster
// must bind to a well-known gossip endpoint, so other nodes can connect to
@@ -64,6 +64,17 @@ def self.zyre_set_zcert(*)
raise NotImplementedError, "compile zyre with --enable-drafts"
end
end
begin # DRAFT method
attach_function :zyre_set_zap_domain, [:pointer, :string], :void, **opts
rescue ::FFI::NotFoundError
if $VERBOSE || $DEBUG
warn "The DRAFT function zyre_set_zap_domain()" +
" is not provided by the installed zyre library."
end
def self.zyre_set_zap_domain(*)
raise NotImplementedError, "compile zyre with --enable-drafts"
end
end
attach_function :zyre_gossip_bind, [:pointer, :string, :varargs], :void, **opts
attach_function :zyre_gossip_connect, [:pointer, :string, :varargs], :void, **opts
begin # DRAFT method
@@ -253,6 +253,17 @@ def set_zcert(zcert)
result
end
# Specify the ZAP domain (for use with CURVE).
#
# @param domain [String, #to_s, nil]
# @return [void]
def set_zap_domain(domain)
raise DestroyedError unless @ptr
self_p = @ptr
result = ::Zyre::FFI.zyre_set_zap_domain(self_p, domain)
result
end
# Set-up gossip discovery of other nodes. At least one node in the cluster
# must bind to a well-known gossip endpoint, so other nodes can connect to
# it. Note that gossip endpoints are completely distinct from Zyre node
View
@@ -220,6 +220,11 @@ ZYRE_EXPORT void
ZYRE_EXPORT void
zyre_set_zcert (zyre_t *self, zcert_t *zcert);
// *** Draft method, for development use, may change without warning ***
// Specify the ZAP domain (for use with CURVE).
ZYRE_EXPORT void
zyre_set_zap_domain (zyre_t *self, const char *domain);
// *** Draft method, for development use, may change without warning ***
// Set-up gossip discovery with CURVE enabled.
ZYRE_EXPORT void
View
@@ -68,6 +68,9 @@ typedef struct _zyre_event_t zyre_event_t;
// Public constants
#define ZRE_DISCOVERY_PORT 5670 // IANA-assigned UDP port for ZRE
#ifdef ZYRE_BUILD_DRAFT_API
#define ZAP_DOMAIN_DEFAULT "global" // Default ZAP domain (auth)
#endif // ZYRE_BUILD_DRAFT_API
// Public classes, each with its own header file
#include "zyre_event.h"
View
@@ -35,5 +35,6 @@
<constant name = "ZRE_DISCOVERY_PORT" value = "5670" state = "stable">IANA-assigned UDP port for ZRE</constant>
<constant name = "REAP_INTERVAL" value = "1000" private = "1" >Once per second</constant>
<constant name = "ZAP_DOMAIN_DEFAULT" value = "global" state = "draft" type = "string">Default ZAP domain (auth)</constant>
</project>
View
@@ -286,6 +286,12 @@ void zyre_set_zcert(zyre_t *self, zcert_t *zcert)
zstr_sendx (self->actor, "SET SECRETKEY", zcert_secret_txt(zcert), NULL);
}
void zyre_set_zap_domain(zyre_t *self, const char *domain)
{
assert (domain);
zstr_sendx (self->actor, "ZAP DOMAIN", domain, NULL);
}
// Explicitly connect to a peer
int
@@ -818,6 +824,9 @@ zyre_test (bool verbose)
zyre_set_verbose (node3);
zyre_set_verbose (node4);
zyre_set_zap_domain(node3, "TEST");
zyre_set_zap_domain(node4, "TEST");
zsock_set_rcvtimeo(node3->inbox, 10000);
zsock_set_rcvtimeo(node4->inbox, 10000);
View
@@ -60,6 +60,11 @@ typedef struct _zyre_node_t zyre_node_t;
ZYRE_PRIVATE void
zyre_set_zcert (zyre_t *self, zcert_t *zcert);
// *** Draft method, defined for internal use only ***
// Specify the ZAP domain (for use with CURVE).
ZYRE_PRIVATE void
zyre_set_zap_domain (zyre_t *self, const char *domain);
// *** Draft method, defined for internal use only ***
// Set-up gossip discovery with CURVE enabled.
ZYRE_PRIVATE void
View
@@ -51,6 +51,7 @@ struct _zyre_node_t {
#ifdef ZYRE_BUILD_DRAFT_API
char *public_key; // Our curve public key
char *secret_key; // Our curve private key
char *zap_domain; // ZAP domain if any
#endif
};
@@ -128,6 +129,7 @@ zyre_node_new (zsock_t *pipe, void *args)
#ifdef ZYRE_BUILD_DRAFT_API
self->beacon_version = BEACON_VERSION_V2;
self->zap_domain = strdup(ZAP_DOMAIN_DEFAULT);
#endif
// Default name for node is first 6 characters of UUID:
// the shorter string is more readable in logs
@@ -162,6 +164,7 @@ zyre_node_destroy (zyre_node_t **self_p)
#ifdef ZYRE_BUILD_DRAFT_API
zstr_free (&self->secret_key);
zstr_free (&self->public_key);
zstr_free (&self->zap_domain);
#endif
free (self->name);
free (self);
@@ -197,6 +200,7 @@ zyre_node_start (zyre_node_t *self)
zcert_t *cert = zcert_new_from_txt(self->public_key, self->secret_key);
zcert_apply(cert, self->inbox);
zsock_set_curve_server (self->inbox, 1);
zsock_set_zap_domain (self->inbox, self->zap_domain);
zcert_destroy(&cert);
}
#endif
@@ -486,6 +490,7 @@ zyre_node_recv_api (zyre_node_t *self)
zcert_t *cert = zcert_new_from_txt(self->public_key, self->secret_key);
zcert_apply(cert, self->inbox);
zsock_set_curve_server (self->inbox, 1);
zsock_set_zap_domain (self->inbox, self->zap_domain);
zcert_destroy(&cert);
}
#endif
@@ -523,6 +528,12 @@ zyre_node_recv_api (zyre_node_t *self)
assert (self->secret_key);
}
else
if (streq (command, "ZAP DOMAIN")) {
free (self->zap_domain);
self->zap_domain = zmsg_popstr (request);
assert (self->zap_domain);
}
else
#endif
if (streq (command, "GOSSIP BIND")) {
zyre_node_gossip_start (self);

0 comments on commit fd77b0f

Please sign in to comment.