Шесть правок по разбору logs (23) с субагентами. - Зависание фронта теперь только таймаут посреди пакета (новый transport::Socket::timedOutMidPacket). Таймаут соединения срабатывает и от запросов другого DC, из-за этого простаивающие фронты DC2/DC4 со всеми ответами засчитывались как зависшие. - Отказы TCP релея считаются и по адресу (addr-149.154.x). kws2, kws4, kws2-1 и kws4-1 ходят на один IP. Адрес подавляется после 3 отказов или вместе с доменом, если сам недавно (<2 мин) отказывал. Сбрасывает его только ответ через этот же адрес, не через DNS-запас. - Рабочий адрес фронта сохраняется для типа сети (wss_route_health.txt.front). - Пул считает готовые запасные сокеты фронтов по DC, а не по ключу. Второй запасной держится 30 с после всплеска (повторное обращение в течение 3 с после попадания, лог wss_pool burst). При промахе на уже известном DC запасной открывается сразу. - После быстрого (<4 с) отказа фронта до on_connected переподключение через 150 мс, а не 1000.
63 lines
2.3 KiB
C++
63 lines
2.3 KiB
C++
/*
|
|
* This is the source code of tgnet library v. 1.1
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
*/
|
|
|
|
#ifndef TGNET_TRANSPORT_SOCKET_H
|
|
#define TGNET_TRANSPORT_SOCKET_H
|
|
|
|
#include <stdint.h>
|
|
#include <sys/socket.h>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace tgnet {
|
|
namespace transport {
|
|
|
|
enum class HandshakePhase : uint8_t {
|
|
None,
|
|
TcpConnected,
|
|
TlsReady,
|
|
WebSocketReady,
|
|
FirstDataReceived,
|
|
};
|
|
|
|
// Transport boundary used by the connection layer. Implementations own their
|
|
// native descriptor and expose a byte stream; MTProto does not know how that
|
|
// stream is carried on the wire.
|
|
class Socket {
|
|
public:
|
|
virtual ~Socket() = default;
|
|
|
|
virtual bool open(const struct sockaddr *address, socklen_t addressLength, std::string *diagnostic) = 0;
|
|
virtual int fd() const = 0;
|
|
virtual bool onEvent(uint32_t events, std::vector<std::vector<uint8_t>> &payloads, std::string *diagnostic) = 0;
|
|
virtual bool write(const uint8_t *data, uint32_t size, std::string *diagnostic) = 0;
|
|
virtual size_t queuedOutputBytes() const = 0;
|
|
virtual bool isReady() const = 0;
|
|
virtual bool wantsWrite() const = 0;
|
|
virtual bool canWriteApplicationData() const = 0;
|
|
virtual bool isClosed() const = 0;
|
|
virtual HandshakePhase handshakePhase() const = 0;
|
|
virtual const char *transportName() const = 0;
|
|
virtual void timedOut() = 0;
|
|
// The same timeout, told whether it struck in the middle of an incoming
|
|
// MTProto packet: a stream frozen mid-transfer, not an idle connection.
|
|
virtual void timedOutMidPacket(bool midPacket) { (void) midPacket; timedOut(); }
|
|
// The handshake completed, application data was sent, and no reply came
|
|
// back within the shared watchdog timeout. Transports use this to penalize
|
|
// routes that look healthy but silently swallow traffic.
|
|
virtual void noteAppDataTimeout() {}
|
|
// One-line account of this socket's life for the disconnect log line
|
|
// (route, bytes each way, handshake and first-data times). Taking it
|
|
// tells the transport not to log the same summary again on close.
|
|
virtual std::string takeSessionSummary() { return std::string(); }
|
|
// Application bytes received since open; the WSS tunnel rotates on it.
|
|
virtual uint64_t receivedBytes() const { return 0; }
|
|
virtual void close() = 0;
|
|
};
|
|
|
|
} // namespace transport
|
|
} // namespace tgnet
|
|
|
|
#endif
|