Ejemplo n.º 1
0
    def __init__(self, service, host, port, key='pylabnet.pem'):
        """ Instantiates a server

        :param service: ServiceBase instance to assign to server
        :param host: (str) name of host (can use 'localhost' for local connections)
        :param port: (int) port number to use - must be unique
        :param key: (str, optional) name of key file stored in C:/Windows/System32/ (for windows, /etc/ssl/certs for linux)
            for authentication purposes. If None, a standard server (without secure
            authentication) will be used
        """

        self.operating_system = get_os()
        if key is None:

            # start a server without any authentication
            self._server = rpyc.ThreadedServer(service=service,
                                               hostname=host,
                                               port=port,
                                               protocol_config={
                                                   'allow_public_attrs': True,
                                                   'sync_request_timeout': 300
                                               })

        else:

            # identify key
            if self.operating_system == "Windows":
                key = os.path.join(os.environ['WINDIR'], 'System32', key)
            elif self.operating_system == "Linux":
                key = os.path.join('/etc/ssl/certs', 'pylabnet.pem')

            if os.path.exists(key):

                # Add SSL authentication
                self._server = rpyc.ThreadedServer(
                    service=service,
                    hostname=host,
                    port=port,
                    protocol_config={
                        'allow_public_attrs': True,
                        'sync_request_timeout': 300
                    },
                    authenticator=rpyc.utils.authenticators.SSLAuthenticator(
                        key, key))

            else:
                msg_str = f'No keyfile found, please check that {key} exists.'
                print(msg_str)
                time.sleep(10)
                raise FileNotFoundError(msg_str)

        self._server_thread = threading.Thread(target=self._start_server,
                                               args=(self._server, ))
Ejemplo n.º 2
0
def run_device_service(port=18812, verbose=False):
    """Start :class:`DeviceService` at the given port"""
    if verbose:
        hostips = net.get_all_local_addr()
        hostnames = net.get_local_hostname(full=False), net.get_local_hostname(
            full=True)
        hostips_list = ", ".join(["{}:{}".format(ip, port) for ip in hostips])
        print("Running device service at {} ({}), IP {}".format(
            hostnames[0], hostnames[1], hostips_list))
    rpyc.ThreadedServer(rpyc.utils.helpers.classpartial(DeviceService,
                                                        verbose=verbose),
                        port=port).start()
Ejemplo n.º 3
0
    def __init__(self, service, port, host='localhost'):

        self._server = rpyc.ThreadedServer(
            service=service,
            hostname=host,
            port=port,
            protocol_config={
                'allow_public_attrs': True,
                'sync_request_timeout': 300
            }
        )

        self._server_thread = threading.Thread(
            target=self._start_server,
            args=(self._server,)
        )
Ejemplo n.º 4
0
from Backend.Testing.rpyc.ABexample.Node import NodeService
import rpyc

serverA = rpyc.ThreadedServer(NodeService("node A"), port=5555)
serverA.start()
Ejemplo n.º 5
0
from Backend.Testing.rpyc.ABexample.Node import NodeService
import rpyc

serverB = rpyc.ThreadedServer(NodeService("node B"), port=5556)
serverB.start()
Ejemplo n.º 6
0
def run_device_service(port=18812, verbose=False):
    """Start :class:`DeviceService` at the given port"""
    rpyc.ThreadedServer(rpyc.utils.helpers.classpartial(DeviceService,
                                                        verbose=verbose),
                        port=port).start()
Ejemplo n.º 7
0
import gdb
import rpyc


class GDBService(rpyc.Service):
    def exposed_get(self):
        return gdb

    def exposed_quit(self):
        gdb.execute('quit')


if __name__ == "__main__":
    server = rpyc.ThreadedServer(GDBService, port=0, protocol_config={'allow_all_attrs': True})
    gdb.write('{}\n'.format(server.port))
    gdb.flush()
    server.start()
Ejemplo n.º 8
0

class SharingService(rpyc.Service):
    """ A class that allows for sharing components between connection instances """
    __shared__ = SharingComponent()

    @property
    def shared(self):
        """ convenient access to an otherwise long object name """
        return SharingService.__shared__

    def exposed_echo(self, message):
        """ example of the potential perils when threading shared state """
        if THREAD_SAFE:
            seq_id = self.shared.get_sequence_id()
        else:
            seq_id = self.shared.sleepy_sequence_id()
        if message == "Echo":
            return f"Echo Reply {seq_id}"
        else:
            return f"Parameter Problem {seq_id}"


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    debugging_config = {'allow_all_attrs': True, 'sync_request_timeout': None}
    echo_svc = rpyc.ThreadedServer(service=SharingService,
                                   port=18861,
                                   protocol_config=debugging_config)
    echo_svc.start()
Ejemplo n.º 9
0
Archivo: replica.py Proyecto: guiazv/SD
        self.is_primary = False
        return True

    def exposed_update(self, primary_id, value):
        self.x = value
        self.updates.append((primary_id, value))


if __name__ == "__main__":
    if len(sys.argv) < 2:
        exit("Faltando parâmetro do identificador")
    id = int(sys.argv[1])

    replica = Replica(id)
    (host, port) = replica.replicas[id]
    server = rpyc.ThreadedServer(replica, hostname=host, port=port)

    server_thread = threading.Thread(target=server.start)
    server_thread.start()

    print(f'Réplica {replica.id} executando...')

    print("Digite 'read' para ler o valor atual da réplica, 'history' para ver o histórico de alterações na réplica, 'write' para alterar o valor ou 'exit' para sair")
    while True:
        command = input()
        command.strip()
        if command == 'read':
            replica.read()
        elif command == 'history':
            replica.history()
        elif command == 'write':
Ejemplo n.º 10
0
import rpyc

class MyService(rpyc.Service):
    # def on_connect(self, conn):
    #     pass
    #
    # def on_disconnect(self, conn):
    #     pass

    def exposed_get_answer(self):
        return 42

    def exposed_hey_there(self):
        print("calling from inside", self.exposed_get_answer())
        return "hi there!"

    exposed_x = 5

t = rpyc.ThreadedServer(MyService, port=18861)
t.start()