예제 #1
0
 def sendDataTo(self, identifier, data):
     device = self.all().filter('identifier =', identifier).get()
     if device == None:
         return response.throw(3, identifier)
     if device.hosts == None:
         return response.reply({'sent': False})
     Host.__updateMobileConnections__(
         identifier
     )  # makes sure that all mobile connections are accounted for
     for host in device.hosts:
         channel.send(host, {'identifier': identifier, 'data': data})
     return response.reply({'sent': True})
예제 #2
0
  def send(self, payload, service=None, client_id=None):
    """Sends a message to a client.

    Args:
        payload: payload that can be serialized to JSON.
        service: name of the service, self.name by default.
        client_id: client ID to which the message should be sent, self.client_id
            by default.
    """
    import channel
    if service is None: service = self.name
    if client_id is None: client_id = self.client_id
    channel.send(service, client_id, payload).get_result()
예제 #3
0
파일: User.py 프로젝트: HunterLarco/Jiro
 def sendDataTo(self, identifier, data):
   device = self.all().filter('identifier =', identifier).get()
   if device == None:
     return response.throw(3, identifier)
   if device.hosts == None:
     return response.reply({
       'sent': False
     })
   Host.__updateMobileConnections__(identifier)# makes sure that all mobile connections are accounted for
   for host in device.hosts:
     channel.send(host, {
       'identifier': identifier,
       'data': data
     })
   return response.reply({
     'sent': True
   })
예제 #4
0
def send(url, amount):
    """Send coin, perhaps through more than one hop.

    After this call, the node at url should have recieved amount satoshis.
    Any fees should be collected from this node's balance.
    """
    # Paying ourself is easy
    if url == g.addr:
        return
    route = Route.query.get(url)
    if route is None:
        # If we don't know how to get there, let channel try.
        # As set up currently, this shouldn't ever work, but
        # we can let channel throw the error
        channel.send(url, amount)
    else:
        # Send the next hop money over our payment channel
        channel.send(route.next_hop, amount + route.cost)
        # Ask the next hop to send money to the destination
        bob = jsonrpcproxy.Proxy(route.next_hop + 'lightning/')
        bob.send(url, amount)
예제 #5
0
def send(url, amount):
    """Send coin, perhaps through more than one hop.

    After this call, the node at url should have recieved amount satoshis.
    Any fees should be collected from this node's balance.
    """
    # Paying ourself is easy
    if url == g.addr:
        return
    route = Route.query.get(url)
    if route is None:
        # If we don't know how to get there, let channel try.
        # As set up currently, this shouldn't ever work, but
        # we can let channel throw the error
        channel.send(url, amount)
    else:
        # Send the next hop money over our payment channel
        channel.send(route.next_hop, amount + route.cost)
        # Ask the next hop to send money to the destination
        bob = jsonrpcproxy.Proxy(route.next_hop+'lightning/')
        bob.send(url, amount)
예제 #6
0
  def test_send(self):
    sent_messages = []
    @ndb.tasklet
    def sent_messages_by_channel(client_id, messages):
      sent_messages.append([client_id, messages]);
    original_send_messages_by_channel = mcchannel._send_messages_by_channel
    mcchannel._send_messages_by_channel = sent_messages_by_channel
    try:
      mcchannel._open_requests = set()
      yield mcchannel.send('service1', '1', 'message1')
      self.assertEquals([['1', {'service1': ['message1']}]], sent_messages)
      sent_messages = []
      self.assertEqual({}, mcchannel._outgoing_messages)

      mcchannel._open_requests = set(['1'])
      yield mcchannel.send('service1', '1', 'message2')
      self.assertEquals([], sent_messages)
      self.assertEqual({'1': {'service1': ['message2']}},
          mcchannel._outgoing_messages)

    finally:
      mcchannel._send_messages_by_channel = original_send_messages_by_channel
예제 #7
0
    def send_message(self):
        try:
            message = self.message.text()
            if len(message) > 0:
                content = f"{datetime.datetime.now().strftime('%H:%M')} <Вы>: {message}"

                phizical.ser_write(channel.send(message))
                self.show_message(content)

                self.message.clear()
            else:
                self.show_service('Нельзя отправить пустое сообщение')
        except:
            self.show_service('Невозможно отправить сообщение')
