Cuberite
A lightweight, fast and extensible game server for Minecraft
|
#include <LuaTCPLink.h>
Public Member Functions | |
void | Close (void) |
Drops the connection without any more processing. More... | |
cLuaTCPLink (cLuaState::cTableRefPtr &&a_Callbacks) | |
Creates a new instance of the link, wrapping the callbacks that are in the specified table. More... | |
cLuaTCPLink (cLuaState::cTableRefPtr &&a_Callbacks, cLuaServerHandleWPtr a_Server) | |
Creates a new instance of the link, attached to the specified plugin and wrapping the callbacks that are in the specified referenced table. More... | |
AString | GetLocalIP (void) const |
Returns the IP address of the local endpoint of the connection. More... | |
UInt16 | GetLocalPort (void) const |
Returns the port used by the local endpoint of the connection. More... | |
AString | GetRemoteIP (void) const |
Returns the IP address of the remote endpoint of the connection. More... | |
UInt16 | GetRemotePort (void) const |
Returns the port used by the remote endpoint of the connection. More... | |
bool | Send (const AString &a_Data) |
Sends the data contained in the string to the remote peer. More... | |
void | Shutdown (void) |
Closes the link gracefully. More... | |
AString | StartTLSClient (const AString &a_OwnCertData, const AString &a_OwnPrivKeyData, const AString &a_OwnPrivKeyPassword, const AString &a_TrustedRootCAs) |
Starts a TLS handshake as a client connection. More... | |
AString | StartTLSServer (const AString &a_OwnCertData, const AString &a_OwnPrivKeyData, const AString &a_OwnPrivKeyPassword, const AString &a_StartTLSData) |
Starts a TLS handshake as a server connection. More... | |
virtual | ~cLuaTCPLink () override |
Public Member Functions inherited from cNetwork::cConnectCallbacks | |
virtual | ~cConnectCallbacks () |
Public Member Functions inherited from cTCPLink::cCallbacks | |
virtual void | OnTlsHandshakeCompleted (void) |
Called when the TLS handshake has been completed and communication can continue regularly. More... | |
virtual | ~cCallbacks () |
Protected Member Functions | |
virtual void | OnConnected (cTCPLink &a_Link) override |
Called when the Connect call succeeds. More... | |
virtual void | OnError (int a_ErrorCode, const AString &a_ErrorMsg) override |
Called when an error is detected on the connection. More... | |
virtual void | OnLinkCreated (cTCPLinkPtr a_Link) override |
Called when the cTCPLink for the connection is created. More... | |
virtual void | OnReceivedData (const char *a_Data, size_t a_Length) override |
Called when there's data incoming from the remote peer. More... | |
virtual void | OnRemoteClosed (void) override |
Called when the remote end closes the connection. More... | |
void | ReceivedCleartextData (const char *a_Data, size_t a_NumBytes) |
Called by the SSL context when there's incoming data available in the cleartext. More... | |
void | Terminated (void) |
Common code called when the link is considered as terminated. More... | |
Protected Attributes | |
cLuaState::cTableRefPtr | m_Callbacks |
The Lua table that holds the callbacks to be invoked. More... | |
cTCPLinkPtr | m_Link |
The underlying link representing the connection. More... | |
cLuaServerHandleWPtr | m_Server |
The server that is responsible for this link, if any. More... | |
Definition at line 27 of file LuaTCPLink.h.
cLuaTCPLink::cLuaTCPLink | ( | cLuaState::cTableRefPtr && | a_Callbacks | ) |
Creates a new instance of the link, wrapping the callbacks that are in the specified table.
Definition at line 16 of file LuaTCPLink.cpp.
cLuaTCPLink::cLuaTCPLink | ( | cLuaState::cTableRefPtr && | a_Callbacks, |
cLuaServerHandleWPtr | a_Server | ||
) |
Creates a new instance of the link, attached to the specified plugin and wrapping the callbacks that are in the specified referenced table.
Definition at line 25 of file LuaTCPLink.cpp.
|
overridevirtual |
Definition at line 35 of file LuaTCPLink.cpp.
void cLuaTCPLink::Close | ( | void | ) |
Drops the connection without any more processing.
Sends the RST packet, queued outgoing and incoming data is lost.
Definition at line 150 of file LuaTCPLink.cpp.
AString cLuaTCPLink::GetLocalIP | ( | void | ) | const |
Returns the IP address of the local endpoint of the connection.
Definition at line 68 of file LuaTCPLink.cpp.
UInt16 cLuaTCPLink::GetLocalPort | ( | void | ) | const |
Returns the port used by the local endpoint of the connection.
Definition at line 85 of file LuaTCPLink.cpp.
AString cLuaTCPLink::GetRemoteIP | ( | void | ) | const |
Returns the IP address of the remote endpoint of the connection.
Definition at line 102 of file LuaTCPLink.cpp.
UInt16 cLuaTCPLink::GetRemotePort | ( | void | ) | const |
Returns the port used by the remote endpoint of the connection.
Definition at line 119 of file LuaTCPLink.cpp.
|
overrideprotectedvirtual |
Called when the Connect call succeeds.
Provides the newly created link that can be used for communication.
Implements cNetwork::cConnectCallbacks.
Definition at line 289 of file LuaTCPLink.cpp.
|
overrideprotectedvirtual |
Called when an error is detected on the connection.
Implements cTCPLink::cCallbacks.
Definition at line 299 of file LuaTCPLink.cpp.
|
overrideprotectedvirtual |
Called when the cTCPLink for the connection is created.
The callback may store the cTCPLink instance for later use, but it should remove it in OnError(), OnRemoteClosed() or right after Close().
Implements cTCPLink::cCallbacks.
Definition at line 312 of file LuaTCPLink.cpp.
|
overrideprotectedvirtual |
Called when there's data incoming from the remote peer.
Implements cTCPLink::cCallbacks.
Definition at line 322 of file LuaTCPLink.cpp.
|
overrideprotectedvirtual |
Called when the remote end closes the connection.
The link is still available for connection information query (IP / port). Sending data on the link is not an error, but the data won't be delivered.
Implements cTCPLink::cCallbacks.
Definition at line 332 of file LuaTCPLink.cpp.
|
protected |
Called by the SSL context when there's incoming data available in the cleartext.
Reports the data via the Lua callback function.
Definition at line 279 of file LuaTCPLink.cpp.
bool cLuaTCPLink::Send | ( | const AString & | a_Data | ) |
Sends the data contained in the string to the remote peer.
Returns true if successful, false on immediate failure (queueing the data failed or link not available).
Definition at line 51 of file LuaTCPLink.cpp.
void cLuaTCPLink::Shutdown | ( | void | ) |
Closes the link gracefully.
The link will send any queued outgoing data, then it will send the FIN packet. The link will still receive incoming data from remote until the remote closes the connection.
Definition at line 136 of file LuaTCPLink.cpp.
AString cLuaTCPLink::StartTLSClient | ( | const AString & | a_OwnCertData, |
const AString & | a_OwnPrivKeyData, | ||
const AString & | a_OwnPrivKeyPassword, | ||
const AString & | a_TrustedRootCAs | ||
) |
Starts a TLS handshake as a client connection.
If a client certificate should be used for the connection, set the certificate into a_OwnCertData and its corresponding private key to a_OwnPrivKeyData. If both are empty, no client cert is presented. a_OwnPrivKeyPassword is the password to be used for decoding PrivKey, empty if not passworded. a_TrustedRootCAs is a
-delimited concatenation of trusted root CAs' certificates in PEM format Returns empty string on success, non-empty error description on failure.
Definition at line 166 of file LuaTCPLink.cpp.
AString cLuaTCPLink::StartTLSServer | ( | const AString & | a_OwnCertData, |
const AString & | a_OwnPrivKeyData, | ||
const AString & | a_OwnPrivKeyPassword, | ||
const AString & | a_StartTLSData | ||
) |
Starts a TLS handshake as a server connection.
Set the server certificate into a_CertData and its corresponding private key to a_OwnPrivKeyData. a_OwnPrivKeyPassword is the password to be used for decoding PrivKey, empty if not passworded. a_StartTLSData is any data that should be pushed into the TLS before reading more data from the remote. This is used mainly for protocols starting TLS in the middle of communication, when the TLS start command can be received together with the TLS Client Hello message in one OnReceivedData() call, to re-queue the Client Hello message into the TLS handshake buffer. Returns empty string on success, non-empty error description on failure.
Definition at line 216 of file LuaTCPLink.cpp.
|
protected |
Common code called when the link is considered as terminated.
Releases m_Link, m_Callbacks and this from m_Server, each when applicable.
Definition at line 249 of file LuaTCPLink.cpp.
|
protected |
The Lua table that holds the callbacks to be invoked.
Definition at line 96 of file LuaTCPLink.h.
|
protected |
The underlying link representing the connection.
May be nullptr.
Definition at line 100 of file LuaTCPLink.h.
|
protected |
The server that is responsible for this link, if any.
Definition at line 103 of file LuaTCPLink.h.