alfred: Update version when adding data to dataset
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
@@ -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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 2/2 alfred: Add option to the client to print extra data information
In reply to Sven EckelmannThe 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
@@ -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
@@ -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
@@ -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
@@ -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
Simon Wunderlich
AppliedRe: [B.A.T.M.A.N.] [PATCHv2 2/2] alfred: Add option to the client to print extra data information
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.
Signed-off-by Sven Eckelmann <[email protected]>---
v2: added missing info in usage/help output
Applied in revision b8210c0.
Thanks!
Simon
Simon Wunderlich
AppliedQuoted 6 lines · On Saturday 07 March 2015 23:41:17 Sven Eckelmann wrote:
The dataset stores the source and the
alfred_tlvof the send data next to the actual data buffer. The source andalfred_tlv::typewas used to find an entry in the dataset hashtable when reading/updating the buffer. Thealfred_tlv::lengthis always updated when the size of the associated buffer gets modified.
Quoted 7 lines
But the
alfred_tlv::versionis 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