XMPPでP2Pの音声チャットセッションを確立する方法1

Posted on 9月 20, 2008
Filed Under jingle, xmpp, libjingle, nat, P2P |

頭を整理するためのMemo

GoogleTalkで使われているというjingle

XEP-0166: Jingle
XMPP protocol extension for initiating and managing peer-to-peer media sessions between two XMPP entities in a way that is interoperable with existing Internet standards
既存のInternet標準と共存できる方法で、2つのXMPPentities間でP2Pメディアセッションを確立、管理するためのXMPPプロトコルの拡張。

In essence, Jingle enables two XMPP entities (e.g., romeo@montague.lit and juliet@capulet.lit) to set up, manage, and tear down a multimedia session. The negotiation takes place over XMPP, and the media transfer takes place outside of XMPP. The simplest session flow is as follows:
セッションのnegotiationはXMPPで、メディアはXMPP外で。

CODE:
  1. Initiator                    Responder
  2.   |                             |
  3.   |   session-initiate          |
  4.   |---------------------------->|
  5.   |   ack                       |
  6.   |<----------------------------|
  7.   |   [transport negotiation]   |
  8.   |<--------------------------->|
  9.   |   session-accept            |
  10.   |<----------------------------|
  11.   |   ack                       |
  12.   |---------------------------->|
  13.   |   AUDIO (RTP)               |
  14.   |<===========================>|
  15.   |                             |

Example 1. Initiator sends session-initiate

CODE:
  1. <iq from='romeo@montague.net/orchard'
  2.     id='jingle1'
  3.     to='juliet@capulet.com/balcony'
  4.     type='set'>
  5.   <jingle xmlns='urn:xmpp:tmp:jingle'>
  6.           action='session-initiate'
  7.           initiator='romeo@montague.net/orchard'
  8.           sid='a73sjjvkla37jfea'>
  9.     <content creator='initiator' name='voice'>
  10.       <description xmlns='urn:xmpp:tmp:jingle:apps:rtp' media='audio'>
  11.         <payload -type id='96' name='speex' clockrate='16000'/>
  12.         <payload -type id='97' name='speex' clockrate='8000'/>
  13.         <payload -type id='18' name='G729'/>
  14.         <payload -type id='0' name='PCMU' />
  15.         <payload -type id='103' name='L16' clockrate='16000' channels='2'/>
  16.         <payload -type id='98' name='x-ISAC' clockrate='8000'/>
  17.       </description>
  18.       <transport xmlns='urn:xmpp:tmp:jingle:transports:ice-udp'/>
  19.     </content>
  20.   </jingle>
  21. </iq>

Example 2. Responder acknowledges session-initiate

CODE:
  1. <iq from='juliet@capulet.com/balcony'
  2.     id='jingle1'
  3.     to='romeo@montague.net/orchard'
  4.     type='result'/>

After successful transport negotiation (not shown here), the responder accepts the session by sending a session-accept action to the initiator.

Example 3. Responder definitively accepts the session

CODE:
  1. <iq from='juliet@capulet.com/balcony'
  2.     id='accept1'
  3.     to='romeo@montague.net/orchard'
  4.     type='set'>
  5.   <jingle xmlns='urn:xmpp:tmp:jingle'
  6.           action='session-accept'
  7.           initiator='romeo@montague.net/orchard'
  8.           responder='juliet@capulet.com/balcony'
  9.           sid='a73sjjvkla37jfea'>
  10.     <content creator='initiator' name='voice'>
  11.       <description xmlns='urn:xmpp:tmp:jingle:apps:rtp' media='audio'>
  12.         <payload -type id='97' name='speex' clockrate='8000'/>
  13.         <payload -type id='18' name='G729'/>
  14.       </description>
  15.       <transport xmlns='urn:xmpp:tmp:jingle:transports:ice-udp'>
  16.         <candidate component='1'
  17.                    foundation='1'
  18.                    generation='0'
  19.                    ip='192.0.2.3'
  20.                    network='1'
  21.                    port='45664'
  22.                    priority='1678246398'
  23.                    protocol='udp'
  24.                    pwd='asd88fgpdd777uzjYhagZg'
  25.                    type='srflx'
  26.                    ufrag='8hhy'/>
  27.       </transport>
  28.     </content>
  29.   </jingle>
  30. </iq>

ここで
・受信側が使えるpayload-typeに絞り込まれて(?)レスポンス
・IPアドレスとポートが受信側のjulietから送信側のromeoへ行ってる。

IPアドレスとポートはどうやって取得してるんだろ。
この例では192..ってローカルのIPだけどNAT超えの時は、NATの外側のグローバルIPとポートが必要でしょう。

XEP-0166: Jingleでは省略されてる transport negotiation について調べる。

Comments

Leave a Reply