Exemple #1
0
 void Service_Resolved(object o, ServiceResolvedEventArgs args)
 {
     var service = args.Service;
     foreach (IPAddress addr in service.HostEntry.AddressList)
     {
         var host = new HostModel() { Address = addr.ToString(), Port = (ushort)service.Port, Name = service.FullName, Id = new Guid(service.TxtRecord["NODEID"].ValueRaw) };
         Console.WriteLine("Address {0}:{1} resolved for {2} - {3} - ({4})", addr, (ushort)(service.Port), service.HostTarget, service.FullName, host.Id);
         lock (knownHosts)
         {
             if (!knownHosts.Any(i => i.Address == addr.ToString()) && !IPAddress.IsLoopback(addr))
             {
                 knownHosts.Add(host);
             }
             else
             {
                 for (int x = 0; x < knownHosts.Count; x++)
                 {
                     if (knownHosts[x].Address == addr.ToString())
                     {
                         host.Probed = knownHosts[x].Id == host.Id && knownHosts[x].Probed;
                         knownHosts[x] = host;
                         break;
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
 void HandleServiceAddResolved(object o, ServiceResolvedEventArgs args)
 {
     IResolvableService svc = o as IResolvableService;
     string desc = svc.Name;
     string host = svc.HostEntry.AddressList[0].ToString();
     foreach (ClientNode node in nvClients.NodeStore)
     {
         if (node.Description == desc && node.Host == host)
             return;
     }
     clientNodes.AddNode(new ClientNode(desc, host));
     this.nvClients.QueueDraw ();
 }
Exemple #3
0
        void HandleArgsServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            IResolvableService s = (IResolvableService)args.Service;
            Console.Error.WriteLine ("Resolved Zeroshare serivce: {0} - {1}:{2} ({3} TXT record entries) [PIN: {4}]", s.FullName, s.HostEntry.AddressList[0], s.Port, s.TxtRecord.Count, s.TxtRecord["PIN"].ValueString);

              		if (s.TxtRecord["PIN"].ValueString == PIN)
            {
                Console.Error.WriteLine ("Found my content source, streaming...");
                new StdinContentDecoder().Decode(new IPEndPoint(s.HostEntry.AddressList[0], s.Port));
                Running = false;
                Console.Error.WriteLine ("Streaming done");
            }
        }
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
			String servName = args.Service.Name + " [" + args.Service.TxtRecord["systemtype"].ValueString + "]";
			if (serviceIPDict.ContainsKey(servName) == false)
            {
                Boolean isCloverleafService = false;
                for (int i = 0; i < args.Service.TxtRecord.Count; i++)
                {
                    TxtRecordItem txt = args.Service.TxtRecord.GetItemAt(i);

                    if (txt.Key.ToLower() == "servicetype" && txt.ValueString.ToLower() == "cloverleaf")
                        isCloverleafService = true;
                }

                if (isCloverleafService == true)
                {
					serviceIPDict.Add(servName,
                        args.Service.HostEntry.AddressList[0].ToString());
                }
            }
        }
Exemple #5
0
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            string name = args.Service.Name;

            Log ("Managed to resolve DAAP share {0}.", args.Service.Name);

            bool password_required = false;

            // iTunes tacks this on to indicate a passsword protected share.  Ugh.
            if (name.EndsWith ("_PW")) {
                name = name.Substring (0, name.Length - 3);
                password_required = true;
            }

            IResolvableService service = (IResolvableService) args.Service;

            foreach(TxtRecordItem item in service.TxtRecord) {
                if(item.Key.ToLower () == "password") {
                    password_required = item.ValueString.ToLower () == "true";
                } else if (item.Key.ToLower () == "machine name") {
                    name = item.ValueString;
                }
            }

            IPAddress address = args.Service.HostEntry.AddressList[0];

            Log ("OnServiceResolved provided {0}", address);

            // XXX: Workaround a Mono bug where we can't resolve IPv6 addresses properly
            if (services.ContainsKey (name) && address.AddressFamily == AddressFamily.InterNetworkV6) {
                // Only skip this service if it resolves to a IPv6 address, and we already have info
                // for this service already.
                Log ("Skipping service: already have IPv4 address.");
                return;
            } else if (!services.ContainsKey (name) && address.AddressFamily == AddressFamily.InterNetworkV6) {
                // This is the first address we've resolved, however, it's an IPv6 address.
                // Try and resolve the hostname in hope that it'll end up as an IPv4 address - it doesn't
                // really matter if it still ends up with an IPv6 address, we're not risking anything.

                foreach (IPAddress addr in Dns.GetHostEntry (args.Service.HostEntry.HostName).AddressList) {
                    if (addr.AddressFamily == AddressFamily.InterNetwork) {
                        address = addr;
                    }
                }
            }

            Log ("Using address {0}", address);

            Dmap.Service svc = new Dmap.Service (address, (ushort)service.Port,
                name, password_required);

            if (services.ContainsKey (name)) {
                services[name] = svc;
            } else {
                services.Add (name, svc);
            }

            if (Found != null)
                Found (this, new ServiceArgs (svc));
        }
 private void ZcBrowserServiceResolved(object o, ServiceResolvedEventArgs args)
 {
     AddFoundServiceFromSCResolvedData(args.Service);
 }
 private static void OnServiceResolved(object o, ServiceResolvedEventArgs args)
 {
     IResolvableService service = o as IResolvableService;
     Console.Write ("*** Resolved name = '{0}', host ip = '{1}', hostname = {2}, port = '{3}', " + 
         "interface = '{4}', address type = '{5}'", 
         service.FullName, service.HostEntry.AddressList[0], service.HostEntry.HostName, service.Port, 
         service.NetworkInterface, service.AddressProtocol);
     
     ITxtRecord record = service.TxtRecord;
     int record_count = record != null ? record.Count : 0;
     if(record_count > 0) {
         Console.Write(", TXT Record = [");
         for(int i = 0, n = record.Count; i < n; i++) {
             TxtRecordItem item = record.GetItemAt(i);
             Console.Write("{0} = '{1}'", item.Key, item.ValueString);
             if(i < n - 1) {
                 Console.Write(", ");
             }
         }
         Console.WriteLine("]");
     } else {
         Console.WriteLine("");
     }
 }
Exemple #8
0
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            IResolvableService service = o as IResolvableService;
            String device = args.Service.Name + " [" + service.HostEntry.AddressList[0] + "]";
            syncContext.Post(delegate
            {
                if (!deviceList.Items.Contains(device))
                {
                    deviceList.Items.Add(device);
                    if (deviceList.Items.Count == 1)
                    {
                        // first device added, select it
                        deviceList.SelectedIndex = 0;
                    }
                }
            }, null);

            ITxtRecord record = service.TxtRecord;
            int record_count = record != null ? record.Count : 0;
            if (record_count > 0)
            {
                Console.Write(", TXT Record = [");
                for (int i = 0, n = record.Count; i < n; i++)
                {
                    TxtRecordItem item = record.GetItemAt(i);
                    Console.Write("{0} = '{1}'", item.Key, item.ValueString);
                    if (i < n - 1)
                    {
                        Console.Write(", ");
                    }
                }
                Console.WriteLine("]");
            }
            else
            {
                Console.WriteLine("");
            }
        }
Exemple #9
0
        void service_Resolved(object o, ServiceResolvedEventArgs args)
        {
            IResolvableService service = args.Service;
            service.Resolved -= new ServiceResolvedEventHandler(service_Resolved);

            DestinationPlatformType fcPlatform = KnownDestinationPlatformType.Other;
            if (service.TxtRecord != null)
            {
                foreach (TxtRecordItem record in service.TxtRecord)
                {
                    if (record.Key == "platform")
                    {
                        string platform = record.ValueString;
                        fcPlatform = KnownDestinationPlatformType.FromString(platform);
                        break;
                    }
                }
            }
            BonjourEventArgs e = new BonjourEventArgs(fcPlatform);

            this.OnServiceFound(service, e);
        }
Exemple #10
0
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            IResolvableService zc_service = args.Service;

            string name = zc_service.Name;
            string machineId = null;

            if (services[zc_service.Name] != null) {
                return; // we already have it somehow
            }

            bool pwRequired = false;

            // iTunes tacks this on to indicate a passsword protected share.  Ugh.
            if (name.EndsWith ("_PW")) {
                name = name.Substring (0, name.Length - 3);
                pwRequired = true;
            }

            foreach(TxtRecordItem item in zc_service.TxtRecord) {
                if(item.Key.ToLower () == "password") {
                    pwRequired = item.ValueString.ToLower () == "true";
                } else if (item.Key.ToLower () == "machine name") {
                    name = item.ValueString;
                } else if (item.Key.ToLower () == "machine id") {
                    machineId = item.ValueString;
                }
            }

            DAAP.Service svc = new DAAP.Service (zc_service.HostEntry.AddressList[0], (ushort)zc_service.Port,
                                                 name, pwRequired, machineId);

            services[svc.Name] = svc;

            if (Found != null)
                Found (this, new ServiceArgs (svc));
        }
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            IResolvableService s = (IResolvableService)args.Service;

                string name = s.Name;
                string machine_id = null;
                bool pwRequired = false;

                Console.WriteLine ("Resolved Service: {0} - {1}:{2} ({3} TXT record entries)",
                    s.FullName, s.HostEntry.AddressList [0], s.Port, s.TxtRecord.Count);

                if (name.EndsWith ("_PW")) {
                    name = name.Substring (0, name.Length - 3);
                    pwRequired = true;
                }

                foreach (TxtRecordItem item in s.TxtRecord) {
                    if (item.Key.ToLower () == "password") {
                        pwRequired = item.ValueString.ToLower () == "true";
                    } else if (item.Key.ToLower () == "machine name") {
                        name = item.ValueString;
                    } else if (item.Key.ToLower () == "machine id") {
                        machine_id = item.ValueString;
                    }
                }

                    DPAP.Service svc = new DPAP.Service (s.HostEntry.AddressList [0], (ushort)s.Port,
                                                name, pwRequired, machine_id);

            services [svc.Name] = svc;

            if (Found != null)
                Found (this, new ServiceArgs (svc));
        }
