Skip to content

Commit

Permalink
Merge pull request #4250 from devos50/fix_peer_tunnel
Browse files Browse the repository at this point in the history
Removed unnecessary check in payouts
  • Loading branch information
devos50 authored Feb 25, 2019
2 parents a3bff8c + 0a15679 commit cb4f782
Showing 1 changed file with 4 additions and 19 deletions.
23 changes: 4 additions & 19 deletions Tribler/community/triblertunnel/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,7 @@ def on_payout_block(self, source_address, data):
# Send the next payout
if payload.circuit_id in self.relay_from_to and block.transaction['down'] > payload.base_amount:
relay = self.relay_from_to[payload.circuit_id]
circuit_peer = self.get_peer_from_address(relay.peer.address)
if not circuit_peer:
self.logger.warning("%s Unable to find next peer %s for payout!", self.my_peer, relay.peer)
return

self.do_payout(circuit_peer, relay.circuit_id, block.transaction['down'] - payload.base_amount * 2,
self.do_payout(relay.peer, relay.circuit_id, block.transaction['down'] - payload.base_amount * 2,
payload.base_amount)

def on_balance_request_cell(self, source_address, data, _):
Expand Down Expand Up @@ -316,15 +311,6 @@ def update_torrent(self, peers, handle, download):
if self.active_data_circuits():
self.readd_bittorrent_peers()

def get_peer_from_address(self, address):
circuit_peer = None
for peer in self.get_peers():
if peer.address == address:
circuit_peer = peer
break

return circuit_peer

def do_payout(self, peer, circuit_id, amount, base_amount):
"""
Perform a payout to a specific peer.
Expand Down Expand Up @@ -371,19 +357,18 @@ def remove_circuit(self, circuit_id, additional_info='', remove_now=False, destr
if self.tribler_session:
self.tribler_session.notifier.notify(NTFY_TUNNEL, NTFY_REMOVE, circuit, additional_info)

circuit_peer = self.get_peer_from_address(circuit.peer.address)
if circuit.bytes_down >= 1024 * 1024 and self.bandwidth_wallet and circuit_peer:
if circuit.bytes_down >= 1024 * 1024 and self.bandwidth_wallet:
# We should perform a payout of the removed circuit.
if circuit.ctype == CIRCUIT_TYPE_RENDEZVOUS:
# We remove an e2e circuit as downloader. We pay the subsequent nodes in the downloader part of the e2e
# circuit. In addition, we pay for one hop seeder anonymity since we don't know the circuit length at
# the seeder side.
self.do_payout(circuit_peer, circuit_id, circuit.bytes_down * ((circuit.goal_hops * 2) + 1),
self.do_payout(circuit.peer, circuit_id, circuit.bytes_down * ((circuit.goal_hops * 2) + 1),
circuit.bytes_down)

if circuit.ctype == CIRCUIT_TYPE_DATA:
# We remove a regular data circuit as downloader. Pay the relay nodes and the exit nodes.
self.do_payout(circuit_peer, circuit_id, circuit.bytes_down * (circuit.goal_hops * 2 - 1),
self.do_payout(circuit.peer, circuit_id, circuit.bytes_down * (circuit.goal_hops * 2 - 1),
circuit.bytes_down)

# Reset the circuit byte counters so we do not payout again if we receive a destroy message.
Expand Down

0 comments on commit cb4f782

Please sign in to comment.