Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9684c57
Support runtime selection of transport.
malsbat Mar 27, 2019
735f60d
Add "-n" option across the board to specify network of addresses.
malsbat Apr 1, 2019
d599154
Allow different multicast ports for test isolation.
malsbat Apr 1, 2019
dba05dc
Run tests in parallel.
malsbat Apr 1, 2019
b74c12b
Use correct network in subscriber interactive mode.
malsbat Apr 1, 2019
dd1c2a2
Support network argument in publish test.
malsbat Apr 1, 2019
438ca09
Enable fuzzer transport again.
malsbat Apr 2, 2019
53a45dd
Transports is plural now.
malsbat Apr 2, 2019
cc28e37
Reduce number of verified builds.
malsbat Apr 2, 2019
b4c85e3
Allow 'transports' or 'transport' as scons variable.
malsbat Apr 2, 2019
3899e66
Ensure ref counts are cleaned up on mbedTLS errors.
malsbat Apr 2, 2019
cf4b5c8
Transports is plural now.
malsbat Apr 2, 2019
d7f520e
Rework multicast isolation for test runner to avoid EADDRINUSE.
malsbat Apr 3, 2019
43d0131
Git ignore patch artifacts.
malsbat Apr 3, 2019
6be92e2
Use common queue for resolver requests.
malsbat Apr 3, 2019
3d320cc
Don't rebuild ext when transports change.
malsbat Apr 10, 2019
22791c5
Remove unused define.
malsbat Apr 11, 2019
d94cdf9
Whitespace.
malsbat Apr 11, 2019
6acd6e4
Default network must be compiled in, not necessarily udp.
malsbat Apr 10, 2019
ae41e3a
Return DPS_ERR_EOD when trying to decode bytes or strings.
malsbat Apr 11, 2019
48a2e79
Pipe transport must supply listen address for peer endpoint.
malsbat Apr 11, 2019
6d9ee6d
Fix fuzzer compile error.
malsbat Apr 12, 2019
c031334
Add missing const qualifiers.
malsbat Apr 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,17 @@ srcs = ['src/bitvec.c',
'src/mbedtls.c',
'src/queue.c']

if env['transport'] == 'udp':
srcs.extend(['src/multicast/network.c',
'src/udp/network.c'])
elif env['transport'] == 'dtls':
srcs.extend(['src/multicast/network.c',
'src/dtls/network.c'])
elif env['transport'] == 'tcp':
srcs.extend(['src/multicast/network.c',
'src/tcp/network.c'])
elif env['transport'] == 'pipe':
srcs.extend(['src/multicast/network.c',
'src/pipe/network.c'])
elif env['transport'] == 'fuzzer':
if env['udp'] or env['dtls'] or env['tcp'] or env['pipe']:
srcs.extend(['src/multicast/network.c'])
if env['udp']:
srcs.extend(['src/udp/network.c'])
if env['dtls']:
srcs.extend(['src/dtls/network.c'])
if env['tcp']:
srcs.extend(['src/tcp/network.c'])
if env['pipe']:
srcs.extend(['src/pipe/network.c'])
if env['fuzzer']:
srcs.extend(['src/fuzzer/network.c'])

