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

Introduce tos for connections. #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ connect_timeout|`integer()`|30000|(msecs)
sctp_out_streams|`integer()`|10|Default SCTP out streams
sctp_in_streams|`integer()`|10|Default SCTP in streams
tcp_listeners|`integer()`|10|Default number of TCP listeners
tos|`integer()`|0|Default value for Type of Service
main_ip|`inet:ip4_address()`|auto|Main IPv4 of the host
main_ip6|`inet:ip6_address()`|auto|Main IPv6 of the host
ext_ip|`inet:ip4_address()`|auto|Public Ipv4 of the host
Expand Down
2 changes: 1 addition & 1 deletion include/nkpacket.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
%% ===================================================================

-define(CONN_LISTEN_OPTS,
[group, user, idle_timeout, host, path, ws_proto, refresh_fun, debug, external_url]).
[group, user, idle_timeout, host, path, ws_proto, refresh_fun, debug, external_url, tos]).

-define(CONN_CLIENT_OPTS, [monitor|?CONN_LISTEN_OPTS]).

Expand Down
2 changes: 2 additions & 0 deletions src/nkpacket.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{registered, []},
{mod, {nkpacket_app, []}},
{applications, [
kernel,
stdlib,
crypto,
ssl,
nklib,
Expand Down
2 changes: 2 additions & 0 deletions src/nkpacket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
tcp_listeners => integer(), % Default 100
send_timeout => integer(),
send_timeout_close => boolean(),
tos => integer(),

% WS/WSS/HTTP/HTTPS options
host => string() | binary(), % Listen only on this host
Expand Down Expand Up @@ -167,6 +168,7 @@
tcp_packet => 1 | 2 | 4 | raw,
send_timeout => integer(),
send_timeout_close => boolean(),
tos => integer(),

% WS/WSS
host => string() | binary(), % Host header to use
Expand Down
5 changes: 4 additions & 1 deletion src/nkpacket_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
-author('Carlos Gonzalez <[email protected]>').
-export([set_config/0]).
-export([max_connections/0, dns_cache_ttl/0, udp_timeout/0, tcp_timeout/0, sctp_timeout/0,
ws_timeout/0, http_timeout/0, connect_timeout/0, sctp_in_streams/0,
ws_timeout/0, http_timeout/0, connect_timeout/0, sctp_in_streams/0, tos/0,
sctp_out_streams/0, main_ip/0, main_ip6/0, ext_ip/0, ext_ip6/0, local_ips/0]).


Expand All @@ -39,6 +39,7 @@
connect_timeout :: integer(),
sctp_in_streams :: integer(),
sctp_out_streams :: integer(),
tos :: integer(),
main_ip :: inet:ip4_address(),
main_ip6 :: inet:ip6_address(),
ext_ip :: inet:ip4_address(),
Expand All @@ -59,6 +60,7 @@ set_config() ->
connect_timeout = nkpacket_app:get(connect_timeout),
sctp_in_streams = nkpacket_app:get(sctp_in_streams),
sctp_out_streams = nkpacket_app:get(sctp_out_streams),
tos = nkpacket_app:get(tos),
main_ip = nkpacket_app:get(main_ip),
main_ip6 = nkpacket_app:get(main_ip6),
ext_ip = nkpacket_app:get(ext_ip),
Expand All @@ -79,6 +81,7 @@ http_timeout() -> do_get_config(#nkpacket_config.http_timeout).
connect_timeout() -> do_get_config(#nkpacket_config.connect_timeout).
sctp_in_streams() -> do_get_config(#nkpacket_config.sctp_in_streams).
sctp_out_streams() -> do_get_config(#nkpacket_config.sctp_out_streams).
tos() -> do_get_config(#nkpacket_config.tos).
main_ip() -> do_get_config(#nkpacket_config.main_ip).
main_ip6() -> do_get_config(#nkpacket_config.main_ip6).
ext_ip() -> do_get_config(#nkpacket_config.ext_ip).
Expand Down
4 changes: 4 additions & 0 deletions src/nkpacket_syntax.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ app_syntax() ->
connect_timeout => nat_integer,
sctp_out_streams => nat_integer,
sctp_in_streams => nat_integer,
tos => pos_integer,
main_ip => [ip4, {atom, [auto]}],
main_ip6 => [ip6, {atom, [auto]}],
ext_ip => [ip4, {atom, [auto]}],
Expand All @@ -61,6 +62,7 @@ app_syntax() ->
connect_timeout => 30000, %
sctp_out_streams => 10,
sctp_in_streams => 10,
tos => 0,
main_ip => auto,
main_ip6 => auto,
ext_ip => auto,
Expand Down Expand Up @@ -114,6 +116,7 @@ syntax() ->
resolve_type => {atom, [listen, connect, send]},
base_nkport => [boolean, {record, nkport}],
user_state => any,
tos => pos_integer,
debug => boolean
},
add_tls_syntax(Base).
Expand All @@ -138,6 +141,7 @@ safe_syntax() ->
external_url,
ws_proto,
headers, % Not sure
tos,
debug,
http_inactivity_timeout,
http_max_empty_lines,
Expand Down
2 changes: 1 addition & 1 deletion src/nkpacket_transport.erl
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ do_connect(#nkconn{protocol=Protocol, transp=Transp, ip=Ip, port=Port, opts=Opts
?DEBUG("base nkport: ~p", [lager:pr(BasePort2, ?MODULE)]),
% Our listening host and meta must not be used for the new connection
BaseMeta2 = maps:without([host, path], BaseMeta),
Opts2 = maps:merge(BaseMeta2, Opts),
Opts2 = maps:merge(Opts, BaseMeta2),
ConnPort = BasePort2#nkport{
id = maps:get(id, Opts),
class = maps:get(class, Opts, none),
Expand Down
4 changes: 2 additions & 2 deletions src/nkpacket_transport_tcp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ connect_outbound(#nkport{remote_ip=Ip, remote_port=Port, opts=Opts, transp=tls}=
list().

outbound_opts(#nkport{opts=Opts}) ->
Opts1 = maps:to_list(maps:with([send_timeout, send_timeout_close], Opts)),
Opts1 = maps:to_list(maps:with([send_timeout, send_timeout_close, tos], Opts)),
[
binary,
{active, false},
Expand All @@ -372,7 +372,7 @@ outbound_opts(#nkport{opts=Opts}) ->
list().

listen_opts(#nkport{transp=tcp, listen_ip=Ip, opts=Opts}) ->
Opts1 = maps:to_list(maps:with([send_timeout, send_timeout_close], Opts)),
Opts1 = maps:to_list(maps:with([send_timeout, send_timeout_close, tos], Opts)),
[
{packet, case Opts of #{tcp_packet:=Packet} -> Packet; _ -> raw end},
binary,
Expand Down