mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-07 13:03:45 +02:00
Reduce TCP relay latency -- see GitHub issue #564
This commit is contained in:
parent
ba07a60c44
commit
4352202349
1 changed files with 24 additions and 13 deletions
|
@ -2142,19 +2142,30 @@ public:
|
||||||
const uint64_t now = OSUtils::now();
|
const uint64_t now = OSUtils::now();
|
||||||
if (((now - _lastDirectReceiveFromGlobal) > ZT_TCP_FALLBACK_AFTER)&&((now - _lastRestart) > ZT_TCP_FALLBACK_AFTER)) {
|
if (((now - _lastDirectReceiveFromGlobal) > ZT_TCP_FALLBACK_AFTER)&&((now - _lastRestart) > ZT_TCP_FALLBACK_AFTER)) {
|
||||||
if (_tcpFallbackTunnel) {
|
if (_tcpFallbackTunnel) {
|
||||||
Mutex::Lock _l(_tcpFallbackTunnel->writeq_m);
|
bool flushNow = false;
|
||||||
if (_tcpFallbackTunnel->writeq.length() == 0)
|
{
|
||||||
_phy.setNotifyWritable(_tcpFallbackTunnel->sock,true);
|
Mutex::Lock _l(_tcpFallbackTunnel->writeq_m);
|
||||||
const unsigned long mlen = len + 7;
|
if (_tcpFallbackTunnel->writeq.size() < (1024 * 64)) {
|
||||||
_tcpFallbackTunnel->writeq.push_back((char)0x17);
|
if (_tcpFallbackTunnel->writeq.length() == 0) {
|
||||||
_tcpFallbackTunnel->writeq.push_back((char)0x03);
|
_phy.setNotifyWritable(_tcpFallbackTunnel->sock,true);
|
||||||
_tcpFallbackTunnel->writeq.push_back((char)0x03); // fake TLS 1.2 header
|
flushNow = true;
|
||||||
_tcpFallbackTunnel->writeq.push_back((char)((mlen >> 8) & 0xff));
|
}
|
||||||
_tcpFallbackTunnel->writeq.push_back((char)(mlen & 0xff));
|
const unsigned long mlen = len + 7;
|
||||||
_tcpFallbackTunnel->writeq.push_back((char)4); // IPv4
|
_tcpFallbackTunnel->writeq.push_back((char)0x17);
|
||||||
_tcpFallbackTunnel->writeq.append(reinterpret_cast<const char *>(reinterpret_cast<const void *>(&(reinterpret_cast<const struct sockaddr_in *>(addr)->sin_addr.s_addr))),4);
|
_tcpFallbackTunnel->writeq.push_back((char)0x03);
|
||||||
_tcpFallbackTunnel->writeq.append(reinterpret_cast<const char *>(reinterpret_cast<const void *>(&(reinterpret_cast<const struct sockaddr_in *>(addr)->sin_port))),2);
|
_tcpFallbackTunnel->writeq.push_back((char)0x03); // fake TLS 1.2 header
|
||||||
_tcpFallbackTunnel->writeq.append((const char *)data,len);
|
_tcpFallbackTunnel->writeq.push_back((char)((mlen >> 8) & 0xff));
|
||||||
|
_tcpFallbackTunnel->writeq.push_back((char)(mlen & 0xff));
|
||||||
|
_tcpFallbackTunnel->writeq.push_back((char)4); // IPv4
|
||||||
|
_tcpFallbackTunnel->writeq.append(reinterpret_cast<const char *>(reinterpret_cast<const void *>(&(reinterpret_cast<const struct sockaddr_in *>(addr)->sin_addr.s_addr))),4);
|
||||||
|
_tcpFallbackTunnel->writeq.append(reinterpret_cast<const char *>(reinterpret_cast<const void *>(&(reinterpret_cast<const struct sockaddr_in *>(addr)->sin_port))),2);
|
||||||
|
_tcpFallbackTunnel->writeq.append((const char *)data,len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flushNow) {
|
||||||
|
void *tmpptr = (void *)_tcpFallbackTunnel;
|
||||||
|
phyOnTcpWritable(_tcpFallbackTunnel->sock,&tmpptr);
|
||||||
|
}
|
||||||
} else if (((now - _lastSendToGlobalV4) < ZT_TCP_FALLBACK_AFTER)&&((now - _lastSendToGlobalV4) > (ZT_PING_CHECK_INVERVAL / 2))) {
|
} else if (((now - _lastSendToGlobalV4) < ZT_TCP_FALLBACK_AFTER)&&((now - _lastSendToGlobalV4) > (ZT_PING_CHECK_INVERVAL / 2))) {
|
||||||
const InetAddress addr(ZT_TCP_FALLBACK_RELAY);
|
const InetAddress addr(ZT_TCP_FALLBACK_RELAY);
|
||||||
TcpConnection *tc = new TcpConnection();
|
TcpConnection *tc = new TcpConnection();
|
||||||
|
|
Loading…
Add table
Reference in a new issue