토렌트를 다운로드 받을 때 피어란을 보면 플래그 또는 상태라고 적혀져 있는 란이 있다. 여러가지 알파벳이 적혀있는데(D, X, I, C 등.. 물음표(?)도 있음) 궁금해서 libtorrent 소스를 한번 뒤져봤다.

바로 찾을 줄 알았는데 시간이 좀 걸렸다. 플래그가 하드코딩 돼있는 줄 알았는데 그게 아니고 비트마스크 플래그 값이고 그걸 클라이언트가 알아서 출력하는 것이었다.

대략 요약하면 플래그는 피어와의 연결상태를 나타내주는 값이다.

 

		// **we** are interested in pieces from this peer.
		static constexpr peer_flags_t interesting = 0_bit;

		// **we** have choked this peer.
		static constexpr peer_flags_t choked = 1_bit;

		// the peer is interested in **us**
		static constexpr peer_flags_t remote_interested = 2_bit;

		// the peer has choked **us**.
		static constexpr peer_flags_t remote_choked = 3_bit;

		// means that this peer supports the
		// `extension protocol`__.
		//
		// __ extension_protocol.html
		static constexpr peer_flags_t supports_extensions = 4_bit;

		// The connection was initiated by us, the peer has a
		// listen port open, and that port is the same as in the
		// address of this peer. If this flag is not set, this
		// peer connection was opened by this peer connecting to
		// us.
		static constexpr peer_flags_t local_connection = 5_bit;

		// The connection is opened, and waiting for the
		// handshake. Until the handshake is done, the peer
		// cannot be identified.
		static constexpr peer_flags_t handshake = 6_bit;

		// The connection is in a half-open state (i.e. it is
		// being connected).
		static constexpr peer_flags_t connecting = 7_bit;

#if TORRENT_ABI_VERSION == 1
		// The connection is currently queued for a connection
		// attempt. This may happen if there is a limit set on
		// the number of half-open TCP connections.
		static constexpr peer_flags_t queued = 8_bit;
#endif

		// The peer has participated in a piece that failed the
		// hash check, and is now "on parole", which means we're
		// only requesting whole pieces from this peer until
		// it either fails that piece or proves that it doesn't
		// send bad data.
		static constexpr peer_flags_t on_parole = 9_bit;

		// This peer is a seed (it has all the pieces).
		static constexpr peer_flags_t seed = 10_bit;

		// This peer is subject to an optimistic unchoke. It has
		// been unchoked for a while to see if it might unchoke
		// us in return an earn an upload/unchoke slot. If it
		// doesn't within some period of time, it will be choked
		// and another peer will be optimistically unchoked.
		static constexpr peer_flags_t optimistic_unchoke = 11_bit;

		// This peer has recently failed to send a block within
		// the request timeout from when the request was sent.
		// We're currently picking one block at a time from this
		// peer.
		static constexpr peer_flags_t snubbed = 12_bit;

		// This peer has either explicitly (with an extension)
		// or implicitly (by becoming a seed) told us that it
		// will not downloading anything more, regardless of
		// which pieces we have.
		static constexpr peer_flags_t upload_only = 13_bit;

		// This means the last time this peer picket a piece,
		// it could not pick as many as it wanted because there
		// were not enough free ones. i.e. all pieces this peer
		// has were already requested from other peers.
		static constexpr peer_flags_t endgame_mode = 14_bit;

		// This flag is set if the peer was in holepunch mode
		// when the connection succeeded. This typically only
		// happens if both peers are behind a NAT and the peers
		// connect via the NAT holepunch mechanism.
		static constexpr peer_flags_t holepunched = 15_bit;

		// indicates that this socket is running on top of the
		// I2P transport.
		static constexpr peer_flags_t i2p_socket = 16_bit;

		// indicates that this socket is a uTP socket
		static constexpr peer_flags_t utp_socket = 17_bit;

		// indicates that this socket is running on top of an SSL
		// (TLS) channel
		static constexpr peer_flags_t ssl_socket = 18_bit;

		// this connection is obfuscated with RC4
		static constexpr peer_flags_t rc4_encrypted = 19_bit;

		// the handshake of this connection was obfuscated
		// with a Diffie-Hellman exchange
		static constexpr peer_flags_t plaintext_encrypted = 20_bit;

		// tells you in which state the peer is in. It is set to
		// any combination of the peer_flags_t flags above.
		peer_flags_t flags;

		// The peer was received from the tracker.
		static constexpr peer_source_flags_t tracker = 0_bit;

		// The peer was received from the kademlia DHT.
		static constexpr peer_source_flags_t dht = 1_bit;

		// The peer was received from the peer exchange
		// extension.
		static constexpr peer_source_flags_t pex = 2_bit;

		// The peer was received from the local service
		// discovery (The peer is on the local network).
		static constexpr peer_source_flags_t lsd = 3_bit;

		// The peer was added from the fast resume data.
		static constexpr peer_source_flags_t resume_data = 4_bit;

		// we received an incoming connection from this peer
		static constexpr peer_source_flags_t incoming = 5_bit;

		// a combination of flags describing from which sources this peer
		// was received. A combination of the peer_source_flags_t above.
		peer_source_flags_t source;

peer_info.hpp에 peer_info 구조체가 정의돼있고 그 안에 static peer_flags_t가 멤버로 들어있다.

플래그는 flags와 source 두 개가 있는데 flags는 피어 상태를 나타내는 것이고, source는 이 피어를 어떻게 찾게 됐는지 나타내는 플래그다. 대충 이 플래그를 조합해 알파벳으로 표기하는 것 같다. 클라이언트마다 알파벳을 다르게 구현할 수도... 있겠지만 보니까 대충 다 비슷한 것 같다.

 

qBittorrent의 깃헙 위키 페이지에는 다음과 같이 설명돼있다.

P = μtp
D = Currently downloading (interested and not choked)
d = Your client wants to download, but peer doesn't want to send (interested and choked)
U = Currently uploading (interested and not choked)
u = Peer wants your client to upload, but your client doesn't want to (interested and choked)
O = Optimistic unchoke
S = Peer is snubbed
I = Peer is an incoming connection
K = Peer is unchoking your client, but your client is not interested
? = Your client unchoked the peer but the peer is not interested
X = Peer was included in peerlists obtained through Peer Exchange (PEX)
H = Peer was obtained through DHT.
E = Peer is using Protocol Encryption (all traffic)
e = Peer is using Protocol Encryption (handshake)
L = Peer is local (discovered through network broadcast, or in reserved local IP ranges) 

 

Choke? Interest? 모르는 용어가 나오는데 비트토렌트의 알고리즘이라고 한다.

choking이란 업로드는 하지 않고 다운로드만을 하는 피어를 방지하기 위한 방법으로 leecher의 다운로드 속도를 떨어트리는 방법이다. 클라이언트는 10초마다 각각 연결의 현재 다운로드 속도를 계산해 choke, unchoke 여부를 결정한다고 한다.

기타 다른 용어들에 대해서는 이 페이지를 참조.

 

토렌트 알고리즘에 깊이 파고들기는 귀찮으니 그냥 여기까지 적겠다.. 갑자기 이런게 궁금해져가지고 휘유;

반응형