Giter VIP home page Giter VIP logo

sleepproxyserver's Introduction

SleepProxyServer

mDNS (Bonjour) Sleep Proxy Server implementation for Python

Provides the Wake on Demand service, similarly to Apple TV and Airport Express devices

Status

SPS has been tested against SleepProxyClient, OSX 10.9's mDNSResponder, and OSX 10.10's discoveryd.
See Debugging instructions below to test other implementations.
Selective-port waking is not implemented, any TCP request to a sleep client will result in a wakeup attempt.

A port to C(++) or Go would be welcome for resource limited ARM devices.

Internals

The included server daemon, scripts/sleeproxyd, binds port 5353 and loops up some greenlets:

  • dnsserve.py: Handle DNSUPDATE registrations sent to UDP:5353 from sleep proxy clients (aka. "sleepers") that are powering down
  • arp.py: Spoof ARP replies for requests from wakers for the sleepers' IP addr. Also monitors sleepers own gratuitous ARPs after wakeup, which deregisters them.
  • mdns.py: Mirrors the mDNS service advertisements of sleepers with Avahi so that their services can still be browsed by wakers on the local network.
  • tcp.py: Listen for wakers' TCP requests to sleepers. On receipt, will attempt to wake the sleeper with a WOL "magic packet".

Installation

Being based on ZeroConf, SPS requires almost no configuration.
Just run it and clients will see its mDNS advertisement and register to it within their regular polling intervals and/or just before sleeping.
sudo pmset networkoversleep 1 may be necessary to ensure OSX clients will publish services at-all-costs.
You must ensure both SPS server and client use the same network-segment and IP subnet and that IP Multicast traffic between them is not blocked.

gevent 1.0 is required for its co-operative threading feature; its packaged in Debian jessie.
Because of this, SPS can't be run under python3 (FIXME: replace gevent with asyncio)

  • Debian 8.0+ (jessie) & Ubuntu 14.04+ (Trusty Tahr)
apt-get install python-scapy python-netifaces python-dbus python-gevent python-pip python-setuptools avahi-daemon git
pip install git+https://github.com/kfix/SleepProxyServer.git
nohup sleepproxyd >/dev/null 2>&1 &
#^put that in rc.local or an initscript or systemd-unit

Development & Debugging

  • run a canned client-less server and test a with a mock registration
scripts/test
  • debug segfaults in cpython or gevent on Debian/Ubuntu
apt-get install gdb python2.7-dbg libc6-dbg python-dbus-dbg python-netifaces-dbg
cd SleepProxyServer/
python setup.py develop --exclude-scripts
gdb -ex r --args python2.7 scripts/sleepproxyd
  • play with scapy filters
scapy
sniff(tcpwatch, prn=lambda x: x.display(), filter='tcp[tcpflags] & tcp-syn != 0 and tcp[tcpflags] & tcp-ack = 0 and dst host 10.1.0.15', iface='eth0')
sniff(prn=lambda x: x.display(), filter='arp host 10.1.0.15', iface='eth0')
  • Watch OSX syslog for alll SPS-related actions (sudo-root required) Press Ctrl-T to sleep-wake-cycle your Mac, generating a SPS registration
scripts/sleepproxy_debug_osx

Further Reading

sleepproxyserver's People

Contributors

kfix avatar rcloran avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.