有些中文翻译文章,不过需要翻墙访问
Tigase改装目标
把Tigase迁移到DAF是我们的目标。DAF(Datou Application Framework)是手机大头的服务器集群应用开发框架,它使用作为服务器节点和节点之间的通讯中间件,使用作为通讯内容格式。
第一日 – 从客户端和服务器之间的通讯开始
在开始的前几天,思路是模糊的,因为对tigase还有太多不了解,所以日记中的一些结论是基于猜测和经验产生的,很可能在继续深入的时候被推翻。所以各位看官发现有重大问题时不必惊慌,以后我会自己发现的。
可以想像,迁移工作分为以下几个重要部分:
- XMPP要求entity与entity之间使用xml进行通讯,但DAF要求entity与entity之间使用PB进行通讯。所以在服务端,我们需要把entity和entity(这里的两个entity特指tigase的内部组件或服务)之间的xml通讯修改为pb通讯,或者采用简单一些的方法:干脆不对tigase进行任何拆解,整个一个服务作为DAF中的一个节点。
- 不管最终方案是否对Tigase进行拆解,都必须对XMPP协议进行转换,转换为大头私有协议,这需要一个协议转换器。
- 因为大头IM客户端和服务器之间的通讯基于http1.0,所以如果要让老版本客户端兼容,必须借助并修改Tigase 的BOSH实现;或者我们自己为每一个已连接的老客户端实现一个消息栈。
- 将Tigase的配置框架修改为DAF的配置框架,这个工作应该不难做
- 将Tigase的启动迁移到DAF的节点启动框架中,这个工作也不难
从上述已想到的工作大项上看,最具挑战性的工作是第一项,工作量无法预估,工作时间更无法预估。
为了顺利得启动第一项工作,首先要了解XMPP协议内容(和),在阅读中文版的时候发现了一个,所以之后开始中英文参照阅读。之后为了实际考察Tigase和XMPP客户端之间的通讯,我使用Pidgin作为XMPP客户端,连接Tigase服务器进行了登录测试。
如何通过日志查看Tigase服务器和Pidgin客户端的通讯日志
添加打印通讯日志代码的最佳位置
打印日志的最佳位置在tigase.net.IOService,IOService中有两个重要方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | protectedvoidwriteData(finalString data) { // 这个方法里面的代码需要极小调整: // 修改前: if(data.length() <256) { log.log(Level.FINEST,"Socket: {0}, Writing data ({1}): {2}",newObject[]{socketIO, data.length(), data}); }else{ log.log(Level.FINEST,"Socket: {0}, Writing data: {1}",newObject[]{socketIO, data.length()}); } // 修改后: log.log(Level.FINEST,"Socket: {0}, Writing data ({1}): {2}",newObject[]{socketIO, data.length(), data}); } protectedchar[] readData()throwsIOException { // 这个方法里面的代码需要极小调整,: if(log.isLoggable(Level.FINEST)) { // 修改前: log.log(Level.FINEST, "Socket: "+ socketIO +", Decoded character data: "+ cb.array().length); // 修改后 log.log(Level.FINEST, "Socket: "+ socketIO +", Decoded character data: "+ cb.toString()); } } |
修改完代码之后,再编辑Tigase_Home/etc/init.properties文件:
1 2 3 4 | # 修改前 --debug = server # 修改后 --debug = net |
好了,现在可以用Pidgin进行登录了,在日志里面可以方便得看到通讯内容:
- C to S: 1<?xmlversion='1.0'?><stream:streamto='chutianxing-laptop'xmlns='jabber:client'xmlns:stream=' 'version='1.0'>
- S to C: 1<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream=' 'from='chutianxing-laptop'id='2a64d8bf-b69e-4267-8792-e1e20d6b6ce5'version='1.0'xml:lang='en'>
- S to C: 1<stream:features><verxmlns="urn:xmpp:features:rosterver"/><starttlsxmlns="urn:ietf:params:xml:ns:xmpp-tls"/><mechanismsxmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>ANONYMOUS</mechanism></mechanisms><registerxmlns=" "/><authxmlns=" "/></stream:features>
- C to S: 1<starttlsxmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
- S to C: 1<proceedxmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
- C to S(encoded ): 1<stream:streamto='chutianxing-laptop'xmlns='jabber:client'xmlns:stream=' 'version='1.0'>
- S to C(encoded ): 1<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream=' 'from='chutianxing-laptop'id='2a64d8bf-b69e-4267-8792-e1e20d6b6ce5'version='1.0'xml:lang='en'>
- S to C(encoded ): 1<stream:features><verxmlns="urn:xmpp:features:rosterver"/><mechanismsxmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>DIGEST-MD5</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>ANONYMOUS</mechanism></mechanisms><registerxmlns=" "/><authxmlns=" "/></stream:features>
- C to S(encoded ): 1<authxmlns='urn:ietf:params:xml:ns:xmpp-sasl'mechanism='DIGEST-MD5'xmlns:ga=' 'ga:client-uses-full-bind-result='true'>dXNlcm5hbWU9ImNodXRpYW54aW5nIixyZWFsbT0iY2h1dGlhbnhpbmctbGFwdG9wIixub25jZT0iL3I0blNzU0dyVlVnZUxwT2tLRU43TVkvU3dOblR1bXJkbFMvUHRCWCIsY25vbmNlPSJhZlFEQ2JxTjVwdDZTVy8wbUNKVmpway93UXFRSU9JNGcxRllyVUNnYWtZPSIsbmM9MDAwMDAwMGEscW9wPWF1dGgsZGlnZXN0LXVyaT0ieG1wcC9jaHV0aWFueGluZy1sYXB0b3AiLHJlc3BvbnNlPWFmMWEyMmQ4OGE1NzZkZWVmODRmOWRjOTczYjU3NDJl</auth>
- S to C(encoded ): 1<failurexmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
- C to S(encoded ): 1<authxmlns='urn:ietf:params:xml:ns:xmpp-sasl'mechanism='PLAIN'xmlns:ga=' 'ga:client-uses-full-bind-result='true'>AGNodXRpYW54aW5nAGVpd2F5</auth>
- S to C(encoded ): 1<successxmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
- C to S(encoded ): 1<stream:streamto='chutianxing-laptop'xmlns='jabber:client'xmlns:stream=' 'version='1.0'>
- S to C(encoded ): 1<?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream=' 'from='chutianxing-laptop'id='2a64d8bf-b69e-4267-8792-e1e20d6b6ce5'version='1.0'xml:lang='en'>
- S to C(encoded ): 1<stream:features><verxmlns="urn:xmpp:features:rosterver"/><sessionxmlns="urn:ietf:params:xml:ns:xmpp-session"/><registerxmlns=" "/><bindxmlns="urn:ietf:params:xml:ns:xmpp-bind"/></stream:features>
- C to S(encoded ): 1<iqtype='set'id='purple85591d16'><bindxmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>pidgin</resource></bind></iq>
- S to C(encoded ): 1<iqto="chutianxing@chutianxing-laptop/pidgin"id="purple85591d16"type="result"><bindxmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>chutianxing@chutianxing-laptop/pidgin</jid></bind></iq>
- C to S(encoded ): 1<iqtype='set'id='purple85591d17'><sessionxmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>
- S to C(encoded ): 1<iqto="chutianxing@chutianxing-laptop/pidgin"id="purple85591d17"type="result"/>
- C to S(encoded ): 1<iqtype='get'id='purple85591d18'to='chutianxing-laptop'><queryxmlns=' #items'/></iq>
- S to C(encoded ): 1<iqfrom="chutianxing-laptop"to="chutianxing@chutianxing-laptop/pidgin"id="purple85591d18"type="result"><queryxmlns=" #items"/></iq>
- C to S(encoded ): 1<iqtype='get'id='purple85591d19'to='chutianxing-laptop'><queryxmlns=' #info'/></iq>
- S to C(encoded ): 1<iqfrom="chutianxing-laptop"to="chutianxing@chutianxing-laptop/pidgin"id="purple85591d19"type="result"><queryxmlns=" #info"><identitycategory="server"name="Tigase ver. 5.1.0-SNAPSHOT"type="im"/><featurevar=" #info"/><featurevar=" #items"/><featurevar="msgoffline"/><featurevar=" "/><featurevar=" "/><featurevar="jabber:iq:version"/><featurevar="jabber:iq:roster"/><featurevar="jabber:iq:roster-dynamic"/><featurevar="vcard-temp"/><featurevar="urn:ietf:params:xml:ns:xmpp-sasl"/><featurevar="urn:xmpp:ping"/><featurevar="urn:ietf:params:xml:ns:xmpp-session"/><featurevar=" #info"/><featurevar=" #items"/><featurevar="jabber:iq:privacy"/><featurevar="urn:ietf:params:xml:ns:xmpp-bind"/><featurevar="jabber:iq:private"/><featurevar="jabber:iq:auth"/></query></iq>
- C to S(encoded ): 1<iqtype='get'id='purple85591d1a'><vCardxmlns='vcard-temp'/></iq>
- S to C(encoded ): 1<iqto="chutianxing@chutianxing-laptop/pidgin"id="purple85591d1a"type="result"><vCardxmlns="vcard-temp"/></iq>
- C to S(encoded ): 1<iqtype='get'id='purple85591d1b'><queryxmlns='jabber:iq:roster'/></iq><iqtype='get'id='purple85591d1c'to='chutianxing-laptop'><queryxmlns=' #items'node=' '/></iq>
- S to C(encoded ): 1<iqfrom="chutianxing-laptop"to="chutianxing@chutianxing-laptop/pidgin"id="purple85591d1c"type="result"><querynode=" "xmlns=" #items"/></iq>
- C to S(encoded ): 1<iqtype='get'id='purple85591d1d'to='proxy.eu.jabber.org'><queryxmlns=' '/></iq>
- S to C(encoded ): 1<iqto="chutianxing@chutianxing-laptop/pidgin"id="purple85591d1b"type="result"><queryxmlns="jabber:iq:roster"><itemname="root"subscription="both"jid="root@chutianxing-laptop"><group>Buddies</group></item></query></iq>
- C to S(encoded ): 1<presence><priority>1</priority><cxmlns=' 'node=' 'hash='sha-1'ver='lV6i//bt2U8Rm0REcX8h4F3Nk3M='ext='voice-v1 camera-v1 video-v1'/><xxmlns='vcard-temp:x:update'><photo/></x></presence>
- ……