Depends(srcs, ext_objs)
Expand Down
15 changes: 10 additions & 5 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ AddOption('--tool', action='append', dest='tools', help='Add tool to the environ

vars = Variables()

transports = Split('udp tcp dtls pipe fuzzer')
bindings = Split('python nodejs go')

# Generic build variables
Expand All @@ -16,7 +17,7 @@ vars.AddVariables(
BoolVariable('fsan', 'Enable fuzzer sanitizer?', False),
BoolVariable('cov', 'Enable code coverage?', False),
EnumVariable('variant', 'Build variant', default='release', allowed_values=('debug', 'release'), ignorecase=2),
EnumVariable('transport', 'Transport protocol', default='udp', allowed_values=('udp', 'tcp', 'dtls', 'pipe', 'fuzzer'), ignorecase=2),
ListVariable('transports', 'Transport protocol', [t for t in transports if t != 'fuzzer'], transports),
EnumVariable('target', 'Build target', default='local', allowed_values=('local', 'yocto'), ignorecase=2),
ListVariable('bindings', 'Bindings to build', bindings, bindings),
PathVariable('application', 'Application to build', '', PathVariable.PathAccept),
Expand Down Expand Up @@ -63,16 +64,20 @@ for key, val in ARGLIST:
for b in bindings:
env[b] = b in env['bindings']

if env['transport'] == 'udp':
# Unpack transports into individually testable booleans
for t in transports:
env[t] = t in env['transports']

if env['udp']:
env['USE_UDP'] = 'true'
env.Append(CPPDEFINES = ['DPS_USE_UDP'])
elif env['transport'] == 'tcp':
if env['tcp']:
env['USE_TCP'] = 'true'
env.Append(CPPDEFINES = ['DPS_USE_TCP'])
elif env['transport'] == 'dtls':
if env['dtls']:
env['USE_DTLS'] = 'true'
env.Append(CPPDEFINES = ['DPS_USE_DTLS'])
elif env['transport'] == 'pipe':
if env['pipe']:
env['USE_PIPE'] = 'true'
env.Append(CPPDEFINES = ['DPS_USE_PIPE'])

Expand Down
8 changes: 4 additions & 4 deletions doc/tutorial/link.dox
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ the @c mcastPub parameter of DPS_StartNode(). All publications and
subscriptions will go through the forwarding node.

The second thing we do is specify the @c listenAddr parameter to
DPS_StartNode(). In this instance we bind the node to all available
interfaces at the port provided. A port value of zero lets DPS assign
an ephemeral listening port. A value of non-zero requests a specific
port.
DPS_StartNode(). In this instance we select UDP and bind the node to
all available interfaces at the port provided. A port value of zero
lets DPS assign an ephemeral listening port. A value of non-zero
requests a specific port.

The last thing we do is get the port DPS has chosen with
DPS_GetListenAddress(). This will be used by the subscriber and
Expand Down
77 changes: 54 additions & 23 deletions doc/tutorial/tutorial.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ static DPS_Node* CreateNodeWithAsymmetricKeyStore(void);
static DPS_Node* CreateNodeWithAuthenticatedSender(const DPS_KeyId* nodeId);
static DPS_Status StartMulticastNode(DPS_Node* node);
static DPS_Status StartUnicastNode(DPS_Node* node, uint16_t listenPort);
static DPS_Status StartNode(DPS_Node* node, int mcastPub, const char* listenText);
static DPS_Status StartNode(DPS_Node* node, int mcastPub, const char* listenNetwork,
const char* listenAddrText);
static void LinkComplete(DPS_Node* node, DPS_NodeAddress* addr, DPS_Status status, void* data);
static DPS_Status Publish(DPS_Node* node, const char* security, DPS_Publication** createdPub);
static DPS_Status PublishAck(DPS_Node* node, const char* security, DPS_Publication** createdPub);
Expand Down Expand Up @@ -108,11 +109,32 @@ static void Usage(int argc, char** argv)
{
DPS_PRINT("Usage %s [-d] [-l <port>] [-p <port>] [-x <network-psk|network-cert|symmetric|asymmetric>] [auth] [publish|subscribe] [ack]\n", argv[0]);
DPS_PRINT(" -d: Enable debug ouput if built for debug.\n");
DPS_PRINT(" -l: Port to listen on. This may be 0 to request an ephemeral port.\n");
DPS_PRINT(" -p: Port to link to.\n");
DPS_PRINT(" -l: Address to listen on. This may be 0 to request an ephemeral port.\n");
DPS_PRINT(" -p: Address to link to.\n");
DPS_PRINT(" -x: Secure the node.\n");
}

static int ParseAddress(char** argv, int argc, int* port, const char** network, const char** addrText)
{
char* endp;
int i = 0;

(*port) = strtol(argv[i], &endp, 10);
if (*endp == 0) {
++i;
} else {
if (!strcmp(argv[i], "dtls") || !strcmp(argv[i], "tcp") ||
!strcmp(argv[i], "udp") || !strcmp(argv[i], "pipe")) {
(*network) = argv[i++];
}
if (i < argc) {
(*addrText) = argv[i++];
}
}

return i;
}

int main(int argc, char** argv)
{
DPS_Node* node = NULL;
Expand All @@ -122,12 +144,12 @@ int main(int argc, char** argv)
int subscribe = DPS_FALSE;
int ack = DPS_FALSE;
int listenPort = -1;
const char* listenText = NULL;
const char* listenAddrText = NULL;
int linkPort = 0;
const char* linkText = NULL;
const char* linkAddrText = NULL;
const char* network = NULL;
const char *security = 0;
int auth = DPS_FALSE;
char* endp;
int i;
DPS_Status ret;

Expand All @@ -140,17 +162,23 @@ int main(int argc, char** argv)
} else if (!strcmp(argv[i], "ack")) {
ack = DPS_TRUE;
} else if (!strcmp(argv[i], "-l") && ((i + 1) < argc)) {
listenPort = strtol(argv[i + 1], &endp, 10);
if (*endp) {
listenText = argv[i + 1];
const char* listenNetwork = NULL;
i += ParseAddress(&argv[i + 1], argc - (i + 1), &listenPort, &listenNetwork, &listenAddrText);
if (network && strcmp(listenNetwork, network)) {
Usage(argc, argv);
return EXIT_FAILURE;
} else {
network = listenNetwork;
}
++i;
} else if (!strcmp(argv[i], "-p") && ((i + 1) < argc)) {
linkPort = strtol(argv[i + 1], &endp, 10);
if (*endp) {
linkText = argv[i + 1];
const char* linkNetwork = NULL;
i += ParseAddress(&argv[i + 1], argc - (i + 1), &linkPort, &linkNetwork, &linkAddrText);
if (network && strcmp(linkNetwork, network)) {
Usage(argc, argv);
return EXIT_FAILURE;
} else {
network = linkNetwork;
}
++i;
} else if (!strcmp(argv[i], "-x") && ((i + 1) < argc)) {
security = argv[i + 1];
++i;
Expand Down Expand Up @@ -199,8 +227,8 @@ int main(int argc, char** argv)
goto Exit;
}

if (linkText || listenText) {
ret = StartNode(node, DPS_MCAST_PUB_DISABLED, listenText);
if (linkAddrText || listenAddrText) {
ret = StartNode(node, DPS_MCAST_PUB_DISABLED, network, listenAddrText);
} else if (linkPort || (listenPort >= 0)) {
if (listenPort == -1) {
listenPort = 0;
Expand All @@ -213,18 +241,19 @@ int main(int argc, char** argv)
goto Exit;
}

if (linkText) {
ret = DPS_Link(node, linkText, LinkComplete, NULL);
if (linkAddrText) {
ret = DPS_Link(node, network, linkAddrText, LinkComplete, NULL);
if (ret != DPS_OK) {
goto Exit;
}
/* Wait for link to complete */
SLEEP(1000);
} else if (linkPort) {
/** [Linking to a node] */
char network[] = "udp";
char addrText[24];
snprintf(addrText, sizeof(addrText), "127.0.0.1:%d", linkPort);
ret = DPS_Link(node, addrText, LinkComplete, NULL);
ret = DPS_Link(node, network, addrText, LinkComplete, NULL);
if (ret != DPS_OK) {
goto Exit;
}
Expand Down Expand Up @@ -362,18 +391,19 @@ static DPS_Node* CreateNodeWithAuthenticatedSender(const DPS_KeyId* nodeId)
return node;
}

static DPS_Status StartNode(DPS_Node* node, int mcastPub, const char* listenText)
static DPS_Status StartNode(DPS_Node* node, int mcastPub, const char* listenNetwork,
const char* listenAddrText)
{
DPS_Status ret;
DPS_NodeAddress* listenAddr = NULL;

if (listenText) {
if (listenNetwork || listenAddrText) {
listenAddr = DPS_CreateAddress();
if (!listenAddr) {
ret = DPS_ERR_RESOURCES;
goto Exit;
}
DPS_SetAddress(listenAddr, listenText);
DPS_SetAddress(listenAddr, listenNetwork, listenAddrText);
}
ret = DPS_StartNode(node, mcastPub, listenAddr);
if (ret != DPS_OK) {
Expand Down Expand Up @@ -412,8 +442,9 @@ static DPS_Status StartUnicastNode(DPS_Node* node, uint16_t port)
ret = DPS_ERR_RESOURCES;
goto Exit;
}
char network[] = "udp";
snprintf(addrText, sizeof(addrText), "[::]:%d", port);
DPS_SetAddress(listenAddr, addrText);
DPS_SetAddress(listenAddr, network, addrText);
ret = DPS_StartNode(node, mcastPub, listenAddr);
if (ret != DPS_OK) {
goto Exit;
Expand Down
1 change: 1 addition & 0 deletions dps_shared.def
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ DPS_LinkTo
DPS_Log
DPS_LogBytes
DPS_MemoryKeyStoreHandle
DPS_NodeAddrNetwork
DPS_NodeAddrToString
DPS_PublicationAddSubId
DPS_PublicationGetNode
Expand Down
Loading