Beispiel #1
0
 def __init__(self, reactor, cap_table, http_endpoint, ws_endpoint, root_cap, title):
     # Constants
     self.__http_endpoint_string = str(http_endpoint)
     self.__http_endpoint = endpoints.serverFromString(reactor, self.__http_endpoint_string)
     self.__ws_endpoint = endpoints.serverFromString(reactor, str(ws_endpoint))
     self.__visit_path = _make_cap_url(root_cap)
     
     wcommon = WebServiceCommon(
         reactor=reactor,
         title=title,
         ws_endpoint_string=ws_endpoint)
     # TODO: Create poller actually for the given reactor w/o redundancy -- perhaps there should be a one-poller-per-reactor map
     subscription_context = SubscriptionContext(reactor=reactor, poller=the_poller)
     
     def resource_factory(entry_point):
         # TODO: If not an IWebEntryPoint, return a generic result
         return IWebEntryPoint(entry_point).get_entry_point_resource(wcommon=wcommon)  # pylint: disable=redundant-keyword-arg
     
     server_root = CapAccessResource(cap_table=cap_table, resource_factory=resource_factory)
     _put_root_static(wcommon, server_root)
     
     if UNIQUE_PUBLIC_CAP in cap_table:
         # TODO: consider factoring out "generate URL for cap"
         server_root.putChild('', Redirect(_make_cap_url(UNIQUE_PUBLIC_CAP)))
         
     self.__ws_protocol = txws.WebSocketFactory(
         FactoryWithArgs.forProtocol(WebSocketDispatcherProtocol, cap_table, subscription_context))
     self.__site = SiteWithDefaultHeaders(server_root)
     
     self.__ws_port_obj = None
     self.__http_port_obj = None
Beispiel #2
0
 def __init__(self, reactor, cap_table, read_only_dbs, writable_db, http_endpoint, ws_endpoint, root_cap, title, flowgraph_for_debug):
     # Constants
     self.__http_endpoint_string = http_endpoint
     self.__http_endpoint = endpoints.serverFromString(reactor, http_endpoint)
     self.__ws_endpoint = endpoints.serverFromString(reactor, ws_endpoint)
     self.__visit_path = _make_cap_url(root_cap)
     
     wcommon = WebServiceCommon(ws_endpoint_string=ws_endpoint)
     
     def BoundSessionResource(session):
         return SessionResource(session, wcommon, reactor, title, read_only_dbs, writable_db, flowgraph_for_debug)
     
     server_root = CapAccessResource(cap_table=cap_table, resource_ctor=BoundSessionResource)
     _put_root_static(server_root)
     
     if UNIQUE_PUBLIC_CAP in cap_table:
         # TODO: consider factoring out "generate URL for cap"
         server_root.putChild('', Redirect(_make_cap_url(UNIQUE_PUBLIC_CAP)))
         
     self.__ws_protocol = txws.WebSocketFactory(
         FactoryWithArgs.forProtocol(OurStreamProtocol, cap_table))
     self.__site = _SiteWithHeaders(server_root)
     
     self.__ws_port_obj = None
     self.__http_port_obj = None
Beispiel #3
0
    def __init__(self, reactor, root_object, read_only_dbs, writable_db,
                 http_endpoint, ws_endpoint, root_cap, title,
                 flowgraph_for_debug):
        # Constants
        self.__http_port = http_endpoint
        self.__ws_port = ws_endpoint

        wcommon = WebServiceCommon(ws_endpoint=ws_endpoint)

        # Roots of resource trees
        # - app_root is everything stateful/authority-bearing
        # - server_root is the HTTP '/' and static resources are placed there
        server_root = Resource()
        if root_cap is None:
            app_root = server_root
            self.__visit_path = '/'
            ws_caps = {None: root_object}
        else:
            app_root = SlashedResource()
            server_root.putChild(root_cap, app_root)
            self.__visit_path = '/' + urllib.quote(root_cap, safe='') + '/'
            ws_caps = {root_cap: root_object}

        # Note: in the root_cap = None case, it matters that the session is done second as it overwrites the definition of /.
        _put_root_static(server_root)
        _put_session(app_root, root_object, wcommon, reactor, title,
                     read_only_dbs, writable_db, flowgraph_for_debug)

        self.__ws_protocol = txws.WebSocketFactory(
            FactoryWithArgs.forProtocol(OurStreamProtocol, ws_caps))
        self.__site = server.Site(server_root)

        self.__ws_port_obj = None
        self.__http_port_obj = None
