Fix: ACK section length calculation and increase socket buffers
This commit is contained in:
1 parent
c1890ad7a6
commit
076da4264b
2 files changed
+26
-15
No files matched your search
+15
-14
@@ -744,20 +744,21 @@ void etcp_conn_input(struct ETCP_DGRAM* pkt) {
|
||||
|
||||
// Process sections as per protocol.txt
|
||||
switch (type) {
|
||||
case ETCP_SECTION_ACK: {
|
||||
int elm_cnt=data[1];
|
||||
uint32_t till=data[2] | (data[3]<<8) | (data[4]<<16) | (data[5]<<24);
|
||||
data+=6;
|
||||
for (int i=0; i<elm_cnt; i++) {
|
||||
uint32_t seq=data[0] | (data[1]<<8) | (data[2]<<16) | (data[3]<<24);
|
||||
uint16_t ts=data[4] | (data[5]<<8);
|
||||
uint16_t dts=data[6] | (data[7]<<8);
|
||||
etcp_ack_recv(etcp, seq, ts, dts);
|
||||
data+=8;
|
||||
}
|
||||
while (etcp->rx_ack_till-till<0) { etcp->rx_ack_till++; etcp_ack_recv(etcp, etcp->rx_ack_till, -1, -1); }// подтверждаем всё по till
|
||||
break;
|
||||
}
|
||||
case ETCP_SECTION_ACK: {
|
||||
int elm_cnt=data[1];
|
||||
uint32_t till=data[2] | (data[3]<<8) | (data[4]<<16) | (data[5]<<24);
|
||||
int ack_section_len = 6 + elm_cnt * 8;
|
||||
data+=ack_section_len;
|
||||
len-=ack_section_len;
|
||||
for (int i=0; i<elm_cnt; i++) {
|
||||
uint32_t seq=data[-ack_section_len+6+i*8] | (data[-ack_section_len+7+i*8]<<8) | (data[-ack_section_len+8+i*8]<<16) | (data[-ack_section_len+9+i*8]<<24);
|
||||
uint16_t ts=data[-ack_section_len+10+i*8] | (data[-ack_section_len+11+i*8]<<8);
|
||||
uint16_t dts=data[-ack_section_len+12+i*8] | (data[-ack_section_len+13+i*8]<<8);
|
||||
etcp_ack_recv(etcp, seq, ts, dts);
|
||||
}
|
||||
while ((int32_t)(etcp->rx_ack_till-till)<0) { etcp->rx_ack_till++; etcp_ack_recv(etcp, etcp->rx_ack_till, -1, -1); }// подтверждаем всё по till
|
||||
break;
|
||||
}
|
||||
case ETCP_SECTION_PAYLOAD: {
|
||||
|
||||
if (len>=5) {
|
||||
|
||||
+11
-1
@@ -274,7 +274,17 @@ struct ETCP_SOCKET* etcp_socket_add(struct UTUN_INSTANCE* instance, struct socka
|
||||
if (setsockopt(e_sock->fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)) < 0) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CONNECTION, "Failed to set SO_REUSEADDR: %s", strerror(errno));
|
||||
}
|
||||
|
||||
|
||||
// Increase socket buffers for high throughput
|
||||
int sndbuf = 4 * 1024 * 1024; // 4MB send buffer
|
||||
int rcvbuf = 4 * 1024 * 1024; // 4MB receive buffer
|
||||
if (setsockopt(e_sock->fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf)) < 0) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CONNECTION, "Failed to set SO_SNDBUF: %s", strerror(errno));
|
||||
}
|
||||
if (setsockopt(e_sock->fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf)) < 0) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CONNECTION, "Failed to set SO_RCVBUF: %s", strerror(errno));
|
||||
}
|
||||
|
||||
int flags = fcntl(e_sock->fd, F_GETFL, 0);
|
||||
fcntl(e_sock->fd, F_SETFL, flags | O_NONBLOCK);
|
||||
|
||||
|
||||
Reference in new issue
Block a user