View Source YaBTT.Schema.Peer (YaBTT v0.1.5)

The schema for a peer.

A peer is a client that is connected to a torrent. It is identified by a unique peer_id, which is a 20-byte string. The peer_id is generated by the client and is not necessarily unique. The ip and port are used to connect to the peer. The ip is optional, and if not provided, the ip of the connection is used. The port is required.

A peer can be connected to many torrents, and a torrent can have many peers.

fields

Fields

  • peer_id - The peer_id of the peer.
  • ip - The ip of the peer.
  • port - The port of the peer.
  • inserted_at - The time the peer was inserted.
  • updated_at - The time the peer was last updated.

associations

Associations

  • torrents - The torrents the peer is connected to.

Link to this section Summary

Functions

A peer can be created or updated with a changeset. The changeset requires the peer_id and port to be present. The ip is optional, and if not provided, the ip of the connection is used.

Link to this section Types

@type changeset_t() :: Ecto.Changeset.t(t())
@type ip_addr() :: :inet.ip_address()
@type params() :: map()
@type t() :: %YaBTT.Schema.Peer{
  __meta__: term(),
  id: term(),
  inserted_at: term(),
  ip: term(),
  key: term(),
  peer_id: term(),
  port: term(),
  torrents: term(),
  updated_at: term()
}

Link to this section Functions

Link to this function

changeset(peer, params, ip)

View Source
@spec changeset(changeset_t() | t(), params(), ip_addr()) :: changeset_t()

A peer can be created or updated with a changeset. The changeset requires the peer_id and port to be present. The ip is optional, and if not provided, the ip of the connection is used.

parameters

Parameters

  • peer - The peer to create a changeset for.
  • conn - The connection to get the ip from.

examples

Examples

iex> alias YaBTT.Schema.Peer
iex> params = %{
...>   "peer_id" => "-TR14276775888084598",
...>   "key" => "ecsc1ggh0h",
...>   "port" => "6881"
...> }
iex> Peer.changeset(%Peer{}, params, {1, 2, 3, 4})