Ejemplo n.º 1
0
    def render_service_row(self, ctx, server):
        nodeid = server.get_serverid()

        ctx.fillSlots("peerid", server.get_longname())
        ctx.fillSlots("nickname", server.get_nickname())
        rhost = server.get_remote_host()
        if server.is_connected():
            if nodeid == self.client.nodeid:
                rhost_s = "(loopback)"
            elif isinstance(rhost, address.IPv4Address):
                rhost_s = "%s:%d" % (rhost.host, rhost.port)
            else:
                rhost_s = str(rhost)
            addr = rhost_s
            service_connection_status = "yes"
            last_connect_time = server.get_last_connect_time()
            service_connection_status_rel_time = render_time_delta(
                last_connect_time, self.now_fn())
            service_connection_status_abs_time = render_time_attr(
                last_connect_time)
        else:
            addr = "N/A"
            service_connection_status = "no"
            last_loss_time = server.get_last_loss_time()
            service_connection_status_rel_time = render_time_delta(
                last_loss_time, self.now_fn())
            service_connection_status_abs_time = render_time_attr(
                last_loss_time)

        last_received_data_time = server.get_last_received_data_time()
        last_received_data_rel_time = render_time_delta(
            last_received_data_time, self.now_fn())
        last_received_data_abs_time = render_time_attr(last_received_data_time)

        announcement = server.get_announcement()
        version = announcement["my-version"]
        available_space = server.get_available_space()
        if available_space is None:
            available_space = "N/A"
        else:
            available_space = abbreviate_size(available_space)
        ctx.fillSlots("address", addr)
        ctx.fillSlots("service_connection_status", service_connection_status)
        ctx.fillSlots("service_connection_status_alt",
                      self._connectedalts[service_connection_status])
        ctx.fillSlots("connected-bool", bool(rhost))
        ctx.fillSlots("service_connection_status_abs_time",
                      service_connection_status_abs_time)
        ctx.fillSlots("service_connection_status_rel_time",
                      service_connection_status_rel_time)
        ctx.fillSlots("last_received_data_abs_time",
                      last_received_data_abs_time)
        ctx.fillSlots("last_received_data_rel_time",
                      last_received_data_rel_time)
        ctx.fillSlots("version", version)
        ctx.fillSlots("available_space", available_space)

        return ctx.tag
Ejemplo n.º 2
0
    def _describe_connection_status(self, cs):
        """Return a dict containing some connection stats."""
        others = cs.non_connected_statuses

        if cs.connected:
            summary = cs.summary
            if others:
                hints = "\n".join([
                    "* %s: %s\n" % (which, others[which])
                    for which in sorted(others)
                ])
                details = "Other hints:\n" + hints
            else:
                details = "(no other hints)"
        else:
            details = tags.ul()
            for which in sorted(others):
                details(tags.li("%s: %s" % (which, others[which])))
            summary = [cs.summary, details]

        connected = "yes" if cs.connected else "no"
        connected_alt = self._connectedalts[connected]

        since = cs.last_connection_time

        if since is not None:
            service_connection_status_rel_time = render_time_delta(
                since, self._now_fn())
            service_connection_status_abs_time = render_time_attr(since)
        else:
            service_connection_status_rel_time = "N/A"
            service_connection_status_abs_time = "N/A"

        last_received_data_time = cs.last_received_time

        if last_received_data_time is not None:
            last_received_data_abs_time = render_time_attr(
                last_received_data_time)
            last_received_data_rel_time = render_time_delta(
                last_received_data_time, self._now_fn())
        else:
            last_received_data_abs_time = "N/A"
            last_received_data_rel_time = "N/A"

        return {
            "summary": summary,
            "details": details,
            "service_connection_status": connected,
            "service_connection_status_alt": connected_alt,
            "service_connection_status_abs_time":
            service_connection_status_abs_time,
            "service_connection_status_rel_time":
            service_connection_status_rel_time,
            "last_received_data_abs_time": last_received_data_abs_time,
            "last_received_data_rel_time": last_received_data_rel_time,
        }
Ejemplo n.º 3
0
    def render_service_row(self, ctx, server):
        server_id = server.get_serverid()

        ctx.fillSlots("peerid", server.get_longname())
        ctx.fillSlots("nickname", server.get_nickname())
        rhost = server.get_remote_host()
        if server.is_connected():
            if server_id == self.client.get_long_nodeid():
                rhost_s = "(loopback)"
            elif isinstance(rhost, address.IPv4Address):
                rhost_s = "%s:%d" % (rhost.host, rhost.port)
            else:
                rhost_s = str(rhost)
            addr = rhost_s
            service_connection_status = "yes"
            last_connect_time = server.get_last_connect_time()
            service_connection_status_rel_time = render_time_delta(last_connect_time, self.now_fn())
            service_connection_status_abs_time = render_time_attr(last_connect_time)
        else:
            addr = "N/A"
            service_connection_status = "no"
            last_loss_time = server.get_last_loss_time()
            service_connection_status_rel_time = render_time_delta(last_loss_time, self.now_fn())
            service_connection_status_abs_time = render_time_attr(last_loss_time)

        last_received_data_time = server.get_last_received_data_time()
        last_received_data_rel_time = render_time_delta(last_received_data_time, self.now_fn())
        last_received_data_abs_time = render_time_attr(last_received_data_time)

        announcement = server.get_announcement()
        version = announcement.get("my-version", "")
        available_space = server.get_available_space()
        if available_space is None:
            available_space = "N/A"
        else:
            available_space = abbreviate_size(available_space)
        ctx.fillSlots("address", addr)
        ctx.fillSlots("service_connection_status", service_connection_status)
        ctx.fillSlots("service_connection_status_alt",
                      self._connectedalts[service_connection_status])
        ctx.fillSlots("service_connection_status_abs_time", service_connection_status_abs_time)
        ctx.fillSlots("service_connection_status_rel_time", service_connection_status_rel_time)
        ctx.fillSlots("last_received_data_abs_time", last_received_data_abs_time)
        ctx.fillSlots("last_received_data_rel_time", last_received_data_rel_time)
        ctx.fillSlots("version", version)
        ctx.fillSlots("available_space", available_space)

        return ctx.tag
