Candidates(候選)
libjingle一個(gè)主要的好處就是它可以穿透防火墻和NAT設(shè)備進(jìn)行鏈接協(xié)商。libjingle使用ICE機(jī)制穿透防火墻。libjingle應(yīng)用程序第一步要做的就是在試圖協(xié)商一個(gè)鏈接時(shí)為其它計(jì)算機(jī)的鏈入創(chuàng)建一個(gè)潛在的本地端口地址鏈表。鏈表中的每個(gè)潛在的地址就稱作一個(gè)候選。候選就是“IP地址:端口”對(duì)應(yīng)對(duì),這些對(duì)應(yīng)對(duì)使應(yīng)用程序和其它計(jì)算機(jī)互聯(lián)(技術(shù)上,這些對(duì)應(yīng)對(duì)只在本地機(jī)上監(jiān)聽)。libjingle提供了強(qiáng)壯的機(jī)制在本地鏈接上發(fā)現(xiàn)候選供其它計(jì)算機(jī)進(jìn)入,甚至穿透防火墻或NAT設(shè)備。
為了向其它計(jì)算機(jī)提供盡可能多的候選鏈接地址,libjingle生成三種本地候選:
● Local IP addresses 一種候選是計(jì)算機(jī)上的本地IP地址。與它共同在一個(gè)網(wǎng)絡(luò)中的其它計(jì)算機(jī)能夠通過(guò)這個(gè)候選進(jìn)入。
● Global addresses第二種候選是兩個(gè)計(jì)算機(jī)之間的NAT或防火墻設(shè)備的對(duì)外地址。如果這個(gè)候選是NAT設(shè)備對(duì)外地址,libjingle使用心跳包使NAT端口與本地機(jī)綁定起來(lái)并對(duì)外公布這個(gè)全局地址。這個(gè)全局地址被作為從NAT對(duì)外地址鏈接進(jìn)入的候選。
(A second candidate is an external address on a NAT or firewall device between the two computers. If this
is outside a NAT device, libjingle uses STUN to cause the NAT to bind to your computer and expose a global address.
This address is used as a candidate to connect from outside the NAT device.)
● Relay server addresses 大約有8%的鏈接嘗試在穿越防火墻時(shí),上述方法失敗。第三種方法就是在兩個(gè)防火墻之間進(jìn)行服務(wù)器中轉(zhuǎn)。盡管libjingle有能力使用中轉(zhuǎn)服務(wù)器,但是沒有提供中轉(zhuǎn)服務(wù)器的URI。libjingle包含中轉(zhuǎn)服務(wù)的代碼(relayserver.h)。應(yīng)用程序可以自己創(chuàng)建和運(yùn)行這個(gè)服務(wù),使用方法是以中轉(zhuǎn)服務(wù)器的IP地址做為BasicPortAllocator的構(gòu)造函數(shù)的第三個(gè)參數(shù)。
下面的圖演示了兩臺(tái)計(jì)算機(jī)之間生成的 local addrress 候選(C1),external NAT 候選(C2),Relay server候選(C3)。

libjingle以鏈表的形式儲(chǔ)存著全部的候選,這樣可以做到在鏈接建立后,libjingle能夠在當(dāng)前鏈接遲緩或中斷后很快地切換到新的鏈接上。
libjingle包支持多種傳輸方式,實(shí)現(xiàn)了Jingle的<transport>元素表現(xiàn)出來(lái)的精神。一個(gè)transport元素能夠包含比簡(jiǎn)單的候選地址更多的信息:例如:ICE標(biāo)簽支持像優(yōu)先權(quán),密碼,用戶碎片(user fragments)的特殊ICE。盡管這是協(xié)商鏈接的首選方法,為了向下兼容的正規(guī)考慮,libjingle仍然支持客戶繼續(xù)使用老式的<candidate>節(jié)。請(qǐng)查看Jingle ICE Transport Specification 里的transport詳細(xì)說(shuō)明。(對(duì)這一段的翻譯無(wú)自信,把原文附出,請(qǐng)高手指教。)
(libjingle now includes support for multiple transports, in the spirit of the Jingle <transport> element. A transport can contain much more information than a simple candidate address: for example, the ICE transport tag supports ICE-specific information such as priority, password, and user fragments. Although this is the preferred way to negotiate connections, for backward compatibility purposes libjingle still supports clients that still use the older bare <candidate> stanza. See the Jingle ICE Transport Specification for an example of a transport specification.)