From patchwork Wed May 24 10:32:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17023 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 262C983804; Wed, 24 May 2017 12:34:38 +0200 (CEST) Authentication-Results: open-mesh.org; dmarc=none header.from=openmesh.com Authentication-Results: open-mesh.org; dkim=fail reason="verification failed; unprotected key" header.d=openmesh-com.20150623.gappssmtp.com header.i=@openmesh-com.20150623.gappssmtp.com header.b=e6bkWQ5H; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com [IPv6:2a00:1450:400c:c09::235]) by open-mesh.org (Postfix) with ESMTPS id 4BAB2837EB for ; Wed, 24 May 2017 12:32:30 +0200 (CEST) Authentication-Results: open-mesh.org; dmarc=none header.from=openmesh.com Received: by mail-wm0-x235.google.com with SMTP id e127so68542564wmg.1 for ; Wed, 24 May 2017 03:32:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openmesh-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gH+KobKWIGZ++mppHH71Ap28WD6HaEnIT9PkiHyl+h8=; b=e6bkWQ5Hc/VD9REzd+9+zU82uXdbYT176YVBEskUknaKY6Kz0XrEsLTa1tSq/QVacT 9r3xdvchkbmYDfZm6yGpLczuD6+Q16ZisoTlSd5tnIoK56clGgLdJPwvC521yadlXFl/ iZPViaZ/SQREwSee3ozOyeCfoMzCG7LKeEG+7g1SUwUXrp/4v82dpkpNENq4Wbb0e6vc D+aBt2SL8lcr1u8kqjj+mUb8yXzRR4yJyDZWqMhebbU7XjAEP2sCkVrabcCKHoYUx/Nu B2BmiPIb9IaNh2r3u1tMmSudiAORgRNs6Hjq+Ws8ICYKjSflC426AIK3z6jB6u7K0muh 82KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gH+KobKWIGZ++mppHH71Ap28WD6HaEnIT9PkiHyl+h8=; b=Q7kGd5rZXMAYxd49GKtPsRjtAcYyyyITN0T1h6YZtPE7JpZ2sfZq9CiZhP5dW25nY3 t9WcgbbDMe1eIOJXfckL9c51XIUWjBuxczy2q2+IkM8csZQsJiAV0IZqWzxPy4BEbIhS TiH0jk3WcdlfMfrD+pht1veNDtlupuy/f6MpVyUqkIJ5wlcrxoGm8G3fu+0MfchENEs4 W/uzuBg4gli39WU2Jpip/CUKerbj19Y/FheetlsFpJRLkfRPt074/rhHWQUyKix7FFco B6Xup8mKmVcyM9OTPaFphCLyMc9dAik53Aj2b6Qyq9F0IkwN/hgzBNEuyzut7IYajHWD 9lEQ== X-Gm-Message-State: AODbwcANZBQw9XHnLFNSFEXcKesxaT4If5P0/vZNR9M2gJvgNabemJo2 1Y4IIau7JiQphi69KDw= X-Received: by 10.28.31.135 with SMTP id f129mr6072844wmf.78.1495621949642; Wed, 24 May 2017 03:32:29 -0700 (PDT) Received: from sven-desktop.home.narfation.org (p2003007C6F5B7CFE527B9DFFFECE2683.dip0.t-ipconnect.de. [2003:7c:6f5b:7cfe:527b:9dff:fece:2683]) by smtp.gmail.com with ESMTPSA id 17sm4307282wml.32.2017.05.24.03.32.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 24 May 2017 03:32:29 -0700 (PDT) From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 24 May 2017 12:32:09 +0200 Message-Id: <20170524103211.810-3-sven.eckelmann@openmesh.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <4690435.IOLn72U8Ez@bentobox> References: <4690435.IOLn72U8Ez@bentobox> X-Mailman-Approved-At: Wed, 24 May 2017 12:34:12 +0200 Cc: Sven Eckelmann Subject: [B.A.T.M.A.N.] [PATCH 3/5] alfred: Check the TQ of master servers before pushing data 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 TQ value of the server might have changed dramatically since we received the last announcement of a master server. This can especially happen when node (which was previously the best server) moves a lot and its announcements are lost for a while. Instead of querying the TQ values of each node when receiving an announcement, just query the TQ value before new data should be pushed to a master server. Signed-off-by: Sven Eckelmann --- alfred.h | 1 - recv.c | 21 +-------------------- server.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/alfred.h b/alfred.h index 5f7a98c..429953f 100644 --- a/alfred.h +++ b/alfred.h @@ -153,7 +153,6 @@ extern alfred_addr alfred_mcast; /* server.c */ int alfred_server(struct globals *globals); -int set_best_server(struct globals *globals); void changed_data_type(struct globals *globals, uint8_t arg); /* client.c */ diff --git a/recv.c b/recv.c index 8aa512d..12bb3f1 100644 --- a/recv.c +++ b/recv.c @@ -268,7 +268,6 @@ process_alfred_announce_master(struct globals *globals, struct alfred_announce_master_v0 *announce) { struct server *server; - struct ether_addr *macaddr; struct ether_addr mac; int ret; int len; @@ -296,6 +295,7 @@ process_alfred_announce_master(struct globals *globals, memcpy(&server->hwaddr, &mac, ETH_ALEN); memcpy(&server->address, source, sizeof(*source)); + server->tq = 0; if (hash_add(interface->server_hash, server)) { free(server); @@ -305,25 +305,6 @@ process_alfred_announce_master(struct globals *globals, clock_gettime(CLOCK_MONOTONIC, &server->last_seen); - /* TQ is not used for master sync mode */ - if (globals->opmode == OPMODE_MASTER) { - server->tq = 0; - return 0; - } - - if (strcmp(globals->mesh_iface, "none") != 0) { - macaddr = translate_mac(globals->mesh_iface, - (struct ether_addr *)&server->hwaddr); - if (macaddr) - server->tq = get_tq(globals->mesh_iface, macaddr); - else - server->tq = 0; - } else { - server->tq = 255; - } - - set_best_server(globals); - return 0; } diff --git a/server.c b/server.c index 2c4042a..09acb80 100644 --- a/server.c +++ b/server.c @@ -113,7 +113,7 @@ static int create_hashes(struct globals *globals) return 0; } -int set_best_server(struct globals *globals) +static int set_best_server(struct globals *globals) { struct hash_it_t *hashit = NULL; struct server *best_server = NULL; @@ -218,6 +218,39 @@ static int purge_data(struct globals *globals) return 0; } +static void update_server_info(struct globals *globals) +{ + struct hash_it_t *hashit = NULL; + struct interface *interface; + struct ether_addr *macaddr; + + /* TQ is not used for master sync mode */ + if (globals->opmode == OPMODE_MASTER) + return; + + list_for_each_entry(interface, &globals->interfaces, list) { + while (NULL != (hashit = hash_iterate(interface->server_hash, + hashit))) { + struct server *server = hashit->bucket->data; + + if (strcmp(globals->mesh_iface, "none") == 0) { + server->tq = 255; + continue; + } + + macaddr = translate_mac(globals->mesh_iface, + &server->hwaddr); + if (macaddr) + server->tq = get_tq(globals->mesh_iface, + macaddr); + else + server->tq = 0; + } + } + + set_best_server(globals); +} + static void check_if_socket(struct interface *interface, struct globals *globals) { int sock; @@ -422,6 +455,7 @@ int alfred_server(struct globals *globals) sync_data(globals); } else { /* send local data to server */ + update_server_info(globals); push_local_data(globals); } purge_data(globals);