Skip to content

Commit

Permalink
fixes nanomsg#143 Protocols and transports should be "configurable"
Browse files Browse the repository at this point in the history
This makes all the protocols and transports optional.  All
of them except ZeroTier are enabled by default, but you can
now disable them (remove from the build) with cmake options.

The test suite is modified so that tests still run as much
as they can, but skip over things caused by missing functionality
from the library (due to configuration).

Further, the constant definitions and prototypes for functions
that are specific to transports or protocols are moved into
appropriate headers, which should be included directly by
applications wishing to use these.

We have also added and improved documentation -- all of the
transports are documented, and several more man pages for
protocols have been added.  (Req/Rep and Surveyor are still
missing.)
  • Loading branch information
gdamore committed Nov 2, 2017
1 parent d340af7 commit 7bf591e
Show file tree
Hide file tree
Showing 76 changed files with 2,686 additions and 1,161 deletions.
109 changes: 74 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,83 @@ option (NNG_TESTS "Build and run tests" ON)
option (NNG_TOOLS "Build extra tools" OFF)
option (NNG_ENABLE_NNGCAT "Enable building nngcat utility." ${NNG_TOOLS})
option (NNG_ENABLE_COVERAGE "Enable coverage reporting." OFF)
option (NNG_ENABLE_ZEROTIER "Enable ZeroTier transport (requires libzerotiercore)." OFF)
set (NNG_ZEROTIER_SOURCE "" CACHE PATH "Location of ZeroTier source tree.")
# Enable access to private APIs for our own use.
add_definitions (-DNNG_PRIVATE)

option (NNG_PROTO_BUS0 "Enable BUSv0 protocol." ON)
if (NNG_PROTO_BUS0)
add_definitions (-DNNG_HAVE_BUS0)
endif ()

option (NNG_PROTO_PAIR0 "Enable PAIRv0 protocol." ON)
if (NNG_PROTO_PAIR0)
add_definitions (-DNNG_HAVE_PAIR0)
endif ()

option (NNG_PROTO_PAIR1 "Enable PAIRv1 protocol." ON)
if (NNG_PROTO_PAIR1)
add_definitions (-DNNG_HAVE_PAIR1)
endif ()

option (NNG_PROTO_REQ0 "Enable REQv0 protocol." ON)
if (NNG_PROTO_REQ0)
add_definitions (-DNNG_HAVE_REQ0)
endif ()

option (NNG_PROTO_REP0 "Enable REPv0 protocol." ON)
if (NNG_PROTO_REP0)
add_definitions (-DNNG_HAVE_REP0)
endif ()

option (NNG_PROTO_PUB0 "Enable PUBv0 protocol." ON)
if (NNG_PROTO_PUB0)
add_definitions (-DNNG_HAVE_PUB0)
endif ()

option (NNG_PROTO_SUB0 "Enable SUBv0 protocol." ON)
if (NNG_PROTO_SUB0)
add_definitions (-DNNG_HAVE_SUB0)
endif ()

option (NNG_PROTO_PUSH0 "Enable PUSHv0 protocol." ON)
if (NNG_PROTO_PUSH0)
add_definitions (-DNNG_HAVE_PUSH0)
endif ()

option (NNG_PROTO_PULL0 "Enable PULLv0 protocol." ON)
if (NNG_PROTO_PULL0)
add_definitions (-DNNG_HAVE_PULL0)
endif ()

option (NNG_PROTO_SURVEYOR0 "Enable SURVEYORv0 protocol." ON)
if (NNG_PROTO_SURVEYOR0)
add_definitions (-DNNG_HAVE_SURVEYOR0)
endif ()

option (NNG_PROTO_RESPONDENT0 "Enable RESPONDENTv0 protocol." ON)
if (NNG_PROTO_RESPONDENT0)
add_definitions (-DNNG_HAVE_RESPONDENT0)
endif ()

option (NNG_TRANSPORT_INPROC "Enable inproc transport." ON)
if (NNG_TRANSPORT_INPROC)
add_definitions (-DNNG_HAVE_INPROC)
endif ()

option (NNG_TRANSPORT_IPC "Enable IPC transport." ON)
if (NNG_TRANSPORT_IPC)
add_definitions (-DNNG_HAVE_IPC)
endif ()

