Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
c08333f2
Commit
c08333f2
authored
9 years ago
by
kaldoran
Committed by
Simon Désaulniers
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
pht: bit padding when the key is too short
parent
e775358a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/indexation/pht.h
+33
-7
33 additions, 7 deletions
include/opendht/indexation/pht.h
tools/dhtnode.cpp
+2
-6
2 additions, 6 deletions
tools/dhtnode.cpp
with
35 additions
and
13 deletions
include/opendht/indexation/pht.h
+
33
−
7
View file @
c08333f2
...
@@ -65,12 +65,7 @@ struct Prefix {
...
@@ -65,12 +65,7 @@ struct Prefix {
* @return The prefix of this sibling.
* @return The prefix of this sibling.
*/
*/
Prefix
getSibling
()
const
{
Prefix
getSibling
()
const
{
Prefix
copy
=
*
this
;
return
swapBit
(
size_
-
1
);
if
(
size_
)
{
size_t
last_bit
=
(
8
-
size_
)
%
8
;
copy
.
content_
.
back
()
^=
(
1
<<
last_bit
);
}
return
copy
;
}
}
InfoHash
hash
()
const
{
InfoHash
hash
()
const
{
...
@@ -115,6 +110,27 @@ struct Prefix {
...
@@ -115,6 +110,27 @@ struct Prefix {
return
8
*
i
+
j
;
return
8
*
i
+
j
;
}
}
/**
* This method swap the bit a the position 'bit' and return the new prefix
*
* @param bit Position of the bit to swap
*
* @return The prefix with the bit at position 'bit' swapped
*
* @throw out_of_range Throw out of range if bit does not exist
*/
Prefix
swapBit
(
size_t
bit
)
const
{
if
(
bit
>=
size_
)
throw
std
::
out_of_range
(
"bit larger than prefix size."
);
Prefix
copy
=
*
this
;
size_t
offset_bit
=
(
8
-
bit
)
%
8
;
copy
.
content_
[
bit
/
8
]
^=
(
1
<<
offset_bit
);
return
copy
;
}
size_t
size_
{
0
};
size_t
size_
{
0
};
Blob
content_
{};
Blob
content_
{};
};
};
...
@@ -174,6 +190,7 @@ public:
...
@@ -174,6 +190,7 @@ public:
{
{
lookup
(
k
,
[
=
](
std
::
vector
<
std
::
shared_ptr
<
Value
>>&
values
,
Prefix
)
{
cb
(
values
);
},
done_cb
,
exact_match
);
lookup
(
k
,
[
=
](
std
::
vector
<
std
::
shared_ptr
<
Value
>>&
values
,
Prefix
)
{
cb
(
values
);
},
done_cb
,
exact_match
);
}
}
/**
/**
* Adds an entry into the index.
* Adds an entry into the index.
*/
*/
...
@@ -236,7 +253,16 @@ private:
...
@@ -236,7 +253,16 @@ private:
*/
*/
virtual
Prefix
linearize
(
Key
k
)
const
{
virtual
Prefix
linearize
(
Key
k
)
const
{
if
(
not
validKey
(
k
))
{
throw
std
::
invalid_argument
(
INVALID_KEY
);
}
if
(
not
validKey
(
k
))
{
throw
std
::
invalid_argument
(
INVALID_KEY
);
}
return
Blob
{
k
.
begin
()
->
second
.
begin
(),
k
.
begin
()
->
second
.
begin
()
+
keySpec_
.
begin
()
->
second
};
Prefix
p
=
Blob
{
k
.
begin
()
->
second
.
begin
(),
k
.
begin
()
->
second
.
end
()};
auto
bit_loc
=
p
.
size_
+
1
;
for
(
auto
i
=
p
.
content_
.
size
();
i
<=
keySpec_
.
begin
()
->
second
;
i
++
)
{
p
.
content_
.
push_back
(
0
);
p
.
size_
+=
8
;
}
return
p
.
swapBit
(
bit_loc
);
};
};
/**
/**
...
...
This diff is collapsed.
Click to expand it.
tools/dhtnode.cpp
+
2
−
6
View file @
c08333f2
...
@@ -296,12 +296,8 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, std::map<std::string, indexation:
...
@@ -296,12 +296,8 @@ void cmd_loop(std::shared_ptr<DhtRunner>& dht, std::map<std::string, indexation:
try
{
try
{
auto
key
=
createPhtKey
(
parseStringMap
(
keystr
));
auto
key
=
createPhtKey
(
parseStringMap
(
keystr
));
indexes
.
at
(
index
).
insert
(
key
,
v
,
indexes
.
at
(
index
).
insert
(
key
,
v
,
[
=
](
bool
success
)
{
[
=
](
bool
ok
)
{
if
(
not
success
)
{
std
::
cout
<<
"Pht::insert: "
<<
(
ok
?
"done."
:
"failed."
)
<<
std
::
endl
;
std
::
cout
<<
"Pht::insert: failed."
<<
std
::
endl
;
return
;
}
std
::
cout
<<
"Pht::insert: done."
<<
std
::
endl
;
}
}
);
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment