Skip to content

Commit

Permalink
Able to start aider without unlocker
Browse files Browse the repository at this point in the history
  • Loading branch information
shinkuan committed Feb 19, 2024
1 parent 170e33f commit 0aa81a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
14 changes: 7 additions & 7 deletions mitm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import mitmproxy.log
import mitmproxy.tcp
import mitmproxy.websocket
import mhm
from pathlib import Path
from optparse import OptionParser
from mitmproxy import proxy, options, ctx
Expand Down Expand Up @@ -71,9 +70,9 @@ async def start_proxy(host, port, enable_unlocker):
)
master.addons.add(ClientWebSocket())
master.addons.add(ClientHTTP())
if enable_unlocker:
from mhm.addons import WebSocketAddon as Unlocker
master.addons.add(Unlocker())
# if enable_unlocker:
from mhm.addons import WebSocketAddon as Unlocker
master.addons.add(Unlocker())
await master.run()
return master

Expand Down Expand Up @@ -158,15 +157,16 @@ def serve_forever(self):
if opts.unlocker is not None:
enable_unlocker = bool(opts.unlocker)

print("fetching resver...")
mhm.fetch_resver()

with open("mhmp.json", "r") as f:
mhmp = json.load(f)
mhmp["mitmdump"]["mode"] = [f"regular@{mitm_port}"]
mhmp["hook"]["enable_skins"] = enable_unlocker
mhmp["hook"]["enable_aider"] = enable_helper
with open("mhmp.json", "w") as f:
json.dump(mhmp, f, indent=4)
import mhm
print("fetching resver...")
mhm.fetch_resver()
# Create and start the proxy server thread
proxy_thread = threading.Thread(target=lambda: asyncio.run(start_proxy(mitm_host, mitm_port, enable_unlocker)))
proxy_thread.start()
Expand Down
17 changes: 10 additions & 7 deletions simple_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import mitmproxy.log
import mitmproxy.tcp
import mitmproxy.websocket
import mhm
from pathlib import Path
from optparse import OptionParser
from mitmproxy import proxy, options, ctx
Expand All @@ -27,8 +26,6 @@
stop = False
SHOW_LIQI = False

mhm.logger.setLevel("WARNING")

class ClientWebSocket:
def __init__(self):
self.liqi: dict[str, LiqiProto]={}
Expand Down Expand Up @@ -171,9 +168,9 @@ async def start_proxy(host, port, enable_unlocker):
)
master.addons.add(ClientWebSocket())
master.addons.add(ClientHTTP())
if enable_unlocker:
from mhm.addons import WebSocketAddon as Unlocker
master.addons.add(Unlocker())
# if enable_unlocker:
from mhm.addons import WebSocketAddon as Unlocker
master.addons.add(Unlocker())
await master.run()
return master

Expand All @@ -187,18 +184,24 @@ async def start_proxy(host, port, enable_unlocker):
mitm_host="127.0.0.1"

print("fetching resver...")
mhm.fetch_resver()

with open("mhmp.json", "r") as f:
mhmp = json.load(f)
mhmp["mitmdump"]["mode"] = [f"regular@{mitm_port}"]
mhmp["hook"]["enable_skins"] = enable_unlocker
mhmp["hook"]["enable_aider"] = enable_helper
with open("mhmp.json", "w") as f:
json.dump(mhmp, f, indent=4)
import mhm
mhm.fetch_resver()
mhm.logger.setLevel("WARNING")

# Create and start the proxy server thread
proxy_thread = threading.Thread(target=lambda: asyncio.run(start_proxy(mitm_host, mitm_port, enable_unlocker)))
proxy_thread.start()



try:
while True:
time.sleep(1)
Expand Down

0 comments on commit 0aa81a4

Please sign in to comment.