Exemplo n.º 1
0
/** \brief Start the operation
 */
bt_err_t bt_session_t::start(const ipport_aview_t &p_listen_aview, const bt_id_t &p_local_peerid)	throw()
{
	socket_err_t	socket_err;
	// log to debug
	KLOG_ERR("p_listen_aview=" << p_listen_aview);
	// copy the parameter
	this->m_listen_aview	= p_listen_aview;
	
	// start the socket_resp_t
	socket_resp_arg_t	resp_arg;
	resp_arg	= bt_session_helper_t::build_socket_resp_arg(listen_lview(), this);
	socket_resp	= nipmem_new socket_resp_t();
	socket_err	= socket_resp->start(resp_arg, this, NULL);
	if( socket_err.failed() )	return bt_err_from_socket(socket_err);

	// update the listen_aview in case socket_resp_t did dynamic binding
	ipport_addr_t	bound_listen_lview = socket_resp->listen_addr().get_peerid_vapi()->to_string()
					+ std::string(":")
					+ socket_resp->listen_addr().get_portid_vapi()->to_string();
	this->m_listen_aview.update_once_bound(bound_listen_lview);

	// set the local_peerid - if the parameter is unset, get 
	if( !p_local_peerid.is_null() )	m_local_peerid	= p_local_peerid;
	else				m_local_peerid	= bt_id_t::build_random();

	// init the static link http - to ease access while debugging
	wikidbg_obj_add_static_page("/bt_session_" + local_peerid().to_string());
	// return no error
	return bt_err_t::OK;
}
Exemplo n.º 2
0
/** \brief Set the bt_ezsession_t recv_maxrate/xmit_maxrate
 */
static bool	set_ezsession_maxrate(void *userptr, const std::string &direction
			, const std::string &rate_str)	throw()
{
	btcli_resp_t *		btcli_resp	= (btcli_resp_t*)userptr;
	bt_ezsession_t *	bt_ezsession	= btcli_resp->bt_ezsession();
	// log to debug
	KLOG_ERR("direction=" << direction << " newrate=" << rate_str);	
	// get the rate_sched_t depending on the direction
	rate_sched_t *		rate_sched	= NULL;
	if( direction == "recv")	rate_sched = bt_ezsession->recv_rsched();
	if( direction == "xmit")	rate_sched = bt_ezsession->xmit_rsched();
	
	// TODO if rate_sched is null here, notify an error to the caller with 
	// "xmit rate sched is not tunable"
	DBG_ASSERT( rate_sched );
	
	// convert the new_rate_str into a double
	double	new_rate	= double(string_t::to_uint64(rate_str));
	// set the new maxrate
	rate_sched->max_rate(new_rate);
	
	// return true all the time
	// TODO currently void is not supported
	// - i need to have a way to report the error to the xmlrpc caller
	// - how do i do that ?
	return true;
}
Exemplo n.º 3
0
/** \brief Start the operation
 * 
 * @return true on error, false otherwise
 */
bool	asyncop_t::start(asyncop_completed_cb_t *callback, void *userptr
				, asyncop_do_work_cb_t do_work_cb
				, asyncop_free_work_cb_t free_work_cb )	throw()
{
	// copy the parameter
	this->callback	= callback;
	this->userptr	= userptr;

	// allocate the thread_ctx - it gonna be freed in t
	thread_ctx	= nipmem_new asyncop_thread_ctx_t();
	// fill the struct
	thread_ctx->do_work_cb	= do_work_cb;
	thread_ctx->free_work_cb= free_work_cb;
	thread_ctx->result_ptr	= NULL;
	thread_ctx->userptr	= userptr;
	thread_ctx->asyncop	= this;

	// initialize glib thread if needed
	if(!g_thread_supported ())	g_thread_init (NULL);
	// create the thread
	GError *gerr	= NULL;
	GThread*thread	= g_thread_create(asyncop_thread_glib_cb, thread_ctx, TRUE, &gerr);
	if( gerr != NULL ){
		KLOG_ERR("can't create a thread for asyncop_t due to gerr=" << gerr->message);
		g_error_free(gerr);
		return true;
	}
	// sanity check - the thread MUST be non NULL
	DBG_ASSERT( thread );

	// return no error
	return false;
}
Exemplo n.º 4
0
/** \brief handle the reception of a ntudp_event_t::CNX_ESTABLISHED from itor
 */
