@ -202,8 +202,9 @@ execute_server(struct sc_server *server,
}
}
static bool
static bool
connect_and_read_byte ( struct sc_intr * intr , sc_socket socket , uint16_t port ) {
connect_and_read_byte ( struct sc_intr * intr , sc_socket socket ,
bool ok = net_connect_intr ( intr , socket , IPV4_LOCALHOST , port ) ;
uint32_t tunnel_host , uint16_t tunnel_port ) {
bool ok = net_connect_intr ( intr , socket , tunnel_host , tunnel_port ) ;
if ( ! ok ) {
if ( ! ok ) {
return false ;
return false ;
}
}
@ -220,13 +221,13 @@ connect_and_read_byte(struct sc_intr *intr, sc_socket socket, uint16_t port) {
}
}
static sc_socket
static sc_socket
connect_to_server ( struct sc_server * server , uint32_t attempts , sc_tick delay ) {
connect_to_server ( struct sc_server * server , uint32_t attempts , sc_tick delay ,
uint16_t port = server - > tunnel . local_port ;
uint32_t host , uint16_t port ) {
do {
do {
LOGD ( " Remaining connection attempts: %d " , ( int ) attempts ) ;
LOGD ( " Remaining connection attempts: %d " , ( int ) attempts ) ;
sc_socket socket = net_socket ( ) ;
sc_socket socket = net_socket ( ) ;
if ( socket ! = SC_SOCKET_NONE ) {
if ( socket ! = SC_SOCKET_NONE ) {
bool ok = connect_and_read_byte ( & server - > intr , socket , port) ;
bool ok = connect_and_read_byte ( & server - > intr , socket , host, port) ;
if ( ok ) {
if ( ok ) {
// it worked!
// it worked!
return socket ;
return socket ;
@ -352,9 +353,20 @@ sc_server_connect_to(struct sc_server *server, struct sc_server_info *info) {
goto fail ;
goto fail ;
}
}
} else {
} else {
uint32_t tunnel_host = server - > params . tunnel_host ;
if ( ! tunnel_host ) {
tunnel_host = IPV4_LOCALHOST ;
}
uint16_t tunnel_port = server - > params . tunnel_port ;
if ( ! tunnel_port ) {
tunnel_port = tunnel - > local_port ;
}
uint32_t attempts = 100 ;
uint32_t attempts = 100 ;
sc_tick delay = SC_TICK_FROM_MS ( 100 ) ;
sc_tick delay = SC_TICK_FROM_MS ( 100 ) ;
video_socket = connect_to_server ( server , attempts , delay ) ;
video_socket = connect_to_server ( server , attempts , delay , tunnel_host ,
tunnel_port ) ;
if ( video_socket = = SC_SOCKET_NONE ) {
if ( video_socket = = SC_SOCKET_NONE ) {
goto fail ;
goto fail ;
}
}
@ -364,8 +376,8 @@ sc_server_connect_to(struct sc_server *server, struct sc_server_info *info) {
if ( control_socket = = SC_SOCKET_NONE ) {
if ( control_socket = = SC_SOCKET_NONE ) {
goto fail ;
goto fail ;
}
}
bool ok = net_connect_intr ( & server - > intr , control_socket ,
bool ok = net_connect_intr ( & server - > intr , control_socket , tunnel_host ,
IPV4_LOCALHOST, tunnel- > loca l_port) ;
tunnel_port) ;
if ( ! ok ) {
if ( ! ok ) {
goto fail ;
goto fail ;
}
}