Changeset b5833c5654f5adca96495c030b1609efb4e5f57f
- Timestamp:
- 12/30/07 23:30:27
(1 year ago)
- Author:
- Jason Michalski <armooo@armooo.net>
- git-committer:
- Jason Michalski <armooo@armooo.net> 1199079027 -0600
- git-parent:
[00f2d9469dfe9bce49996e55c691e2a1a23051bb]
- git-author:
- William McBrine <wmcbrine@gmail.com> 1198986350 -0500
- Message:
Added the ability to listen for/send beacons on TCP port 2190, for use with the manual server menu. (Use "beacon = listen" in pyTivo.conf to listen only, or "beacon = 255.255.255.255 listen" (or whatever) to both broadcast and listen. With no beacon keyword, no listening occurs.)
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r00f2d94 |
rb5833c5 |
|
| 16 | 16 | return ';'.join(self.services) |
|---|
| 17 | 17 | |
|---|
| 18 | | def format_beacon(self): |
|---|
| | 18 | def format_beacon(self, conntype): |
|---|
| 19 | 19 | beacon = [] |
|---|
| 20 | 20 | |
|---|
| … | … | |
| 23 | 23 | beacon.append('tivoconnect=1') |
|---|
| 24 | 24 | beacon.append('swversion=1') |
|---|
| 25 | | beacon.append('method=broadcast') |
|---|
| | 25 | beacon.append('method=%s' % conntype) |
|---|
| 26 | 26 | beacon.append('identity=%s' % guid) |
|---|
| 27 | 27 | |
|---|
| … | … | |
| 35 | 35 | beacon_ips = config.getBeaconAddresses() |
|---|
| 36 | 36 | for beacon_ip in beacon_ips.split(): |
|---|
| 37 | | try: |
|---|
| 38 | | self.UDPSock.sendto(self.format_beacon(), (beacon_ip, 2190)) |
|---|
| 39 | | except error, e: |
|---|
| 40 | | print e |
|---|
| 41 | | pass |
|---|
| | 37 | if beacon_ip != 'listen': |
|---|
| | 38 | try: |
|---|
| | 39 | self.UDPSock.sendto(self.format_beacon('broadcast'), |
|---|
| | 40 | (beacon_ip, 2190)) |
|---|
| | 41 | except error, e: |
|---|
| | 42 | print e |
|---|
| 42 | 43 | |
|---|
| 43 | 44 | def start(self): |
|---|
| … | … | |
| 49 | 50 | self.timer.cancel() |
|---|
| 50 | 51 | |
|---|
| | 52 | def listen(self): |
|---|
| | 53 | """For the direct-connect, TCP-style beacon""" |
|---|
| | 54 | import thread |
|---|
| | 55 | |
|---|
| | 56 | def server(): |
|---|
| | 57 | import struct |
|---|
| | 58 | |
|---|
| | 59 | TCPSock = socket(AF_INET, SOCK_STREAM) |
|---|
| | 60 | TCPSock.bind(('', 2190)) |
|---|
| | 61 | TCPSock.listen(5) |
|---|
| | 62 | |
|---|
| | 63 | while True: |
|---|
| | 64 | # Wait for a connection |
|---|
| | 65 | client, address = TCPSock.accept() |
|---|
| | 66 | |
|---|
| | 67 | # Accept the client's beacon |
|---|
| | 68 | client_length = struct.unpack('!I', client.recv(4))[0] |
|---|
| | 69 | client_message = client.recv(client_length) |
|---|
| | 70 | |
|---|
| | 71 | print client_length |
|---|
| | 72 | |
|---|
| | 73 | # Send ours |
|---|
| | 74 | message = self.format_beacon('connected') |
|---|
| | 75 | client.send(struct.pack('!I', len(message))) |
|---|
| | 76 | client.send(message) |
|---|
| | 77 | client.close() |
|---|
| | 78 | |
|---|
| | 79 | thread.start_new_thread(server, ()) |
|---|
| | 80 | |
|---|
| 51 | 81 | if __name__ == '__main__': |
|---|
| 52 | 82 | b = Beacon() |
|---|
| 53 | 83 | |
|---|
| 54 | | |
|---|
| 55 | 84 | b.add_service('TiVoMediaServer:9032/http') |
|---|
| 56 | | b.send_beacon_timer() |
|---|
| | 85 | b.send_beacon() |
|---|
| r8698247 |
rb5833c5 |
|
| 1 | 1 | #!/usr/bin/env python |
|---|
| 2 | 2 | |
|---|
| 3 | | |
|---|
| 4 | 3 | import beacon, httpserver, os, sys |
|---|
| 5 | | |
|---|
| 6 | 4 | import config |
|---|
| 7 | 5 | |
|---|
| … | … | |
| 16 | 14 | b.add_service('TiVoMediaServer:' + str(port) + '/http') |
|---|
| 17 | 15 | b.start() |
|---|
| | 16 | if 'listen' in config.getBeaconAddresses(): |
|---|
| | 17 | b.listen() |
|---|
| 18 | 18 | |
|---|
| 19 | 19 | try: |
|---|
| … | … | |
| 21 | 21 | except KeyboardInterrupt: |
|---|
| 22 | 22 | b.stop() |
|---|
| 23 | | |
|---|