Skip to content

Commit

Permalink
Merge pull request Netflix#64 from timiblossom/master
Browse files Browse the repository at this point in the history
Remove directive use and replace with a variable checking for printing t...
  • Loading branch information
timiblossom committed Dec 9, 2014
2 parents 76646f2 + 2938830 commit d84faaf
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 163 deletions.
5 changes: 1 addition & 4 deletions conf/dynomite.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
dyn_o_mite:
listen: 127.0.0.1:8102
env: network
datacenter: localdc
rack: localrack
dyn_listen: 127.0.0.1:8101
tokens: '3101134286'
tokens: '101134286'
servers:
- 127.0.0.1:22122:1
redis: true
2 changes: 1 addition & 1 deletion src/dyn_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@

#define CONF_DEFAUTL_SEED_PROVIDER "simple_provider"


#define PEM_KEY_FILE "conf/dynomite.pem"


struct conf_listen {
struct string pname; /* listen: as "name:port" */
struct string name; /* name */
Expand Down
7 changes: 4 additions & 3 deletions src/dyn_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ core_start(struct instance *nci)
ctx = core_ctx_create(nci);
if (ctx != NULL) {
nci->ctx = ctx;
#ifdef DN_DEBUG_LOG
crypto_test();
#endif

if (TRACING_LEVEL == LOG_VVERB) {
crypto_check();
}
return ctx;
}

Expand Down
3 changes: 3 additions & 0 deletions src/dyn_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#define DN_EAGAIN -2
#define DN_ENOMEM -3


typedef int rstatus_t; /* return type */
typedef int err_t; /* error type */

Expand Down Expand Up @@ -123,6 +124,8 @@ struct dyn_ring;

#include "event/dyn_event.h"

#define TRACING_LEVEL 0


typedef enum dyn_state {
INIT = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/dyn_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ static int rsa_test()
return 0;
}

void crypto_test(void)
void crypto_check(void)
{
aes_test();
rsa_test();
Expand Down
2 changes: 1 addition & 1 deletion src/dyn_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ rstatus_t dyn_rsa_encrypt(unsigned char *plain_msg, unsigned char *encrypted_buf
rstatus_t dyn_rsa_decrypt(unsigned char *encrypted_msg, unsigned char *decrypted_buf);


void crypto_test(void);
void crypto_check(void);

#endif /* DYN_CRYPTO_H_ */
152 changes: 79 additions & 73 deletions src/dyn_dnode_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,10 @@ void
dyn_parse_req(struct msg *r)
{

#ifdef DN_DEBUG_LOG
log_debug(LOG_VVERB, "In dyn_parse_req, start to process request :::::::::::::::::::::: ");
msg_dump(r);
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "In dyn_parse_req, start to process request :::::::::::::::::::::: ");
msg_dump(r);
}

bool done_parsing = false;

Expand All @@ -400,17 +400,19 @@ dyn_parse_req(struct msg *r)
struct dmsg *dmsg = r->dmsg;

if (dmsg->type != DMSG_UNKNOWN && dmsg->type != DMSG_REQ && dmsg->type != GOSSIP_SYN) {
log_debug(LOG_DEBUG, "Req parser: I got a dnode msg of type %d", dmsg->type);
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "Req parser: I got a dnode msg of type %d", dmsg->type);
}
r->state = 0;
r->result = MSG_PARSE_OK;
r->dyn_state = DYN_DONE;
return;
}

if (dmsg->type == GOSSIP_SYN) {
#ifdef DN_DEBUG_LOG
log_debug(LOG_DEBUG, "Req parser: I got a GOSSIP_SYN msg");
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "Req parser: I got a GOSSIP_SYN msg");
}

//TODOs: need to address multi-buffer msg later
struct mbuf *b = STAILQ_LAST(&r->mhdr, mbuf, next);
Expand All @@ -432,32 +434,32 @@ dyn_parse_req(struct msg *r)
return;
}

#ifdef DN_DEBUG_LOG
log_debug(LOG_DEBUG, "data or encrypted aes key length : %d", dmsg->plen);
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "data or encrypted aes key length : %d", dmsg->plen);
}


