Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receiving data coming over relay #96

Merged
merged 8 commits into from
Apr 24, 2017
Merged

Receiving data coming over relay #96

merged 8 commits into from
Apr 24, 2017

Conversation

arkgil
Copy link
Contributor

@arkgil arkgil commented Apr 24, 2017

This PR is an alternative implementation of #95.

Instead of installing handler functions in the client process, processes can subscribe to data sent by specified peers. This way we have even more generic behaviour plus we can easily track subscribers and clean up state related to them when they die.

Copy link
Member

@erszcz erszcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff! I marked some minor things.


@spec update_subscriber_ref(subscribers, pid, reference) :: subscribers
defp update_subscriber_ref(subscribers, sub_pid, sub_ref) do
if Map.has_key?(subscribers, sub_pid) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Map.has_key? followed by Map.get - we traverse the map twice, while Map.fetch/Map.get_and_update would do the job by traversing just once. Not a big deal (before we load test), but not complex to fix either.

Subscribes PID to data received from the given peer

Message format is
{:peer_data, client_pid :: pid,peer :: address, data :: binary}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pid,peer -> pid, peer

Subscribes calling process to data received from the given peer

Message format is
{:peer_data, client_pid :: pid,peer :: address, data :: binary}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No space after comma, as above.

@erszcz
Copy link
Member

erszcz commented Apr 24, 2017

All green!

@erszcz erszcz merged commit 24a2a90 into master Apr 24, 2017
@erszcz erszcz deleted the data-subscribers branch April 24, 2017 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants