CS计算机代考程序代写 compiler cache b’e6864ee5fa5c8e91470ba61503440aaff3ca59′

b’e6864ee5fa5c8e91470ba61503440aaff3ca59′

blob 7382�#include
#include
#include
#include

#include “../common/contextmanager.h”
#include “../common/err.h”
#include “../common/protocol.h”

#include “authtableentry.h”
#include “format.h”
#include “map.h”
#include “map_factories.h”
#include “storage.h”

using namespace std;

/// MyStorage is the student implementation of the Storage class
class MyStorage : public Storage {
/// The map of authentication information, indexed by username
Map *auth_table;

/// The name of the file from which the Storage object was loaded, and to
/// which we persist the Storage object every time it changes
string filename = “”;

public:
/// Construct an empty object and specify the file from which it should be
/// loaded. To avoid exceptions and errors in the constructor, the act of
/// loading data is separate from construction.
///
/// @param fname The name of the file to use for persistence
/// @param buckets The number of buckets in the hash table
/// @param upq The upload quota
/// @param dnq The download quota
/// @param rqq The request quota
/// @param qd The quota duration
/// @param top The size of the “top keys” cache
/// @param admin The administrator’s username
MyStorage(const std::string &fname, size_t buckets, size_t, size_t, size_t,
double, size_t, const std::string &)
: auth_table(authtable_factory(buckets)), filename(fname) {}

/// Destructor for the storage object.
virtual ~MyStorage() {}

/// Create a new entry in the Auth table. If the user already exists, return
/// an error. Otherwise, create a salt, hash the password, and then save an
/// entry with the username, salt, hashed password, and a zero-byte content.
///
/// @param user The user name to register
/// @param pass The password to associate with that user name
///
/// @return A result tuple, as described in storage.h
virtual result_t add_user(const string &user, const string &pass) {
cout << "my_storage.cc::add_user() is not implemented\n"; // NB: These asserts are to prevent compiler warnings assert(user.length() > 0);
assert(pass.length() > 0);
return {false, RES_ERR_UNIMPLEMENTED, {}};
}

/// Set the data bytes for a user, but do so if and only if the password
/// matches
///
/// @param user The name of the user whose content is being set
/// @param pass The password for the user, used to authenticate
/// @param content The data to set for this user
///
/// @return A result tuple, as described in storage.h
virtual result_t set_user_data(const string &user, const string &pass,
const vector &content) {
cout << "my_storage.cc::set_user_data() is not implemented\n"; // NB: These asserts are to prevent compiler warnings assert(user.length() > 0);
assert(pass.length() > 0);
assert(content.size() > 0);
return {false, RES_ERR_UNIMPLEMENTED, {}};
}

/// Return a copy of the user data for a user, but do so only if the password
/// matches
///
/// @param user The name of the user who made the request
/// @param pass The password for the user, used to authenticate
/// @param who The name of the user whose content is being fetched
///
/// @return A result tuple, as described in storage.h. Note that “no data” is
/// an error
virtual result_t get_user_data(const string &user, const string &pass,
const string &who) {
cout << "my_storage.cc::get_user_data() is not implemented\n"; // NB: These asserts are to prevent compiler warnings assert(user.length() > 0);
assert(pass.length() > 0);
assert(who.length() > 0);
return {false, RES_ERR_UNIMPLEMENTED, {}};
}

/// Return a newline-delimited string containing all of the usernames in the
/// auth table
///
/// @param user The name of the user who made the request
/// @param pass The password for the user, used to authenticate
///
/// @return A result tuple, as described in storage.h
virtual result_t get_all_users(const string &user, const string &pass) {
cout << "my_storage.cc::get_all_users() is not implemented\n"; // NB: These asserts are to prevent compiler warnings assert(user.length() > 0);
assert(pass.length() > 0);
return {false, RES_ERR_UNIMPLEMENTED, {}};
}

/// Authenticate a user
///
/// @param user The name of the user who made the request
/// @param pass The password for the user, used to authenticate
///
/// @return A result tuple, as described in storage.h
virtual result_t auth(const string &user, const string &pass) {
cout << "my_storage.cc::auth() is not implemented\n"; // NB: These asserts are to prevent compiler warnings assert(user.length() > 0);
assert(pass.length() > 0);
return {false, RES_ERR_UNIMPLEMENTED, {}};
}

/// Shut down the storage when the server stops. This method needs to close
/// any open files related to incremental persistence. It also needs to clean
/// up any state related to .so files. This is only called when all threads
/// have stopped accessing the Storage object.
virtual void shutdown() {
cout << "my_storage.cc::shutdown() is not implemented\n"; } /// Write the entire Storage object to the file specified by this.filename. To /// ensure durability, Storage must be persisted in two steps. First, it must /// be written to a temporary file (this.filename.tmp). Then the temporary /// file can be renamed to replace the older version of the Storage object. /// /// @return A result tuple, as described in storage.h virtual result_t save_file() { cout << "my_storage.cc::save_file() is not implemented\n"; return {false, RES_ERR_UNIMPLEMENTED, {}}; } /// Populate the Storage object by loading this.filename. Note that load() /// begins by clearing the maps, so that when the call is complete, exactly /// and only the contents of the file are in the Storage object. /// /// @return A result tuple, as described in storage.h. Note that a /// non-existent /// file is not an error. virtual result_t load_file() { FILE *storage_file = fopen(filename.c_str(), "r"); if (storage_file == nullptr) { return {true, "File not found: " + filename, {}}; } cout << "my_storage.cc::save_file() is not implemented\n"; return {false, RES_ERR_UNIMPLEMENTED, {}}; } }; /// Create an empty Storage object and specify the file from which it should be /// loaded. To avoid exceptions and errors in the constructor, the act of /// loading data is separate from construction. /// /// @param fname The name of the file to use for persistence /// @param buckets The number of buckets in the hash table /// @param upq The upload quota /// @param dnq The download quota /// @param rqq The request quota /// @param qd The quota duration /// @param top The size of the "top keys" cache /// @param admin The administrator's username Storage *storage_factory(const std::string &fname, size_t buckets, size_t upq, size_t dnq, size_t rqq, double qd, size_t top, const std::string &admin) { return new MyStorage(fname, buckets, upq, dnq, rqq, qd, top, admin); }