bool	ntudp_client_t::recv_cnx_established(ntudp_full_t *ntudp_full)	throw()
{
	ntudp_err_t	ntudp_err;
	ntudp_event_t	ntudp_event;
	// copy the ntudp_full_t pointer
	this->ntudp_full = ntudp_full;
	// start the ntudp_full
	ntudp_err = ntudp_full->start(this, NULL);
	if( ntudp_err.failed() )	goto error;

	// logging to debug
	KLOG_DBG("create a full udp " << *ntudp_full);
	
	// notify a CNX_ESTABLISHED with a NULL pointer
	// - the NULL pointer is required as the ntudp_full is already contained in the ntudp_client_t
	ntudp_event = ntudp_event_t::build_cnx_established(NULL);
	// notify the event
	return notify_callback(ntudp_event);
	
error:;	KLOG_ERR("Unable to init ntudp_full due to " << ntudp_err );
	// delete ntudp_full and mark it unused
	nipmem_zdelete	ntudp_full;
	// TODO: solve this issue
	// - ntudp_event has no real cnx_refused as it has no connection establishement over the wire
	// - so how to notify this error ?
	// - note that this error is currently quite theorical - doing a ASSERT( 0 ) until it 
	//   a solution is found
	DBG_ASSERT( 0 );
	// notify a CNX_REFUSED
//	ntudp_event = ntudp_event_t::build_cnx_refused("Unable to init ntudp_full due to "+ ntudp_err.to_string());
	// notify the event
//	notify_callback(ntudp_event);
	// return dontkeep - as the notified has just been deleted
	return false;
}
Exemplo n.º 5
0
/** \brief callback notified by \ref socket_full_t when to notify an event
 */
bool	router_resp_cnx_t::neoip_socket_full_event_cb(void *userptr, socket_full_t &cb_socket_full
							, const socket_event_t &socket_event)	throw()
{
	KLOG_ERR("enter event=" << socket_event);
	// sanity check - the event MUST be full_ok
	DBG_ASSERT( socket_event.is_full_ok() );
	
	// if the socket_event_t is fatal, autodelete this router_resp_cnx_t
	if( socket_event.is_fatal() ){
		nipmem_delete	this;
		return false;
	}
	
	// handle each possible events from its type
	switch( socket_event.get_value() ){
	case socket_event_t::RECVED_DATA:
			// handle the received packet
			return handle_recved_data(*socket_event.get_recved_data());
	case socket_event_t::NEW_MTU:
			// TODO FIXME to look at i am not sure about the mtu discovery state
			// - it depends on the socket_t semantique in fact
			DBG_ASSERT( 0 );		
	default:	DBG_ASSERT(0);
	}	
	// return 'tokeep'
	return true;	
}
Exemplo n.º 6
0
/** \brief Return the file_range_t to read - may return null if no data are available
 * 
 * - even in case of has_circularidx, the returned file_range_t.beg is always < than end()
 */
file_range_t	bt_httpo_full_t::range_to_read()	const throw()
{
	const bt_mfile_t &	bt_mfile	= bt_swarm->get_mfile();
	const bt_pieceavail_t &	pieceavail	= bt_swarm->local_pavail();
	file_size_t		chunk_beg	= current_pos();
	file_size_t		chunk_end	= m_range_tosend.end();
	// log to debug
	KLOG_ERR("enter chunk_beg=" << chunk_beg << " chunk_end=" << chunk_end);
	// sanity check - bt_io_read_t MUST NOT be in progress when this function is called
	DBG_ASSERT( bt_io_read == NULL );

	// if the socket_full_t xmitbuf has no freespace, return now
	if( socket_full->xmitbuf_freelen() == 0 )		return file_range_t();

	// if the chunk_beg is > than chunk_end, return now
	// - special case which means that all data has been delivered
	// - happen IIF not has_circularidx()
	if( chunk_beg > chunk_end )				return file_range_t();

	// compute pieceidx_beg of the chunk_beg
	size_t	pieceidx_beg	= bt_unit_t::totfile_to_pieceidx(chunk_beg, bt_mfile);
	// if pieceidx_beg is not available, return a null file_range_t
	if( !pieceavail.is_avail(pieceidx_beg) )		return file_range_t();
	
	// clamp the chunk_end with bt_mfile.totfile_size()
	// - usefull in case of has_circular_idx(), where m_range_tosend.end()==file_size_t::MAX
	chunk_end = std::min( chunk_end, bt_mfile.totfile_size()-1);

	// Compute pieceidx_end - the pieceidx of the last piece available
	size_t	pieceidx_max	= bt_unit_t::totfile_to_pieceidx(chunk_end, bt_mfile);
	size_t	pieceidx_end	= 0;
	for(size_t i = pieceidx_beg; i <= pieceidx_max; i++){
		if( pieceavail.is_unavail(i) )	break; 
		pieceidx_end	= i;
	}
	// clamp chunk_end to be the end of the last available pieceidx
	chunk_end	= std::min( chunk_end, bt_unit_t::pieceidx_to_pieceend(pieceidx_end, bt_mfile) );
	// clamp the chunk_end with socket_full->xmitbuf_freelen()
	if( chunk_end-chunk_beg+1 > socket_full->xmitbuf_freelen() )
		chunk_end	= chunk_beg + socket_full->xmitbuf_freelen() - 1;

	// log to debug
	KLOG_ERR("leave chunk_beg=" << chunk_beg << " chunk_end=" << chunk_end);

	// return the file_range
	return file_range_t(chunk_beg, chunk_end);
}
Exemplo n.º 7
0
/** \brief dnsgrab_t callback to received request	
 */
