Ignore:
Timestamp:
Apr 22, 2009, 4:50:28 PM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@167
Message:

Implement server-to-server dialback protocol and stream management.

Author: ralphm.
Fixes #33.

This also abstracts the concept of a client factory that fires a deferred.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/generic.py

    r35 r55  
    1010from zope.interface import implements
    1111
    12 from twisted.internet import defer
    13 from twisted.words.protocols.jabber import error
     12from twisted.internet import defer, protocol
     13from twisted.words.protocols.jabber import error, xmlstream
    1414from twisted.words.protocols.jabber.xmlstream import toResponse
    1515from twisted.words.xish import domish, utility
     16
     17try:
     18    from twisted.words.xish.xmlstream import BootstrapMixin
     19except ImportError:
     20    from wokkel.compat import BootstrapMixin
    1621
    1722from wokkel import disco
     
    156161        self.source.send = lambda obj: self.sink.dispatch(obj)
    157162        self.sink.send = lambda obj: self.source.dispatch(obj)
     163
     164
     165class DeferredXmlStreamFactory(BootstrapMixin, protocol.ClientFactory):
     166    protocol = xmlstream.XmlStream
     167
     168    def __init__(self, authenticator):
     169        BootstrapMixin.__init__(self)
     170
     171        self.authenticator = authenticator
     172
     173        deferred = defer.Deferred()
     174        self.deferred = deferred
     175        self.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.deferred.callback)
     176        self.addBootstrap(xmlstream.INIT_FAILED_EVENT, deferred.errback)
     177
     178
     179    def buildProtocol(self, addr):
     180        """
     181        Create an instance of XmlStream.
     182
     183        A new authenticator instance will be created and passed to the new
     184        XmlStream. Registered bootstrap event observers are installed as well.
     185        """
     186        xs = self.protocol(self.authenticator)
     187        xs.factory = self
     188        self.installBootstraps(xs)
     189        return xs
     190
     191
     192    def clientConnectionFailed(self, connector, reason):
     193        self.deferred.errback(reason)
Note: See TracChangeset for help on using the changeset viewer.