34 import Pyro |
34 import Pyro |
35 import Pyro.core |
35 import Pyro.core |
36 import Pyro.util |
36 import Pyro.util |
37 from Pyro.errors import PyroError |
37 from Pyro.errors import PyroError |
38 |
38 |
39 service_type = '_PYRO._tcp.local.' |
39 zeroconf_service_type = '_PYRO._tcp.local.' |
40 # this module attribute contains a list of DNS-SD (Zeroconf) service types |
40 # this module attribute contains a list of DNS-SD (Zeroconf) service types |
41 # supported by this connector confnode. |
41 # supported by this connector confnode. |
42 # |
42 # |
43 # for connectors that do not support DNS-SD, this attribute can be omitted |
43 # for connectors that do not support DNS-SD, this attribute can be omitted |
44 # or set to an empty list. |
44 # or set to an empty list. |
51 confnodesroot.logger.write(_("PYRO connecting to URI : %s\n") % uri) |
51 confnodesroot.logger.write(_("PYRO connecting to URI : %s\n") % uri) |
52 |
52 |
53 servicetype, location = uri.split("://") |
53 servicetype, location = uri.split("://") |
54 if servicetype == "PYROS": |
54 if servicetype == "PYROS": |
55 import connectors.PYRO.PSK_Adapter |
55 import connectors.PYRO.PSK_Adapter |
56 schemename = "PYROLOCPSK" |
56 schemename = "PYROPSK" |
57 urlpath, ID = location.split('#') |
57 url, ID = location.split('#') |
58 # load PSK from project |
58 # load PSK from project |
59 secpath = os.path.join(str(confnodesroot.ProjectPath), 'psk', ID+'.secret') |
59 secpath = os.path.join(str(confnodesroot.ProjectPath), 'psk', ID+'.secret') |
60 if not os.path.exists(secpath): |
60 if not os.path.exists(secpath): |
61 confnodesroot.logger.write_error( |
61 confnodesroot.logger.write_error( |
62 'Error: Pre-Shared-Key Secret in %s is missing!\n' % secpath) |
62 'Error: Pre-Shared-Key Secret in %s is missing!\n' % secpath) |
63 return None |
63 return None |
64 Pyro.config.PYROPSK = open(secpath).read() |
64 Pyro.config.PYROPSK = (open(secpath).read(), ID) |
|
65 # strip ID from URL, so that pyro can understand it. |
|
66 location = url |
65 else: |
67 else: |
66 schemename = "PYROLOC" |
68 schemename = "PYROLOC" |
67 |
69 |
68 if location.find(service_type) != -1: |
70 if location.find(zeroconf_service_type) != -1: |
69 try: |
71 try: |
70 from zeroconf import Zeroconf |
72 from zeroconf import Zeroconf |
71 r = Zeroconf() |
73 r = Zeroconf() |
72 i = r.get_service_info(service_type, location) |
74 i = r.get_service_info(zeroconf_service_type, location) |
73 if i is None: |
75 if i is None: |
74 raise Exception("'%s' not found" % location) |
76 raise Exception("'%s' not found" % location) |
75 ip = str(socket.inet_ntoa(i.address)) |
77 ip = str(socket.inet_ntoa(i.address)) |
76 port = str(i.port) |
78 port = str(i.port) |
77 newlocation = ip + ':' + port |
79 newlocation = ip + ':' + port |