def enter(self, dummy):
        """ Implementation of State virtual.

            This checks the graph against the local repository and
            adds edges required to update it to the TARGET_VERSION
            specified in the context object. Then it starts inserting
            CHKS for the new edges into Freenet, doing padding /
            metadata salting as required.

        """
        #require_state(from_state, QUIESCENT)
        assert (self.parent.ctx.get('REINSERT', 0) > 0 or
                (not self.parent.ctx['INSERT_URI'] is None))
        assert not self.parent.ctx.graph is None

        graph = self.parent.ctx.graph.clone()
        if self.parent.params.get('DUMP_GRAPH', False):
            self.parent.ctx.ui_.status("--- Initial Graph ---\n")
            self.parent.ctx.ui_.status(graph_to_string(graph) +'\n')

        latest_revs = get_heads(graph)

        self.parent.ctx.ui_.status("Latest heads(s) in Freenet: %s\n"
                                 % ' '.join([ver[:12] for ver in latest_revs]))

        if self.parent.ctx.get('REINSERT', 0) == 1:
            self.parent.ctx.ui_.status("No bundles to reinsert.\n")
            # REDFLAG: Think this through. Crappy code, but expedient.
            # Hmmmm.... need version table to build minimal graph
            self.parent.ctx.version_table = build_version_table(graph,
                                                                self.parent.ctx.
                                                                repo)
            self.parent.transition(INSERTING_GRAPH)
            return

        if not self.parent.ctx.has_versions(latest_revs):
            self.parent.ctx.ui_.warn("The local repository isn't up "
                                     + "to date.\n"
                                     + "Try doing an fn-pull.\n")
            self.parent.transition(FAILING) # Hmmm... hard coded state name
            return

        # Update graph.
        try:
            self.set_new_edges(graph)
        except UpToDate, err:
            # REDFLAG: Later, add FORCE_INSERT parameter?
            # REDFLAG: rework UpToDate exception to include versions, stuff
            #      versions in  ctx?
            self.parent.ctx['UP_TO_DATE'] = True
            self.parent.ctx.ui_.warn(str(err) + '\n') # Hmmm
            self.parent.transition(FAILING) # Hmmm... hard coded state name
            return
Exemple #2
0
def read_freenet_heads(params, update_sm, request_uri):
    """ Helper function reads the know heads from Freenet. """
    update_sm.start_requesting_heads(request_uri)
    run_until_quiescent(update_sm, params['POLL_SECS'], False)
    if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING, ))):
        if update_sm.ctx.graph is None:
            # Heads are in the top key.
            top_key_tuple = update_sm.get_state(REQUIRES_GRAPH_4_HEADS).\
                            get_top_key_tuple()
            assert top_key_tuple[1][0][5]  # heads list complete
            return top_key_tuple[1][0][2]  # stored in first update

        else:
            # Have to pull the heads from the graph.
            assert not update_sm.ctx.graph is None
            return get_heads(update_sm.ctx.graph)

    raise util.Abort("Couldn't read heads from Freenet.")
