Repository : ssh://git@open-mesh.org/alfred
On branch : master
commit 5972745fb2e9979cd79fec3266f0e12bd37f1664 Author: Sven Eckelmann sven@open-mesh.com Date: Fri Jan 11 20:30:36 2013 +0100
alfred: Add transaction id to request packets
The request sent by a slave has to start a transaction. Otherwise it is not possible to distinct for him the incoming data without an extra handshaking protocol. The request packets get an extra field to store the requested transaction identifier.
Signed-off-by: Sven Eckelmann sven@open-mesh.com
5972745fb2e9979cd79fec3266f0e12bd37f1664 alfred.h | 3 ++- client.c | 4 +++- packet.h | 2 ++ recv.c | 3 ++- send.c | 9 +++++---- unix_sock.c | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/alfred.h b/alfred.h index e885e2a..bab2049 100644 --- a/alfred.h +++ b/alfred.h @@ -107,7 +107,8 @@ int alfred_client_set_data(struct globals *globals); int recv_alfred_packet(struct globals *globals); /* send.c */ int push_data(struct globals *globals, struct in6_addr *destination, - enum data_source max_source_level, int type_filter); + enum data_source max_source_level, int type_filter, + uint16_t tx_id); int announce_master(struct globals *globals); int push_local_data(struct globals *globals); int sync_data(struct globals *globals); diff --git a/client.c b/client.c index 7c7cb4d..90b9f02 100644 --- a/client.c +++ b/client.c @@ -47,8 +47,10 @@ int alfred_client_request_data(struct globals *globals)
request->header.type = ALFRED_REQUEST; request->header.version = ALFRED_VERSION; - request->header.length = htons(1); + request->header.length = sizeof(*request) - sizeof(request->header); + request->header.length = htons(request->header.length); request->requested_type = globals->clientmode_arg; + request->tx_id = get_random_id();
ret = write(globals->unix_sock, buf, len); if (ret != len) diff --git a/packet.h b/packet.h index a01015d..f40a4e9 100644 --- a/packet.h +++ b/packet.h @@ -106,12 +106,14 @@ struct alfred_announce_master_v0 { * struct alfred_request_v0 - Request for a specific type * @header: TLV header describing the complete packet * @requested_type: data type which is requested + * @tx_id: random identificator used for this transaction * * Sent as unicast to the node storing it */ struct alfred_request_v0 { struct alfred_tlv header; uint8_t requested_type; + uint16_t tx_id; } __packed;
#define ALFRED_VERSION 0 diff --git a/recv.c b/recv.c index 20da0ee..f7be8f3 100644 --- a/recv.c +++ b/recv.c @@ -179,7 +179,8 @@ static int process_alfred_request(struct globals *globals, if (len != (sizeof(*request) - sizeof(request->header))) return -1;
- push_data(globals, source, SOURCE_SYNCED, request->requested_type); + push_data(globals, source, SOURCE_SYNCED, request->requested_type, + request->tx_id);
return 0; } diff --git a/send.c b/send.c index e378ed4..138ed43 100644 --- a/send.c +++ b/send.c @@ -48,7 +48,8 @@ int announce_master(struct globals *globals) }
int push_data(struct globals *globals, struct in6_addr *destination, - enum data_source max_source_level, int type_filter) + enum data_source max_source_level, int type_filter, + uint16_t tx_id) { struct hash_it_t *hashit = NULL; uint8_t buf[MAX_PAYLOAD]; @@ -61,7 +62,7 @@ int push_data(struct globals *globals, struct in6_addr *destination, push = (struct alfred_push_data_v0 *)buf; push->header.type = ALFRED_PUSH_DATA; push->header.version = ALFRED_VERSION; - push->tx.id = get_random_id(); + push->tx.id = tx_id;
while (NULL != (hashit = hash_iterate(globals->data_hash, hashit))) { struct dataset *dataset = hashit->bucket->data; @@ -117,7 +118,7 @@ int sync_data(struct globals *globals) struct server *server = hashit->bucket->data;
push_data(globals, &server->address, SOURCE_FIRST_HAND, - NO_FILTER); + NO_FILTER, get_random_id()); } return 0; } @@ -129,7 +130,7 @@ int push_local_data(struct globals *globals) return -1;
push_data(globals, &globals->best_server->address, SOURCE_LOCAL, - NO_FILTER); + NO_FILTER, get_random_id());
return 0; } diff --git a/unix_sock.c b/unix_sock.c index fc50436..037761e 100644 --- a/unix_sock.c +++ b/unix_sock.c @@ -206,7 +206,7 @@ send_reply: push = (struct alfred_push_data_v0 *)buf; push->header.type = ALFRED_PUSH_DATA; push->header.version = ALFRED_VERSION; - push->tx.id = get_random_id(); + push->tx.id = request->tx_id;
while (NULL != (hashit = hash_iterate(globals->data_hash, hashit))) { struct dataset *dataset = hashit->bucket->data;