-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- should prevent the same object being re-requested indefinitely - locking for object tracking - move SSL-specific error handling to TLSDispatcher - observe maximum connection limit when accepting a new connection - stack depth test (for debugging purposes) - separate download thread - connection pool init moved to main thread
- Loading branch information
1 parent
76fed78
commit 0cc8589
Showing
12 changed files
with
125 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Queue | ||
import threading | ||
|
||
import addresses | ||
#from bmconfigparser import BMConfigParser | ||
from debug import logger | ||
from helper_threading import StoppableThread | ||
#from inventory import Inventory | ||
from network.connectionpool import BMConnectionPool | ||
import protocol | ||
|
||
class DownloadThread(threading.Thread, StoppableThread): | ||
maxPending = 500 | ||
requestChunk = 1000 | ||
|
||
def __init__(self): | ||
threading.Thread.__init__(self, name="DownloadThread") | ||
self.initStop() | ||
self.name = "DownloadThread" | ||
logger.info("init download thread") | ||
|
||
def run(self): | ||
while not self._stopped: | ||
requested = 0 | ||
for i in BMConnectionPool().inboundConnections.values() + BMConnectionPool().outboundConnections.values(): | ||
# this may take a while, but it needs a consistency so I think it's better | ||
with i.objectsNewToMeLock: | ||
downloadPending = len(list((k for k, v in i.objectsNewToMe.iteritems() if not v))) | ||
if downloadPending >= DownloadThread.maxPending: | ||
continue | ||
# keys with True values in the dict | ||
request = list((k for k, v in i.objectsNewToMe.iteritems() if v)) | ||
if len(request) == 0: | ||
continue | ||
if len(request) > DownloadThread.requestChunk - downloadPending: | ||
request = request[:DownloadThread.requestChunk - downloadPending] | ||
# mark them as pending | ||
for k in request: | ||
i.objectsNewToMe[k] = False | ||
|
||
payload = addresses.encodeVarint(len(request)) + ''.join(request) | ||
i.writeQueue.put(protocol.CreatePacket('getdata', payload)) | ||
logger.debug("%s:%i Requesting %i objects", i.destination.host, i.destination.port, len(request)) | ||
requested += len(request) | ||
self.stop.wait(1) | ||
|
||
def stopThread(self): | ||
super(DownloadThread, self).stopThread() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters