Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
26d637f5
Commit
26d637f5
authored
Aug 20, 2021
by
Antoine Kaufmann
Browse files
dist: add NetEntryReceived to properly copy queue entry into queue
Just memcpy risks the received reading incomplete messages.
parent
014c076f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
10 deletions
+31
-10
dist/common/net.c
dist/common/net.c
+30
-10
dist/common/net.h
dist/common/net.h
+1
-0
No files found.
dist/common/net.c
View file @
26d637f5
...
...
@@ -160,16 +160,6 @@ int NetConnect() {
return
0
;
}
int
NetConnect
()
{
if
(
PeersInitNets
())
return
1
;
if
(
PeersInitDevs
())
return
1
;
return
0
;
}
int
NetPeerSendDevIntro
(
struct
Peer
*
peer
)
{
#ifdef DEBUG
fprintf
(
stderr
,
"PeerDevSendIntro(%s)
\n
"
,
peer
->
sock_path
);
...
...
@@ -457,4 +447,34 @@ void NetPoll() {
if
(
report
)
NetOpPassReport
();
}
void
NetEntryReceived
(
struct
Peer
*
peer
,
uint32_t
pos
,
void
*
data
)
{
uint64_t
off
=
(
uint64_t
)
pos
*
peer
->
cleanup_elen
;
void
*
entry
=
peer
->
cleanup_base
+
off
;
if
(
peer
->
is_dev
)
{
struct
SimbricksProtoNetD2NDummy
*
d2n
=
entry
;
// first copy data after header
memcpy
(
d2n
+
1
,
(
uint8_t
*
)
data
+
sizeof
(
*
d2n
),
peer
->
cleanup_elen
-
sizeof
(
*
d2n
));
// then copy header except for last byte
memcpy
(
entry
,
data
,
sizeof
(
*
d2n
)
-
1
);
// WMB()
// now copy last byte
struct
SimbricksProtoNetD2NDummy
*
src_d2n
=
data
;
d2n
->
own_type
=
src_d2n
->
own_type
;
}
else
{
struct
SimbricksProtoNetN2DDummy
*
n2d
=
entry
;
// first copy data after header
memcpy
(
n2d
+
1
,
(
uint8_t
*
)
data
+
sizeof
(
*
n2d
),
peer
->
cleanup_elen
-
sizeof
(
*
n2d
));
// then copy header except for last byte
memcpy
(
entry
,
data
,
sizeof
(
*
n2d
)
-
1
);
// WMB()
// now copy last byte
struct
SimbricksProtoNetN2DDummy
*
src_n2d
=
data
;
n2d
->
own_type
=
src_n2d
->
own_type
;
}
}
\ No newline at end of file
dist/common/net.h
View file @
26d637f5
...
...
@@ -103,6 +103,7 @@ int NetPeerSendDevIntro(struct Peer *peer);
int
NetPeerSetupNetQueues
(
struct
Peer
*
peer
);
int
NetPeerReport
(
struct
Peer
*
peer
,
uint32_t
written_pos
,
uint32_t
clean_pos
);
int
NetPeerEvent
(
struct
Peer
*
peer
,
uint32_t
events
);
void
NetEntryReceived
(
struct
Peer
*
peer
,
uint32_t
pos
,
void
*
data
);
// To be implemented in proxy implementation
int
NetOpPassIntro
(
struct
Peer
*
peer
);
...
...
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