bool url_redir_t::neoip_dnsgrab_cb(void *cb_userptr, dnsgrab_request_t &request)	throw()
{
	// log the request
	KLOG_ERR("Received a request of " << request.get_request_name() 
			<< " From " << request.get_addr_family()
			<< " by " << (request.is_request_by_name() ? "name" : "address"));

	// if the request is NOT for AF_INET, report notfound
// TODO i fails in the libnss library and if a AF_INET6 comes it does retry in
// AF_INET, before it did.... fix the libnss
// - then reenable this line
	if( request.get_addr_family() != "AF_INET" )		goto report_notfound;
	// if the request is NOT by name, report false for NOT OK
	if( !request.is_request_by_name() )			goto report_notfound;
	// if the request is for a unknown name, report false for NOT OK
	if( get_hosturl(request.get_request_name()).empty() )	goto report_notfound;

	KLOG_ERR("request handled for " << request.get_request_name());

/*
 * if the name start by "neoip." or "buddy." AND
 * doesnt end by .fr .org .com etc...
 * 
 * then keep it
 */
//	char *	required_prefix[]	= { "neoip.", "buddy." };
//	char *	forbidden_suffix[]	= { ".org", ".com", ".net" };

 

	// set the reply with dummy data before notifying it
	request.get_reply_present()	= true;
	request.get_reply_name()	= "neoip.localhost";
//	request.get_reply_aliases().push_back("jerome.etienne");
//	request.get_reply_aliases().push_back("jeje");
	request.get_reply_addresses().push_back("127.0.0.2");
	
	// return tokeep
	return true;
	
report_notfound:
	// make the reply as not found
	request.get_reply_present()	= true;
	request.get_reply_name()	= std::string();	
	return true;
}
Exemplo n.º 8
0
/** \brief callback notified with fdwatch_t has an condition to notify
 */
bool	asyncexe_t::stdout_fdwatch_cb( void *cb_userptr, const fdwatch_t &cb_fdwatch
						, const fdwatch_cond_t &fdwatch_cond )	throw()
{
	int	readlen		= 0;	
	// log the event
	KLOG_DBG("enter fdwatch_cond=" << fdwatch_cond);

	// if the condition is input
	if( fdwatch_cond.is_input() ){
		size_t	recv_max_len	= 16*1024;
		void *	buffer		= nipmem_alloca(recv_max_len);
		// read data in the socket
		readlen = read(stdout_fdwatch->get_fd(), buffer, recv_max_len);
		// if readlen < 0, treat it as error
		// - due to a weird bug in glib|linux, G_IO_ERR/HUP isnt received
		//   so there is a test if (cond.is_input() && readlen==0) fallthru
		//   and treat it as error
		if( readlen < 0 )	readlen = 0;
		// if some data have been read, add them to the stdout_barray
		if( readlen > 0 )	stdout_barray.append(buffer, readlen);
		// log to debug
		KLOG_DBG("readlen=" << readlen);
	}

	// handle a connection error
	if( fdwatch_cond.is_error() || (fdwatch_cond.is_input() && readlen == 0) ){
		// wait for the pid to get the result
		int	status	= 0;
#ifndef _WIN32
		int	ret	= waitpid(childpid, &status, 0);
		if( ret == -1 && errno == ECHILD )	status = 0;
		else if( ret != childpid )		status = -1;
		// extract the return status
		status		= WEXITSTATUS(status);
#endif
		// log to debug
		KLOG_ERR("childpid=" << childpid << " return status=" << status );
		KLOG_ERR("received error. now recved_data=" << stdout_barray.to_datum() );
		// else notify the caller with a success
		return notify_callback(libsess_err_t::OK, stdout_barray, status);
	}

	// return tokeep
	return true;
}
Exemplo n.º 9
0
/** \brief Test function
 */
