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:
parent
f1e0a784d9
commit
95ed1e044b
3 changed files with 11 additions and 4 deletions
|
@ -39,3 +39,7 @@ class TimeoutError(Exception):
|
|||
msg = 'Timeout connecting to uninitialized node'
|
||||
Exception.__init__(self, msg)
|
||||
self.remote_contact_id = remote_contact_id
|
||||
|
||||
|
||||
class TransportNotConnected(Exception):
|
||||
pass
|
||||
|
|
|
@ -223,7 +223,8 @@ class Node(MockKademliaHelper):
|
|||
"""
|
||||
|
||||
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)
|
||||
# Start refreshing k-buckets periodically, if necessary
|
||||
self.bootstrap_join(known_node_addresses or [], self._joinDeferred)
|
||||
|
|
|
@ -4,12 +4,12 @@ import errno
|
|||
|
||||
from twisted.internet import protocol, defer
|
||||
from lbrynet.core.call_later_manager import CallLaterManager
|
||||
from error import BUILTIN_EXCEPTIONS, UnknownRemoteException, TimeoutError, TransportNotConnected
|
||||
|
||||
import constants
|
||||
import encoding
|
||||
import msgtypes
|
||||
import msgformat
|
||||
from error import BUILTIN_EXCEPTIONS, UnknownRemoteException, TimeoutError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -26,6 +26,7 @@ class KademliaProtocol(protocol.DatagramProtocol):
|
|||
self._sentMessages = {}
|
||||
self._partialMessages = {}
|
||||
self._partialMessagesProgress = {}
|
||||
self._listening = defer.Deferred(None)
|
||||
|
||||
def sendRPC(self, contact, method, args, rawResponse=False):
|
||||
"""
|
||||
|
@ -97,7 +98,8 @@ class KademliaProtocol(protocol.DatagramProtocol):
|
|||
return df
|
||||
|
||||
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):
|
||||
""" 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)
|
||||
raise err
|
||||
else:
|
||||
log.warning("transport not connected!")
|
||||
raise TransportNotConnected()
|
||||
|
||||
def _sendResponse(self, contact, rpcID, response):
|
||||
""" Send a RPC response to the specified contact
|
||||
|
|
Loading…
Reference in a new issue