Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
telemersion
Telemersive Switchboard
Commits
9238c23d
Commit
9238c23d
authored
Feb 19, 2021
by
Roman Haefeli
Browse files
Mirror: add logger and catch all
parent
6d1b0a91
Changes
2
Hide whitespace changes
Inline
Side-by-side
proxies/udp_mirror.py
View file @
9238c23d
...
...
@@ -5,6 +5,7 @@
udp_mirror: reflects udp packets to their origin
"""
import
logging
import
socket
import
sys
import
threading
...
...
@@ -16,7 +17,7 @@ class MirrorProxy(threading.Thread):
purposes.
"""
def
__init__
(
self
,
listen_port
=
None
,
listen_address
=
'0.0.0.0'
):
def
__init__
(
self
,
listen_port
=
None
,
listen_address
=
'0.0.0.0'
,
logger
=
None
):
super
(
MirrorProxy
,
self
).
__init__
()
if
not
isinstance
(
listen_port
,
int
)
or
not
1024
<=
listen_port
<=
65535
:
raise
ValueError
(
'Specified port "%s" is invalid.'
%
listen_port
)
...
...
@@ -27,22 +28,29 @@ class MirrorProxy(threading.Thread):
except
socket
.
error
as
msg
:
raise
self
.
kill_signal
=
False
self
.
logger
=
logger
def
run
(
self
):
while
not
self
.
kill_signal
:
try
:
data
,
addr
=
self
.
sock
.
recvfrom
(
65536
)
except
socket
.
timeout
:
continue
self
.
sock
.
sendto
(
data
,
addr
)
try
:
data
,
addr
=
self
.
sock
.
recvfrom
(
65536
)
except
socket
.
timeout
:
continue
self
.
sock
.
sendto
(
data
,
addr
)
except
:
self
.
logger
.
exception
(
'Oops, something went wrong!'
,
extra
=
{
'stack'
:
True
})
def
stop
(
self
):
self
.
kill_signal
=
True
self
.
join
()
def
main
():
logger
=
logging
.
getLogger
()
handler
=
logging
.
StreamHandler
(
sys
.
stderr
)
logger
.
addHandler
(
handler
)
try
:
proxy
=
MirrorProxy
(
listen_port
=
int
(
sys
.
argv
[
1
]))
proxy
=
MirrorProxy
(
listen_port
=
int
(
sys
.
argv
[
1
])
,
logger
=
logger
)
proxy
.
start
()
proxy
.
join
()
except
KeyboardInterrupt
:
...
...
proxies/udp_one2onebi.py
View file @
9238c23d
...
...
@@ -5,11 +5,11 @@
udp_one2onebi: for 1-to-1 connections
"""
import
logging
import
socket
import
sys
import
threading
import
time
import
logging
class
One2OneBiProxy
(
threading
.
Thread
):
"""
...
...
Write
Preview
Supports
Markdown
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