Esempio n. 1
0
	def	findsomeval_rpc( self, keyid, max_nb_record, dest_naddr, opttl = kad_delay( 30 ) ):
		'''Perform a FINDSOMEVAL rpc to dest_naddr
		
			It may return 2 kind of results:
				- if the destination node has records matching this keyid, it return
				  a list of 2 elements
				  - Element 1 is bool equal to True, the destination node has more records matching
				    this keyid
				  - Element 2 is a list of the found kad_rec
				- if the destination node has no records matching this keyid, it return
				  a list of 2 elements
				  - Element 1 is a string equal to a cookie_id
				  - Element 2 is a list of the nclosest node to the keyid
		'''
		# sanity check - check the parameters type
		assert isinstance( keyid		, kad_id )
		assert isinstance( max_nb_record, int )
		assert isinstance( dest_naddr	, kad_naddr )
		assert isinstance( opttl		, kad_delay )
		# send the rpc itself
		result = self.rpcserver.dht.findsomeval_rpc( keyid.to_xmlrpc(), str( max_nb_record ), self.sessid, opttl.to_xmlrpc() )
		if isinstance(result[0], bool):
			# if it is a recdups
			return [result[0], [kad_rec.from_xmlrpc( i ) for i in result[1]]]			
		else:
			# if it is a naddrlist
			return [result[0], [kad_naddr.from_xmlrpc( i ) for i in result[1]]]	
Esempio n. 2
0
	def	findnode_rpc( self, nodeid, dest_naddr, opttl = kad_delay( 30 ) ):
		'''Perform a FINDNODE rpc for nodeid to dest_naddr
		
			It return a list of 2 elements:
				  - Element 1 is a string equal to a cookie_id
				  - Element 2 is a list of the nclosest kad_naddr to the keyid
		'''
		# sanity check - check the parameters type
		assert isinstance( nodeid		, kad_id )
		assert isinstance( dest_naddr	, kad_naddr )
		assert isinstance( opttl		, kad_delay )
		# send the rpc itself
		result = self.rpcserver.dht.findnode_rpc( nodeid.to_xmlrpc(), dest_naddr.to_xmlrpc(), self.sessid, opttl.to_xmlrpc() )
		# convert and return the result
		return [result[0], [kad_naddr.from_xmlrpc( i ) for i in result[1]]]