raise TransportNotConnected instead of logging a warning

-add a _listening Deferred to KademliaProtocol which is called when the protocol is started
This commit is contained in:
Jack Robison 2018-05-23 17:41:56 -04:00
parent f1e0a784d9
commit 95ed1e044b
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
3 changed files with 11 additions and 4 deletions

View file

@ -39,3 +39,7 @@ class TimeoutError(Exception):
msg = 'Timeout connecting to uninitialized node' msg = 'Timeout connecting to uninitialized node'
Exception.__init__(self, msg) Exception.__init__(self, msg)
self.remote_contact_id = remote_contact_id self.remote_contact_id = remote_contact_id
class TransportNotConnected(Exception):
pass

View file

@ -223,7 +223,8 @@ class Node(MockKademliaHelper):
""" """
self.start_listening() self.start_listening()
# #TODO: Refresh all k-buckets further away than this node's closest neighbour yield self._protocol._listening
# TODO: Refresh all k-buckets further away than this node's closest neighbour
self.safe_start_looping_call(self._change_token_lc, constants.tokenSecretChangeInterval) self.safe_start_looping_call(self._change_token_lc, constants.tokenSecretChangeInterval)
# Start refreshing k-buckets periodically, if necessary # Start refreshing k-buckets periodically, if necessary
self.bootstrap_join(known_node_addresses or [], self._joinDeferred) self.bootstrap_join(known_node_addresses or [], self._joinDeferred)

View file

@ -4,12 +4,12 @@ import errno
from twisted.internet import protocol, defer from twisted.internet import protocol, defer
from lbrynet.core.call_later_manager import CallLaterManager from lbrynet.core.call_later_manager import CallLaterManager
from error import BUILTIN_EXCEPTIONS, UnknownRemoteException, TimeoutError, TransportNotConnected
import constants import constants
import encoding import encoding
import msgtypes import msgtypes
import msgformat import msgformat
from error import BUILTIN_EXCEPTIONS, UnknownRemoteException, TimeoutError
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -26,6 +26,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
self._sentMessages = {} self._sentMessages = {}
self._partialMessages = {} self._partialMessages = {}
self._partialMessagesProgress = {} self._partialMessagesProgress = {}
self._listening = defer.Deferred(None)
def sendRPC(self, contact, method, args, rawResponse=False): def sendRPC(self, contact, method, args, rawResponse=False):
""" """
@ -97,7 +98,8 @@ class KademliaProtocol(protocol.DatagramProtocol):
return df return df
def startProtocol(self): def startProtocol(self):
log.info("DHT listening on UDP %i", self._node.port) log.info("DHT listening on UDP %s:%i", self._node.externalIP, self._node.port)
self._listening.callback(True)
def datagramReceived(self, datagram, address): def datagramReceived(self, datagram, address):
""" Handles and parses incoming RPC messages (and responses) """ Handles and parses incoming RPC messages (and responses)
@ -279,7 +281,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
log.error("DHT socket error: %s (%i)", err.message, err.errno) log.error("DHT socket error: %s (%i)", err.message, err.errno)
raise err raise err
else: else:
log.warning("transport not connected!") raise TransportNotConnected()
def _sendResponse(self, contact, rpcID, response): def _sendResponse(self, contact, rpcID, response):
""" Send a RPC response to the specified contact """ Send a RPC response to the specified contact