最近在做webrtc相關的內容,底層ice協商遇到如下問題:
libnice版本:0.1.14 獲取地址:https://nice.freedesktop.org/releases/
單nat的情況:
1. 當瀏覽器(標准webrtc實現)位於nat內,服務器(使用libnice)位於公網時,可以實現ice的成功協商,獲取協商的端口。
2. 當瀏覽器位於公網,服務器位於nat內時,服務器的ice協商遲遲不能成功。
抓包顯示:

其中10.1.1.226為nat內地址,10.9.9.105為服務器地址。
226發出binding request請求后,在105回復的response請求中攜帶了其映射的地址:172.16.193.176
icerfc: https://tools.ietf.org/html/rfc5245 標准中有如下一段話:

即,在binding response消息中會攜帶客戶端映射的外網地址。

客戶端收到bind response信息中的映射地址后,需要把該地址當做新的candidate,來協商
因此按照規范定義,在這種情況下應該是可以協商通過的,但是libnice並沒有。
查閱google:
https://github.com/meetecho/janus-gateway/issues/788
有興趣的可以讀完整個討論,這里摘錄開頭
Not sure if this is anything you want to look into now, but I thought I'd file it in case.
Current master of libnice (1778f79008 as of this writing) doesn't seem to work properly with Janus.
I am currently using the latest libnice with a Licode installation I have, so I don't think the issue is only with libnice. Some git bisect work got me to the problem commit: 1ab9d7c104978ea1904aaaad708c1c8c23c77592 is the first bad commit commit 1ab9d7c104978ea1904aaaad708c1c8c23c77592 Author: Olivier Crête olivier.crete@collabora.com Date: Thu May 26 16:05:36 2016 -0400 conncheck: Separate valid and succeded states RFC 5245 specifies that when a mapped-address differs from the address from the request was sent, the mapped-address is used to select the valid pair, but the source address of the check is used to select the pair that succeeded, so they are not the same. After reverting that commit (took a small amount of conflict resolution, but not too bad),
I was able to get libnice master working again with Janus. Normally I wouldn't expect you to chase the master commits,
but libnice is a unique beast -- the last official release was almost two years ago,
and it has issues that have long since been fixed in master.
I thought it might be worth looking at this problem commit that
I found to see if there's some reasonable adjustment you can make in Janus to accommodate for it.
with libnice master, ice fails when client in NAT。
因此懷疑是libnice的版本問題,在github上master分支拉取最新代碼編譯后,問題解決。
