Skip to content

Commit

Permalink
Merge pull request #761 from oduwsdl/issue-760
Browse files Browse the repository at this point in the history
Allow custom port specification for replay
  • Loading branch information
machawk1 authored Apr 6, 2022
2 parents 3f392c5 + 3435e5b commit c2c62d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 12 additions & 1 deletion ipwb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ def check_args_replay(args):
print(f'Proxying to {args.proxy}')
proxy = args.proxy

port = replay.IPWBREPLAY_PORT
if hasattr(args, 'port') and args.port is not None:
print(f'Using custom port {args.port} for replay.')
port = args.port

# TODO: add any other sub-arguments for replay here
if supplied_index_parameter:
replay.start(cdxj_file_path=args.index, proxy=proxy)
replay.start(cdxj_file_path=args.index, proxy=proxy, port=port)
else:
print('ERROR: An index file must be specified if not piping, e.g.,')
print(("> ipwb replay "
Expand Down Expand Up @@ -133,6 +138,12 @@ def check_args(args_in):
help='Proxy URL',
metavar='<host:port>',
nargs='?')
replay_parser.add_argument(
'-p', '--port',
help='Custom Port',
type=int,
default=util.IPWBREPLAY_PORT
)
replay_parser.set_defaults(func=check_args_replay,
onError=replay_parser.print_help)

Expand Down
11 changes: 7 additions & 4 deletions ipwb/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,12 +1047,15 @@ def get_cdxj_line_binary_search(
return line_found


def start(cdxj_file_path, proxy=None):
def start(cdxj_file_path, proxy=None, port=IPWBREPLAY_PORT):
host_port = ipwb_utils.get_ipwb_replay_config()
app.proxy = proxy

# Retain port for subsequent runs
ipwb_utils.set_ipwb_replay_config(IPWBREPLAY_HOST, port)

if not host_port:
ipwb_utils.set_ipwb_replay_config(IPWBREPLAY_HOST, IPWBREPLAY_PORT)
host_port = (IPWBREPLAY_HOST, port)

# This will throw an exception if daemon is not available.
ipwb_utils.check_daemon_is_alive()
Expand All @@ -1062,9 +1065,9 @@ def start(cdxj_file_path, proxy=None):

try:
print((f'IPWB replay started on '
f'http://{IPWBREPLAY_HOST}:{IPWBREPLAY_PORT}'))
f'http://{host_port[0]}:{host_port[1]}'))

app.run(host='0.0.0.0', port=IPWBREPLAY_PORT)
app.run(host='0.0.0.0', port=host_port[1])
except gaierror:
print('Detected no active Internet connection.')
print('Overriding to use default IP and port configuration.')
Expand Down

0 comments on commit c2c62d1

Please sign in to comment.