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
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
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
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, []
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, []