Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

ShareLabelChallengeHandler.cc

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: ShareLabelChallengeHandler.cc,v 1.3 2004/05/19 15:56:59 mmarsh Exp $
00008 //
00009 // $Log: ShareLabelChallengeHandler.cc,v $
00010 // Revision 1.3  2004/05/19 15:56:59  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:31:51  mmarsh
00014 // *** empty log message ***
00015 //
00016 //
00017 
00018 #include <vector>
00019 
00020 #include "ShareLabelChallengeHandler.h"
00021 #include "ShareLabelChallengeEvent.h"
00022 #include "ServerState.h"
00023 #include "ShareLabelChallenge.h"
00024 
00025 using namespace CODEX_Server;
00026 
00027 ShareLabelChallengeHandler::ShareLabelChallengeHandler(
00028    CODEX_Events::DeadPileType& deadPile,
00029    CODEX_Events::QType& eventQueue ) :
00030    CODEX_Events::Activity( deadPile, eventQueue )
00031 {
00032    sendEvent( new ShareLabelChallengeEvent( this, this ), 0 );
00033 }
00034 
00035 bool
00036 ShareLabelChallengeHandler::handler( ShareLabelChallengeEvent& event )
00037 {
00038    ServerState* serverState = ServerState::instance();
00039    if ( 0 == serverState )
00040    {
00041       return false;
00042    }
00043 
00044    typedef vector< const unsigned char* >  SVec;
00045 
00046    SVec completed;
00047 
00048    // Loop over all challenged requests.
00049    ServerState::ChallengeMap::const_iterator cItr =
00050       serverState->challengeMap().begin();
00051    ServerState::ChallengeMap::const_iterator cEnd =
00052       serverState->challengeMap().end();
00053    for ( ; cItr != cEnd ; ++cItr )
00054    {
00055 
00056       // Loop over the challenges to this request.  This is done in
00057       // reverse order, since later challenges are more likely to contain
00058       // a currently valid label.
00059       ServerState::ChallengeVector::const_reverse_iterator vItr =
00060          cItr->second.rbegin();
00061       ServerState::ChallengeVector::const_reverse_iterator vEnd =
00062          cItr->second.rend();
00063       for ( ; vItr != vEnd ; ++vItr )
00064       {
00065          // Get the challenge object.
00066          ShareLabelChallenge* slc = *vItr;
00067          try
00068          {
00069             // If the shares are available for this label, we must have
00070             // received valid shares for the label.  An exception will be
00071             // thrown if the label is not yet known.
00072             //
00073             // From an efficiency standpoint this is not ideal, since we
00074             // have to invoke the exception mechanism for what will likely
00075             // be a somewhat common occurrence, especially in a well-exercised
00076             // system.
00077             bool haveLabel = false;
00078 
00079             try
00080             {
00081                serverState->rsaShares( slc->label(), slc->challenger() );
00082                haveLabel = true;
00083             }
00084             catch ( InvalidLabelException& )
00085             {
00086             }
00087             catch ( ... )
00088             {
00089                haveLabel = true;
00090             }
00091 
00092             try
00093             {
00094                serverState->elgamalShares( slc->label(), slc->challenger() );
00095                haveLabel = true;
00096             }
00097             catch ( InvalidLabelException& )
00098             {
00099             }
00100             catch ( ... )
00101             {
00102                haveLabel = true;
00103             }
00104 
00105             if ( ! haveLabel )
00106             {
00107                continue;
00108             }
00109 
00110             // An exception was not thrown, so it must be OK to send the
00111             // event re-issuing the request with the new label.
00112             sendEvent( slc->event(), event.source() );
00113 
00114             // Now clear the current entry, which prevents freeing memory
00115             // in use.
00116             slc->zeroData();
00117 
00118             // Mark this request challenge as having been completed so that
00119             // the challenge can be cleaned up.
00120             completed.push_back( cItr->first );
00121 
00122             // Finally, break out of the inner loop and look at the next
00123             // challenged request, if any.
00124             break;
00125          }
00126          catch ( ... )
00127          {
00128             // Exceptions are not error here -- just keep going.
00129          }
00130       }
00131 
00132    }
00133 
00134    // Loop over the completed challenges, cleaning them up.
00135    SVec::iterator sItr = completed.begin();
00136    SVec::iterator sEnd = completed.end();
00137    for ( ; sItr != sEnd ; ++sItr )
00138    {
00139       serverState->removeChallenge( *sItr );
00140    }
00141 
00142    return false;
00143 }

Generated on Wed Jun 2 16:32:56 2004 for COrnell Data EXchange (CODEX) by doxygen1.2.18