コード例 #1
0
ファイル: c_geth.py プロジェクト: maxilix/sesan_v2
    def end(self):

        if (self.proc):
            if (self.proc.poll() == None):
                self.proc.terminate()
                self.proc.wait()
                console.info("geth subprocess terminated")
            else:
                console.warn(
                    "geth subprocess already terminate with return code {0}".
                    format(self.proc.poll()))
        """
		# last logs
		newLog = self.log.readline().split(' ')
		while (newLog != ['']):
			index = 2
			message = ""
			while ((index < len(newLog)) and (newLog[index] != '') and ('"' not in newLog[index]) and ("=" not in newLog[index])):
				message += newLog[index]
				message += ' '
				index += 1
			if   (newLog[0] == "WARN"):
				console.warn(message)
			elif (newLog[0] == "INFO"):
				console.info(message)
			else:
				console.error(message)
			newLog = self.log.readline().split(' ')
		"""
        self.log.close()

        console.info("geth closed")
コード例 #2
0
ファイル: c_geth.py プロジェクト: maxilix/sesan_v2
 def get_enodeS(self):
     enodeS = self.w3.geth.admin.node_info()["enode"]
     ip = tools.get_public_ip()
     if ip not in enodeS:
         console.warn("public ip is {0} and enode ip is {1}".format(
             ip,
             enodeS.split('@')[1].split(':')[0]))
     return enodeS
コード例 #3
0
    def __received_frame(self, frame, contact):
        valid = False
        who = "{0}-newGuest".format(self.user[0])
        console.print("new connexion from {0}:{1}".format(
            contact[0], contact[1]),
                      who=who)

        try:
            if (frame[0] == BC_BEGIN_IDENTITY):
                console.bc(frame[0], who=who)
                index = 1
                while (frame[index] != BC_END_IDENTITY):
                    console.bc(frame[index], who=who)

                    if (frame[index] == BC_ERROR):
                        console.warn("identity frame aborted", who=who)
                        valid = False
                        return
                    elif (frame[index] == BC_RECEIVED_ENODE):
                        index += 1
                        newGuest.enodeB = frame[index:index + 70]
                        if (contact[0] != newGuest.ip()):
                            console.warn("guest's ip doesn't match", who=who)
                            valid = False
                            return
                        index += 70
                        #
                        #
                        #
                        valid = True
                    else:
                        valid = False
                        console.warn("invalid balise in identity frame",
                                     who=who)
                        return

                console.bc(frame[index], who=who)
                index += 1

                if (valid):
                    #
                    #
                    #
                    console.print("identity completed", who=who)
                    return
                else:
                    console.warn("incomplete identity", who=who)
                    return

            else:
                raise IndexError

        except IndexError:
            console.warn("bad frame construction from {0}:{1}".format(
                contact[0], contact[1]),
                         who=who)
            return
コード例 #4
0
ファイル: c_geth.py プロジェクト: maxilix/sesan_v2
    def __load_dealer(self):
        try:
            with open("{0}/.{1}.json".format(ROOT, GETH_DEALER_NAME),
                      'r') as fd:
                cfg = json.load(fd)

            self.dealer = self.w3.eth.contract(address=cfg["address"],
                                               abi=cfg["abi"])
            console.info("dealer contract loaded")
            return True
        except:
            console.warn("failed to load dealer contract")
            return False
