From patchwork Sat Nov 12 09:25:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 16847 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 1539C83261; Sat, 12 Nov 2016 10:26:04 +0100 (CET) Authentication-Results: open-mesh.org; dmarc=none header.from=narfation.org Authentication-Results: open-mesh.org; dkim=fail reason="verification failed; unprotected key" header.d=narfation.org header.i=@narfation.org header.b=ydNYl10h; dkim-adsp=fail (unprotected policy); dkim-atps=neutral Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2001:4d88:2000:7::2; helo=v3-1039.vlinux.de; envelope-from=sven@narfation.org; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=pass header.from=narfation.org Received: from v3-1039.vlinux.de (narfation.org [IPv6:2001:4d88:2000:7::2]) by open-mesh.org (Postfix) with ESMTPS id 3C0F383258 for ; Sat, 12 Nov 2016 10:25:42 +0100 (CET) Received: from sven-desktop.home.narfation.org (p200300C593D3C6FDDB07A9EADAF9B442.dip0.t-ipconnect.de [IPv6:2003:c5:93d3:c6fd:db07:a9ea:daf9:b442]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 594D21100D6; Sat, 12 Nov 2016 10:25:40 +0100 (CET) Authentication-Results: v3-1039.vlinux.de; dmarc=none header.from=narfation.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=narfation.org; s=20121; t=1478942740; bh=Ze0wBr3OKOVApiWGetvkJxdbm4kdGu6vpMEEmDABtX4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ydNYl10h7XAXLZmdbLVf/KsOOOVXnEphLA/fIc5OGzUFnThgoDk0U7uLCeQ1Lo8n0 kJUFCpVFyViDESAYD0cL5sfSV0UvPjL7UBL3QaEMA8fVm/PhTMIVZcEHuYouF6SuRW OjrkzsdMfcE+kdOuI8yAuzOFRa89ND/lYzFuJV2k= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Sat, 12 Nov 2016 10:25:22 +0100 Message-Id: <20161112092524.13170-5-sven@narfation.org> X-Mailer: git-send-email 2.10.2 In-Reply-To: <4404358.R7R4S15M79@sven-edge> References: <4404358.R7R4S15M79@sven-edge> Subject: [B.A.T.M.A.N.] [PATCH 5/7] alfred: Use expected packet count to finished transactions X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" The TXEND packet will specify the number of PUSH_DATA packets are required to finish a transaction. This number has therefore to be stored when a TXEND packet is receiver to later be able to decide whether the transaction can be finished or not. Signed-off-by: Sven Eckelmann --- alfred.h | 8 +++++++- recv.c | 11 +++++------ unix_sock.c | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/alfred.h b/alfred.h index 9d0f6a6..eb8200c 100644 --- a/alfred.h +++ b/alfred.h @@ -71,7 +71,7 @@ struct transaction_head { struct ether_addr server_addr; uint16_t id; uint8_t requested_type; - uint16_t finished; + uint16_t txend_packets; int num_packet; int client_socket; struct timespec last_rx_time; @@ -161,6 +161,12 @@ struct transaction_head * transaction_add(struct globals *globals, struct ether_addr mac, uint16_t id); struct transaction_head *transaction_clean(struct globals *globals, struct transaction_head *head); + +static inline bool transaction_finished(struct transaction_head *head) +{ + return head->txend_packets == head->num_packet; +} + /* send.c */ int push_data(struct globals *globals, struct interface *interface, struct in6_addr *destination, enum data_source max_source_level, diff --git a/recv.c b/recv.c index dd0b021..1f56016 100644 --- a/recv.c +++ b/recv.c @@ -131,7 +131,7 @@ transaction_add(struct globals *globals, struct ether_addr mac, uint16_t id) head->server_addr = mac; head->id = id; head->requested_type = 0; - head->finished = 0; + head->txend_packets = 0; head->num_packet = 0; head->client_socket = -1; clock_gettime(CLOCK_MONOTONIC, &head->last_rx_time); @@ -162,16 +162,14 @@ struct transaction_head *transaction_clean(struct globals *globals, static int finish_alfred_transaction(struct globals *globals, struct transaction_head *head, - struct ether_addr mac, - uint16_t num_packets) + struct ether_addr mac) { struct transaction_packet *transaction_packet, *safe; /* finish when all packets received */ - if (head->num_packet != num_packets) + if (!transaction_finished(head)) return 0; - head->finished = 1; list_for_each_entry_safe(transaction_packet, safe, &head->packet_list, list) { finish_alfred_push_data(globals, mac, transaction_packet->push); @@ -362,7 +360,8 @@ static int process_alfred_status_txend(struct globals *globals, if (!head) return -1; - finish_alfred_transaction(globals, head, mac, ntohs(request->tx.seqno)); + head->txend_packets = ntohs(request->tx.seqno); + finish_alfred_transaction(globals, head, mac); return 0; } diff --git a/unix_sock.c b/unix_sock.c index 150ad32..edc7e0b 100644 --- a/unix_sock.c +++ b/unix_sock.c @@ -276,7 +276,7 @@ int unix_sock_req_data_finish(struct globals *globals, requested_type = head->requested_type; id = head->id; client_sock = head->client_socket; - if (head->finished != 1) + if (!transaction_finished(head)) send_data = 0; free(head);