def __init__(self,
              supplier_idurl,
              customer_idurl,
              needed_bytes,
              key_id=None,
              queue_subscribe=True):
     """
     """
     self.supplier_idurl = supplier_idurl
     self.customer_idurl = customer_idurl
     self.needed_bytes = needed_bytes
     self.key_id = key_id
     self.queue_subscribe = queue_subscribe
     if self.needed_bytes is None:
         total_bytes_needed = diskspace.GetBytesFromString(
             settings.getNeededString(), 0)
         num_suppliers = settings.getSuppliersNumberDesired()
         if num_suppliers > 0:
             self.needed_bytes = int(
                 math.ceil(2.0 * total_bytes_needed / float(num_suppliers)))
         else:
             self.needed_bytes = int(
                 math.ceil(2.0 * settings.MinimumNeededBytes() /
                           float(settings.DefaultDesiredSuppliers())))
     name = 'supplier_%s_%s' % (
         nameurl.GetName(self.supplier_idurl),
         diskspace.MakeStringFromBytes(self.needed_bytes).replace(' ', ''),
     )
     self.request_packet_id = None
     self.callbacks = {}
     try:
         st = bpio.ReadTextFile(
             settings.SupplierServiceFilename(
                 idurl=self.supplier_idurl,
                 customer_idurl=self.customer_idurl,
             )).strip()
     except:
         st = 'DISCONNECTED'
     automat.Automat.__init__(
         self,
         name,
         state=st,
         debug_level=_DebugLevel,
         log_events=_Debug,
         log_transitions=_Debug,
     )
     for cb in self.callbacks.values():
         cb(self.supplier_idurl, self.state, self.state)
 def __init__(self, supplier_idurl, customer_idurl, needed_bytes):
     """
     """
     self.supplier_idurl = supplier_idurl
     self.customer_idurl = customer_idurl
     self.needed_bytes = needed_bytes
     if self.needed_bytes is None:
         total_bytes_needed = diskspace.GetBytesFromString(
             settings.getNeededString(), 0)
         num_suppliers = settings.getSuppliersNumberDesired()
         if num_suppliers > 0:
             self.needed_bytes = int(
                 math.ceil(2.0 * total_bytes_needed / float(num_suppliers)))
         else:
             self.needed_bytes = int(
                 math.ceil(2.0 * settings.MinimumNeededBytes() /
                           float(settings.DefaultDesiredSuppliers())))
     name = 'supplier_%s_%s' % (
         nameurl.GetName(self.supplier_idurl),
         diskspace.MakeStringFromBytes(self.needed_bytes).replace(' ', ''),
     )
     self.request_packet_id = None
     self.callbacks = {}
     try:
         st = bpio.ReadTextFile(
             settings.SupplierServiceFilename(
                 idurl=self.supplier_idurl,
                 customer_idurl=self.customer_idurl,
             )).strip()
     except:
         st = 'DISCONNECTED'
     if st == 'CONNECTED':
         automat.Automat.__init__(self, name, 'CONNECTED', _DebugLevel,
                                  _Debug)
     elif st == 'NO_SERVICE':
         automat.Automat.__init__(self, name, 'NO_SERVICE', _DebugLevel,
                                  _Debug)
     else:
         automat.Automat.__init__(self, name, 'DISCONNECTED', _DebugLevel,
                                  _Debug)
     for cb in self.callbacks.values():
         cb(self.supplier_idurl, self.state, self.state)
Exemple #3
0
 def doRequestService(self, arg):
     """
     Action method.
     """
     bytes_needed = diskspace.GetBytesFromString(settings.getNeededString(),
                                                 0)
     num_suppliers = settings.getSuppliersNumberDesired()
     if num_suppliers > 0:
         bytes_per_supplier = int(
             math.ceil(2.0 * bytes_needed / float(num_suppliers)))
     else:
         bytes_per_supplier = int(
             math.ceil(2.0 * settings.MinimumNeededBytes() /
                       float(settings.DefaultDesiredSuppliers())))
     service_info = 'service_supplier %d' % bytes_per_supplier
     request = p2p_service.SendRequestService(self.idurl,
                                              service_info,
                                              callbacks={
                                                  commands.Ack():
                                                  self._supplier_acked,
                                                  commands.Fail():
                                                  self._supplier_failed,
                                              })
     self.request_packet_id = request.PacketID