Example #1
0
        public bool FindService(ActionName wanted, string envelope, string ident, out ServiceInfo si, out ActionInfo ai)
        {
            lock (stateLock) {
                TimeCheck(DateTime.UtcNow);

                var cand = new List <ServiceInfo> ();
                foreach (var ssi in services.Values)
                {
                    if (ident != null && ident != ssi.Identity)
                    {
                        continue;
                    }
                    ActionInfo sai = ssi.LookupAction(wanted);
                    if (sai == null)
                    {
                        continue;
                    }

                    if (!auth.IsAuthorized(ssi, wanted))
                    {
                        continue;
                    }
                    if (!ssi.IsSignatureValid)
                    {
                        continue;
                    }
                    if (!ssi.Envelopes.Contains(envelope))
                    {
                        continue;
                    }

                    cand.Add(ssi);
                }

                si = null;
                ai = null;
                if (cand.Count == 0)
                {
                    return(false);
                }

                si = cand [new Random().Next(cand.Count)];
                ai = si.LookupAction(wanted);
                return(true);
            }
        }