option (NNG_TRANSPORT_TCP "Enable TCP transport." ON)
if (NNG_TRANSPORT_TCP)
add_definitions (-DNNG_HAVE_TCP)
endif ()

option (NNG_TRANSPORT_ZEROTIER "Enable ZeroTier transport (requires libzerotiercore)." OFF)
if (NNG_TRANSPORT_ZEROTIER)
add_definitions (-DNNG_HAVE_ZEROTIER)
endif ()
# Platform checks.

if (NNG_ENABLE_COVERAGE)
Expand Down Expand Up @@ -247,39 +319,6 @@ nng_check_sym (strlcat string.h NNG_HAVE_STRLCAT)
nng_check_sym (strlcpy string.h NNG_HAVE_STRLCPY)
nng_check_sym (strnlen string.h NNG_HAVE_STRNLEN)

# Search for ZeroTier
# We use the libzerotiercore.a library, which is unfortunately a C++ object
# even though it exposes only public C symbols. It would be extremely
# helpful if libzerotiercore didn't make us carry the whole C++ runtime
# behind us. The user must specify the location of the ZeroTier source
# tree (dev branch for now, and already compiled please) by setting the
# NNG_ZEROTIER_SOURCE macro.
# NB: This needs to be the zerotierone tree, not the libzt library.
# This is because we don't access the API, but instead use the low
# level zerotiercore functionality directly.
# NB: As we wind up linking libzerotiercore.a into the application,
# this means that your application will *also* need to either be licensed
# under the GPLv3, or you will need to have a commercial license from
# ZeroTier permitting its use elsewhere.
if (NNG_ENABLE_ZEROTIER)
enable_language(CXX)
find_library(NNG_LIBZTCORE zerotiercore PATHS ${NNG_ZEROTIER_SOURCE})
if (NNG_LIBZTCORE)
set(CMAKE_REQUIRED_INCLUDES ${NNG_ZEROTIER_SOURCE}/include)
# set(CMAKE_REQUIRED_LIBRARIES ${NNG_LIBZTCORE} c++)
# set(NNG_REQUIRED_LIBRARIES ${NNG_REQUIRED_LIBRARIES} ${NNG_LIBZTCORE} c++)
message(STATUS "C++ ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES}")
set(CMAKE_REQUIRED_LIBRARIES ${NNG_LIBZTCORE} ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
set(NNG_REQUIRED_LIBRARIES ${NNG_REQUIRED_LIBRARIES} ${NNG_LIBZTCORE} ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES})
set(NNG_REQUIRED_INCLUDES ${NNG_REQUIRED_INCLUDES} ${NNG_ZEROTIER_SOURCE}/include)
nng_check_sym(ZT_Node_join ZeroTierOne.h NNG_HAVE_ZEROTIER)
endif()
if (NOT NNG_HAVE_ZEROTIER)
message (FATAL_ERROR "Cannot find ZeroTier components")
endif()
message(STATUS "Found ZeroTier at ${NNG_LIBZTCORE}")
endif()

add_subdirectory (src)

if (NNG_TESTS)
Expand Down
6 changes: 2 additions & 4 deletions docs/nng_bus.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ SYNOPSIS

[source,c]
----------
#include <nng/protocol/bus/bus.h>
#include <nng/protocol/bus0/bus.h>
int nng_bus_open(nng_socket *s);
int nng_bus0_open(nng_socket *s);
----------

DESCRIPTION
Expand Down Expand Up @@ -57,7 +55,7 @@ likely that message loss is to occur.
Socket Operations
~~~~~~~~~~~~~~~~~

The `nng_bus_open()` call creates a bus socket. This socket
The `nng_bus0_open()` call creates a bus socket. This socket
may be used to send and receive messages. Sending messages will
attempt to deliver to each directly connected peer.

Expand Down
17 changes: 11 additions & 6 deletions docs/nng_inproc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ URI Format

This transport uses URIs using the scheme `inproc://`, followed by
an arbitrary string of text, terminated by a `NUL` byte. The
entire URI must be less than `NNG_MAXADDRLEN` bytes long, including
the terminating `NUL`.
entire URI must be less than `NNG_MAXADDRLEN` bytes long.

Multiple URIs can be used within the
same application, and they will not interfere with one another.
Expand All @@ -65,16 +64,22 @@ When using an `nng_sockaddr` structure, the actual structure is of type