nunit_res_t	amf0_testclass_t::general(const nunit_testclass_ftor_t &testclass_ftor) throw()
{
	// log to debug
	KLOG_DBG("enter");

	// setup some dvar_t to do a comparison
	dvar_t	dvar0	= dvar_str_t("_result");
	dvar_t	dvar1	= dvar_dbl_t(1);
	dvar_t	dvar2	= dvar_nil_t();
	dvar_t	dvar3	= dvar_map_t()
			.insert("level"		, dvar_str_t("status"))
			.insert("description"	, dvar_str_t("Connection succeeded."))
			.insert("code"		, dvar_str_t("NetConnection.Connect.Success"));



	// build amf0_data from a dvar_t
	bytearray_t	amf0_data;
	amf0_build_t::to_amf0(dvar0, amf0_data);
	amf0_build_t::to_amf0(dvar1, amf0_data);
	amf0_build_t::to_amf0(dvar2, amf0_data);
	amf0_build_t::to_amf0(dvar3, amf0_data);
	// log to debug
	KLOG_ERR("dvar.to_amf0=" << amf0_data);

	// parse the
	flv_err_t	flv_err;
	dvar_t		dvar;
	flv_err		= amf0_parse_t::amf_to_dvar(amf0_data, dvar);
	NUNIT_ASSERT( flv_err.succeed() );
	NUNIT_ASSERT( dvar == dvar0 );
	flv_err		= amf0_parse_t::amf_to_dvar(amf0_data, dvar);
	NUNIT_ASSERT( flv_err.succeed() );
	NUNIT_ASSERT( dvar == dvar1 );
	flv_err		= amf0_parse_t::amf_to_dvar(amf0_data, dvar);
	NUNIT_ASSERT( flv_err.succeed() );
	NUNIT_ASSERT( dvar == dvar2 );
	flv_err		= amf0_parse_t::amf_to_dvar(amf0_data, dvar);
	NUNIT_ASSERT( flv_err.succeed() );
	NUNIT_ASSERT( dvar == dvar3 );
	KLOG_ERR("dvar=" << dvar);

	// report no error
	return NUNIT_RES_OK;
}
Exemplo n.º 10
0
/** \brief callback called when the timeout_t expire
 */
bool 	router_peer_testclass_t::neoip_timeout_expire_cb(void *userptr, timeout_t &cb_timeout)	throw()
{
	// log to debug
	KLOG_ERR("enter");
	// stop the timeout
	bstrap_timeout.stop();	
	// report the result
	return nunit_ftor(NUNIT_RES_OK);
}
Exemplo n.º 11
0
/** \brief Autodelete the object and return false to ease readability
 */
bool	http_sresp_cnx_t::autodelete(const std::string &reason)		throw()
{
	// if there is a reason, log it
	if( !reason.empty() )	KLOG_ERR("autodelete due to " << reason);	
	// delete the object itself
	nipmem_delete	this;
	// return dontkeep for convenience
	return false;
}
Exemplo n.º 12
0
/** \brief Used by kad_*_t internal to notify an echoed local ip_addr_t
 * 
 * - in practice this is used only by kad_ping_rpc_t as PING_REPLY does
 *   include the echoed local ip_addr_t
 * - this function is used to keep the local_ipaddr_pview() uptodate
 * - WARNING: this function MUST NOT notify any callback
 *   - this function is called INSYNC inside the kad_ping_rpc_t callback
 *   - so very low level
 *   - if there are notification to be made, use a zerotimer_t
 */
