Remote.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Remote
  2. //
  3. // Douglas
  4. //
  5. // Remote.java
  6. /* Copyright 2011 Douglas Thrift
  7. *
  8. * This file is part of Big Screen Bot.
  9. *
  10. * Big Screen Bot is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * Big Screen Bot is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with Big Screen Bot. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. package net.douglasthrift.bigscreenbot;
  24. import java.io.IOException;
  25. import java.net.InetAddress;
  26. import java.net.UnknownHostException;
  27. import java.security.KeyManagementException;
  28. import java.security.NoSuchAlgorithmException;
  29. import java.util.ArrayList;
  30. import java.util.List;
  31. import javax.jmdns.JmDNS;
  32. import javax.jmdns.ServiceInfo;
  33. import javax.net.ssl.SSLSocketFactory;
  34. import javax.net.ssl.KeyManager;
  35. import javax.net.ssl.KeyManagerFactory;
  36. import com.google.anymote.common.AnymoteFactory;
  37. import com.google.anymote.common.ErrorListener;
  38. import com.google.anymote.device.DeviceAdapter;
  39. import com.google.anymote.device.MessageReceiver;
  40. import com.google.polo.ssl.DummySSLSocketFactory;
  41. public class Remote
  42. {
  43. private static final String TYPE = "_anymote._tcp.local.";
  44. private Settings settings;
  45. private JmDNS mdns;
  46. public Remote(Settings settings) throws UnknownHostException, IOException
  47. {
  48. this.settings = settings;
  49. String interfaze = settings.getProperty("interface");
  50. if (interfaze != null)
  51. mdns = JmDNS.create(InetAddress.getByName(interfaze));
  52. else
  53. mdns = JmDNS.create();
  54. }
  55. public List<String> listDevices()
  56. {
  57. List<String> devices = new ArrayList<String>();
  58. for (ServiceInfo info : mdns.list(TYPE))
  59. devices.add(info.getName());
  60. return devices;
  61. }
  62. public void beginPairDevice(String device) throws NoSuchAlgorithmException, KeyManagementException
  63. {
  64. ServiceInfo info = mdns.getServiceInfo(TYPE, device);
  65. InetAddress address = info.getInetAddresses()[0];
  66. int port = info.getPort();
  67. SSLSocketFactory factory = DummySSLSocketFactory.fromKeyManagers(getKeyManagers());
  68. }
  69. @Override
  70. protected void finalize() throws IOException
  71. {
  72. mdns.close();
  73. }
  74. private KeyManager[] getKeyManagers() throws NoSuchAlgorithmException
  75. {
  76. KeyManagerFactory factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  77. //factory.init(store, "".toCharArray());
  78. return factory.getKeyManagers();
  79. }
  80. }
  81. // vim: expandtab