Skip to content

Commit

Permalink
fixed bugs when authenticating in I2TCP server end up in infinite loo…
Browse files Browse the repository at this point in the history
…p issue
  • Loading branch information
i2cy committed Oct 2, 2022
1 parent 1ab3a81 commit a1894d0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .idea/I2cylib.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions i2cylib/network/I2TCP/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def __init__(self, key=b"I2TCPbasicKey", port=24678,
I2TCP server class I2TCP服务端类
:param key: str(or bytes), dynamic key for authentication 对称动态密钥
:param port: int, server port that to be bond 服务端要绑定的端口号
:param port: int, server port that to be bonded 服务端要绑定的端口号
:param max_con: int, max TCP connection(s) that allowed
to be accept at the same time 最大同时接受的连接数
to be accepted at the same time 最大同时接受的连接数
:param logger: Logger, server log output object 日志器(来自于i2cylib.utils.logger.logger.Logger)
:param secured_connection: bool, enable encryption in connection 启用安全加密层
:param max_buffer_size: int, max package buffer size for every handler 包缓冲区最大大小(单位:个)
Expand Down Expand Up @@ -56,7 +56,7 @@ def __init__(self, key=b"I2TCPbasicKey", port=24678,

def _mainloop_thread(self):
"""
over write server main loop
overwrite server main loop
:return: None
"""
Expand Down Expand Up @@ -147,7 +147,7 @@ def _packager(self, data):

if self.flag_secured_connection_built: # 安全连接加密
assert isinstance(self.coder_pack, Iccode)
while self.flag_pack_busy:
while self.flag_pack_busy and self.live:
time.sleep(0.001)
self.flag_pack_busy = True
self.coder_pack.reset()
Expand Down
3 changes: 3 additions & 0 deletions i2cylib/network/I2TCP/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ def massive_send(clt, data):
logger = Logger()
srv = Server(port=24678, key=b"test", logger=logger, secured_connection=True)
clt = Client(port=24678, hostname="127.0.0.1", key=b"test", logger=logger)
ex_clt = Client(port=24678, hostname="127.0.0.1", key=b"asds", logger=logger)

srv.start()
ex_clt.connect()
time.sleep(1)
clt.connect()

data = b""
Expand Down
5 changes: 4 additions & 1 deletion i2cylib/network/i2tcp_basic/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@ def test():
if not clt.connect():
print("trying to connect to local test server")
clt.reset()
clt = I2TCPclient("localhost", logger=Logger(filename="client_testrun.log"))
clt = I2TCPclient("localhost", key=b"testtest123", logger=Logger(filename="client_testrun.log"))
clt.connect()
time.sleep(2)
clt = I2TCPclient("localhost", key=b"basic", logger=Logger(filename="client_testrun.log"))
clt.connect()
gtc = ""
for i in range(3):
Expand Down
3 changes: 3 additions & 0 deletions i2cylib/network/i2tcp_basic/base_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,9 @@ def _auth(self):
else:
self.logger.WARNING("{} unauthorized connection, key received: {}".format(self.log_header,
dynamic_key))
raise Exception("{} unauthorized connection, key received: {}".format(self.log_header,
dynamic_key))

feedback = b""
while len(feedback) < 2:
feedback += self.srv.recv(2 - len(feedback))
Expand Down

0 comments on commit a1894d0

Please sign in to comment.