if (dmsg->mlen > 1) {
#ifdef DN_DEBUG_LOG
log_debug(LOG_DEBUG, "dmsg->mlen is something: %d, need to process it", dmsg->plen);
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "dmsg->mlen is something: %d, need to process it", dmsg->plen);
}
//Decrypt AES key
dyn_rsa_decrypt(dmsg->data, aes_decrypted_buf);
strncpy(r->owner->aes_key, aes_decrypted_buf, strlen(aes_decrypted_buf));
//Decrypt payload
dyn_aes_decrypt(dmsg->payload, dmsg->plen, decrypted_buf, aes_decrypted_buf);
} else {
#ifdef DN_DEBUG_LOG
log_debug(LOG_DEBUG, "dmsg->mlen is a dummy: %d, NO need to process it", dmsg->plen);
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "dmsg->mlen is a dummy: %d, NO need to process it", dmsg->plen);
}
dyn_aes_decrypt(dmsg->payload, dmsg->plen, decrypted_buf, r->owner->aes_key);
}


#ifdef DN_DEBUG_LOG
loga("AES encryption key: %s\n", base64_encode(aes_decrypted_buf, AES_KEYLEN));
log_hexdump(LOG_VERB, decrypted_buf->pos, mbuf_length(decrypted_buf), "dyn message decrypted payload: ");
#endif
if (TRACING_LEVEL == LOG_VVERB) {
loga("AES encryption key: %s\n", base64_encode(aes_decrypted_buf, AES_KEYLEN));
log_hexdump(LOG_VVERB, decrypted_buf->pos, mbuf_length(decrypted_buf), "dyn message decrypted payload: ");
}

struct mbuf *b = STAILQ_LAST(&r->mhdr, mbuf, next);
b->last = b->pos;
Expand Down Expand Up @@ -487,10 +489,11 @@ dyn_parse_req(struct msg *r)
void dyn_parse_rsp(struct msg *r)
{

#ifdef DN_DEBUG_LOG
log_debug(LOG_VERB, "In dyn_parse_rsp, start to process response :::::::::::::::::::::::: ");
msg_dump(r);
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "In dyn_parse_rsp, start to process response :::::::::::::::::::::::: ");
msg_dump(r);
}


if (dyn_parse_core(r)) {
struct dmsg *dmsg = r->dmsg;
Expand All @@ -512,17 +515,17 @@ void dyn_parse_rsp(struct msg *r)
return;
}

#ifdef DN_DEBUG_LOG
log_debug(LOG_VERB, "encrypted aes key length : %d", dmsg->mlen);
loga("AES encryption key from conn: %s\n", base64_encode(r->owner->aes_key, AES_KEYLEN));
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "encrypted aes key length : %d", dmsg->mlen);
loga("AES encryption key from conn: %s\n", base64_encode(r->owner->aes_key, AES_KEYLEN));
}

//Dont need to decrypt AES key - pull it out from the conn
dyn_aes_decrypt(dmsg->payload, dmsg->plen, decrypted_buf, r->owner->aes_key);

#ifdef DN_DEBUG_LOG
log_hexdump(LOG_VERB, decrypted_buf->pos, mbuf_length(decrypted_buf), "dyn message decrypted payload: ");
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_hexdump(LOG_VVERB, decrypted_buf->pos, mbuf_length(decrypted_buf), "dyn message decrypted payload: ");
}

struct mbuf *b = STAILQ_LAST(&r->mhdr, mbuf, next);
b->last = b->pos;
Expand All @@ -536,11 +539,11 @@ void dyn_parse_rsp(struct msg *r)
return memcache_parse_rsp(r);
}

#ifdef DN_DEBUG_LOG

//bad case
log_debug(LOG_DEBUG, "Bad message - cannot parse"); //fix me to do something
msg_dump(r);
#endif


//r->state = 0;
//r->result = MSG_PARSE_OK;
Expand All @@ -550,9 +553,9 @@ void dyn_parse_rsp(struct msg *r)
void
dmsg_free(struct dmsg *dmsg)
{
#ifdef DN_DEBUG_LOG
log_debug(LOG_VVERB, "free dmsg %p id %"PRIu64"", dmsg, dmsg->id);
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "free dmsg %p id %"PRIu64"", dmsg, dmsg->id);
}

