Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
udp-forwarder-ex
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
udp-forwarder-ex
Commits
33ab3dd2
There was an error fetching the commit references. Please try again later.
Unverified
Commit
33ab3dd2
authored
4 years ago
by
Bensong Liu
Browse files
Options
Downloads
Patches
Plain Diff
do some bugfix
parent
33bc11f5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/protocols/plain.hpp
+12
-6
12 additions, 6 deletions
src/protocols/plain.hpp
src/utils.hpp
+1
-1
1 addition, 1 deletion
src/utils.hpp
with
13 additions
and
7 deletions
src/protocols/plain.hpp
+
12
−
6
View file @
33ab3dd2
...
@@ -66,19 +66,21 @@ namespace Protocols {
...
@@ -66,19 +66,21 @@ namespace Protocols {
auto
onEvent
=
[
&
](
auto
activeFd
)
{
auto
onEvent
=
[
&
](
auto
activeFd
)
{
if
(
activeFd
==
ipcPipe
)
{
if
(
activeFd
==
ipcPipe
)
{
// Outbound gave me a message to forward! Send it.
// Outbound gave me a message to forward! Send it.
rlog
.
debug
(
"Inbound event: from outbound msg. "
);
auto
targetClientId
=
rlib
::
sockIO
::
recv_msg
(
activeFd
);
auto
targetClientId
=
rlib
::
sockIO
::
recv_msg
(
activeFd
);
auto
msg
=
rlib
::
sockIO
::
recv_msg
(
activeFd
);
auto
msg
=
rlib
::
sockIO
::
recv_msg
(
activeFd
);
auto
clientAddr
=
ClientIdUtils
::
parseClientId
(
targetClientId
);
auto
clientAddr
=
ClientIdUtils
::
parseClientId
(
targetClientId
);
auto
status
=
sendto
(
udpSenderSocket
,
msg
.
data
(),
msg
.
size
(),
0
,
&
clientAddr
.
addr
,
clientAddr
.
len
);
auto
status
=
sendto
(
listenFd
,
msg
.
data
(),
msg
.
size
(),
0
,
&
clientAddr
.
addr
,
clientAddr
.
len
);
dynamic_assert
(
status
!=
-
1
,
"sendto failed"
);
dynamic_assert
(
status
!=
-
1
,
"sendto failed"
);
}
}
else
if
(
activeFd
==
listenFd
)
{
else
if
(
activeFd
==
listenFd
)
{
rlog
.
debug
(
"Inbound event: from client msg. "
);
SockAddr
clientAddr
;
SockAddr
clientAddr
;
auto
msgLength
=
recvfrom
(
activeFd
,
msgBuffer
.
data
(),
msgBuffer
.
size
(),
0
,
&
clientAddr
.
addr
,
&
clientAddr
.
len
);
auto
msgLength
=
recvfrom
(
activeFd
,
msgBuffer
.
data
(),
msgBuffer
.
size
(),
0
,
&
clientAddr
.
addr
,
&
clientAddr
.
len
);
dynamic_assert
(
msgLength
!=
-
1
,
"recvfrom failed"
);
dynamic_assert
(
msgLength
!=
-
1
,
"recvfrom failed"
);
forwardMessageToOutbound
(
msgBuffer
.
substr
(
msgLength
),
ClientIdUtils
::
makeClientId
(
clientAddr
));
forwardMessageToOutbound
(
msgBuffer
.
substr
(
0
,
msgLength
),
ClientIdUtils
::
makeClientId
(
clientAddr
));
}
}
};
};
...
@@ -136,6 +138,7 @@ namespace Protocols {
...
@@ -136,6 +138,7 @@ namespace Protocols {
std
::
string
msgBuffer
(
DGRAM_BUFFER_SIZE
,
'\0'
);
std
::
string
msgBuffer
(
DGRAM_BUFFER_SIZE
,
'\0'
);
auto
onEvent
=
[
&
](
auto
activeFd
)
{
auto
onEvent
=
[
&
](
auto
activeFd
)
{
if
(
activeFd
==
ipcPipe
)
{
if
(
activeFd
==
ipcPipe
)
{
rlog
.
debug
(
"Outbound event: from inbound msg. "
);
// Inbound gave me a message to forward! Send it.
// Inbound gave me a message to forward! Send it.
auto
targetClientId
=
rlib
::
sockIO
::
recv_msg
(
activeFd
);
auto
targetClientId
=
rlib
::
sockIO
::
recv_msg
(
activeFd
);
auto
msg
=
rlib
::
sockIO
::
recv_msg
(
activeFd
);
auto
msg
=
rlib
::
sockIO
::
recv_msg
(
activeFd
);
...
@@ -146,18 +149,21 @@ namespace Protocols {
...
@@ -146,18 +149,21 @@ namespace Protocols {
rlib
::
sockIO
::
quick_send
(
iter
->
second
,
msg
);
// udp
rlib
::
sockIO
::
quick_send
(
iter
->
second
,
msg
);
// udp
}
}
else
{
else
{
rlog
.
debug
(
"create new conn to server. "
);
// This clientId is new. I don't know how to listen many sockets for response, so I just issue `connect` just like TCP does.
// This clientId is new. I don't know how to listen many sockets for response, so I just issue `connect` just like TCP does.
auto
connFd
=
rlib
::
quick_connect
(
serverAddr
,
serverPort
,
true
);
auto
connFd
=
rlib
::
quick_connect
(
serverAddr
,
serverPort
,
true
);
epoll_add_fd
(
epollFd
,
connFd
);
epoll_add_fd
(
epollFd
,
connFd
);
connectionMap
.
add
(
targetClientId
,
connFd
);
connectionMap
.
add
(
targetClientId
,
connFd
);
rlib
::
sockIO
::
quick_send
(
connFd
,
msg
);
// udp
rlib
::
sockIO
::
quick_send
(
connFd
,
msg
);
// udp
// send(connFd, msg.data(), msg.size(), MSG_DONTWAIT);
}
}
}
}
else
{
else
{
rlog
.
debug
(
"Outbound msg: from server msg. "
);
// Message from some connFd. Read and forward it.
// Message from some connFd. Read and forward it.
auto
status
=
recv
(
activeFd
,
msgBuffer
.
data
(),
msgBuffer
.
size
(),
0
);
auto
msgLength
=
recv
(
activeFd
,
msgBuffer
.
data
(),
msgBuffer
.
size
(),
0
);
dynamic_assert
(
status
!=
-
1
,
"recv failed"
);
dynamic_assert
(
msgLength
!=
-
1
,
"recv failed"
);
if
(
status
==
0
)
{
if
(
msgLength
==
0
)
{
// TODO: close the socket, and notify Inbound to destory data structures.
// TODO: close the socket, and notify Inbound to destory data structures.
epoll_del_fd
(
epollFd
,
activeFd
);
epoll_del_fd
(
epollFd
,
activeFd
);
connectionMap
.
del
(
activeFd
);
connectionMap
.
del
(
activeFd
);
...
@@ -166,7 +172,7 @@ namespace Protocols {
...
@@ -166,7 +172,7 @@ namespace Protocols {
dynamic_assert
(
connectionMap
.
server2client
.
count
(
activeFd
)
>
0
,
"connectionMap MUST contain server connfd. "
);
dynamic_assert
(
connectionMap
.
server2client
.
count
(
activeFd
)
>
0
,
"connectionMap MUST contain server connfd. "
);
forwardMessageToInbound
(
msgBuffer
.
substr
(
0
,
status
),
connectionMap
.
server2client
.
at
(
activeFd
));
forwardMessageToInbound
(
msgBuffer
.
substr
(
0
,
msgLength
),
connectionMap
.
server2client
.
at
(
activeFd
));
}
}
};
};
...
...
This diff is collapsed.
Click to expand it.
src/utils.hpp
+
1
−
1
View file @
33ab3dd2
...
@@ -23,7 +23,7 @@ struct SockAddr {
...
@@ -23,7 +23,7 @@ struct SockAddr {
sockaddr_in
in4
;
sockaddr_in
in4
;
sockaddr_in6
in6
;
sockaddr_in6
in6
;
};
};
socklen_t
len
;
socklen_t
len
=
sizeof
(
sockaddr_storage
)
;
};
};
struct
ClientIdUtils
{
struct
ClientIdUtils
{
...
...
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