int vine_data_path_connect(vine_address_family_e addr_family,
const char *ip, int port, const char *iface_name,
- vine_security_h security,
+ vine_security_h security, const char *token,
vine_data_path_connected_cb callback, void *user_data,
vine_data_path_h *connected_datapath, vine_event_queue_h event_fd)
{
vine_dp_ssl ssl = {false, VINE_DP_TLS_VERSION_DEFAULT, 0, NULL, NULL, NULL};
_extract_security_info(security, &ssl);
- int ret = g_dp_plugin_fn.connect(dp->plugin_handle,
+ int ret;
+ if (token) {
+ ret = g_dp_plugin_fn.set_token(dp->plugin_handle, token);
+ if (ret != VINE_DATA_PATH_ERROR_NONE) {
+ _vine_data_path_destroy(dp);
+ _destroy_security_info(&ssl);
+ return __convert_data_path_error_to_vine_error((vine_data_path_error)ret);
+ }
+ }
+
+ ret = g_dp_plugin_fn.connect(dp->plugin_handle,
addr_family == VINE_ADDRESS_FAMILY_IPV4 ? VINE_DP_IPV4 : VINE_DP_IPV6,
ip, port, iface_name, ssl);
_destroy_security_info(&ssl);
static_cast<DataPath *>(userdata)->invoke_opened_cb(ret);
return;
}
-
- ret = dp->subscribe_service();
- if (ret != VINE_ERROR_NONE) {
- dp->close();
- static_cast<DataPath *>(userdata)->invoke_opened_cb(ret);
- return;
- }
}
static void _pubsub_accepted_cb(vine_data_path_h datapath, void *user_data)
return;
}
- const char *ip = _vine_data_path_get_ip(datapath);
- int port = _vine_data_path_get_port(datapath);
- dp->add_joined_peer(ip, port, datapath);
+ char *token = NULL;
+ if (vine_data_path_get_token(datapath, &token) != VINE_ERROR_NONE) {
+ VINE_LOGE("Cannot find peer's service name. Ignore[%p]", datapath);
+ dp->decrease_init_disc_num();
+ _vine_data_path_close(datapath);
+ return;
+ }
+
+ dp->add_joined_peer(token, datapath);
+ free(token);
_vine_data_path_set_received_cb(datapath, _pubsub_received_cb, user_data);
vine_data_path_set_terminated_cb(datapath, _pubsub_terminated_cb, user_data);
return;
}
- const char *ip = _vine_data_path_get_ip(datapath);
- int port = _vine_data_path_get_port(datapath);
+ char *token = NULL;
+ if (vine_data_path_get_token(datapath, &token) != VINE_ERROR_NONE) {
+ VINE_LOGE("Cannot find peer's service name. Ignore[%p]", datapath);
+ dp->decrease_init_disc_num();
+ _vine_data_path_close(datapath);
+ return;
+ }
- dp->add_joined_peer(ip, port, datapath);
+ dp->add_joined_peer(token, datapath);
+ free(token);
_vine_data_path_set_received_cb(datapath, _pubsub_received_cb, user_data);
vine_data_path_set_terminated_cb(datapath, _pubsub_terminated_cb, user_data);
DPPubSub *dp = static_cast<DPPubSub *>(user_data);
int port = _vine_service_get_port(service);
- if (dp->is_joined_peer(_vine_service_get_name(service), ip, port)) {
+ if (dp->is_joined_peer(_vine_service_get_name(service), ip)) {
VINE_LOGD("%s:%d was already joined.", ip, port);
return;
}
DPPubSub *dp = static_cast<DPPubSub *>(user_data);
dp->set_service_name(service_name);
+ int ret = dp->subscribe_service();
+ if (ret != VINE_ERROR_NONE) {
+ dp->close();
+ static_cast<DataPath *>(user_data)->invoke_opened_cb(ret);
+ return;
+ }
}
int DataPath::set_security(void *security)
mOpenedCbData = user_data;
return vine_data_path_connect(mAddrFamily, mServerIp.c_str(), mServerPort,
- iface_name, mSecurity, _connected_cb, static_cast<void *>(this), &mDataPath, mEventFd);
+ iface_name, mSecurity, NULL,
+ _connected_cb, static_cast<void *>(this), &mDataPath, mEventFd);
}
void DPClient::close()
{
vine_data_path_h datapath;
const char *iface_name = mIfaceName.size() > 0 ? mIfaceName.c_str() : NULL;
- int ret = vine_data_path_connect(mAddrFamily, ip, port, iface_name, mSecurity,
- _pubsub_connected_cb, static_cast<void *>(this), &datapath, mEventFd);
+ int ret = vine_data_path_connect(mAddrFamily, ip, port, iface_name,
+ mSecurity, mServiceName.c_str(),
+ _pubsub_connected_cb, static_cast<void *>(this),
+ &datapath, mEventFd);
return ret;
}
return VINE_ERROR_NONE;
}
-bool DPPubSub::is_joined_peer(const char *service_name, const char *ip, int port)
+bool DPPubSub::is_joined_peer(const char *service_name, const char *ip)
{
if (mServiceName.compare(service_name) == 0) {
VINE_LOGD("It's me!");
return true;
}
- // TODO: compare the service name.
- // service name might be unique.
-
- DPKey key = std::make_pair(ip, port);
- return (mDataPathList.count(key) > 0);
+ return (mDataPathList.count(string(service_name)) > 0);
}
int DPPubSub::get_joined_peer()
return mDataPathList.size();
}
-void DPPubSub::add_joined_peer(const char *ip, int port, vine_data_path_h datapath)
+void DPPubSub::add_joined_peer(const char *service_name, vine_data_path_h datapath)
{
- if (!ip || !datapath)
+ if (!service_name || !datapath)
return;
- VINE_LOGD("%s:%d, %p is added.", ip, port, datapath);
- DPKey key = std::make_pair(ip, port);
- mDataPathList.insert(std::make_pair(key, datapath));
+ VINE_LOGD("%s, %p is added.", service_name, datapath);
+ mDataPathList.insert(std::make_pair(string(service_name), datapath));
}
void DPPubSub::del_joined_peer(vine_data_path_h datapath)
DPMap::iterator found = std::find_if(mDataPathList.begin(),
mDataPathList.end(),
- [datapath](std::pair<DPKey, vine_data_path_h> const& item)
+ [datapath](std::pair<std::string, vine_data_path_h> const& item)
{
VINE_LOGD("item.second[%p]", item.second);
return (item.second == datapath);