Browse Source

add support for udp...

main
John-Mark Gurney 5 years ago
parent
commit
c203547c28
1 changed files with 34 additions and 0 deletions
  1. +34
    -0
      ntunnel/__init__.py

+ 34
- 0
ntunnel/__init__.py View File

@@ -171,6 +171,12 @@ _allowedparameters = {
'host': str,
'port': int,
},
'udp': {
'host': str,
'port': int,
'lclhost': str,
'lclport': int,
},
}

def parsesockstr(sockstr):
@@ -199,6 +205,21 @@ def parsesockstr(sockstr):
The host parameter specifies the host, and the
port parameter specifies the port of the
connection.

udp:
Default parameter is host[:port].
Note that the meaning depends upon if it is used
in a server context vs a client context. In the
server context, host and port specify the host to
bind to, and in the client context, specify the
remote host and port to connect to. In the case
of a client, there are also the lclhost and lclport
that can be specified to bind the local side of
the socket.

The host parameter specifies the host, and the
port parameter specifies the port of the
connection.
'''

proto, rem = sockstr.split(':', 1)
@@ -209,6 +230,10 @@ def parsesockstr(sockstr):

if proto == 'unix':
args = { 'path': rem }

if proto == 'udp':
h, p = rem.split(':')
args = { 'host': h, 'port': p }
else:
args = dict(i.split('=', 1) for i in rem.split(','))

@@ -535,6 +560,15 @@ class Tests_misc(unittest.TestCase):
'tcp:host=apath': ('tcp', { 'host': 'apath' }),
'tcp:host=apath,port=5': ('tcp', { 'host': 'apath',
'port': 5 }),
'udp:host=apath,port=5': ('udp', { 'host': 'apath',
'port': 5 }),
'udp:port=5': ('udp', { 'port': 5 }),
'udp:port=5,lclport=10,lclhost=foo': ('udp',
{ 'port': 5, 'lclport': 10, 'lclhost': 'foo' }),
'udp:apath:5': ('udp', { 'host': 'apath',
'port': 5 }),
'udp::5': ('udp', { 'host': '',
'port': 5 }),
}

for s, r in results.items():


Loading…
Cancel
Save