Пример #1
0
 def finish_request(self, request, client_address):
     data, socket = request
     print("{0} wrote: {1}".format(client_address, repr(data)))
     datagram = CRBCData(complete=data)
     datagram.name = datagram.get('Name')
     response = None
     if datagram.method == CRBCEstablishment.Register:
         if datagram.name in self.__mapping.keys():
             response = CRBCNameAlreadyInUse(name=datagram.name)
         else:
             ttl = float(datagram.get('Time-to-live'))
             self.__mapping[datagram.name] = (client_address, ttl)
             if not ttl == 0:
                 Timer(
                     ttl, self.__remove_entry, [datagram.name], {}).start()
             response = CRBCNameAccepted(name=datagram.name)
     elif datagram.method == CRBCCommunication.Send or CRBCCommunication.Received == datagram.method:
         if datagram.name in self.__mapping.keys():
             destination = self.__mapping[datagram.name][0]
             received = super(CRBCRegistry, self).send_message(
                 datagram.writable(), *destination)
             response = CRBCCommunication(complete=received)
         else:
             response = CRBCDestinationUnknown(name=datagram.name)
     else:
         response = CRBCWhatThaHeck()
     socket.sendto(response.writable(), client_address)
Пример #2
0
 def finish_request(self, request, client_address):
     data, socket = request
     print("{0} wrote: {1}".format(client_address, repr(data)))
     datagram = CRBCData(complete=data)
     datagram.name = datagram.get('Name')
     response = None
     if datagram.method == CRBCEstablishment.Register:
         if datagram.name in self.__mapping.keys():
             response = CRBCNameAlreadyInUse(name=datagram.name)
         else:
             ttl = float(datagram.get('Time-to-live'))
             self.__mapping[datagram.name] = (client_address, ttl)
             if not ttl == 0:
                 Timer(ttl, self.__remove_entry, [datagram.name],
                       {}).start()
             response = CRBCNameAccepted(name=datagram.name)
     elif datagram.method == CRBCCommunication.Send or CRBCCommunication.Received == datagram.method:
         if datagram.name in self.__mapping.keys():
             destination = self.__mapping[datagram.name][0]
             received = super(CRBCRegistry,
                              self).send_message(datagram.writable(),
                                                 *destination)
             response = CRBCCommunication(complete=received)
         else:
             response = CRBCDestinationUnknown(name=datagram.name)
     else:
         response = CRBCWhatThaHeck()
     socket.sendto(response.writable(), client_address)
Пример #3
0
 def finish_request(self, request, client_address):
     data, socket = request
     print("{0} wrote: {1}".format(client_address, repr(data)))
     datagram = CRBCData(complete=data)
     if self.check_revoke:
         if self.process_crbc_revocation(datagram):
             return
     datagram.name = datagram.get('Name')
     response = self.process_crbc_datagram(datagram)
     socket.sendto(response.writable(), client_address)
Пример #4
0
 def finish_request(self, request, client_address):
     data, socket = request
     print("{0} wrote: {1}".format(client_address, repr(data)))
     datagram = CRBCData(complete=data)
     if self.check_revoke:
         if self.process_crbc_revocation(datagram):
             return
     datagram.name = datagram.get('Name')
     response = self.process_crbc_datagram(datagram)
     socket.sendto(response.writable(), client_address)