Skip to contentSkip to conversation

alfred: Update version when adding data to dataset

PATCH Applied Sven Eckelmann 2 participants 5 messages Mar 7, 2015 – Mar 11, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 alfred: Update version when adding data to dataset

The dataset stores the source and the alfred_tlv of the send data next to the actual data buffer. The source and alfred_tlv::type was used to find an entry in the dataset hashtable when reading/updating the buffer. The alfred_tlv::length is always updated when the size of the associated buffer gets modified.

But the alfred_tlv::version is only written when receiving the first data for a dataset. But this initial (maybe outdated) version is always propagated when a client asks over the unix socket or the dataset is exchanged between alfred servers. This has to also be updated when new data is added to the dataset to avoid clients to interpret the data using the wrong data format version.

---
 recv.c      | 1 +
 unix_sock.c | 1 +
 2 files changed, 2 insertions(+)
recv.c +1 -0
index 34a16fc..e0252eb 100644
@@ -91,6 +91,7 @@ static int finish_alfred_push_data(struct globals *globals,
 			goto err;
 
 		dataset->data.header.length = data_len;
+		dataset->data.header.version = data->header.version;
 		memcpy(dataset->buf, data->data, data_len);
 
 		/* if the sender is also the the source of the dataset, we
unix_sock.c +1 -0
index ae86956..0707252 100644
@@ -151,6 +151,7 @@ static int unix_sock_add_data(struct globals *globals,
 		goto err;
 
 	dataset->data.header.length = data_len;
+	dataset->data.header.version = data->header.version;
 	memcpy(dataset->buf, data->data, data_len);
 
 	ret = 0;
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/2 alfred: Add option to the client to print extra data information

The version of a dataset can be queried using the parameter --verbose/-d. It is printed as third component of each dataset line when starting the unix client in request mode.

---
 alfred.h     | 1 +
 client.c     | 7 ++++++-
 main.c       | 7 ++++++-
 man/alfred.8 | 3 +++
 4 files changed, 16 insertions(+), 2 deletions(-)
alfred.h +1 -0
index ef00551..f26c80c 100644
@@ -113,6 +113,7 @@ struct globals {
 	enum clientmode clientmode;
 	int clientmode_arg;
 	int clientmode_version;
+	int verbose;
 
 	int unix_sock;
 	const char *unix_path;
client.c +6 -1
index 32fdd54..42dd4ad 100644
@@ -121,7 +121,12 @@ int alfred_client_request_data(struct globals *globals)
 				printf("%c", pos[i]);
 		}
 
-		printf("\" },\n");
+		printf("\"");
+
+		if (globals->verbose)
+			printf(", %u", data->header.version);
+
+		printf(" },\n");
 	}
 
 	unix_sock_close(globals);
main.c +6 -1
index d298d65..65948d3 100644
@@ -75,6 +75,7 @@ static struct globals *alfred_init(int argc, char *argv[])
 		{"change-interface",	required_argument,	NULL,	'I'},
 		{"unix-path",		required_argument,	NULL,	'u'},
 		{"version",		no_argument,		NULL,	'v'},
+		{"verbose",		no_argument,		NULL,	'd'},
 		{NULL,			0,			NULL,	0},
 	};
 
@@ -89,10 +90,11 @@ static struct globals *alfred_init(int argc, char *argv[])
 	globals->clientmode_version = 0;
 	globals->mesh_iface = "bat0";
 	globals->unix_path = ALFRED_SOCK_PATH_DEFAULT;
+	globals->verbose = 0;
 
 	time_random_seed();
 
-	while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:u:", long_options,
+	while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:u:d", long_options,
 				  &opt_ind)) != -1) {
 		switch (opt) {
 		case 'r':
@@ -149,6 +151,9 @@ static struct globals *alfred_init(int argc, char *argv[])
 		case 'u':
 			globals->unix_path = optarg;
 			break;
+		case 'd':
+			globals->verbose++;
+			break;
 		case 'v':
 			printf("%s %s\n", argv[0], SOURCE_VERSION);
 			printf("A.L.F.R.E.D. - Almighty Lightweight Remote Fact Exchange Daemon\n");
man/alfred.8 +3 -0
index 0449189..a8050ab 100644
@@ -67,6 +67,9 @@ alfred will forget about it (after 10 minutes).
 \fB\-r\fP, \fB\-\-request\fP \fIdata\-type\fP
 Collect data from the network and prints it on the network
 .TP
+\fB\-d\fP, \fB\-\-verbose\fP
+Show extra information in the data output
+.TP
 \fB\-V\fP, \fB\-\-req\-version\fP \fIversion\fP
 Specify the data version set for \fB\-s\fP
 
Signature · 1 line
2.1.4
#2 lore raw

PATCH v2 2/2 alfred: Add option to the client to print extra data information

In reply to Sven Eckelmann

The version of a dataset can be queried using the parameter --verbose/-d. It is printed as third component of each dataset line when starting the unix client in request mode.

---
v2: added missing info in usage/help output

---
 alfred.h     | 1 +
 client.c     | 7 ++++++-
 main.c       | 8 +++++++-
 man/alfred.8 | 3 +++
 4 files changed, 17 insertions(+), 2 deletions(-)
alfred.h +1 -0
index ef00551..f26c80c 100644
@@ -113,6 +113,7 @@ struct globals {
 	enum clientmode clientmode;
 	int clientmode_arg;
 	int clientmode_version;
+	int verbose;
 
 	int unix_sock;
 	const char *unix_path;
client.c +6 -1
index 32fdd54..42dd4ad 100644
@@ -121,7 +121,12 @@ int alfred_client_request_data(struct globals *globals)
 				printf("%c", pos[i]);
 		}
 
-		printf("\" },\n");
+		printf("\"");
+
+		if (globals->verbose)
+			printf(", %u", data->header.version);
+
+		printf(" },\n");
 	}
 
 	unix_sock_close(globals);
main.c +7 -1
index d298d65..72a17fc 100644
@@ -38,6 +38,7 @@ static void alfred_usage(void)
 	printf("                                      for the supplied data type (0-255)\n");
 	printf("  -r, --request [data type]           collect data from the network and prints\n");
 	printf("                                      it on the network\n");
+	printf("  -d, --verbose                       Show extra information in the data output\n");
 	printf("  -V, --req-version                   specify the data version set for -s\n");
 	printf("  -M, --modeswitch master             switch daemon to mode master\n");
 	printf("                   slave              switch daemon to mode slave\n");
@@ -75,6 +76,7 @@ static struct globals *alfred_init(int argc, char *argv[])
 		{"change-interface",	required_argument,	NULL,	'I'},
 		{"unix-path",		required_argument,	NULL,	'u'},
 		{"version",		no_argument,		NULL,	'v'},
+		{"verbose",		no_argument,		NULL,	'd'},
 		{NULL,			0,			NULL,	0},
 	};
 
@@ -89,10 +91,11 @@ static struct globals *alfred_init(int argc, char *argv[])
 	globals->clientmode_version = 0;
 	globals->mesh_iface = "bat0";
 	globals->unix_path = ALFRED_SOCK_PATH_DEFAULT;
+	globals->verbose = 0;
 
 	time_random_seed();
 
-	while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:u:", long_options,
+	while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:u:d", long_options,
 				  &opt_ind)) != -1) {
 		switch (opt) {
 		case 'r':
@@ -149,6 +152,9 @@ static struct globals *alfred_init(int argc, char *argv[])
 		case 'u':
 			globals->unix_path = optarg;
 			break;
+		case 'd':
+			globals->verbose++;
+			break;
 		case 'v':
 			printf("%s %s\n", argv[0], SOURCE_VERSION);
 			printf("A.L.F.R.E.D. - Almighty Lightweight Remote Fact Exchange Daemon\n");
man/alfred.8 +3 -0
index 0449189..a8050ab 100644
@@ -67,6 +67,9 @@ alfred will forget about it (after 10 minutes).
 \fB\-r\fP, \fB\-\-request\fP \fIdata\-type\fP
 Collect data from the network and prints it on the network
 .TP
+\fB\-d\fP, \fB\-\-verbose\fP
+Show extra information in the data output
+.TP
 \fB\-V\fP, \fB\-\-req\-version\fP \fIversion\fP
 Specify the data version set for \fB\-s\fP
 
Signature · 1 line
2.1.4
#4 lore raw
In reply to Sven Eckelmann
Quoted 6 lines · On Saturday 07 March 2015 23:41:17 Sven Eckelmann wrote:

The dataset stores the source and the alfred_tlv of the send data next to the actual data buffer. The source and alfred_tlv::type was used to find an entry in the dataset hashtable when reading/updating the buffer. The alfred_tlv::length is always updated when the size of the associated buffer gets modified.

Quoted 7 lines

But the alfred_tlv::version is only written when receiving the first data for a dataset. But this initial (maybe outdated) version is always propagated when a client asks over the unix socket or the dataset is exchanged between alfred servers. This has to also be updated when new data is added to the dataset to avoid clients to interpret the data using the wrong data format version.

Applied in revision 17d1102.

Thanks!
Simon

#3 lore raw

Re: [B.A.T.M.A.N.] [PATCHv2 2/2] alfred: Add option to the client to print extra data information

In reply to Sven Eckelmann
Quoted 7 lines · On Saturday 07 March 2015 23:45:53 Sven Eckelmann wrote:

The version of a dataset can be queried using the parameter --verbose/-d. It is printed as third component of each dataset line when starting the unix client in request mode.

---
v2: added missing info in usage/help output

Applied in revision b8210c0.

Thanks!
Simon