Exemple #3
0
def read_freenet_heads(params, update_sm, request_uri):
    """ Helper function reads the know heads from Freenet. """
    update_sm.start_requesting_heads(request_uri)
    run_until_quiescent(update_sm, params['POLL_SECS'], False)
    if update_sm.get_state(QUIESCENT).arrived_from(((FINISHING,))):
        if update_sm.ctx.graph is None:
            # Heads are in the top key.
            top_key_tuple = update_sm.get_state(REQUIRES_GRAPH_4_HEADS).\
                            get_top_key_tuple()
            assert top_key_tuple[1][0][5] # heads list complete
            return top_key_tuple[1][0][2] # stored in first update

        else:
            # Have to pull the heads from the graph.
            assert not update_sm.ctx.graph is None
            return get_heads(update_sm.ctx.graph)

    raise util.Abort("Couldn't read heads from Freenet.")
    def _set_graph(self, graph):
        """ INTERNAL: Set the graph and fixup any pending CHK edge
            requests with their edges.  """

        edges = chk_to_edge_triple_map(graph)

        skip_chks = set([]) # REDFLAG: remove!
        for request in self.pending.values():
            candidate = request.candidate
            if candidate[6]:
                continue
            edge = edges[candidate[0]]
            candidate[3] = edge
            candidate[4] = None
            #print "_set_graph -- fixed up: ", request.tag, edge
            # REDFLAG: why am I keeping state in two places?
            old_tag = request.tag
            request.tag = edge
            del self.pending[old_tag]
            self.pending[request.tag] = request
            skip_chks.add(candidate[0])

        #print "pending.keys(): ", self.pending.keys()

        fixup(edges, self.current_candidates)
        fixup(edges, self.next_candidates)
        fixup(edges, self.finished_candidates)

        assert not self.top_key_tuple is None
        if self.parent.params.get('DUMP_TOP_KEY', False):
            text = "Fixed up top key CHKs:\n"
            for update in self.top_key_tuple[1]:
                for chk in update[3]:
                    if chk in edges:
                        text += "   " + str(edges[chk]) + ":" + chk + "\n"
                    else:
                        text += "   BAD TOP KEY DATA!" + ":" + chk + "\n"
            self.parent.ctx.ui_.status(text)

        all_heads = get_heads(graph)

        assert (self.freenet_heads is None or
                self.freenet_heads == all_heads)
        self.freenet_heads = all_heads
        self.parent.ctx.graph = graph

        self.rep_invariant()

        # REDFLAG: remove testing code
        #kill_prob = 0.00
        #print "BREAKING EDGES: Pkill==", kill_prob
        #print skip_chks
        #break_edges(graph, kill_prob, skip_chks)

        # "fix" (i.e. break) pending good chks.
        # REDFLAG: comment this out too?
        for candidate in self.current_candidates + self.next_candidates:
            if candidate[6]:
                continue
            edge = candidate[3]
            assert not edge is None
            if graph.get_chk(edge).find("badrouting") != -1:
                candidate[0] = graph.get_chk(edge)

        #self.dump()
        self.rep_invariant()

        self.parent.ctx.ui_.status("Got graph. Latest graph index: %i\n" %
                                   graph.latest_index)
Exemple #5
0
    def _set_graph(self, graph):
        """ INTERNAL: Set the graph and fixup any pending CHK edge
            requests with their edges.  """

        edges = chk_to_edge_triple_map(graph)

        skip_chks = set([])  # REDFLAG: remove!
        for request in self.pending.values():
            candidate = request.candidate
            if candidate[6]:
                continue
            edge = edges[candidate[0]]
            candidate[3] = edge
            candidate[4] = None
            #print "_set_graph -- fixed up: ", request.tag, edge
            # REDFLAG: why am I keeping state in two places?
            old_tag = request.tag
            request.tag = edge
            del self.pending[old_tag]
            self.pending[request.tag] = request
            skip_chks.add(candidate[0])

        #print "pending.keys(): ", self.pending.keys()

        fixup(edges, self.current_candidates)
        fixup(edges, self.next_candidates)
        fixup(edges, self.finished_candidates)

        assert not self.top_key_tuple is None
        if self.parent.params.get('DUMP_TOP_KEY', False):
            text = "Fixed up top key CHKs:\n"
            for update in self.top_key_tuple[1]:
                for chk in update[3]:
                    if chk in edges:
                        text += "   " + str(edges[chk]) + ":" + chk + "\n"
                    else:
                        text += "   BAD TOP KEY DATA!" + ":" + chk + "\n"
            self.parent.ctx.ui_.status(text)

        all_heads = get_heads(graph)

        assert (self.freenet_heads is None or self.freenet_heads == all_heads)
        self.freenet_heads = all_heads
        self.parent.ctx.graph = graph

        self.rep_invariant()

        # REDFLAG: remove testing code
        #kill_prob = 0.00
        #print "BREAKING EDGES: Pkill==", kill_prob
        #print skip_chks
        #break_edges(graph, kill_prob, skip_chks)

        # "fix" (i.e. break) pending good chks.
        # REDFLAG: comment this out too?
        for candidate in self.current_candidates + self.next_candidates:
            if candidate[6]:
                continue
            edge = candidate[3]
            assert not edge is None
            if graph.get_chk(edge).find("badrouting") != -1:
                candidate[0] = graph.get_chk(edge)

        #self.dump()
        self.rep_invariant()

        self.parent.ctx.ui_.status("Got graph. Latest graph index: %i\n" %
                                   graph.latest_index)