17 #include <netinet/in.h>
79 virtual bool Send(
const void * a_Data,
size_t a_Length) = 0;
85 return Send(a_Data.data(), a_Data.size());
std::shared_ptr< cCryptoKey > cCryptoKeyPtr
std::shared_ptr< cX509Cert > cX509CertPtr
std::shared_ptr< cTCPLink > cTCPLinkPtr
std::shared_ptr< cCryptoKey > cCryptoKeyPtr
std::vector< cTCPLinkPtr > cTCPLinkPtrs
std::shared_ptr< cUDPEndpoint > cUDPEndpointPtr
std::shared_ptr< cX509Cert > cX509CertPtr
std::shared_ptr< cServerHandle > cServerHandlePtr
std::vector< cServerHandlePtr > cServerHandlePtrs
std::vector< AString > AStringVector
Interface that provides the methods available on a single TCP connection.
virtual UInt16 GetLocalPort(void) const =0
Returns the port used by the local endpoint of the connection.
bool Send(const AString &a_Data)
Queues the specified data for sending to the remote peer.
virtual UInt16 GetRemotePort(void) const =0
Returns the port used by the remote endpoint of the connection.
cCallbacksPtr GetCallbacks(void) const
Returns the callbacks that are used.
virtual AString StartTLSClient(cX509CertPtr a_OwnCert, cCryptoKeyPtr a_OwnPrivKey, cX509CertPtr a_TrustedRootCAs)=0
Starts a TLS handshake as a client connection.
virtual AString GetLocalIP(void) const =0
Returns the IP address of the local endpoint of the connection.
virtual bool Send(const void *a_Data, size_t a_Length)=0
Queues the specified data for sending to the remote peer.
virtual void Close(void)=0
Drops the connection without any more processing.
cTCPLink(cCallbacksPtr a_Callbacks)
Creates a new link, with the specified callbacks.
virtual void Shutdown(void)=0
Closes the link gracefully.
virtual AString StartTLSServer(cX509CertPtr a_OwnCert, cCryptoKeyPtr a_OwnPrivKey, const AString &a_StartTLSData)=0
Starts a TLS handshake as a server connection.
cCallbacksPtr m_Callbacks
Callbacks to be used for the various situations.
std::shared_ptr< cCallbacks > cCallbacksPtr
virtual AString GetRemoteIP(void) const =0
Returns the IP address of the remote endpoint of the connection.
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg)=0
Called when an error is detected on the connection.
virtual void OnReceivedData(const char *a_Data, size_t a_Length)=0
Called when there's data incoming from the remote peer.
virtual void OnRemoteClosed(void)=0
Called when the remote end closes the connection.
virtual void OnTlsHandshakeCompleted(void)
Called when the TLS handshake has been completed and communication can continue regularly.
virtual void OnLinkCreated(cTCPLinkPtr a_Link)=0
Called when the cTCPLink for the connection is created.
Interface that provides the methods available on a listening server socket.
virtual bool IsListening(void) const =0
Returns true if the server has been started correctly and is currently listening for incoming connect...
virtual void Close(void)=0
Stops the server, no more incoming connections will be accepted.
Interface that provides methods available on UDP communication endpoints.
virtual void Close(void)=0
Closes the underlying socket.
virtual bool IsOpen(void) const =0
Returns true if the endpoint is open.
cCallbacks & m_Callbacks
The callbacks used for various events on the endpoint.
cUDPEndpoint(cCallbacks &a_Callbacks)
Creates a new instance of an endpoint, with the specified callbacks.
virtual void EnableBroadcasts(void)=0
Marks the socket as capable of sending broadcast, using whatever OS API is needed.
virtual UInt16 GetPort(void) const =0
Returns the local port to which the underlying socket is bound.
virtual bool Send(const AString &a_Payload, const AString &a_Host, UInt16 a_Port)=0
Sends the specified payload in a single UDP datagram to the specified host + port combination.
Interface for the callbacks for events that can happen on the endpoint.
virtual void OnReceivedData(const char *a_Data, size_t a_Size, const AString &a_RemoteHost, UInt16 a_RemotePort)=0
Called when there is an incoming datagram from a remote host.
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg)=0
Called when an error occurs on the endpoint.
static bool Connect(const AString &a_Host, UInt16 a_Port, cConnectCallbacksPtr a_ConnectCallbacks, cTCPLink::cCallbacksPtr a_LinkCallbacks)
Queues a TCP connection to be made to the specified host.
static AStringVector EnumLocalIPAddresses(void)
Returns all local IP addresses for network interfaces currently available.
static cServerHandlePtr Listen(UInt16 a_Port, cListenCallbacksPtr a_ListenCallbacks)
Opens up the specified port for incoming connections.
std::shared_ptr< cListenCallbacks > cListenCallbacksPtr
static cUDPEndpointPtr CreateUDPEndpoint(UInt16 a_Port, cUDPEndpoint::cCallbacks &a_Callbacks)
Opens up an UDP endpoint for sending and receiving UDP datagrams on the specified port.
std::shared_ptr< cConnectCallbacks > cConnectCallbacksPtr
static bool HostnameToIP(const AString &a_Hostname, cResolveNameCallbacksPtr a_Callbacks)
Queues a DNS query to resolve the specified hostname to IP address.
static bool IPToHostName(const AString &a_IP, cResolveNameCallbacksPtr a_Callbacks)
Queues a DNS query to resolve the specified IP address to a hostname.
std::shared_ptr< cResolveNameCallbacks > cResolveNameCallbacksPtr
Callbacks used for connecting to other servers as a client.
virtual void OnConnected(cTCPLink &a_Link)=0
Called when the Connect call succeeds.
virtual ~cConnectCallbacks()
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg)=0
Called when the Connect call fails.
Callbacks used when listening for incoming connections as a server.
virtual cTCPLink::cCallbacksPtr OnIncomingConnection(const AString &a_RemoteIPAddress, UInt16 a_RemotePort)=0
Called when the TCP server created with Listen() receives a new incoming connection.
virtual ~cListenCallbacks()
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg)=0
Called when the socket fails to listen on the specified port.
virtual void OnAccepted(cTCPLink &a_Link)=0
Called when the TCP server created with Listen() creates a new link for an incoming connection.
Callbacks used when resolving names to IPs.
virtual bool OnNameResolvedV6(const AString &a_Name, const sockaddr_in6 *a_IP)
Called when the hostname is successfully resolved into an IPv6 address.
virtual void OnFinished(void)=0
Called when all the addresses resolved have been reported via the OnNameResolved() callback.
virtual ~cResolveNameCallbacks()
virtual void OnNameResolved(const AString &a_Name, const AString &a_IP)=0
Called when the hostname is successfully resolved into an IP address.
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg)=0
Called when an error is encountered while resolving.
virtual bool OnNameResolvedV4(const AString &a_Name, const sockaddr_in *a_IP)
Called when the hostname is successfully resolved into an IPv4 address.