- Rewrite of actor/agent type consitency code: now more aware of

initiator/responder difference.
This commit is contained in:
ccremers 2005-09-09 10:05:29 +00:00
parent 5c0c5d3333
commit 5b73d707a0
4 changed files with 135 additions and 80 deletions

View File

@ -574,6 +574,71 @@ countIntruderActions ()
return count; return count;
} }
//! Check this variables whether it is a good agent type
/**
* Checks for leaf/etc and correct agent type
*/
int
goodAgentType (Term agent)
{
agent = deVar (agent);
if (!realTermLeaf (agent))
{ // not a leaf
return false;
}
else
{ // real leaf
if (isTermVariable (agent))
{
// Variable: check type consistency (should have a solution)
// Not yet: depends on matching mode also
}
else
{
// Constant: allow only exact type
if (!inTermlist (agent->stype, TERM_Agent))
{
return false;
}
}
}
return true;
}
//! Check initiator roles
/**
* Returns false iff an agent type is wrong
*/
int
initiatorAgentsType ()
{
int run;
run = 0;
while (run < sys->maxruns)
{
// Only for initiators
if (sys->runs[run].role->initiator)
{
Termlist agents;
agents = sys->runs[run].agents;
while (agents != NULL)
{
if (!goodAgentType (agents->term))
{
return false;
}
agents = agents->next;
}
}
run++;
}
return true; // seems to be okay
}
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Proof reporting // Proof reporting
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -2799,72 +2864,42 @@ prune_theorems ()
return 1; return 1;
} }
// Check if all agents are agents (!) // Check if all actors are agents for responders (initiators come next)
run = 0; run = 0;
while (run < sys->maxruns) while (run < sys->maxruns)
{ {
Termlist agl; if (!sys->runs[run].role->initiator)
agl = sys->runs[run].agents;
while (agl != NULL)
{ {
Term agent; Term actor;
agent = deVar (agl->term); actor = agentOfRun (sys, run);
if (agent == NULL) if (!goodAgentType (actor))
{
error ("Agent of run %i is NULL", run);
}
/**
* Check whether the agent of the run is of a sensible type.
*
* @TODO Note that this still needs a lemma.
*/
{
int sensibleagent;
sensibleagent = true;
if (!realTermLeaf (agent))
{ // not a leaf
sensibleagent = false;
}
else
{ // real leaf
if (switches.match == 0 || !isTermVariable (agent))
{ // either strict matching, or not a variable, so we should check matching types
if (agent->stype == NULL)
{ // Too generic
sensibleagent = false;
}
else
{ // Has a type
if (!inTermlist (agent->stype, TERM_Agent))
{ // but not the right type
sensibleagent = false;
}
}
}
}
if (!sensibleagent)
{ {
if (switches.output == PROOF) if (switches.output == PROOF)
{ {
indentPrint (); indentPrint ();
eprintf ("Pruned because the agent "); eprintf ("Pruned because the actor ");
termPrint (agent); termPrint (actor);
eprintf (" of run %i is not of a compatible type.\n", eprintf (" of run %i is not of a compatible type.\n", run);
run);
} }
return 1; return 1;
} }
} }
agl = agl->next;
}
run++; run++;
} }
// Prune wrong agents type for initators
if (!initiatorAgentsType ())
{
if (switches.output == PROOF)
{
indentPrint ();
eprintf
("Pruned: an initiator role does not have the correct type for one of its agents.\n");
}
return 1;
}
// Check if all agents of the main run are valid // Check if all agents of the main run are valid
if (!isRunTrusted (sys, 0)) if (!isRunTrusted (sys, 0))
{ {

View File

@ -626,11 +626,26 @@ roleCompile (Term nameterm, Tac tc)
/* parse the content of the role */ /* parse the content of the role */
levelInit (); levelInit ();
{
int firstEvent;
/* initiator/responder flag not set */
firstEvent = 1;
while (tc != NULL) while (tc != NULL)
{ {
switch (tc->op) switch (tc->op)
{ {
case TAC_READ: case TAC_READ:
if (firstEvent)
{
// First a read, thus responder
/*
* Semantics: defaults (in role.c) to initiator _unless_ the first event is a read,
* in which case we assume that the agent names are possibly received as variables
*/
thisRole->initiator = 0;
}
commEvent (READ, tc); commEvent (READ, tc);
break; break;
case TAC_SEND: case TAC_SEND:
@ -649,8 +664,10 @@ roleCompile (Term nameterm, Tac tc)
} }
break; break;
} }
firstEvent = 0;
tc = tc->next; tc = tc->next;
} }
}
compute_role_variables (sys, thisProtocol, thisRole); compute_role_variables (sys, thisProtocol, thisRole);
levelDone (); levelDone ();
} }

View File

@ -240,6 +240,7 @@ roleCreate (Term name)
r->roledef = NULL; r->roledef = NULL;
r->locals = NULL; r->locals = NULL;
r->variables = NULL; r->variables = NULL;
r->initiator = 1; //! Will be determined later, if a read is the first action (in compiler.c)
r->next = NULL; r->next = NULL;
return r; return r;
} }

View File

@ -120,6 +120,8 @@ struct role
Termlist locals; Termlist locals;
//! Local variables for this role. //! Local variables for this role.
Termlist variables; Termlist variables;
//! Flag for initiator roles
int initiator;
//! Pointer to next role definition. //! Pointer to next role definition.
struct role *next; struct role *next;
}; };