dn_free(dmsg);
}
Expand All @@ -561,9 +564,9 @@ dmsg_free(struct dmsg *dmsg)
void
dmsg_put(struct dmsg *dmsg)
{
#ifdef DN_DEBUG_LOG
log_debug(LOG_VVERB, "put dmsg %p id %"PRIu64"", dmsg, dmsg->id);
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "put dmsg %p id %"PRIu64"", dmsg, dmsg->id);
}

nfree_dmsgq++;
TAILQ_INSERT_HEAD(&free_dmsgq, dmsg, m_tqe);
Expand All @@ -574,20 +577,20 @@ dmsg_dump(struct dmsg *dmsg)
{
struct mbuf *mbuf;

#ifdef DN_DEBUG_LOG
log_debug(LOG_DEBUG, "dmsg dump: id %"PRIu64" version %d bit_field %d type %d len %"PRIu32" plen %"PRIu32" ",
dmsg->id, dmsg->version, dmsg->bit_field, dmsg->type, dmsg->mlen, dmsg->plen);
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "dmsg dump: id %"PRIu64" version %d bit_field %d type %d len %"PRIu32" plen %"PRIu32" ",
dmsg->id, dmsg->version, dmsg->bit_field, dmsg->type, dmsg->mlen, dmsg->plen);
}
//loga_hexdump(dmsg->data, dmsg->mlen, "dmsg with %ld bytes of data", dmsg->mlen);
}


void
dmsg_init(void)
{
#ifdef DN_DEBUG_LOG
log_debug(LOG_DEBUG, "dmsg size %d", sizeof(struct dmsg));
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "dmsg size %d", sizeof(struct dmsg));
}

