def post(self): """Register a new available stream.""" # TODO kind of messy way to handle two different data types, but for # some reason Torando is loading the name and description as lists # instead of strings if they are form encded if not hasattr(self.request, 'arguments') or not self.request.arguments: self.load_json() else: self.request.arguments['name'] = self.request.arguments['name'][0] self.request.arguments['description'] = ( self.request.arguments.get('description', [''])[0]) self.request.arguments.setdefault('source', Node.me().uuid) if Stream.get_by(name=self.request.arguments['name']): self.redirect("%s/upload" % settings.ASTRAL_WEBSERVER) return stream = Stream.from_dict(self.request.arguments) try: StreamsAPI(settings.ASTRAL_WEBSERVER).create( source_uuid=stream.source.uuid, name=stream.name, slug=stream.slug, description=stream.description) except RequestError, e: log.warning("Unable to register stream with origin webserver: %s", e)
stream = Stream.get_by(slug=stream_slug) if not stream: try: log.debug( "Don't know of stream with slug %s, asking the " "origin", stream_slug) stream_data = StreamsAPI( settings.ASTRAL_WEBSERVER).find(stream_slug) except RequestError, e: log.warning("Can't connect to server: %s", e) except ResourceNotFound: log.debug("Origin didn't know of a stream with slug", stream_slug) raise HTTPError(404) else: stream = Stream.from_dict(stream_data) if not stream: log.debug("Couldnt find stream with slug %s anywhere", stream_slug) raise HTTPError(404) destination_uuid = self.get_json_argument('destination_uuid', '') if destination_uuid: destination = Node.get_by(uuid=destination_uuid) # TODO since we only have the IP, we have to assume the port is 8000 # to be able to request back to it for more details. hmm. # TODO another problem is that the tornado server is (and i should # have realized this sooner...) single-threaded, and based on the # event model. So the requsting node is blocked waiting for us to # responsed, then we go and query it. well, that's deadlock! a # workaroud since we're only dealing with single supernode # situations is just to query the supernode, since they MUST know # about that other node.
node, self.node()) NodesAPI(base_url).unregister(self.node().absolute_url()) else: node = Node.from_dict(node) log.info("Stored %s from %s", node, base_url) def load_streams(self, base_url=None): base_url = base_url or settings.ASTRAL_WEBSERVER try: streams = StreamsAPI(base_url).list() except RequestError, e: log.warning("Can't connect to server: %s", e) else: log.debug("Streams returned from the server: %s", streams) for stream in streams: stream = Stream.from_dict(stream) if stream: log.info("Stored %s from %s", stream, base_url) self.prime_stream_tunnels() def prime_stream_tunnels(self): for stream in Stream.query.filter(Stream.source == Node.me()): stream.queue_tunnel_status_flip() def register_with_origin(self): try: NodesAPI(settings.ASTRAL_WEBSERVER).register( self.node().to_dict()) except RequestError, e: log.warning("Can't connect to server to register as a " "supernode: %s", e)
"-- telling web server to kill it", node, self.node()) NodesAPI(base_url).unregister(self.node().absolute_url()) else: node = Node.from_dict(node) log.info("Stored %s from %s", node, base_url) def load_streams(self, base_url=None): base_url = base_url or settings.ASTRAL_WEBSERVER try: streams = StreamsAPI(base_url).list() except RequestError, e: log.warning("Can't connect to server: %s", e) else: log.debug("Streams returned from the server: %s", streams) for stream in streams: stream = Stream.from_dict(stream) if stream: log.info("Stored %s from %s", stream, base_url) self.prime_stream_tunnels() def prime_stream_tunnels(self): for stream in Stream.query.filter(Stream.source == Node.me()): stream.queue_tunnel_status_flip() def register_with_origin(self): try: NodesAPI(settings.ASTRAL_WEBSERVER).register(self.node().to_dict()) except RequestError, e: log.warning( "Can't connect to server to register as a " "supernode: %s", e)
the requesting node, and start doing so if it can.""" stream = Stream.get_by(slug=stream_slug) if not stream: try: log.debug("Don't know of stream with slug %s, asking the " "origin", stream_slug) stream_data = StreamsAPI(settings.ASTRAL_WEBSERVER).find( stream_slug) except RequestError, e: log.warning("Can't connect to server: %s", e) except ResourceNotFound: log.debug("Origin didn't know of a stream with slug", stream_slug) raise HTTPError(404) else: stream = Stream.from_dict(stream_data) if not stream: log.debug("Couldnt find stream with slug %s anywhere", stream_slug) raise HTTPError(404) destination_uuid = self.get_json_argument('destination_uuid', '') if destination_uuid: destination = Node.get_by(uuid=destination_uuid) # TODO since we only have the IP, we have to assume the port is 8000 # to be able to request back to it for more details. hmm. # TODO another problem is that the tornado server is (and i should # have realized this sooner...) single-threaded, and based on the # event model. So the requsting node is blocked waiting for us to # responsed, then we go and query it. well, that's deadlock! a # workaroud since we're only dealing with single supernode # situations is just to query the supernode, since they MUST know # about that other node.