#NEWLINE# def send_message( self , host , port , message ) : #NEWLINE# #INDENT# "\n        Sends a message to the specified contact, adds it to the _pending\n        dictionary and ensures it times-out after the correct period. If an\n        error occurs the deferred's errback is called.\n        " #NEWLINE# peer_key = ( host , port ) #NEWLINE# if ( peer_key in self . _contacts ) : #NEWLINE# #INDENT# protocol = self . _contacts [ peer_key ] #NEWLINE# protocol . sendMessage ( message ) #NEWLINE# return #NEWLINE# #UNINDENT# d = defer . Deferred ( ) #NEWLINE# client_string = ( 'tcp:%s:%d' % ( host , port ) ) #NEWLINE# client = clientFromString ( reactor , d ) #NEWLINE# connection = client . connect ( MessageFactory ( self ) ) #NEWLINE# connection_timeout = reactor . callLater ( 5 , connection . cancel ) #NEWLINE# def on_connect( protocol ) : #NEWLINE# #INDENT# if connection_timeout . active ( ) : #NEWLINE# #INDENT# connection_timeout . cancel ( ) #NEWLINE# #UNINDENT# self . _contacts [ peer_key ] = protocol #NEWLINE# protocol . sendMessage ( message ) #NEWLINE# #UNINDENT# def on_error( error ) : #NEWLINE# #INDENT# d . errback ( error ) #NEWLINE# #UNINDENT# connection . addCallback ( on_connect ) #NEWLINE# connection . addErrback ( on_error )