chunkd: clone chunksrv_req to chunksrv_resp
PATCH 1/1 chunkd: clone chunksrv_req to chunksrv_resp
This just-committed change prepares for a more significant protocol change later on (variable-length keys in requests).
This is a network protocol change, though a minor one you probably won't notice, due to the chunksrv_req/chunksrv_resp structures currently being twins (that will soon change).
commit 69cf0ae597fd83086c1746a02c776b0bc05d591e
Author: Jeff Garzik <[email protected]> Date: Wed Nov 4 16:44:34 2009 -0500
Clone chunksrv_req into new chunksrv_resp, to separate request and response messages.
- resp_code removed from chunksrv_req
- s/checksum/sig/ in chunksrv_req
- req_len() used to calculate request size (preparation for future)
- resp_init_req() used to init response from request, rather than memcpy()
- improve data-in debugging
include/chunk_msg.h +13 -1
@@ -10,6 +10,7 @@ enum {CHD_USER_SZ =64 ,CHD_KEY_SZ =64 ,CHD_CSUM_SZ =64 , + CHD_SIG_SZ = 64, }; enum chunksrv_ops {
@@ -37,6 +38,17 @@ enum errcode {struct chunksrv_req {uint8_t magic[CHD_MAGIC_SZ ];/* CHUNKD_MAGIC */ uint8_t op;/* CHO_xxx */ +uint8_t rsv1[3 ]; +uint32_t nonce;/* random number, to stir checksum */ +uint64_t data_len;/* len of addn'l data */ +char user[CHD_USER_SZ ];/* username */ +char key[CHD_KEY_SZ ];/* object id */ +char sig[CHD_SIG_SZ ];/* HMAC signature */ +}; + +struct chunksrv_resp { +uint8_t magic[CHD_MAGIC_SZ ];/* CHUNKD_MAGIC */ +uint8_t op;/* CHO_xxx */ uint8_t resp_code;/* errcode's */ uint8_t rsv1[2 ];uint32_t nonce;/* random number, to stir checksum */
@@ -47,7 +59,7 @@ struct chunksrv_req { };struct chunksrv_resp_get { -struct chunksrv_req req; +struct chunksrv_resp resp;uint64_t mtime; };
include/chunksrv.h +1 -0
@@ -3,6 +3,7 @@#include <chunk_msg.h> +extern size_t req_len (const struct chunksrv_req *req);extern void chreq_sign (struct chunksrv_req *req,const char *key,char *b64hmac_out);
lib/chunkdc.c +40 -39
227 lines not on this page · raw message
lib/chunksrv.c +5 -0
@@ -5,6 +5,11 @@#include <glib.h> #include <chunk_msg.h> +size_t req_len (const struct chunksrv_req *req) +{ +return sizeof (*req); +} +void chreq_sign (struct chunksrv_req *req,const char *key,char *b64hmac_out) {unsigned int len =0 ;
server/chunkd.h +2 -0
@@ -256,6 +256,8 @@ extern bool cli_write_start(struct client *cli);extern int cli_req_avail (struct client *cli);extern int cli_poll_mod (struct client *cli);extern bool srv_poll_del (int fd); +extern void resp_init_req (struct chunksrv_resp *resp, +const struct chunksrv_req *req);/* config.c */ extern void read_config (void );
server/object.c +31 -24
137 lines not on this page · raw message
server/server.c +22 -9
@@ -269,6 +269,18 @@ static bool srv_poll_mask(int fd, short mask_set, short mask_clear)return true; } +void resp_init_req (struct chunksrv_resp *resp, +const struct chunksrv_req *req) +{ +memset (resp,0 ,sizeof (*resp)); +memcpy (resp->magic, req->magic,CHD_MAGIC_SZ ); + resp->op = req->op; + resp->nonce = req->nonce; + resp->data_len = req->data_len; +strncpy (resp->user, req->user,CHD_USER_SZ ); +strncpy (resp->key, req->key,CHD_KEY_SZ ); +} +static bool cli_write_free (struct client *cli,struct client_write *tmp,bool done) {
@@ -648,7 +660,7 @@ out:bool cli_err (struct client *cli,enum errcode code,bool recycle_ok) {int rc; -struct chunksrv_req *resp =NULL ; +struct chunksrv_resp *resp =NULL ;if (code != Success) applog(LOG_INFO, "client %s error %s",
@@ -660,7 +672,7 @@ bool cli_err(struct client *cli, enum errcode code, bool recycle_ok)return true; } -memcpy (resp, &cli->creq,sizeof (cli->creq)); +resp_init_req (resp, &cli->creq); resp->resp_code = code;
@@ -683,7 +695,7 @@ static bool cli_resp_xml(struct client *cli, GList *content)int rc;bool rcb;size_t content_len =strlist_len (content); -struct chunksrv_req *resp =NULL ; +struct chunksrv_resp *resp =NULL ; resp =malloc (sizeof (*resp));if (!resp) {
@@ -691,7 +703,7 @@ static bool cli_resp_xml(struct client *cli, GList *content)return true; } -memcpy (resp, &cli->creq,sizeof (cli->creq)); +resp_init_req (resp, &cli->creq); resp->data_len =cpu_to_le64 (content_len);
@@ -787,14 +799,14 @@ static bool authcheck(const struct chunksrv_req *req)char hmac[64 ];memcpy (&tmpreq, req,sizeof (tmpreq)); -memset (&tmpreq.checksum,0 ,sizeof (tmpreq.checksum)); +memset (&tmpreq.sig,0 ,sizeof (tmpreq.sig));/* for lack of a better authentication scheme, we * supply the username as the secret key */ chreq_sign (&tmpreq, req->user, hmac); -return strcmp (req->checksum, hmac) ? false : true; +return strcmp (req->sig, hmac) ? false : true; }static bool valid_req_hdr (const struct chunksrv_req *req)
@@ -812,8 +824,8 @@ static bool valid_req_hdr(const struct chunksrv_req *req)if (len ==sizeof (req->key))return false; - len =strnlen (req->checksum,sizeof (req->checksum)); -if (len <1 || len ==sizeof (req->checksum)) + len =strnlen (req->sig,sizeof (req->sig)); +if (len <1 || len ==sizeof (req->sig))return false;return true;
@@ -912,7 +924,8 @@ static bool cli_evt_read_req(struct client *cli, unsigned int events) cli->req_ptr += rc; cli->req_used += rc; -if (cli->req_used <sizeof (cli->creq)) +/* poll for more, if fixed-length record not yet received */ +if (cli->req_used <sizeof (struct chunksrv_req ))return false; cli->state = evt_exec_req;