Ejemplo n.º 1
0
    def _load_ticket(self, stream_slug, destination_uuid):
        stream = Stream.get_by(slug=stream_slug)
        if not destination_uuid:
            return Ticket.get_by(stream=stream, destination=Node.me())

        node = Node.get_by(uuid=destination_uuid)
        return Ticket.query.filter_by(stream=stream, destination=node).first()
Ejemplo n.º 2
0
    def _load_ticket(self, stream_slug, destination_uuid):
        stream = Stream.get_by(slug=stream_slug)
        if not destination_uuid:
            return Ticket.get_by(stream=stream, destination=Node.me())

        node = Node.get_by(uuid=destination_uuid)
        return Ticket.query.filter_by(stream=stream, destination=node).first()
Ejemplo n.º 3
0
 def test_delete(self):
     node = Node.me()
     ticket = TicketFactory(destination=node)
     self.http_client.fetch(HTTPRequest(
         self.get_url(ticket.absolute_url()), 'DELETE'), self.stop)
     response = self.wait()
     eq_(response.code, 200)
     eq_(Ticket.get_by(id=ticket.id), None)
     ok_(Stream.get_by(slug=ticket.stream.slug))
Ejemplo n.º 4
0
 def test_get_tickets(self):
     response = self.fetch("/tickets")
     eq_(response.code, 200)
     result = json.loads(response.body)
     ok_("tickets" in result)
     eq_(len(result["tickets"]), 3)
     for ticket in result["tickets"]:
         source = Node.get_by(uuid=ticket["source"])
         destination = Node.get_by(uuid=ticket["destination"])
         ok_(Ticket.get_by(stream=Stream.get_by(slug=ticket["stream"]), source=source, destination=destination))
Ejemplo n.º 5
0
 def test_delete(self):
     node = Node.me()
     ticket = TicketFactory(destination=node)
     self.http_client.fetch(
         HTTPRequest(self.get_url(ticket.absolute_url()), 'DELETE'),
         self.stop)
     response = self.wait()
     eq_(response.code, 200)
     eq_(Ticket.get_by(id=ticket.id), None)
     ok_(Stream.get_by(slug=ticket.stream.slug))
Ejemplo n.º 6
0
 def _handle_ticket(self, ticket):
     # reload to get a new database session
     ticket = Ticket.get_by(id=ticket.id)
     if ticket.source == Node.me():
         source_ip = "127.0.0.1"
     else:
         source_ip = ticket.source.ip_address
     try:
         port = self.create_tunnel(ticket.id, source_ip, ticket.source_port,
                                   self.tunnels)
     except Exception, e:
         log.warning("Couldn't create a tunnel for %s: %s", ticket, e)
Ejemplo n.º 7
0
 def _handle_ticket(self, ticket):
     # reload to get a new database session
     ticket = Ticket.get_by(id=ticket.id)
     if ticket.source == Node.me():
         source_ip = "127.0.0.1"
     else:
         source_ip = ticket.source.ip_address
     try:
         port = self.create_tunnel(ticket.id, source_ip,
                 ticket.source_port, self.tunnels)
     except Exception, e:
         log.warning("Couldn't create a tunnel for %s: %s",
                 ticket, e)
Ejemplo n.º 8
0
    def _offer_ourselves(cls, stream, destination):
        tickets = Ticket.query.filter_by(source=Node.me())
        if (tickets.count() >= settings.OUTGOING_STREAM_LIMIT
                or Node.me().upstream and tickets.count()
                    * settings.STREAM_BITRATE > Node.me().upstream):
            log.info("Can't stream %s to %s, already at limit", stream,
                    destination)
            raise HTTPError(412)

        ticket = Ticket.get_by(stream=stream, destination=Node.me())
        if ticket:
            new_ticket = Ticket(stream=stream, destination=destination,
                    source_port=ticket.source_port, hops=ticket.hops + 1)
            log.info("We are receiving %s and have room to forward -- "
                "created %s to potentially forward to %s", stream, new_ticket,
                destination)
            return new_ticket
Ejemplo n.º 9
0
    def _offer_ourselves(cls, stream, destination):
        tickets = Ticket.query.filter_by(source=Node.me())
        if (tickets.count() >= settings.OUTGOING_STREAM_LIMIT
                or Node.me().upstream and tickets.count() *
                settings.STREAM_BITRATE > Node.me().upstream):
            log.info("Can't stream %s to %s, already at limit", stream,
                     destination)
            raise HTTPError(412)

        ticket = Ticket.get_by(stream=stream, destination=Node.me())
        if ticket:
            new_ticket = Ticket(stream=stream,
                                destination=destination,
                                source_port=ticket.source_port,
                                hops=ticket.hops + 1)
            log.info(
                "We are receiving %s and have room to forward -- "
                "created %s to potentially forward to %s", stream, new_ticket,
                destination)
            return new_ticket
Ejemplo n.º 10
0
 def close_expired_tunnels(self):
     for ticket_id, tunnel in self.tunnels.items():
         if not Ticket.get_by(id=ticket_id):
             self.destroy_tunnel(ticket_id, self.tunnels)
Ejemplo n.º 11
0
 def _already_streaming(cls, stream, destination):
     return Ticket.get_by(stream=stream, destination=destination)
Ejemplo n.º 12
0
 def close_expired_tunnels(self):
     for ticket_id, tunnel in self.tunnels.items():
         if not Ticket.get_by(id=ticket_id):
             self.destroy_tunnel(ticket_id, self.tunnels)
Ejemplo n.º 13
0
 def _already_streaming(cls, stream, destination):
     return Ticket.get_by(stream=stream, destination=destination)