from allmydata import interfaces, uri, webish, dirnode
from allmydata.storage.shares import get_share_file
-from allmydata.storage_client import StorageFarmBroker
+from allmydata.storage_client import StorageFarmBroker, StubServer
from allmydata.immutable import upload
from allmydata.immutable.downloader.status import DownloadStatus
from allmydata.dirnode import DirectoryNode
def get_helper_info(self):
return (None, False)
-class FakeIServer:
- def __init__(self, binaryserverid):
- self.binaryserverid = binaryserverid
- def get_name(self): return "short"
- def get_longname(self): return "long"
- def get_serverid(self): return self.binaryserverid
-
def build_one_ds():
ds = DownloadStatus("storage_index", 1234)
now = time.time()
- serverA = FakeIServer(hashutil.tagged_hash("foo", "serverid_a")[:20])
- serverB = FakeIServer(hashutil.tagged_hash("foo", "serverid_b")[:20])
+ serverA = StubServer(hashutil.tagged_hash("foo", "serverid_a")[:20])
+ serverB = StubServer(hashutil.tagged_hash("foo", "serverid_b")[:20])
storage_index = hashutil.storage_index_hash("SI")
e0 = ds.add_segment_request(0, now)
e0.activate(now+0.5)
cmpu_id = base32.b2a(hashutil.tagged_hash("foo", "serverid_b")[:20])
# serverids[] keys are strings, since that's what JSON does, but
# we'd really like them to be ints
- self.failUnlessEqual(data["serverids"]["0"], "phwr")
- self.failUnless(data["serverids"].has_key("1"), data["serverids"])
- self.failUnlessEqual(data["serverids"]["1"], "cmpu", data["serverids"])
- self.failUnlessEqual(data["server_info"][phwr_id]["short"], "phwr")
- self.failUnlessEqual(data["server_info"][cmpu_id]["short"], "cmpu")
+ self.failUnlessEqual(data["serverids"]["0"], "phwrsjte")
+ self.failUnless(data["serverids"].has_key("1"),
+ str(data["serverids"]))
+ self.failUnlessEqual(data["serverids"]["1"], "cmpuvkjm",
+ str(data["serverids"]))
+ self.failUnlessEqual(data["server_info"][phwr_id]["short"],
+ "phwrsjte")
+ self.failUnlessEqual(data["server_info"][cmpu_id]["short"],
+ "cmpuvkjm")
self.failUnlessIn("dyhb", data)
self.failUnlessIn("misc", data)
d.addCallback(_check_dl_json)
for ev in events:
ev = ev.copy()
if ev.has_key('server'):
- ev["serverid"] = base32.b2a(ev["server"].get_serverid())
+ ev["serverid"] = ev["server"].get_longname()
del ev["server"]
# find an empty slot in the rows
free_slot = None
for ev in events:
# DownloadStatus promises to give us events in temporal order
ev = ev.copy()
- ev["serverid"] = base32.b2a(ev["server"].get_serverid())
+ ev["serverid"] = ev["server"].get_longname()
del ev["server"]
if ev["serverid"] not in serverid_to_group:
groupnum = len(serverid_to_group)
"start_time", "finish_time")
data["block"],data["block_rownums"] = self._find_overlap_requests(ds.block_requests)
- servernums = {}
- serverid_strings = {}
- for d_ev in data["dyhb"]:
- if d_ev["serverid"] not in servernums:
- servernum = len(servernums)
- servernums[d_ev["serverid"]] = servernum
- #title= "%s: %s" % ( ",".join([str(shnum) for shnum in shnums]))
- serverid_strings[servernum] = d_ev["serverid"][:4]
- data["server_info"] = dict([(serverid, {"num": servernums[serverid],
- "color": self.color(base32.a2b(serverid)),
- "short": serverid_strings[servernums[serverid]],
- })
- for serverid in servernums.keys()])
- data["num_serverids"] = len(serverid_strings)
+ server_info = {} # maps longname to {num,color,short}
+ server_shortnames = {} # maps servernum to shortname
+ for d_ev in ds.dyhb_requests:
+ s = d_ev["server"]
+ longname = s.get_longname()
+ if longname not in server_info:
+ num = len(server_info)
+ server_info[longname] = {"num": num,
+ "color": self.color(s),
+ "short": s.get_name() }
+ server_shortnames[str(num)] = s.get_name()
+
+ data["server_info"] = server_info
+ data["num_serverids"] = len(server_info)
# we'd prefer the keys of serverids[] to be ints, but this is JSON,
# so they get converted to strings. Stupid javascript.
- data["serverids"] = serverid_strings
+ data["serverids"] = server_shortnames
data["bounds"] = {"min": ds.first_timestamp, "max": ds.last_timestamp}
return simplejson.dumps(data, indent=1) + "\n"
rtt = received - sent
if not shnums:
shnums = ["-"]
- t[T.tr(style="background: %s" % self.color(server.get_serverid()))[
+ t[T.tr(style="background: %s" % self.color(server))[
[T.td[server.get_name()], T.td[srt(sent)], T.td[srt(received)],
T.td[",".join([str(shnum) for shnum in shnums])],
T.td[self.render_time(None, rtt)],
rtt = None
if r_ev["finish_time"] is not None:
rtt = r_ev["finish_time"] - r_ev["start_time"]
- color = self.color(server.get_serverid())
+ color = self.color(server)
t[T.tr(style="background: %s" % color)[
T.td[server.get_name()], T.td[r_ev["shnum"]],
T.td["[%d:+%d]" % (r_ev["start"], r_ev["length"])],
return l
- def color(self, peerid):
+ def color(self, server):
+ peerid = server.get_serverid() # binary
def m(c):
return min(ord(c) / 2 + 0x80, 0xff)
return "#%02x%02x%02x" % (m(peerid[0]), m(peerid[1]), m(peerid[2]))