Commit e15da4c4 authored by Julien Muchembled's avatar Julien Muchembled

New re6st.version module

- new -V/--version command line option
- protocol extended to get the version of any node in the network,
  which will allow to track those running an old version of re6st
parent 6b7605e7
...@@ -15,9 +15,8 @@ build-package: debian/changelog ...@@ -15,9 +15,8 @@ build-package: debian/changelog
dpkg-buildpackage -us -uc -b dpkg-buildpackage -us -uc -b
debian/changelog: debian/changelog:
printf 're6stnet (0-%u.g%s) nexedi; urgency=low\n\n -- %s %s\n' \ printf 're6stnet (%s) nexedi; urgency=low\n\n -- %s %s\n' \
"`git rev-list --topo-order --count HEAD`" \ "`python re6st/version.py`" \
"`git rev-parse --short HEAD`" \
"`git var GIT_COMMITTER_IDENT |sed 's/\(.*>\) .*/\\1/'`" \ "`git var GIT_COMMITTER_IDENT |sed 's/\(.*>\) .*/\\1/'`" \
"`date -R`" >debian/changelog "`date -R`" >debian/changelog
......
import logging, random, socket, subprocess, time import logging, random, socket, subprocess, time
from collections import defaultdict, deque from collections import defaultdict, deque
from . import plib, utils from . import plib, utils, version
PORT = 326 PORT = 326
...@@ -417,6 +417,12 @@ class TunnelManager(object): ...@@ -417,6 +417,12 @@ class TunnelManager(object):
if address: if address:
self._address[family] = utils.dump_address(address) self._address[family] = utils.dump_address(address)
def _sendto(self, to, msg):
try:
return self.sock.sendto(msg, to[:2])
except socket.error, e:
logging.info('Failed to send message to %s (%s)', to, e)
def handlePeerEvent(self): def handlePeerEvent(self):
msg, address = self.sock.recvfrom(1<<16) msg, address = self.sock.recvfrom(1<<16)
if address[0] == '::1': if address[0] == '::1':
...@@ -447,13 +453,11 @@ class TunnelManager(object): ...@@ -447,13 +453,11 @@ class TunnelManager(object):
self._makeTunnel(prefix, address) self._makeTunnel(prefix, address)
elif code == 2: # request elif code == 2: # request
if self._address: if self._address:
msg = '\1%s %s\n' % (self._prefix, self._sendto(address, '\1%s %s\n' % (self._prefix,
';'.join(self._address.itervalues())) ';'.join(self._address.itervalues())))
try:
self.sock.sendto(msg, address[:2])
except socket.error, e:
logging.info('Failed to reply to %s (%s)', address, e)
#else: # I don't know my IP yet! #else: # I don't know my IP yet!
elif code == 3:
self._sendto(address, '\4' + version.version)
elif code == 255: elif code == 255:
# the registry wants to know the topology for debugging purpose # the registry wants to know the topology for debugging purpose
if not sender or sender[len(self._network):].startswith( if not sender or sender[len(self._network):].startswith(
......
import subprocess as _S
from os.path import dirname as _d
_d = _d(__file__)
def _git_call(*args):
return _S.call(("git",) + args, cwd=_d)
def _git_output(*args):
p = _S.Popen(("git",) + args, cwd=_d, stdout=_S.PIPE, stderr=_S.PIPE)
out, err = p.communicate()
if p.returncode:
raise _S.CalledProcessError(p.returncode, "git", err)
return out.strip()
_git_call("update-index", "-q", "--refresh")
dirty = _git_call("diff-index", "--quiet", "HEAD", "--")
if dirty not in (0, 1):
raise _S.CalledProcessError(dirty, "git")
revision = int(_git_output("rev-list", "--topo-order", "--count", "HEAD"))
short = _git_output("rev-parse", "--short", "HEAD")
version = "0-%s.g%s" % (revision, short)
if dirty:
version += ".dirty"
if __name__ == "__main__":
print version
...@@ -3,7 +3,7 @@ import atexit, errno, logging, os, select, signal, socket ...@@ -3,7 +3,7 @@ import atexit, errno, logging, os, select, signal, socket
import sqlite3, subprocess, sys, time, threading import sqlite3, subprocess, sys, time, threading
from collections import deque from collections import deque
from OpenSSL import crypto from OpenSSL import crypto
from re6st import db, plib, tunnel, utils from re6st import db, plib, tunnel, utils, version
from re6st.registry import RegistryClient, RENEW_PERIOD from re6st.registry import RegistryClient, RENEW_PERIOD
from re6st.utils import exit from re6st.utils import exit
...@@ -14,6 +14,7 @@ def getConfig(): ...@@ -14,6 +14,7 @@ def getConfig():
parser = utils.ArgParser(fromfile_prefix_chars='@', parser = utils.ArgParser(fromfile_prefix_chars='@',
description="Resilient virtual private network application.") description="Resilient virtual private network application.")
_ = parser.add_argument _ = parser.add_argument
_('-V', '--version', action='version', version=version.version)
_('--ip', action='append', default=[], _('--ip', action='append', default=[],
help="IP address advertised to other nodes. Special values:\n" help="IP address advertised to other nodes. Special values:\n"
......
%define _builddir %(pwd) %define _builddir %(pwd)
%define ver %(python re6st/version.py)
Summary: resilient, scalable, IPv6 network application Summary: resilient, scalable, IPv6 network application
Name: re6stnet Name: re6stnet
Version: 0 Version: %(set %ver; echo ${1%%-*})
Release: %(git rev-list --topo-order --count HEAD).g%(git rev-parse --short HEAD) Release: %(set %ver; echo ${1#*-})
License: GPLv2+ License: GPLv2+
Group: Applications/Internet Group: Applications/Internet
BuildArch: noarch BuildArch: noarch
...@@ -63,5 +64,5 @@ if [ $1 -ge 1 ] ; then ...@@ -63,5 +64,5 @@ if [ $1 -ge 1 ] ; then
fi fi
%changelog %changelog
* Fri Dec 10 2012 Julien Muchembled <jm@nexedi.com> * Mon Dec 10 2012 Julien Muchembled <jm@nexedi.com>
- Initial package - Initial package
...@@ -2,6 +2,30 @@ ...@@ -2,6 +2,30 @@
""" """
from setuptools import setup, find_packages from setuptools import setup, find_packages
from setuptools.command import sdist as _sdist, build_py as _build_py
from distutils import log
from re6st import version
version = {"__file__": "re6st/version.py"}
execfile(version["__file__"], version)
def copy_file(self, infile, outfile, *args, **kw):
if infile == version["__file__"]:
if not self.dry_run:
log.info("generating %s -> %s", infile, outfile)
with open(outfile, "wb") as f:
for x in sorted(version.iteritems()):
if not x[0].startswith("_"):
f.write("%s = %r\n" % x)
return outfile, 1
cls, = self.__class__.__bases__
return cls.copy_file(self, infile, outfile, *args, **kw)
class build_py(_build_py.build_py):
copy_file = copy_file
class sdist(_sdist.sdist):
copy_file = copy_file
classifiers = """\ classifiers = """\
Environment :: Console Environment :: Console
...@@ -16,7 +40,7 @@ Topic :: System :: Networking ...@@ -16,7 +40,7 @@ Topic :: System :: Networking
setup( setup(
name = 're6stnet', name = 're6stnet',
version = '0.1', version = version["version"],
description = __doc__.strip(), description = __doc__.strip(),
author = 'Nexedi', author = 'Nexedi',
author_email = 're6stnet@erp5.org', author_email = 're6stnet@erp5.org',
...@@ -43,4 +67,5 @@ setup( ...@@ -43,4 +67,5 @@ setup(
# "http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.7.20120714.tar.gz#egg=miniupnpc-1.7", # "http://miniupnp.free.fr/files/download.php?file=miniupnpc-1.7.20120714.tar.gz#egg=miniupnpc-1.7",
# ], # ],
zip_safe = False, zip_safe = False,
cmdclass=dict(build_py=build_py, sdist=sdist),
) )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment