Exemple #1
0
        internal async Task <bool> RegisterSubscriber(Subscription sub, string datatype)
        {
            var args    = new XmlRpcValue(ThisNode.Name, sub.Name, datatype, XmlRpcManager.Instance.Uri);
            var result  = new XmlRpcValue();
            var payload = new XmlRpcValue();

            if (!await Master.ExecuteAsync("registerSubscriber", args, result, payload, true).ConfigureAwait(false))
            {
                logger.LogError($"RPC \"registerSubscriber\" for topic {sub.Name} failed.");
                return(false);
            }

            // get list of of publisher URIs
            var pubUris = payload
                          .Select(x => x.GetString())
                          .Distinct()
                          .ToList();

            Publication localPublication = null;

            lock (gate)
            {
                localPublication = advertisedTopics.FirstOrDefault(p => p.Name == sub.Name && !p.Dropped && Md5SumsMatch(p.Md5Sum, sub.Md5Sum));
            }

            await sub.PubUpdate(pubUris).ConfigureAwait(false);

            if (localPublication != null)    // self-subscribed
            {
                sub.AddLocalConnection(localPublication);
            }

            return(true);
        }