Tigase输出从客户端和服务器的请求应答日志

ぐ巨炮叔叔 提交于 2019-12-04 04:37:10

http://chutianxing.wordpress.com有些中文翻译文章,不过需要翻墙访问


Tigase改装目标

把Tigase迁移到DAF是我们的目标。DAF(Datou Application Framework)是手机大头的服务器集群应用开发框架,它使用Zeroc ICE作为服务器节点和节点之间的通讯中间件,使用Google Protocol Buffers作为通讯内容格式。

第一日 – 从客户端和服务器之间的通讯开始

在开始的前几天,思路是模糊的,因为对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进行登录了,在日志里面可以方便得看到通讯内容:

  1. C to S:
    1
    <?xmlversion='1.0'?><stream:streamto='chutianxing-laptop'xmlns='jabber:client'xmlns:stream=' http://etherx.jabber.org/streams'version='1.0'>
  2. S to C:
    1
    <?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream=' http://etherx.jabber.org/streams'from='chutianxing-laptop'id='2a64d8bf-b69e-4267-8792-e1e20d6b6ce5'version='1.0'xml:lang='en'>
  3. 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=" http://jabber.org/features/iq-register"/><authxmlns=" http://jabber.org/features/iq-auth"/></stream:features>
  4. C to S:
    1
    <starttlsxmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
  5. S to C:
    1
    <proceedxmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
  6. C to S(encoded ):
    1
    <stream:streamto='chutianxing-laptop'xmlns='jabber:client'xmlns:stream=' http://etherx.jabber.org/streams'version='1.0'>
  7. S to C(encoded ):
    1
    <?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream=' http://etherx.jabber.org/streams'from='chutianxing-laptop'id='2a64d8bf-b69e-4267-8792-e1e20d6b6ce5'version='1.0'xml:lang='en'>
  8. 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=" http://jabber.org/features/iq-register"/><authxmlns=" http://jabber.org/features/iq-auth"/></stream:features>
  9. C to S(encoded ):
    1
    <authxmlns='urn:ietf:params:xml:ns:xmpp-sasl'mechanism='DIGEST-MD5'xmlns:ga=' http://www.google.com/talk/protocol/auth'ga:client-uses-full-bind-result='true'>dXNlcm5hbWU9ImNodXRpYW54aW5nIixyZWFsbT0iY2h1dGlhbnhpbmctbGFwdG9wIixub25jZT0iL3I0blNzU0dyVlVnZUxwT2tLRU43TVkvU3dOblR1bXJkbFMvUHRCWCIsY25vbmNlPSJhZlFEQ2JxTjVwdDZTVy8wbUNKVmpway93UXFRSU9JNGcxRllyVUNnYWtZPSIsbmM9MDAwMDAwMGEscW9wPWF1dGgsZGlnZXN0LXVyaT0ieG1wcC9jaHV0aWFueGluZy1sYXB0b3AiLHJlc3BvbnNlPWFmMWEyMmQ4OGE1NzZkZWVmODRmOWRjOTczYjU3NDJl</auth>
  10. S to C(encoded ):
    1
    <failurexmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
  11. C to S(encoded ):
    1
    <authxmlns='urn:ietf:params:xml:ns:xmpp-sasl'mechanism='PLAIN'xmlns:ga=' http://www.google.com/talk/protocol/auth'ga:client-uses-full-bind-result='true'>AGNodXRpYW54aW5nAGVpd2F5</auth>
  12. S to C(encoded ):
    1
    <successxmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
  13. C to S(encoded ):
    1
    <stream:streamto='chutianxing-laptop'xmlns='jabber:client'xmlns:stream=' http://etherx.jabber.org/streams'version='1.0'>
  14. S to C(encoded ):
    1
    <?xmlversion='1.0'?><stream:streamxmlns='jabber:client'xmlns:stream=' http://etherx.jabber.org/streams'from='chutianxing-laptop'id='2a64d8bf-b69e-4267-8792-e1e20d6b6ce5'version='1.0'xml:lang='en'>
  15. S to C(encoded ):
    1
    <stream:features><verxmlns="urn:xmpp:features:rosterver"/><sessionxmlns="urn:ietf:params:xml:ns:xmpp-session"/><registerxmlns=" http://jabber.org/features/iq-register"/><bindxmlns="urn:ietf:params:xml:ns:xmpp-bind"/></stream:features>
  16. C to S(encoded ):
    1
    <iqtype='set'id='purple85591d16'><bindxmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>pidgin</resource></bind></iq>
  17. 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>
  18. C to S(encoded ):
    1
    <iqtype='set'id='purple85591d17'><sessionxmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>
  19. S to C(encoded ):
    1
    <iqto="chutianxing@chutianxing-laptop/pidgin"id="purple85591d17"type="result"/>
  20. C to S(encoded ):
    1
    <iqtype='get'id='purple85591d18'to='chutianxing-laptop'><queryxmlns=' http://jabber.org/protocol/disco#items'/></iq>
  21. S to C(encoded ):
    1
    <iqfrom="chutianxing-laptop"to="chutianxing@chutianxing-laptop/pidgin"id="purple85591d18"type="result"><queryxmlns=" http://jabber.org/protocol/disco#items"/></iq>
  22. C to S(encoded ):
    1
    <iqtype='get'id='purple85591d19'to='chutianxing-laptop'><queryxmlns=' http://jabber.org/protocol/disco#info'/></iq>
  23. S to C(encoded ):
    1
    <iqfrom="chutianxing-laptop"to="chutianxing@chutianxing-laptop/pidgin"id="purple85591d19"type="result"><queryxmlns=" http://jabber.org/protocol/disco#info"><identitycategory="server"name="Tigase ver. 5.1.0-SNAPSHOT"type="im"/><featurevar=" http://jabber.org/protocol/disco#info"/><featurevar=" http://jabber.org/protocol/disco#items"/><featurevar="msgoffline"/><featurevar=" http://jabber.org/protocol/stats"/><featurevar=" http://jabber.org/protocol/commands"/><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=" http://jabber.org/protocol/disco#info"/><featurevar=" http://jabber.org/protocol/disco#items"/><featurevar="jabber:iq:privacy"/><featurevar="urn:ietf:params:xml:ns:xmpp-bind"/><featurevar="jabber:iq:private"/><featurevar="jabber:iq:auth"/></query></iq>
  24. C to S(encoded ):
    1
    <iqtype='get'id='purple85591d1a'><vCardxmlns='vcard-temp'/></iq>
  25. S to C(encoded ):
    1
    <iqto="chutianxing@chutianxing-laptop/pidgin"id="purple85591d1a"type="result"><vCardxmlns="vcard-temp"/></iq>
  26. C to S(encoded ):
    1
    <iqtype='get'id='purple85591d1b'><queryxmlns='jabber:iq:roster'/></iq><iqtype='get'id='purple85591d1c'to='chutianxing-laptop'><queryxmlns=' http://jabber.org/protocol/disco#items'node=' http://jabber.org/protocol/commands'/></iq>
  27. S to C(encoded ):
    1
    <iqfrom="chutianxing-laptop"to="chutianxing@chutianxing-laptop/pidgin"id="purple85591d1c"type="result"><querynode=" http://jabber.org/protocol/commands"xmlns=" http://jabber.org/protocol/disco#items"/></iq>
  28. C to S(encoded ):
    1
    <iqtype='get'id='purple85591d1d'to='proxy.eu.jabber.org'><queryxmlns=' http://jabber.org/protocol/bytestreams'/></iq>
  29. 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>
  30. C to S(encoded ):
    1
    <presence><priority>1</priority><cxmlns=' http://jabber.org/protocol/caps'node=' http://pidgin.im/'hash='sha-1'ver='lV6i//bt2U8Rm0REcX8h4F3Nk3M='ext='voice-v1 camera-v1 video-v1'/><xxmlns='vcard-temp:x:update'><photo/></x></presence>
  31. ……
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!