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

Add support for Fly.io deployments #167

Merged
merged 2 commits into from
Sep 23, 2024
Merged

Add support for Fly.io deployments #167

merged 2 commits into from
Sep 23, 2024

Conversation

mickel8
Copy link
Member

@mickel8 mickel8 commented Sep 21, 2024

No description provided.

Copy link

codecov bot commented Sep 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 87.87%. Comparing base (e42c09d) to head (7fafd57).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
lib/ex_webrtc/ice/fly_ip_filter.ex 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #167      +/-   ##
==========================================
- Coverage   87.98%   87.87%   -0.12%     
==========================================
  Files          44       45       +1     
  Lines        2356     2358       +2     
==========================================
- Hits         2073     2072       -1     
- Misses        283      286       +3     
Files with missing lines Coverage Δ
lib/ex_webrtc/peer_connection/configuration.ex 94.16% <ø> (-0.05%) ⬇️
lib/ex_webrtc/ice/fly_ip_filter.ex 0.00% <0.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e42c09d...7fafd57. Read the comment docs.

There are just two things you need to do:

- configure a STUN server both on the client and server side
- use custom Fly.io IP filter on the server side
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- use custom Fly.io IP filter on the server side
- use a custom Fly.io IP filter on the server side

- configure a STUN server both on the client and server side
- use custom Fly.io IP filter on the server side

In theory, configuring a STUN server just on a one side should be enough but we recommend to do it on both sides.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In theory, configuring a STUN server just on a one side should be enough but we recommend to do it on both sides.
In theory, configuring a STUN server just on one side should be enough but we recommend doing it on both sides.

Comment on lines 5 to 6
This module defines a single function, which filters out IP addresses,
which ICE Agent will use as its host candidates.
Copy link
Member

Choose a reason for hiding this comment

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

  1. "filters out" to me sounds like it's rejecting these addresses rather than accepting them
  2. I feel like adding a bit more info about the function could be helpful
Suggested change
This module defines a single function, which filters out IP addresses,
which ICE Agent will use as its host candidates.
This module defines a single function, which filters IP addresses,
which ICE Agent will use as its host candidates.
It accepts only the IPv4 address that `fly-global-services` resolves to.

which ICE Agent will use as its host candidates.
"""

@spec ip_filter(:inet.ip_address()) :: boolean()
Copy link
Member

Choose a reason for hiding this comment

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

[nitpick] We could add a behaviour in ExICE. Then again, it's only one function -- up to you

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's stay with the current version for know. In debugging and testing it's verry convenient to pass anonymous function instead of creating a module with a single function.

I thought about returning an anonymous function from ip_filter and use ICEAgent.ip_filter type in typespec but sounds like an overkill 🤔

});
```

in Elixir code:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
in Elixir code:
In Elixir code:

)
```

in `runtime.exs`:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
in `runtime.exs`:
In `runtime.exs`:

end
```

in fly.toml:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
in fly.toml:
In fly.toml:

Comment on lines +22 to +30
```elixir
ip_filter = Application.get_env(:your_app, :ice_ip_filter)

{:ok, pc} =
PeerConnection.start_link(
ice_ip_filter: ip_filter,
ice_servers: [%{urls: "stun:stun.l.google.com:19302"}]
)
```
Copy link
Member

Choose a reason for hiding this comment

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

[nitpick] When :ice_ip_filter is unset in the application, we're passing ice_ip_filter: nil to PeerConnection, which means

|> Keyword.put_new(:ice_ip_filter, fn _ -> true end)

doesn't insert the default filter.

When we pass it to ICE, however, this line
https://github.com/elixir-webrtc/ex_ice/blob/4c5190687e11b28a8209f2c930895647d0b2a64c/lib/ex_ice/priv/ice_agent.ex#L137
makes it work again, as it gets the nil stored in the keyword list and overrides it with the default filter.

I feel like this creates a kind of ambiguity and depends on ExICE not changing its behaviour of parsing options, which can potentially lead to hard-to-find errors in the future. To avoid this in this example, I would explicitly not insert ice_ip_filter to the PC options when it's missing from the application's environment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch!

```

That's it!
No special UDP port exports or dedicated IP address needed.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
No special UDP port exports or dedicated IP address needed.
No special UDP port exports or dedicated IP addresses are needed.

@mickel8 mickel8 requested a review from sgfn September 23, 2024 10:46
@mickel8 mickel8 merged commit da126b6 into master Sep 23, 2024
3 checks passed
@mickel8 mickel8 deleted the fly branch September 23, 2024 11:00
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.

2 participants