public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 2/7] alfred: Move tx finish functionality in extra function
Date: Sat, 12 Nov 2016 10:25:19 +0100	[thread overview]
Message-ID: <20161112092524.13170-2-sven@narfation.org> (raw)
In-Reply-To: <4404358.R7R4S15M79@sven-edge>

The process_alfred_status_txend has two main functionalities. It first
tries to find a transaction to be able to get its status. When it was found
then it either commits the data or just cleans it up.

The latter will be used by later by process_alfred_push_data to implement
out-of-order txend packets. Thus split process_alfred_status_txend now into
two functions to avoid code duplication.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 recv.c | 67 ++++++++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 39 insertions(+), 28 deletions(-)

diff --git a/recv.c b/recv.c
index b6b6eab..6878e5e 100644
--- a/recv.c
+++ b/recv.c
@@ -160,6 +160,44 @@ struct transaction_head *transaction_clean(struct globals *globals,
 	return head;
 }
 
+static int finish_alfred_transaction(struct globals *globals,
+				     struct transaction_head *head,
+				     struct ether_addr mac,
+				     uint16_t num_packets)
+{
+	struct transaction_packet *transaction_packet, *safe;
+
+	/* this transaction was already finished/dropped */
+	if (head->finished != 0)
+		return -1;
+
+	/* missing packets -> cleanup everything */
+	if (head->num_packet == num_packets)
+		head->finished = -1;
+	else
+		head->finished = 1;
+
+	list_for_each_entry_safe(transaction_packet, safe, &head->packet_list,
+				 list) {
+		if (head->finished == 1)
+			finish_alfred_push_data(globals, mac,
+						transaction_packet->push);
+
+		list_del(&transaction_packet->list);
+		free(transaction_packet->push);
+		free(transaction_packet);
+	}
+
+	transaction_clean(globals, head);
+
+	if (head->client_socket < 0)
+		free(head);
+	else
+		unix_sock_req_data_finish(globals, head);
+
+	return 1;
+}
+
 static int process_alfred_push_data(struct globals *globals,
 				    struct in6_addr *source,
 				    struct alfred_push_data_v0 *push)
@@ -313,7 +351,6 @@ static int process_alfred_status_txend(struct globals *globals,
 				       struct alfred_status_v0 *request)
 {
 	struct transaction_head search, *head;
-	struct transaction_packet *transaction_packet, *safe;
 	struct ether_addr mac;
 	int len, ret;
 
@@ -336,33 +373,7 @@ static int process_alfred_status_txend(struct globals *globals,
 	if (!head)
 		return -1;
 
-	/* this transaction was already finished/dropped */
-	if (head->finished != 0)
-		return -1;
-
-	/* missing packets -> cleanup everything */
-	if (head->num_packet != ntohs(request->tx.seqno))
-		head->finished = -1;
-	else
-		head->finished = 1;
-
-	list_for_each_entry_safe(transaction_packet, safe, &head->packet_list,
-				 list) {
-		if (head->finished == 1)
-			finish_alfred_push_data(globals, mac,
-						transaction_packet->push);
-
-		list_del(&transaction_packet->list);
-		free(transaction_packet->push);
-		free(transaction_packet);
-	}
-
-	transaction_clean(globals, head);
-
-	if (head->client_socket < 0)
-		free(head);
-	else
-		unix_sock_req_data_finish(globals, head);
+	finish_alfred_transaction(globals, head, mac, ntohs(request->tx.seqno));
 
 	return 0;
 }
-- 
2.10.2


  parent reply	other threads:[~2016-11-12  9:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-12  9:24 [B.A.T.M.A.N.] [PATCH 0/7] alfred: Allow out-of-order TXEND Sven Eckelmann
2016-11-12  9:25 ` [B.A.T.M.A.N.] [PATCH 1/7] alfred: Avoid hash search for transaction cleanup Sven Eckelmann
2016-11-12  9:25 ` Sven Eckelmann [this message]
2016-11-12  9:25 ` [B.A.T.M.A.N.] [PATCH 3/7] alfred: Remove checks for committed/dropped transaction Sven Eckelmann
2016-11-12  9:25 ` [B.A.T.M.A.N.] [PATCH 4/7] alfred: Don't force cleanup of transaction on TXEND Sven Eckelmann
2016-11-12  9:25 ` [B.A.T.M.A.N.] [PATCH 5/7] alfred: Use expected packet count to finished transactions Sven Eckelmann
2016-11-12  9:25 ` [B.A.T.M.A.N.] [PATCH 6/7] alfred: Allow PUSH_DATA to finish transactions Sven Eckelmann
2016-11-12  9:25 ` [B.A.T.M.A.N.] [PATCH 7/7] alfred: Allow TXEND to start new transaction Sven Eckelmann
2016-11-17 16:06 ` [B.A.T.M.A.N.] [PATCH 0/7] alfred: Allow out-of-order TXEND Simon Wunderlich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161112092524.13170-2-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox