dht鐖櫕

浠ュ墠鐮旂┒杩囩櫨搴︾埇铏紝澶ф鐭ラ亾浠栨槸閫氳繃浜掔浉鍏虫敞鍘荤埇鍒汉鐨勬敹钘忕殑璧勬簮锛屼絾鏄鍔涢摼鎺ョ殑鐖彇杩樼湡鏄笉澶竻妤氾紝鐮旂┒涓涓嬨傜劧鍚庢垜鍙戠幇09骞翠箣鍓嶏紝鏈澶х殑绉嶅瓙涓嬭浇骞冲彴锛屾捣鐩楁咕锛屽叾瀹炵敤鐨勬槸Tracker鏈嶅姟鍣紝浣嗘槸寰堟槑鏄剧殑渚垫潈锛屽洜涓轰粬鎻愪緵鐨勮繖鏍蜂竴涓伐鍏凤紝鍙互鏄疶racker鏄痓t绉嶅瓙涓嬭浇鐨勭伒榄傦紝浣嗘槸鐜板湪涓嶉渶瑕佷簡锛屽洜涓哄ぇ閮ㄥ垎BT涓嬭浇鐢ㄧ殑閮芥槸DHT鍗忚銆

鏌ヤ簡涓涓嬪彂鐜板簲璇ユ槸璺熻繖涓猟ht鐖櫕鏈夌偣鍏崇郴銆
鏌ヤ簡涓涓嬬浉鍏崇殑姒傚康銆

1.1 P2P缃戠粶

瀵圭瓑璁$畻锛圥eer to Peer锛岀畝绉皃2p锛夊彲浠ョ畝鍗曠殑瀹氫箟鎴愰氳繃鐩存帴浜ゆ崲鏉ュ叡浜绠楁満璧勬簮鍜屾湇鍔★紝鑰屽绛夎绠楁ā鍨嬪簲鐢ㄥ眰褰㈡垚鐨勭綉缁滈氬父绉颁负瀵圭瓑缃戠粶銆傜浉淇″ぇ瀹堕兘鐢ㄨ繃杩呴浄锛屽氨涓嶅璇翠簡銆
浣跨敤P2P鎶鏈殑鏈夋瘮鐗瑰竵锛屾捣鐩楁咕涔嬬被鐨勩

1.2 DHT缃戠粶

DHT锛圖istributed Hash Table锛屽垎甯冨紡鍝堝笇琛級锛孌HT鐢辫妭鐐圭粍鎴愶紝瀹冨瓨鍌╬eer鐨勪綅缃紝鏄竴绉嶅垎甯冨紡瀛樺偍鏂规硶銆傚湪涓嶉渶瑕佹湇鍔″櫒鐨勬儏鍐典笅锛屾瘡涓鎴风璐熻矗涓涓皬鑼冨洿鐨勮矾鐢憋紝骞惰礋璐e瓨鍌ㄤ竴灏忛儴鍒嗘暟鎹紝浠庤屽疄鐜版暣涓狣HT缃戠粶鐨勫鍧鍜屽瓨鍌紝鍏朵腑BT瀹㈡埛绔寘鍚竴涓狣HT鑺傜偣锛岀敤鏉ヨ仈绯籇HT涓叾浠栬妭鐐癸紝浠庤屽緱鍒皃eer鐨勪綅缃紝杩涜岄氳繃BitTorrent鍗忚涓嬭浇銆

绠鍗曟潵璇碊HT灏辨槸璐熻矗绠$悊鎻愪緵淇℃伅鍜屾湇鍔¤妭鐐圭殑绠$悊涓庤矾鐢卞姛鑳斤紝涓や釜闇瑕佸尯鍒嗙殑姒傚康锛

鈥減eer鈥 鏄湪涓涓 TCP 绔彛涓婄洃鍚殑瀹㈡埛绔/鏈嶅姟鍣紝瀹冨疄鐜颁簡 BitTorrent 鍗忚

