Beispiel #1
0
/* Child process that finds out what to connect to and proxies 
 */
void start_shoveler(int in_socket)
{
   fd_set fds;
   struct timeval tv;
   int res = PROBE_AGAIN;
   int out_socket;
   struct connection cnx;

   init_cnx(&cnx);
   cnx.q[0].fd = in_socket;

   FD_ZERO(&fds);
   FD_SET(in_socket, &fds);
   memset(&tv, 0, sizeof(tv));
   tv.tv_sec = probing_timeout;

   while (res == PROBE_AGAIN) {
       /* POSIX does not guarantee that tv will be updated, but the client can
        * only postpone the inevitable for so long */
       res = select(in_socket + 1, &fds, NULL, NULL, &tv);
       if (res == -1)
           perror("select");

       if (FD_ISSET(in_socket, &fds)) {
           /* Received data: figure out what protocol it is */
           res = probe_client_protocol(&cnx);
       } else {
           /* Timed out: it's necessarily SSH */
           cnx.proto = timeout_protocol();
           break;
       }
   }

   if (cnx.proto->service &&
       check_access_rights(in_socket, cnx.proto->service)) {
       exit(0);
   }

   /* Connect the target socket */
   out_socket = connect_addr(&cnx, in_socket);
   CHECK_RES_DIE(out_socket, "connect");

   cnx.q[1].fd = out_socket;

   log_connection(&cnx);

   flush_deferred(&cnx.q[1]);

   shovel(&cnx);

   close(in_socket);
   close(out_socket);
   
   if (verbose)
      fprintf(stderr, "connection closed down\n");

   exit(0);
}
Beispiel #2
0
int
connect_peer(char *peer, char *port) {
  struct addrinfo *addr = get_peer_addr(peer, port);
  int sock = get_socket(addr);
  connect_addr(sock, addr);
  set_nodelay(sock);
  freeaddrinfo(addr);
  return sock;
}
Beispiel #3
0
  int CloudBus::svc(void)
  {
    
    while (true) {
      if (connected_) {
	//
      } else {
	std::string connect_addr(relay_inet_addr_);
	if (connect_addr == "localhost") {
	  connect_addr = node_info_.address;
	}
	ACE_INET_Addr server(relay_port_,connect_addr.c_str());
	ACE_SOCK_Connector connector;

	if (connector.connect(this->peer(),server) == 0) {
	  ACE_TCHAR peer_name[MAXHOSTNAMELENGTH];
	  ACE_INET_Addr peer_addr;
	  if ((this->peer().get_remote_addr (peer_addr) == 0) && 
	      (peer_addr.addr_to_string (peer_name, MAXHOSTNAMELENGTH) == 0)) {

	    GDEBUG("CloudBus connected to relay at  %s\n", peer_name);
	    if (this->reactor ()->register_handler(this, ACE_Event_Handler::READ_MASK) != 0) {
	      GERROR("Failed to register read handler\n");
	      return -1;
	    }

	    mtx_.acquire();
	    connected_ = true;
	    mtx_.release();
	    if (!query_mode_) {
	      send_node_info();
	    }
	  } 
	}
      }
      //Sleep for 5 seconds
      ACE_Time_Value tv (5);
      ACE_OS::sleep (tv);	  	
    }
    return 0;
  }