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;
            }
        }
Example #2
0
        public virtual void DoMain(string[] argv)
        {
            this.info = ScanServiceDescription (Assembly.GetCallingAssembly ());

            wq = new WorkQueue (20);
            srv = new SCAMPSOAServer (info.Certificate, OnMessage);
            ann = new MulticastAnnouncer (info, srv.Bindings);
            new ManualResetEvent (false).WaitOne ();
        }
Example #3
0
 public bool IsAuthorized(ServiceInfo inf, ActionName act)
 {
     var cert = inf.Certificate;
     if (cert == null)
         return false;
     Regex checker;
     if (!compiledAuth.TryGetValue (CryptoUtils.Fingerprint (cert), out checker))
         return false;
     return checker.IsMatch (act.Sector + ':' + act.Namespace + '.' + act.Name);
 }
Example #4
0
        public MulticastAnnouncer(ServiceInfo info, IDictionary<IPAddress, string> serviceAddresses)
        {
            this.info = info;
            this.serviceAddresses = serviceAddresses;

            foreach (var ip in SOAConfig.Config.BusDiscoveryAddresses) {
                try {
                    var cl = new UdpClient (new IPEndPoint (ip, SOAConfig.Config.BusPort));
                    cl.JoinMulticastGroup (SOAConfig.Config.BusMulticastGroup, ip);
                    sockets [ip] = cl;
                } catch (Exception ex) {
                    Logger.LogError ("Failed to create announce socket for {0}: {1}", ip, ex);
                }
            }

            tmr = new Timer (SendAnnouncements);
            Reset ();
        }
Example #5
0
        /// <summary>
        /// Receives a service blob into the store.
        /// </summary>
        /// <remarks>This should be called with the object lock held.</remarks>
        /// <param name="blob">Signed, uncompressed service blob.</param>
        protected void Insert(string blob)
        {
            // do we already have this exact blob?
            if (services.ContainsKey (blob))
                return;

            ServiceInfo inf = null;
            if (stash != null)
                stash.TryGetValue (blob, out inf);

            try {
                if (inf == null)
                    inf = new ServiceInfo (blob);
            } catch (Exception ex) {
                Logger.LogInfo ("Failed to parse service blob {0}: {1}", blob, ex);
                return;
            }

            if (checkedReplace) {
                if (!inf.IsSignatureValid)
                    return;
                string id = inf.DeduplicationKey;
                ServiceInfo old;
                if (servicesByID.TryGetValue (id, out old)) {
                    if (inf.Timestamp <= old.Timestamp) {
                        Logger.LogInfo ("Received new service blob for {0} with timestamp {1} but the newest seen timestamp is already {2}",
                            id, inf.Timestamp, old.Timestamp);
                        return;
                    }

                    servicesByID.Remove (id);
                    services.Remove (old.Source);
                }
                servicesByID [id] = inf;
            }

            services [blob] = inf;
        }
Example #6
0
 static SOAClient GetConnection(ServiceInfo si)
 {
     lock (conn_lock) {
         SOAClient cl;
         if (!connections.TryGetValue (si.URI, out cl) || cl.Closed) {
             Uri parsed = new Uri (si.URI);
             switch (parsed.Scheme) {
             case "scamp+tls":
                 cl = new SCAMPSOAClient (parsed, si.Certificate);
                 break;
             default:
                 throw new RPCException ("general", "No connection handler available for scheme {0}", parsed.Scheme);
             }
             connections [si.URI] = cl;
         }
         return cl;
     }
 }