Skip to content
LazebnyV edited this page Dec 3, 2014 · 1 revision

h3. Constructor and destructor of the Bindy class:

  • Bindy(std::string filename, bool is_active_node, bool is_buffered);

Creates an instantiation of the class. The filename parameter is a file containing a list of usernames and keys. The first boolean parameter specifies whether the class is the active node (for example, should accept incoming connections). The second boolean parameter specifies whether the class should use internal data buffering (enables read/write methods instead of callback function).

  • ~Bindy();

Destroys the class object and releases its resources.

h3. Public methods of the Bindy class:

  • void connect ();

Server method: starts listening on a socket in background and returns.

  • void connect (in_addr ipv4);

Client method. Connects to the node at the "ipv4" address.

  • void disconnect(conn_id_t conn_id);

Disconnects connection identified by conn_id.

  • void send_data (uint32_t connection_id, std::vector<char> data);

Sends data to the established connection identified by the "connection_id". Identifier is unique during the Bindy class lifetime and is set at the moment Bindy accepts (server) or initiates (client) the connection.

  • void set_handler (void (* datasink)(uint32_t connection_id, std::vector<char> data));

Sets the callback function which will receive unstructured data from the peers. Its parameters are connection identifier for the connection to the node which sent the data, and the data itself.

  • void set_discnotify (void (* discnotify)(conn_id_t conn_id));

Sets the callback function which is called each time Bindy detects a connection was dropped either by another party or as a result of network failure.

  • std::list<conn_id_t> list_connections ();

Returns the list of active connections.

  • int read (conn_id_t conn_id, byte * p, int size);

Tries to read "size" bytes from buffer into "p"; returns amount of bytes read and removed from buffer. Used only with buffered mode.

  • int get_data_size (conn_id_t);

Returns amount of data in the buffer of connection identified by "conn_id".

  • in_addr get_ip(conn_id_t conn_id);

Returns the ip address of the peer of connection identified by "conn_id".

Clone this wiki locally