mirror of
https://github.com/svpcom/wfb-ng.git
synced 2025-02-19 07:03:48 -04:00
Add support of python3.x
This commit is contained in:
parent
9b2d8df981
commit
8c6f66bec7
2
setup.py
2
setup.py
@ -1,12 +1,12 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from setuptools import setup, find_packages, command
|
from setuptools import setup, find_packages, command
|
||||||
import distutils.command.bdist_rpm as orig
|
import distutils.command.bdist_rpm as orig
|
||||||
import setuptools.command.bdist_rpm as orig2
|
import setuptools.command.bdist_rpm as orig2
|
||||||
|
|
||||||
|
|
||||||
class bdist_rpm(orig.bdist_rpm):
|
class bdist_rpm(orig.bdist_rpm):
|
||||||
"""
|
"""
|
||||||
Override the default bdist_rpm behavior to do the following:
|
Override the default bdist_rpm behavior to do the following:
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
Depends: python-twisted, libpcap-dev, libsodium-dev, python-pyroute2
|
Depends: python-twisted, libpcap-dev, libsodium-dev, python-pyroute2, python-future, python-configparser
|
||||||
Package: wifibroadcast
|
Package: wifibroadcast
|
||||||
|
@ -18,6 +18,15 @@
|
|||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
|
||||||
|
from builtins import *
|
||||||
import sys
|
import sys
|
||||||
import curses
|
import curses
|
||||||
import curses.textpad
|
import curses.textpad
|
||||||
@ -33,7 +42,7 @@ from telemetry.conf import settings
|
|||||||
|
|
||||||
|
|
||||||
class AntennaStat(LineReceiver):
|
class AntennaStat(LineReceiver):
|
||||||
delimiter = '\n'
|
delimiter = b'\n'
|
||||||
|
|
||||||
def lineReceived(self, line):
|
def lineReceived(self, line):
|
||||||
attrs = json.loads(line)
|
attrs = json.loads(line)
|
||||||
@ -62,7 +71,7 @@ class AntennaStat(LineReceiver):
|
|||||||
x += len(msg)
|
x += len(msg)
|
||||||
|
|
||||||
if rssi_d:
|
if rssi_d:
|
||||||
for i, (k, v) in enumerate(sorted(rssi_d.iteritems())):
|
for i, (k, v) in enumerate(sorted(rssi_d.items())):
|
||||||
pkt_s, rssi_min, rssi_avg, rssi_max = v
|
pkt_s, rssi_min, rssi_avg, rssi_max = v
|
||||||
self.factory.window.addstr(i + 4, 0, '%04x: %d pkt/s, rssi %d < %d < %d\n' % (int(k, 16), pkt_s, rssi_min, rssi_avg, rssi_max))
|
self.factory.window.addstr(i + 4, 0, '%04x: %d pkt/s, rssi %d < %d < %d\n' % (int(k, 16), pkt_s, rssi_min, rssi_avg, rssi_max))
|
||||||
else:
|
else:
|
||||||
@ -118,9 +127,9 @@ def init(stdscr, profile):
|
|||||||
|
|
||||||
height, width = stdscr.getmaxyx()
|
height, width = stdscr.getmaxyx()
|
||||||
height -= 1
|
height -= 1
|
||||||
w1h = height / 3
|
w1h = height // 3
|
||||||
w1w = width
|
w1w = width
|
||||||
w2h = height / 3
|
w2h = height // 3
|
||||||
w2w = width
|
w2w = width
|
||||||
w3h = height - w1h - w2h
|
w3h = height - w1h - w2h
|
||||||
w3w = width
|
w3w = width
|
||||||
@ -163,7 +172,7 @@ def main():
|
|||||||
stderr = sys.stderr
|
stderr = sys.stderr
|
||||||
|
|
||||||
if len(sys.argv) != 2:
|
if len(sys.argv) != 2:
|
||||||
print >> stderr, "Usage: %s <profile>" % (sys.argv[0],)
|
print("Usage: %s <profile>" % (sys.argv[0],), file=stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
fd = tempfile.TemporaryFile()
|
fd = tempfile.TemporaryFile()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (C) 2018 Vasily Evseenko <svpcom@p2ptech.org>
|
# Copyright (C) 2018, 2019 Vasily Evseenko <svpcom@p2ptech.org>
|
||||||
|
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
@ -18,6 +18,16 @@
|
|||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
|
||||||
|
from builtins import *
|
||||||
|
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet import reactor, defer, task
|
from twisted.internet import reactor, defer, task
|
||||||
from telemetry.conf import settings
|
from telemetry.conf import settings
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
|
||||||
|
from builtins import *
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from telemetry import config_parser
|
from telemetry import config_parser
|
||||||
@ -14,7 +24,7 @@ def _parse_config(telemetry_cfg=None):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
settings, cfg_files = _parse_config()
|
settings, cfg_files = _parse_config()
|
||||||
except Exception, v:
|
except Exception as v:
|
||||||
print >>sys.stderr, 'ERROR: Unable to parse config: %s' % (v,)
|
print('ERROR: Unable to parse config: %s' % (v,), file=sys.stderr)
|
||||||
_cfg_files = [ 'master.cfg', 'site.cfg' ]
|
_cfg_files = [ 'master.cfg', 'site.cfg' ]
|
||||||
settings, cfg_files = _parse_config()
|
settings, cfg_files = _parse_config()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (C) 2018 Vasily Evseenko <svpcom@p2ptech.org>
|
# Copyright (C) 2018, 2019 Vasily Evseenko <svpcom@p2ptech.org>
|
||||||
|
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
@ -18,7 +18,18 @@
|
|||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
import ConfigParser
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from builtins import *
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
|
||||||
|
from builtins import str
|
||||||
|
from builtins import object
|
||||||
|
|
||||||
|
import configparser
|
||||||
import ast
|
import ast
|
||||||
import copy
|
import copy
|
||||||
import glob
|
import glob
|
||||||
@ -65,17 +76,17 @@ def parse_config(basedir, cfg_patterns, interpolate=True):
|
|||||||
used_files = []
|
used_files = []
|
||||||
|
|
||||||
for g in cfg_patterns:
|
for g in cfg_patterns:
|
||||||
for f in (glob.glob(os.path.join(basedir, g)) if isinstance(g, basestring) else [g]):
|
for f in (glob.glob(os.path.join(basedir, g)) if isinstance(g, str) else [g]):
|
||||||
fd = open(f) if isinstance(f, basestring) else f
|
fd = open(f) if isinstance(f, str) else f
|
||||||
filename = getattr(fd, 'filename', str(fd))
|
filename = getattr(fd, 'filename', str(fd))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fd.seek(0) # handle case when source config is fd
|
fd.seek(0) # handle case when source config is fd
|
||||||
config = ConfigParser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config.readfp(fd, filename=filename)
|
config.readfp(fd, filename=filename)
|
||||||
except Exception, v:
|
except Exception as v:
|
||||||
raise ConfigError(v)
|
raise ConfigError(v)
|
||||||
|
|
||||||
used_files.append(filename)
|
used_files.append(filename)
|
||||||
@ -87,7 +98,7 @@ def parse_config(basedir, cfg_patterns, interpolate=True):
|
|||||||
for item, value in config.items(section):
|
for item, value in config.items(section):
|
||||||
try:
|
try:
|
||||||
value = ast.literal_eval(value)
|
value = ast.literal_eval(value)
|
||||||
if interpolate and isinstance(value, basestring):
|
if interpolate and isinstance(value, str):
|
||||||
# Interpolate string using current settings
|
# Interpolate string using current settings
|
||||||
value = value % settings
|
value = value % settings
|
||||||
except:
|
except:
|
||||||
@ -100,7 +111,7 @@ def parse_config(basedir, cfg_patterns, interpolate=True):
|
|||||||
s_name=str(section)
|
s_name=str(section)
|
||||||
setattr(settings, s_name, _s)
|
setattr(settings, s_name, _s)
|
||||||
finally:
|
finally:
|
||||||
if isinstance(f, basestring):
|
if isinstance(f, str):
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
return settings, used_files
|
return settings, used_files
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
from builtins import *
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import struct
|
import struct
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (C) 2018 Vasily Evseenko <svpcom@p2ptech.org>
|
# Copyright (C) 2018, 2019 Vasily Evseenko <svpcom@p2ptech.org>
|
||||||
|
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
@ -18,7 +18,17 @@
|
|||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
import mavlink
|
from __future__ import absolute_import
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
|
||||||
|
from builtins import *
|
||||||
|
|
||||||
|
from . import mavlink
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.internet import reactor, defer
|
from twisted.internet import reactor, defer
|
||||||
from twisted.internet.protocol import DatagramProtocol
|
from twisted.internet.protocol import DatagramProtocol
|
||||||
@ -52,7 +62,7 @@ class UDPProxyProtocol(DatagramProtocol):
|
|||||||
if not self.agg_queue_timer.called:
|
if not self.agg_queue_timer.called:
|
||||||
self.agg_queue_timer.cancel()
|
self.agg_queue_timer.cancel()
|
||||||
self.agg_queue_timer = None
|
self.agg_queue_timer = None
|
||||||
self._send_to_peer(''.join(self.agg_queue))
|
self._send_to_peer(b''.join(self.agg_queue))
|
||||||
self.agg_queue = []
|
self.agg_queue = []
|
||||||
self.agg_queue_size = 0
|
self.agg_queue_size = 0
|
||||||
|
|
||||||
@ -85,7 +95,7 @@ class UDPProxyProtocol(DatagramProtocol):
|
|||||||
self.agg_queue_timer.cancel()
|
self.agg_queue_timer.cancel()
|
||||||
self.agg_queue_timer = None
|
self.agg_queue_timer = None
|
||||||
|
|
||||||
self._send_to_peer(''.join(self.agg_queue))
|
self._send_to_peer(b''.join(self.agg_queue))
|
||||||
self.agg_queue = []
|
self.agg_queue = []
|
||||||
self.agg_queue_size = 0
|
self.agg_queue_size = 0
|
||||||
|
|
||||||
|
@ -18,6 +18,16 @@
|
|||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
|
||||||
|
from builtins import *
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
@ -45,7 +55,8 @@ class ExecError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
def call_and_check_rc(cmd, *args):
|
def call_and_check_rc(cmd, *args):
|
||||||
def _check_rc((stdout, stderr, rc)):
|
def _check_rc(_args):
|
||||||
|
(stdout, stderr, rc) = _args
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
err = ExecError('RC %d: %s %s' % (rc, cmd, ' '.join(args)))
|
err = ExecError('RC %d: %s %s' % (rc, cmd, ' '.join(args)))
|
||||||
err.stdout = stdout.strip()
|
err.stdout = stdout.strip()
|
||||||
@ -87,7 +98,7 @@ class StatisticsProtocol(Protocol):
|
|||||||
self.factory.sessions.remove(self)
|
self.factory.sessions.remove(self)
|
||||||
|
|
||||||
def send_stats(self, data):
|
def send_stats(self, data):
|
||||||
self.transport.write(json.dumps(data) + '\n')
|
self.transport.write(json.dumps(data).encode('utf-8') + b'\n')
|
||||||
|
|
||||||
|
|
||||||
class AntennaFactory(Factory):
|
class AntennaFactory(Factory):
|
||||||
@ -110,13 +121,13 @@ class AntennaFactory(Factory):
|
|||||||
def select_tx_antenna(self, ant_rssi):
|
def select_tx_antenna(self, ant_rssi):
|
||||||
wlan_rssi = {}
|
wlan_rssi = {}
|
||||||
for k, grp in groupby(sorted(((int(ant_id, 16) >> 8) & 0xff, rssi_avg) \
|
for k, grp in groupby(sorted(((int(ant_id, 16) >> 8) & 0xff, rssi_avg) \
|
||||||
for ant_id, (pkt_s, rssi_min, rssi_avg, rssi_max) in ant_rssi.iteritems()),
|
for ant_id, (pkt_s, rssi_min, rssi_avg, rssi_max) in ant_rssi.items()),
|
||||||
lambda x: x[0]):
|
lambda x: x[0]):
|
||||||
# Select max average rssi from all wlan's antennas
|
# Select max average rssi from all wlan's antennas
|
||||||
wlan_rssi[k] = max(rssi for _, rssi in grp)
|
wlan_rssi[k] = max(rssi for _, rssi in grp)
|
||||||
|
|
||||||
tx_max = 0
|
tx_max = 0
|
||||||
for k, v in wlan_rssi.iteritems():
|
for k, v in wlan_rssi.items():
|
||||||
if k != tx_max and v > wlan_rssi[tx_max]:
|
if k != tx_max and v > wlan_rssi[tx_max]:
|
||||||
tx_max = k
|
tx_max = k
|
||||||
|
|
||||||
@ -132,7 +143,7 @@ class AntennaFactory(Factory):
|
|||||||
mav_rssi = []
|
mav_rssi = []
|
||||||
flags = 0
|
flags = 0
|
||||||
|
|
||||||
for i, (k, v) in enumerate(sorted(ant_rssi.iteritems())):
|
for i, (k, v) in enumerate(sorted(ant_rssi.items())):
|
||||||
pkt_s, rssi_min, rssi_avg, rssi_max = v
|
pkt_s, rssi_min, rssi_avg, rssi_max = v
|
||||||
mav_rssi.append(rssi_avg)
|
mav_rssi.append(rssi_avg)
|
||||||
|
|
||||||
@ -158,7 +169,7 @@ class AntennaFactory(Factory):
|
|||||||
|
|
||||||
|
|
||||||
class AntennaProtocol(LineReceiver):
|
class AntennaProtocol(LineReceiver):
|
||||||
delimiter = '\n'
|
delimiter = b'\n'
|
||||||
|
|
||||||
def __init__(self, antenna_f, rx_id):
|
def __init__(self, antenna_f, rx_id):
|
||||||
self.antenna_f = antenna_f
|
self.antenna_f = antenna_f
|
||||||
@ -167,7 +178,7 @@ class AntennaProtocol(LineReceiver):
|
|||||||
self.count_all = None
|
self.count_all = None
|
||||||
|
|
||||||
def lineReceived(self, line):
|
def lineReceived(self, line):
|
||||||
cols = line.strip().split('\t')
|
cols = line.decode('utf-8').strip().split('\t')
|
||||||
try:
|
try:
|
||||||
if len(cols) < 2:
|
if len(cols) < 2:
|
||||||
raise BadTelemetry()
|
raise BadTelemetry()
|
||||||
@ -183,7 +194,7 @@ class AntennaProtocol(LineReceiver):
|
|||||||
if len(cols) != 3:
|
if len(cols) != 3:
|
||||||
raise BadTelemetry()
|
raise BadTelemetry()
|
||||||
|
|
||||||
p_all, p_dec_err, p_dec_ok, p_fec_rec, p_lost, p_bad = map(int, cols[2].split(':'))
|
p_all, p_dec_err, p_dec_ok, p_fec_rec, p_lost, p_bad = list(int(i) for i in cols[2].split(':'))
|
||||||
|
|
||||||
if not self.count_all:
|
if not self.count_all:
|
||||||
self.count_all = (p_all, p_dec_ok, p_fec_rec, p_lost, p_dec_err, p_bad)
|
self.count_all = (p_all, p_dec_ok, p_fec_rec, p_lost, p_dec_err, p_bad)
|
||||||
@ -203,13 +214,13 @@ class AntennaProtocol(LineReceiver):
|
|||||||
|
|
||||||
|
|
||||||
class DbgProtocol(LineReceiver):
|
class DbgProtocol(LineReceiver):
|
||||||
delimiter = '\n'
|
delimiter = b'\n'
|
||||||
|
|
||||||
def __init__(self, rx_id):
|
def __init__(self, rx_id):
|
||||||
self.rx_id = rx_id
|
self.rx_id = rx_id
|
||||||
|
|
||||||
def lineReceived(self, line):
|
def lineReceived(self, line):
|
||||||
log.msg('%s: %s' % (self.rx_id, line))
|
log.msg('%s: %s' % (self.rx_id, line.decode('utf-8')))
|
||||||
|
|
||||||
|
|
||||||
class RXProtocol(ProcessProtocol):
|
class RXProtocol(ProcessProtocol):
|
||||||
|
@ -1,6 +1,17 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
|
||||||
|
from builtins import *
|
||||||
|
from builtins import range
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
@ -50,7 +61,7 @@ class UDPProxyTestCase(unittest.TestCase):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_proxy(self):
|
def test_proxy(self):
|
||||||
addr = ('127.0.0.1', 14551)
|
addr = ('127.0.0.1', 14551)
|
||||||
p = SendPacket('test', addr, 10)
|
p = SendPacket(b'test', addr, 10)
|
||||||
ep3 = reactor.listenUDP(9999, p)
|
ep3 = reactor.listenUDP(9999, p)
|
||||||
ep4 = reactor.listenUDP(14553, Echo())
|
ep4 = reactor.listenUDP(14553, Echo())
|
||||||
try:
|
try:
|
||||||
@ -58,7 +69,7 @@ class UDPProxyTestCase(unittest.TestCase):
|
|||||||
_data, _addr = yield p.df
|
_data, _addr = yield p.df
|
||||||
self.assertGreater(time.time() - ts, 1.0)
|
self.assertGreater(time.time() - ts, 1.0)
|
||||||
self.assertEqual(_addr, addr)
|
self.assertEqual(_addr, addr)
|
||||||
self.assertEqual(_data, 'test' * 10)
|
self.assertEqual(_data, b'test' * 10)
|
||||||
finally:
|
finally:
|
||||||
ep4.stopListening()
|
ep4.stopListening()
|
||||||
ep3.stopListening()
|
ep3.stopListening()
|
||||||
@ -66,7 +77,7 @@ class UDPProxyTestCase(unittest.TestCase):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_rssi_injection(self):
|
def test_rssi_injection(self):
|
||||||
addr = ('127.0.0.1', 14551)
|
addr = ('127.0.0.1', 14551)
|
||||||
p = SendPacket('test', addr)
|
p = SendPacket(b'test', addr)
|
||||||
|
|
||||||
ep3 = reactor.listenUDP(9999, p)
|
ep3 = reactor.listenUDP(9999, p)
|
||||||
yield df_sleep(0.1)
|
yield df_sleep(0.1)
|
||||||
@ -77,6 +88,6 @@ class UDPProxyTestCase(unittest.TestCase):
|
|||||||
_data, _addr = yield p.df
|
_data, _addr = yield p.df
|
||||||
self.assertLess(time.time() - ts, 1.0)
|
self.assertLess(time.time() - ts, 1.0)
|
||||||
self.assertEqual(_addr, addr)
|
self.assertEqual(_addr, addr)
|
||||||
self.assertEqual(_data, '\xfd\t\x00\x00\x00\x03\xf2m\x00\x00\x02\x00\x03\x00\x01\x01d\x00\x04\xa8\xad')
|
self.assertEqual(_data, b'\xfd\t\x00\x00\x00\x03\xf2m\x00\x00\x02\x00\x03\x00\x01\x01d\x00\x04\xa8\xad')
|
||||||
finally:
|
finally:
|
||||||
ep3.stopListening()
|
ep3.stopListening()
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
from builtins import *
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from twisted.python import log
|
from twisted.python import log
|
||||||
from twisted.trial import unittest
|
from twisted.trial import unittest
|
||||||
@ -26,5 +35,5 @@ class TUNTAPTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def test_tuntap(self):
|
def test_tuntap(self):
|
||||||
# Test manually via "ping -I tuntest1 192.168.77.2" and "tcpdump -i tuntest2 -nn -p icmp"
|
# Test manually via "ping -I tuntest1 192.168.77.2" and "tcpdump -i tuntest2 -nn -p icmp"
|
||||||
return df_sleep(0)
|
return df_sleep(1)
|
||||||
|
|
||||||
|
@ -1,8 +1,35 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright (C) 2018, 2019 Vasily Evseenko <svpcom@p2ptech.org>
|
||||||
|
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; version 3.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along
|
||||||
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import division
|
||||||
|
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
|
||||||
|
from builtins import *
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import mavlink
|
from . import mavlink
|
||||||
import fcntl
|
import fcntl
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
@ -20,7 +47,7 @@ class TUNTAPTransport(abstract.FileDescriptor):
|
|||||||
TUNSETIFF = 0x400454ca
|
TUNSETIFF = 0x400454ca
|
||||||
IFF_NO_PI = 0x1000
|
IFF_NO_PI = 0x1000
|
||||||
|
|
||||||
def __init__(self, reactor, protocol, name, addr, dev='/dev/net/tun', mtu=1400, mode=TUN):
|
def __init__(self, reactor, protocol, name, addr, dev=b'/dev/net/tun', mtu=1400, mode=TUN):
|
||||||
abstract.FileDescriptor.__init__(self, reactor)
|
abstract.FileDescriptor.__init__(self, reactor)
|
||||||
self.queue = deque()
|
self.queue = deque()
|
||||||
self.mtu = mtu
|
self.mtu = mtu
|
||||||
@ -30,7 +57,7 @@ class TUNTAPTransport(abstract.FileDescriptor):
|
|||||||
try:
|
try:
|
||||||
# We don't need packet info
|
# We don't need packet info
|
||||||
mode |= self.IFF_NO_PI
|
mode |= self.IFF_NO_PI
|
||||||
fcntl.ioctl(self.fd, self.TUNSETIFF, struct.pack('16sH', name, mode))
|
fcntl.ioctl(self.fd, self.TUNSETIFF, struct.pack('16sH', bytes(name, 'ascii'), mode))
|
||||||
with closing(IPRoute()) as ip:
|
with closing(IPRoute()) as ip:
|
||||||
ifidx = ip.link_lookup(ifname=name)[0]
|
ifidx = ip.link_lookup(ifname=name)[0]
|
||||||
_addr, _mask = addr.split('/')
|
_addr, _mask = addr.split('/')
|
||||||
@ -96,8 +123,8 @@ class TUNTAPTransport(abstract.FileDescriptor):
|
|||||||
return len(self.queue) > 1000
|
return len(self.queue) > 1000
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
if isinstance(data, unicode): # no, really, I mean it
|
if not isinstance(data, (bytes, type(None))): # no, really, I mean it
|
||||||
raise TypeError("Data must not be unicode")
|
raise TypeError("Only binary strings are supported")
|
||||||
|
|
||||||
if not self.connected or self._writeDisconnected:
|
if not self.connected or self._writeDisconnected:
|
||||||
return
|
return
|
||||||
@ -129,7 +156,7 @@ class TUNTAPProtocol(Protocol):
|
|||||||
|
|
||||||
def send_keepalive(self):
|
def send_keepalive(self):
|
||||||
if self.peer is not None:
|
if self.peer is not None:
|
||||||
self.peer.write('')
|
self.peer.write(b'')
|
||||||
|
|
||||||
def dataReceived(self, data):
|
def dataReceived(self, data):
|
||||||
self.lc.reset()
|
self.lc.reset()
|
||||||
|
Loading…
Reference in New Issue
Block a user