27 #ifndef ECHOLINK_PROXY_INCLUDED 28 #define ECHOLINK_PROXY_INCLUDED 38 #include <sigc++/sigc++.h> 47 #include <AsyncTcpClient.h> 48 #include <AsyncTimer.h> 121 class Proxy :
public sigc::trackable
140 Proxy(
const std::string &host, uint16_t port,
const std::string &callsign,
141 const std::string &password);
175 bool tcpOpen(
const Async::IpAddress &remote_ip);
220 bool udpData(
const Async::IpAddress &addr,
const void *data,
unsigned len);
232 bool udpCtrl(
const Async::IpAddress &addr,
const void *data,
unsigned len);
287 sigc::signal<void,
const Async::IpAddress&, uint16_t,
void*,
300 sigc::signal<void,
const Async::IpAddress&, uint16_t,
void*,
331 MSG_TYPE_TCP_OPEN=1, MSG_TYPE_TCP_DATA, MSG_TYPE_TCP_CLOSE,
332 MSG_TYPE_TCP_STATUS, MSG_TYPE_UDP_DATA, MSG_TYPE_UDP_CONTROL,
336 static const int NONCE_SIZE = 8;
337 static const int MSG_HEADER_SIZE = 1 + 4 + 4;
338 static const int RECONNECT_INTERVAL = 10000;
339 static const int CMD_TIMEOUT = 10000;
340 static const int recv_buf_size = 16384;
342 static Proxy *the_instance;
344 Async::TcpClient<> con;
345 const std::string callsign;
346 std::string password;
349 uint8_t recv_buf[recv_buf_size];
351 Async::Timer reconnect_timer;
352 Async::Timer cmd_timer;
356 bool sendMsgBlock(MsgBlockType type,
357 const Async::IpAddress &remote_ip=Async::IpAddress(),
358 const void *data=0,
unsigned len=0);
359 void onConnected(
void);
360 int onDataReceived(Async::TcpConnection *con,
void *data,
int len);
361 void onDisconnected(Async::TcpConnection *con,
362 Async::TcpClient<>::DisconnectReason reason);
363 void disconnectHandler(
void);
364 int handleAuthentication(
const unsigned char *buf,
int len);
365 int parseProxyMessageBlock(
unsigned char *buf,
int len);
366 void handleProxyMessageBlock(MsgBlockType type,
367 const Async::IpAddress &remote_ip, uint32_t len,
368 unsigned char *data);
369 void handleTcpDataMsg(uint8_t *buf,
int len);
370 void handleTcpCloseMsg(
const uint8_t *buf,
int len);
371 void handleTcpStatusMsg(
const uint8_t *buf,
int len);
372 void handleUdpDataMsg(
const Async::IpAddress &remote_ip, uint8_t *buf,
374 void handleUdpCtrlMsg(
const Async::IpAddress &remote_ip, uint8_t *buf,
376 void handleSystemMsg(
const unsigned char *buf,
int len);
377 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.
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.
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, const Async::IpAddress &, uint16_t, void *, unsigned > udpCtrlReceived
Signal emitted when UDP control data has been received.
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< void, const Async::IpAddress &, uint16_t, void *, unsigned > udpDataReceived
Signal emitted when UDP data has been received.
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.