void	kad_listener_t::notify_echoed_local_ipaddr(const ip_addr_t &echoed_ipaddr
				, const kad_addr_t &remote_addr)	throw()
{
	// log to debug
	KLOG_ERR("enter echoed_ipaddr=" << echoed_ipaddr << " remote_kaddr=" << remote_addr);
	// if remote_addr.oaddr().ipaddr().is_public() is not true, do nothing
	// - as it mean the echoed_ipaddr is not a public view
	if( !remote_addr.oaddr().ipaddr().is_public() )	return;
	// if echoed_ipaddr is not public,, do nothing
	if( !echoed_ipaddr.is_public() )		return;

	// log to debug
	KLOG_ERR("notifying local_ipaddr_pview=" << echoed_ipaddr << " to ndiag_watch_t");

	// notify it to the ndiag_watch_t	
	ndiag_watch_t *	ndiag_watch	= ndiag_watch_get();
	ndiag_watch->notify_ipaddr_pview(echoed_ipaddr);
}
Exemplo n.º 13
0
/** \brief callback called when the neoip_timeout expire
 */
bool router_resp_cnx_t::expire_timeout_cb(void *userptr, timeout_t &cb_timeout)	throw()
{
	// log to debug
	KLOG_ERR("enter");
	// autodelete
	nipmem_delete this;
	// return 'dontkeep'
	return false;
}
Exemplo n.º 14
0
/** \brief init the gcry_md_hd
 * 
 * - this init is assumed to be done everytime it is done for ciph_type
 */
bool skey_ciph_t::init_gcry_hd()				throw()
{
	const skey_ciph_algo_t &algo	= ciph_type.get_algo();
	// get the algo from the algo_str
	int gcry_cipher_algo = gcry_cipher_map_name( algo.to_string().c_str() );
	// if the algo_str isnt supported, throw an exception
	if( !gcry_cipher_algo ){
		KLOG_ERR("Can't map " << algo.to_string() << " in gcrypt cipher_map_name");
		return true;
	}
	// open the gcrypt cipher
	if( gcry_cipher_open(&gcry_cipher_hd, gcry_cipher_algo, get_gcry_cipher_mode(), GCRY_CIPHER_SECURE) ){
		KLOG_ERR("Can't open " << ciph_type << " in gcrypt cipher_open");
		return true;
	}
	// return false if no error occured
	return false;
}
Exemplo n.º 15
0
/** \brief callback notified by \ref nudp_t receive a packet
 */
bool	nudp_testclass_t::neoip_inet_nudp_event_cb(void *cb_userptr, nudp_t &cb_nudp, pkt_t &pkt
					, const ipport_addr_t &local_addr
					, const ipport_addr_t &remote_addr)	throw()
{
	// log to debug
	KLOG_ERR("enter local_addr=" << local_addr << " remote_addr=" << remote_addr
					<< " pkt=" << pkt );
	// return tokeep	
	return true;
}
Exemplo n.º 16
0
/** \brief callback called when the neoip_timeout expire
 */
bool nudp_testclass_t::neoip_timeout_expire_cb(void *userptr, timeout_t &cb_timeout)	throw()
{
	// log to debug
	KLOG_ERR("enter");

	// send a packet thru nudp_t
	ipport_addr_t	remote_addr	= "255.255.255.255:4000";
	datum_t		data		= datum_t("Hello " + OSTREAMSTR(xmit_count));
	inet_err_t	inet_err	= nudp->send_to(data.void_ptr(), data.length(), remote_addr);
	KLOG_ERR("inet_err=" << inet_err );
	// update the rxmit_timeout
	rxmit_timeout.change_period( delay_t::from_sec(1) );
	
	// increase the xmit_count
	xmit_count++;

	// return tokeep
	return true;
}
Exemplo n.º 17
0
/** \brief Test function
 */
nunit_res_t	obj_factory_testclass_t::general(const nunit_testclass_ftor_t &testclass_ftor) throw()
{
	// log to debug
	KLOG_ERR("enter");

	// insert all the factory_product_t
	FACTORY_PRODUCT_INSERT	(nunit_obj_factory_plant, std::string, nunit_obj_factory_product_base_t
						, "two", nunit_obj_factory_product_2);
	FACTORY_PRODUCT_INSERT	(nunit_obj_factory_plant, std::string, nunit_obj_factory_product_base_t
						, "one", nunit_obj_factory_product_1);

	// test if the factory_product_t have been inserted
	std::vector<std::string>	key_list = nunit_obj_factory_plant->get_key_list();
	for(size_t i = 0; i < key_list.size(); i++ ){
		KLOG_ERR("i=" << i << " key=" << key_list[i]);
	}
	// return no error
	return NUNIT_RES_OK;
}
Exemplo n.º 18
0
/** \brief called when a nunit_runner_t is completed
 */
