- Added debug code for dot output.

- Push/pop goals are counted now, making the child parameter obsolete.
This commit is contained in:
ccremers 2004-10-18 13:04:34 +00:00
parent 4b10c7f151
commit 94b3ac7c96
3 changed files with 79 additions and 51 deletions

View File

@ -67,6 +67,7 @@ typedef struct goalstruct Goal;
*/ */
int iterate (); int iterate ();
void printSemiState ();
/** /**
* Program code * Program code
@ -148,6 +149,15 @@ arachneDone ()
void void
indentPrint () indentPrint ()
{ {
if (sys->output == ATTACK && globalError == 0)
{
// Arachne, attack, not an error
// We assume that means DOT output
eprintf ("// ");
}
else
{
// If it is not to stdout, or it is not an attack...
int i; int i;
for (i = 0; i < indentDepth; i++) for (i = 0; i < indentDepth; i++)
@ -159,6 +169,7 @@ indentPrint ()
eprintf (" "); eprintf (" ");
} }
} }
}
//! Print indented binding //! Print indented binding
void void
@ -265,8 +276,7 @@ add_read_goals (const int run, const int old, const int new)
} }
termPrint (rd->message); termPrint (rd->message);
} }
goal_add (rd->message, run, i, 0); count = count + goal_add (rd->message, run, i, 0);
count++;
} }
rd = rd->next; rd = rd->next;
i++; i++;
@ -278,17 +288,6 @@ add_read_goals (const int run, const int old, const int new)
return count; return count;
} }
//! Remove n goals
void
remove_read_goals (int n)
{
while (n > 0)
{
goal_remove_last ();
n--;
}
}
//! Determine the run that follows from a substitution. //! Determine the run that follows from a substitution.
/** /**
* After an Arachne unification, stuff might go wrong w.r.t. nonce instantiation. * After an Arachne unification, stuff might go wrong w.r.t. nonce instantiation.
@ -529,7 +528,7 @@ bind_existing_to_goal (const Binding b, const int run, const int index)
*/ */
if (goal_bind (b, run, index)) if (goal_bind (b, run, index))
{ {
int keycount; int newgoals;
Termlist tl; Termlist tl;
proof_suppose_binding (b); proof_suppose_binding (b);
@ -541,7 +540,7 @@ bind_existing_to_goal (const Binding b, const int run, const int index)
termlistPrint (keylist); termlistPrint (keylist);
eprintf ("\n"); eprintf ("\n");
} }
keycount = 0; newgoals = 0;
tl = keylist; tl = keylist;
while (tl != NULL) while (tl != NULL)
{ {
@ -561,20 +560,15 @@ bind_existing_to_goal (const Binding b, const int run, const int index)
} }
} }
/* add the key as a goal */ /* add the key as a goal */
goal_add (tl->term, b->run_to, b->ev_to, prioritylevel); newgoals = newgoals + goal_add (tl->term, b->run_to, b->ev_to, prioritylevel);
tl = tl->next; tl = tl->next;
keycount++;
} }
indentDepth++; indentDepth++;
flag = flag && iterate (); flag = flag && iterate ();
indentDepth--; indentDepth--;
while (keycount > 0) goal_remove_last (newgoals);
{
goal_remove_last ();
keycount--;
}
} }
else else
{ {
@ -609,7 +603,7 @@ bind_existing_to_goal (const Binding b, const int run, const int index)
run, index); run, index);
} }
// Reset length // Reset length
remove_read_goals (newgoals); goal_remove_last (newgoals);
sys->runs[run].length = old_length; sys->runs[run].length = old_length;
return flag; return flag;
} }
@ -675,7 +669,7 @@ bind_new_run (const Binding b, const Protocol p, const Role r,
indentDepth++; indentDepth++;
flag = bind_existing_to_goal (b, run, index); flag = bind_existing_to_goal (b, run, index);
indentDepth--; indentDepth--;
remove_read_goals (newgoals); goal_remove_last (newgoals);
semiRunDestroy (); semiRunDestroy ();
return flag; return flag;
} }
@ -719,6 +713,15 @@ dotSemiState ()
termPrint (current_claim->type); termPrint (current_claim->type);
eprintf ("\";\n"); eprintf ("\";\n");
// Needed for the bindings later on: create graph
goal_graph_create (); // create graph
warshall (graph, nodes); // determine closure
#ifdef DEBUG
// For debugging purposes, we also display an ASCII version of some stuff in the comments
printSemiState ();
#endif
// Draw graph // Draw graph
// First, all simple runs // First, all simple runs
run = 0; run = 0;
@ -838,8 +841,6 @@ dotSemiState ()
// Second, all bindings. // Second, all bindings.
// We now determine them ourselves between existing runs // We now determine them ourselves between existing runs
goal_graph_create (); // create graph
warshall (graph, nodes); // determine closure
run = 0; run = 0;
while (run < sys->maxruns) while (run < sys->maxruns)
{ {
@ -1227,7 +1228,7 @@ bind_goal_new_encrypt (const Binding b)
} }
goal_unbind (b); goal_unbind (b);
indentDepth--; indentDepth--;
remove_read_goals (newgoals); goal_remove_last (newgoals);
semiRunDestroy (); semiRunDestroy ();
} }
} }
@ -2017,7 +2018,7 @@ arachne ()
//! Destroy //! Destroy
while (sys->bindings != NULL) while (sys->bindings != NULL)
{ {
remove_read_goals (1); goal_remove_last (1);
} }
while (sys->maxruns > 0) while (sys->maxruns > 0)
{ {

View File

@ -379,9 +379,12 @@ binding_print (const Binding b)
* The int parameter 'level' is just to store additional info. Here, it stores priorities for a goal. * The int parameter 'level' is just to store additional info. Here, it stores priorities for a goal.
* Higher level goals will be selected first. Typically, a normal goal is level 0, a key is 1. * Higher level goals will be selected first. Typically, a normal goal is level 0, a key is 1.
*/ */
void int
goal_add (Term term, const int run, const int ev, const int level) goal_add (Term term, const int run, const int ev, const int level)
{ {
int sum;
sum = 0;
term = deVar (term); term = deVar (term);
#ifdef DEBUG #ifdef DEBUG
if (term == NULL) if (term == NULL)
@ -403,7 +406,7 @@ goal_add (Term term, const int run, const int ev, const int level)
i = 0; i = 0;
while (i < width) while (i < width)
{ {
goal_add (tupleProject (term, i), run, ev, level); sum = sum + goal_add (tupleProject (term, i), run, ev, level);
if (i > 0) if (i > 0)
{ {
Binding b; Binding b;
@ -415,29 +418,53 @@ goal_add (Term term, const int run, const int ev, const int level)
} }
} }
else else
{
// Determine whether we already had it
int nope;
int testSame (void *data)
{ {
Binding b; Binding b;
b = (Binding) data;
if (isTermEqual (b->term, term) &&
run == b->run_to &&
ev == b->ev_to)
{ // abort scan, report
return 0;
}
else
{ // proceed with scan
return 1;
}
}
nope = list_iterate (sys->bindings, testSame);
if (nope)
{
// Add a new binding
Binding b;
b = binding_create (term, run, ev); b = binding_create (term, run, ev);
b->level = level; b->level = level;
sys->bindings = list_insert (sys->bindings, b); sys->bindings = list_insert (sys->bindings, b);
sum = sum + 1;
} }
} }
return sum;
}
//! Remove a goal //! Remove a goal
void void
goal_remove_last () goal_remove_last (int n)
{
while (n > 0 && (sys->bindings != NULL))
{ {
Binding b; Binding b;
int child;
child = 1;
while (child && (sys->bindings != NULL))
{
b = (Binding) sys->bindings->data; b = (Binding) sys->bindings->data;
child = b->child;
binding_destroy (b); binding_destroy (b);
sys->bindings = list_delete (sys->bindings); sys->bindings = list_delete (sys->bindings);
n--;
} }
} }

View File

@ -41,8 +41,8 @@ void goal_graph_create ();
int binding_print (Binding b); int binding_print (Binding b);
void goal_add (Term term, const int run, const int ev, const int level); int goal_add (Term term, const int run, const int ev, const int level);
void goal_remove_last (); void goal_remove_last (int n);
int goal_bind (const Binding b, const int run, const int ev); int goal_bind (const Binding b, const int run, const int ev);
void goal_unbind (const Binding b); void goal_unbind (const Binding b);
int labels_ordered (Termmap runs, Termlist labels); int labels_ordered (Termmap runs, Termlist labels);