#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "dtn_api.h"
#include "dtn_ipc.h"
Go to the source code of this file.
Functions | |
int | dtn_open (dtn_handle_t *h) |
Open a new connection to the router. | |
int | dtn_close (dtn_handle_t handle) |
Close an open dtn handle. | |
int | dtn_errno (dtn_handle_t handle) |
Get the error associated with the given handle. | |
char * | dtn_strerror (int err) |
Get a string value associated with the dtn error code. | |
int | dtn_build_local_eid (dtn_handle_t h, dtn_endpoint_id_t *local_eid, const char *tag) |
Build an appropriate local endpoint id by appending the specified service tag to the daemon's preferred administrative endpoint id. | |
int | dtn_register (dtn_handle_t h, dtn_reg_info_t *reginfo, dtn_reg_id_t *newregid) |
Create a dtn registration. | |
int | dtn_unregister (dtn_handle_t h, dtn_reg_id_t regid) |
Remove a dtn registration. | |
int | dtn_find_registration (dtn_handle_t h, dtn_endpoint_id_t *eid, dtn_reg_id_t *regid) |
Check for an existing registration on the given endpoint id, returning DTN_SUCCSS and filling in the registration id if it exists, or returning ENOENT if it doesn't. | |
int | dtn_change_registration (dtn_handle_t h, dtn_reg_id_t regid, dtn_reg_info_t *reginfo) |
Modify an existing registration. | |
int | dtn_bind (dtn_handle_t h, dtn_reg_id_t regid) |
Associate a registration with the current ipc channel. | |
int | dtn_unbind (dtn_handle_t h, dtn_reg_id_t regid) |
Explicitly remove an association from the current ipc handle. | |
int | dtn_send (dtn_handle_t h, dtn_bundle_spec_t *spec, dtn_bundle_payload_t *payload, dtn_bundle_id_t *id) |
Send a bundle either from memory or from a file. | |
int | dtn_recv (dtn_handle_t h, dtn_bundle_spec_t *spec, dtn_bundle_payload_location_t location, dtn_bundle_payload_t *payload, dtn_timeval_t timeout) |
Blocking receive for a bundle, filling in the spec and payload structures with the bundle data. | |
int | dtn_begin_poll (dtn_handle_t h, dtn_timeval_t timeout) |
Begin a polling period for incoming bundles. | |
int | dtn_cancel_poll (dtn_handle_t h) |
Cancel a polling interval. | |
void | dtn_copy_eid (dtn_endpoint_id_t *dst, dtn_endpoint_id_t *src) |
Copy the contents of one eid into another. | |
int | dtn_parse_eid_string (dtn_endpoint_id_t *eid, const char *str) |
Parse a string into an endpoint id structure, validating that it is in fact a valid endpoint id (i.e. | |
int | dtn_set_payload (dtn_bundle_payload_t *payload, dtn_bundle_payload_location_t location, char *val, int len) |
Sets the value of the given payload structure to either a memory buffer or a file location. | |
void | dtn_free_payload (dtn_bundle_payload_t *payload) |
Frees dynamic storage allocated by the xdr for a bundle payload in dtn_recv. | |
const char * | dtn_status_report_reason_to_str (dtn_status_report_reason_t reason) |
Return a string version of a status report reason code. |
int dtn_begin_poll | ( | dtn_handle_t | handle, | |
dtn_timeval_t | timeout | |||
) |
Begin a polling period for incoming bundles.
Returns a file descriptor suitable for calling poll() or select() on. Note that dtn_bind() must have been previously called at least once on the handle.
If the kernel returns an indication that there is data ready on the file descriptor, a call to dtn_recv will then return the bundle without blocking.
Also, no other API calls besides dtn_recv can be executed during a polling period, so an app must call dtn_poll_cancel before trying to run other API calls.
int dtn_bind | ( | dtn_handle_t | handle, | |
dtn_reg_id_t | regid | |||
) |
Associate a registration with the current ipc channel.
This serves to put the registration in "active" mode.
Definition at line 321 of file dtn_api.c.
Referenced by DTNBindCommand::exec(), dtntunnel::DTNTunnel::init_registration(), main(), and make_registration().
int dtn_build_local_eid | ( | dtn_handle_t | h, | |
dtn_endpoint_id_t * | local_eid, | |||
const char * | tag | |||
) |
Build an appropriate local endpoint id by appending the specified service tag to the daemon's preferred administrative endpoint id.
Definition at line 104 of file dtn_api.c.
Referenced by TcaController::init(), dtntunnel::DTNTunnel::init_registration(), main(), and parse_eid().
int dtn_cancel_poll | ( | dtn_handle_t | h | ) |
int dtn_change_registration | ( | dtn_handle_t | h, | |
dtn_reg_id_t | regid, | |||
dtn_reg_info_t * | reginfo | |||
) |
int dtn_close | ( | dtn_handle_t | handle | ) |
Close an open dtn handle.
Returns DTN_SUCCESS on success.
Definition at line 58 of file dtn_api.c.
Referenced by DTNCloseCommand::exec(), dtntunnel::DTNTunnel::main(), main(), reader_thread(), and TcaController::~TcaController().
void dtn_copy_eid | ( | dtn_endpoint_id_t * | dst, | |
dtn_endpoint_id_t * | src | |||
) |
Copy the contents of one eid into another.
Definition at line 529 of file dtn_api.c.
Referenced by dtntunnel::TCPTunnel::Connection::Connection(), TcaController::dtn_reg(), DTNSendCommand::exec(), DTNRegisterCommand::exec(), from_bundles(), dtntunnel::DTNTunnel::init_registration(), main(), reader_thread(), TcaController::send_bundle(), dtntunnel::DTNTunnel::send_bundle(), and to_bundles().
int dtn_errno | ( | dtn_handle_t | handle | ) |
Get the error associated with the given handle.
Definition at line 67 of file dtn_api.c.
Referenced by TcaController::dtn_reg(), TcaController::eat_bundles(), DTNRecvCommand::exec(), DTNUnbindCommand::exec(), DTNBindCommand::exec(), DTNSendCommand::exec(), DTNUnregisterCommand::exec(), DTNRegisterCommand::exec(), from_bundles(), dtntunnel::DTNTunnel::init_registration(), dtntunnel::DTNTunnel::main(), main(), make_registration(), reader_thread(), TcaController::send_bundle(), dtntunnel::DTNTunnel::send_bundle(), and to_bundles().
int dtn_find_registration | ( | dtn_handle_t | h, | |
dtn_endpoint_id_t * | eid, | |||
dtn_reg_id_t * | regid | |||
) |
Check for an existing registration on the given endpoint id, returning DTN_SUCCSS and filling in the registration id if it exists, or returning ENOENT if it doesn't.
Definition at line 251 of file dtn_api.c.
Referenced by dtntunnel::DTNTunnel::init_registration(), main(), and make_registration().
void dtn_free_payload | ( | dtn_bundle_payload_t * | payload | ) |
Frees dynamic storage allocated by the xdr for a bundle payload in dtn_recv.
Definition at line 591 of file dtn_api.c.
Referenced by DTNRecvCommand::exec(), dtntunnel::DTNTunnel::main(), and main().
int dtn_open | ( | dtn_handle_t * | handle | ) |
Open a new connection to the router.
On success, initializes the handle parameter as a new handle to the daemon and returns DTN_SUCCESS. On failure, sets handle to NULL and returns a dtn_errno error code.
Definition at line 32 of file dtn_api.c.
Referenced by DTNOpenCommand::exec(), TcaController::init(), dtntunnel::DTNTunnel::init_registration(), main(), and reader_thread().
int dtn_parse_eid_string | ( | dtn_endpoint_id_t * | eid, | |
const char * | str | |||
) |
Parse a string into an endpoint id structure, validating that it is in fact a valid endpoint id (i.e.
a URI).
Definition at line 536 of file dtn_api.c.
Referenced by main(), make_spec(), parse_eid(), TcaController::send_bundle(), and dtn::APIEndpointIDOpt::set().
int dtn_recv | ( | dtn_handle_t | handle, | |
dtn_bundle_spec_t * | spec, | |||
dtn_bundle_payload_location_t | location, | |||
dtn_bundle_payload_t * | payload, | |||
dtn_timeval_t | timeout | |||
) |
Blocking receive for a bundle, filling in the spec and payload structures with the bundle data.
The location parameter indicates the manner by which the caller wants to receive payload data (i.e. either in memory or in a file). The timeout parameter specifies an interval in milliseconds to block on the server-side (-1 means infinite wait).
Note that it is advisable to call dtn_free_payload on the returned structure, otherwise the XDR routines will memory leak.
Definition at line 416 of file dtn_api.c.
Referenced by TcaController::eat_bundles(), DTNRecvCommand::exec(), from_bundles(), dtntunnel::DTNTunnel::main(), main(), TcaController::recv_bundle(), and to_bundles().
int dtn_register | ( | dtn_handle_t | handle, | |
dtn_reg_info_t * | reginfo, | |||
dtn_reg_id_t * | newregid | |||
) |
Create a dtn registration.
If the init_passive flag in the reginfo struct is true, the registration is initially in passive state, requiring a call to dtn_bind to activate it. Otherwise, the call to dtn_bind is unnecessary as the registration will be created in the active state and bound to the handle.
Definition at line 163 of file dtn_api.c.
Referenced by TcaController::dtn_reg(), DTNRegisterCommand::exec(), dtntunnel::DTNTunnel::init_registration(), main(), make_registration(), and reader_thread().
int dtn_send | ( | dtn_handle_t | h, | |
dtn_bundle_spec_t * | spec, | |||
dtn_bundle_payload_t * | payload, | |||
dtn_bundle_id_t * | id | |||
) |
Send a bundle either from memory or from a file.
Definition at line 375 of file dtn_api.c.
Referenced by DTNSendCommand::exec(), main(), reader_thread(), TcaController::send_bundle(), dtntunnel::DTNTunnel::send_bundle(), and to_bundles().
int dtn_set_payload | ( | dtn_bundle_payload_t * | payload, | |
dtn_bundle_payload_location_t | location, | |||
char * | val, | |||
int | len | |||
) |
Sets the value of the given payload structure to either a memory buffer or a file location.
Returns: 0 on success, DTN_ESIZE if the memory location is selected and the payload is too big.
Definition at line 563 of file dtn_api.c.
Referenced by DTNSendCommand::exec(), fill_payload(), main(), reader_thread(), TcaController::send_bundle(), and dtntunnel::DTNTunnel::send_bundle().
const char* dtn_status_report_reason_to_str | ( | dtn_status_report_reason_t | reason | ) |
char* dtn_strerror | ( | int | err | ) |
Get a string value associated with the dtn error code.
Definition at line 74 of file dtn_api.c.
Referenced by TcaController::dtn_reg(), TcaController::eat_bundles(), DTNRecvCommand::exec(), DTNUnbindCommand::exec(), DTNBindCommand::exec(), DTNSendCommand::exec(), DTNUnregisterCommand::exec(), DTNRegisterCommand::exec(), DTNOpenCommand::exec(), from_bundles(), TcaController::init(), dtntunnel::DTNTunnel::init_registration(), dtntunnel::DTNTunnel::main(), main(), make_registration(), reader_thread(), dtntunnel::TCPTunnel::Connection::run(), TcaController::send_bundle(), dtntunnel::DTNTunnel::send_bundle(), and to_bundles().
int dtn_unbind | ( | dtn_handle_t | handle, | |
dtn_reg_id_t | regid | |||
) |
Explicitly remove an association from the current ipc handle.
Note that this is also implicitly done when the handle is closed.
This serves to put the registration back in "passive" mode.
Definition at line 348 of file dtn_api.c.
Referenced by DTNUnbindCommand::exec().
int dtn_unregister | ( | dtn_handle_t | handle, | |
dtn_reg_id_t | regid | |||
) |
Remove a dtn registration.
If the registration is in the passive state (i.e. not bound to any handle), it is immediately removed from the system. If it is in active state and bound to the given handle, the removal is deferred until the handle unbinds the registration or closes. This allows applications to pre-emptively call unregister so they don't leak registrations.
Definition at line 211 of file dtn_api.c.
Referenced by DTNUnregisterCommand::exec(), and main().