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
35 """
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 """
40 - def __init__(self, sock, protocol, additionalData):
41 Connection.__init__(self, sock, protocol)
42
43
44 protocol.makeConnection(self)
45
46
47
48
49
50
51
52
53
54 self.startReading()
55 self.connected = 1
56
57 protocol.dataReceived(additionalData)
58
60 return address.IPv4Address('TCP', *(self.socket.getsockname() + ('INET',)))
61
63 return address.IPv4Address('TCP', *(self.socket.getpeername() + ('INET',)))
64
66 """
67 A medium we use to talk to the porter.
68 Mostly, we use this to say what mountpoints (or perhaps, later,
69 (hostname, mountpoint) pairs?) we expect to receive requests for.
70 """
73
76
78 return self.callRemote("registerPrefix", prefix)
79
81 return self.callRemote("deregisterPrefix", prefix)
82
84 """
85 A PB client factory that knows how to log into a Porter.
86 Lives in streaming components, and accepts FDs passed over this connection.
87 """
88
101
106
109
112
115
118
121
124
126 - def __init__(self, childFactory, mountPoints, do_start_deferred, prefixes=[]):
127 """
128 @param mountPoints: a list of mountPoint strings that should be
129 registered to the porter
130 """
131 PorterClientFactory.__init__(self, childFactory)
132 self._mountPoints = mountPoints
133 self._prefixes = prefixes
134 self._do_start_deferred = do_start_deferred
135
137
138
139 if self._do_start_deferred:
140 self.debug("Firing initial deferred: should indicate that login is "
141 "complete")
142 self._do_start_deferred.callback(None)
143 self._do_start_deferred = None
144
146
147
148
149
150 self.debug("Got deferred login, adding callbacks")
151 deferred.addCallback(self.medium.setRemoteReference)
152 for mount in self._mountPoints:
153 self.debug("Registering mount point %s with porter", mount)
154 deferred.addCallback(lambda r,m: self.registerPath(m),
155 mount)
156 for mount in self._prefixes:
157 self.debug("Registering mount prefix %s with porter", mount)
158 deferred.addCallback(lambda r,m: self.registerPrefix(m),
159 mount)
160 deferred.addCallback(self._fireDeferred)
161