Пример #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;
            }
        }
Пример #2
0
        public ServiceInfo(X509Certificate2 cert, string sector, string identity, string[] envelopes, ActionInfo[] actions)
        {
            serverInstance = true;
            serviceCert = cert ?? CryptoUtils.LoadKeyPair (SOAConfig.Config.Get (identity + ".soa_cert", null), SOAConfig.Config.Get (identity + ".soa_key", null));
            this.packetVersion = 3;
            this.identity = identity + ':' + CryptoUtils.RandomBase64 (24);
            this.sector = sector;
            this.weight = 1.0;
            this.sendInterval = 5000.0;
            this.envelopes = (string[])envelopes.Clone ();
            this.actions = (ActionInfo[])actions.Clone ();

            foreach (var ac in actions) {
                if (ac.Name.Sector != Sector)
                    throw new ArgumentException ("action sector must match service sector");
            }

            CreateActionLookup ();
        }