Repository : ssh://git@open-mesh.org/alfred
On branch : master
commit 6afecbe687210db175f063f8ca86ce839fad7a08 Author: Sven Eckelmann sven@open-mesh.com Date: Thu Jan 17 10:15:44 2013 +0100
alfred: Send a tx end packet after data was pushed
The transaction for a transfer must be checked before the receiver can move the data to the own data hash. The basic check will use the amount of data transferred. The sender uses a txend packet including the necessary information.
Signed-off-by: Sven Eckelmann sven@open-mesh.com
6afecbe687210db175f063f8ca86ce839fad7a08 packet.h | 20 ++++++++++++++++++++ send.c | 14 ++++++++++++++ 2 files changed, 34 insertions(+)
diff --git a/packet.h b/packet.h index f40a4e9..e859d8d 100644 --- a/packet.h +++ b/packet.h @@ -66,11 +66,15 @@ struct alfred_transaction_mgmt { * @ALFRED_PUSH_DATA: Packet is an alfred_push_data_v* * @ALFRED_ANNOUNCE_MASTER: Packet is an alfred_announce_master_v* * @ALFRED_REQUEST: Packet is an alfred_request_v* + * @ALFRED_STATUS_TXEND: Transaction was finished by sender + * @ALFRED_STATUS_ERROR: Error was detected during the transaction */ enum alfred_packet_type { ALFRED_PUSH_DATA = 0, ALFRED_ANNOUNCE_MASTER = 1, ALFRED_REQUEST = 2, + ALFRED_STATUS_TXEND = 3, + ALFRED_STATUS_ERROR = 4, };
/* packets */ @@ -116,6 +120,22 @@ struct alfred_request_v0 { uint16_t tx_id; } __packed;
+/** + * struct alfred_status_v0 - Status info of a transaction + * @header: TLV header describing the complete packet + * @tx: Transaction identificator and sequence number of packet + * + * The sequence number has a special meaning. Failure status packets use + * it to store the error code. Success status packets store the number of + * transfered packets in it. + * + * Sent as unicast to the node requesting the data + */ +struct alfred_status_v0 { + struct alfred_tlv header; + struct alfred_transaction_mgmt tx; +} __packed; + #define ALFRED_VERSION 0 #define ALFRED_PORT 0x4242 #define ALFRED_MAX_RESERVED_TYPE 64 diff --git a/send.c b/send.c index 138ed43..588dac1 100644 --- a/send.c +++ b/send.c @@ -58,6 +58,8 @@ int push_data(struct globals *globals, struct in6_addr *destination, uint16_t total_length = 0; size_t tlv_length; uint16_t seqno = 0; + uint16_t length; + struct alfred_status_v0 status_end;
push = (struct alfred_push_data_v0 *)buf; push->header.type = ALFRED_PUSH_DATA; @@ -105,6 +107,18 @@ int push_data(struct globals *globals, struct in6_addr *destination, sizeof(*push) + total_length); }
+ /* send transaction txend packet */ + status_end.header.type = ALFRED_STATUS_TXEND; + status_end.header.version = ALFRED_VERSION; + length = sizeof(status_end) - sizeof(status_end.header); + status_end.header.length = htons(length); + + status_end.tx.id = tx_id; + status_end.tx.seqno = htons(seqno); + + send_alfred_packet(globals, destination, &status_end, + sizeof(status_end)); + return 0; }