def send_ack(self, receiver_address, msg): assert isinstance(msg, (Ack, BaseError)) assert isaddress(receiver_address) host_port = self.discovery.get(receiver_address) self.transport.send(self.raiden, host_port, msg.encode()) self.sent_acks[msg.echo] = (receiver_address, msg) log.debug("MSGHASH SENT", echo=pex(msg.echo))
def send(self, receiver_address, msg): assert isaddress(receiver_address) assert not isinstance(msg, (Ack, BaseError)), msg log.info("SENDING {} > {} : {}".format(pex(self.raiden.address), pex(receiver_address), msg)) host_port = self.discovery.get(receiver_address) data = msg.encode() msghash = sha3(data) self.tries[msghash] = self.max_tries log.debug("MSGHASH SENT", msghash=pex(msghash)) assert len(data) < self.max_message_size def repeater(): while self.tries.get(msghash, 0) > 0: if not self.repeat_messages and self.tries[ msghash] < self.max_tries: raise Exception("DEACTIVATED MSG resents {} {}".format( pex(receiver_address), msg)) self.tries[msghash] -= 1 self.transport.send(self.raiden, host_port, data) gevent.sleep(self.try_interval) # Each sent msg must be acked. When msg is acked its hash is removed from self.tries if msghash in self.tries: assert False, "Node does not reply, fixme suspend node" gevent.spawn(repeater)
def send(self, receiver_address, msg): assert isaddress(receiver_address) assert not isinstance(msg, (Ack, BaseError)), msg log.info("SENDING {} > {} : {}".format(pex(self.raiden.address), pex(receiver_address), msg)) host_port = self.discovery.get(receiver_address) data = msg.encode() msghash = sha3(data) self.tries[msghash] = self.max_tries log.debug("MSGHASH SENT", msghash=pex(msghash)) assert len(data) < self.max_message_size def repeater(): while self.tries.get(msghash, 0) > 0: if not self.repeat_messages and self.tries[msghash] < self.max_tries: raise Exception( "DEACTIVATED MSG resents {} {}".format(pex(receiver_address), msg)) self.tries[msghash] -= 1 self.transport.send(self.raiden, host_port, data) gevent.sleep(self.try_interval) # Each sent msg must be acked. When msg is acked its hash is removed from self.tries if msghash in self.tries: assert False, "Node does not reply, fixme suspend node" gevent.spawn(repeater)
def __init__(self, raiden, asset_address): assert isinstance(raiden, raiden_service.RaidenService) assert isaddress(asset_address) self.raiden = raiden self.asset_address = asset_address self.channels = dict() # receiver : Channel # create channels for contracts channelmanager = raiden.chain.channelmanager_by_asset(asset_address) assert isinstance(channelmanager, ChannelManagerContract) for netting_contract in channelmanager.nettingcontracts_by_address(raiden.address): self.add_channel(netting_contract) # create network graph for contract self.channelgraph = ChannelGraph(channelmanager) # TransferManager for asset self.transfermanager = transfermanager.TransferManager(self)
def __init__(self, raiden, asset_address): assert isinstance(raiden, raiden_service.RaidenService) assert isaddress(asset_address) self.raiden = raiden self.asset_address = asset_address self.channels = dict() # receiver : Channel # create channels for contracts channelmanager = raiden.chain.channelmanager_by_asset(asset_address) assert isinstance(channelmanager, ChannelManagerContract) for netting_contract in channelmanager.nettingcontracts_by_address( raiden.address): self.add_channel(netting_contract) # create network graph for contract self.channelgraph = ChannelGraph(channelmanager) # TransferManager for asset self.transfermanager = transfermanager.TransferManager(self)
def send(self, receiver_address, msg): assert isaddress(receiver_address) assert not isinstance(msg, (Ack, BaseError)), msg print "SENDING {} > {} : {}".format(pex(self.raiden.address), pex(receiver_address), msg) host_port = self.discovery.get(receiver_address) msghash = msg.hash self.tries[msghash] = self.max_tries data = rlp.encode(msg) assert len(data) < self.max_message_size def repeater(): while self.tries.get(msghash, 0) > 0: if not self.repeat_messages and self.tries[msghash] < self.max_tries: raise Exception( "DEACTIVATED MSG resents {} {}".format(pex(receiver_address), msg)) self.tries[msghash] -= 1 self.transport.send(self.raiden, host_port, data) gevent.sleep(self.try_interval) if msghash in self.tries: assert False, "Node does not reply, fixme suspend node" gevent.spawn(repeater)
def request_transfer(self, asset_address, amount, target): assert isaddress(asset_address) and isaddress(target) assert asset_address in self.assets tm = self.raiden.assetmanagers[asset_address].transfermanager assert isinstance(tm, TransferManager) tm.request_transfer(amount, target)
def send(self, recipient, msg): # assert msg.sender assert isaddress(recipient) self.protocol.send(recipient, msg)
def __init__(self, sender=''): assert not sender or isaddress(sender) super(Signed, self).__init__(sender=sender)
def add_asset(self, asset_address): assert isaddress(asset_address) assert asset_address not in self.channelmanagercontracts self.channelmanagercontracts[asset_address] = ChannelManagerContract(self, asset_address)
def sign(self, sender): # fixme dummy assert isaddress(sender) self.sender = sender return self
def __init__(self, chain, asset_address): self.chain = chain assert isaddress(asset_address) self.asset_address = asset_address self.nettingcontracts = dict() # address_A + addressB : NettingChannelContract
def __init__(self, chain, asset_address): self.chain = chain assert isaddress(asset_address) self.asset_address = asset_address self.nettingcontracts = dict( ) # address_A + addressB : NettingChannelContract
def register(self, nodeid, host, port): assert isaddress(nodeid) # fixme, this is H(pubkey) self.h[nodeid] = (host, port)
def add_asset(self, asset_address): assert isaddress(asset_address) assert asset_address not in self.channelmanagercontracts self.channelmanagercontracts[asset_address] = ChannelManagerContract( self, asset_address)
def send_ack(self, receiver_address, msg): assert isinstance(msg, (Ack, BaseError)) assert isaddress(receiver_address) host_port = self.discovery.get(receiver_address) self.transport.send(self.raiden, host_port, rlp.encode(msg)) self.sent_acks[msg.echo] = (receiver_address, msg)