diff --git a/mitmaddon/littlesnitch.py b/mitmaddon/littlesnitch.py index 76a1f8d..94c6a17 100644 --- a/mitmaddon/littlesnitch.py +++ b/mitmaddon/littlesnitch.py @@ -2,12 +2,12 @@ import pdb from mitmproxy import ctx import threading -from queue import Queue +from queue import Queue, Empty import time import zmq import json -NO_MSG {"msg": None} +NO_MSG = {"msg": None} INIT_MSG = {"msg": "init"} ACK_MSG = {"msg": "ack"} PING_MSG = {"msg": "ping"} @@ -30,7 +30,7 @@ def get_msg(socket): if msg: return json.loads(msg) except json.JSONDecodeError: - print("malformed message received '{msg}'") + print(f"malformed message received {msg}") return NO_MSG @@ -68,7 +68,10 @@ def networking(q): timer = time.monotonic() if not a: - a = q.get(block=False) + try: + a = q.get(block=False) + except Empty: + pass if a: send_msg(a, socket) msg = get_msg(socket) diff --git a/networkthread.cpp b/networkthread.cpp index 55a82ad..9216749 100644 --- a/networkthread.cpp +++ b/networkthread.cpp @@ -19,12 +19,12 @@ void NetworkThread::process() { while(true){ bool connected = false; - while(!connected) { - sock.send(zmq::str_buffer("{'type': 'init'}"), zmq::send_flags::dontwait); + while(!connected) { + sock.send(zmq::buffer(INIT_MSG_STR.c_str(), INIT_MSG_STR.length()), zmq::send_flags::dontwait); zmq::message_t msg; const auto ret = sock.recv(msg, zmq::recv_flags::dontwait); if(ret) { - if(msg.to_string() == "{'type': 'ack'}") { + if(msg.to_string() == ACK_MSG_STR) { connected = true; } } diff --git a/networkthread.h b/networkthread.h index d0b6d93..2985179 100644 --- a/networkthread.h +++ b/networkthread.h @@ -3,7 +3,8 @@ #include #include -const auto INIT_MSG = R"({"msg": "init"})"_json; +const std::string INIT_MSG_STR = R"({"msg": "init"})"; +const std::string ACK_MSG_STR = R"({"msg": "ack"})"; class NetworkThread : public QObject {