Ejemplo n.º 1
0
def sendRequestBlock():
    with registerThread(connection):
        main = slave.mainObject()
        if slave.requestBlock(main, {"number": 3}, "requestBlock", None, True,
                              slave.IP, False):
            return "OK"

        return "Error"
Ejemplo n.º 2
0
def init():
    with registerThread(connection):
        with open("top_secret_data.pkl", "rb") as pfile:
            data = pickle.load(pfile)
            if slave.initKey(data[slave.name][0],
                             data[slave.mainObject().name]):
                return "OK"

            return "Error"
Ejemplo n.º 3
0
def init():
    with registerThread(connection):
        res = main.firstInit()

        if res == {}:
            return "Error"

        print(res)
        with open("top_secret_data.pkl", "wb") as pfile:
            pickle.dump(res, pfile)
            return "OK"
Ejemplo n.º 4
0
def objectTurned():
    with registerThread(connection):
        return main.objectTurned(request.form)
Ejemplo n.º 5
0
def sendBlock():
    with registerThread(connection):
        return main.sendBlocks(request.form)
Ejemplo n.º 6
0
def shareBlock():
    with registerThread(connection):
        if main.shareBlock():
            return "OK"

        return "Error"
Ejemplo n.º 7
0
def requestKeys():
    with registerThread(connection):
        if main.requestNewKeys():
            return "OK"

        return "Error"
Ejemplo n.º 8
0
    def wrapper(self, obj, data, where, resp, thread, other, check):
        if other is None:
            data = {"data": self.createMsg(data)}
        else:
            data = {"data": self.createMsg(data), "other": other}

        if thread:
            with registerThread(self.connection):
                response = None
                try:
                    response = requests.post("http://" + obj.IP + "/" + where,
                                             data=data)
                except requests.exceptions.RequestException as e:
                    self.alert("Connection error with object. " + str(e), 5,
                               obj)
                    return
                except requests.exceptions.HTTPError as e:
                    self.alert("Connection error with object. " + str(e), 5,
                               obj)
                    return

                lock = Lock()
                with lock:
                    print(response.text)
                    if response.status_code != 200:
                        self.alert(
                            "Status code error: %d" % response.status_code, 6,
                            obj)
                        return

                    if check:
                        resp = obj.checkMsg(response.text)
                    else:
                        resp = response.text

                    return procces_func(self, obj, data, where, resp, thread,
                                        other, check)
        else:
            response = None
            try:
                response = requests.post("http://" + obj.IP + "/" + where,
                                         data=data)
            except requests.exceptions.RequestException as e:
                self.alert("Connection error with object. " + str(e), 5, obj)
                return
            except requests.exceptions.HTTPError as e:
                self.alert("Connection error with object. " + str(e), 5, obj)
                return

            print(response.text)
            if response.status_code != 200:
                self.alert("Status code error: %d" % response.status_code, 6,
                           obj)
                return

            if check:
                resp = obj.checkMsg(response.text)
            else:
                resp = response.text

            return procces_func(self, obj, data, where, resp, thread, other,
                                check)
Ejemplo n.º 9
0
def turnOn():
    with registerThread(connection):
        if slave.turn(on=True):
            return "OK"

        return "Error"
Ejemplo n.º 10
0
def turnOff():
    with registerThread(connection):
        if slave.turn(on=False):
            return "OK"

        return "Error"
Ejemplo n.º 11
0
def requestNewKey():
    with registerThread(connection):
        return slave.generateNewKeys(request.form)
Ejemplo n.º 12
0
def updateBlock():
    with registerThread(connection):
        return slave.updateBlock(request.form)