#include "dtn_errno.h"
#include "dtn_types.h"
Go to the source code of this file.
Typedefs | |
typedef int * | dtn_handle_t |
The basic handle for communication with the dtn router. | |
Functions | |
int | dtn_open (dtn_handle_t *handle) |
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 handle, dtn_endpoint_id_t *local_eid, const char *service_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 handle, dtn_reg_info_t *reginfo, dtn_reg_id_t *newregid) |
Create a dtn registration. | |
int | dtn_unregister (dtn_handle_t handle, dtn_reg_id_t regid) |
Remove a dtn registration. | |
int | dtn_find_registration (dtn_handle_t handle, 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 handle, dtn_reg_id_t newregid, dtn_reg_info_t *reginfo) |
Modify an existing registration. | |
int | dtn_bind (dtn_handle_t handle, dtn_reg_id_t regid) |
Associate a registration with the current ipc channel. | |
int | dtn_unbind (dtn_handle_t handle, dtn_reg_id_t regid) |
Explicitly remove an association from the current ipc handle. | |
int | dtn_send (dtn_handle_t handle, 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 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. | |
int | dtn_begin_poll (dtn_handle_t handle, dtn_timeval_t timeout) |
Begin a polling period for incoming bundles. | |
int | dtn_cancel_poll (dtn_handle_t handle) |
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 err) |
Return a string version of a status report reason code. |
typedef int* dtn_handle_t |
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.
Definition at line 469 of file dtn_api.c.
References DTN_BEGIN_POLL, DTN_EINPOLL, DTN_EXDR, dtnipc_send(), handle, and xdr_dtn_timeval_t().
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.
References DTN_BIND, DTN_EINPOLL, DTN_EXDR, dtnipc_send_recv(), handle, and xdr_dtn_reg_id_t().
Referenced by DTNBindCommand::exec(), dtntunnel::DTNTunnel::init_registration(), main(), and make_registration().
int dtn_build_local_eid | ( | dtn_handle_t | handle, | |
dtn_endpoint_id_t * | local_eid, | |||
const char * | service_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.
References DTN_EINPOLL, DTN_EINVAL, DTN_EXDR, DTN_LOCAL_EID, DTN_MAX_ENDPOINT_ID, DTN_SUCCESS, dtnipc_recv(), dtnipc_send(), handle, xdr_dtn_endpoint_id_t(), and xdr_dtn_service_tag_t().
Referenced by TcaController::init(), dtntunnel::DTNTunnel::init_registration(), main(), and parse_eid().
int dtn_cancel_poll | ( | dtn_handle_t | handle | ) |
Cancel a polling interval.
Definition at line 499 of file dtn_api.c.
References DTN_CANCEL_POLL, DTN_EINVAL, dtnipc_send_recv(), and handle.
int dtn_change_registration | ( | dtn_handle_t | handle, | |
dtn_reg_id_t | newregid, | |||
dtn_reg_info_t * | reginfo | |||
) |
Modify an existing registration.
Definition at line 299 of file dtn_api.c.
References DTN_EINPOLL, DTN_EINTERNAL, and handle.
Referenced by main().
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.
References DTN_SUCCESS, dtnipc_close(), and handle.
Referenced by DTNCloseCommand::exec(), main(), dtntunnel::DTNTunnel::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.
References DTN_MAX_ENDPOINT_ID, src, and dtn_endpoint_id_t::uri.
Referenced by dtntunnel::TCPTunnel::Connection::Connection(), TcaController::dtn_reg(), DTNRegisterCommand::exec(), DTNSendCommand::exec(), from_bundles(), dtntunnel::DTNTunnel::init_registration(), main(), reader_thread(), dtntunnel::DTNTunnel::send_bundle(), TcaController::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(), DTNRegisterCommand::exec(), DTNUnregisterCommand::exec(), DTNSendCommand::exec(), DTNBindCommand::exec(), DTNUnbindCommand::exec(), DTNRecvCommand::exec(), from_bundles(), dtntunnel::DTNTunnel::init_registration(), main(), dtntunnel::DTNTunnel::main(), make_registration(), reader_thread(), dtntunnel::DTNTunnel::send_bundle(), TcaController::send_bundle(), and to_bundles().
int dtn_find_registration | ( | dtn_handle_t | handle, | |
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.
References DTN_EINPOLL, DTN_EXDR, DTN_FIND_REGISTRATION, DTN_SUCCESS, dtnipc_recv(), dtnipc_send(), handle, xdr_dtn_endpoint_id_t(), and xdr_dtn_reg_id_t().
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.
References xdr_dtn_bundle_payload_t().
Referenced by DTNRecvCommand::exec(), main(), and dtntunnel::DTNTunnel::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.
References DTN_EINTERNAL, DTN_SUCCESS, dtnipc_open(), and handle.
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.
References DTN_EINVAL, DTN_ESIZE, DTN_MAX_ENDPOINT_ID, and dtn_endpoint_id_t::uri.
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.
References DTN_EXDR, DTN_RECV, DTN_SUCCESS, dtnipc_recv(), dtnipc_send_recv(), handle, xdr_dtn_bundle_payload_location_t(), xdr_dtn_bundle_payload_t(), xdr_dtn_bundle_spec_t(), and xdr_dtn_timeval_t().
Referenced by TcaController::eat_bundles(), DTNRecvCommand::exec(), from_bundles(), main(), dtntunnel::DTNTunnel::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.
References DTN_EINPOLL, DTN_EXDR, DTN_REGISTER, DTN_SUCCESS, dtnipc_recv(), dtnipc_send(), handle, xdr_dtn_reg_id_t(), and xdr_dtn_reg_info_t().
Referenced by TcaController::dtn_reg(), DTNRegisterCommand::exec(), dtntunnel::DTNTunnel::init_registration(), main(), make_registration(), and reader_thread().
int dtn_send | ( | dtn_handle_t | handle, | |
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.
References DTN_EINPOLL, DTN_EXDR, DTN_SEND, dtnipc_send_recv(), handle, xdr_dtn_bundle_id_t(), xdr_dtn_bundle_payload_t(), and xdr_dtn_bundle_spec_t().
Referenced by DTNSendCommand::exec(), main(), reader_thread(), dtntunnel::DTNTunnel::send_bundle(), TcaController::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.
References dtn_bundle_payload_t::buf, dtn_bundle_payload_t::buf_len, dtn_bundle_payload_t::buf_val, DTN_ESIZE, DTN_MAX_BUNDLE_MEM, DTN_PAYLOAD_FILE, DTN_PAYLOAD_MEM, DTN_PAYLOAD_TEMP_FILE, dtn_bundle_payload_t::filename, dtn_bundle_payload_t::filename_len, dtn_bundle_payload_t::filename_val, and dtn_bundle_payload_t::location.
Referenced by DTNSendCommand::exec(), fill_payload(), main(), reader_thread(), dtntunnel::DTNTunnel::send_bundle(), and TcaController::send_bundle().
const char* dtn_status_report_reason_to_str | ( | dtn_status_report_reason_t | err | ) |
Return a string version of a status report reason code.
Definition at line 598 of file dtn_api.c.
References REASON_BLOCK_UNINTELLIGIBLE, REASON_DEPLETED_STORAGE, REASON_ENDPOINT_ID_UNINTELLIGIBLE, REASON_FORWARDED_UNIDIR_LINK, REASON_LIFETIME_EXPIRED, REASON_NO_ADDTL_INFO, REASON_NO_ROUTE_TO_DEST, REASON_NO_TIMELY_CONTACT, and REASON_TRANSMISSION_CANCELLED.
Referenced by main().
char* dtn_strerror | ( | int | err | ) |
Get a string value associated with the dtn error code.
Definition at line 74 of file dtn_api.c.
References DTN_EBUSY, DTN_ECOMM, DTN_ECONNECT, DTN_EINPOLL, DTN_EINTERNAL, DTN_EINVAL, DTN_EMSGTYPE, DTN_ENOSPACE, DTN_ENOTFOUND, DTN_ESIZE, DTN_ETIMEOUT, DTN_EXDR, DTN_SUCCESS, and snprintf().
Referenced by TcaController::dtn_reg(), TcaController::eat_bundles(), DTNOpenCommand::exec(), DTNRegisterCommand::exec(), DTNUnregisterCommand::exec(), DTNSendCommand::exec(), DTNBindCommand::exec(), DTNUnbindCommand::exec(), DTNRecvCommand::exec(), from_bundles(), TcaController::init(), dtntunnel::DTNTunnel::init_registration(), main(), dtntunnel::DTNTunnel::main(), make_registration(), reader_thread(), dtntunnel::TCPTunnel::Connection::run(), dtntunnel::DTNTunnel::send_bundle(), TcaController::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.
References DTN_EINPOLL, DTN_EXDR, DTN_UNBIND, dtnipc_send_recv(), handle, and xdr_dtn_reg_id_t().
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.
References DTN_EINPOLL, DTN_EXDR, DTN_SUCCESS, DTN_UNREGISTER, dtnipc_recv(), dtnipc_send(), handle, and xdr_dtn_reg_id_t().
Referenced by DTNUnregisterCommand::exec(), and main().