Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Main
Synchronet
Commits
2ae025dc
Commit
2ae025dc
authored
5 months ago
by
Deucе
Browse files
Options
Downloads
Patches
Plain Diff
Move the transport state into the session struct.
This avoids another allocation/free requirement.
parent
8dc94392
No related branches found
No related tags found
No related merge requests found
Pipeline
#7371
passed
5 months ago
Stage: build
Stage: test
Stage: cleanup
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/ssh/deucessh.h
+8
-6
8 additions, 6 deletions
src/ssh/deucessh.h
src/ssh/ssh-trans.c
+44
-47
44 additions, 47 deletions
src/ssh/ssh-trans.c
src/ssh/ssh.c
+1
-1
1 addition, 1 deletion
src/ssh/ssh.c
with
53 additions
and
54 deletions
src/ssh/deucessh.h
+
8
−
6
View file @
2ae025dc
...
...
@@ -30,7 +30,12 @@ typedef int (*deuce_ssh_transport_io_cb_t)(uint8_t *buf, size_t bufsz, atomic_bo
typedef
int
(
*
deuce_ssh_transport_rxline_cb_t
)(
uint8_t
*
buf
,
size_t
bufsz
,
size_t
*
bytes_received
,
atomic_bool
*
terminate
,
void
*
cbdata
);
typedef
int
(
*
deuce_ssh_transport_extra_line_cb_t
)(
uint8_t
*
buf
,
size_t
bufsz
,
void
*
cbdata
);
typedef
struct
deuce_ssh_session
{
typedef
struct
deuce_ssh_session
*
deuce_ssh_session_t
;
#include
"ssh-arch.h"
#include
"ssh-trans.h"
struct
deuce_ssh_session
{
/* Global */
mtx_t
mtx
;
atomic_bool
initialized
;
...
...
@@ -47,8 +52,8 @@ typedef struct deuce_ssh_session {
void
*
rx_line_cbdata
;
void
*
extra_line_cbdata
;
deuce_ssh_transport_state
_t
trans
;
}
*
deuce_ssh_session_t
;
struct
deuce_ssh_transport_state
trans
;
};
int
deuce_ssh_session_init
(
deuce_ssh_session_t
sess
);
bool
deuce_ssh_session_terminate
(
deuce_ssh_session_t
sess
);
...
...
@@ -56,7 +61,4 @@ void deuce_ssh_session_cleanup(deuce_ssh_session_t sess);
int
deuce_ssh_transport_set_callbacks
(
deuce_ssh_transport_io_cb_t
tx
,
deuce_ssh_transport_io_cb_t
rx
,
deuce_ssh_transport_rxline_cb_t
rx_line
,
deuce_ssh_transport_extra_line_cb_t
extra_line_cb
);
#include
"ssh-arch.h"
#include
"ssh-trans.h"
#endif
This diff is collapsed.
Click to expand it.
src/ssh/ssh-trans.c
+
44
−
47
View file @
2ae025dc
...
...
@@ -156,9 +156,9 @@ tx_handshake(void *arg)
memcpy
(
&
tx_packet
[
sz
],
gconf
.
version_comment
,
asz
);
sz
+=
asz
;
}
memcpy
(
sess
->
trans
->
id_str
,
tx_packet
,
sz
);
sess
->
trans
->
id_str_sz
=
sz
;
sess
->
trans
->
id_str
[
sz
]
=
0
;
memcpy
(
sess
->
trans
.
id_str
,
tx_packet
,
sz
);
sess
->
trans
.
id_str_sz
=
sz
;
sess
->
trans
.
id_str
[
sz
]
=
0
;
memcpy
(
&
tx_packet
[
sz
],
"
\r\n
"
,
2
);
sz
+=
2
;
res
=
gconf
.
tx
(
tx_packet
,
sz
,
&
sess
->
terminate
,
sess
->
tx_cbdata
);
...
...
@@ -172,45 +172,45 @@ tx_handshake(void *arg)
void
deuce_ssh_transport_cleanup
(
deuce_ssh_session_t
sess
)
{
if
(
sess
->
trans
->
kex_selected
)
{
if
(
sess
->
trans
->
kex_selected
->
cleanup
!=
NULL
)
sess
->
trans
->
kex_selected
->
cleanup
(
sess
);
sess
->
trans
->
kex_selected
=
NULL
;
if
(
sess
->
trans
.
kex_selected
)
{
if
(
sess
->
trans
.
kex_selected
->
cleanup
!=
NULL
)
sess
->
trans
.
kex_selected
->
cleanup
(
sess
);
sess
->
trans
.
kex_selected
=
NULL
;
}
if
(
sess
->
trans
->
key_algo_selected
)
{
if
(
sess
->
trans
->
key_algo_selected
->
cleanup
!=
NULL
)
sess
->
trans
->
key_algo_selected
->
cleanup
(
sess
);
sess
->
trans
->
key_algo_selected
=
NULL
;
if
(
sess
->
trans
.
key_algo_selected
)
{
if
(
sess
->
trans
.
key_algo_selected
->
cleanup
!=
NULL
)
sess
->
trans
.
key_algo_selected
->
cleanup
(
sess
);
sess
->
trans
.
key_algo_selected
=
NULL
;
}
if
(
sess
->
trans
->
enc_c2s_selected
)
{
if
(
sess
->
trans
->
enc_c2s_selected
->
cleanup
!=
NULL
)
sess
->
trans
->
enc_c2s_selected
->
cleanup
(
sess
);
sess
->
trans
->
enc_c2s_selected
=
NULL
;
if
(
sess
->
trans
.
enc_c2s_selected
)
{
if
(
sess
->
trans
.
enc_c2s_selected
->
cleanup
!=
NULL
)
sess
->
trans
.
enc_c2s_selected
->
cleanup
(
sess
);
sess
->
trans
.
enc_c2s_selected
=
NULL
;
}
if
(
sess
->
trans
->
enc_s2c_selected
)
{
if
(
sess
->
trans
->
enc_s2c_selected
->
cleanup
!=
NULL
)
sess
->
trans
->
enc_s2c_selected
->
cleanup
(
sess
);
sess
->
trans
->
enc_s2c_selected
=
NULL
;
if
(
sess
->
trans
.
enc_s2c_selected
)
{
if
(
sess
->
trans
.
enc_s2c_selected
->
cleanup
!=
NULL
)
sess
->
trans
.
enc_s2c_selected
->
cleanup
(
sess
);
sess
->
trans
.
enc_s2c_selected
=
NULL
;
}
if
(
sess
->
trans
->
mac_c2s_selected
)
{
if
(
sess
->
trans
->
mac_c2s_selected
->
cleanup
!=
NULL
)
sess
->
trans
->
mac_c2s_selected
->
cleanup
(
sess
);
sess
->
trans
->
mac_c2s_selected
=
NULL
;
if
(
sess
->
trans
.
mac_c2s_selected
)
{
if
(
sess
->
trans
.
mac_c2s_selected
->
cleanup
!=
NULL
)
sess
->
trans
.
mac_c2s_selected
->
cleanup
(
sess
);
sess
->
trans
.
mac_c2s_selected
=
NULL
;
}
if
(
sess
->
trans
->
mac_s2c_selected
)
{
if
(
sess
->
trans
->
mac_s2c_selected
->
cleanup
!=
NULL
)
sess
->
trans
->
mac_s2c_selected
->
cleanup
(
sess
);
sess
->
trans
->
mac_s2c_selected
=
NULL
;
if
(
sess
->
trans
.
mac_s2c_selected
)
{
if
(
sess
->
trans
.
mac_s2c_selected
->
cleanup
!=
NULL
)
sess
->
trans
.
mac_s2c_selected
->
cleanup
(
sess
);
sess
->
trans
.
mac_s2c_selected
=
NULL
;
}
if
(
sess
->
trans
->
comp_c2s_selected
)
{
if
(
sess
->
trans
->
comp_c2s_selected
->
cleanup
!=
NULL
)
sess
->
trans
->
comp_c2s_selected
->
cleanup
(
sess
);
sess
->
trans
->
comp_c2s_selected
=
NULL
;
if
(
sess
->
trans
.
comp_c2s_selected
)
{
if
(
sess
->
trans
.
comp_c2s_selected
->
cleanup
!=
NULL
)
sess
->
trans
.
comp_c2s_selected
->
cleanup
(
sess
);
sess
->
trans
.
comp_c2s_selected
=
NULL
;
}
if
(
sess
->
trans
->
comp_s2c_selected
)
{
if
(
sess
->
trans
->
comp_s2c_selected
->
cleanup
!=
NULL
)
sess
->
trans
->
comp_s2c_selected
->
cleanup
(
sess
);
sess
->
trans
->
comp_s2c_selected
=
NULL
;
if
(
sess
->
trans
.
comp_s2c_selected
)
{
if
(
sess
->
trans
.
comp_s2c_selected
->
cleanup
!=
NULL
)
sess
->
trans
.
comp_s2c_selected
->
cleanup
(
sess
);
sess
->
trans
.
comp_s2c_selected
=
NULL
;
}
sess
->
remote_software_id_string_sz
=
0
;
...
...
@@ -230,9 +230,6 @@ deuce_ssh_transport_init(deuce_ssh_session_t sess)
if
(
gconf
.
software_version
==
NULL
)
gconf
.
software_version
=
sw_ver
;
sess
->
trans
=
calloc
(
1
,
sizeof
(
struct
deuce_ssh_transport_state
));
if
(
sess
->
trans
==
NULL
)
return
DEUCE_SSH_ERROR_ALLOC
;
thrd_t
thrd
;
if
(
thrd_create
(
&
thrd
,
rx_thread
,
sess
)
!=
thrd_success
)
return
DEUCE_SSH_ERROR_INIT
;
...
...
@@ -243,15 +240,15 @@ deuce_ssh_transport_init(deuce_ssh_session_t sess)
thrd_join
(
thrd
,
&
tres
);
return
res
;
}
sess
->
trans
->
kex_selected
=
NULL
;
sess
->
trans
->
key_algo_selected
=
NULL
;
sess
->
trans
->
enc_c2s_selected
=
NULL
;
sess
->
trans
->
enc_s2c_selected
=
NULL
;
sess
->
trans
->
mac_c2s_selected
=
NULL
;
sess
->
trans
->
mac_s2c_selected
=
NULL
;
sess
->
trans
->
comp_c2s_selected
=
NULL
;
sess
->
trans
->
comp_s2c_selected
=
NULL
;
sess
->
trans
->
transport_thread
=
thrd
;
sess
->
trans
.
kex_selected
=
NULL
;
sess
->
trans
.
key_algo_selected
=
NULL
;
sess
->
trans
.
enc_c2s_selected
=
NULL
;
sess
->
trans
.
enc_s2c_selected
=
NULL
;
sess
->
trans
.
mac_c2s_selected
=
NULL
;
sess
->
trans
.
mac_s2c_selected
=
NULL
;
sess
->
trans
.
comp_c2s_selected
=
NULL
;
sess
->
trans
.
comp_s2c_selected
=
NULL
;
sess
->
trans
.
transport_thread
=
thrd
;
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
src/ssh/ssh.c
+
1
−
1
View file @
2ae025dc
...
...
@@ -22,7 +22,7 @@ deuce_ssh_session_terminate(deuce_ssh_session_t sess)
if
(
atomic_compare_exchange_strong
(
&
sess
->
initialized
,
&
t
,
false
))
{
sess
->
terminate
=
true
;
int
tres
;
thrd_join
(
sess
->
trans
->
transport_thread
,
&
tres
);
thrd_join
(
sess
->
trans
.
transport_thread
,
&
tres
);
sess
->
terminate
=
false
;
return
true
;
}
...
...
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