Beispiel #1
0
	void session::start(int flags, settings_pack const& pack, io_service* ios)
	{
		bool const internal_executor = ios == nullptr;

		if (internal_executor)
		{
			// the user did not provide an executor, we have to use our own
			m_io_service = boost::make_shared<io_service>();
			ios = m_io_service.get();
		}

		m_impl = boost::make_shared<session_impl>(boost::ref(*ios));
		*static_cast<session_handle*>(this) = session_handle(m_impl.get());

#ifndef TORRENT_DISABLE_EXTENSIONS
		if (flags & add_default_plugins)
		{
			add_extension(create_ut_pex_plugin);
			add_extension(create_ut_metadata_plugin);
			add_extension(create_smart_ban_plugin);
		}
#else
		TORRENT_UNUSED(flags);
#endif

		m_impl->start_session(pack);

		if (internal_executor)
		{
			// start a thread for the message pump
			m_thread = std::make_shared<std::thread>(
				[&]() { m_io_service->run(); });
		}
	}
Beispiel #2
0
SessionHandle IEServer::InitializeSession() {
  LOG(TRACE) << "Entering IEServer::InitializeSession";
  SessionHandle session_handle(new IESession());
  SessionParameters params;
  params.port = this->port();
  session_handle->Initialize(reinterpret_cast<void*>(&params));
  return session_handle;
}
Beispiel #3
0
std::wstring Server::CreateSession() {
	// TODO: make this generic and not tightly bound to the IESession class
	SessionHandle session_handle(new IESession(this->port_));
	std::wstring session_id = session_handle->Initialize();

	this->sessions_[session_id] = session_handle;
	return session_id;
}
Beispiel #4
0
SessionHandle IEServer::InitializeSession() {
  LOG(TRACE) << "Entering IEServer::InitializeSession";
  SessionHandle session_handle(new IESession());
  SessionParameters params;
  params.port = this->port();
  params.implementation = IESession::ConvertDriverEngine(this->driver_implementation_);
  session_handle->Initialize(reinterpret_cast<void*>(&params));
  return session_handle;
}
Beispiel #5
0
static inline int
session_send_evt_to_thread (void *data, void *args, u32 thread_index,
			    session_evt_type_t evt_type)
{
  session_event_t *evt;
  svm_msg_q_msg_t msg;
  svm_msg_q_t *mq;
  u32 tries = 0, max_tries;

  mq = session_main_get_vpp_event_queue (thread_index);
  while (svm_msg_q_try_lock (mq))
    {
      max_tries = vlib_get_current_process (vlib_get_main ())? 1e6 : 3;
      if (tries++ == max_tries)
	{
	  SESSION_DBG ("failed to enqueue evt");
	  return -1;
	}
    }
  if (PREDICT_FALSE (svm_msg_q_ring_is_full (mq, SESSION_MQ_IO_EVT_RING)))
    {
      svm_msg_q_unlock (mq);
      return -2;
    }
  msg = svm_msg_q_alloc_msg_w_ring (mq, SESSION_MQ_IO_EVT_RING);
  if (PREDICT_FALSE (svm_msg_q_msg_is_invalid (&msg)))
    {
      svm_msg_q_unlock (mq);
      return -2;
    }
  evt = (session_event_t *) svm_msg_q_msg_data (mq, &msg);
  evt->event_type = evt_type;
  switch (evt_type)
    {
    case SESSION_CTRL_EVT_RPC:
      evt->rpc_args.fp = data;
      evt->rpc_args.arg = args;
      break;
    case SESSION_IO_EVT_TX:
    case SESSION_IO_EVT_TX_FLUSH:
    case SESSION_IO_EVT_BUILTIN_RX:
      evt->session_index = *(u32 *) data;
      break;
    case SESSION_IO_EVT_BUILTIN_TX:
    case SESSION_CTRL_EVT_CLOSE:
      evt->session_handle = session_handle ((session_t *) data);
      break;
    default:
      clib_warning ("evt unhandled!");
      svm_msg_q_unlock (mq);
      return -1;
    }

  svm_msg_q_add_and_unlock (mq, &msg);
  return 0;
}
Beispiel #6
0
static void
session_program_transport_close (session_t * s)
{
  u32 thread_index = vlib_get_thread_index ();
  session_worker_t *wrk;
  session_event_t *evt;

  /* If we are in the handler thread, or being called with the worker barrier
   * held, just append a new event to pending disconnects vector. */
  if (vlib_thread_is_main_w_barrier () || thread_index == s->thread_index)
    {
      wrk = session_main_get_worker (s->thread_index);
      vec_add2 (wrk->pending_disconnects, evt, 1);
      clib_memset (evt, 0, sizeof (*evt));
      evt->session_handle = session_handle (s);
      evt->event_type = SESSION_CTRL_EVT_CLOSE;
    }
  else
    session_send_ctrl_evt_to_thread (s, SESSION_CTRL_EVT_CLOSE);
}
Beispiel #7
0
	void session::start(int flags, settings_pack const& pack, io_service* ios)
	{
#if defined _MSC_VER && defined TORRENT_DEBUG
		// workaround for microsofts
		// hardware exceptions that makes
		// it hard to debug stuff
		::_set_se_translator(straight_to_debugger);
#endif

		bool internal_executor = ios == NULL;

		if (internal_executor)
		{
			// the user did not provide an executor, we have to use our own
			m_io_service = boost::make_shared<io_service>();
			ios = m_io_service.get();
		}

		m_impl = boost::make_shared<session_impl>(boost::ref(*ios));
		*static_cast<session_handle*>(this) = session_handle(m_impl.get());

#ifndef TORRENT_DISABLE_EXTENSIONS
		if (flags & add_default_plugins)
		{
			add_extension(create_ut_pex_plugin);
			add_extension(create_ut_metadata_plugin);
			add_extension(create_smart_ban_plugin);
		}
#else
		TORRENT_UNUSED(flags);
#endif

		m_impl->start_session(pack);

		if (internal_executor)
		{
			// start a thread for the message pump
			m_thread = boost::make_shared<thread>(boost::bind(&io_service::run
				, m_io_service.get()));
		}
	}
