#pragma once #include #include #include #include #include #include "interconnect_stream.h" #include "packet.h" #include "types.h" namespace NActors { struct TProgramInfo { ui64 PID = 0; ui64 StartTime = 0; ui64 Serial = 0; }; enum class ENetwork : ui32 { //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // local messages //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Start = EventSpaceBegin(TEvents::ES_INTERCONNECT_TCP), SocketReadyRead = Start, SocketReadyWrite, SocketError, Connect, Disconnect, IncomingConnection, HandshakeAsk, HandshakeAck, HandshakeNak, HandshakeDone, HandshakeFail, Kick, Flush, NodeInfo, BunchOfEventsToDestroy, HandshakeRequest, HandshakeReplyOK, HandshakeReplyError, ResolveAddress, AddressInfo, ResolveError, HTTPStreamStatus, HTTPSendContent, ConnectProtocolWakeup, HTTPProtocolRetry, EvPollerRegister, EvPollerRegisterResult, EvPollerReady, EvUpdateFromInputSession, EvConfirmUpdate, EvSessionBufferSizeRequest, EvSessionBufferSizeResponse, EvProcessPingRequest, EvGetSecureSocket, EvSecureSocket, //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // nonlocal messages; their indices must be preserved in order to work properly while doing rolling update //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // interconnect load test message EvLoadMessage = Start + 256, }; struct TEvSocketReadyRead: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvSocketReadyRead, "Network: TEvSocketReadyRead") }; struct TEvSocketReadyWrite: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvSocketReadyWrite, "Network: TEvSocketReadyWrite") }; struct TEvSocketError: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvSocketError, ::strerror(Error)) TString GetReason() const { return ::strerror(Error); } const int Error; TIntrusivePtr Socket; TEvSocketError(int error, TIntrusivePtr sock) : Error(error) , Socket(std::move(sock)) { } }; struct TEvSocketConnect: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvSocketConnect, "Network: TEvSocketConnect") }; struct TEvSocketDisconnect: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvSocketDisconnect, "Network: TEvSocketDisconnect") TDisconnectReason Reason; TEvSocketDisconnect(TDisconnectReason reason) : Reason(std::move(reason)) { } }; struct TEvHandshakeAsk: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvHandshakeAsk, "Network: TEvHandshakeAsk") TEvHandshakeAsk(const TActorId& self, const TActorId& peer, ui64 counter) : Self(self) , Peer(peer) , Counter(counter) { } const TActorId Self; const TActorId Peer; const ui64 Counter; }; struct TEvHandshakeAck: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvHandshakeAck, "Network: TEvHandshakeAck") TEvHandshakeAck(const TActorId& self, ui64 nextPacket, TSessionParams params) : Self(self) , NextPacket(nextPacket) , Params(std::move(params)) {} const TActorId Self; const ui64 NextPacket; const TSessionParams Params; }; struct TEvHandshakeNak : TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvSocketReadyRead, "Network: TEvHandshakeNak") }; struct TEvHandshakeRequest : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvHandshakeRequest, "Network: TEvHandshakeRequest") NActorsInterconnect::THandshakeRequest Record; }; struct TEvHandshakeReplyOK : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvHandshakeReplyOK, "Network: TEvHandshakeReplyOK") NActorsInterconnect::THandshakeReply Record; }; struct TEvHandshakeReplyError : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvHandshakeReplyError, "Network: TEvHandshakeReplyError") TEvHandshakeReplyError(TString error) { Record.SetErrorExplaination(error); } NActorsInterconnect::THandshakeReply Record; }; struct TEvIncomingConnection: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvIncomingConnection, "Network: TEvIncomingConnection") TIntrusivePtr Socket; NInterconnect::TAddress Address; TEvIncomingConnection(TIntrusivePtr socket, NInterconnect::TAddress address) : Socket(std::move(socket)) , Address(std::move(address)) {} }; struct TEvHandshakeDone: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvHandshakeDone, "Network: TEvHandshakeDone") TEvHandshakeDone( TIntrusivePtr socket, const TActorId& peer, const TActorId& self, ui64 nextPacket, TAutoPtr&& programInfo, TSessionParams params) : Socket(std::move(socket)) , Peer(peer) , Self(self) , NextPacket(nextPacket) , ProgramInfo(std::move(programInfo)) , Params(std::move(params)) { } TIntrusivePtr Socket; const TActorId Peer; const TActorId Self; const ui64 NextPacket; TAutoPtr ProgramInfo; const TSessionParams Params; }; struct TEvHandshakeFail: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvHandshakeFail, "Network: TEvHandshakeFail") enum EnumHandshakeFail { HANDSHAKE_FAIL_TRANSIENT, HANDSHAKE_FAIL_PERMANENT, HANDSHAKE_FAIL_SESSION_MISMATCH, }; TEvHandshakeFail(EnumHandshakeFail temporary, TString explanation) : Temporary(temporary) , Explanation(std::move(explanation)) { } const EnumHandshakeFail Temporary; const TString Explanation; }; struct TEvKick: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvKick, "Network: TEvKick") }; struct TEvFlush: public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvFlush, "Network: TEvFlush") }; struct TEvLocalNodeInfo : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvLocalNodeInfo, "Network: TEvLocalNodeInfo") ui32 NodeId; NAddr::IRemoteAddrPtr Address; }; struct TEvBunchOfEventsToDestroy : TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvBunchOfEventsToDestroy, "Network: TEvBunchOfEventsToDestroy") TEvBunchOfEventsToDestroy(TDeque> events) : Events(std::move(events)) { } TDeque> Events; }; struct TEvResolveAddress : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvResolveAddress, "Network: TEvResolveAddress") TString Address; ui16 Port; }; struct TEvAddressInfo : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvAddressInfo, "Network: TEvAddressInfo") NAddr::IRemoteAddrPtr Address; }; struct TEvResolveError : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvResolveError, "Network: TEvResolveError") TString Explain; }; struct TEvHTTPStreamStatus : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvHTTPStreamStatus, "Network: TEvHTTPStreamStatus") enum EStatus { READY, COMPLETE, ERROR, }; EStatus Status; TString Error; TString HttpHeaders; }; struct TEvHTTPSendContent : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvHTTPSendContent, "Network: TEvHTTPSendContent") const char* Data; size_t Len; bool Last; }; struct TEvConnectWakeup : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvConnectWakeup, "Protocols: TEvConnectWakeup") }; struct TEvHTTPProtocolRetry : public TEventLocal { DEFINE_SIMPLE_LOCAL_EVENT(TEvHTTPProtocolRetry, "Protocols: TEvHTTPProtocolRetry") }; struct TEvLoadMessage : TEventPB(ENetwork::EvLoadMessage)> { TEvLoadMessage() = default; template TEvLoadMessage(const TContainer& route, const TString& id, const TString* payload) { for (const TActorId& actorId : route) { auto* hop = Record.AddHops(); if (actorId) { ActorIdToProto(actorId, hop->MutableNextHop()); } } Record.SetId(id); if (payload) { Record.SetPayload(*payload); } } template TEvLoadMessage(const TContainer& route, const TString& id, TRope&& payload) { for (const TActorId& actorId : route) { auto* hop = Record.AddHops(); if (actorId) { ActorIdToProto(actorId, hop->MutableNextHop()); } } Record.SetId(id); AddPayload(std::move(payload)); } }; struct TEvUpdateFromInputSession : TEventLocal(ENetwork::EvUpdateFromInputSession)> { ui64 ConfirmedByInput; // latest Confirm value from processed input packet ui64 NumDataBytes; TDuration Ping; TEvUpdateFromInputSession(ui64 confirmedByInput, ui64 numDataBytes, TDuration ping) : ConfirmedByInput(confirmedByInput) , NumDataBytes(numDataBytes) , Ping(ping) { } }; struct TEvConfirmUpdate : TEventLocal(ENetwork::EvConfirmUpdate)> {}; struct TEvSessionBufferSizeRequest : TEventLocal(ENetwork::EvSessionBufferSizeRequest)> { //DEFINE_SIMPLE_LOCAL_EVENT(TEvSessionBufferSizeRequest, "Session: TEvSessionBufferSizeRequest") DEFINE_SIMPLE_LOCAL_EVENT(TEvSessionBufferSizeRequest, "Network: TEvSessionBufferSizeRequest"); }; struct TEvSessionBufferSizeResponse : TEventLocal(ENetwork::EvSessionBufferSizeResponse)> { TEvSessionBufferSizeResponse(const TActorId& sessionId, ui64 outputBufferSize) : SessionID(sessionId) , BufferSize(outputBufferSize) { } TActorId SessionID; ui64 BufferSize; }; struct TEvProcessPingRequest : TEventLocal(ENetwork::EvProcessPingRequest)> { const ui64 Payload; TEvProcessPingRequest(ui64 payload) : Payload(payload) {} }; struct TEvGetSecureSocket : TEventLocal { TIntrusivePtr Socket; TEvGetSecureSocket(TIntrusivePtr socket) : Socket(std::move(socket)) {} }; struct TEvSecureSocket : TEventLocal { TIntrusivePtr Socket; TEvSecureSocket(TIntrusivePtr socket) : Socket(std::move(socket)) {} }; }