Convert CLD network protocol from UDP to TCP. Server, client lib,
and chunkd's cldu module are all updated. tabled's cldu module must
be updated also.
The original rationale for UDP use was following Google's lead, based
on the advice in the original Chubby paper, describing TCP's back-off
policies and other behavior during times of high network congestion.
This seems a bit dubious without further third party evidence, and TCP
vastly simplifies our lives. While the code remains open and modular
enough to support other protocols (hopefully RDMA or SCTP one day),
this upgrade from UDP to TCP promises to make the current codebase
much easier to use, while avoiding the reinvent TCP, by using UDP
problem, which was a rabbit hole threatening CLD.
Signed-off-by: Jeff Garzik jgar...@redhat.com
---
chunkd/cldu.c|6
cld/cld.h| 43 ++
cld/msg.c|4
cld/server.c | 356 ---
cld/session.c|4
configure.ac |1
include/Makefile.am |2
include/cld_common.h |4
include/cldc.h | 24 ++-
include/ncld.h |4
include/ubbp.h | 52 +++
lib/Makefile.am |2
lib/cldc-dns.c |2
lib/cldc-tcp.c | 185 ++
lib/cldc-udp.c | 141
lib/cldc.c | 54 +++
16 files changed, 595 insertions(+), 289 deletions(-)
diff --git a/chunkd/cldu.c b/chunkd/cldu.c
index 026c523..41f94b5 100644
--- a/chunkd/cldu.c
+++ b/chunkd/cldu.c
@@ -165,7 +165,7 @@ static void cldu_sess_event(void *priv, uint32_t what)
*/
if (cs-nsess) {
applog(LOG_ERR, Session failed, sid SIDFMT,
- SIDARG(cs-nsess-udp-sess-sid));
+ SIDARG(cs-nsess-tcp-sess-sid));
} else {
applog(LOG_ERR, Session open failed);
}
@@ -177,7 +177,7 @@ static void cldu_sess_event(void *priv, uint32_t what)
} else {
if (cs)
applog(LOG_INFO, cldc event 0x%x sid SIDFMT,
- what, SIDARG(cs-nsess-udp-sess-sid));
+ what, SIDARG(cs-nsess-tcp-sess-sid));
else
applog(LOG_INFO, cldc event 0x%x no sid, what);
}
@@ -372,7 +372,7 @@ static int cldu_set_cldc(struct cld_session *cs, int
newactive)
}
applog(LOG_INFO, New CLD session created, sid SIDFMT,
- SIDARG(cs-nsess-udp-sess-sid));
+ SIDARG(cs-nsess-tcp-sess-sid));
/*
* First, make sure the base directory exists.
diff --git a/cld/cld.h b/cld/cld.h
index 17f14b8..b1f9bbf 100644
--- a/cld/cld.h
+++ b/cld/cld.h
@@ -30,6 +30,7 @@
#include cld_common.h
#include hail_log.h
#include hail_private.h
+#include ubbp.h
struct client;
struct session_outpkt;
@@ -43,10 +44,39 @@ enum {
SFL_FOREGROUND = (1 0), /* run in foreground */
};
+struct atcp_read {
+ void*buf;
+ unsigned intbuf_size;
+ unsigned intbytes_wanted;
+ unsigned intbytes_read;
+
+ void(*cb)(void *, bool);
+ void*cb_data;
+
+ struct list_headnode;
+};
+
+struct atcp_read_state {
+ struct list_headq;
+};
+
struct client {
+ int fd;
+
+ struct eventev;
+ short ev_mask;/* EV_READ and/or EV_WRITE */
+
struct sockaddr_in6 addr; /* inet address */
socklen_t addr_len; /* inet address len */
charaddr_host[64]; /* ASCII version of inet addr */
+ charaddr_port[16]; /* ASCII version of inet addr */
+
+ struct atcp_read_state rst;
+
+ struct ubbp_header ubbp;
+
+ charraw_pkt[CLD_RAW_MSG_SZ];
+ unsigned intraw_size;
};
struct session {
@@ -124,6 +154,17 @@ struct pkt_info {
size_t hdr_len;
};
+#define ___constant_swab32(x) ((uint32_t)( \
+(((uint32_t)(x) (uint32_t)0x00ffUL) 24) |\
+(((uint32_t)(x) (uint32_t)0xff00UL) 8) |\
+(((uint32_t)(x) (uint32_t)0x00ffUL) 8) |\
+(((uint32_t)(x) (uint32_t)0xff00UL) 24)))
+
+static inline uint32_t swab32(uint32_t v)
+{
+ return ___constant_swab32(v);
+}
+
/* msg.c */
extern int inode_lock_rescan(DB_TXN *txn, cldino_t inum);
extern void msg_get(struct session *sess, const void *v);
@@ -178,7 +219,7 @@ extern int sess_load(GHashTable *ss);
extern struct server cld_srv;
extern struct hail_log srv_log;
extern struct timeval current_time;
-extern int udp_tx(int