Ejemplo n.º 4
0
    def _render_connection_status(self, ctx, cs):
        connected = "yes" if cs.connected else "no"
        ctx.fillSlots("service_connection_status", connected)
        ctx.fillSlots("service_connection_status_alt",
                      self._connectedalts[connected])

        since = cs.last_connection_time
        ctx.fillSlots("service_connection_status_rel_time",
                      render_time_delta(since, self.now_fn())
                      if since is not None
                      else "N/A")
        ctx.fillSlots("service_connection_status_abs_time",
                      render_time_attr(since)
                      if since is not None
                      else "N/A")

        last_received_data_time = cs.last_received_time
        ctx.fillSlots("last_received_data_abs_time",
                      render_time_attr(last_received_data_time)
                      if last_received_data_time is not None
                      else "N/A")
        ctx.fillSlots("last_received_data_rel_time",
                      render_time_delta(last_received_data_time, self.now_fn())
                      if last_received_data_time is not None
                      else "N/A")

        others = cs.non_connected_statuses
        if cs.connected:
            ctx.fillSlots("summary", cs.summary)
            if others:
                details = "\n".join(["* %s: %s\n" % (which, others[which])
                                     for which in sorted(others)])
                ctx.fillSlots("details", "Other hints:\n" + details)
            else:
                ctx.fillSlots("details", "(no other hints)")
        else:
            details = T.ul()
            for which in sorted(others):
                details[T.li["%s: %s" % (which, others[which])]]
            ctx.fillSlots("summary", [cs.summary, details])
            ctx.fillSlots("details", "")
Ejemplo n.º 5
0
    def _render_connection_status(self, ctx, cs):
        connected = "yes" if cs.connected else "no"
        ctx.fillSlots("service_connection_status", connected)
        ctx.fillSlots("service_connection_status_alt",
                      self._connectedalts[connected])

        since = cs.last_connection_time
        ctx.fillSlots("service_connection_status_rel_time",
                      render_time_delta(since, self.now_fn())
                      if since is not None
                      else "N/A")
        ctx.fillSlots("service_connection_status_abs_time",
                      render_time_attr(since)
                      if since is not None
                      else "N/A")

        last_received_data_time = cs.last_received_time
        ctx.fillSlots("last_received_data_abs_time",
                      render_time_attr(last_received_data_time)
                      if last_received_data_time is not None
                      else "N/A")
        ctx.fillSlots("last_received_data_rel_time",
                      render_time_delta(last_received_data_time, self.now_fn())
                      if last_received_data_time is not None
                      else "N/A")

        others = cs.non_connected_statuses
        if cs.connected:
            ctx.fillSlots("summary", cs.summary)
            if others:
                details = "\n".join(["* %s: %s\n" % (which, others[which])
                                     for which in sorted(others)])
                ctx.fillSlots("details", "Other hints:\n" + details)
            else:
                ctx.fillSlots("details", "(no other hints)")
        else:
            details = T.ul()
            for which in sorted(others):
                details[T.li["%s: %s" % (which, others[which])]]
            ctx.fillSlots("summary", [cs.summary, details])
            ctx.fillSlots("details", "")
Ejemplo n.º 6
0
    def render_introducers_row(self, ctx, s):
        (furl, connected, ic) = s
        service_connection_status = "yes" if connected else "no"

        since = ic.get_since()
        service_connection_status_rel_time = render_time_delta(since, self.now_fn())
        service_connection_status_abs_time = render_time_attr(since)

        last_received_data_time = ic.get_last_received_data_time()
        last_received_data_rel_time = render_time_delta(last_received_data_time, self.now_fn())
        last_received_data_abs_time = render_time_attr(last_received_data_time)

        ctx.fillSlots("introducer_furl", "%s" % (furl))
        ctx.fillSlots("service_connection_status", "%s" % (service_connection_status,))
        ctx.fillSlots("service_connection_status_alt",
            self._connectedalts[service_connection_status])
        ctx.fillSlots("service_connection_status_abs_time", service_connection_status_abs_time)
        ctx.fillSlots("service_connection_status_rel_time", service_connection_status_rel_time)
        ctx.fillSlots("last_received_data_abs_time", last_received_data_abs_time)
        ctx.fillSlots("last_received_data_rel_time", last_received_data_rel_time)
        return ctx.tag