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
15 #should be passed to threadedserver
16 #from sfa.plc.api import SfaAPI
19 # Implements an HTTPS XML-RPC server. Generally it is expected that SFA
20 # functions will take a credential string, which is passed to
21 # decode_authentication. Decode_authentication() will verify the validity of
22 # the credential, and verify that the user is using the key that matches the
23 # GID supplied in the credential.
25 class SfaServer(threading.Thread):
28 # Create a new SfaServer object.
30 # @param ip the ip address to listen on
31 # @param port the port to listen on
32 # @param key_file private key filename of registry
33 # @param cert_file certificate filename containing public key
34 # (could be a GID file)
36 def __init__(self, ip, port, key_file, cert_file,interface):
37 threading.Thread.__init__(self)
38 self.key = Keypair(filename = key_file)
39 self.cert = Certificate(filename = cert_file)
40 #self.server = SecureXMLRPCServer((ip, port), SecureXMLRpcRequestHandler, key_file, cert_file)
41 self.server = ThreadedServer((ip, port), SecureXMLRpcRequestHandler, key_file, cert_file)
42 self.server.interface=interface
43 self.trusted_cert_list = None
44 self.register_functions()
45 logger.info("Starting SfaServer, interface=%s"%interface)
48 # Register functions that will be served by the XMLRPC server. This
49 # function should be overridden by each descendant class.
51 def register_functions(self):
52 self.server.register_function(self.noop)
55 # Sample no-op server function. The no-op function decodes the credential
56 # that was passed to it.
58 def noop(self, cred, anything):
59 self.decode_authentication(cred)
63 # Execute the server, serving requests forever.
66 self.server.serve_forever()