tCheck sync status amongst a peer list - synk - synchronize files between hosts
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 7e527e7825ec47e18fbba3ebb88ef9910bfa5ec4
(DIR) parent c20b5a3174a84d877f65d2885ec681943e67751f
(HTM) Author: Willy <willyatmailoodotorg>
Date: Tue, 30 Aug 2016 22:33:09 +0200
Check sync status amongst a peer list
Diffstat:
M synk.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/synk.c b/synk.c
t@@ -56,6 +56,7 @@ long gettimestamp(const char *path);
int getpeermeta(struct peer_t *, struct metadata_t);
struct peer_t *freshestpeer(struct peers_t *);
int syncfile(struct peers_t *, const char *);
+int syncstatus(struct peers_t *);
int flushpeers(struct peers_t *);
const char *rsync_cmd[] = { "rsync", "-azEq", "--delete", NULL };
t@@ -222,6 +223,28 @@ flushpeers(struct peers_t *plist)
}
/*
+ * Check the synchronisation status between all peers. If at least 2 hashes
+ * differ, it returns with a non-zero status.
+ */
+int
+syncstatus(struct peers_t *plist)
+{
+ struct peer_t *tmp = NULL;
+ unsigned char *hash = NULL;
+
+ SLIST_FOREACH(tmp, plist, entries) {
+ if (hash == NULL) {
+ hash = tmp->meta.hash;
+ } else {
+ if (!sha512_compare(hash, tmp->meta.hash))
+ return 1;
+ }
+ }
+
+ return 1;
+}
+
+/*
* Client part: connect to the given address/port and send the given path to
* the server. The server should return the timestamp for this file on the
* socket. Connection is terminated after receiving the timestamp