32 #ifndef ECHOLINK_PROXY_INCLUDED 33 #define ECHOLINK_PROXY_INCLUDED 43 #include <sigc++/sigc++.h> 52 #include <AsyncTcpClient.h> 53 #include <AsyncTimer.h> 128 class Proxy :
public sigc::trackable
147 Proxy(
const std::string &host, uint16_t port,
const std::string &callsign,
148 const std::string &password);
182 bool tcpOpen(
const Async::IpAddress &remote_ip);
227 bool udpData(
const Async::IpAddress &addr,
const void *data,
unsigned len);
239 bool udpCtrl(
const Async::IpAddress &addr,
const void *data,
unsigned len);
293 sigc::signal<void,
const Async::IpAddress&,
void*,
305 sigc::signal<void,
const Async::IpAddress&,
void*,
336 MSG_TYPE_TCP_OPEN=1, MSG_TYPE_TCP_DATA, MSG_TYPE_TCP_CLOSE,
337 MSG_TYPE_TCP_STATUS, MSG_TYPE_UDP_DATA, MSG_TYPE_UDP_CONTROL,
341 static const int NONCE_SIZE = 8;
342 static const int MSG_HEADER_SIZE = 1 + 4 + 4;
343 static const int RECONNECT_INTERVAL = 10000;
344 static const int CMD_TIMEOUT = 10000;
345 static const int recv_buf_size = 16384;
347 static Proxy *the_instance;
349 Async::TcpClient con;
350 const std::string callsign;
351 std::string password;
354 uint8_t recv_buf[recv_buf_size];
356 Async::Timer reconnect_timer;
357 Async::Timer cmd_timer;
361 bool sendMsgBlock(MsgBlockType type,
362 const Async::IpAddress &remote_ip=Async::IpAddress(),
363 const void *data=0,
unsigned len=0);
364 void onConnected(
void);
365 int onDataReceived(Async::TcpConnection *con,
void *data,
int len);
366 void onDisconnected(Async::TcpConnection *con,
367 Async::TcpClient::DisconnectReason reason);
368 void disconnectHandler(
void);
369 int handleAuthentication(
const unsigned char *buf,
int len);
370 int parseProxyMessageBlock(
unsigned char *buf,
int len);
371 void handleProxyMessageBlock(MsgBlockType type,
372 const Async::IpAddress &remote_ip, uint32_t len,
373 unsigned char *data);
374 void handleTcpDataMsg(uint8_t *buf,
int len);
375 void handleTcpCloseMsg(
const uint8_t *buf,
int len);
376 void handleTcpStatusMsg(
const uint8_t *buf,
int len);
377 void handleUdpDataMsg(
const Async::IpAddress &remote_ip, uint8_t *buf,
379 void handleUdpCtrlMsg(
const Async::IpAddress &remote_ip, uint8_t *buf,
381 void handleSystemMsg(
const unsigned char *buf,
int len);
382 void cmdTimeout(
void);
sigc::signal< void, uint32_t > tcpStatusReceived
Signal emitted when the TCP_STATUS proxy message is received.
sigc::signal< void, bool > proxyReady
A signal that is emitted when the proxy is ready for operation.
bool tcpClose(void)
Close an active TCP connection.
sigc::signal< void, const Async::IpAddress &, void *, unsigned > udpDataReceived
Signal emitted when UDP data has been received.
bool udpData(const Async::IpAddress &addr, const void *data, unsigned len)
Send UDP data to the specified remote IP.
bool udpCtrl(const Async::IpAddress &addr, const void *data, unsigned len)
Send UDP control data to the specified remote IP.
void disconnect(void)
Disconnect from the proxy server.
Proxy(const std::string &host, uint16_t port, const std::string &callsign, const std::string &password)
Default constuctor.
sigc::signal< void > tcpCloseReceived
Signal emitted when the TCP_CLOSE proxy message is received.
sigc::signal< void, const Async::IpAddress &, void *, unsigned > udpCtrlReceived
Signal emitted when UDP control data has been received.
void connect(void)
Connect to the proxy server.
bool tcpData(const void *data, unsigned len)
Send TCP data through an established TCP connection.
static Proxy * instance(void)
Implements the EchoLink Proxy protocol.
void reset(void)
Disconnect from proxy server then connect again after a delay.
sigc::signal< void > tcpConnected
Signal that is emitted when a TCP connection is established.
sigc::signal< void > tcpDisconnected
Signal that is emitted when a TCP connection is closed.
sigc::signal< int, void *, unsigned > tcpDataReceived
Signal emitted when TCP data has been received.
bool tcpOpen(const Async::IpAddress &remote_ip)
Open a TCP connection to port 5200 to the specified host.
Namespace to encapsulate EchoLink communication classes.
TcpState tcpState(void)
Read back the current TCP connection state.