Beispiel #8
0
SessionHandle IEServer::InitializeSession() {
  SessionHandle session_handle(new IESession());
  int port = this->port();
  session_handle->Initialize(&port);
  return session_handle;
}
Beispiel #9
0
/*
 * 1.Learn the port number through which the session will send the data.
 * 2.Spawn a new thread to send the data and give the control back to the above layer
 */ 
void *session_transfer(void *ptr) {

	/* Extract the data from the above layer */
	session_data *s_data;
	s_data = (session_data *) ptr;

        while (1) {

                /* Allocate the session */ 
                session_t session;
                                                
                /* Fill the session structure */
                session_build_parameters(s_data->ip, s_data->host_name, &session);

                /* Send the hello packets to get the port number */
                int ret = 0;
                ret = learn_new_port(&session);

                if (ret == -1) {
                        printf("No port assigned.\n");
                        continue;
                }

                /* Change the port number of the address since the new port will be used for further communication */
                session.address.sin_port = htons(session.port);

                log_mesg("SESSION connected to Port %d\n", session.port);
                printf("SESSION connected to Port %d\n", session.port);

                /* Connection is established. Lets read from the stdin and transfer the data */
                char session_data[SESSION_SIZE + MAX_RECORD_SIZE] = {0};
                char *success;
                int num_bytes = 0;

                while (1) {

                        /* Read the data from standard input. Read SESSION_SIZE bytes and send the data */
                        while(1) {
                                printf("Read %d bytes..\n", num_bytes);
                                  success = fgets(session_data + num_bytes, MAX_RECORD_SIZE, stdin);

                                  num_bytes = strlen(session_data);

                                  if (!success) {
                                          /* Nothing to read. BREAK. */
                                          printf("No data to read. \n");
                                          break;
                                  }
                                  
                                  if (num_bytes >= SESSION_SIZE) {
                                          printf("Session Full ...\n");
                                          break;
                                  }
                        }


                        /* No data. Lets sleep for sometime */
                        if (strlen(session_data) == 0 ) {
                                printf("No data to send. \n");
                                sleep(10);
                                continue;
                        } else {
                                printf("Sending data ...\n");

                                memcpy(session.file_name, "DATA.txt", sizeof(session.file_name));

                                session.no_of_bytes = strlen(session_data);
                                session.total_no_of_bytes = session.no_of_bytes;

                                /* Calculate the number of data packets in the session */
                                session.no_of_packets = session.no_of_bytes/MAX_FRAME_SIZE;

                                /* One more packet is required if some more bytes are left */
                                if (session.no_of_bytes % MAX_FRAME_SIZE) {
                                        session.no_of_packets++;
                                }

                                /* Initialize the sequence number for the data packets*/
                                session.next_frame_number = 0;

                                /* Handle session */
                                session_handle(&session, session_data);
                                printf("Send Over... \n");
                                          
                                /* Reset the buffer */
                                bzero(session_data, SESSION_SIZE + MAX_RECORD_SIZE);
                                num_bytes = 0;
                        }
                }
        }
}