Openfire源码分析by jiyuqi.docx

上传人:b****4 文档编号:24660006 上传时间:2023-05-30 格式:DOCX 页数:37 大小:155.05KB
下载 相关 举报
Openfire源码分析by jiyuqi.docx_第1页
第1页 / 共37页
Openfire源码分析by jiyuqi.docx_第2页
第2页 / 共37页
Openfire源码分析by jiyuqi.docx_第3页
第3页 / 共37页
Openfire源码分析by jiyuqi.docx_第4页
第4页 / 共37页
Openfire源码分析by jiyuqi.docx_第5页
第5页 / 共37页
点击查看更多>>
下载资源
资源描述

Openfire源码分析by jiyuqi.docx

《Openfire源码分析by jiyuqi.docx》由会员分享,可在线阅读,更多相关《Openfire源码分析by jiyuqi.docx(37页珍藏版)》请在冰豆网上搜索。

Openfire源码分析by jiyuqi.docx

Openfire源码分析byjiyuqi

启动流程

Socket接口

Socket通信使用Mina框架实现,是XMPP协议的处理入口,具体为:

消息接收后由不同的节处理器处理:

StanzaHandler基础消息类型,之后进行消息路由:

最后通过路由表进行路由:

Http接口

Http接口用于Web端的管理以及Web客户端的通信,使用jetty实现。

通过XMPServer启动ConectionManager来管理链接启动,包括SSL,HTTP,TCP等。

消息处理流程

消息发送

消息的发送通过NIOConnection.deliver(Packetpacket)实现。

模块功能列表

启动模块

RoutingTableImpl

/**

*Routingtablethatstoresroutestoclientsessions,outgoingserversessions

*andcomponents.Assoonasauserauthenticateswiththeserveritsclientsession

*willbeaddedtotheroutingtable.Whenevertheclientsessionbecomesavailable

*orunavailabletheroutingtablewillbeupdatedtoo.

*

*Whenrunninginsideofaclustertheroutingtablewillalsokeepreferencestoroutes

*hostedinotherclusternodes.A{@linkRemotePacketRouter}willbeusetoroutepackets

*torouteshostedinotherclusternodes.

*

*Failuretorouteapacketwillendupsending{@linkIQRouter#routingFailed(JID,Packet)},

*{@linkMessageRouter#routingFailed(JID,Packet)}or{@linkPresenceRouter#routingFailed(JID,Packet)}

*dependingonthepackettypethattriedtobesent.

*

*@authorGastonDombiak

*/

AuditManager

/**

*Managesanddirectsservermessageauditingbehavior.Turningon

*allauditingoptionscanproducecopiousamountsofdataand

*significantlyslowtheserverasitsavesthedatatopersistentstorage.

*

*AuditingcurrentlysavesauditdatatoarawXMLfile

*whichcanlaterbeprocessedandminedforinformation.

*

*@authorIainShigeoka

*/

RostManager

/**

*AsimpleservicethatallowscomponentstoretrievearosterbasedsolelyontheID

*oftheowner.Usershaveconveniencemethodsforobtainingarosterassociatedwith

*theowner.Howevertherearemanycomponentsthatneedtoretrievetheroster

*basedsolelyonthegenericIDownerkey.Thisinterfacedefinesaservicethatcan

*dothat.Thisallowsclassesthatgenericallymanageresourceforresourceowners

*(suchaspresenceupdates)togenericallyoffertheirserviceswithoutknowingor

*caringiftherosterownerisauser,chatbot,etc.

*

*@authorIainShigeoka

*/

PluginManager

/**

*Loadsandmanagesplugins.Thepluginsdirectoryismonitoredforany

*newplugins,andtheyaredynamicallyloaded.

*

*

Aninstanceofthisclasscanbeobtainedusing:

*

*XMPPServer.getInstance().getPluginManager()

*

*@authorMattTucker

*@seePlugin

*@seeorg.jivesoftware.openfire.XMPPServer#getPluginManager()

*/

