def post(self): """Add the node specified in POSTed JSON to the list of known nodes.""" uuid = self.get_json_argument('uuid') if (Node.me().supernode and self.get_json_argument( 'primary_supernode_uuid', '') == Node.me().uuid): children_count = Node.query.filter_by(primary_supernode=Node.me() ).count() if children_count > settings.SUPERNODE_MAX_CHILDREN: raise HTTPError(503) if not Node.get_by(uuid=uuid): # TODO what if supernode changes? need to update self.request.arguments.setdefault('ip_address', self.request.remote_ip) Node.from_dict(self.request.arguments) session.commit()
"the node from the database", node, stream) log.debug("Node returned: %s", e) node.delete() except RequestFailed, e: if e.response.status_int == 412: log.debug("%s didn't have room to forward %s to us", node, stream) else: if existing_ticket: return existing_ticket if ticket_data: source = Node.get_by(uuid=ticket_data['source']) if not source: source_node_data = NodesAPI(node.uri()).get( Node.absolute_url(source)) source = Node.from_dict(source_node_data) return Ticket(stream=stream, source=source, source_port=ticket_data['source_port'], destination=destination, hops=ticket_data['hops'] + 1) @classmethod def _request_stream_from_watchers(cls, stream, destination, unconfirmed_tickets=None): tickets = [] for ticket in Ticket.query.filter_by(stream=stream): if cls._already_seeding(ticket): return [ticket]
def load_static_bootstrap_nodes(self): log.info("Loading static bootstrap nodes %s", settings.BOOTSTRAP_NODES) nodes = [Node.from_dict(node) for node in settings.BOOTSTRAP_NODES] session.commit() log.debug("Loaded static bootstrap nodes %s", nodes)
def load_dynamic_bootstrap_nodes(self, base_url=None): base_url = base_url or settings.ASTRAL_WEBSERVER try: nodes = NodesAPI(base_url).list() except RequestError, e: log.warning("Can't connect to server: %s", e) else: log.debug("Nodes returned from the server: %s", nodes) for node in nodes: if self.node().conflicts_with(node): log.warn("Received %s which conflicts with us (%s) " "-- 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 load_static_bootstrap_nodes(self): log.info("Loading static bootstrap nodes %s", settings.BOOTSTRAP_NODES) nodes = [Node.from_dict(node) for node in settings.BOOTSTRAP_NODES] session.commit() log.debug("Loaded static bootstrap nodes %s", nodes)
def load_dynamic_bootstrap_nodes(self, base_url=None): base_url = base_url or settings.ASTRAL_WEBSERVER try: nodes = NodesAPI(base_url).list() except RequestError, e: log.warning("Can't connect to server: %s", e) else: log.debug("Nodes returned from the server: %s", nodes) for node in nodes: if self.node().conflicts_with(node): log.warn( "Received %s which conflicts with us (%s) " "-- 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()
"the node from the database", node, stream) log.debug("Node returned: %s", e) node.delete() except RequestFailed, e: if e.response.status_int == 412: log.debug("%s didn't have room to forward %s to us", node, stream) else: if existing_ticket: return existing_ticket if ticket_data: source = Node.get_by(uuid=ticket_data['source']) if not source: source_node_data = NodesAPI(node.uri()).get( Node.absolute_url(source)) source = Node.from_dict(source_node_data) return Ticket(stream=stream, source=source, source_port=ticket_data['source_port'], destination=destination, hops=ticket_data['hops'] + 1) @classmethod def _request_stream_from_watchers(cls, stream, destination, unconfirmed_tickets=None): tickets = [] for ticket in Ticket.query.filter_by(stream=stream): if cls._already_seeding(ticket): return [ticket] else: if not cls._already_ticketed(unconfirmed_tickets, ticket.destination):