libdht
Typedefs | Functions
peers.h File Reference

Announce or search peers for an infohash. More...

#include <stdlib.h>
Include dependency graph for peers.h:

Go to the source code of this file.

Typedefs

typedef void(* get_peers_callback) (const unsigned char info_hash[20], const struct sockaddr_storage *peers, size_t count, void *opaque)
 Peer search complete callback. More...
 

Functions

int dht_get_peers (struct dht_node *node, const unsigned char info_hash[20], get_peers_callback callback, void *opaque, dht_search_t *handle)
 Search the DHT for peers for an infohash. More...
 
int dht_announce_peer (struct dht_node *node, const unsigned char info_hash[20], int port, get_peers_callback callback, void *opaque, dht_search_t *handle)
 Announce peer for an infohash. More...
 

Detailed Description

Announce or search peers for an infohash.

This contains defines high-level definitions for searching or announcing peers.

Typedef Documentation

typedef void(* get_peers_callback) (const unsigned char info_hash[20], const struct sockaddr_storage *peers, size_t count, void *opaque)

Peer search complete callback.

This callback is called when a search for peers completes.

Parameters
info_hashThe target infohash of the search.
peersArray of peer addresses, or NULL if no peers have been found or the search was cancelled.
countLength of the peers array.
opaqueUser data pointer passed to dht_get_peers or dht_announce_peer.

Function Documentation

int dht_announce_peer ( struct dht_node node,
const unsigned char  info_hash[20],
int  port,
get_peers_callback  callback,
void *  opaque,
dht_search_t handle 
)

Announce peer for an infohash.

Add the IP address of the current node and the given port number to the list of peers for the given infohash. This is traditionally used to announce that the "peer" controlling the current node is downloading a torrent, but other use are possible. If the port parameter is -1, the node's current UDP port is used. Since it is necessary to perform a search on the DHT before sending announce queries, the completion callback will be called with the list of already existing peers found for the given infohash. The returned handle can be used to cancel the pending announce with dht_node_cancel. This function is a wrapper for the low-level dht_node_announce function.

Parameters
nodeThe DHT node.
info_hashThe target infohash of the announce.
portPeer port number to announce, or -1 to use the nodes's current UDP port number.
callbackFunction that will be called when the announce is complete.
opaqueOpaque pointer that will be passed to the callback when the announce is complete.
handlePointer to a variable that will receive the search handle.
Returns
0 if the announce sucessfully started, or -1 in case of failure.
int dht_get_peers ( struct dht_node node,
const unsigned char  info_hash[20],
get_peers_callback  callback,
void *  opaque,
dht_search_t handle 
)

Search the DHT for peers for an infohash.

Start a recursive search for peers for the given infohash on the DHT. The returned handle can be used to cancel the pending search with dht_node_cancel. This function is a wrapper for the low-level dht_node_search function.

Parameters
nodeThe DHT node.
info_hashThe target infohash of the search.
callbackFunction that will be called when the search completes.
opaqueOpaque pointer that will be passed to the callback when the search completes.
handlePointer to a variable that will receive the search handle.
Returns
0 if the search sucessfully started, or -1 in case of failure.