Beispiel #4
0
 def __init__(self, reactor, root_object, note_dirty, read_only_dbs, writable_db, http_endpoint, ws_endpoint, root_cap, title, flowgraph_for_debug):
     self.__http_port = http_endpoint
     self.__ws_port = ws_endpoint
     
     wcommon = WebServiceCommon(note_dirty=note_dirty, ws_endpoint=ws_endpoint)
     
     # Roots of resource trees
     # - appRoot is everything stateful/authority-bearing
     # - serverRoot is the HTTP '/' and static resources are placed there
     serverRoot = _make_static(static_resource_path)
     if root_cap is None:
         appRoot = serverRoot
         self.__visit_path = '/'
         ws_caps = {None: root_object}
     else:
         serverRoot = _make_static(static_resource_path)
         appRoot = SlashedResource()
         serverRoot.putChild(root_cap, appRoot)
         self.__visit_path = '/' + urllib.quote(root_cap, safe='') + '/'
         ws_caps = {root_cap: root_object}
     
     self.__ws_protocol = txws.WebSocketFactory(
         FactoryWithArgs.forProtocol(OurStreamProtocol, ws_caps, note_dirty))
     
     # UI entry point
     appRoot.putChild('', _RadioIndexHtmlResource(wcommon=wcommon, title=title))
     
     # Exported radio control objects
     appRoot.putChild('radio', BlockResource(root_object, wcommon, not_deletable))
     
     # Frequency DB
     appRoot.putChild('dbs', shinysdr.i.db.DatabasesResource(read_only_dbs))
     appRoot.putChild('wdb', shinysdr.i.db.DatabaseResource(writable_db))
     
     # Debug graph
     appRoot.putChild('flow-graph', FlowgraphVizResource(reactor, flowgraph_for_debug))
     
     # Ephemeris
     appRoot.putChild('ephemeris', EphemerisResource())
     
     # Construct explicit resources for merge.
     test = _reify(serverRoot, 'test')
     jasmine = _reify(test, 'jasmine')
     for name in ['jasmine.css', 'jasmine.js', 'jasmine-html.js']:
         jasmine.putChild(name, static.File(os.path.join(
             deps_path, 'jasmine/lib/jasmine-core/', name)))
     
     client = _reify(serverRoot, 'client')
     client.putChild('require.js', static.File(os.path.join(deps_path, 'require.js')))
     client.putChild('text.js', static.File(os.path.join(deps_path, 'text.js')))
     
     _add_plugin_resources(client)
     
     self.__site = server.Site(serverRoot)
     self.__ws_port_obj = None
     self.__http_port_obj = None
Beispiel #5
0
    def __init__(self, reactor, cap_table, read_only_dbs, writable_db,
                 http_endpoint, ws_endpoint, root_cap, title,
                 flowgraph_for_debug):
        # Constants
        self.__http_endpoint_string = http_endpoint
        self.__http_endpoint = endpoints.serverFromString(
            reactor, http_endpoint)
        self.__ws_endpoint = endpoints.serverFromString(reactor, ws_endpoint)
        self.__visit_path = _make_cap_url(root_cap)

        wcommon = WebServiceCommon(ws_endpoint_string=ws_endpoint)
        # TODO: Create poller actually for the given reactor w/o redundancy -- perhaps there should be a one-poller-per-reactor map
        subscription_context = SubscriptionContext(reactor=reactor,
                                                   poller=the_poller)

        def BoundSessionResource(session):
            return SessionResource(session, wcommon, reactor, title,
                                   read_only_dbs, writable_db,
                                   flowgraph_for_debug)

        server_root = CapAccessResource(cap_table=cap_table,
                                        resource_ctor=BoundSessionResource)
        _put_root_static(server_root)

        if UNIQUE_PUBLIC_CAP in cap_table:
            # TODO: consider factoring out "generate URL for cap"
            server_root.putChild('',
                                 Redirect(_make_cap_url(UNIQUE_PUBLIC_CAP)))

        self.__ws_protocol = txws.WebSocketFactory(
            FactoryWithArgs.forProtocol(OurStreamProtocol, cap_table,
                                        subscription_context))
        self.__site = _SiteWithHeaders(server_root)

        self.__ws_port_obj = None
        self.__http_port_obj = None
Beispiel #6
0
parent_process = psutil.Process(os.getpid()).parent()


def check_parent():
    """ Checks if parent process is still alive, and exits if not """
    if not parent_process.is_running():
        print(
            "websocket/process bridge exiting because parent process is gone")
        reactor.stop()


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Starts websocket/process bridge.")
    parser.add_argument(
        "--port",
        type=str,
        dest="port",
        default="8191",
        help="Port for websocket/process bridge. Default 8191.",
    )
    args = parser.parse_args()

    parent_checker = LoopingCall(check_parent)
    parent_checker.start(1)

    bridgeFactory = ProcessSocketBridgeFactory()
    reactor.listenTCP(int(args.port), txws.WebSocketFactory(bridgeFactory))
    print("websocket/process bridge listening on port %s" % args.port)
    reactor.run()
