Ejemplo n.º 1
0
/** \brief Start the action
 */
kad_err_t	kad_ping_rpc_t::start(kad_peer_t *kad_peer, const kad_addr_t &remote_addr
				, const delay_t &expire_delay
				, kad_ping_rpc_cb_t *callback, void *userptr) 		throw()
{
	kad_pkttype_t	pkttype(kad_peer->get_profile().pkttype());
	kad_err_t	kad_err;
	// copy some parameters
	this->kad_peer	= kad_peer;
	this->callback	= callback;
	this->userptr	= userptr;

	// build the packet to send
	pkt_t		request_payload;
	request_payload	= build_request_payload();

	// create the kad_client_t and start it
	m_client_rpc	= nipmem_new kad_client_rpc_t();
	kad_err 	= m_client_rpc->start(kad_peer, request_payload
						, pkttype.PING_REQUEST(), pkttype.PING_REPLY()
						, remote_addr, expire_delay, this);
	if( kad_err.failed() )	return kad_err;

	// update the statistic
	kad_peer->get_stat()->nb_ping_sent++;

	// return no error
	return kad_err_t::OK;
}
Ejemplo n.º 2
0
/** \brief callback notified when a kad_srvcnx_t receive a packet
 * 
 * - this function only forward the packet to the proper kad_peer_t, the actual
 *   processing is happening in the kad_peer_t itself
 */
bool kad_listener_t::neoip_kad_srvcnx_cb(void *cb_userptr, kad_srvcnx_t &cb_kad_srvcnx
				, pkt_t &pkt, const ipport_addr_t &local_oaddr
				, const ipport_addr_t &remote_oaddr)		throw()
{
	const kad_profile_t &	profile		= peer_db.front()->get_profile();
	pkt_t			orig_pkt	= pkt;
	kad_peer_t *		kad_peer	= NULL;
	kad_pkttype_t		pkttype(profile.pkttype());
	kad_realmid_t		dest_realmid;
	kad_peerid_t		dest_peerid;
	// log to debug
	KLOG_DBG("enter pkt=" << pkt);

	// parse the incoming packet	
	try {
		// read the pkttype
		pkt >> pkttype;
		// read the realm id - if realmid_in_pkt_ok()
		if( profile.rpc().realmid_in_pkt_ok() )		pkt >> dest_realmid;
		// get the destination peerid from the incoming packet - if dest_peerid_in_pkt_ok()
		if( profile.rpc().dest_peerid_in_pkt_ok() )	pkt >> dest_peerid; 
	} catch(serial_except_t &e) {
		KLOG_INFO("Cant parse incoming packet due to " << e.what() );
		goto	error;
	}

	// try to find a kad_peer_t matching this realmid/peerid
	// - it works even if they are null
	kad_peer = get_kad_peer(dest_realmid, dest_peerid);
	// if the realm doesnt exist, log and exit
	if( !kad_peer ){
		// log the event
		KLOG_INFO("Received a packet " << pkttype << " for an unexisting realmid=" << dest_realmid
						<< " peerid=" << dest_peerid);
		// send a kad_pkttype_t::RESET_REPLY, if the packet is not itself a RESET_REPLY
		// - similar to "an icmp error MUST NOT be replied to an icmp error" - rfc1812.4.3.2.7
		if( pkttype != pkttype.RESET_REPLY() ){
			// build the kad_pkttype_t::RESET_REPLY
			pkt	= pkt_t();
			pkt << pkttype.RESET_REPLY();
			pkt.append(orig_pkt.void_ptr(), orig_pkt.length());
			// return now
			return true;
		}
		goto error;
	}
	
	// log to debug
	KLOG_DBG("received a pkttype=" << pkttype << " for realmid=" << dest_realmid 
						<< " peerid=" << dest_peerid);
	// forward the packet to the proper realm
	pkt	= kad_peer->handle_request(orig_pkt, local_oaddr, remote_oaddr);
	return true;
error:;
	// swallow the packet as there is no reply
	pkt	= pkt_t();
	// keep the server running anyway
	return true;
}
Ejemplo n.º 3
0
/** \brief function to test a pkttype_t
 */
nunit_res_t	pkttype_testclass_t::test_null(const nunit_testclass_ftor_t &testclass_ftor) throw()
{
	// set variable
	pkttype_profile_t	profile(10, 2, pkttype_profile_t::UINT32);
	nunit_pkttype_t		pkttype(profile);
	// test the .is_null()
	NUNIT_ASSERT( pkttype.is_null() == true );
	pkttype	= pkttype.PKT_REPLY();
	NUNIT_ASSERT( pkttype.is_null() != true );
	// return no error
	return NUNIT_RES_OK;
}
Ejemplo n.º 4
0
Archivo: il.c Proyecto: 99years/plan9
static int
p_seprint(Msg *m)
{
	Hdr *h;
	int dport, sport;

	if(m->pe - m->ps < ILLEN)
		return -1;
	h = (Hdr*)m->ps;
	m->ps += ILLEN;

	dport = NetS(h->dport);
	sport = NetS(h->sport);
	demux(p_mux, sport, dport, m, &dump);

	m->p = seprint(m->p, m->e, "s=%d d=%d t=%s id=%lud ack=%lud spec=%d ck=%4.4ux ln=%d",
			sport, dport, pkttype(h->type),
			(ulong)NetL(h->id), (ulong)NetL(h->ack),
			h->spec,
			NetS(h->sum), NetS(h->len));
	return 0;
}