2 # This module implements a general-purpose server layer for sfa.
3 # The same basic server should be usable on the registry, component, or
6 # TODO: investigate ways to combine this with existing PLC server?
11 from sfa.server.threadedserver import ThreadedServer, SecureXMLRpcRequestHandler
13 from sfa.util.sfalogging import logger
14 from sfa.trust.certificate import Keypair, Certificate
17 # Implements an HTTPS XML-RPC server. Generally it is expected that SFA
18 # functions will take a credential string, which is passed to
19 # decode_authentication. Decode_authentication() will verify the validity of
20 # the credential, and verify that the user is using the key that matches the
21 # GID supplied in the credential.
23 class SfaServer(threading.Thread):
26 # Create a new SfaServer object.
28 # @param ip the ip address to listen on
29 # @param port the port to listen on
30 # @param key_file private key filename of registry
31 # @param cert_file certificate filename containing public key
32 # (could be a GID file)
34 def __init__(self, ip, port, key_file, cert_file,interface):
35 threading.Thread.__init__(self)
36 self.key = Keypair(filename = key_file)
37 self.cert = Certificate(filename = cert_file)
38 #self.server = SecureXMLRPCServer((ip, port), SecureXMLRpcRequestHandler, key_file, cert_file)
39 self.server = ThreadedServer((ip, port), SecureXMLRpcRequestHandler, key_file, cert_file)
40 self.server.interface=interface
41 self.trusted_cert_list = None
42 self.register_functions()
43 logger.info("Starting SfaServer, interface=%s"%interface)
46 # Register functions that will be served by the XMLRPC server. This
47 # function should be overridden by each descendant class.
49 def register_functions(self):
50 self.server.register_function(self.noop)
53 # Sample no-op server function. The no-op function decodes the credential
54 # that was passed to it.
56 def noop(self, cred, anything):
60 # Execute the server, serving requests forever.
63 self.server.serve_forever()