Browse Source

use argparse and make yam an executable script

master
Kevin Froman 12 months ago
parent
commit
594df495c3
7 changed files with 96 additions and 31 deletions
  1. +4
    -0
      CHANGELOG.md
  2. +4
    -1
      setup.py
  3. +0
    -0
      src/yam/__init__.py
  4. +46
    -14
      src/yam/yam.py
  5. +6
    -3
      src/youandme/tor.py
  6. +13
    -2
      tests/test_client.py
  7. +23
    -11
      tests/test_server.py

+ 4
- 0
CHANGELOG.md View File

@ -2,6 +2,10 @@
This project uses Semantic Versioning
## 1.0.0
Made yam a proper script (install and you can run from path with $ yam.py <args>)
## 0.0.0
Initial release

+ 4
- 1
setup.py View File

@ -4,13 +4,16 @@ this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
packages = find_packages(exclude=['contrib', 'docs', 'tests'])
setup(name='youandme',
version='0.0.2',
version='1.0.0',
description='Simple private data sharing via bytearrays, Tor tunneling and metadata paranoia',
long_description=long_description,
long_description_content_type='text/markdown',
author='Kevin Froman',
packages=packages,
scripts=['src/yam/yam.py'],
author_email='beardog@mailbox.org',
url='https://chaoswebs.net',
install_requires=[


+ 0
- 0
src/yam/__init__.py View File


src/yam.py → src/yam/yam.py View File


+ 6
- 3
src/youandme/tor.py View File

@ -1,14 +1,17 @@
import stem.process
def launch_tor(control_port="1336", socks_port="1337"):
def launch_tor(control_port="1336", socks_port="1337", data_dir=""):
control_port = str(control_port)
socks_port = str(socks_port)
stem.process.launch_tor_with_config(
config = {
'ControlPort': control_port,
'SocksPort': socks_port,
'Log': [
'NOTICE stdout'
],
}, take_ownership=True)
}
if data_dir:
config['DataDirectory'] = data_dir
stem.process.launch_tor_with_config(
config = config, take_ownership=True)

+ 13
- 2
tests/test_client.py View File

@ -7,8 +7,19 @@ import stem.process
from stem.control import Controller
from youandme import client
control_port = str(1353)
socks_port = str(1354)
def get_open_port():
# taken from (but modified) https://stackoverflow.com/a/2838309 by https://stackoverflow.com/users/133374/albert ccy-by-sa-3 https://creativecommons.org/licenses/by-sa/3.0/
# changes from source: import moved to top of file, bind specifically to localhost
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("127.0.0.1",0))
s.listen(1)
port = s.getsockname()[1]
s.close()
return port
control_port = str(get_open_port())
socks_port = str(get_open_port())
assert control_port != socks_port
stem.process.launch_tor_with_config(
config = {


+ 23
- 11
tests/test_server.py View File

@ -1,23 +1,35 @@
import unittest
import socket
from threading import Thread
import tempfile
import time
import stem
import stem.process
from stem.control import Controller
from youandme import server
control_port = str(1353)
socks_port = str(1354)
def get_open_port():
# taken from (but modified) https://stackoverflow.com/a/2838309 by https://stackoverflow.com/users/133374/albert ccy-by-sa-3 https://creativecommons.org/licenses/by-sa/3.0/
# changes from source: import moved to top of file, bind specifically to localhost
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("127.0.0.1",0))
s.listen(1)
port = s.getsockname()[1]
s.close()
return port
control_port = str(get_open_port())
socks_port = str(get_open_port())
assert control_port != socks_port
with tempfile.TemporaryDirectory() as tmpdirname:
stem.process.launch_tor_with_config(
config = {
'ControlPort': control_port,
'SocksPort': socks_port,
'DataDirectory': tmpdirname
stem.process.launch_tor_with_config(
config = {
'ControlPort': control_port,
'SocksPort': socks_port,
'Log': [
'NOTICE stdout'
],
}, take_ownership=True)
}, take_ownership=True, init_msg_handler=lambda i: print(i))
def send_test_data(ip, port):
time.sleep(2)
@ -52,7 +64,7 @@ class TestServer(unittest.TestCase):
)
Thread(target=send_test_data, args=[ip, port], daemon=True).start()
conn, addr = s.accept()
Thread(target=server, args=[0.1, controller, conn, send_data, recv_data], daemon=True).start()
Thread(target=server.server, args=[0.1, controller, conn, send_data, recv_data], daemon=True).start()
time.sleep(1)
max_iters = 10000000
c = 0


Loading…
Cancel
Save