identity_tentacle.cpp

Go to the documentation of this file.
00001 #ifndef IDENTITY_TENTACLE_IMPLEMENTATION_FILE
00002 #define IDENTITY_TENTACLE_IMPLEMENTATION_FILE
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : identity_tentacle                                                 *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2002-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include "identity_tentacle.h"
00019 #include "identity_infoton.h"
00020 #include "octopus.h"
00021 
00022 #include <basis/log_base.h>
00023 #include <data_struct/string_hash.h>
00024 #include <mechanisms/time_stamp.h>
00025 
00026 #undef LOG
00027 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s)
00028 
00029 //#define DEBUG_IDENTITY_TENTACLE
00030   // uncomment for debugging version.
00031 
00033 
00034 identity_tentacle::identity_tentacle(octopus &parent)
00035 : tentacle_helper<identity_infoton>(identity_infoton::identity_classifier(),
00036       false),
00037   _parent(parent)
00038 {}
00039 
00040 identity_tentacle::~identity_tentacle() {}
00041 
00042 outcome identity_tentacle::reconstitute(const string_array &classifier,
00043     byte_array &packed_form, infoton * &reformed)
00044 {
00045   if (classifier != identity_infoton::identity_classifier()) 
00046     return NO_HANDLER;
00047 
00048   return reconstituter(classifier, packed_form, reformed,
00049       (identity_infoton *)NIL);
00050 }
00051 
00052 outcome identity_tentacle::consume(infoton &to_chow,
00053     const octopus_request_id &item_id, byte_array &transformed)
00054 {
00055   FUNCDEF("consume");
00056   transformed.reset();
00057   identity_infoton *inf = dynamic_cast<identity_infoton *>(&to_chow);
00058   if (!inf) {
00059     // if the infoton doesn't cast, then it is not for us.  we need to vet
00060     // that the identity looks pretty much okay.
00061 
00062 //hmmm: check host?
00063 //      that would imply that all users of octopi have correctly identified
00064 //      themselves.  this is not currently the case.  we need a way to
00065 //      automate that step for a user of an octopus?
00066 bool uhhh = true;
00067 
00068     if (uhhh) {
00069       // this infoton's entity was allowed, so we call it partially processed.
00070       return PARTIAL;
00071     }
00072 #ifdef DEBUG_IDENTITY_TENTACLE
00073     LOG(istring("denying infoton ") + item_id.mangled_form());
00074 #endif
00075     // the infoton's identity is invalid; it needs to be dropped.
00076     return DISALLOWED;
00077   }
00078 
00079 #ifdef DEBUG_IDENTITY_TENTACLE
00080   LOG(istring("old name, storing under: ") + item_id.mangled_form());
00081 #endif
00082 
00083   // this is definitely for an identity request now.
00084   inf->_new_name = _parent.issue_identity();
00085 
00086 #ifdef DEBUG_IDENTITY_TENTACLE
00087   LOG(istring("new name: ") + inf->_new_name.mangled_form());
00088 #endif
00089 
00090   if (!store_product((infoton *)inf->clone(), item_id))
00091     return NO_SPACE;
00092   return OKAY;
00093 }
00094 
00095 
00096 #endif //IDENTITY_TENTACLE_IMPLEMENTATION_FILE
00097 

Generated on Fri Nov 28 04:29:18 2008 for HOOPLE Libraries by  doxygen 1.5.1