View lcov test coverage results on http://www.ufoot.org/liquidwar/v6/doc/coverage/src/lib/nod/index.html.
sys_context: global system context
info: node info object to modify
id: ID of the new member
url: URL of the new member, can be NULL
Adds a new member to the community.
Return value: 1 if new member could be added, 0 if not.
sys_context: global system context
info: node info object to test
id: ID of the member we want to check
url: URL of the member we want to check
Tells wether a member is already in the community. Note that if there’s a member with the same URL but with a different ID, or a member with the same ID but a different URL, the function will fail, we need URLs and IDs to both be different for the peer to be added. Not respecting this would lead to confusion, while sharing an ID is conceivable over the whole network, it can’t be tolerated within a community. Same for the URL.
Return value: 1 if new member could be added, 0 if not.
sys_context: global system context
info: node info object to test
id: ID of the member we want to check
Tells wether a member exists with this ID. Will test both ourselves and remote peers.
Return value: 1 if ID is already taken, 0 if available.
sys_context: global system context
info: node info object to test
id: ID of the member we want to check
Tells wether a member exists with this ID, but for which we don’t know the URL, that is, url is NULL.
Return value: 1 if ID is already taken and has NULL url, 0 else.
sys_context: global system context
info: node info object to test
url: URL of the member we want to check
Tells wether a member exists with this URL. Will test both ourselves and remote peers.
Return value: 1 if URL is already taken, 0 if available.
sys_context: global system context
info: node info object to test
url: URL of the member we want to check
Returns the id of the node with this URL, if it’s known to us.
Return value: id if it’s the community, else 0
sys_context: global system context
info: node info object to test
id: ID of the member we want to check
Returns the id of the node with this URL, if it’s known to us.
Return value: url if it’s the community else NULL, must be freed
sys_context: global system context
info: node info object to modify
id: ID of the member we want to remove
Removes a community member by ID.
Return value: 1 if successfully removed, 0 if was not present.
sys_context: global system context
info: node info object to modify
url: URL of the member we want to remove
Removes a community member by URL.
Return value: 1 if successfully removed, 0 if was not present.
sys_context: global system context
info: node info object to modify
Tells how many members there are in a community. This include ourselves so this can never be 0, should at least be 1. Note that this is pretty much the same as the nb_nodes member of dyn_info, but this one is calculated dynamically from peer list, while the other one is updated from time to time from game_state information.
Return value: number of community members, including this node (us).
sys_context: global system context
info: node info object to modify
Resets all peers, set community to only one member, ourselves.
Return value: none.
sys_context: global system context
info: node to query
Builds a string containing all peer ids, separated by a separator.
Return value: newly allocated string
sys_context: global system context
info: node to modify
peer_id_list_str: new value
Interprets a peer_id_list_str and puts it into the node data structures. Note that this function won’t really copy the list, instead it will populate the dyn_info struct with the right values.
Return value: none
sys_context: global system context
info: node to process
func: function to use as a callback
func_data: data passed along with the function
Applies function func to all the members of the community which have an id but not an URL...
Return value: none.
sys_context: global system context
dyn_info: the dyn info struct to free
Frees a dyn info object, to be used after a
call to lw6nod_info_dup_dyn
for instance.
Return value: none
sys_context: global system context
program: the program (normally it’s liquidwar6)
version: the version
codename: the codename
stamp: the stamp
id: the node id
url: the node public url
title: the node title
description: the node description
password: the node password
bench: the node bench
open_relay: open relay or not
uptime: uptime in seconds
idle_screenshot_size: the size (bytes) of the image to display when game is idle
idle_screenshot_data: the data (jpeg) of the image to display when game is idle
Creates a node info object. The arguments correspond to the immutable node
attributes, other properties such as how many players are connected or
set in other functions like lw6nod_info_update
which can be called later.
Return value: newly allocated object, NULL on error.
sys_context: global system context
info: the node info to free
Frees a node info object.
Return value: none
info: the node info to lock
Locks a node info object, this is usefull for some members, typically list of servers, can be accessed by separated threads, one reading, many writing, and these objects (chained lists) certainly do not want to be modified while being read.
Return value: 1 if ok, 0 if not.
sys_context: global system context
info: the node info to unlock
Unlocks a node info object, this is the compation of
the lw6nod_info_lock
function.
Return value: 1 if ok, 0 if not.
sys_context: global system context
info: the node info to modify
Clears a node info object and sets all its variable attributes to NULL/default values. This is what we want when the node is idle, not playing.
Return value: none.
sys_context: global system context
info: the node info to update
community_id: the id of the community the node belongs to
round: the current round (can have an offset with real round number)
level: the name of the current level (map)
required_bench: the bench required to connect
nb_colors: number of colors playing
max_nb_colors: max number of colors allowed
nb_cursors: number of cursors playing
max_nb_cursors: max number of cursors allowed
nb_nodes: number of nodes playing
max_nb_nodes: max number of nodes allowed
peer_id_list: list of peers ids, can be NULL
game_screenshot_size: size of screenshot (bytes)
game_screenshot_data: screenshot data (byte buffer, contains JPEG)
Set a node info object variable attributes. Call this whenever the node has changed some parameter. Not too often for it’s not needed and some operations such as modying the screenshot, can be time consuming.
Return value: 1 if OK, 0 if error.
sys_context: global system context
info: the node info containing the dyn info to duplicate
Extracts the dynamic part of an info struct and duplicates it, this is to avoid protection fault error when concurrent threads access this info.
Return value: newly allocated object, must be freed.
sys_context: global system context
Creates a new hash, to be used as a discovered nodes list. Using this function has the advantage of setting the hash options to their defaults. We use a hash to avoid having uselessly long lists containing always the same node due to multiple detections.
Return value: an empty hash
sys_context: global system context
info: the node info to update
public_url: the address of the discovered node
Registers a new server, and queues it as something that should be checked later because it’s interesting. We can’t insert in the database all the servers we suspect to exist so network threads should use this, then main thread will process discovered servers afterwards. This is also a good way to avoid trivial DOS attacks.
Return value: 1 if OK, O if error.
sys_context: global system context
info: the node info to query
Returns a list of all discovered nodes (their public URL) and empties the current queue as well.
Return value: a list of dynamically allocated strings.
sys_context: global system context
Creates a new list, to be filled with nodes and typically passed
to lw6nod_info_set_verified_nodes
. Using this function has the
advantage of setting the listh options to their defaults.
Return value: an empty list
sys_context: global system context
info: the node info to modify
list: the list of verified nodes, will be freed by this function
Sets the list of verified nodes, that is, the list of nodes
we are sure to exist, this is typically the list we will
display later on a web page. We can’t directly display
any discovered node, one needs to filter them through main thread.
Something very important about this function is that list
will
be freed by function, that is, if you call this, then you can
(you should) forget your object, it will disappear any time soon.
Return value: 1 if OK, 0 on error.
sys_context: global system context
info: the node info concerned
func: the function to apply
func_data: arbitrary pointer holding data to pass to function
Calls lw6sys_hash_map
with func
on every member of the list of verified
nodes. The reason there’s a function for this is that it is
very important that list object is locked when doing this.
This function does perform a lock/unlock so it is safe.
Return value: none.
sys_context: global system context
mode: test mode (bitmask)
Registers all tests for the libnod module.
Return value: 1 if test is successfull, 0 on error.
sys_context: global system context
mode: test mode (bitmask)
Runs the nod
module test suite, testing most (if not all...)
functions.
Return value: 1 if test is successfull, 0 on error.
Constant informations about a node, these are informations that do not vary through the node’s life, so they are set object creation then left unchanged.
Type: char *
Definition: char* lw6nod_const_info_s::program
Program, this should be set to liquidwar6.
Type: char *
Definition: char* lw6nod_const_info_s::version
The version of the program.
Type: char *
Definition: char* lw6nod_const_info_s::codename
The codename of the program.
Type: int
Definition: int lw6nod_const_info_s::stamp
The stamp of the program.
Type: lw6nod_ref_info_t
Definition: lw6nod_ref_info_t lw6nod_const_info_s::ref_info
Reference information, how to uniquely identify node.
Type: char *
Definition: char* lw6nod_const_info_s::title
The title of the node, its readable short name.
Type: char *
Definition: char* lw6nod_const_info_s::description
More details about the node.
Type: int
Definition: int lw6nod_const_info_s::has_password
Wether the node is password protected or not.
Type: char *
Definition: char* lw6nod_const_info_s::password
The password used, cleartext.
Type: int
Definition: int lw6nod_const_info_s::bench
The node bench.
Type: int
Definition: int lw6nod_const_info_s::open_relay
Wether the node acts as an open relay or not.
Type: int64_t
Definition: int64_t lw6nod_const_info_s::creation_timestamp
The node creation timestamp.
Type: int
Definition: int lw6nod_const_info_s::idle_screenshot_size
Size of the screenshot (in bytes) when in idle mode.
Type: void *
Definition: void* lw6nod_const_info_s::idle_screenshot_data
Idle mode screenshot data. This is just a plain JPEG buffer, which will be used as a fallback if there’s no real screenshot available.
Dynamic informations about a node, these are informations that vary through the node’s life, so they are unset at object creation and can then be updated from game context.
Type: u_int64_t
Definition: u_int64_t lw6nod_dyn_info_s::community_id_int
The ID of the community this node belongs to, as a 64-bit unsigned integer.
Type: char *
Definition: char* lw6nod_dyn_info_s::community_id_str
The ID of the community this node belongs to, as a string (64-bit integer converted to hexa).
Type: lw6nod_ref_info_t
Definition: lw6nod_ref_info_t lw6nod_dyn_info_s::community_peers[LW6NOD_MAX_NB_PEERS]
The list of community members, you need to refer to the nb_nodes member to know quickly how many members they are but actually, in practice, there can be holes in this array, you need to check each slot, for instance 0 can be filled, 2 can be filled too, but 1 be empty. Note that we don’t count ourselves in this list.
Type: int
Definition: int lw6nod_dyn_info_s::round
The current round.
Type: char *
Definition: char* lw6nod_dyn_info_s::level
The current level.
Type: int
Definition: int lw6nod_dyn_info_s::required_bench
The required bench to connect to this node.
Type: int
Definition: int lw6nod_dyn_info_s::nb_colors
Number of colors playing.
Type: int
Definition: int lw6nod_dyn_info_s::max_nb_colors
Maximum number of colors allowed to play.
Type: int
Definition: int lw6nod_dyn_info_s::nb_cursors
Number of cursors playing.
Type: int
Definition: int lw6nod_dyn_info_s::max_nb_cursors
Maximum number of cursors allowed to play.
Type: int
Definition: int lw6nod_dyn_info_s::nb_nodes
Number of nodes playing.
Type: int
Definition: int lw6nod_dyn_info_s::max_nb_nodes
Maximum number of nodes allowed to play.
Type: int
Definition: int lw6nod_dyn_info_s::game_screenshot_size
Size of the screenshot, in bytes.
Type: void *
Definition: void* lw6nod_dyn_info_s::game_screenshot_data
Game screenshot data. This is just a plain JPEG buffer, which will be served when peers and/or web clients want to gather informations about the game. This can be NULL, in that the fallback constant data will be used.
Informations about a node. Note that in practice this structure is just used to describe our current node, there might be several instances of this if a program instanciates several nodes, but another data structure is used to store information about peers.typedef struct lw6nod_info_s
Type: lw6sys_mutex_t *
Definition: lw6sys_mutex_t* lw6nod_info_s::mutex
Mutex used to access dynamic informations.
Type: lw6nod_const_info_t
Definition: lw6nod_const_info_t lw6nod_info_s::const_info
Constant informations, never changes.
Type: lw6nod_dyn_info_t
Definition: lw6nod_dyn_info_t lw6nod_info_s::dyn_info
Dynamic informations, can be updated. Do not modify this directly, instead use appropriate functions which will use mutexes properly.
Type: lw6sys_hash_t *
Definition: lw6sys_hash_t* lw6nod_info_s::discovered_nodes
List of discovered nodes, do not access this directly, instead use proper query functions which, in turn, will use mutexes properly.
Type: lw6sys_list_t *
Definition: lw6sys_list_t* lw6nod_info_s::verified_nodes
List of verified nodes, do not access this directly, instead use proper query functions which, in turn, will use mutexes properly.
Reference information about a node, this is all you need to uniquely identify a node. In theory, only the ID are only the URL are enough, in practice it’s not that bad to have some redundancy, plus it makes it easier and faster to connect to them and transmit informations.
Type: u_int64_t
Definition: u_int64_t lw6nod_ref_info_s::id_int
The id of the node, as an integer (64-bit unsigned).
Type: char *
Definition: char* lw6nod_ref_info_s::id_str
The id of the node, as a string (64-bit converted to hexa).
Type: char *
Definition: char* lw6nod_ref_info_s::url
The public URL of the node.