# &develguide;

## Available Functions

### `get_nodes(cluster_id, proto)`

The function will return all a copy of all the needed information from the nodes (machine_id, state, description, sock address) stored in shm, whos state is up(1) and have a certain cluster_id and protocol.

This function is usually used for replication purposes.

This function returns NULL on error.

Meaning of the parameters is as follows:

- int cluster_id - the cluster id

- int proto - the protocol

#### `get_nodes` usage

    ...
    get_nodes(cluster_id, proto);
    ...

### `free_nodes(nodes)`

This function will free the allocated data for the copy.

Meaning of the parameters is as follows:

- clusterer_node_t *nodes - the data returned by the get_nodes function

#### `free_nodes` usage

    ...
    free_nodes(nodes);
    ...

### `set_state(cluster_id, machine_id, state, proto)`

The function sets the state of a machine belonging to a certain cluster, which have the specified protocol.

This function is usually used for replication purposes.

Meaning of the parameters is as follows:

- int cluster_id - cluster_id

- int machine_id - machine_id

- int state - the server state

- int proto - protocol

#### `set_state` usage

    ...
    set_state(1,1,2,PROTO_BIN);
    ...

### `check(cluster_id, sockaddr, server_id, proto)`

This function is used to check if the source of a receiving packet is known.

It returns 1 if the source is known, else it returns 0.

Meaning of the parameters is as follows:

- int cluster_id - cluster id

- union sockaddr_union* sockaddr - incoming connexion socket address

- int server_id - incoming connexion server_id

- int proto - protocol

#### `check` usage

    ...
    check(1, sockaddr, 2, PROTO_BIN)
    ...

### `get_my_id()`

This function will return the server id's.

#### `get_my_id` usage

    ...
    get_my_id()
    ...

### `send_to(cluster_id, protocol)`

This function will replicate information to the nodes belonging to a cluster_id that have a specific protocol.

Meaning of the parameters is as follows:

- int cluster_id - cluster_id

- int protocol - protocol

#### `send_to` usage

    ...
    send_to(cluster_id, protocol)
    ...

### `register_module(module_name, protocol, callback_function, timeout, auth_check, cluster_id)`

This function registers a module to a certain protocol. It acts like an intermediary: when a valid packet has arrived, if the auth_check parameter is specified then it is checked for authenticity. After that, the timestamps are updated and the callback function from the registered module is called. The clusterer module checks for every registered module if the duration between the last receiving packet and the current time is greater than the module specified timeout. If it is, the servers are temporary disabled for a period of timestamp * 2. If any packets are received for the temporary disabled servers the registered module is notified.

Meaning of the parameters is as follows:

- char *module_name - module name

- int protocol - protocol

- void (*callback_function)(int, struct receive_info *, int) - the registered module callback function

- int timeout - timeput

- int auth_check - 0 if the authentication check is disabled, 1 if the authentication check is enabled

- int cluster_id - cluster_id

#### `register_module` usage

    ...
    register_module(dialog, PROTO_BIN, cb, timeout, auth_check, cluster_id)
    ...