Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
efdfbe5e
Commit
efdfbe5e
authored
6 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
namedirectory: lock cache during lookup
Change-Id: If92032d68a6429695cb698ca6fc497b1b095f3a5
parent
f0506e16
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ringdht/namedirectory.cpp
+9
-9
9 additions, 9 deletions
src/ringdht/namedirectory.cpp
src/ringdht/namedirectory.h
+13
-1
13 additions, 1 deletion
src/ringdht/namedirectory.h
with
22 additions
and
10 deletions
src/ringdht/namedirectory.cpp
+
9
−
9
View file @
efdfbe5e
...
@@ -105,9 +105,9 @@ size_t getContentLength(restbed::Response& reply)
...
@@ -105,9 +105,9 @@ size_t getContentLength(restbed::Response& reply)
void
NameDirectory
::
lookupAddress
(
const
std
::
string
&
addr
,
LookupCallback
cb
)
void
NameDirectory
::
lookupAddress
(
const
std
::
string
&
addr
,
LookupCallback
cb
)
{
{
try
{
try
{
auto
cacheRes
=
nameCache
_
.
find
(
addr
);
std
::
string
cacheRes
ult
=
nameCache
(
addr
);
if
(
cacheRes
!=
nameCache_
.
end
())
{
if
(
not
cacheRes
ult
.
empty
())
{
cb
(
cacheRes
->
second
,
Response
::
found
);
cb
(
cacheRes
ult
,
Response
::
found
);
return
;
return
;
}
}
...
@@ -179,9 +179,9 @@ void NameDirectory::lookupName(const std::string& n, LookupCallback cb)
...
@@ -179,9 +179,9 @@ void NameDirectory::lookupName(const std::string& n, LookupCallback cb)
}
}
toLower
(
name
);
toLower
(
name
);
auto
cacheRes
=
addrCache
_
.
find
(
name
);
std
::
string
cacheRes
ult
=
addrCache
(
name
);
if
(
cacheRes
!=
addrCache_
.
end
())
{
if
(
not
cacheRes
ult
.
empty
())
{
cb
(
cacheRes
->
second
,
Response
::
found
);
cb
(
cacheRes
ult
,
Response
::
found
);
return
;
return
;
}
}
...
@@ -260,9 +260,9 @@ void NameDirectory::registerName(const std::string& addr, const std::string& n,
...
@@ -260,9 +260,9 @@ void NameDirectory::registerName(const std::string& addr, const std::string& n,
}
}
toLower
(
name
);
toLower
(
name
);
auto
cacheRes
=
addrCache
_
.
find
(
name
);
auto
cacheRes
ult
=
addrCache
(
name
);
if
(
cacheRes
!=
addrCache_
.
end
())
{
if
(
not
cacheRes
ult
.
empty
())
{
if
(
cacheRes
->
second
==
addr
)
if
(
cacheRes
ult
==
addr
)
cb
(
RegistrationResponse
::
success
);
cb
(
RegistrationResponse
::
success
);
else
else
cb
(
RegistrationResponse
::
alreadyTaken
);
cb
(
RegistrationResponse
::
alreadyTaken
);
...
...
This diff is collapsed.
Click to expand it.
src/ringdht/namedirectory.h
+
13
−
1
View file @
efdfbe5e
...
@@ -58,12 +58,24 @@ private:
...
@@ -58,12 +58,24 @@ private:
NameDirectory
(
NameDirectory
&&
)
=
delete
;
NameDirectory
(
NameDirectory
&&
)
=
delete
;
constexpr
static
const
char
*
const
DEFAULT_SERVER_HOST
=
"ns.jami.net"
;
constexpr
static
const
char
*
const
DEFAULT_SERVER_HOST
=
"ns.jami.net"
;
std
::
mutex
lock_
{};
const
std
::
string
serverHost_
{
DEFAULT_SERVER_HOST
};
const
std
::
string
serverHost_
{
DEFAULT_SERVER_HOST
};
const
std
::
string
cachePath_
;
const
std
::
string
cachePath_
;
std
::
map
<
std
::
string
,
std
::
string
>
nameCache_
{};
std
::
map
<
std
::
string
,
std
::
string
>
nameCache_
{};
std
::
map
<
std
::
string
,
std
::
string
>
addrCache_
{};
std
::
map
<
std
::
string
,
std
::
string
>
addrCache_
{};
std
::
mutex
lock_
{};
std
::
string
nameCache
(
const
std
::
string
&
addr
)
{
std
::
lock_guard
<
std
::
mutex
>
l
(
lock_
);
auto
cacheRes
=
nameCache_
.
find
(
addr
);
return
cacheRes
!=
nameCache_
.
end
()
?
cacheRes
->
second
:
std
::
string
{};
}
std
::
string
addrCache
(
const
std
::
string
&
name
)
{
std
::
lock_guard
<
std
::
mutex
>
l
(
lock_
);
auto
cacheRes
=
addrCache_
.
find
(
name
);
return
cacheRes
!=
addrCache_
.
end
()
?
cacheRes
->
second
:
std
::
string
{};
}
bool
validateName
(
const
std
::
string
&
name
)
const
;
bool
validateName
(
const
std
::
string
&
name
)
const
;
...
...
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