Cuberite
A lightweight, fast and extensible game server for Minecraft
LuaTCPLink.h
Go to the documentation of this file.
1 
2 // LuaTCPLink.h
3 
4 // Declares the cLuaTCPLink class representing a Lua wrapper for the cTCPLink class and the callbacks it needs
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "../OSSupport/Network.h"
13 #include "LuaState.h"
14 
15 
16 
17 
18 
19 // fwd:
20 class cLuaServerHandle;
21 typedef std::weak_ptr<cLuaServerHandle> cLuaServerHandleWPtr;
22 
23 
24 
25 
26 
30 {
31 public:
33  cLuaTCPLink(cLuaState::cTableRefPtr && a_Callbacks);
34 
37 
38  virtual ~cLuaTCPLink() override;
39 
42  bool Send(const AString & a_Data);
43 
45  AString GetLocalIP(void) const;
46 
48  UInt16 GetLocalPort(void) const;
49 
51  AString GetRemoteIP(void) const;
52 
54  UInt16 GetRemotePort(void) const;
55 
59  void Shutdown(void);
60 
63  void Close(void);
64 
72  const AString & a_OwnCertData,
73  const AString & a_OwnPrivKeyData,
74  const AString & a_OwnPrivKeyPassword,
75  const AString & a_TrustedRootCAs
76  );
77 
87  const AString & a_OwnCertData,
88  const AString & a_OwnPrivKeyData,
89  const AString & a_OwnPrivKeyPassword,
90  const AString & a_StartTLSData
91  );
92 
93 protected:
94 
97 
101 
104 
107  void Terminated(void);
108 
111  void ReceivedCleartextData(const char * a_Data, size_t a_NumBytes);
112 
113  // cNetwork::cConnectCallbacks overrides:
114  virtual void OnConnected(cTCPLink & a_Link) override;
115  virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) override;
116 
117  // cTCPLink::cCallbacks overrides:
118  virtual void OnLinkCreated(cTCPLinkPtr a_Link) override;
119  virtual void OnReceivedData(const char * a_Data, size_t a_Length) override;
120  virtual void OnRemoteClosed(void) override;
121  // The OnError() callback is shared with cNetwork::cConnectCallbacks
122 };
123 
124 
125 
126 
std::weak_ptr< cLuaServerHandle > cLuaServerHandleWPtr
Definition: LuaTCPLink.h:20
unsigned short UInt16
Definition: Globals.h:158
std::shared_ptr< cTCPLink > cTCPLinkPtr
Definition: Network.h:25
std::string AString
Definition: StringUtils.h:11
std::unique_ptr< cTableRef > cTableRefPtr
Definition: LuaState.h:419
UInt16 GetRemotePort(void) const
Returns the port used by the remote endpoint of the connection.
Definition: LuaTCPLink.cpp:119
cLuaServerHandleWPtr m_Server
The server that is responsible for this link, if any.
Definition: LuaTCPLink.h:103
virtual void OnReceivedData(const char *a_Data, size_t a_Length) override
Called when there's data incoming from the remote peer.
Definition: LuaTCPLink.cpp:322
AString GetLocalIP(void) const
Returns the IP address of the local endpoint of the connection.
Definition: LuaTCPLink.cpp:68
cLuaTCPLink(cLuaState::cTableRefPtr &&a_Callbacks)
Creates a new instance of the link, wrapping the callbacks that are in the specified table.
Definition: LuaTCPLink.cpp:16
bool Send(const AString &a_Data)
Sends the data contained in the string to the remote peer.
Definition: LuaTCPLink.cpp:51
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.
Definition: LuaTCPLink.cpp:166
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when an error is detected on the connection.
Definition: LuaTCPLink.cpp:299
virtual void OnRemoteClosed(void) override
Called when the remote end closes the connection.
Definition: LuaTCPLink.cpp:332
void Close(void)
Drops the connection without any more processing.
Definition: LuaTCPLink.cpp:150
void ReceivedCleartextData(const char *a_Data, size_t a_NumBytes)
Called by the SSL context when there's incoming data available in the cleartext.
Definition: LuaTCPLink.cpp:279
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.
Definition: LuaTCPLink.cpp:216
void Terminated(void)
Common code called when the link is considered as terminated.
Definition: LuaTCPLink.cpp:249
cLuaState::cTableRefPtr m_Callbacks
The Lua table that holds the callbacks to be invoked.
Definition: LuaTCPLink.h:96
virtual void OnConnected(cTCPLink &a_Link) override
Called when the Connect call succeeds.
Definition: LuaTCPLink.cpp:289
AString GetRemoteIP(void) const
Returns the IP address of the remote endpoint of the connection.
Definition: LuaTCPLink.cpp:102
void Shutdown(void)
Closes the link gracefully.
Definition: LuaTCPLink.cpp:136
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override
Called when the cTCPLink for the connection is created.
Definition: LuaTCPLink.cpp:312
cTCPLinkPtr m_Link
The underlying link representing the connection.
Definition: LuaTCPLink.h:100
UInt16 GetLocalPort(void) const
Returns the port used by the local endpoint of the connection.
Definition: LuaTCPLink.cpp:85
virtual ~cLuaTCPLink() override
Definition: LuaTCPLink.cpp:35
Interface that provides the methods available on a single TCP connection.
Definition: Network.h:42
Callbacks used for connecting to other servers as a client.
Definition: Network.h:237