Skip to content

Commit

Permalink
Update to latest NNG revision.
Browse files Browse the repository at this point in the history
* **Polyamorous mode is deprecated.**
* The enum for allocation flags was changed to a macro, which was not
  being included in API generation.
* Docs were updated.
  • Loading branch information
codypiersall committed Aug 27, 2020
1 parent dbf1789 commit 4609dff
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
3 changes: 2 additions & 1 deletion generate_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ process_header nng/include/nng/protocol/survey0/respond.h >> nng_api.h
process_header nng/include/nng/supplemental/tls/tls.h | egrep -v "nng_tls_config_(pass|key)" >> nng_api.h
process_header nng/include/nng/transport/tls/tls.h >> nng_api.h

grep '#define NNG_.*_VERSION' nng/include/nng/nng.h >> nng_api.h
grep '^#define NNG_FLAG' nng/include/nng/nng.h >> nng_api.h
grep '^#define NNG_.*_VERSION' nng/include/nng/nng.h >> nng_api.h
24 changes: 17 additions & 7 deletions nng_api.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// THIS FILE WAS AUTOMATICALLY GENERATED BY generate_api.sh
// THIS FILE WAS AUTOMATICALLY GENERATED BY ./generate_api.sh
typedef struct nng_ctx_s {
uint32_t id;
} nng_ctx;
Expand Down Expand Up @@ -276,7 +276,7 @@ extern void nng_sleep_aio(nng_duration, nng_aio *);
extern int nng_msg_alloc(nng_msg **, size_t);
extern void nng_msg_free(nng_msg *);
extern int nng_msg_realloc(nng_msg *, size_t);
extern void *nng_msg_header(nng_msg *);
extern void * nng_msg_header(nng_msg *);
extern size_t nng_msg_header_len(const nng_msg *);
extern void * nng_msg_body(nng_msg *);
extern size_t nng_msg_len(const nng_msg *);
Expand Down Expand Up @@ -341,10 +341,6 @@ extern int nng_pipe_id(nng_pipe);
extern nng_socket nng_pipe_socket(nng_pipe);
extern nng_dialer nng_pipe_dialer(nng_pipe);
extern nng_listener nng_pipe_listener(nng_pipe);
enum nng_flag_enum {
NNG_FLAG_ALLOC = 1,
NNG_FLAG_NONBLOCK = 2
};
extern int nng_stats_get(nng_stat **);
extern void nng_stats_free(nng_stat *);
extern void nng_stats_dump(nng_stat *);
Expand Down Expand Up @@ -545,6 +541,7 @@ int nng_pair0_open(nng_socket *);
int nng_pair0_open_raw(nng_socket *);
int nng_pair1_open(nng_socket *);
int nng_pair1_open_raw(nng_socket *);
int nng_pair1_open_poly(nng_socket *);
int nng_push0_open(nng_socket *);
int nng_push0_open_raw(nng_socket *);
int nng_pull0_open(nng_socket *);
Expand All @@ -571,6 +568,12 @@ typedef enum nng_tls_auth_mode {
NNG_TLS_AUTH_MODE_OPTIONAL = 1,
NNG_TLS_AUTH_MODE_REQUIRED = 2,
} nng_tls_auth_mode;
typedef enum nng_tls_version {
NNG_TLS_1_0 = 0x301,
NNG_TLS_1_1 = 0x302,
NNG_TLS_1_2 = 0x303,
NNG_TLS_1_3 = 0x304
} nng_tls_version;
int nng_tls_config_alloc(nng_tls_config **, nng_tls_mode);
void nng_tls_config_hold(nng_tls_config *);
void nng_tls_config_free(nng_tls_config *);
Expand All @@ -583,7 +586,14 @@ int nng_tls_config_auth_mode(nng_tls_config *, nng_tls_auth_mode);
int nng_tls_config_ca_file(nng_tls_config *, const char *);
int nng_tls_config_cert_key_file(
nng_tls_config *, const char *, const char *);
int nng_tls_config_version(
nng_tls_config *, nng_tls_version, nng_tls_version);
const char *nng_tls_engine_name(void);
const char *nng_tls_engine_description(void);
bool nng_tls_engine_fips_mode(void);
int nng_tls_register(void);
#define NNG_FLAG_ALLOC 1u // Recv to allocate receive buffer
#define NNG_FLAG_NONBLOCK 2u // Non-blocking operations
#define NNG_MAJOR_VERSION 1
#define NNG_MINOR_VERSION 3
#define NNG_MINOR_VERSION 4
#define NNG_PATCH_VERSION 0
24 changes: 17 additions & 7 deletions pynng/nng.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ class Pair0(Socket):


class Pair1(Socket):
"""A socket for bidrectional communication with potentially many partners.
"""A socket for bidrectional communication with potentially many peers.
The Python version of `nng_pair1
<https://nanomsg.github.io/nng/man/tip/nng_pair.7>`_.
Expand All @@ -701,10 +701,18 @@ class Pair1(Socket):
keyword-only argument, ``polyamorous``, which must be set to ``True`` to
connect with more than one peer.
.. Note::
.. Warning::
If you want to connect to multiple peers you **must** pass
``polyamorous=True`` when you create your socket.
``polyamorous=True`` when you create your socket. ``polyamorous`` is a
read-only attribute of the socket and cannot be changed after creation.
.. Warning::
Pair1 was an experimental feature in nng, and is currently deprecated.
It will likely be removed in the future; see `nng's docs
<https://nng.nanomsg.org/man/v1.3.2/nng_pair_open.3.html>`_ for
details.
To get the benefits of polyamory, you need to use the methods that work
with :class:`Message` objects: :meth:`Socket.recv_msg` and
Expand All @@ -724,22 +732,24 @@ class Pair1(Socket):
"""

def __init__(self, *, polyamorous=None, **kwargs):
def __init__(self, *, polyamorous=False, **kwargs):
# make sure we don't listen/dial before setting polyamorous, so we pop
# them out of kwargs, then do the dial/listen below.
# It's not beautiful, but it will work.
dial_addr = kwargs.pop('dial', None)
listen_addr = kwargs.pop('dial', None)
super().__init__(**kwargs)
if polyamorous is not None:
self.polyamorous = polyamorous
if polyamorous:
self._opener = lib.nng_pair1_open_poly
else:
self._opener = lib.nng_pair1_open
# now we can do the listen/dial
if dial_addr is not None:
self.dial(dial_addr, block=kwargs.get('block_on_dial'))
if listen_addr is not None:
self.listen(listen_addr)

_opener = lib.nng_pair1_open
_opener = lib.nng_pair1_open_poly
polyamorous = BooleanOption('pair1:polyamorous')


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
THIS_DIR = os.path.abspath(os.path.dirname(__file__))

NNG_REPO = 'https://github.com/nanomsg/nng'
NNG_REV = '60198afcb25766a5ca060c9d3c368c4d37ad40da'
NNG_REV = '4f5e11c391c4a8f1b2731aee5ad47bc0c925042a'
MBEDTLS_REPO = 'https://github.com/ARMmbed/mbedtls.git'
MBEDTLS_REV = '04a049bda1ceca48060b57bc4bcf5203ce591421'

Expand Down

0 comments on commit 4609dff

Please sign in to comment.