鈥滆妭鐐光 鏄湪涓涓 UDP 绔彛涓婄洃鍚殑瀹㈡埛绔/鏈嶅姟鍣紝瀹冨疄鐜颁簡** DHT(鍒嗗竷寮忓搱甯岃〃) 鍗忚**銆

1.3 Kademlia绠楁硶

Kademlia鏄疍HT缃戠粶鐨勪竴绉嶅疄鐜般傚湪Kademlia缃戠粶涓紝璺濈鏄氳繃寮傛垨(XOR)璁$畻鐨勶紝缁撴灉涓烘棤绗﹀彿鏁存暟銆俤istance(A, B) = |A xor B|锛屽艰秺灏忚〃绀鸿秺杩戙

1.4 KRPC鍗忚

KRPC 鏄妭鐐逛箣闂寸殑浜や簰鍗忚锛屾槸鐢 bencode 缂栫爜缁勬垚鐨勪竴涓畝鍗曠殑 RPC 缁撴瀯锛屼粬浣跨敤 UDP 鎶ユ枃鍙戦併備竴涓嫭绔嬬殑璇锋眰鍖呰鍙戝嚭鍘荤劧鍚庝竴涓嫭绔嬬殑鍖呰鍥炲銆傝繖涓崗璁病鏈夐噸鍙戙傚畠鍖呭惈 3 绉嶆秷鎭細璇锋眰锛屽洖澶嶅拰閿欒銆傚DHT鍗忚鑰岃█锛岃繖閲屾湁 4 绉嶈姹傦細

ping 妫鏌ヤ竴涓妭鐐规槸鍚︽湁鏁

find_node 鍚戜竴涓妭鐐瑰彂閫佹煡鎵捐妭鐐圭殑璇锋眰锛屽湪鍒濆璺敱琛ㄦ垨楠岃瘉妗舵槸鍚﹀瓨娲绘椂浣跨敤

get_peers 鍚戜竴涓妭鐐瑰彂閫佹煡鎵捐祫婧愮殑璇锋眰

announce_peer 鍚戜竴涓妭鐐瑰彂閫佽嚜宸卞凡缁忓紑濮嬩笅杞芥煇涓祫婧愮殑閫氱煡

涓鏉RPC娑堟伅鐢变竴涓嫭绔嬬殑瀛楀吀缁勬垚锛屽叾涓璽鍜寉鍏抽敭瀛楁槸姣忔潯淇℃伅閮藉寘鍚殑

1.5 MagNet鍗忚

MagNet鍗忚锛屼篃灏辨槸纾佸姏閾炬帴銆傛槸涓涓氳繃sha1绠楁硶鐢熸垚涓涓20瀛楄妭闀跨殑瀛楃涓诧紝P2P瀹㈡埛绔娇鐢ㄧ鍔涢摼鎺ワ紝涓嬭浇璧勬簮鐨勭瀛愭枃浠讹紝鐒跺悗鏍规嵁绉嶅瓙鏂囦欢涓嬭浇璧勬簮銆

鍥犲凡鏈夌幇鎴愮殑鑴氭湰瀹炵幇锛屽彧闇瑕佸鐩稿叧鍗忚鏈変釜澶ф浜嗚В灏卞彲浠ュ姩鎵嬩簡銆

鍡鍒跺畬鎰熻杩樻槸涓嶅お鎳傚憿 绠椾簡 闅忕紭鍚

2.1 DHT鐖櫕瀹炵幇鍘熺悊

浼鎴怐HT鑺傜偣鍔犲叆DHT缃戠粶涓敹闆嗕俊鎭紝DHT涓璶ode锛堝姞鍏ョ綉缁滅殑鏃跺欓殢鏈虹敓鎴愶級涓巌nfohash閮芥槸浣跨敤160bit鐨勮〃绀烘柟寮忥紝涔熷氨鏄40浣嶇殑16杩涘埗锛屾剰鍛崇潃鏁伴噺绾ф湁2^160锛岀埇铏富瑕佹敹闆唃et_peer銆乤nnounce_peer杩欎袱涓姹傜殑淇℃伅