コード例 #5
0
ファイル: c_geth.py プロジェクト: maxilix/sesan_v2
    def update(self):
        time.sleep(UPDATE_WAITING_TIME)

        newLog = self.log.readline()
        if "New local node record" in newLog:
            console.info("enode refresh")
        elif "Successfully sealed new block" in newLog:
            console.print("new block sealed : {0}".format(
                self.get_blocknumber()))
        elif "Block sealing failed" in newLog:
            console.warn("block sealing failed")
            self.forge(False)
        else:
            pass
        """
コード例 #6
0
    def update_udp(self):
        try:
            (frame, contact) = self.udpGuestSoc.recvfrom(FRAME_LENGHT)

            # split frame byte to byte
            frame = list(frame)

            n, frame = self.__check_identity_frame(frame, contact)
            if (n == -1):
                return
            elif (frame == []):
                console.warn("no command", who=self.guests[n].who)
                return
            else:
                self.__check_command_frame(self.guests[n], frame)

        except socket.timeout:
            return
コード例 #7
0
ファイル: c_geth.py プロジェクト: maxilix/sesan_v2
    def __load_eigentrust(self):
        try:
            with open("{0}/.{1}.json".format(ROOT, GETH_EIGENTRUST_NAME),
                      'r') as fd:
                cfg = json.load(fd)

            self.eigentrust = self.w3.eth.contract(address=cfg["address"],
                                                   abi=cfg["abi"])

            self.eigentrustEvents = dict()
            self.eigentrustEvents[
                "NewUser"] = self.eigentrust.events.NewUser.createFilter(
                    fromBlock=0)
            self.eigentrustEvents[
                "Vote"] = self.eigentrust.events.Vote.createFilter(fromBlock=0)

            console.info("eigentrust contract loaded")
            return True
        except:
            console.warn("failed to load eigentrust contract")
            return False
コード例 #8
0
    def __check_command_frame(self, guest, frame):
        try:
            if (frame[0] == BC_BEGIN_COMMAND):
                console.bc(frame[0], who=guest.who)
                index = 1
                while (frame[index] != BC_END_COMMAND):
                    console.bc(frame[index], who=guest.who)

                    if (frame[index] == BC_ERROR):
                        console.warn("command frame aborted", who=guest.who)
                        return

                    #elif (frame[index] == BC.):

                    else:
                        console.warn("invalid balise in command frame",
                                     who=who)
                        return

                console.bc(frame[index], who=guest.who)
                return
            else:
                raise IndexError

        except IndexError:
            console.warn("bad frame construction from {0}:{1}".format(
                contact[0], contact[1]),
                         who=who)
            return
コード例 #9
0
ファイル: c_client.py プロジェクト: maxilix/sesan_v2
    def __command(self, guest, frame):
        contact = ("".join(["{0}.".format(guest.ip[x])])[:-1],
                   255 * udpPyPort[0] + udpPyPort[1])

        try:
            if (frame[0] == BC_BEGIN_COMMAND):
                console.bc(frame[0], who=guest.who)
                index = 1
                while (frame[index] != BC_END_COMMAND):
                    console.bc(frame[index], who=guest.who)

                    if (frame[index] == BC_ERROR):
                        console.warn("command frame aborted", who=guest.who)
                        return

                    #elif (frame[index] == BC.):

                    else:
                        console.warn("invalid balise in command frame",
                                     who=who)
                        return

                console.bc(frame[index], who=guest.who)
                return
            else:
                raise IndexError

        except IndexError:
            console.warn("bad frame construction from {0}:{1}".format(
                contact[0], contact[1]),
                         who=who)
            return
コード例 #10
0
    def __check_identity_frame(self, frame, contact):

        valid = False
        newGuest = Guest(self.user[0])
        newGuest.udpContact = contact
        console.print("new connexion from {0}:{1}".format(
            contact[0], contact[1]),
                      who=newGuest.who)

        try:
            if (frame[0] == BC_BEGIN_IDENTITY):
                console.bc(frame[0], who=newGuest.who)
                index = 1
                while (frame[index] != BC_END_IDENTITY):
                    console.bc(frame[index], who=newGuest.who)

                    if (frame[index] == BC_ERROR):
                        console.warn("identity frame aborted",
                                     who=newGuest.who)
                        valid = False
                        return -1, []
                    elif (frame[index] == BC_RECEIVED_ENODE):
                        index += 1
                        newGuest.enodeB = frame[index:index + 70]
                        if (contact[0] != newGuest.ip()):
                            console.warn("guest's ip doesn't match",
                                         who=newGuest.who)
                            valid = False
                            return -1, []
                        index += 70
                        valid = True
                    elif (frame[index] == BC_RECEIVED_ADDRESS):
                        index += 1
                        newGuest.addressB = frame[index:index + 20]
                        index += 20
                    else:
                        valid = False
                        console.warn("invalid balise in identity frame",
                                     who=newGuest.who)
                        return -1, []

                console.bc(frame[index], who=newGuest.who)
                index += 1

                if (valid and newGuest.update()):
                    n = self.__guest_exist(newGuest)
                    if (n == -1):
                        self.guests.append(newGuest)
                        n = len(self.guests) - 1
                    else:
                        self.guests[n] = newGuest
                    console.print("identity completed", who=newGuest.who)
                    return n, frame[index:]
                else:
                    console.warn("incomplete identity", who=newGuest.who)
                    return -1, []

            else:
                raise IndexError

        except IndexError:
            console.warn("bad frame construction from {0}:{1}".format(
                contact[0], contact[1]),
                         who=newGuest.who)
            return -1, []
コード例 #11
0
ファイル: c_client.py プロジェクト: maxilix/sesan_v2
    def __identity(self, frame, contact):

        valid = False
        newGuest = Guest(self.username)
        console.print("new connexion from {0}:{1}".format(
            contact[0], contact[1]),
                      who=newGuest.who)

        try:
            if (frame[0] == BC_BEGIN_IDENTITY):
                console.bc(frame[0], who=newGuest.who)
                index = 1
                while (frame[index] != BC_END_IDENTITY):
                    console.bc(frame[index], who=newGuest.who)

                    if (frame[index] == BC_ERROR):
                        console.warn("identity frame aborted",
                                     who=newGuest.who)
                        valid = False
                        return -1, []
                    elif (frame[index] == BC_IDENTITY_USER):
                        index += 1
                        newGuest.guestType = "user"
                        newGuest.enode = frame[index:index + 70]
                        if ([int(contact[0].split('.')[x])
                             for x in range(4)] != newGuest.enode[64:68]):
                            console.warn("guest's ip doesn't match",
                                         who=newGuest.who)
                            valid = False
                            return -1, []
                        index += 70
                        valid = True
                    elif (frame[index] == BC_IDENTITY_TRACKER):
                        index += 1
                        newGuest.guestType = "tracker"
                        #
                        #	code
                        #
                        valid = True
                        console.error("not implemented")
                        return -1, []
                    else:
                        valid = False
                        console.warn("invalid balise in identity frame",
                                     who=newGuest.who)
                        return -1, []

                console.bc(frame[index], who=newGuest.who)
                index += 1

                if valid:
                    newGuest.udpPyPort = list(contact[1].to_bytes(
                        2, byteorder='big'))
                    newGuest.update()
                    n = self.__guest_exist(newGuest)
                    if (n == -1):
                        self.guests.append(newGuest)
                        n = len(self.guests) - 1
                    console.print("identity completed", who=newGuest.who)
                    return n, frame[index:]
                else:
                    console.warn("incomplete identity", who=newGuest.who)
                    return -1, []

            else:
                raise IndexError

        except IndexError:
            console.warn("bad frame construction from {0}:{1}".format(
                contact[0], contact[1]),
                         who=newGuest.who)
            return -1, []
コード例 #12
0
ファイル: c_geth.py プロジェクト: maxilix/sesan_v2
 def remove_peer(self, enodeS):
     try:
         self.w3.geth.admin.remove_peer(enodeS)
     except:
         console.warn("wrong enode, peer not removed")
コード例 #13
0
ファイル: c_geth.py プロジェクト: maxilix/sesan_v2
 def add_peer(self, enodeS):
     try:
         self.w3.geth.admin.add_peer(enodeS)
     except:
         console.warn("wrong enode, peer not added")