Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom port specification for replay #761

Merged
merged 4 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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: 10 additions & 0 deletions ipwb/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def check_args_replay(args):
print(f'Proxying to {args.proxy}')
proxy = args.proxy

if hasattr(args, 'port') and args.port is not None:
machawk1 marked this conversation as resolved.
Show resolved Hide resolved
print(f'Using custom port {args.port} for replay.')
util.set_ipwb_replay_config_portonly(args.port)

# TODO: add any other sub-arguments for replay here
if supplied_index_parameter:
replay.start(cdxj_file_path=args.index, proxy=proxy)
Expand Down Expand Up @@ -133,6 +137,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
5 changes: 3 additions & 2 deletions ipwb/replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ def start(cdxj_file_path, proxy=None):

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

# This will throw an exception if daemon is not available.
ipwb_utils.check_daemon_is_alive()
Expand All @@ -1062,9 +1063,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
6 changes: 6 additions & 0 deletions ipwb/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ def get_ipwb_replay_config(ipfs_json=None):
return None


def set_ipwb_replay_config_portonly(port):
ipfs_json = read_ipfs_config()
ipfs_json['Ipwb']['Replay']['Port'] = port
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that ipfs_json['Ipwb']['Replay'] will be populated already even on the first run when there is no config file in place? If not, then this might throw an exception.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! It does throw an exception in this instance. I will update the PR.

write_ipfs_config(ipfs_json)


def set_ipwb_replay_config(Host, Port, ipfs_json=None):
if not ipfs_json:
ipfs_json = read_ipfs_config()
Expand Down