Skip to content

Commit

Permalink
Fix: TFO not working
Browse files Browse the repository at this point in the history
  • Loading branch information
semigodking committed Nov 25, 2019
1 parent ebbd1d0 commit 46b2314
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,6 @@ struct bufferevent* red_connect_relay_tfo(const char *ifname,

retval = red_prepare_relay(ifname, addr->ss_family, readcb, writecb, errorcb, cbarg);
if (retval) {
// write data to evbuffer so that data can be sent when connection is set up
if (bufferevent_write(retval, data, *len) != 0) {
log_errno(LOG_NOTICE, "bufferevent_write");
*len = 0; // Nothing sent, caller needs to write data again when connection is setup.
goto fail;
}

relay_fd = bufferevent_getfd(retval);
if (timeout_write)
bufferevent_set_timeouts(retval, NULL, timeout_write);
Expand All @@ -321,13 +314,17 @@ struct bufferevent* red_connect_relay_tfo(const char *ifname,
size_t s = sendto(relay_fd, data, * len, MSG_FASTOPEN,
(struct sockaddr *)addr, addr_size(addr)
);
*len = 0; // Assume nothing sent, caller needs to write data again when connection is setup.
if (s == -1) {
if (errno == EINPROGRESS || errno == EAGAIN
|| errno == EWOULDBLOCK) {
// Remote server doesn't support tfo or it's the first connection to the server.
// Connection will automatically fall back to conventional TCP.
log_error(LOG_DEBUG, "TFO: no cookie");
// write data to evbuffer so that data can be sent when connection is set up
if (bufferevent_write(retval, data, *len) != 0) {
log_errno(LOG_NOTICE, "bufferevent_write");
goto fail;
}
return retval;
} else if (errno == EOPNOTSUPP || errno == EPROTONOSUPPORT ||
errno == ENOPROTOOPT) {
Expand All @@ -352,6 +349,11 @@ struct bufferevent* red_connect_relay_tfo(const char *ifname,
log_errno(LOG_NOTICE, "connect");
goto fail;
}
// write data to evbuffer so that data can be sent when connection is set up
if (bufferevent_write(retval, data, *len) != 0) {
log_errno(LOG_NOTICE, "bufferevent_write");
goto fail;
}
}
return retval;

Expand Down

0 comments on commit 46b2314

Please sign in to comment.