[source,c]
--------
#define NNG_AF_INPROC 1
#define NNG_AF_INPROC 1 <1>
#define NNG_MAXADDRLEN 128
struct nng_sockaddr_inproc {
typedef nng_sockaddr_inproc {
// <2>
uint16_t sa_family; // must be NNG_AF_INPROC
uint32_t sa_path[NNG_MAXADDRLEN]; // arbitrary "path"
char sa_path[NNG_MAXADDRLEN]; // arbitrary "path"
//
}
--------
<1> The values of these macros may change, so applications
should avoid depending upon their values and instead use them symbolically.
<2> Other members may be present, but only those listed here
are suitable for application use.

The `sa_family` member will have the value `NNG_AF_INPROC` (1).
The `sa_family` member will have the value `NNG_AF_INPROC`.
The `sa_path` member is an ASCIIZ string, and may contain any characters,
terminated by a `NUL` byte.

Expand Down
110 changes: 110 additions & 0 deletions docs/nng_ipc.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
nng_ipc(7)
==========
:doctype: manpage
:manmanual: nng
:mansource: nng
:icons: font
:source-highlighter: pygments
:copyright: Copyright 2017 Garrett D'Amore <[email protected]> \
Copyright 2017 Capitar IT Group BV <info@capitar.com> \
This software is supplied under the terms of the MIT License, a \
copy of which should be located in the distribution where this \
file was obtained (LICENSE.txt). A copy of the license may also \
be found online at https://opensource.org/licenses/MIT.

NAME
----
nng_ipc - IPC transport for nng

SYNOPSIS
--------

[source,c]
----------
#include <nng/transport/ipc/ipc.h>
int nng_ipc_register(void);
----------

DESCRIPTION
-----------

The _nng_ipc_ transport provides communication support between
_nng_ sockets within different processes on the same host. For POSIX
platforms, this is implemented using UNIX domain sockets. For Windows,
this is implemented using Windows Named Pipes. Other platforms may
have different implementation strategies.

// We need to insert a reference to the nanomsg RFC.

Registration
~~~~~~~~~~~~

The _ipc_ transport is generally built-in to the _nng_ core, so
no extra steps to use it should be necessary.

URI Format
~~~~~~~~~~

This transport uses URIs using the scheme `ipc://`, followed by
a path name in the file system where the socket or named pipe
should be created.

TIP: On Windows, all names are prefixed by `\.\pipe\` and do not
occupy the normal file system. On POSIX platforms, the path is
taken literally, and is relative to the current directory, unless
an extra leading `/` is provided. For example, `ipc://myname` refers
to the name `myname` in the current directory, whereas `ipc:///tmp/myname`
refers to `myname` located in `/tmp`.

The entire URI must be less than `NNG_MAXADDRLEN` bytes long.

Socket Address
~~~~~~~~~~~~~~

When using an `nng_sockaddr` structure, the actual structure is of type
`nng_sockaddr_ipc`. This is a `struct` type with the following definition:

[source,c]
--------
#define NNG_AF_IPC 2 <1>
#define NNG_MAXADDRLEN 128
typedef struct {
// ... <2>
uint16_t sa_family; // must be NNG_AF_IPC
char sa_path[NNG_MAXADDRLEN]; // arbitrary "path"
// ...
} nng_sockaddr_ipc;
--------
<1> The values of these macros may change, so applications
should avoid depending upon their values and instead use them symbolically.
<2> Other members may be present, but only those listed here
are suitable for application use.

The `sa_family` member will have the value `NNG_AF_IPC`.
The `sa_path` member is an ASCIIZ string, and may contain any legal
path name (platform-dependent), terminated by a `NUL` byte.

Transport Options
~~~~~~~~~~~~~~~~~

The _ipc_ transport has no special
options.footnote:[Options for security attributes and credentials are planned.]

AUTHORS
-------
link:mailto:[email protected][Garrett D'Amore]

SEE ALSO
--------
<<nng.adoc#,nng(7)>>

COPYRIGHT
---------

Copyright 2017 mailto:[email protected][Garrett D'Amore] +
Copyright 2017 mailto:[email protected][Capitar IT Group BV]

This document is supplied under the terms of the
https://opensource.org/licenses/LICENSE.txt[MIT License].
Loading

0 comments on commit 7bf591e

Please sign in to comment.