bool nunitapps_runner_t::neoip_nunit_runner_completed_cb(void *userptr, nunit_runner_t &nunit_runner)	throw()
{
    // log to debug
    KLOG_ERR("nunit_runner completed");
    // delete nunit_suite
    nipmem_zdelete	nunit_suite;
    // Stop the event loop
    lib_session_get()->loop_stop_asap();
    // return 'dontkeep'
    return false;
}
Exemplo n.º 19
0
/** \brief general test 
 */
nunit_res_t	netif_stat_testclass_t::general(const nunit_testclass_ftor_t &testclass_ftor) throw()
{
	// log to debug
	KLOG_ERR("enter");
	
	netif_stat_t	netif_stat;
	netif_stat	= netif_stat_helper_t::one_netif_stat("eth0");
	KLOG_ERR("netif_stat=" << netif_stat);
	netif_stat	= netif_stat_helper_t::one_netif_stat("lo");
	KLOG_ERR("netif_stat=" << netif_stat);

	netif_stat_t	netif_stat1	= netif_stat_helper_t::one_netif_stat("eth0");
	netif_stat_t	netif_stat2	= netif_stat_helper_t::one_netif_stat("eth0");
	KLOG_ERR("delta=" << netif_stat2 - netif_stat1);

	KLOG_ERR("all netif_stat=" << netif_stat_helper_t::all_netif_stat() );

	// return no error
	return NUNIT_RES_OK;
}
Exemplo n.º 20
0
/** \brief get the btcli_ezswarmid_arr_t from the bt_ezsession
 */
static btcli_ezswarmid_arr_t	get_ezswarmid_arr(void *userptr)	throw()
{
	btcli_resp_t *		btcli_resp	= (btcli_resp_t*)userptr;
	bt_ezsession_t *	bt_ezsession	= btcli_resp->bt_ezsession();
	btcli_ezswarmid_arr_t	ezswarmid_arr;
	KLOG_ERR("btcli_resp=" << btcli_resp);
	// build the btcli_ezswarmid_arr_t
	ezswarmid_arr	= btcli_ezswarmid_arr_t::from_bt_ezsession(bt_ezsession);
	// return the just built btcli_ezswarmid_arr_t
	return ezswarmid_arr;
}
Exemplo n.º 21
0
/** \brief Build a fake test which always report asynchronously
 * 
 * - it starts a router of 1sec, return a delayed result and notify
 *   the actual result once the router expires
 */
nunit_res_t	router_peer_testclass_t::wait_for_bstrap(const nunit_testclass_ftor_t &testclass_ftor) throw()
{
	// log to debug
	KLOG_ERR("enter");
	// Start the timeout
	bstrap_timeout.start(delay_t::from_sec(1), this, NULL);
	// copy the functor to report nunit_res_t asynchronously
	nunit_ftor	= testclass_ftor;
	// return a delayed nunit_res_t
	return NUNIT_RES_DELAYED;
}
/** \brief callback notified by \ref rtmp_resp_t when to notify an event
 */
bool	rtmp_cam_full_testclass_t::neoip_rtmp_cam_resp_cb(void *cb_userptr, rtmp_cam_resp_t &cb_cam_resp
					, rtmp_cam_full_t *cb_cam_full)	throw()
{
	// log to debug
	KLOG_ERR("enter");
	// if there is already a rtmp_cam_full_t initialized, delete this one immediatly
	if( cam_full ){
		// log to debug
		KLOG_ERR("one rtmp_cam_full_t is already handled. dropping new one");
		nipmem_zdelete	cb_cam_full;
		return true;
	}
	// set the callback on the local object
	// - it is already started by rtmp_cam_resp_t
	cam_full	= cb_cam_full;
	cam_full->set_callback(this, NULL);

	// return tokeep
	return true;
}
Exemplo n.º 23
0
/** \brief Function used to update the listen_pview *DURING* bt_session_t run
 */