dmsg_id = 0;
nfree_dmsgq = 0;
Expand Down Expand Up @@ -693,9 +696,9 @@ dmsg_write(struct mbuf *mbuf, uint64_t msg_id, uint8_t type,
mbuf_write_char(mbuf, ' ');
//mbuf_write_string(mbuf, data);
if (conn->dnode_secured && conn->dnode_crypto_state == 0) {
#ifdef DN_DEBUG_LOG
loga("AES key to be encrypted : %s \n", base64_encode(aes_key, 32));
#endif
if (TRACING_LEVEL == LOG_VVERB) {
loga("AES key to be encrypted : %s \n", base64_encode(aes_key, 32));
}
dyn_rsa_encrypt(aes_key, aes_encrypted_buf);
mbuf_write_bytes(mbuf, aes_encrypted_buf, AES_ENCRYPTED_KEYLEN);
conn->dnode_crypto_state = 1;
Expand All @@ -709,9 +712,9 @@ dmsg_write(struct mbuf *mbuf, uint64_t msg_id, uint8_t type,
mbuf_write_uint32(mbuf, payload_len);
mbuf_write_string(mbuf, &CRLF_STR);

#ifdef DN_DEBUG_LOG
log_hexdump(LOG_VERB, mbuf->pos, mbuf_length(mbuf), "dyn message producer: ");
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_hexdump(LOG_VERB, mbuf->pos, mbuf_length(mbuf), "dyn message producer: ");
}

return DN_OK;
}
Expand Down Expand Up @@ -750,9 +753,9 @@ dmsg_write_mbuf(struct mbuf *mbuf, uint64_t msg_id, uint8_t type, struct conn *c
mbuf_write_char(mbuf, ' ');
//mbuf_write_mbuf(mbuf, data);
if (conn->dnode_secured) {
#ifdef DN_DEBUG_LOG
loga("AES key to be encrypted : %s \n", base64_encode(aes_key, 32));
#endif
if (TRACING_LEVEL == LOG_VVERB) {
loga("AES key to be encrypted : %s \n", base64_encode(aes_key, 32));
}
dyn_rsa_encrypt(aes_key, aes_encrypted_buf);
mbuf_write_bytes(mbuf, aes_encrypted_buf, AES_ENCRYPTED_KEYLEN);
} else {
Expand All @@ -766,9 +769,9 @@ dmsg_write_mbuf(struct mbuf *mbuf, uint64_t msg_id, uint8_t type, struct conn *c

mbuf_write_string(mbuf, &CRLF_STR);

#ifdef DN_DEBUG_LOG
log_hexdump(LOG_VERB, mbuf->pos, mbuf_length(mbuf), "dyn message producer: ");
#endif
if (TRACING_LEVEL == LOG_VVERB) {
log_hexdump(LOG_VERB, mbuf->pos, mbuf_length(mbuf), "dyn message producer: ");
}

return DN_OK;
}
Expand Down Expand Up @@ -941,24 +944,24 @@ dmsg_parse(struct dmsg *dmsg)

end = p;

#ifdef DN_DEBUG_LOG
log_hexdump(LOG_VERB, host_id, host_id_len, "host_id: ");
log_hexdump(LOG_VERB, ts, ts_len, "ts: ");
log_hexdump(LOG_VERB, node_state, node_state_len, "state: ");
log_hexdump(LOG_VERB, host_addr, host_addr_len, "host_addr: ");
if (TRACING_LEVEL == LOG_VVERB) {
log_hexdump(LOG_VVERB, host_id, host_id_len, "host_id: ");
log_hexdump(LOG_VVERB, ts, ts_len, "ts: ");
log_hexdump(LOG_VVERB, node_state, node_state_len, "state: ");
log_hexdump(LOG_VVERB, host_addr, host_addr_len, "host_addr: ");

log_debug(LOG_VERB, "\t\t host_id : '%.*s'", host_id_len, host_id);
log_debug(LOG_VERB, "\t\t ts : '%.*s'", ts_len, ts);
log_debug(LOG_VERB, "\t\t node_state : '%.*s'", node_state_len, node_state);
log_debug(LOG_VERB, "\t\t host_addr : '%.*s'", host_addr_len, host_addr);
#endif
log_debug(LOG_VVERB, "\t\t host_id : '%.*s'", host_id_len, host_id);
log_debug(LOG_VVERB, "\t\t ts : '%.*s'", ts_len, ts);
log_debug(LOG_VVERB, "\t\t node_state : '%.*s'", node_state_len, node_state);
log_debug(LOG_VVERB, "\t\t host_addr : '%.*s'", host_addr_len, host_addr);
}

struct node *rnode = (struct node *) array_get(&ring_msg->nodes, count);
dmsg_parse_host_id(host_id, host_id_len, &rnode->dc, &rnode->rack, &rnode->token);

#ifdef DN_DEBUG_LOG
print_dyn_token(&rnode->token, 5);
#endif
if (TRACING_LEVEL == LOG_VVERB) {
print_dyn_token(&rnode->token, 5);
}

string_copy(&rnode->name, host_addr, host_addr_len);
string_copy(&rnode->pname, host_addr, host_addr_len); //need to add port
Expand Down Expand Up @@ -995,7 +998,10 @@ dmsg_process(struct context *ctx, struct conn *conn, struct dmsg *dmsg)

struct string s;

log_debug(LOG_DEBUG, "dmsg process: type %d", dmsg->type);
if (TRACING_LEVEL == LOG_VVERB) {
log_debug(LOG_VVERB, "dmsg process: type %d", dmsg->type);
}

switch(dmsg->type) {
case DMSG_DEBUG:
s.len = dmsg->mlen;
Expand Down
10 changes: 1 addition & 9 deletions src/dyn_dnode_peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,9 +1085,6 @@ dnode_peer_pool_update(struct server_pool *pool)
int64_t now;
uint32_t pnlive_server; /* prev # live server */

#ifdef DN_DEBUG_LOG
loga("dnode_peer_pool_update entering ........................");
#endif

//fix me
if (!pool->auto_eject_hosts) {
Expand Down Expand Up @@ -1162,7 +1159,7 @@ dnode_peer_pool_server(struct server_pool *pool, struct rack *rack, uint8_t *key
ASSERT(array_n(&pool->peers) != 0);
ASSERT(key != NULL && keylen != 0);

ASSERT(rack != NULL);
//ASSERT(rack != NULL);

switch (pool->dist_type) {
case DIST_KETAMA:
Expand Down Expand Up @@ -1224,11 +1221,6 @@ dnode_peer_pool_conn(struct context *ctx, struct server_pool *pool, struct rack
struct server *server;
struct conn *conn;

#ifdef DN_DEBUG_LOG
loga("dnode_peer_pool_conn entering ........................");
loga("getting a conn for rack '%.*s' ", rack->name->len, rack->name->data);
#endif

//status = dnode_peer_pool_update(pool);
status = dnode_peer_pool_run(pool);
if (status != DN_OK) {
Expand Down
Loading

0 comments on commit d84faaf

Please sign in to comment.