예제 #8
0
def send(url, amount):
    """Send coin, perhaps through more than one hop.

    After this call, the node at url should have recieved amount satoshis.
    Any fees should be collected from this node's balance.
    """
    # Paying ourself is easy
    if url == g.addr:
        return True
    row = g.ldat.execute("SELECT nexthop, cost FROM ROUTES WHERE address = ?",
                         (url, )).fetchone()
    if row is None:
        # If we don't know how to get there, let channel try.
        # As set up currently, this shouldn't ever work, but
        # we can let channel throw the error
        channel.send(url, amount)
    else:
        # Send the next hop money over our payment channel
        next_hop, cost = row
        channel.send(next_hop, amount + cost)
        # Ask the next hop to send money to the destination
        bob = jsonrpcproxy.Proxy(next_hop + 'lightning/')
        bob.send(url, amount)
    return True
예제 #9
0
def _flush(service, datasource_key):
  """Attempts to delete the in-memory state from memcache and if successfully
  deleted, notifies clients.

  Args:
      service: service name.
      datasource_key: datasource key.
  """
  memcache_prefix = _config.NAMESPACE + str(hash(datasource_key)) + '_'
  state_key = memcache_prefix + 'state'
  memcache_client = memcache.Client()
  results_get_state = yield memcache_client.get_multi_async([state_key])
  state = results_get_state.get(state_key)
  if state is None:
    logging.warning('Memcache read failure')
    return
  results_delete_state = yield memcache_client.delete_multi_async([state_key])
  # Can't make sense of the values in the list returned by delete.
  if results_delete_state is None:
    logging.warning('Memcache write failure')
    return
  from channel import send
  for client_id in state['clients']:
    yield send(service, client_id, {'flush': state['token']})
예제 #10
0
  def post(self):
    """Implements the abstract method of the superclass.
    """
    datasource_key_urlsafe = self.request.get('datasource_key',
        default_value=None)
    service = self.request.get('service', default_value=None)
    datasource_key = ndb.Key(urlsafe=datasource_key_urlsafe)
    memcache_prefix = _config.NAMESPACE + str(hash(datasource_key)) + '_'
    state_key = memcache_prefix + 'state'
    state = memcache.get(state_key)
    if state is None:
      logging.warning('Memcache read failure.')
      return

    def txn():
      last_version = state['version']
      version_key = ndb.Key(_Version, 1, parent=datasource_key)
      version_entity = version_key.get()
      if version_entity is None:
        version_entity = _Version(version=0, id=1, parent=datasource_key)
      try:
        updates = _get_updates(datasource_key, version_entity.version,
            last_version).get_result()
      except _MemcacheReadFailure:
        logging.warning('Memcache failure when saving data to disk.',
            exc_info=sys.exc_info())
        _flush(service, datasource_key)
        return
      if 'last_transaction' in state:
        for update in state['last_transaction']:
          updates.append(update)
          last_version = update['version']
      version_entity.version = last_version
      entities_put = [version_entity]
      keys_delete = []
      for update in updates:
        if len(update['path']) == 0: id = '/'
        else: id = '/'.join(update['path'])
        encoded_value = update['new_value']
        if json.loads(encoded_value) is not None:
          entities_put.append(_Value(id=id, parent=datasource_key,
              value=encoded_value))
        else:
          keys_delete.append(ndb.Key(_Value, id, parent=datasource_key))
      ndb.put_multi(entities_put)
      ndb.delete_multi(keys_delete)
      return last_version

    try:
      last_version = ndb.transaction(txn, retries=0)
    except ndb.google_imports.datastore_errors.TransactionFailedError:
      logging.warning('Datastore transaction failed.')
      return

    _update_saving_status_after_saving(service, datasource_key)
    from channel import send
    for client_id in state['clients']:
      send(service, client_id,
          {'saved': [state['token'], last_version]}).get_result()

    logging.info('Commited transaction.')
예제 #11
0
파일: echo.py 프로젝트: zyb2013/fflib
def handle_msg(channel_, msg_):
    print(channel_, msg_)
    channel.send(channel_, msg_)
예제 #12
0
파일: echo.py 프로젝트: AdolphLua/fflib
def handle_msg(channel_, msg_):
    print(channel_, msg_)
    channel.send(channel_, msg_)