Zyre module

The top level namespace for Zyre classes.

Constants

BUILT_WITH_DRAFT_API
BUILT_WITH_DRAFT_CZMQ_API
VERSION

Gem version (semver)

Public Class Methods

allow( *addresses )

Allow (whitelist) a list of IP addresses. For NULL, all clients from these addresses will be accepted. For PLAIN and CURVE, they will be allowed to continue with authentication. You can call this method multiple times to whitelist more IP addresses. If you whitelist one or more addresses, any non-whitelisted addresses are treated as blacklisted:

# File lib/zyre.rb, line 50
def self::allow( *addresses )
        @whitelisted_ips.merge( addresses )
end
deny( *addresses )

Deny (blacklist) a list of IP addresses. For all security mechanisms, this rejects the connection without any further authentication. Use either a whitelist, or a blacklist, not not both. If you define both a whitelist and a blacklist, only the whitelist takes effect:

# File lib/zyre.rb, line 59
def self::deny( *addresses )
        @blacklisted_ips.merge( addresses )
end
disable_zsys_handler

Disable CZMQ’s default signal handler, which allows for handling it in Ruby instead.

static VALUE
rzyre_s_disable_zsys_handler( VALUE module )
{
        rzyre_log( "info", "Disabling zsys INT/TERM handler." );
        zsys_handler_set( NULL );
        return Qtrue;
}
has_draft_apis?()

Returns true if the underlying Zyre library was built with draft APIs.

# File lib/zyre.rb, line 71
def self::has_draft_apis?
        return Zyre::BUILT_WITH_DRAFT_API ? true : false
end
has_draft_czmq_apis?()

Returns true if the underlying Czmq library was built with draft APIs.

# File lib/zyre.rb, line 65
def self::has_draft_czmq_apis?
        return Zyre::BUILT_WITH_DRAFT_CZMQ_API ? true : false
end
interfaces → hash

Return a Hash of broadcast-capable interfaces on the local host keyed by name. The values contain other information about the interface:

{ “<interface name>” => { address: “<interface address>”, broadcast: “<interface broadcast address>”, netmask: “<interface network mask>”, } }

static VALUE
rzyre_s_interfaces( VALUE module )
{

        ziflist_t *iflist = ziflist_new();
        ziflist_reload( iflist );

        const VALUE rval = rb_hash_new();
        const char *iface = ziflist_first( iflist );

        while ( iface ) {
                const char *address_s = ziflist_address( iflist );
                const char *broadcast_s = ziflist_broadcast( iflist );
                const char *netmask_s = ziflist_netmask( iflist );
                const VALUE info_hash = rb_hash_new();

                rzyre_log( "debug", "Getting info for %s", address_s );
                rb_hash_aset( info_hash, ID2SYM(rb_intern("address")), rb_usascii_str_new_cstr(address_s) );
                rb_hash_aset( info_hash, ID2SYM(rb_intern("broadcast")), rb_usascii_str_new_cstr(broadcast_s) );
                rb_hash_aset( info_hash, ID2SYM(rb_intern("netmask")), rb_usascii_str_new_cstr(netmask_s) );

                rb_hash_aset( rval, rb_usascii_str_new_cstr(iface), info_hash );

                iface = ziflist_next( iflist );
        }

        ziflist_destroy( &iflist );

        return rval;
}
normalize_headers( headers )

Transform the given headers hash into a form that can be passed to Zyre.

# File lib/zyre.rb, line 37
def self::normalize_headers( headers )
        return headers.
                transform_keys {|k| Zyre.transform_header_key(k) }.
                transform_values {|v| v.to_s.encode('us-ascii') }
end
start_authenticator()
static VALUE
rzyre_s_start_authenticator( VALUE module )
{
        return Qnil;
}
transform_header_key( key )

If the given key is a Symbol, transform it into an RFC822-style header key. If it’s not a Symbol, returns it unchanged.

# File lib/zyre.rb, line 27
def self::transform_header_key( key )
        if key.is_a?( Symbol )
                key = key.to_s.gsub( /_/, '-' ).capitalize
        end

        return key
end
z85_decode( string ) → data

Return the data decoded from the specified Z85-encoded binary string. If there is a problem decoding the string, returns nil.

static VALUE
rzyre_s_z85_decode( VALUE module, VALUE string )
{
#if HAVE_ZMQ_Z85_DECODE
        const char *data_str = StringValueCStr( string );
        const long len = RSTRING_LEN( string );
        const long res_len = (len * 0.8) + 1;
        char *decoded = NULL;
        VALUE result = Qnil;

        if ( len % 5 ) return Qnil;

        decoded = RB_ZALLOC_N( char, res_len );
        zmq_z85_decode( (unsigned char *)decoded, data_str );

        if ( decoded != NULL ) {
                result = rb_str_new( decoded, res_len - 1 );
        }

        ruby_xfree( decoded );

        return result;
#else
        rb_notimplement();
#endif
}
z85_encode( data ) → string

Return the specified binary data as a Z85-encoded binary string. The size of the data must be divisible by 4. If there is a problem encoding the data, returns nil.

static VALUE
rzyre_s_z85_encode( VALUE module, VALUE data )
{
#if HAVE_ZMQ_Z85_ENCODE
        const char *data_str = StringValuePtr( data );
        const long len = RSTRING_LEN( data );
        const long res_len = (len * 1.25) + 1;
        char *encoded = NULL;
        VALUE result = Qnil;

        if ( len % 4 ) return Qnil;

        encoded = RB_ZALLOC_N( char, res_len );
        zmq_z85_encode( encoded, (unsigned char *)data_str, len );

        if ( encoded != NULL ) {
                result = rb_usascii_str_new( encoded, res_len - 1 );
        }

        ruby_xfree( encoded );

        return result;
#else
        rb_notimplement();
#endif
}
zyre_version → int

Return the version of the underlying libzyre.

static VALUE
rzyre_s_zyre_version()
{
        static uint64_t version;

        version = zyre_version();

        return LONG2NUM( version );
}