webXMPP

Check-in [3ffad81c57]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Counterpart to protocol changes in chore/pong.py, we are now NAT/firewall friendly.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:3ffad81c57fd111eee9f7e08f74959c0e487c04b824afde6bd8893a5299c31b4
User & Date: vandyswa@gmail.com 2017-07-01 00:00:55
Context
2017-07-01
00:03
Merge branch 'master' of https://github.com/vandys/webXMPP check-in: bbd719910e user: ajv-899-334-8894@vsta.org tags: master, trunk
00:00
Counterpart to protocol changes in chore/pong.py, we are now NAT/firewall friendly. check-in: 3ffad81c57 user: vandyswa@gmail.com tags: master, trunk
2017-06-30
05:09
Merge branch 'master' of https://github.com/vandys/-webXMPP check-in: 04a597a22e user: vandyswa@gmail.com tags: master, trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to notified.py.

   206    206   
   207    207       # Watch DBus to turn LED's off when screen unlocks
   208    208       setup_dbus()
   209    209   
   210    210       # Prepare for notifications
   211    211       notify2.init("Messsaging")
   212    212   
   213         -    # Params; we in particular need to know the server's
   214         -    #  intended timeout.
   215         -    while True:
   216         -        pak = conn.pingpong(conn.msg("params", "get"))
   217         -        if pak is not None:
   218         -            break
   219         -        time.sleep(pong.WAITNET)
          213  +    # Our notification server
          214  +    dest = (cfg.server, cfg.port)
   220    215   
   221         -    # This is how long they'll hold a notify/get pending before
   222         -    #  sending back a null result.
   223         -    # If we request one and don't hear back in this amount of
   224         -    #  time, we have a lost packet or something.
   225         -    tmo = pak.inner["timeout"] * 1.1
   226         -
   227         -    # Server loop
   228         -    dest = (cfg.server, cfg.port)
          216  +    # We need a send-receive-send pattern as a minimum to become
          217  +    #  an assured/streaming UDP "connection".  This loop starts
          218  +    #  a new socket, does a param get/got, and then a timed
          219  +    #  get.  At the timeout, the server provides a "got", after
          220  +    #  which we send another "get".  This keeps the firewall/NAT
          221  +    #  state alive indefinitely, at a cost of one transmit and
          222  +    #  one receive every 2.5 minutes.
          223  +    # When we hit a network error (usually due to change in our
          224  +    #  IP address), we reset the connection and start over with
          225  +    #  the param get/got.
   229    226       while True:
   230         -        # Always yield for a second, so no matter
   231         -        #  what we never CPU spin hard.
   232         -        time.sleep(1)
   233         -
   234         -        # Next round of notifications
   235         -        # Request events starting at this serial number
   236         -        pak = conn.msg("notify", "get", {
   237         -            "gen": gen,
   238         -            "detail": cfg.detail,
   239         -            "nmsg": cfg.nmsg})
   240         -        pak.who = dest
   241         -        resp = conn.ping_pong(pak, tmo)
   242         -
   243         -        # Failure
   244         -        if resp is None:
          227  +        # Params; we in particular need to know the server's
          228  +        #  intended timeout.
          229  +        while True:
          230  +            pak = conn.pingpong(conn.msg("params", "get"))
          231  +            if pak is not None:
          232  +                break
          233  +            # Note that on error, the "pong" library will already
          234  +            #  have closed out the socket
   245    235               time.sleep(pong.WAITNET)
   246         -            continue
          236  +
          237  +        # This is how long they'll hold a notify/get pending before
          238  +        #  sending back a null result.
          239  +        # If we request one and don't hear back in this amount of
          240  +        #  time, we have a lost packet or something.
          241  +        # 1.1 is our 10% slop factor over the expected timeout
          242  +        #  from the server.
          243  +        tmo = pak.inner["timeout"] * 1.1
          244  +
          245  +        # Server loop
          246  +        while True:
          247  +            # Always yield for a second, so no matter
          248  +            #  what we never CPU spin hard.
          249  +            time.sleep(1)
          250  +
          251  +            # Next round of notifications
          252  +            # Request events starting at this serial number
          253  +            pak = conn.msg("notify", "get", {
          254  +                "gen": gen,
          255  +                "detail": cfg.detail,
          256  +                "nmsg": cfg.nmsg})
          257  +            pak.who = dest
          258  +            resp = conn.ping_pong(pak, tmo)
          259  +
          260  +            # Failure
          261  +            if resp is None:
          262  +                # We drop out of the server loop, and start over
          263  +                #  with a fresh socket and param get/got
          264  +                time.sleep(pong.WAITNET)
          265  +                break
   247    266   
   248         -        # Nothing happened
   249         -        if resp.inner["gen"] == gen:
   250         -            continue
          267  +            # Nothing happened
          268  +            if resp.inner["gen"] == gen:
          269  +                continue
   251    270   
   252         -        # New messages
   253         -        notify(resp)
   254         -        gen = resp.inner["gen"]
          271  +            # New messages
          272  +            notify(resp)
          273  +            gen = resp.inner["gen"]
   255    274   
   256    275   if __name__ == "__main__":
   257    276       load_cfg()
   258    277   
   259    278       # No arg, just be a service daemon
   260    279       if len(sys.argv) == 1:
   261    280           run()