adding support for client behind
This commit is contained in:
parent
ba14f2f525
commit
268d26d802
@ -126,15 +126,19 @@ class Node:
|
||||
|
||||
|
||||
class SpeedTestServer(Node):
|
||||
def client(self, server: Interface):
|
||||
pass
|
||||
def get_internet_setup(self) -> Optional[str]:
|
||||
return textwrap.dedent('''
|
||||
cloud-init status --wait || cloud-init status --long
|
||||
sudo apt-get install -y iperf3
|
||||
''')
|
||||
|
||||
# Entry method for running the serve with `with speedtest:`
|
||||
def __enter__(self):
|
||||
pass
|
||||
def server(self):
|
||||
self.ssh('iperf3 -s -1 -D', error_stdout=True, error_stderr=True)
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
pass
|
||||
def client(self, target, time=30):
|
||||
command = 'iperf3 -c {target} -t {time} -O 5 -J'.format(target=target, time=time)
|
||||
out = self.ssh(command, error_stdout=True, error_stderr=True, return_stdout=True)
|
||||
return json.loads(out)
|
||||
|
||||
|
||||
class RemotePortal(Node):
|
||||
@ -167,9 +171,6 @@ class RemotePortal(Node):
|
||||
return textwrap.dedent('''
|
||||
set -e
|
||||
|
||||
sudo sysctl -w net.ipv4.conf.all.arp_announce=1
|
||||
sudo sysctl -w net.ipv4.conf.all.arp_ignore=2
|
||||
|
||||
cat << EOF > config.ini
|
||||
[Host]
|
||||
PrivateKey = INVALID
|
||||
@ -188,6 +189,15 @@ class RemotePortal(Node):
|
||||
sudo ip link set up nc0
|
||||
sudo ip addr add 172.19.152.2/31 dev nc0
|
||||
|
||||
ip rule add from all table local priority 20
|
||||
ip rule del 0
|
||||
|
||||
ip rule add to {local_host} dport 1234 table local priority 9
|
||||
|
||||
ip route flush 10
|
||||
ip route add table 10 to {local_host} via 172.19.152.3 dev nc0
|
||||
ip rule add to {local_host} table 10 priority 10
|
||||
|
||||
ps $(cat mpbl3p.pid)
|
||||
''').format(
|
||||
local_host=self.get_interfaces()[0].get_address(),
|
||||
@ -268,7 +278,7 @@ class LocalPortal(Node):
|
||||
set -e
|
||||
|
||||
sudo sysctl -w net.ipv4.conf.all.arp_announce=1
|
||||
sudo sysctl -w net.ipv4.conf.all.arp_ignore=2
|
||||
sudo sysctl -w net.ipv4.conf.all.arp_ignore=1
|
||||
|
||||
{policy_routing}
|
||||
|
||||
@ -285,8 +295,22 @@ class LocalPortal(Node):
|
||||
sudo ip link set up nc0
|
||||
sudo ip addr add 172.19.152.3/31 dev nc0
|
||||
|
||||
ip route flush 8
|
||||
ip route add table 8 default via 172.19.152.2 dev nc0
|
||||
ip rule add from {remote_host} iif {local_interface} table 8 priority 8
|
||||
|
||||
ip route flush 9
|
||||
ip route add table 9 to {remote_host} dev {local_interface}
|
||||
ip rule add to {remote_host} table 9 priority 9
|
||||
|
||||
ps $(cat mpbl3p.pid)
|
||||
''').format(**self.setup_params, peers=peers, policy_routing=policy_routing)
|
||||
''').format(
|
||||
**self.setup_params,
|
||||
peers=peers,
|
||||
policy_routing=policy_routing,
|
||||
remote_host=self.remote_portal.get_interfaces()[0].get_address(),
|
||||
local_interface='eth{}'.format(len(self.get_interfaces())-2),
|
||||
)
|
||||
|
||||
def speedtest_server(self):
|
||||
self.ssh('iperf3 -s -1 -D', error_stdout=True, error_stderr=True)
|
||||
|
Loading…
Reference in New Issue
Block a user