核心模块

PresenceManagerImpl

/**

*Thepresencemanagertracksonaglobalbasiswho'sonline.Thepresence

*monitorwatchesandreportsonwhatusersarepresentontheserver,and

*inotherjabberdomainsthatitknowsabout.Thepresencemanagerdoes

*notknowaboutinvisibleusers(theyareinvisible).

*

*@authorIainShigeoka

*/

SessionManager

/**

*Managesthesessionsassociatedwithanaccount.Theinformation

*maintainedbytheSessionmanagerisentirelytransientanddoes

*notneedtobepreservedbetweenserverrestarts.

*

*@authorDerekDeMoro

*/

PacketRouterImpl

/**

*Arouterthathandlesincomingpackets.Packetswillberoutedtotheir

*correspondinghandler.Arouterismuchlikeaforwardedwithsomelogic

*tofiguteoutwhoisthetargetforeachpacket.

*

*@authorGastonDombiak

*/

IQRouter

/**

*Routesiqpacketsthroughouttheserver.Routingisbasedontherecipient

*andsenderaddresses.Thetypicalpacketwilloftenberoutedtwice,once

*fromthesendertosomeinternalservercomponentforhandlingorprocessing,

*andthenbacktotheroutertobedeliveredtoit'sfinaldestination.

*

*@authorIainShigeoka

*/

MessageRouter

/**

*

Routemessagepacketsthroughouttheserver.

*

Routingisbasedontherecipientandsenderaddresses.Thetypical

*packetwilloftenberoutedtwice,oncefromthesendertosomeinternal

*servercomponentforhandlingorprocessing,andthenbacktotherouter

*tobedeliveredtoit'sfinaldestination.

*

*@authorIainShigeoka

*/

PresenceRouter

/**

*

Routepresencepacketsthroughouttheserver.

*

Routingisbasedontherecipientandsenderaddresses.Thetypical

*packetwilloftenberoutedtwice,oncefromthesendertosomeinternal

*servercomponentforhandlingorprocessing,andthenbacktotherouter

*tobedeliveredtoit'sfinaldestination.

*

*@authorIainShigeoka

*/

MulticastRouter

将一个包路由到多个目的地址,包括远程地址,但只获取深度为1的地址。

/**

*Routerofpacketswithmultiplerecipients.Clientsmaysendasinglepacketwithmultiple

*recipientsandtheserverwillbroadcastthepackettothetargetreceipients.Ifrecipients

*belongtoremoteservers,thenthisserverwilldiscoverifremotetargetserverssupport

*multicastservice.Ifaremoteserversupportsthemulticastservice,asinglepacketwillbe

*senttotheremoteserver.Ifaremoteserverdoesn'tthesupportmulticast

*processing,thelocalserversendsacopyoftheoriginalstanzatoeachaddress.

*

*Thecurrentimplementationwillonlysearchuptothefirstlevelofnodesofremoteservers

*whentryingtofindoutifremoteservershavesupportformulticastservice.Itisassumed

*thatitishighlyunlikelyforserverstohaveanodeinthesecondorthirddepthlevel

*providingthemulticastservice.Serversshouldnormallyprovidethisservicethemselvesor

*atleastasafirstlevelnode.

*

*Thisisanimplementationof

//www.jabber.org/jeps/jep-0033.html>

*JEP-0033:

ExtendedStanzaAddressing

*

*@authorMattTucker

*/

PacketTransporterImpl

/**

*In-memoryimplementationofthepackettransporterservice.

*

*@authorIainShigeoka

*/

PacketDelivererImpl

/**

*In-memoryimplementationofthepacketdelivererservice

*

*@authorIainShigeoka

*/

TransportHandler

/**

*Routespacketstotheappropriatetransportgatewayordropsthepacket.

*

*@authorIainShigeoka

*/

OfflineMessageStrategy

