Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
J
jami-daemon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
130
Issues
130
List
Boards
Labels
Service Desk
Milestones
Iterations
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Analytics
Analytics
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
savoirfairelinux
jami-daemon
Commits
6db90428
Commit
6db90428
authored
Apr 21, 2019
by
Adrien Béraud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jamiaccount: use new OpenDHT APIs
Change-Id: I2a590a5e4a63279582ea605b7fbf10d37ec4c571
parent
7f2f77f6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
47 deletions
+46
-47
src/jamidht/jamiaccount.cpp
src/jamidht/jamiaccount.cpp
+46
-47
No files found.
src/jamidht/jamiaccount.cpp
View file @
6db90428
...
...
@@ -2127,37 +2127,10 @@ JamiAccount::doRegister_()
});
#endif
auto
currentDhtStatus
=
std
::
make_shared
<
dht
::
NodeStatus
>
(
dht
::
NodeStatus
::
Disconnected
);
dht_
.
setOnStatusChanged
([
this
,
currentDhtStatus
](
dht
::
NodeStatus
s4
,
dht
::
NodeStatus
s6
)
{
JAMI_DBG
(
"[Account %s] Dht status : IPv4 %s; IPv6 %s"
,
getAccountID
().
c_str
(),
dhtStatusStr
(
s4
),
dhtStatusStr
(
s6
));
RegistrationState
state
;
auto
newStatus
=
std
::
max
(
s4
,
s6
);
if
(
newStatus
==
*
currentDhtStatus
)
return
;
switch
(
newStatus
)
{
case
dht
::
NodeStatus
::
Connecting
:
JAMI_WARN
(
"[Account %s] connecting to the DHT network..."
,
getAccountID
().
c_str
());
state
=
RegistrationState
::
TRYING
;
break
;
case
dht
::
NodeStatus
::
Connected
:
JAMI_WARN
(
"[Account %s] connected to the DHT network"
,
getAccountID
().
c_str
());
state
=
RegistrationState
::
REGISTERED
;
break
;
case
dht
::
NodeStatus
::
Disconnected
:
JAMI_WARN
(
"[Account %s] disconnected from the DHT network"
,
getAccountID
().
c_str
());
state
=
RegistrationState
::
UNREGISTERED
;
break
;
default:
state
=
RegistrationState
::
ERROR_GENERIC
;
break
;
}
*
currentDhtStatus
=
newStatus
;
setRegistrationState
(
state
);
});
dht
::
DhtRunner
::
Config
config
{};
config
.
dht_config
.
node_config
.
network
=
0
;
config
.
dht_config
.
node_config
.
maintain_storage
=
false
;
config
.
dht_config
.
node_config
.
persist_path
=
cachePath_
+
DIR_SEPARATOR_STR
"dhtstate"
;
config
.
dht_config
.
id
=
identity_
;
config
.
proxy_server
=
getDhtProxyServer
();
config
.
push_node_id
=
getAccountID
();
...
...
@@ -2172,16 +2145,7 @@ JamiAccount::doRegister_()
dht_
.
setPushNotificationToken
(
deviceKey_
);
}
dht_
.
run
((
in_port_t
)
dhtPortUsed_
,
config
);
dht_
.
setLocalCertificateStore
([](
const
dht
::
InfoHash
&
pk_id
)
{
std
::
vector
<
std
::
shared_ptr
<
dht
::
crypto
::
Certificate
>>
ret
;
if
(
auto
cert
=
tls
::
CertificateStore
::
instance
().
getCertificate
(
pk_id
.
toString
()))
ret
.
emplace_back
(
std
::
move
(
cert
));
JAMI_DBG
(
"Query for local certificate store: %s: %zu found."
,
pk_id
.
toString
().
c_str
(),
ret
.
size
());
return
ret
;
});
dht
::
DhtRunner
::
Context
context
{};
auto
dht_log_level
=
Manager
::
instance
().
dhtLogLevel
.
load
();
if
(
dht_log_level
>
0
)
{
static
auto
silent
=
[](
char
const
*
/*m*/
,
va_list
/*args*/
)
{};
...
...
@@ -2189,7 +2153,7 @@ JamiAccount::doRegister_()
static
auto
log_warn
=
[](
char
const
*
m
,
va_list
args
)
{
Logger
::
vlog
(
LOG_WARNING
,
nullptr
,
0
,
true
,
m
,
args
);
};
static
auto
log_debug
=
[](
char
const
*
m
,
va_list
args
)
{
Logger
::
vlog
(
LOG_DEBUG
,
nullptr
,
0
,
true
,
m
,
args
);
};
#ifndef _MSC_VER
dht_
.
setLoggers
(
context
.
logger
=
std
::
make_unique
<
dht
::
Logger
>
(
log_error
,
(
dht_log_level
>
1
)
?
log_warn
:
silent
,
(
dht_log_level
>
2
)
?
log_debug
:
silent
);
...
...
@@ -2200,23 +2164,56 @@ JamiAccount::doRegister_()
auto
now
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
std
::
chrono
::
steady_clock
::
now
().
time_since_epoch
()).
count
();
jami
::
emitSignal
<
DRing
::
DebugSignal
::
MessageSend
>
(
std
::
to_string
(
now
)
+
" "
+
std
::
string
(
tmp
));
};
dht_
.
setLoggers
(
log_all
,
log_all
,
silent
);
context
.
logger
=
std
::
make_unique
<
dht
::
Logger
>
(
log_all
,
log_all
,
silent
);
#else
if
(
dht_log_level
>
2
)
{
dht_
.
setLoggers
(
log_error
,
log_warn
,
log_debug
);
context
.
logger
=
std
::
make_unique
<
dht
::
Logger
>
(
log_error
,
log_warn
,
log_debug
);
}
else
if
(
dht_log_level
>
1
)
{
dht_
.
setLoggers
(
log_error
,
log_warn
,
silent
);
context
.
logger
=
std
::
make_unique
<
dht
::
Logger
>
(
log_error
,
log_warn
,
silent
);
}
else
{
dht_
.
setLoggers
(
log_error
,
silent
,
silent
);
context
.
logger
=
std
::
make_unique
<
dht
::
Logger
>
(
log_error
,
silent
,
silent
);
}
#endif
}
context
.
certificateStore
=
[](
const
dht
::
InfoHash
&
pk_id
)
{
std
::
vector
<
std
::
shared_ptr
<
dht
::
crypto
::
Certificate
>>
ret
;
if
(
auto
cert
=
tls
::
CertificateStore
::
instance
().
getCertificate
(
pk_id
.
toString
()))
ret
.
emplace_back
(
std
::
move
(
cert
));
JAMI_DBG
(
"Query for local certificate store: %s: %zu found."
,
pk_id
.
toString
().
c_str
(),
ret
.
size
());
return
ret
;
};
dht_
.
importValues
(
loadValues
());
auto
currentDhtStatus
=
std
::
make_shared
<
dht
::
NodeStatus
>
(
dht
::
NodeStatus
::
Disconnected
);
context
.
statusChangedCallback
=
[
this
,
currentDhtStatus
](
dht
::
NodeStatus
s4
,
dht
::
NodeStatus
s6
)
{
JAMI_DBG
(
"[Account %s] Dht status : IPv4 %s; IPv6 %s"
,
getAccountID
().
c_str
(),
dhtStatusStr
(
s4
),
dhtStatusStr
(
s6
));
RegistrationState
state
;
auto
newStatus
=
std
::
max
(
s4
,
s6
);
if
(
newStatus
==
*
currentDhtStatus
)
return
;
switch
(
newStatus
)
{
case
dht
::
NodeStatus
::
Connecting
:
JAMI_WARN
(
"[Account %s] connecting to the DHT network..."
,
getAccountID
().
c_str
());
state
=
RegistrationState
::
TRYING
;
break
;
case
dht
::
NodeStatus
::
Connected
:
JAMI_WARN
(
"[Account %s] connected to the DHT network"
,
getAccountID
().
c_str
());
state
=
RegistrationState
::
REGISTERED
;
break
;
case
dht
::
NodeStatus
::
Disconnected
:
JAMI_WARN
(
"[Account %s] disconnected from the DHT network"
,
getAccountID
().
c_str
());
state
=
RegistrationState
::
UNREGISTERED
;
break
;
default:
state
=
RegistrationState
::
ERROR_GENERIC
;
break
;
}
*
currentDhtStatus
=
newStatus
;
setRegistrationState
(
state
);
};
setRegistrationState
(
RegistrationState
::
TRYING
);
dht_
.
run
((
in_port_t
)
dhtPortUsed_
,
config
,
std
::
move
(
context
));
dht_
.
bootstrap
(
loadNodes
());
auto
bootstrap
=
loadBootstrap
();
if
(
not
bootstrap
.
empty
())
dht_
.
bootstrap
(
bootstrap
);
...
...
@@ -2606,6 +2603,10 @@ JamiAccount::doUnregister(std::function<void(bool)> released_cb)
}
JAMI_WARN
(
"[Account %s] unregistering account %p"
,
getAccountID
().
c_str
(),
this
);
dht_
.
shutdown
([
this
](){
JAMI_WARN
(
"[Account %s] dht shutdown complete"
,
getAccountID
().
c_str
());
});
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
callsMutex_
);
pendingCalls_
.
clear
();
...
...
@@ -2618,8 +2619,6 @@ JamiAccount::doUnregister(std::function<void(bool)> released_cb)
upnp_
->
removeMappings
();
}
saveNodes
(
dht_
.
exportNodes
());
saveValues
(
dht_
.
exportValues
());
dht_
.
join
();
lock
.
unlock
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment