1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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 __version__ = "$Rev: 6125 $"
34
35
36
38 """
39 A connection class for use with passed FDs.
40 Similar to tcp.Server, but gets the initial FD from a different source,
41 obviously, and also passes along some data with the original connection.
42 """
43 - def __init__(self, sock, protocol, addr, additionalData):
44 Connection.__init__(self, sock, protocol)
45 self.client = addr
46
47
48 protocol.makeConnection(self)
49
50
51
52
53
54
55
56
57
58 self.startReading()
59 self.connected = 1
60
61 protocol.dataReceived(additionalData)
62
64 return address.IPv4Address('TCP', *(self.socket.getsockname() + ('INET',)))
65
67 return address.IPv4Address('TCP', *(self.client + ('INET',)))
68
70 """
71 A medium we use to talk to the porter.
72 Mostly, we use this to say what mountpoints (or perhaps, later,
73 (hostname, mountpoint) pairs?) we expect to receive requests for.
74 """
77
80
82 return self.callRemote("registerPrefix", prefix)
83
85 return self.callRemote("deregisterPrefix", prefix)
86
88 """
89 A PB client factory that knows how to log into a Porter.
90 Lives in streaming components, and accepts FDs passed over this connection.
91 """
92
105
110
113
116
119
122
125
128
130 - def __init__(self, childFactory, mountPoints, do_start_deferred,
131 prefixes=None):
132 """
133 @param mountPoints: a list of mountPoint strings that should be
134 registered to the porter
135 """
136 PorterClientFactory.__init__(self, childFactory)
137 self._mountPoints = mountPoints
138 self._prefixes = prefixes or []
139 self._do_start_deferred = do_start_deferred
140
142
143
144 if self._do_start_deferred:
145 self.debug("Firing initial deferred: should indicate that login is "
146 "complete")
147 self._do_start_deferred.callback(None)
148 self._do_start_deferred = None
149
151
152
153
154
155 self.debug("Got deferred login, adding callbacks")
156 deferred.addCallback(self.medium.setRemoteReference)
157 for mount in self._mountPoints:
158 self.debug("Registering mount point %s with porter", mount)
159 deferred.addCallback(lambda r,m: self.registerPath(m),
160 mount)
161 for mount in self._prefixes:
162 self.debug("Registering mount prefix %s with porter", mount)
163 deferred.addCallback(lambda r,m: self.registerPrefix(m),
164 mount)
165 deferred.addCallback(self._fireDeferred)
166