Beispiel #7
0
    def __init__(self, reactor, top, note_dirty, read_only_dbs, writable_db,
                 http_endpoint, ws_endpoint, root_cap, title):
        self.__http_port = http_endpoint
        self.__ws_port = ws_endpoint

        self.__ws_protocol = txws.WebSocketFactory(
            OurStreamFactory(top, root_cap))

        # Roots of resource trees
        # - appRoot is everything stateful/authority-bearing
        # - serverRoot is the HTTP '/' and static resources are placed there
        serverRoot = _make_static(staticResourcePath)
        if root_cap is None:
            appRoot = serverRoot
            self.__visit_path = '/'
        else:
            serverRoot = _make_static(staticResourcePath)
            appRoot = _SlashedResource()
            serverRoot.putChild(root_cap, appRoot)
            self.__visit_path = '/' + urllib.quote(root_cap, safe='') + '/'

        # UI entry point
        appRoot.putChild('', _RadioIndexHtmlResource(title))

        # Exported radio control objects
        appRoot.putChild('radio', BlockResource(top, note_dirty, notDeletable))

        # Frequency DB
        appRoot.putChild('dbs', shinysdr.db.DatabasesResource(read_only_dbs))
        appRoot.putChild('wdb', shinysdr.db.DatabaseResource(writable_db))

        # Debug graph
        appRoot.putChild('flow-graph', FlowgraphVizResource(reactor, top))

        # Construct explicit resources for merge.
        test = _reify(serverRoot, 'test')
        jasmine = _reify(test, 'jasmine')
        for name in ['jasmine.css', 'jasmine.js', 'jasmine-html.js']:
            jasmine.putChild(
                name,
                static.File(
                    os.path.join(os.path.dirname(__file__),
                                 'deps/jasmine/lib/jasmine-core/', name)))

        client = _reify(serverRoot, 'client')
        client.putChild(
            'openlayers',
            static.File(
                os.path.join(os.path.dirname(__file__), 'deps/openlayers')))
        client.putChild(
            'require.js',
            static.File(
                os.path.join(os.path.dirname(__file__), 'deps/require.js')))

        # Plugin resources
        load_list_css = []
        load_list_js = []
        plugin_resources = Resource()
        client.putChild('plugins', plugin_resources)
        for resource_def in getPlugins(IClientResourceDef, shinysdr.plugins):
            # Add the plugin's resource to static serving
            plugin_resources.putChild(resource_def.key, resource_def.resource)
            plugin_resource_url = '/client/plugins/' + urllib.quote(
                resource_def.key, safe='') + '/'
            # Tell the client to load the plugins
            # TODO constrain path values to be relative
            if resource_def.load_css_path is not None:
                load_list_css.append(plugin_resource_url +
                                     resource_def.load_cs_path)
            if resource_def.load_js_path is not None:
                # TODO constrain value to be in the directory
                load_list_js.append(plugin_resource_url +
                                    resource_def.load_js_path)

        # Client plugin list
        client.putChild(
            'plugin-index.json',
            static.Data(
                _json_encoder_for_values.encode({
                    u'css': load_list_css,
                    u'js': load_list_js,
                }).encode('utf-8'), 'application/json'))

        self.__site = server.Site(serverRoot)
        self.__ws_port_obj = None
        self.__http_port_obj = None
Beispiel #8
0
        buf += struct.pack('x')
        buf += struct.pack('!H', 1)
        buf += struct.pack('H', x_pos)
        buf += struct.pack('!H', y_pos)
        buf += struct.pack('!H', img.size[0])
        buf += struct.pack('!H', img.size[1])
        buf += struct.pack('!i', 0)
        self.transport.write(buf)

        buf = img.tostring('raw', 'RGBX')
        print 'Image size:', len(buf)
        self.transport.write(buf)


class RFBFactory(Factory):
    protocol = RFBProtocol


txws.encoders = {
    "base64": b64encode,
    "binary, base64": b64encode,
}

txws.decoders = {
    "base64": b64decode,
    "binary, base64": b64decode,
}

port = listen("tcp:8080", txws.WebSocketFactory(RFBFactory()))
reactor.run()
Beispiel #9
0

class ProcessSocketBridgeFactory(protocol.Factory):
    """Builds sockets that can launch/bridge to a process"""
    def buildProtocol(self, addr):
        return SocketSide()


# Parent process could have already exited, so this is slightly racy. Only
# alternative is to set up a pipe between parent and child, but that requires
# special cooperation from the parent.
parent_process = psutil.Process(os.getpid()).parent()


def check_parent():
    """ Checks if parent process is still alive, and exits if not """
    if not parent_process.is_running():
        print(
            "websocket/process bridge exiting because parent process is gone")
        reactor.stop()


if __name__ == "__main__":
    parent_checker = LoopingCall(check_parent)
    parent_checker.start(1)

    bridgeFactory = ProcessSocketBridgeFactory()
    reactor.listenTCP(8191, txws.WebSocketFactory(bridgeFactory))
    print("websocket/process bridge listening on port 8191")
    reactor.run()