void	bt_swarm_full_t::update_listen_pview(const ipport_addr_t &new_listen_pview)	throw()
{
	// log to debug
	KLOG_ERR("enter NOT YET IMPLEMENTED new_listen_pview=" << new_listen_pview);

	// ask bt_swarm_full_utmsg_t to send an handshake IIF remote peer 
	// has bt_protoflag_t::UT_MSGPROTO
	// - this bt_utmsg_handshake_t contains the listen port
	// - TODO once again IIF the port has changed...
	if( remote_protoflag.fully_include(bt_protoflag_t::UT_MSGPROTO) )
		full_utmsg()->send_handshake();
}
Exemplo n.º 24
0
/** \brief Return a string describing the file_path2_t as a url file path
 */
std::string	file_path2_t::to_urlpath_string()	const throw()
{
#if 0
	// sanity check - the drvletter MUST be empty
	DBG_ASSERT( drvletter().empty() );
#else
	if( !drvletter().empty() )	KLOG_ERR("there is a driveletter when it should not!!!");
#endif
	// forward to the to_string_sepa for url
	// - TODO put this in a constant
	return to_string_sepa("//");
}
Exemplo n.º 25
0
/** \brief Execute a command from the GUI
 */
void	btcli_swarm_t::do_command(const std::string &command)	throw()
{
	// log to debug
	KLOG_ERR("command=" << command);
	
	// TODO halfbacked stat automata
	if( command == "stop" ){
		if( bt_ezswarm->in_share() ){
			bt_ezswarm->graceful_change_state(bt_ezswarm_state_t::STOPPED);
		}else{
		}
	}else if( command == "start" ){
		if( bt_ezswarm->in_stopped() ){
			bt_ezswarm->graceful_change_state(bt_ezswarm_state_t::SHARE);
		}else{
		}
	}else{
		KLOG_ERR("received unknown command " << command);
		DBG_ASSERT( 0 );
	}
}
Exemplo n.º 26
0
/** \brief Handle the --register cmdline actions
 */
router_err_t	router_apps_t::cmdline_action_register()		throw()
{
	lib_session_t *		lib_session	= lib_session_get();
	lib_apps_t *		lib_apps	= lib_session->lib_apps();
	const strvar_db_t &	arg_option	= lib_apps->arg_option();
	file_path_t		config_path	= lib_session->conf_rootdir() / "router";
	const std::string &	reg_param	= arg_option.get_first_value("register");
	router_name_t		dnsname		= router_name_t(dns_helper_t::idna_to_ascii(reg_param));
	router_err_t		router_err;
	file_err_t		file_err;
	x509_cert_t		ca_cert;
	x509_privkey_t		ca_privkey;
	// sanity check - the arg_option MUST contain the "register" key
	DBG_ASSERT( arg_option.contain_key("register") );
	
	KLOG_ERR("reg_param=" << reg_param);
	// display some info for the user
	KLOG_STDOUT("Registering host name " << dnsname << ". If the cryptographic key generation is too long, generate entropy by moving the mouse or using the disk\n");
	KLOG_STDOUT("Start registering peername " << dnsname << " ... ");

	// check that the dnsname is either is_fully_qualified() or is_host_only()
	if( !dnsname.is_fully_qualified() && !dnsname.is_host_only() ){
		std::string	reason = "dnsname " + dnsname.to_string() + " is invalid (only host-only and fully qualified are allowed)";
		return router_err_t(router_err_t::ERROR, reason);
	}
	
	// if dnsname to register is_authsigned_ok(), get cert/priv for the domain authority 
	if( dnsname.is_authsigned_ok() ){
		// try to get the ca_cert/ca_privkey for this dnsname
		router_err	= router_apps_helper_t::rootca_load_for_authsign(dnsname
							, ca_cert, ca_privkey);
		if( router_err.failed() )	return router_err;
		// sanity check - ca_cert and ca_privkey MUST NOT be null
		DBG_ASSERT( !ca_cert.is_null() );
		DBG_ASSERT( !ca_privkey.is_null() );
	}
	
	// log to debug
	KLOG_DBG("dnsname="		<< dnsname);
	KLOG_DBG("x509_cert="		<< ca_cert);
	KLOG_DBG("x509_privkey="	<< ca_privkey);
	
	// start generating the local identity
	router_err	= router_apps_helper_t::lident_create(config_path, dnsname, 1024
						, ca_cert, ca_privkey);
	if( router_err.failed() )	return router_err;

	// exit after a successfull action
	KLOG_STDOUT("OK\n");

	// return no error, but a specific reason to avoid launching the apps
	return router_err_t(router_err_t::OK, "DONTLAUNCHAPPS");
}
Exemplo n.º 27
0
bool cnc_daemon_start_encode_response(int message_type, CNCWrapper * wrapper)
{
    CborEncoder encoder, container;
    CborError err;
    uint8_t data[MTU] = {0};

    if (wrapper == NULL)
    {
        KLOG_ERR(&log_handle, LOG_COMPONENT_NAME, "%s called with a NULL pointer\n", __func__);
        return false;
    }

    cbor_encoder_init(&encoder, data, MTU, 0);
    err = cbor_encoder_create_map(&encoder, &container, 4); //TODO: Dynamically assign map size
    if (err)
    {
        KLOG_ERR(&log_handle, LOG_COMPONENT_NAME, "Unable to initialize cbor encoder, Error code: %i", err);
        return false;
    }

    if (err = cbor_encode_text_stringz(&container, "MSG_TYPE"))
    {
        KLOG_ERR(&log_handle, LOG_COMPONENT_NAME, "Unable to encode key \"MSG_TYPE\". Error code: %i\n", err);
        return false;
    }

    if (err = cbor_encode_int(&container, message_type))
    {
        KLOG_ERR(&log_handle, LOG_COMPONENT_NAME, "Unable to encode value for key \"MSG_TYPE\" Error code: %i\n", err);
        return false;
    }

    switch (message_type)
    {
        case RESPONSE_TYPE_COMMAND_RESULT:
            return cnc_daemon_encode_response(data, wrapper, &encoder, &container);
        case RESPONSE_TYPE_PROCESSING_ERROR:
            return cnc_daemon_encode_processing_error(data, wrapper, &encoder, &container);
    }
}
/** \brief callback notified by \ref ndiag_aview_t to notify an event
 */
