int vine_dp_get_remote_ip(vine_dp_h dp, vine_address_family_e *addr_family, char **ip);
/**
- * @brief Sets the port.
- * @remarks @a port is a remote server port if @a dp's type is VINE_DP_TYPE_CLIENT. \
- * Otherwise, @a port is a listen port. \
- * If it is a listen port, you can set it to 0 so that a random port is picked by the kernel.
+ * @brief Sets the port of a remote server.
+ * @remarks @a dp's type can be VINE_DP_TYPE_CLIENT only.
* @since_tizen 6.5
* @param[in] dp The data path handle
* @param[in] port The port
* @return 0 on success, otherwise a negative error value
* @retval #VINE_ERROR_NONE Successful
* @retval #VINE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #VINE_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #VINE_ERROR_NOT_SUPPORTED Not supported
+ * @see vine_dp_create()
+ * @see vine_dp_get_remote_port()
+ */
+int vine_dp_set_remote_port(vine_dp_h dp, int port);
+
+/**
+ * @brief Gets the port of a remote server.
+ * @remarks @a dp's type can be VINE_DP_TYPE_CLIENT only.
+ * @since_tizen 6.5
+ * @param[in] dp The data path handle
+ * @param[out] port The port
+ * @return 0 on success, otherwise a negative error value
+ * @retval #VINE_ERROR_NONE Successful
+ * @retval #VINE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #VINE_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #VINE_ERROR_NOT_SUPPORTED Not supported
+ * @see vine_dp_create()
+ * @see vine_dp_set_remote_port()
+ */
+int vine_dp_get_remote_port(vine_dp_h dp, int *port);
+
+/**
+ * @brief Gets the local IP address.
+ * @remarks @a ip must be released using free().
+ * If VINE_DP_TYPE_SERVER are listening to multiple interfaces,
+ * @a ip would be returned empty without error.
+ * For the same reason, VINE_DP_TYPE_PUBSUB doesn't support this API.
+ * @since_tizen 6.5
+ * @param[in] dp The data path handle
+ * @param[out] addr_family The address family
+ * @param[out] ip The local IP address
+ * @return 0 on success, otherwise a negative error value
+ * @retval #VINE_ERROR_NONE Successful
+ * @retval #VINE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #VINE_ERROR_NOT_SUPPORTED Not supported
+ * @see vine_dp_create()
+ */
+int vine_dp_get_ip(vine_dp_h dp, vine_address_family_e *addr_family, char **ip);
+
+/**
+ * @brief Sets the listen port.
+ * @remarks @a dp's type can be VINE_DP_TYPE_SERVER or VINE_DP_TYPE_PUBSUB. \
+ * You can set it to 0 so that a random port is picked by the kernel.
+ * @since_tizen 6.5
+ * @param[in] dp The data path handle
+ * @param[in] port The listen port
+ * @return 0 on success, otherwise a negative error value
+ * @retval #VINE_ERROR_NONE Successful
+ * @retval #VINE_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #VINE_ERROR_INVALID_OPERATION Invalid operation
* @retval #VINE_ERROR_NOT_SUPPORTED Not supported
* @see vine_dp_create()
*/
/**
* @brief Gets the port.
+ * @remarks @a port is the local port number used for the connection. \
+ * If dp is VINE_DP_TYPE_SERVER or VINE_DP_TYPE_PUBSUB, \
+ * @a port is the same with a listen port.
* @since_tizen 6.5
* @param[in] dp The data path handle
* @param[out] port The port
* @retval #VINE_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VINE_ERROR_NOT_SUPPORTED Not supported
* @see vine_dp_create()
+ * @see vine_dp_set_port()
*/
int vine_dp_get_port(vine_dp_h dp, int *port);
%bcond_without lws_static_prebuilt
Name: capi-network-vine
Summary: An service discovery framework
-Version: 1.0.1
+Version: 1.0.2
Release: 0
Group: Network & Connectivity/API
License: Apache-2.0
#include <pthread.h>
#include <stdbool.h>
#include <sys/eventfd.h>
+#include <sys/socket.h>
#include <unistd.h>
#include <arpa/inet.h>
return strncmp(IPV4_MAPPED_IPV6_PREFIX, ip, IPV4_MAPPED_IPv6_PREFIX_LEN) == 0;
}
-static void _get_peer_network_info(struct lws *wsi,
- vine_dp_addr_family_e *family, char ip[], int *port)
+static void __get_network_info(struct sockaddr_storage *addr,
+ vine_dp_addr_family_e *family, char ip[], int *port)
{
- struct sockaddr_storage addr;
- socklen_t len = sizeof(addr);
- int fd;
- int ret;
-
- fd = lws_get_socket_fd(wsi);
- if (fd < 0) {
- VINE_LOGE("lws_get_socket_fd fails[%d]", fd);
- return;
- }
-
- ret = getpeername(fd, (struct sockaddr*)&addr, &len);
- if (ret < 0) {
- VINE_LOGE("Cannot get name of connected peer. errno[%d]", errno);
+ if (!addr)
return;
- }
- if (addr.ss_family == AF_INET) {
- struct sockaddr_in *s = (struct sockaddr_in*)&addr;
+ if (addr->ss_family == AF_INET) {
+ struct sockaddr_in *s = (struct sockaddr_in*)addr;
*port = ntohs(s->sin_port);
*family = VINE_DP_IPV4;
inet_ntop(AF_INET, &s->sin_addr, ip, INET6_ADDRSTRLEN);
} else {
- struct sockaddr_in6 *s = (struct sockaddr_in6*)&addr;
+ struct sockaddr_in6 *s = (struct sockaddr_in6*)addr;
*port = ntohs(s->sin6_port);
inet_ntop(AF_INET6, &s->sin6_addr, ip, INET6_ADDRSTRLEN);
if (__is_ipv4_mapped(ip)) {
*family = VINE_DP_IPV6;
}
}
+}
+
+static int _get_local_network_info(struct lws *wsi,
+ vine_dp_addr_family_e *family, char ip[], int *port)
+{
+ struct sockaddr_storage addr;
+ socklen_t len = sizeof(struct sockaddr_storage);
+ int fd, ret;
+
+ fd = lws_get_socket_fd(wsi);
+ if (fd < 0) {
+ VINE_LOGE("lws_get_socket_fd fails[%d]", fd);
+ return VINE_DATA_PATH_ERROR_OPERATION_FAILED;
+ }
+
+ ret = getsockname(fd, (struct sockaddr *)&addr, &len);
+ if (ret < 0) {
+ VINE_LOGE("Cannot get sockname. errno[%d]", errno);
+ return VINE_DATA_PATH_ERROR_OPERATION_FAILED;
+ }
+
+ __get_network_info(&addr, family, ip, port);
+ VINE_LOGD("address family[%d] ip[%s], port[%d]\n", addr.ss_family, ip, *port);
+ return VINE_DATA_PATH_ERROR_NONE;
+}
+
+static void _get_peer_network_info(struct lws *wsi,
+ vine_dp_addr_family_e *family, char ip[], int *port)
+{
+ struct sockaddr_storage addr;
+ socklen_t len = sizeof(addr);
+ int fd;
+ int ret;
+
+ fd = lws_get_socket_fd(wsi);
+ if (fd < 0) {
+ VINE_LOGE("lws_get_socket_fd fails[%d]", fd);
+ return;
+ }
+
+ ret = getpeername(fd, (struct sockaddr*)&addr, &len);
+ if (ret < 0) {
+ VINE_LOGE("Cannot get name of connected peer. errno[%d]", errno);
+ return;
+ }
+ __get_network_info(&addr, family, ip, port);
VINE_LOGD("address family[%d] peer ip[%s], peer port[%d]\n", addr.ss_family, ip, *port);
}
g_callbacks.pollfd_cb(VINE_DATA_PATH_POLLFD_MOD, pollfd->fd, pollfd->events);
}
+static void _invoke_connected_cb(struct lws *wsi, bool connected, void *user_data)
+{
+ if (!connected) {
+ g_callbacks.connected_cb(-1, user_data);
+ return;
+ }
+
+ g_callbacks.connected_cb(0, user_data);
+}
+
static int _websocket_protocol_cb(struct lws *wsi,
enum lws_callback_reasons reason, void *user, void *in, size_t len)
{
case LWS_CALLBACK_ESTABLISHED: {
VINE_LOGI("Websocket connection is established.");
-
websocket_s *client_ws = (websocket_s *)lws_wsi_user(wsi);
vhd->curr_conn++;
if (g_callbacks.accepted_cb) {
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR:
VINE_LOGI("Failed connection request to server.");
if (ws && g_callbacks.connected_cb)
- g_callbacks.connected_cb(-1, ws->user);
+ _invoke_connected_cb(wsi, false, ws->user);
break;
case LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER: {
case LWS_CALLBACK_CLIENT_ESTABLISHED:
VINE_LOGI("Connected with server.");
if (ws && g_callbacks.connected_cb)
- g_callbacks.connected_cb(0, ws->user);
+ _invoke_connected_cb(wsi, true, ws->user);
break;
case LWS_CALLBACK_CLIENT_RECEIVE:
g_callbacks = callbacks;
}
+static int websocket_get_local_address_info(vine_dp_plugin_h handle,
+ int *address_family, char local_ip[], int *port)
+{
+ RET_VAL_IF(handle == NULL, VINE_DATA_PATH_ERROR_INVALID_PARAMETER, "handle is NULL");
+ RET_VAL_IF(address_family == NULL,
+ VINE_DATA_PATH_ERROR_INVALID_PARAMETER, "address_family is NULL");
+ RET_VAL_IF(local_ip == NULL, VINE_DATA_PATH_ERROR_INVALID_PARAMETER, "local_ip is NULL");
+ RET_VAL_IF(port == NULL, VINE_DATA_PATH_ERROR_INVALID_PARAMETER, "port is NULL");
+
+ websocket_s *ws = (websocket_s *)handle;
+ return _get_local_network_info(ws->wsi, (vine_dp_addr_family_e *)address_family, local_ip, port);
+}
+
static int websocket_set_token(vine_dp_plugin_h handle, const char *token)
{
RET_VAL_IF(handle == NULL, VINE_DATA_PATH_ERROR_INVALID_PARAMETER, "handle is NULL");
fn->write = websocket_write;
fn->close = websocket_close;
+ fn->get_local_address_info = websocket_get_local_address_info;
+
fn->set_token = websocket_set_token;
fn->get_token = websocket_get_token;
}
int (*write)(vine_dp_plugin_h handle, unsigned char *buf, size_t len);
int (*close)(vine_dp_plugin_h handle);
+ int (*get_local_address_info)(vine_dp_plugin_h handle,
+ int *addr_family, char local_ip[], int *port);
+
// The token means an additional information which is used during connection establishing.
// The way to send it can be different based on a plugin.
// In case of libwebsockets, send it through a HTTP custom header.
vine_address_family_e vine_data_path_get_addr_family(vine_data_path_h datapath);
int vine_data_path_get_port(vine_data_path_h datapath);
vine_security_h vine_data_path_get_security(vine_data_path_h datapath);
+int vine_data_path_get_local_address_info(vine_data_path_h datapath, int *address_family,
+ char **ip, int *port);
int vine_data_path_set_received_cb(vine_data_path_h datapath,
vine_data_path_received_cb callback, void *user_data);
virtual int set_addr_family(vine_address_family_e addr_family) = 0;
virtual int set_remote_ip(vine_address_family_e, const std::string &ip) = 0;
virtual int get_remote_ip(vine_address_family_e *addr_family, char **ip) = 0;
+ virtual int set_remote_port(int port) = 0;
+ virtual int get_remote_port() = 0;
+ virtual int get_ip(vine_address_family_e *addr_family, char **ip) = 0;
virtual int set_port(int port) = 0;
virtual int get_port() = 0;
+ virtual int update_local_address_info() = 0;
virtual int set_topic(std::string topic) = 0;
virtual int set_max_connections(int max_conn) = 0;
virtual int set_accepted_cb(vine_dp_accepted_cb callback, void *user_data) = 0;
virtual int set_addr_family(vine_address_family_e addr_family);
virtual int set_remote_ip(vine_address_family_e, const std::string &ip);
virtual int get_remote_ip(vine_address_family_e *addr_family, char **ip);
+ virtual int set_remote_port(int port);
+ virtual int get_remote_port();
+ virtual int get_ip(vine_address_family_e *addr_family, char **ip);
virtual int set_port(int port);
virtual int get_port(){ return mListenPort; };
+ virtual int update_local_address_info();
virtual int set_topic(std::string topic);
virtual int set_max_connections(int max_conn);
virtual int set_accepted_cb(vine_dp_accepted_cb callback, void *user_data);
vine_data_path_h mDataPath;
vine_address_family_e mAddrFamily;
int mListenPort;
+ std::string mLocalIp;
int mMaxConnNum;
vine_dp_accepted_cb mAcceptedCb;
void *mAcceptedCbData;
virtual int set_addr_family(vine_address_family_e addr_family);
virtual int set_remote_ip(vine_address_family_e, const std::string &ip);
virtual int get_remote_ip(vine_address_family_e *addr_family, char **ip);
+ virtual int set_remote_port(int port);
+ virtual int get_remote_port(){ return mPeerPort; };
+ virtual int get_ip(vine_address_family_e *addr_family, char **ip);
virtual int set_port(int port);
- virtual int get_port(){ return mPeerPort; };
+ virtual int get_port(){ return mPort; };
+ virtual int update_local_address_info();
virtual int set_topic(std::string topic);
virtual int set_max_connections(int max_conn){ return VINE_ERROR_NONE; };
virtual int set_accepted_cb(vine_dp_accepted_cb callback, void *user_data);
vine_address_family_e mAddrFamily;
std::string mPeerIp;
int mPeerPort;
+ std::string mLocalIp;
+ int mPort;
bool isCreatedByServerDp;
};
virtual int set_addr_family(vine_address_family_e addr_family);
virtual int set_remote_ip(vine_address_family_e, const std::string &ip);
virtual int get_remote_ip(vine_address_family_e *addr_family, char **ip);
+ virtual int set_remote_port(int port);
+ virtual int get_remote_port();
+ virtual int get_ip(vine_address_family_e *addr_family, char **ip);
virtual int set_port(int port);
virtual int get_port(){ return mListenPort; };
-
+ virtual int update_local_address_info();
virtual int set_topic(std::string topic);
virtual int set_max_connections(int max_conn);
virtual int set_accepted_cb(vine_dp_accepted_cb callback, void *user_data);
vine_address_family_e mAddrFamily;
std::set<std::string> mIpList;
int mListenPort;
+ std::string mLocalIp;
int mMaxConnNum;
vine_dp_peer_joined_cb mPeerJoinedCb;
int _vine_dp_set_addr_family(vine_dp_h dp, vine_address_family_e addr_family);
int _vine_dp_set_remote_ip(vine_dp_h dp, vine_address_family_e addr_family, const char *ip);
int _vine_dp_get_remote_ip(vine_dp_h dp, vine_address_family_e *addr_family, char **ip);
+int _vine_dp_set_remote_port(vine_dp_h dp, int port);
+int _vine_dp_get_remote_port(vine_dp_h dp, int *port);
+int _vine_dp_get_ip(vine_dp_h dp, vine_address_family_e *addr_family, char **ip);
int _vine_dp_set_port(vine_dp_h dp, int port);
int _vine_dp_get_port(vine_dp_h dp, int *port);
int _vine_dp_set_topic(vine_dp_h dp, const char *topic);
vine_data_path_s *dp = (vine_data_path_s *)datapath;
return dp->security;
}
+
+int vine_data_path_get_local_address_info(vine_data_path_h datapath, int *address_family,
+ char **ip, int *port)
+{
+ RET_VAL_IF(datapath == NULL, VINE_ERROR_INVALID_PARAMETER, "datapath is NULL");
+ RET_VAL_IF(address_family == NULL, VINE_ERROR_INVALID_PARAMETER, "address_family is NULL");
+ RET_VAL_IF(ip == NULL, VINE_ERROR_INVALID_PARAMETER, "ip is NULL");
+ RET_VAL_IF(port == NULL, VINE_ERROR_INVALID_PARAMETER, "port is NULL");
+
+ vine_data_path_s *dp = (vine_data_path_s *)datapath;
+ vine_error_e error;
+ int addr_family, local_port;
+ char local_ip[VINE_MAX_IP_LEN + 1] = {0, };
+ int ret = g_dp_plugin_fn.get_local_address_info(dp->plugin_handle,
+ &addr_family, local_ip, &local_port);
+
+ error = __convert_data_path_error_to_vine_error((vine_data_path_error)ret);
+ if (error != VINE_ERROR_NONE)
+ return error;
+
+ *address_family = addr_family;
+ *port = local_port;
+ *ip = STRDUP(local_ip);
+
+ return VINE_ERROR_NONE;
+}
{
DataPath *dp = static_cast<DataPath *>(userdata);
dp->set_port(port);
+ dp->update_local_address_info();
VINE_LOGI("port[%d] result[%d]", port, result);
dp->invoke_opened_cb((vine_error_e)result);
_received_cb, static_cast<void *>(connected_client_dp));
vine_data_path_set_terminated_cb(datapath,
_terminated_cb, static_cast<void *>(connected_client_dp));
+
+ connected_client_dp->update_local_address_info();
static_cast<DPServer *>(user_data)->invoke_accepted_cb(connected_client_dp);
}
static void _connected_cb(vine_data_path_h datapath, int result, void *user_data)
{
- vine_data_path_set_received_cb(datapath, _received_cb, user_data);
- vine_data_path_set_terminated_cb(datapath, _terminated_cb, user_data);
- static_cast<DataPath *>(user_data)->invoke_opened_cb(result);
+ if (result == 0) {
+ vine_data_path_set_received_cb(datapath, _received_cb, user_data);
+ vine_data_path_set_terminated_cb(datapath, _terminated_cb, user_data);
+ }
+
+ DataPath *dp = static_cast<DataPath *>(user_data);
+ dp->update_local_address_info();
+ dp->invoke_opened_cb(result);
}
static void _pubsub_received_cb(vine_data_path_h datapath, size_t received_len, void *user_data)
return VINE_ERROR_INVALID_OPERATION;
}
+int DPServer::set_remote_port(int port)
+{
+ return VINE_ERROR_INVALID_OPERATION;
+}
+
+int DPServer::get_remote_port()
+{
+ return -1;
+}
+
int DPServer::set_port(int port)
{
if (port < 0 || port > 65535)
return VINE_ERROR_NONE;
}
+int DPServer::get_ip(vine_address_family_e *addr_family, char **ip)
+{
+ *addr_family = mAddrFamily;
+ *ip = STRDUP(mLocalIp.c_str());
+ return VINE_ERROR_NONE;
+}
+
+int DPServer::update_local_address_info()
+{
+ char *ip;
+ int addr_family;
+ int port;
+ int ret = vine_data_path_get_local_address_info(mDataPath, &addr_family, &ip, &port);
+ if (ret != VINE_ERROR_NONE)
+ return ret;
+
+ mLocalIp = string(ip);
+ free(ip);
+
+ return VINE_ERROR_NONE;
+}
+
int DPServer::set_topic(std::string topic)
{
return VINE_ERROR_INVALID_OPERATION;
mDataPath = NULL;
mPeerIp = "";
mPeerPort = 0;
+ mPort = 0;
mReceivedCb = NULL;
mReceivedCbData = NULL;
mOpenedCb = NULL;
mAddrFamily = vine_data_path_get_addr_family(mDataPath);
mPeerIp = vine_data_path_get_ip(mDataPath);
mPeerPort = vine_data_path_get_port(mDataPath);
+ mPort = 0;
mReceivedCb = NULL;
mReceivedCbData = NULL;
mOpenedCb = NULL;
return VINE_ERROR_NONE;
}
-int DPClient::set_port(int port)
+int DPClient::set_remote_port(int port)
{
RET_VAL_IF(isCreatedByServerDp, VINE_ERROR_INVALID_OPERATION, "cannot set port");
if (port <= 0 || port > 65535) // Do not allow 0
return VINE_ERROR_NONE;
}
+int DPClient::set_port(int port)
+{
+ return VINE_ERROR_INVALID_OPERATION;
+}
+
+int DPClient::get_ip(vine_address_family_e *addr_family, char **ip)
+{
+ *addr_family = mAddrFamily;
+ *ip = STRDUP(mLocalIp.c_str());
+ return VINE_ERROR_NONE;
+}
+
+int DPClient::update_local_address_info()
+{
+ char *ip;
+ int addr_family;
+ int port;
+ int ret = vine_data_path_get_local_address_info(mDataPath, &addr_family, &ip, &port);
+ if (ret != VINE_ERROR_NONE)
+ return ret;
+
+ mLocalIp = string(ip);
+ mPort = port;
+
+ free(ip);
+
+ return VINE_ERROR_NONE;
+}
+
int DPClient::set_topic(std::string topic)
{
return VINE_ERROR_INVALID_OPERATION;
return VINE_ERROR_INVALID_OPERATION;
}
+int DPPubSub::set_remote_port(int port)
+{
+ return VINE_ERROR_INVALID_OPERATION;
+}
+
+int DPPubSub::get_remote_port()
+{
+ return -1;
+}
+
int DPPubSub::set_port(int port)
{
if (port < 0 || port > 65535)
return VINE_ERROR_NONE;
}
+int DPPubSub::get_ip(vine_address_family_e *addr_family, char **ip)
+{
+ return VINE_ERROR_INVALID_OPERATION;
+}
+
+int DPPubSub::update_local_address_info()
+{
+ char *ip;
+ int addr_family;
+ int port;
+ int ret = vine_data_path_get_local_address_info(mServerDataPath, &addr_family, &ip, &port);
+ if (ret != VINE_ERROR_NONE)
+ return ret;
+
+ mLocalIp = string(ip);
+ free(ip);
+
+ return VINE_ERROR_NONE;
+}
+
int DPPubSub::set_topic(std::string topic)
{
mTopic = topic;
return _dp->get_remote_ip(addr_family, ip);
}
+int _vine_dp_set_remote_port(vine_dp_h dp, int port)
+{
+ RET_VAL_IF(dp == NULL, VINE_ERROR_INVALID_PARAMETER, "dp is null.");
+
+ DataPath *_dp = static_cast<DataPath *>(dp);
+ return _dp->set_remote_port(port);
+}
+
+int _vine_dp_get_remote_port(vine_dp_h dp, int *port)
+{
+ RET_VAL_IF(dp == NULL, VINE_ERROR_INVALID_PARAMETER, "dp is null.");
+ RET_VAL_IF(port == NULL, VINE_ERROR_INVALID_PARAMETER, "port is null.");
+
+ DataPath *_dp = static_cast<DataPath *>(dp);
+ int remote_port = _dp->get_remote_port();
+ if (remote_port < 0)
+ return VINE_ERROR_INVALID_OPERATION;
+ *port = remote_port;
+ return VINE_ERROR_NONE;
+}
+int _vine_dp_get_ip(vine_dp_h dp, vine_address_family_e *addr_family, char **ip)
+{
+ RET_VAL_IF(dp == NULL, VINE_ERROR_INVALID_PARAMETER, "dp is null.");
+ RET_VAL_IF(addr_family == NULL, VINE_ERROR_INVALID_PARAMETER, "addr_family is null.");
+ RET_VAL_IF(ip == NULL, VINE_ERROR_INVALID_PARAMETER, "ip is null.");
+
+ DataPath *_dp = static_cast<DataPath *>(dp);
+ return _dp->get_ip(addr_family, ip);
+}
+
int _vine_dp_set_port(vine_dp_h dp, int port)
{
RET_VAL_IF(dp == NULL, VINE_ERROR_INVALID_PARAMETER, "dp is null.");
return _vine_dp_get_remote_ip(dp, addr_family, ip);
}
+API int vine_dp_set_remote_port(vine_dp_h dp, int port)
+{
+ __VINE_FUNC_ENTER__;
+ CHECK_FEATURE_SUPPORTED;
+
+ return _vine_dp_set_remote_port(dp, port);
+}
+
+API int vine_dp_get_remote_port(vine_dp_h dp, int *port)
+{
+ __VINE_FUNC_ENTER__;
+ CHECK_FEATURE_SUPPORTED;
+
+ return _vine_dp_get_remote_port(dp, port);
+}
+
+API int vine_dp_get_ip(vine_dp_h dp, vine_address_family_e *addr_family, char **ip)
+{
+ __VINE_FUNC_ENTER__;
+ CHECK_FEATURE_SUPPORTED;
+
+ return _vine_dp_get_ip(dp, addr_family, ip);
+}
+
API int vine_dp_set_port(vine_dp_h dp, int port)
{
__VINE_FUNC_ENTER__;
vine_dp_set_remote_ip(server_dp, VINE_ADDRESS_FAMILY_IPV4, TEST_IP));
}
-TEST_F(VineDpTest, GetRemoteN)
+TEST_F(VineDpTest, GetRemoteIpN)
{
vine_address_family_e family;
char *ip;
free(ip);
}
-TEST_F(VineDpTest, SetPortN)
+TEST_F(VineDpTest, SetRemotePortN)
{
EXPECT_EQ(VINE_ERROR_INVALID_PARAMETER,
- vine_dp_set_port(client_dp, -1));
+ vine_dp_set_remote_port(client_dp, -1));
+ EXPECT_EQ(VINE_ERROR_INVALID_PARAMETER,
+ vine_dp_set_remote_port(NULL, 12345));
+ EXPECT_EQ(VINE_ERROR_INVALID_OPERATION,
+ vine_dp_set_remote_port(server_dp, 12345));
+ EXPECT_EQ(VINE_ERROR_INVALID_OPERATION,
+ vine_dp_set_remote_port(pubsub_dp, 12345));
+}
+
+TEST_F(VineDpTest, SetRemotePortP)
+{
+ EXPECT_EQ(VINE_ERROR_NONE,
+ vine_dp_set_remote_port(client_dp, 12345));
+}
+
+TEST_F(VineDpTest, GetRemotePortN)
+{
+ int port;
+ EXPECT_EQ(VINE_ERROR_INVALID_PARAMETER,
+ vine_dp_get_remote_port(client_dp, NULL));
+ EXPECT_EQ(VINE_ERROR_INVALID_PARAMETER,
+ vine_dp_get_remote_port(NULL, &port));
+ EXPECT_EQ(VINE_ERROR_INVALID_OPERATION,
+ vine_dp_get_remote_port(server_dp, &port));
+ EXPECT_EQ(VINE_ERROR_INVALID_OPERATION,
+ vine_dp_get_remote_port(pubsub_dp, &port));
+}
+
+TEST_F(VineDpTest, GetRemotePortP)
+{
+ int port;
+ EXPECT_EQ(VINE_ERROR_NONE,
+ vine_dp_get_remote_port(client_dp, &port));
+}
+
+TEST_F(VineDpTest, GetIpN)
+{
+ vine_address_family_e family;
+ char *ip;
+ EXPECT_EQ(VINE_ERROR_INVALID_PARAMETER,
+ vine_dp_get_ip(client_dp, NULL, &ip));
+ EXPECT_EQ(VINE_ERROR_INVALID_PARAMETER,
+ vine_dp_get_ip(client_dp, &family, NULL));
+
+ EXPECT_EQ(VINE_ERROR_INVALID_OPERATION,
+ vine_dp_get_ip(pubsub_dp, &family, &ip));
+}
+
+TEST_F(VineDpTest, GetIpP)
+{
+ vine_address_family_e family;
+ char *ip;
+ EXPECT_EQ(VINE_ERROR_NONE,
+ vine_dp_get_ip(client_dp, &family, &ip));
+ free(ip);
+}
+
+TEST_F(VineDpTest, SetPortN)
+{
EXPECT_EQ(VINE_ERROR_INVALID_PARAMETER,
vine_dp_set_port(NULL, 12345));
+ EXPECT_EQ(VINE_ERROR_INVALID_PARAMETER,
+ vine_dp_set_port(server_dp, -1));
+ EXPECT_EQ(VINE_ERROR_INVALID_OPERATION,
+ vine_dp_set_port(client_dp, 12345));
}
TEST_F(VineDpTest, SetPortP)
{
EXPECT_EQ(VINE_ERROR_NONE,
- vine_dp_set_port(client_dp, 12345));
+ vine_dp_set_port(server_dp, 12345));
}
TEST_F(VineDpTest, GetPortN)
vine_dp_h dp;
vine_dp_create(session, VINE_DP_TYPE_CLIENT, &dp);
vine_dp_set_remote_ip(dp, address_family, ip);
- vine_dp_set_port(dp, port);
+ vine_dp_set_remote_port(dp, port);
vine_dp_set_security(dp, security);
vine_dp_set_received_cb(dp, __client_received_cb, NULL);
vine_dp_create(g_session, VINE_DP_TYPE_CLIENT, &g_client_dp);
vine_dp_set_remote_ip(g_client_dp,
addr_type ? VINE_ADDRESS_FAMILY_IPV6 : VINE_ADDRESS_FAMILY_IPV4, ip);
- PRINT_RESULT(vine_dp_set_port(g_client_dp, port), "vine_dp_set_port");
+ PRINT_RESULT(vine_dp_set_remote_port(g_client_dp, port), "vine_dp_set_remote_port");
vine_security_h security = __create_security_handle(security_type, true);
vine_dp_set_security(g_client_dp, security);
vine_security_destroy(security);
static void __opened_cb(vine_dp_h dp, vine_error_e result, void *user_data)
{
printf("DP %s.\n", result == VINE_ERROR_NONE ? "is opened" : "open failure");
+ if (result != VINE_ERROR_NONE)
+ return;
+
+ vine_address_family_e addr_family;
+ char *ip = NULL;
+ int port = 0;
+
+ vine_dp_get_port(dp, &port);
+ printf("\t> %s port: %d\n",
+ vine_configs.dp_type == VINE_DP_TYPE_CLIENT ? "connected" : "listen",
+ port);
+
+ vine_dp_get_ip(dp, &addr_family, &ip);
+ printf("\t> local IP: %s, address family: %d \n", ip, addr_family);
+ free(ip);
+
vine_dp_set_received_cb(dp, __received_cb, NULL);
vine_dp_set_terminated_cb(dp, __terminated_cb, NULL);
static void __accepted_cb(vine_dp_h dp, vine_dp_h accepted_dp, void *user_data)
{
+ vine_address_family_e addr_family;
+ int port = 0;
+ char *ip = NULL;
+
+ vine_dp_get_remote_port(accepted_dp, &port);
printf("client is accepted.\n");
+ printf("\t> client port: %d\n", port);
+
+ vine_dp_get_ip(accepted_dp, &addr_family, &ip);
+ printf("\t> used local IP: %s, address family: %d\n", ip, addr_family);
+ free(ip);
+
vine_dp_set_received_cb(accepted_dp, __received_cb, NULL);
vine_dp_set_terminated_cb(accepted_dp, __terminated_cb, NULL);
static void _set_dp_info(vine_dp_type_e type)
{
vine_dp_create(vine_configs.session, type, &vine_configs.dp);
- vine_dp_set_port(vine_configs.dp, tool_config_get_port());
-
vine_address_family_e addr_family = _convert_addr_family(tool_config_get_address_family());
vine_dp_set_address_family(vine_configs.dp, addr_family);
vine_dp_set_max_connections(vine_configs.dp, tool_config_get_max_conn());
if (type == VINE_DP_TYPE_CLIENT) {
+ vine_dp_set_remote_port(vine_configs.dp, tool_config_get_port());
vine_dp_set_remote_ip(vine_configs.dp, addr_family,
tool_config_get_remote_address());
vine_dp_set_received_cb(vine_configs.dp, __received_cb, NULL);
+ } else {
+ vine_dp_set_port(vine_configs.dp, tool_config_get_port());
}
if (type == VINE_DP_TYPE_SERVER)