Trees | Indices | Help |
---|
|
1 # -*- Mode: Python -*- 2 # vi:si:et:sw=4:sts=4:ts=4 3 # 4 # Flumotion - a streaming media server 5 # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 6 # All rights reserved. 7 8 # This file may be distributed and/or modified under the terms of 9 # the GNU General Public License version 2 as published by 10 # the Free Software Foundation. 11 # This file is distributed without any warranty; without even the implied 12 # warranty of merchantability or fitness for a particular purpose. 13 # See "LICENSE.GPL" in the source distribution for more information. 14 15 # Licensees having purchased or holding a valid Flumotion Advanced 16 # Streaming Server license may use this file in accordance with the 17 # Flumotion Advanced Streaming Server Commercial License Agreement. 18 # See "LICENSE.Flumotion" in the source distribution for more information. 19 20 # Headers in this file shall remain intact. 21 22 from twisted.internet.protocol import Protocol, Factory 23 from twisted.internet.tcp import Port, Connection 24 from twisted.internet import reactor, address 25 from twisted.cred import credentials 26 27 from flumotion.common import medium, log 28 from flumotion.twisted import defer, fdserver 29 from flumotion.twisted import pb as fpb 30 31 import socket 32 33 # Very similar to tcp.Server, but we need to call things in a different order35 """ 36 A connection class for use with passed FDs. 37 Similar to tcp.Server, but gets the initial FD from a different source, 38 obviously, and also passes along some data with the original connection. 39 """6541 Connection.__init__(self, sock, protocol) 42 self.client = addr 43 44 # Inform the protocol we've made a connection. 45 protocol.makeConnection(self) 46 47 # Now, we want to feed in the extra data BEFORE the reactor reads 48 # anything additional from the socket. However, if we call this in 49 # the other order, and the socket gets closed (or passed to something 50 # non-twisted) after just the initial chunk, we'll be calling 51 # startReading() on something we've already stopped reading. That won't 52 # work too well... Fortunately, the reactor runs in this thread, so 53 # merely adding it (with startReading()) can't cause a read to happen 54 # immediately. 55 self.startReading() 56 self.connected = 1 57 58 protocol.dataReceived(additionalData)5961 return address.IPv4Address('TCP', *(self.socket.getsockname() + ('INET',)))6267 """ 68 A medium we use to talk to the porter. 69 Mostly, we use this to say what mountpoints (or perhaps, later, 70 (hostname, mountpoint) pairs?) we expect to receive requests for. 71 """ 74 778379 return self.callRemote("registerPrefix", prefix)8082 return self.callRemote("deregisterPrefix", prefix)85 """ 86 A PB client factory that knows how to log into a Porter. 87 Lives in streaming components, and accepts FDs passed over this connection. 88 """ 8912591 """ 92 Create a PorterClientFactory that will use childFactory to create 93 protocol instances for clients attached to the FDs received over this 94 connection. 95 """ 96 fpb.ReconnectingPBClientFactory.__init__(self) 97 98 self.medium = PorterMedium() 99 100 self.protocol = fdserver.FDPassingBroker 101 self._childFactory = childFactory102 107 110 113 116 119 122162128 """ 129 @param mountPoints: a list of mountPoint strings that should be 130 registered to the porter 131 """ 132 PorterClientFactory.__init__(self, childFactory) 133 self._mountPoints = mountPoints 134 self._prefixes = prefixes 135 self._do_start_deferred = do_start_deferred136138 # If we still have the deferred, fire it (this happens after we've 139 # completed log in the _first_ time, not subsequent times) 140 if self._do_start_deferred: 141 self.debug("Firing initial deferred: should indicate that login is " 142 "complete") 143 self._do_start_deferred.callback(None) 144 self._do_start_deferred = None145147 # This is called when we start logging in to give us the deferred for 148 # the login process. Once we're logged in, we want to set our 149 # remote ref, then register our path with the porter, then (possibly) 150 # fire a different deferred 151 self.debug("Got deferred login, adding callbacks") 152 deferred.addCallback(self.medium.setRemoteReference) 153 for mount in self._mountPoints: 154 self.debug("Registering mount point %s with porter", mount) 155 deferred.addCallback(lambda r,m: self.registerPath(m), 156 mount) 157 for mount in self._prefixes: 158 self.debug("Registering mount prefix %s with porter", mount) 159 deferred.addCallback(lambda r,m: self.registerPrefix(m), 160 mount) 161 deferred.addCallback(self._fireDeferred)
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Aug 7 15:02:55 2008 | http://epydoc.sourceforge.net |