/**

*Controlswhatisdonewithofflinemessages.

*

*@authorIainShigeoka

*/

OfflineMessageStore

/**

*Representstheuser'sofflinemessagestorage.Amessagestoreholdsmessagesthatwere

*senttotheuserwhiletheywereunavailable.Theusercanretrievetheirmessagesby

*settingtheirpresenceto"available".Themessageswillthenbedeliverednormally.

*Offlinemessagestorageisoptional,inwhichcaseanullimplementationisreturnedthat

*alwaysthrowsUnauthorizedExceptionwhenaddingmessagestothestore.

*

*@authorIainShigeoka

*/

VCardManager

电子名片管理器

/**

*ManagesVCardinformationforusers.

*

*@authorMattTucker

*/

标准模块

IQBindHandler

/**

*Bindsaresourcetothestreamsothattheclient'saddressbecomesafullJID.Oncearesource

*hasbeenbindedtothesessiontheentity(i.e.client)isconsidereda"connectedresource".

*

*Clientsmayspecifyadesiredresourcebutifnonewasspecifiedthentheserverwillcreate

*arandomresourceforthesession.ThenewresourceshouldbeinaccordancewithResourcePrep.

*Theserverwillalsoverifyifthereareprevioussessionsfromthesameuserthatarealready

*usingtheresourcespecifiedbytheuser.Dependingontheserverconfigurationtheoldsession

*maybekickedorthenewsessionmayberejected.

*

*@authorGastonDombiak

*/

IQSessionEstablishmentHandler

/**

*Activateclientsessionsonceresourcebindinghasbeendone.Clientsneedtoactivetheir

*sessionsinordertoengageininstantmessagingandpresenceactivities.Theservermay

*denysessionsactivationsifthemaxnumberofsessionsintheserverhasbeenreachedor

*ifauserdoesnothavepermissionstocreatesessions.

*

*Currentimplementationdoesnotcheckanyoftheaboveconditions.However,futureversions

*mayaddsupportforthosecheckings.

*

*@authorGastonDombiak

*/

IQAuthHandler

/**

*ImplementstheTYPE_IQjabber:

iq:

authprotocol(plainonly).Clients

*usethisprotocoltoauthenticatewiththeserver.A'get'query

*runsanauthenticationprobewithagivenusername.Returnthe

*authenticationformoranerrorindicatingtheuserisnot

*registeredontheserver.

*

*A'set'queryauthenticateswithinformationgiveninthe

*authenticationform.Anauthenticatedsessionmayresettheir

*authenticationinformationusinga'set'query.

*

*

Assumptions

*Thishandlerassumesthattherequestisaddressedtotheserver.

*AnappropriateTYPE_IQtagmatchershouldbeplacedinfrontofthis

*onetorouteTYPE_IQrequestsnotaddressedtotheserverto

*anotherchannel(probablyfordirectdeliverytotherecipient).

*

*@authorIainShigeoka

*/

IQPingHandler

/**

*ImplementstheXMPPPingasdefinedbyXEP-0199.Thisprotocoloffersan

*alternativetothetraditional'whitespaceping'approachofdeterminingthe

*availabilityofanentity.TheXMPPPingprotocolallowspingstobe

*performedinamoreXML-friendlyapproach,whichcanbeusedovermorethan

*onehopinthecommunicationpath.

*

*@authorGuusderKinderen

*@see

//www.xmpp.org/extensions/xep-0199.html">XEP-0199:

XMPPPing

*/

IQPrivateHandler

/**

*ImplementstheTYPE_IQjabber:

iq:

privateprotocol.Clients

*usethisprotocoltostoreandretrievearbitraryapplication

*configurationinformation.Usingtheserverforsettingstorage

*allowsclientconfigurationstofollowuserswhereevertheygo.

*

*A'get'queryretrievesanystoreddata.

*A'set'querystoresnewdata.

*

*

*Currentlyanemptyimplementationtoallowusagewi

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 企业管理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1