-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docker compose file for network testing
- Loading branch information
Showing
14 changed files
with
266 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import argparse | ||
import asyncio | ||
import signal | ||
import sys | ||
from asyncio import Protocol, Transport | ||
from typing import Optional | ||
|
||
from tarpn.util import shutdown | ||
|
||
|
||
class TTY(Protocol): | ||
def __init__(self): | ||
self.transport: Optional[Transport] = None | ||
|
||
def connection_made(self, transport: Transport): | ||
self.transport = transport | ||
sys.stderr.write(f"Connected to {transport.get_extra_info('peername')}\r\n") | ||
sys.stderr.flush() | ||
|
||
def connection_lost(self, exc): | ||
sys.stderr.write(f"Lost connection to {self.transport.get_extra_info('peername')}\r\n") | ||
sys.stderr.flush() | ||
self.transport = None | ||
signal.raise_signal(signal.SIGTERM) | ||
|
||
def data_received(self, data: bytes) -> None: | ||
msg = data.decode("utf-8") | ||
for line in msg.splitlines(): | ||
if line.startswith("Welcome to the TARPN shell") or line.startswith("(tarpn)"): | ||
return | ||
else: | ||
sys.stdout.write(line.strip()) | ||
sys.stdout.flush() | ||
|
||
def handle_stdin(self): | ||
line = sys.stdin.readline() | ||
if self.transport is not None: | ||
if line == "": # Got a ^D | ||
self.transport.close() | ||
signal.raise_signal(signal.SIGTERM) | ||
else: | ||
line = line.strip() | ||
self.transport.write(line + "\r\n") | ||
else: | ||
sys.stdout.write("Not connected\r\n") | ||
sys.stdout.flush() | ||
|
||
def handle_signal(self, loop, scheduler): | ||
if self.transport is not None: | ||
self.transport.close() | ||
asyncio.create_task(shutdown(loop)) | ||
scheduler.shutdown() | ||
|
||
|
||
async def async_main(): | ||
parser = argparse.ArgumentParser(description='Open a shell to a running tarpn-core') | ||
parser.add_argument("sock", help="Path to unix socket") | ||
parser.add_argument("cmd", help="Command to send") | ||
args = parser.parse_args() | ||
|
||
tty = TTY() | ||
loop = asyncio.get_event_loop() | ||
loop.add_reader(sys.stdin, tty.handle_stdin) | ||
(transport, protocol) = await loop.create_unix_connection(lambda: tty, path=args.sock) | ||
transport.write(args.cmd.encode("utf-8")) | ||
await asyncio.sleep(1) | ||
|
||
|
||
def main(): | ||
asyncio.run(async_main()) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,9 @@ do | |
IFS="|" | ||
done | ||
|
||
if [[ -v SLEEP ]]; | ||
then | ||
sleep $SLEEP | ||
fi | ||
|
||
/opt/tarpn/bin/tarpn-node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[default] | ||
mycall=AL1CE | ||
|
||
[node] | ||
log.dir = /tmp/tarpn-logs-alice | ||
log.config = config/logging.ini | ||
|
||
node.call = ${mycall}-9 | ||
node.alias = ALICE | ||
node.sock = /tmp/socks/tarpn-shell-alice.sock | ||
|
||
|
||
[port:1] | ||
port.enabled = True | ||
port.type = serial | ||
port.framing = kiss | ||
port.bitrate = 9600 | ||
kiss.checksum = false | ||
serial.device = /tmp/vmodem_A0 | ||
serial.speed = 9600 | ||
|
||
[port:2] | ||
port.enabled = True | ||
port.type = serial | ||
port.framing = kiss | ||
port.bitrate = 9600 | ||
kiss.checksum = false | ||
serial.device = /tmp/vmodem_B1 | ||
serial.speed = 9600 | ||
|
||
[network] | ||
host.name = alice | ||
mesh.enabled = True | ||
mesh.address = 00.ab | ||
mesh.ttl = 7 | ||
|
||
[app:demo] | ||
app.address = mesh://ff.ff:100 | ||
app.call = ${mycall}-7 | ||
app.alias = DEMO | ||
app.sock = /tmp/socks/tarpn-demo-a.sock | ||
app.module = plugins.demo | ||
app.class = DemoApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[default] | ||
mycall=B0B | ||
|
||
[node] | ||
log.dir = /tmp/tarpn-logs-bob | ||
log.config = config/logging.ini | ||
|
||
node.call = ${mycall}-9 | ||
node.alias = BOB | ||
node.sock = /tmp/socks/tarpn-shell-bob.sock | ||
|
||
|
||
[port:1] | ||
port.enabled = True | ||
port.type = serial | ||
port.framing = kiss | ||
port.bitrate = 9600 | ||
kiss.checksum = false | ||
serial.device = /tmp/vmodem_A1 | ||
serial.speed = 9600 | ||
|
||
[network] | ||
host.name = bob | ||
mesh.enabled = True | ||
mesh.address = 00.aa | ||
mesh.ttl = 7 | ||
|
||
|
||
[app:demo] | ||
app.address = mesh://ff.ff:100 | ||
app.call = ${mycall}-7 | ||
app.alias = DEMO | ||
app.sock = /tmp/socks/tarpn-demo-b.sock | ||
app.module = plugins.demo | ||
app.class = DemoApp |
Oops, something went wrong.