From: Guus Sliepen Date: Wed, 30 Jul 2014 13:04:47 +0000 (+0200) Subject: Add meshlink_get_pmtu() to get the path MTU to a specific node. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=85c11b44f7e62f8c89447f221c6c7258f16b0338;p=meshlink Add meshlink_get_pmtu() to get the path MTU to a specific node. --- diff --git a/src/meshlink.c b/src/meshlink.c index 4031075b..fcdaff62 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -944,6 +944,19 @@ void meshlink_send_from_queue(event_loop_t* el,meshlink_handle_t *mesh) { return ; } +ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *destination) { + if(!mesh || !destination) + return -1; + + node_t *n = (node_t *)destination; + if(!n->status.reachable) + return 0; + else if(n->mtuprobes > 30 && n->minmtu) + return n->minmtu; + else + return MTU; +} + meshlink_node_t *meshlink_get_node(meshlink_handle_t *mesh, const char *name) { if(!mesh || !name) return NULL; diff --git a/src/meshlink.h b/src/meshlink.h index b938ca38..cca509c5 100644 --- a/src/meshlink.h +++ b/src/meshlink.h @@ -240,6 +240,20 @@ extern void meshlink_set_log_cb(meshlink_handle_t *mesh, meshlink_log_level_t le */ extern bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len); +/// Query the maximum packet size that can be sent to a node. +/** This functions returns the maximum size of packets (path MTU) that can be sent to a specific node with meshlink_send(). + * The path MTU is a property of the path packets will take to the destination node over the Internet. + * It can be different for different destination nodes. + * and the path MTU can change at any point in time due to changes in the Internet. + * Therefore, although this should only occur rarely, it can still happen that packets that do not exceed this size get dropped. + * + * @param mesh A handle which represents an instance of MeshLink. + * @param destination A pointer to a meshlink_node_t describing the destination for the data. + * + * @return The recommended maximum size of packets that are to be sent to the destination node, 0 if the node is unreachable, + * or a negative value in case of an error. + */ +extern ssize_t meshlink_get_pmtu(meshlink_handle_t *mesh, meshlink_node_t *destination); /// Get a handle for a specific node. /** This function returns a handle for the node with the given name.