读bittorrent小结
我现在已经看了一段时间bittorrent源码 主要线索就是以下:
parseargs
|
V
rawserver = RawServer(doneflag, config['timeout_check_interval'], config['timeout'], errorfunc = errorfunc)
|
V
storage = Storage(files, open, path.exists, path.getsize)
|
V
storagewrapper = StorageWrapper(storage, config['download_slice_size'], pieces, info['piece length'], finished, failed, statusfunc, doneflag, config['check_hashes'], data_flunked)
|
V
choker = Choker(config['max_uploads'], rawserver.add_task, finflag.isSet, config['min_uploads'])
|
V
upmeasure = Measure(config['max_rate_period'],
config['upload_rate_fudge'])
|
V
ratemeasure = RateMeasure(storagewrapper.get_amount_left())
|
V
picker = PiecePicker(len(pieces), config['rarest_first_cutoff'], config['rarest_first_priority_cutoff'])
|
V
downloader = Downloader(storagewrapper, picker,
config['request_backlog'], config['max_rate_period'],
len(pieces), downmeasure, config['snub_time'],
ratemeasure.data_came_in)
|
V
connecter = Connecter(make_upload, downloader, choker,
len(pieces), upmeasure, config['max_upload_rate'] * 1024, rawserver.add_task)
|
V
encoder = Encoder(connecter, rawserver,
myid, config['max_message_length'], rawserver.add_task,
config['keepalive_interval'], infohash, config['max_initiate'])
|
V
rerequest = Rerequester(response['announce'], config['rerequest_interval'],
rawserver.add_task, connecter.how_many_connections,
config['min_peers'], encoder.start_connection,
rawserver.external_add_task, storagewrapper.get_amount_left,
upmeasure.get_total, downmeasure.get_total, listen_port,
config['ip'], myid, infohash, config['http_timeout'], errorfunc,
config['max_initiate'], doneflag)
|
V
DownloaderFeedback(choker, rawserver.add_task, statusfunc,
upmeasure.get_rate, downmeasure.get_rate,
upmeasure.get_total_megs, downmeasure.get_total_megs, ratemeasure.get_time_left,
ratemeasure.get_size_left, file_length, finflag,
config['display_interval'], spewflag)
|
V
rawserver.listen_forever(encoder)
storage.close()
rerequest.announce(2)
我正是按照这样的顺序分析的,结下来我主要分析这几个类,到这时真有点
“源码之下无秘密”,继续让我们去看源码之下的秘密吧