bool 	casti_inetreach_httpd_t::neoip_ndiag_aview_cb(void *cb_userptr, ndiag_aview_t &cb_ndiag_aview
						, const ipport_addr_t &new_listen_pview)	throw()
{
	// log to debug
	KLOG_ERR("enter new_listen_pview=" << new_listen_pview);
	
	// notify the caller that ndiag_aview_t may have changed
	bool	tokeep	= notify_callback(new_listen_pview);
	if( !tokeep )	return false;
	
	// return tokeep
	return true;
}
Exemplo n.º 29
0
/** \brief function to test a date_t
 */
nunit_res_t	date_testclass_t::canonical_string(const nunit_testclass_ftor_t &testclass_ftor) throw()
{
	// log to debug
	KLOG_DBG("enter");
	// get the date for the 'present'
	date_t		date1	= date_t::present();
	// convert it to a canonical_string
	std::string	abs_str	= date_helper_t::to_canonical_string(date1);
	// convert it back to a date_t
	date_t		date2	= date_helper_t::from_canonical_string(abs_str);
	// compute the difference (it is not equal because the string doesnt contains the msec)
	delay_t		delta	= (date1 > date2 ? (date1 - date2) : (date2 - date1));
	// log to debug
	KLOG_ERR("blabla=[" << abs_str	<< "]");
	KLOG_ERR("blabla=[" << date2	<< "]");
	KLOG_ERR("blabla=[" << delta	<< "]");
	// the difference MUST NOT be more than 1sec 
	NUNIT_ASSERT( delta < delay_t::from_sec(1) );
	
	// return no error	
	return NUNIT_RES_OK;
}
/** \brief function called by caller when the bt_pieceprec_arr_t change 
 */
void	bt_utmsg_piecewish_t::notify_pieceprec_change()	throw()
{
	// log to debug
	KLOG_ERR("enter");
	// compute the new local_pwish
	bitfield_t	new_local_pwish	= generate_local_pwish();
	// generate the bt_cmd_t to xmit
	bt_cmd_t bt_cmd	= build_cmd_delta_bitfield(local_pwish(), new_local_pwish);
	// update the local_pwish with the new one
	m_local_pwish	= new_local_pwish;
	// send this command thru all the connections
	send_cmd_to_all_cnx(bt_cmd);
}