void NodeQuery::removed(const NodeStub& node) { ScopeLock lock(_mutex); assert(node); if (_notifyImmediately) { UM_LOG_DEBUG("Removed node %s", SHORT_UUID(node.getUUID()).c_str()); _listener->removed(node); _nodes.erase(node.getUUID()); } else { _pendingRemovals.insert(node); } }
void NodeQuery::found(const NodeStub& node) { ScopeLock lock(_mutex); assert(node); if (_notifyImmediately) { if (_nodes.find(node.getUUID()) != _nodes.end()) { // UM_LOG_DEBUG("Changed node %s", SHORT_UUID(node->getUUID()).c_str()); _listener->changed(node); } else { UM_LOG_DEBUG("Added node %s", SHORT_UUID(node.getUUID()).c_str()); _listener->added(node); _nodes[node.getUUID()] = node; } } else { _pendingFinds.insert(node); } }
void RTPPublisher::removed(const SubscriberStub& sub, const NodeStub& node) { RScopeLock lock(_mutex); int status; std::string ip = sub.getIP(); uint16_t port = sub.getPort(); if (!ip.length()) //only use separate subscriber ip (for multicast support etc.), if specified ip = node.getIP(); // do we now about this sub via this node? bool subscriptionFound = false; std::pair<_domainSubs_t::iterator, _domainSubs_t::iterator> subIter = _domainSubs.equal_range(sub.getUUID()); while(subIter.first != subIter.second) { if (subIter.first->second.first.getUUID() == node.getUUID()) { subscriptionFound = true; break; } subIter.first++; } if (!subscriptionFound) return; UM_LOG_INFO("%s: lost a %s subscriber (%s:%u) for channel %s", SHORT_UUID(_uuid).c_str(), sub.isMulticast() ? "multicast" : "unicast", ip.c_str(), port, _channelName.c_str()); struct libre::sa addr; libre::sa_init(&addr, AF_INET); if ((status = libre::sa_set_str(&addr, ip.c_str(), port))) UM_LOG_WARN("%s: error %d in libre::sa_set_str(%s:%u): %s", SHORT_UUID(_uuid).c_str(), status, ip.c_str(), port, strerror(status)); else _destinations.erase(ip+":"+toStr(port)); if (_domainSubs.count(sub.getUUID()) == 1) { // about to vanish if (_greeter != NULL) { Publisher pub(Publisher(StaticPtrCast<PublisherImpl>(shared_from_this()))); _greeter->farewell(pub, sub); } _subs.erase(sub.getUUID()); } _domainSubs.erase(subIter.first); UMUNDO_SIGNAL(_pubLock); }
void RTPPublisher::added(const SubscriberStub& sub, const NodeStub& node) { RScopeLock lock(_mutex); int status; std::string ip = sub.getIP(); uint16_t port = sub.getPort(); if (!ip.length()) //only use separate subscriber ip (for multicast support etc.), if specified ip = node.getIP(); // do we already now about this sub via this node? std::pair<_domainSubs_t::iterator, _domainSubs_t::iterator> subIter = _domainSubs.equal_range(sub.getUUID()); while(subIter.first != subIter.second) { if (subIter.first->second.first.getUUID() == node.getUUID()) return; // we already know about this sub from this node subIter.first++; } UM_LOG_INFO("%s: received a new %s subscriber (%s:%u) for channel %s", SHORT_UUID(_uuid).c_str(), sub.isMulticast() ? "multicast" : "unicast", ip.c_str(), port, _channelName.c_str()); struct libre::sa addr; libre::sa_init(&addr, AF_INET); status = libre::sa_set_str(&addr, ip.c_str(), port); if (status) { UM_LOG_WARN("%s: error %d in libre::sa_set_str(%s:%u): %s", SHORT_UUID(_uuid).c_str(), status, ip.c_str(), port, strerror(status)); } else { _destinations[ip + ":" + toStr(port)] = addr; } _subs[sub.getUUID()] = sub; _domainSubs.insert(std::make_pair(sub.getUUID(), std::make_pair(node, sub))); if (_greeter != NULL && _domainSubs.count(sub.getUUID()) == 1) { // only perform greeting for first occurence of subscriber Publisher pub(StaticPtrCast<PublisherImpl>(shared_from_this())); _greeter->welcome(pub, sub); } UMUNDO_SIGNAL(_pubLock); }