mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-16 15:12:30 +00:00
* Added a missing READ_PORT case to a switch in handshake.cc.
* Stuff. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1164 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -38,6 +38,72 @@
|
||||
|
||||
#include "object_storage.h"
|
||||
|
||||
#include "parse.h"
|
||||
|
||||
namespace rpc {
|
||||
|
||||
object_storage::local_iterator
|
||||
object_storage::find_local(const torrent::raw_string& key) {
|
||||
std::size_t n = hash_fixed_key_type::hash(key.data(), key.size()) % bucket_count();
|
||||
|
||||
for (local_iterator itr = begin(n), last = end(n); itr != last; itr++)
|
||||
if (itr->first.size() == key.size() && std::memcmp(itr->first.data(), key.data(), key.size()) == 0)
|
||||
return itr;
|
||||
|
||||
return end(bucket_count());
|
||||
}
|
||||
|
||||
object_storage::iterator
|
||||
object_storage::insert(const char* key_data, uint32_t key_size, const torrent::Object& object, unsigned int flags) {
|
||||
if (std::find(key_data, key_data + key_size, '\0') != key_data + key_size)
|
||||
throw torrent::input_error("Found nul-char in string.");
|
||||
|
||||
// Check for size > key_size.
|
||||
// Check for empty string.
|
||||
|
||||
// Ensure the object type is correct.
|
||||
|
||||
if (!(flags & mask_type))
|
||||
throw torrent::input_error("No type flags set when calling object_storage::insert.");
|
||||
|
||||
std::pair<iterator, bool> result = base_type::insert(std::make_pair(key_type(key_data, key_size), object_storage_node()));
|
||||
|
||||
if (!result.second)
|
||||
throw torrent::input_error("Key already exists in object_storage.");
|
||||
|
||||
result.first->second.object = object;
|
||||
result.first->second.flags = flags;
|
||||
|
||||
return result.first;
|
||||
}
|
||||
|
||||
const torrent::Object&
|
||||
object_storage::get(const torrent::raw_string& key) {
|
||||
local_iterator itr = find_local(key);
|
||||
|
||||
if (itr == end(bucket_count()))
|
||||
throw torrent::input_error("Key not found.");
|
||||
|
||||
return itr->second.object;
|
||||
}
|
||||
|
||||
const torrent::Object&
|
||||
object_storage::set(const torrent::raw_string& key, const torrent::Object& object) {
|
||||
local_iterator itr = find_local(key);
|
||||
|
||||
if (itr == end(bucket_count()))
|
||||
throw torrent::input_error("Key not found.");
|
||||
|
||||
// Redo this...
|
||||
|
||||
switch (itr->second.flags & mask_type) {
|
||||
case flag_generic_type: itr->second.object = object; break;
|
||||
case flag_value_type: itr->second.object = convert_to_value(object); break;
|
||||
case flag_string_type: itr->second.object = convert_to_string(object); break;
|
||||
default: throw torrent::internal_error("object_storage::set: Type not set.");
|
||||
}
|
||||
|
||||
return itr->second.object;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user