close

http://hi.baidu.com/cnjowang/blog/item/446747551b9f2151574e0053.html    轉貼

 

在Asterisk中對某個peer的類型分為3種:peer, user和friend
看看voip-info對這三種類型的解釋

  • peer: A SIP entity to which Asterisk sends calls (a SIP provider for example). If you want a user (extension) to have multiple phones, define an extension that calls two SIP peers. The peer authenticates at registration.
  • user: A SIP entity which places calls through Asterisk (A phone which can place calls only). Users authenticate to reach services with their context.
  • friend: An entity which is both a user and a peer. This make sense for most desk handsets and other devices. Asterisk will create two objects, one peer and one user, with the same name.

If a _peer_ is defined with host=dynamic it is allowed to register with Asterisk to tell Asterisk where it can be found (IP address/host name) and that it is reachable from now on.

簡單的說,在這篇文檔裡, type=peer定義對方是一個服務提供者, 它允許你的Asterisk通過這裡定義的服務商打電話; 而user則定義對方是你的一個客戶端, 允許對方通過你的Asterisk打電話. friend就是兩者兼有.

但是實際情況是什麼? 試試這樣的定義:
[1001]
username=1001
secret=xxxxx
host=dynamic
port=5060
type=peer
context=from-extensions

然後用一個SIP客戶端來嘗試註冊到你的Asterisk上, what happened?
你會發現客戶端也能註冊上!

其實type的真正意義在於Asterisk怎麼去處理發往外部和來自外部的請求.
type=peer
如果type是peer,有兩層含義.
1. 可以將對方作為一個SIP Service Provider, 允許你的Asterisk通過對方進行呼出.
2. 如果對方在邏輯上是一個客戶端, asterisk將根據傳入的Invite請求來對對方進行身份驗證, 但需要注意的是這裡的驗證不是通過username和secret, 而是通過對方的address和port. 這裡分兩種情況:
* 對方的address和port沒有匹配到你在sip.conf中對任何一個peer的設置, 如果你的Asterisk允許匿名呼入(allowguest=yes), 那麼, 該呼入將被傳到在sip.conf的general配置中的context上. 如果不允許匿名呼入, 直接拒絕該呼入.
* 對方的address和port匹配到了任何一個sip.conf種的peer設置, 那麼改呼入將被傳到該peer指定的context上.
Asterisk還提供了一個insecure參數來配置對peer呼入的身份驗證方式.
insecure=port|invite
    port: Asterisk忽略對方的port, 只根據對方的address來驗證某個peer, Asterisk收到對方的Invite後, 會發送SIP/2.0 401 Unauthorized到對方, 要求對方發送認證信息, 但事實上對方返回回來的認證信息不會被真正使用.
    invite: Asterisk對初始Invite不進行驗證. 這意味著Asterisk直接使用客戶端傳入的Invite包中的信息嘗試進行驗證而不會發送SIP/2.0 401 Unauthorized包到對方

type=user
根據來源Invite包中的用戶和密碼信息來認證,所以對方不能也不需要Register到你的Asterisk服務器上.

需要額外說明一點的是Register, 如果某個peer的host設置為dynamic, 那麼Asterisk允許客戶端通過Register的方式來告訴Asterisk對方的地址和端口.

arrow
arrow
    全站熱搜

    安德森 發表在 痞客邦 留言(0) 人氣()