Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/16_docker_network_python/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"container_name" : "client",
// It can be important to ensure your container's start in the correct order.
// In this example, we want the server to start before the client, so we add a sleep command.
"commands" : ["sleep 1", "python3 client.py client 0"],
"commands" : ["sleep 2", "python3 client.py client 0"],
"outgoing_connections" : ["server"]
},
{
Expand Down Expand Up @@ -74,7 +74,7 @@
},
{
"container_name" : "client",
"commands" : ["sleep 1", "python3 client.py client 1"],
"commands" : ["sleep 2", "python3 client.py client 1"],
"outgoing_connections" : ["server"]
},
{
Expand Down Expand Up @@ -112,7 +112,7 @@
},
{
"container_name" : "client",
"commands" : ["sleep 1", "python3 client.py client 2"],
"commands" : ["sleep 2", "python3 client.py client 2"],
"outgoing_connections" : ["server"]
},
{
Expand Down Expand Up @@ -150,7 +150,7 @@
},
{
"container_name" : "client",
"commands" : ["sleep 1", "python3 client.py client 3"],
"commands" : ["sleep 2", "python3 client.py client 3"],
"outgoing_connections" : ["server"]
},
{
Expand Down Expand Up @@ -189,7 +189,7 @@
},
{
"container_name" : "client",
"commands" : ["sleep 1", "python3 client.py client 4 udp_enabled"],
"commands" : ["sleep 2", "python3 client.py client 4 udp_enabled"],
"outgoing_connections" : ["server"]
},
{
Expand Down
44 changes: 25 additions & 19 deletions examples/16_docker_network_python/config/test_input/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import traceback

MY_NAME = ""
KNOWN_HOSTS_TCP = 'knownhosts_tcp.csv'
KNOWN_HOSTS_UDP = 'knownhosts_udp.csv'
KNOWN_HOSTS_TCP = 'knownhosts_tcp.txt'
KNOWN_HOSTS_UDP = 'knownhosts_udp.txt'
USE_UDP = False


Expand Down Expand Up @@ -42,29 +42,35 @@ def read_known_hosts_csv():
global server_name
global incoming_tcp_port, outgoing_tcp_port
global incoming_udp_port, outgoing_udp_port
with open(KNOWN_HOSTS_TCP) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for sender, recv, port in csv_reader:

with open(KNOWN_HOSTS_TCP) as infile:
content = infile.readlines()

for line in content:
sender, recv, port = line.split()
if sender == MY_NAME:
outgoing_tcp_port =port
server_name = recv
elif recv == MY_NAME:
incoming_tcp_port = port
server_name = sender
else:
continue

if USE_UDP:
with open(KNOWN_HOSTS_UDP) as infile:
content = infile.readlines()

for line in content:
sender, recv, port = line.split()
if sender == MY_NAME:
outgoing_tcp_port =port
outgoing_udp_port =port
server_name = recv
elif recv == MY_NAME:
incoming_tcp_port = port
incoming_udp_port = port
server_name = sender
else:
continue
if USE_UDP:
with open(KNOWN_HOSTS_UDP) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for sender, recv, port in csv_reader:
if sender == MY_NAME:
outgoing_udp_port =port
server_name = recv
elif recv == MY_NAME:
incoming_udp_port = port
server_name = sender
else:
continue

def initialize_incoming_connections():
global incoming_tcp_socket, incoming_udp_socket
Expand Down
40 changes: 21 additions & 19 deletions examples/16_docker_network_python/config/test_input/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,28 @@ def build_switchboard():
try:
#Read the known_hosts.csv see the top of the file for the specification
for connection_type in ["tcp", "udp"]:
filename = 'knownhosts_{0}.csv'.format(connection_type)
filename = 'knownhosts_{0}.txt'.format(connection_type)
with open(filename, 'r') as infile:
reader = csv.reader(infile)
for sender, recipient, port in reader:
#Strip away trailing or leading whitespace
sender = '{0}_Actual'.format(sender.strip())
recipient = '{0}_Actual'.format(recipient.strip())
port = port.strip()

if not port in PORTS:
PORTS.append(port)
else:
raise SystemExit("ERROR: port {0} was encountered twice. Please keep all ports independant.".format(port))

SWITCHBOARD[port] = {}
SWITCHBOARD[port]['connection_type'] = connection_type
SWITCHBOARD[port]['sender'] = sender
SWITCHBOARD[port]['recipient'] = recipient
SWITCHBOARD[port]['connected'] = False
SWITCHBOARD[port]['connection'] = None
content = infile.readlines()

for line in content:
sender, recipient, port = line.split()
#Strip away trailing or leading whitespace
sender = '{0}_Actual'.format(sender.strip())
recipient = '{0}_Actual'.format(recipient.strip())
port = port.strip()

if not port in PORTS:
PORTS.append(port)
else:
raise SystemExit("ERROR: port {0} was encountered twice. Please keep all ports independant.".format(port))

SWITCHBOARD[port] = {}
SWITCHBOARD[port]['connection_type'] = connection_type
SWITCHBOARD[port]['sender'] = sender
SWITCHBOARD[port]['recipient'] = recipient
SWITCHBOARD[port]['connected'] = False
SWITCHBOARD[port]['connection'] = None


except IOError as e:
Expand Down
31 changes: 16 additions & 15 deletions examples/16_docker_network_python/submissions/correct/server.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env python3
import socket
import os
import csv
import sys
import time
import traceback

MY_NAME = ""
KNOWN_HOSTS_CSV = 'knownhosts_tcp.csv'
KNOWN_HOSTS_TCP = 'knownhosts_tcp.txt'

# This tutorial is kept simple intentionally rather than using data structures or
# dictionaries to store these values.
Expand All @@ -19,28 +18,30 @@
open_connection = None

def init():
read_known_hosts_csv()
read_known_hosts_tcp()
initialize_incoming_connections()


#knownhosts_tcp.csv and knownhosts_udp.csv are of the form
#sender,recipient,port_number
# such that sender sends all communications to recipient via port_number.
def read_known_hosts_csv():
def read_known_hosts_tcp():
global client_name
global incoming_port
global outgoing_port
with open(KNOWN_HOSTS_CSV) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for sender, recv, port in csv_reader:
if sender == MY_NAME:
outgoing_port =port
client_name = recv
elif recv == MY_NAME:
incoming_port = port
client_name = sender
else:
continue
with open(KNOWN_HOSTS_TCP) as infile:
content = infile.readlines()

for line in content:
sender, recv, port = line.split()
if sender == MY_NAME:
outgoing_port =port
client_name = recv
elif recv == MY_NAME:
incoming_port = port
client_name = sender
else:
continue

def initialize_incoming_connections():
global incoming_socket
Expand Down
31 changes: 16 additions & 15 deletions examples/16_docker_network_python/submissions/incorrect/server.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env python3
import socket
import os
import csv
import sys
import time
import traceback

MY_NAME = ""
KNOWN_HOSTS_CSV = 'knownhosts_tcp.csv'
KNOWN_HOSTS_TCP = 'knownhosts_tcp.txt'

# This tutorial is kept simple intentionally rather than using data structures or
# dictionaries to store these values.
Expand All @@ -19,28 +18,30 @@
open_connection = None

def init():
read_known_hosts_csv()
read_known_hosts_tcp()
initialize_incoming_connections()


#knownhosts_tcp.csv and knownhosts_udp.csv are of the form
#sender,recipient,port_number
# such that sender sends all communications to recipient via port_number.
def read_known_hosts_csv():
def read_known_hosts_tcp():
global client_name
global incoming_port
global outgoing_port
with open(KNOWN_HOSTS_CSV) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for sender, recv, port in csv_reader:
if sender == MY_NAME:
outgoing_port =port
client_name = recv
elif recv == MY_NAME:
incoming_port = port
client_name = sender
else:
continue
with open(KNOWN_HOSTS_TCP) as infile:
content = infile.readlines()

for line in content:
sender, recv, port = line.split()
if sender == MY_NAME:
outgoing_port =port
client_name = recv
elif recv == MY_NAME:
incoming_port = port
client_name = sender
else:
continue

def initialize_incoming_connections():
global incoming_socket
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env python3
import socket
import os
import csv
import sys
import time
import traceback

MY_NAME = ""
KNOWN_HOSTS_CSV = 'knownhosts_tcp.csv'
KNOWN_HOSTS_TCP = 'knownhosts_tcp.txt'

# This tutorial is kept simple intentionally rather than using data structures or
# dictionaries to store these values.
Expand All @@ -19,27 +18,30 @@
open_connection = None

def init():
read_known_hosts_csv()
read_known_hosts_tcp()
initialize_incoming_connections()


#knownhosts_tcp.csv and knownhosts_udp.csv are of the form
#sender,recipient,port_number
# such that sender sends all communications to recipient via port_number.
def read_known_hosts_csv():
def read_known_hosts_tcp():
global client_name
global incoming_port
global outgoing_port
with open(KNOWN_HOSTS_CSV) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for sender, recv, port in csv_reader:
if sender == MY_NAME:
outgoing_port =port
client_name = recv
elif recv == MY_NAME:
incoming_port = port
client_name = sender
else:
continue
with open(KNOWN_HOSTS_TCP) as infile:
content = infile.readlines()

for line in content:
sender, recv, port = line.split()
if sender == MY_NAME:
outgoing_port =port
client_name = recv
elif recv == MY_NAME:
incoming_port = port
client_name = sender
else:
continue

def initialize_incoming_connections():
global incoming_socket
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/usr/bin/env python3
import socket
import os
import csv
import sys
import time
import traceback

MY_NAME = ""
KNOWN_HOSTS_CSV = 'knownhosts_tcp.csv'
KNOWN_HOSTS_TCP = 'knownhosts_tcp.txt'

# This tutorial is kept simple intentionally rather than using data structures or
# dictionaries to store these values.
Expand All @@ -19,28 +18,30 @@
open_connection = None

def init():
read_known_hosts_csv()
read_known_hosts_tcp()
initialize_incoming_connections()


#knownhosts_tcp.csv and knownhosts_udp.csv are of the form
#sender,recipient,port_number
# such that sender sends all communications to recipient via port_number.
def read_known_hosts_csv():
def read_known_hosts_tcp():
global client_name
global incoming_port
global outgoing_port
with open(KNOWN_HOSTS_CSV) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for sender, recv, port in csv_reader:
if sender == MY_NAME:
outgoing_port =port
client_name = recv
elif recv == MY_NAME:
incoming_port = port
client_name = sender
else:
continue
with open(KNOWN_HOSTS_TCP) as infile:
content = infile.readlines()

for line in content:
sender, recv, port = line.split()
if sender == MY_NAME:
outgoing_port =port
client_name = recv
elif recv == MY_NAME:
incoming_port = port
client_name = sender
else:
continue

def initialize_incoming_connections():
global incoming_socket
Expand Down
Loading