Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dhtnet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
dhtnet
Commits
0cf544d4
Commit
0cf544d4
authored
1 year ago
by
Amna Snene
Browse files
Options
Downloads
Patches
Plain Diff
ConnectionManager: add connectDevice(InfoHash)
Change-Id: I5179a05b63b4576f468d76c00f1aa9fe3c2e4083
parent
e5f2506a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/connectionmanager.h
+9
-0
9 additions, 0 deletions
include/connectionmanager.h
src/connectionmanager.cpp
+66
-0
66 additions, 0 deletions
src/connectionmanager.cpp
with
75 additions
and
0 deletions
include/connectionmanager.h
+
9
−
0
View file @
0cf544d4
...
...
@@ -72,6 +72,8 @@ using ChannelRequestCallback = std::function<bool(const std::shared_ptr<dht::cry
* Used by connectDevice, when the socket is ready
*/
using
ConnectCallback
=
std
::
function
<
void
(
const
std
::
shared_ptr
<
ChannelSocket
>&
,
const
DeviceId
&
)
>
;
using
ConnectCallbackLegacy
=
std
::
function
<
void
(
const
std
::
shared_ptr
<
ChannelSocket
>&
,
const
dht
::
InfoHash
&
)
>
;
/**
* Used when an incoming connection is ready
*/
...
...
@@ -111,6 +113,13 @@ public:
bool
noNewSocket
=
false
,
bool
forceNewSocket
=
false
,
const
std
::
string
&
connType
=
""
);
void
connectDevice
(
const
dht
::
InfoHash
&
deviceId
,
const
std
::
string
&
name
,
ConnectCallbackLegacy
cb
,
bool
noNewSocket
=
false
,
bool
forceNewSocket
=
false
,
const
std
::
string
&
connType
=
""
);
void
connectDevice
(
const
std
::
shared_ptr
<
dht
::
crypto
::
Certificate
>&
cert
,
const
std
::
string
&
name
,
ConnectCallback
cb
,
...
...
This diff is collapsed.
Click to expand it.
src/connectionmanager.cpp
+
66
−
0
View file @
0cf544d4
...
...
@@ -148,6 +148,13 @@ public:
bool
noNewSocket
=
false
,
bool
forceNewSocket
=
false
,
const
std
::
string
&
connType
=
""
);
void
connectDevice
(
const
dht
::
InfoHash
&
deviceId
,
const
std
::
string
&
uri
,
ConnectCallbackLegacy
cb
,
bool
noNewSocket
=
false
,
bool
forceNewSocket
=
false
,
const
std
::
string
&
connType
=
""
);
void
connectDevice
(
const
std
::
shared_ptr
<
dht
::
crypto
::
Certificate
>&
cert
,
const
std
::
string
&
name
,
ConnectCallback
cb
,
...
...
@@ -602,6 +609,53 @@ ConnectionManager::Impl::connectDevice(const DeviceId& deviceId,
});
}
void
ConnectionManager
::
Impl
::
connectDevice
(
const
dht
::
InfoHash
&
deviceId
,
const
std
::
string
&
name
,
ConnectCallbackLegacy
cb
,
bool
noNewSocket
,
bool
forceNewSocket
,
const
std
::
string
&
connType
)
{
if
(
!
dht
())
{
cb
(
nullptr
,
deviceId
);
return
;
}
if
(
deviceId
.
toString
()
==
identity
().
second
->
getLongId
().
toString
())
{
cb
(
nullptr
,
deviceId
);
return
;
}
findCertificate
(
deviceId
,
[
w
=
weak
(),
deviceId
,
name
,
cb
=
std
::
move
(
cb
),
noNewSocket
,
forceNewSocket
,
connType
](
const
std
::
shared_ptr
<
dht
::
crypto
::
Certificate
>&
cert
)
{
if
(
!
cert
)
{
if
(
auto
shared
=
w
.
lock
())
if
(
shared
->
config_
->
logger
)
shared
->
config_
->
logger
->
error
(
"No valid certificate found for device {}"
,
deviceId
);
cb
(
nullptr
,
deviceId
);
return
;
}
if
(
auto
shared
=
w
.
lock
())
{
shared
->
connectDevice
(
cert
,
name
,
[
cb
,
deviceId
](
const
std
::
shared_ptr
<
ChannelSocket
>&
sock
,
const
DeviceId
&
did
){
cb
(
sock
,
deviceId
);
},
noNewSocket
,
forceNewSocket
,
connType
);
}
else
cb
(
nullptr
,
deviceId
);
});
}
void
ConnectionManager
::
Impl
::
connectDevice
(
const
std
::
shared_ptr
<
dht
::
crypto
::
Certificate
>&
cert
,
const
std
::
string
&
name
,
...
...
@@ -1534,6 +1588,18 @@ ConnectionManager::connectDevice(const DeviceId& deviceId,
pimpl_
->
connectDevice
(
deviceId
,
name
,
std
::
move
(
cb
),
noNewSocket
,
forceNewSocket
,
connType
);
}
void
ConnectionManager
::
connectDevice
(
const
dht
::
InfoHash
&
deviceId
,
const
std
::
string
&
name
,
ConnectCallbackLegacy
cb
,
bool
noNewSocket
,
bool
forceNewSocket
,
const
std
::
string
&
connType
)
{
pimpl_
->
connectDevice
(
deviceId
,
name
,
std
::
move
(
cb
),
noNewSocket
,
forceNewSocket
,
connType
);
}
void
ConnectionManager
::
connectDevice
(
const
std
::
shared_ptr
<
dht
::
crypto
::
Certificate
>&
cert
,
const
std
::
string
&
name
,
...
...
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