X Tutup
Skip to content

Commit 1b4dfca

Browse files
authored
fix ss udp bug
1 parent eace2d3 commit 1b4dfca

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

pproxy/__doc__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__title__ = "pproxy"
2-
__version__ = "1.9.1"
2+
__version__ = "1.9.4"
33
__license__ = "MIT"
44
__description__ = "Proxy server that can tunnel among remote servers by regex rules."
55
__keywords__ = "proxy socks http shadowsocks shadowsocksr ssr redirect pf tunnel cipher ssl udp"

pproxy/proto.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def udp_parse(self, data, **kw):
3737
raise Exception(f'{self.name} don\'t support UDP server')
3838
def udp_connect(self, rauth, host_name, port, data, **kw):
3939
raise Exception(f'{self.name} don\'t support UDP client')
40+
def udp_client(self, data):
41+
return data
42+
def udp_client2(self, host_name, port, data):
43+
return data
4044
async def connect(self, reader_remote, writer_remote, rauth, host_name, port, **kw):
4145
raise Exception(f'{self.name} don\'t support client')
4246
async def channel(self, reader, writer, stat_bytes, stat_conn):
@@ -143,6 +147,17 @@ def udp_parse(self, data, auth, **kw):
143147
return
144148
host_name, port = socks_address(reader, n)
145149
return host_name, port, reader.read()
150+
def udp_client(self, data):
151+
reader = io.BytesIO(data)
152+
n = reader.read(1)[0]
153+
host_name, port = socks_address(reader, n)
154+
return reader.read()
155+
def udp_client2(self, host_name, port, data):
156+
try:
157+
return b'\x01' + socket.inet_aton(host_name) + port.to_bytes(2, 'big') + data
158+
except Exception:
159+
pass
160+
return b'\x03' + packstr(host_name.encode()) + port.to_bytes(2, 'big') + data
146161
def udp_connect(self, rauth, host_name, port, data, **kw):
147162
return rauth + b'\x03' + packstr(host_name.encode()) + port.to_bytes(2, 'big') + data
148163

pproxy/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ async def datagram_handler(writer, data, addr, protos, urserver, block, cipher,
156156
verbose(f'UDP {lproto.name} {remote_text}{roption.logtext(host_name, port)}')
157157
data = roption.prepare_udp_connection(host_name, port, data)
158158
def reply(rdata):
159+
rdata = lproto.udp_client2(host_name, port, rdata)
159160
writer.sendto(cipher.datagram.encrypt(rdata) if cipher else rdata, addr)
160161
await roption.open_udp_connection(host_name, port, data, addr, reply)
161162
except Exception as ex:
@@ -220,7 +221,9 @@ def new_data_arrived(prot, data):
220221
else:
221222
prot.databuf.append(data)
222223
def datagram_received(prot, data, addr):
223-
reply(self.cipher.datagram.decrypt(data) if self.cipher else data)
224+
data = self.cipher.datagram.decrypt(data) if self.cipher else data
225+
data = self.rproto.udp_client(data) if not self.direct else data
226+
reply(data)
224227
def connection_lost(prot, exc):
225228
self.udpmap.pop(addr)
226229
if addr in self.udpmap:

0 commit comments

Comments
 (0)
X Tutup