Pass fragment to dtls1_retransmit_message.

We can pass the fragment pointer to dtls1_retransmit_message rather than
having it look it up again.

Change-Id: If6957428418a44e7ceac91a93f7c6032d331d9d8
Reviewed-on: https://boringssl-review.googlesource.com/3510
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
Adam Langley 2015-02-19 15:51:58 -08:00
parent 40f101b78b
commit bcc4e23041
2 changed files with 66 additions and 94 deletions

View File

@ -933,106 +933,15 @@ int dtls1_get_queue_priority(unsigned short seq, int is_ccs) {
return seq * 2 - is_ccs; return seq * 2 - is_ccs;
} }
int dtls1_retransmit_buffered_messages(SSL *s) { static int dtls1_retransmit_message(SSL *s, hm_fragment *frag) {
pqueue sent = s->d1->sent_messages;
piterator iter;
pitem *item;
hm_fragment *frag;
int found = 0;
iter = pqueue_iterator(sent);
for (item = pqueue_next(&iter); item != NULL; item = pqueue_next(&iter)) {
frag = (hm_fragment *)item->data;
if (dtls1_retransmit_message(
s, (unsigned short)dtls1_get_queue_priority(
frag->msg_header.seq, frag->msg_header.is_ccs),
0, &found) <= 0 &&
found) {
return -1;
}
}
return 1;
}
int dtls1_buffer_message(SSL *s, int is_ccs) {
pitem *item;
hm_fragment *frag;
uint8_t seq64be[8];
/* this function is called immediately after a message has
* been serialized */
assert(s->init_off == 0);
frag = dtls1_hm_fragment_new(s->init_num, 0);
if (!frag) {
return 0;
}
memcpy(frag->fragment, s->init_buf->data, s->init_num);
if (is_ccs) {
assert(s->d1->w_msg_hdr.msg_len + DTLS1_CCS_HEADER_LENGTH ==
(unsigned int)s->init_num);
} else {
assert(s->d1->w_msg_hdr.msg_len + DTLS1_HM_HEADER_LENGTH ==
(unsigned int)s->init_num);
}
frag->msg_header.msg_len = s->d1->w_msg_hdr.msg_len;
frag->msg_header.seq = s->d1->w_msg_hdr.seq;
frag->msg_header.type = s->d1->w_msg_hdr.type;
frag->msg_header.frag_off = 0;
frag->msg_header.frag_len = s->d1->w_msg_hdr.msg_len;
frag->msg_header.is_ccs = is_ccs;
frag->msg_header.epoch = s->d1->w_epoch;
memset(seq64be, 0, sizeof(seq64be));
seq64be[6] = (uint8_t)(
dtls1_get_queue_priority(frag->msg_header.seq, frag->msg_header.is_ccs) >>
8);
seq64be[7] = (uint8_t)(
dtls1_get_queue_priority(frag->msg_header.seq, frag->msg_header.is_ccs));
item = pitem_new(seq64be, frag);
if (item == NULL) {
dtls1_hm_fragment_free(frag);
return 0;
}
pqueue_insert(s->d1->sent_messages, item);
return 1;
}
int dtls1_retransmit_message(SSL *s, unsigned short seq, unsigned long frag_off,
int *found) {
int ret; int ret;
/* XDTLS: for now assuming that read/writes are blocking */ /* XDTLS: for now assuming that read/writes are blocking */
pitem *item;
hm_fragment *frag;
unsigned long header_length; unsigned long header_length;
uint8_t seq64be[8];
uint8_t save_write_sequence[8]; uint8_t save_write_sequence[8];
/* assert(s->init_num == 0); /* assert(s->init_num == 0);
assert(s->init_off == 0); */ assert(s->init_off == 0); */
/* XDTLS: the requested message ought to be found, otherwise error */
memset(seq64be, 0, sizeof(seq64be));
seq64be[6] = (uint8_t)(seq >> 8);
seq64be[7] = (uint8_t)seq;
item = pqueue_find(s->d1->sent_messages, seq64be);
if (item == NULL) {
assert(0);
*found = 0;
return 0;
}
*found = 1;
frag = (hm_fragment *)item->data;
if (frag->msg_header.is_ccs) { if (frag->msg_header.is_ccs) {
header_length = DTLS1_CCS_HEADER_LENGTH; header_length = DTLS1_CCS_HEADER_LENGTH;
} else { } else {
@ -1091,6 +1000,71 @@ int dtls1_retransmit_message(SSL *s, unsigned short seq, unsigned long frag_off,
return ret; return ret;
} }
int dtls1_retransmit_buffered_messages(SSL *s) {
pqueue sent = s->d1->sent_messages;
piterator iter = pqueue_iterator(sent);
pitem *item;
for (item = pqueue_next(&iter); item != NULL; item = pqueue_next(&iter)) {
hm_fragment *frag = (hm_fragment *)item->data;
if (dtls1_retransmit_message(s, frag) <= 0) {
return -1;
}
}
return 1;
}
int dtls1_buffer_message(SSL *s, int is_ccs) {
pitem *item;
hm_fragment *frag;
uint8_t seq64be[8];
/* this function is called immediately after a message has
* been serialized */
assert(s->init_off == 0);
frag = dtls1_hm_fragment_new(s->init_num, 0);
if (!frag) {
return 0;
}
memcpy(frag->fragment, s->init_buf->data, s->init_num);
if (is_ccs) {
assert(s->d1->w_msg_hdr.msg_len + DTLS1_CCS_HEADER_LENGTH ==
(unsigned int)s->init_num);
} else {
assert(s->d1->w_msg_hdr.msg_len + DTLS1_HM_HEADER_LENGTH ==
(unsigned int)s->init_num);
}
frag->msg_header.msg_len = s->d1->w_msg_hdr.msg_len;
frag->msg_header.seq = s->d1->w_msg_hdr.seq;
frag->msg_header.type = s->d1->w_msg_hdr.type;
frag->msg_header.frag_off = 0;
frag->msg_header.frag_len = s->d1->w_msg_hdr.msg_len;
frag->msg_header.is_ccs = is_ccs;
frag->msg_header.epoch = s->d1->w_epoch;
memset(seq64be, 0, sizeof(seq64be));
seq64be[6] = (uint8_t)(
dtls1_get_queue_priority(frag->msg_header.seq, frag->msg_header.is_ccs) >>
8);
seq64be[7] = (uint8_t)(
dtls1_get_queue_priority(frag->msg_header.seq, frag->msg_header.is_ccs));
item = pitem_new(seq64be, frag);
if (item == NULL) {
dtls1_hm_fragment_free(frag);
return 0;
}
pqueue_insert(s->d1->sent_messages, item);
return 1;
}
/* call this function when the buffered messages are no longer needed */ /* call this function when the buffered messages are no longer needed */
void dtls1_clear_record_buffer(SSL *s) { void dtls1_clear_record_buffer(SSL *s) {
pitem *item; pitem *item;

View File

@ -809,8 +809,6 @@ int dtls1_send_change_cipher_spec(SSL *s, int a, int b);
int dtls1_send_finished(SSL *s, int a, int b, const char *sender, int slen); int dtls1_send_finished(SSL *s, int a, int b, const char *sender, int slen);
int dtls1_read_failed(SSL *s, int code); int dtls1_read_failed(SSL *s, int code);
int dtls1_buffer_message(SSL *s, int ccs); int dtls1_buffer_message(SSL *s, int ccs);
int dtls1_retransmit_message(SSL *s, unsigned short seq, unsigned long frag_off,
int *found);
int dtls1_get_queue_priority(unsigned short seq, int is_ccs); int dtls1_get_queue_priority(unsigned short seq, int is_ccs);
int dtls1_retransmit_buffered_messages(SSL *s); int dtls1_retransmit_buffered_messages(SSL *s);
void dtls1_clear_record_buffer(SSL *s); void dtls1_clear_record_buffer(SSL *s);