View Source YaBTTWeb.Controllers.Announce (YaBTT v0.1.5)

The Announce controller for the YaBTT application.

Link to this section Summary

Functions

The main entry point for the plug. This function is called for every request.

Initializes the plug. This function is called once when the plug is compiled.

Bind the response message to the connection struct. All the message will be encoded as bencoding with Bento.encode/2.

Link to this section Types

@type resp_msg() :: YaBTT.t(term()) | :error

Link to this section Functions

@spec call(Plug.Conn.t(), Plug.opts()) :: Plug.Conn.t()

The main entry point for the plug. This function is called for every request.

This function is responsible for:

  • Receive a report from peer
  • Update the track list
  • Return peers who hold the target torrent
  • Return other information

parameters

Parameters

  • conn: The connection struct.
  • opts: The options passed to the plug.

return

Return

Processed connection structure.

@spec init(Plug.opts()) :: Plug.opts()

Initializes the plug. This function is called once when the plug is compiled.

This function pass the passed options call/2.

parameters

Parameters

  • opts: The options passed to the plug.

return

Return

The options passed to the plug.

Link to this function

put_resp_msg(conn, arg2)

View Source
@spec put_resp_msg(Plug.Conn.t(), resp_msg()) :: Plug.Conn.t()

Bind the response message to the connection struct. All the message will be encoded as bencoding with Bento.encode/2.

parameters

Parameters

  • conn: The connection struct.
  • msg: The response message.

example

Example

iex> conn = %Plug.Conn{}
iex> msg = {:ok, %{"interval" => 1800, "peers" => []}}
iex> conn = YaBTTWeb.Controllers.Announce.put_resp_msg(conn, msg)
iex> conn.resp_body
"d8:intervali1800e5:peerslee"

iex> conn = %Plug.Conn{}
iex> msg = {:error, "Some error message"}
iex> conn = YaBTTWeb.Controllers.Announce.put_resp_msg(conn, msg)
iex> conn.resp_body
"d14:failure reason18:Some error messagee"

iex> conn = %Plug.Conn{}
iex> conn = YaBTTWeb.Controllers.Announce.put_resp_msg(conn, :error)
iex> conn.resp_body
"d14:failure reason22:unknown internal errore"