simple-proxy 0.0.4__tar.gz → 0.0.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: simple-proxy
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Summary: A very simple NIO TCP proxy server
5
5
  Home-page: https://github.com/ruanhao/simple-proxy
6
6
  Author: Hao Ruan
@@ -22,7 +22,7 @@ config = {
22
22
  'keywords': ['network', 'tcp', 'non-blocking', 'proxy'],
23
23
  'version': __version__,
24
24
  'packages': find_packages(),
25
- 'install_requires': ['click', 'py-netty==0.0.39', 'cryptography>=39.0.1'],
25
+ 'install_requires': ['click', 'py-netty', 'cryptography', 'attrs'],
26
26
  'python_requires': ">=3.7, <4",
27
27
  'setup_requires': ['wheel'],
28
28
  'package_data': {'simple_proxy': ['*']},
@@ -4,6 +4,7 @@ import ssl
4
4
  from functools import wraps
5
5
  from py_netty.handler import LoggingChannelHandler
6
6
  from py_netty import Bootstrap, ServerBootstrap, EventLoopGroup
7
+ from py_netty.channel import NioSocketChannel
7
8
  import traceback
8
9
  import sys
9
10
  import os
@@ -188,22 +189,26 @@ def sneaky():
188
189
 
189
190
 
190
191
  @sneaky()
191
- def _handle(buffer, direction, src, dst, print_content, to_file):
192
- try:
193
- src_ip, src_port = src.getpeername()[:2]
194
- dst_ip, dst_port = dst.getpeername()[:2]
195
- except OSError:
196
- return buffer
192
+ def _handle(buffer: bytes, direction: bool, src: NioSocketChannel, dst: NioSocketChannel, print_content: bool, to_file: bool):
193
+ # try:
194
+ # src_ip, src_port = src.getpeername()[:2]
195
+ # dst_ip, dst_port = dst.getpeername()[:2]
196
+ # except OSError:
197
+ # return buffer
198
+
199
+ src_ip, src_port = src.channelinfo().peername
200
+ dst_ip, dst_port = dst.channelinfo().peername
197
201
 
198
202
  raddr = (src_ip, src_port) if direction else (dst_ip, dst_port)
199
- client = _clients[raddr]
203
+
200
204
  if buffer:
201
- if direction:
202
- client.read(len(buffer))
203
- else:
204
- client.write(len(buffer))
205
+ client = _clients.get(raddr)
206
+ if client:
207
+ if direction:
208
+ client.read(len(buffer))
209
+ else:
210
+ client.write(len(buffer))
205
211
  else: # EOF
206
- del _clients[raddr]
207
212
  return buffer
208
213
 
209
214
  if not print_content and not to_file:
@@ -296,7 +301,7 @@ class ProxyChannelHandler(LoggingChannelHandler):
296
301
  class _ChannelHandler(LoggingChannelHandler):
297
302
 
298
303
  def channel_read(this, ctx, bytebuf):
299
- _handle(bytebuf, False, ctx.channel().socket(), ctx0.channel().socket(), self._content, self._to_file)
304
+ _handle(bytebuf, False, ctx.channel(), ctx0.channel(), self._content, self._to_file)
300
305
  ctx0.write(bytebuf)
301
306
 
302
307
  def channel_inactive(this, ctx):
@@ -338,7 +343,7 @@ class ProxyChannelHandler(LoggingChannelHandler):
338
343
  self._client_channel(ctx, self._remote_host, self._remote_port)
339
344
  _clients[self.raddr].proxy_socket = self._client.socket()
340
345
 
341
- _handle(bytebuf, True, ctx.channel().socket(), self._client.socket(), self._content, self._to_file)
346
+ _handle(bytebuf, True, ctx.channel(), self._client, self._content, self._to_file)
342
347
  self._client.write(bytebuf)
343
348
 
344
349
  def channel_inactive(self, ctx):
@@ -105,22 +105,22 @@ def from_module(filename=None):
105
105
  return os.path.join(module_path(mod), filename)
106
106
 
107
107
 
108
- def getpeername(sock: socket.socket) -> str:
108
+ def _get_address_str(sock: socket.socket, peer: bool = False) -> str:
109
109
  if not sock:
110
110
  return '?'
111
111
  try:
112
- return ':'.join(map(str, sock.getpeername()))
112
+ addr_tuple = sock.getpeername() if peer else sock.getsockname()
113
+ return ':'.join(map(str, addr_tuple[:2]))
113
114
  except OSError:
114
- return '?'
115
+ return '!'
116
+
117
+
118
+ def getpeername(sock: socket.socket) -> str:
119
+ return _get_address_str(sock, peer=True)
115
120
 
116
121
 
117
122
  def getsockname(sock: socket.socket) -> str:
118
- if not sock:
119
- return '?'
120
- try:
121
- return ':'.join(map(str, sock.getsockname()))
122
- except OSError:
123
- return '?'
123
+ return _get_address_str(sock, peer=False)
124
124
 
125
125
 
126
126
  def generate_private_key():
@@ -0,0 +1 @@
1
+ __version__ = "0.0.6"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: simple-proxy
3
- Version: 0.0.4
3
+ Version: 0.0.6
4
4
  Summary: A very simple NIO TCP proxy server
5
5
  Home-page: https://github.com/ruanhao/simple-proxy
6
6
  Author: Hao Ruan
@@ -0,0 +1,4 @@
1
+ click
2
+ py-netty
3
+ cryptography
4
+ attrs
@@ -1 +0,0 @@
1
- __version__ = "0.0.4"
@@ -1,3 +0,0 @@
1
- click
2
- py-netty==0.0.39
3
- cryptography>=39.0.1
File without changes
File without changes
File without changes