Exemple #12
0
        private void OnServiceResolved (object o, ServiceResolvedEventArgs args)
		{
			IResolvableService service = o as IResolvableService;

			lock(locker) {
				if (services.ContainsKey(service.Name)) {
					// TODO: When making changes (like name or photo) at runtime becomes possible
					// this should allow updates to this info
					return; // we already have it somehow
            	}
			}

            ServiceInfo serviceInfo = new ServiceInfo (service.Name, service.HostEntry.AddressList[0], (ushort)service.Port);

			ITxtRecord record = service.TxtRecord;
			serviceInfo.UserName = record["User Name"].ValueString;
			serviceInfo.MachineName = record["Machine Name"].ValueString;
			serviceInfo.Version = record["Version"].ValueString;
			serviceInfo.PhotoType = record["PhotoType"].ValueString;
			serviceInfo.PhotoLocation = record["Photo"].ValueString;
			
			Logger.Debug("Setting default photo");
			serviceInfo.Photo = Utilities.GetIcon("blankphoto", 48);
			
			lock(locker) {
				services[serviceInfo.Name] = serviceInfo;
				
				if(serviceInfo.PhotoType.CompareTo(Preferences.Local) == 0 ||
					serviceInfo.PhotoType.CompareTo (Preferences.Gravatar) == 0 ||
					serviceInfo.PhotoType.CompareTo (Preferences.Uri) == 0) {
					// Queue the resolution of the photo
					PhotoService.QueueResolve (serviceInfo);
				}		
			}

            if (ServiceAdded != null)
			{
				Logger.Debug("About to call ServiceAdded");
                ServiceAdded (this, new ServiceArgs (serviceInfo));
				Logger.Debug("ServiceAdded was just called");
			} else {
				Logger.Debug("ServiceAdded was null and not called");
			}
        }
        private void OnServiceResolved(object o, ServiceResolvedEventArgs args)
        {
            IResolvableService service = o as IResolvableService;
            if (service == null) {
                return;
            }

            Log.DebugFormat ("Resolved RAOP service at {0}", service.HostEntry.AddressList[0]);

            ITxtRecord record = service.TxtRecord;

            string version = String.Empty;
            int sample_size = 16, sample_rate = 44100, channels = 2;

            for (int i = 0, n = record.Count; i < n; i++) {
                TxtRecordItem item = record.GetItemAt(i);
                switch (item.Key) {
                    case "vs":
                        version = item.ValueString;
                        break;
                    case "ss":
                        sample_size = Convert.ToInt32 (item.ValueString);
                        break;
                    case "sr":
                        sample_rate = Convert.ToInt32 (item.ValueString);
                        break;
                    case "ch":
                        channels = Convert.ToInt32 (item.ValueString);
                        break;
                }
            }

            lock (speakers) {
                // TODO: better Name
                speakers.Add (new RemoteSpeaker (service.HostEntry.HostName,
                    service.HostEntry.AddressList[0], service.Port,
                    version, sample_rate, sample_size, channels));
            }

            EventHandler handler = SpeakersChanged;
            if (handler != null) {
                handler (this, EventArgs.Empty);
            }
        }
        static void Service_Resolved(object o, ServiceResolvedEventArgs args)
        {
            if (browser != null)
            {
                System.Net.IPAddress[] addresses = args.Service.HostEntry.AddressList;
                string strUid = args.Service.TxtRecord["uid"].ValueString;
                int uid = int.Parse(strUid);
                List<EndpointInfo> ei = null;

                if (DiscoveredPeers.ContainsKey(uid))
                {
                    ei = DiscoveredPeers[uid];
                }
                else
                {
                    ei = new List<EndpointInfo>(10);
                    lock (DiscoveredPeers)
                    {
                        DiscoveredPeers.Add(uid, ei);
                    }
                }

                lock (ei)
                {
                    foreach (System.Net.IPAddress addr in addresses)
                    {
                        ei.Add(new EndpointInfo() { UID = uid, Address = addr, Port = args.Service.Port });
                        //dict.StartClient(addr.ToString(), args.Service.Port);
                    }
                }
            }
        }
        static void ServiceRemoved_Resolved(object o, ServiceResolvedEventArgs args)
        {
            if (browser != null)
            {
                System.Net.IPAddress[] addresses = args.Service.HostEntry.AddressList;
                string strUid = args.Service.TxtRecord["uid"].ValueString;
                int uid = int.Parse(strUid);

                lock (DiscoveredPeers)
                {
                    DiscoveredPeers.Remove(uid);
                }
            }
        }