-
Notifications
You must be signed in to change notification settings - Fork 16
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
Allocate reserved relay address #39
Merged
Merged
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
cca1216
Refactor UDP.allocate test helper
erszcz d2ace5f
Test reserving a port / allocation with a RESERVATION-TOKEN
erszcz 3cff668
Update Jerboa: ReservationToken.new is now available
erszcz ccee493
wip: Reserve consecutive relay port
erszcz 5128d69
wip: do_reserve_another_relay
erszcz 5c673e5
Extend client_info and refactor the way it's passed around
erszcz fc6211f
wip: Start a new worker as part of reserving the new relay address
erszcz 1afe552
wip: Save state before backtracking
erszcz 844154a
Introduce ReservationLog
erszcz 3dddeeb
Store Reservations as tuples
erszcz 2495291
Register newly allocated Reservations in the log
erszcz e2de158
Remove unused parameters
erszcz 86919c9
Use more lenient lookup method
erszcz 39d0bab
Leave TODO: expire the reservation
erszcz c822fe8
Clean up retval/error propagation
erszcz 396bdea
Fix a crucial typo
erszcz 1c9faad
Allocate reserved port if RESERVATION-TOKEN is passed
erszcz 648c993
Handle invalid/expired reservations
erszcz e7cdf77
Adhere more closely to the RFC - make the test pass
erszcz 5f5c333
Remove now-unused function
erszcz f91bf83
Remove code duplicated by a sloppy conflict resolution
erszcz 4aa64aa
Fix test for the top-level supervisor children
erszcz 562c3db
[skip ci] Fix style
erszcz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Fennec.ReservationLog do | ||
@moduledoc false | ||
|
||
## Runtime support for storing and fetching pending reservations. | ||
## I.e. an ETS table owner process. | ||
|
||
alias Fennec.TURN.Reservation | ||
alias Jerboa.Format.Body.Attribute.ReservationToken | ||
|
||
def start_link() do | ||
Agent.start_link(fn -> init_db(__MODULE__) end, name: __MODULE__) | ||
end | ||
|
||
def child_spec() do | ||
Supervisor.Spec.worker(Fennec.ReservationLog, []) | ||
end | ||
|
||
@spec register(Reservation.t) :: :ok | {:error, :exists} | ||
def register(%Reservation{} = r) do | ||
case :ets.insert_new(__MODULE__, Reservation.to_tuple(r)) do | ||
false -> {:error, :exists} | ||
_ -> :ok | ||
end | ||
end | ||
|
||
@spec take(ReservationToken.t) :: Reservation.t | nil | ||
def take(%ReservationToken{} = token) do | ||
case :ets.take(__MODULE__, token.value) do | ||
[] -> nil | ||
[r] -> Reservation.from_tuple(r) | ||
end | ||
end | ||
|
||
defp init_db(table_name) do | ||
## TODO: largely guesswork here, not load tested | ||
perf_opts = [write_concurrency: true] | ||
^table_name = :ets.new(table_name, [:public, :named_table] ++ perf_opts) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
defmodule Fennec.TURN.Reservation do | ||
@moduledoc false | ||
|
||
## A Reservation represents a relay address reserved | ||
## by an allocation request with a positive `EvenPort.reserved?`. | ||
## The relay address is created along with a RESERVATION-TOKEN | ||
## which is returned to the client requesting the allocation, | ||
## and is stored until another allocation request with the same | ||
## reservation token is sent by the client. | ||
## The Reservation is then turned into a full-blown Allocation. | ||
## This mechanism is used to allocate consecutive port pairs, | ||
## for example for RTP and RTCP transmissions. | ||
|
||
alias Jerboa.Format.Body.Attribute.ReservationToken | ||
|
||
defstruct [:token, :socket] | ||
|
||
@type t :: %__MODULE__{ | ||
token: ReservationToken.t, | ||
socket: Fennec.UDP.socket | ||
} | ||
|
||
@spec new(Fennec.UDP.socket) :: t | ||
def new(socket) do | ||
%__MODULE__{token: ReservationToken.new(), | ||
socket: socket} | ||
end | ||
|
||
@doc false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no need for |
||
## Only intended for storing in ETS | ||
def to_tuple(%__MODULE__{} = r) do | ||
%__MODULE__{token: %ReservationToken{value: token}} = r | ||
{token, r.socket} | ||
end | ||
|
||
@doc false | ||
## Only intended for storing in ETS | ||
def from_tuple({token, socket}) when is_binary(token) and is_port(socket) do | ||
%__MODULE__{token: %ReservationToken{value: token}, | ||
socket: socket} | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a space before first param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. It looked better when the signature was: