Skip to content

Commit

Permalink
Merge pull request #6753 from xoriole/fix/event-stream
Browse files Browse the repository at this point in the history
Add missing notifier topic observers based on enum values
  • Loading branch information
xoriole committed Feb 4, 2022
2 parents 7a319b1 + 9df6c64 commit f36bf3d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/tribler-core/run_tunnel_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async def start(self, options):
session.set_as_default()

self.log_circuits = options.log_circuits
session.notifier.add_observer(NTFY.TUNNEL_REMOVE, self.circuit_removed)
session.notifier.add_observer(NTFY.TUNNEL_REMOVE.value, self.circuit_removed)

await session.start_components()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ async def run(self):
self.payout_manager = PayoutManager(bandwidth_accounting_component.community,
ipv8_component.dht_discovery_community)

self.session.notifier.add_observer(NTFY.PEER_DISCONNECTED_EVENT, self.payout_manager.do_payout)
self.session.notifier.add_observer(NTFY.TRIBLER_TORRENT_PEER_UPDATE, self.payout_manager.update_peer)
self.session.notifier.add_observer(NTFY.PEER_DISCONNECTED_EVENT.value, self.payout_manager.do_payout)
self.session.notifier.add_observer(NTFY.TRIBLER_TORRENT_PEER_UPDATE.value, self.payout_manager.update_peer)


async def shutdown(self):
await super().shutdown()
if self.payout_manager:
self.session.notifier.remove_observer(NTFY.PEER_DISCONNECTED_EVENT, self.payout_manager.do_payout)
self.session.notifier.remove_observer(NTFY.TRIBLER_TORRENT_PEER_UPDATE, self.payout_manager.update_peer)
self.session.notifier.remove_observer(NTFY.PEER_DISCONNECTED_EVENT.value, self.payout_manager.do_payout)
self.session.notifier.remove_observer(NTFY.TRIBLER_TORRENT_PEER_UPDATE.value,
self.payout_manager.update_peer)

await self.payout_manager.shutdown()
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def connect_notifier(self, notifier: Notifier):
self.notifier = notifier

for event_type, event_lambda in reactions_dict.items():
self.notifier.add_observer(event_type,
self.notifier.add_observer(event_type.value,
lambda *args, el=event_lambda, et=event_type:
self.write_data({"type": et.value, "event": el(*args)}))

Expand All @@ -91,7 +91,7 @@ def on_circuit_removed(circuit, *args):
self.write_data({"type": NTFY.TUNNEL_REMOVE.value, "event": event})

# Tribler tunnel circuit has been removed
self.notifier.add_observer(NTFY.TUNNEL_REMOVE, on_circuit_removed)
self.notifier.add_observer(NTFY.TUNNEL_REMOVE.value, on_circuit_removed)

async def on_shutdown(self, _):
await self.shutdown_task_manager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ async def test_events(rest_manager, notifier):
messages_to_wait_for.add(NTFY.TRIBLER_EXCEPTION.value)
for subject, data in testdata.items():
if data:
notifier.notify(subject, *data)
notifier.notify(subject.value, *data)
else:
notifier.notify(subject)
notifier.notify(subject.value)
rest_manager.root_endpoint.endpoints['/events'].on_tribler_exception(ReportedError('', '', {}, False))
await events_up.wait()

Expand Down

0 comments on commit f36bf3d

Please sign in to comment.