<!-- Module User's Guide -->

<chapter>

	<title>&adminguide;</title>

	<section id="overview" xreflabel="Overview">
	<title>Overview</title>
	<para>
		The <emphasis role='bold'>proto_bin</emphasis> module is a
		transport module which implements Binary Interface TCP-based communication. It does
		not handle TCP connections management, but only offers higher-level
		primitives to read and write BIN messages over TCP. It calls registered
		callback functions for every complete message received.
	</para>
	</section>
	<para>
		Once loaded, you will be able to define BIN listeners in your
		configuration file by adding their IP and, optionally, a listening port,
		similar to this example:
	<para>
		<programlisting format="linespecific">
...
socket= bin:127.0.0.1 		# change the listening IP
socket= bin:127.0.0.1:5080	# change the listening IP and port
...
</programlisting>
	</para>
	</para>

	<section id="dependencies" xreflabel="Dependencies">
	<title>Dependencies</title>
	<section>
		<title>&osips; Modules</title>
		<para>
		The following modules must be loaded before this module:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>None</emphasis>.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>

	<section>
		<title>External Libraries or Applications</title>
		<para>
		The following libraries or applications must be installed before
		running &osips; with this module loaded:
			<itemizedlist>
			<listitem>
			<para>
				<emphasis>None</emphasis>.
			</para>
			</listitem>
			</itemizedlist>
		</para>
	</section>
	</section>

	<section id="exported_parameters" xreflabel="Exported Parameters">
	<title>Exported Parameters</title>
	<section id="param_bin_port" xreflabel="bin_port">
		<title><varname>bin_port</varname> (integer)</title>
		<para>
		The default port to be used by all TCP listeners.
		</para>
		<para>
		<emphasis>
			Default value is 5555.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>bin_port</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_bin", "bin_port", 6666)
...
</programlisting>
		</example>
	</section>

	<section id="param_bin_send_timeout" xreflabel="bin_send_timeout">
		<title><varname>bin_send_timeout</varname> (integer)</title>
		<para>
		Time in milliseconds after a TCP connection will be closed if it is
		not available for blocking writing in this interval (and &osips; wants
		to send something on it).
		</para>
		<para>
		<emphasis>
			Default value is 100 ms.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>bin_send_timeout</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_bin", "bin_send_timeout", 200)
...
</programlisting>
		</example>
	</section>
	<section id="param_bin_max_msg_chunks" xreflabel="bin_max_msg_chunks">
		<title><varname>bin_max_msg_chunks</varname> (integer)</title>
		<para>
			The maximum number of chunks in which a BIN message is expected to
			arrive via TCP. If a received packet is more fragmented than this,
			the connection is dropped (either the connection is very
			overloaded and this leads to high fragmentation - or we are the
			victim of an ongoing attack where the attacker is sending very
			fragmented traffic in order to decrease server performance).
		</para>
		<para>
		<emphasis>
			Default value is 32.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>bin_max_msg_chunks</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_bin", "bin_max_msg_chunks", 8)
...
</programlisting>
		</example>
	</section>
	<section id="param_bin_async" xreflabel="bin_async">
		<title><varname>bin_async</varname> (integer)</title>
		<para>
			Specifies whether the TCP connect and write operations should be
			done in an asynchronous mode (non-blocking connect and
			write) or not. If disabled, OpenSIPS will block and wait for TCP
			operations like connect and write.
		</para>
		<para>
		<emphasis>
			Default value is 1 (enabled).
		</emphasis>
		</para>
		<example>
		<title>Set <varname>bin_async</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_bin", "bin_async", 0)
...
</programlisting>
		</example>
	</section>
	<section id="param_bin_async_max_postponed_chunks" xreflabel="bin_async_max_postponed_chunks">
		<title><varname>bin_async_max_postponed_chunks</varname> (integer)</title>
		<para>
			If <emphasis>bin_async</emphasis> is enabled, this specifies the
			maximum number of BIN messages that can be stashed for later/async
			writing. If the connection pending writes exceed this number, the
			connection will be marked as broken and dropped.
		</para>
		<para>
		<emphasis>
			Default value is 1024.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>bin_async_max_postponed_chunks</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_bin", "bin_async_max_postponed_chunks", 1024)
...
</programlisting>
		</example>
	</section>
	<section id="param_bin_async_local_connect_timeout" xreflabel="bin_async_local_connect_timeout">
		<title><varname>bin_async_local_connect_timeout</varname> (integer)</title>
		<para>
			If <emphasis>bin_async</emphasis> is enabled, this specifies the
			number of milliseconds that a connect will be tried in blocking
			mode (optimization). If the connect operation lasts more than
			this, the connect will go to async mode and will be passed to TCP
			MAIN for polling.
		</para>
		<para>
		<emphasis>
			Default value is 100 ms.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>bin_async_local_connect_timeout</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_bin", "bin_async_local_connect_timeout", 200)
...
</programlisting>
		</example>
	</section>
	<section id="param_bin_async_local_write_timeout" xreflabel="bin_async_local_write_timeout">
		<title><varname>bin_async_local_write_timeout</varname> (integer)</title>
		<para>
			If <emphasis>bin_async</emphasis> is enabled, this specifies the
			number of milliseconds that a write op will be tried in blocking
			mode (optimization). If the write operation lasts more than this,
			the write will go to async mode and will be passed to bin MAIN for
			polling.
		</para>
		<para>
		<emphasis>
			Default value is 10 ms.
		</emphasis>
		</para>
		<example>
		<title>Set <varname>bin_async_local_write_timeout</varname> parameter</title>
		<programlisting format="linespecific">
...
modparam("proto_bin", "tcp_async_local_write_timeout", 100)
...
</programlisting>
		</example>
	</section>
	</section>

</chapter>