2.2 get_peer

get_peers涓巘orrent鏂囦欢鐨刬nfohash鏈夊叧锛屾壘鍒板緟鏌ヨ祫婧愭槸鍚︽湁peer銆傝繖鏃禟PRC涓殑q=get_peers锛屽叾涓寘鍚妭鐐筰d鍜宨nfo_hash涓や釜鍙傛暟锛屽鏋滆璇锋眰鐨勮妭鐐规湁瀵瑰簲info_hash鐨刾eers锛屽皢杩斿洖涓涓叧閿瓧values锛屽鏋滄棤鍒欒繑鍥炲叧閿瓧nodes锛屽悓鏃朵篃杩斿洖涓涓猼oken锛宼oken鍦╝nnouce_peer涓渶瑕佹惡甯︺
鍙傛暟锛

{"id" : "<querying nodes id>", "info_hash" : "<20-byte infohash of target torrent>"}
鍥炲锛

{"id" : "<queried nodes id>", "token" :"<opaque write token>", "values" : ["<peer 1 info string>", "<peer 2 info string>"]}
鎴栬

{"id" : "<queried nodes id>", "token" :"<opaque write token>", "nodes" : "<compact node info>"}
杩欓噷杩囨潵鐨刬nfo_hash涓嶄竴瀹氭槸鏈夌湡瀹炲瓨鍦ㄧ殑

2.3 announce_peer

杩欎釜璇锋眰鐢ㄦ潵琛ㄦ槑鍙戝嚭announce_peer璇锋眰鐨勮妭鐐癸紝姝e湪鏌愪釜绔彛涓嬭浇torrent鏂囦欢銆傚寘鍚洓涓弬鏁拌姹傝妭鐐筰d銆乮nfo_hash銆佹暣鍨嬬鍙ort鍜宼onken锛屾敹鍒拌姹傜殑鑺傜偣妫鏌ヨ繖涓猼oken锛屽鏋滅浉鍚岋紝鍒欒繑鍥炶妭鐐圭殑IP鍜宲ort绛夎仈绯讳俊鎭傜埇铏腑涓嶈兘鐩存帴鐢╝nnounce_peer锛屽惁鍒欏緢瀹规槗浠庝笂涓嬫枃涓垽鏂槸閫氭姤铏氬亣璧勬簮鑰岃绂佹帀銆

鍙傛暟锛

{"id" : "<querying nodes id>", "implied_port": <0 or 1>, "info_hash" : "<20-byte infohash of target torrent>", "port" : <port number>, "token" : "<opaque token>"}
鍥炲锛

{"id" : "<queried nodes id>"}
杩欓噷杩囨潵鐨刬nfo_hash琛ㄦ槑宸茬粡鏈夊湪涓嬭浇浜嗭紝澶ч儴鍒嗘槸瀛樺湪鐨勶紝杩欓噷涓昏鏀堕泦杩欎釜璇锋眰鐨勪俊鎭痠nfo_hash銆乮p銆乸ort銆乶ame锛坣ame涓嶄竴瀹氭湁锛

ping鍜宖ind_node鍜屾姤鏂囨渚嬬湅涓涓嬪畼鏂规枃妗f垨鏂囩珷鍚庣殑鍙傝冪炕璇戞枃绔狅紝鏂囨。宸茬粡鍐欏緱寰堣缁嗕簡锛涗簡瑙d簡杩欎袱涓姹傦紝鍩烘湰瑙e喅淇℃伅鏀堕泦鐨勯棶棰樹簡銆

All posts

Other pages

鍙戣〃璇勮

鐢靛瓙閭欢鍦板潃涓嶄細琚叕寮銆 蹇呭~椤瑰凡鐢*鏍囨敞