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

auto-reroute is out of date #20

Open
nolanbconaway opened this issue Nov 20, 2017 · 5 comments
Open

auto-reroute is out of date #20

nolanbconaway opened this issue Nov 20, 2017 · 5 comments

Comments

@nolanbconaway
Copy link

The routes are not up-to-date! So this no longer works. Output looks like this:

You are currently using the default route
Testing single segment download speed from Default...
[32mrouting through Default results in 51.76 Mbit/s[0m

Testing single segment download speed from Cogent...
[32mrouting through Cogent results in 0 Mbit/s[0m

Testing single segment download speed from Console#1...
[32mrouting through Console#1 results in 0 Mbit/s[0m

Testing single segment download speed from Console#2...
[32mrouting through Console#2 results in 0 Mbit/s[0m

Testing single segment download speed from GTT...
[32mrouting through GTT results in 0 Mbit/s[0m

Testing single segment download speed from NTT#1...
[32mrouting through NTT#1 results in 0 Mbit/s[0m

Testing single segment download speed from NTT#2...
[32mrouting through NTT#2 results in 0 Mbit/s[0m

Testing single segment download speed from Level3...
[32mrouting through Level3 results in 0 Mbit/s[0m

Testing single segment download speed from Telia...
[32mrouting through Telia results in 0 Mbit/s[0m

Routing through Default provided the highest speed of 51.76 Mbit/s
No need to change routes, as the Default was chosen at the beginning of this test.
All done!

I am writing a Python version of this script that automagically grabs the relevant routes but I am not sure where you're finding the test_files. Would be glad to share my script when written, or to swap out your script (which is still run daily on my network) with updated values.

@frankthetank7254
Copy link
Owner

It as unfortunately been broken for a little while, but not for a lack of trying... See https://github.com/feralhosting/feralfilehosting/issues/74
I was going to ask about it in chat again soon, but have yet to do so

@nolanbconaway
Copy link
Author

nolanbconaway commented Nov 24, 2017

I wrote this quick script to accomplish a similar task. Since the test files are not available, the approach is to download a test file via sftp and set the route via the best speed. I don't know if I am computing download speed correctly, I just did file_size_in_mb / download_time_in_seconds. Decent in a pinch!

import sys
import os
import time
from bs4 import BeautifulSoup
import requests
import pysftp

USERNAME    = 'USER'
PASSWORD    = 'PASSWORD'
HOSTNAME    = 'HOST'
REMOTEPATH  = '/path/to/your/file' 
LOCALPATH   = '/download/file/path'

def get_download_speed():
    try:
        con = pysftp.Connection(HOSTNAME, username=USERNAME, password=PASSWORD) 
        size_mb = con.stat(REMOTEPATH).st_size / 1000000.0
        t0 = time.time()
        con.get(REMOTEPATH, localpath=LOCALPATH)
        t1 = time.time()
        os.remove(LOCALPATH)
    except: raise
    finally: con.close()
    return size_mb / (t1-t0)

def make_soup():
    res = requests.get('https://network.feral.io/reroute')
    if res.status_code != 200:
        raise Exception('The Feral reroute tool is unavailable at this time. Fuhgeddaboudit...')
    return BeautifulSoup(res.content, "lxml")

def get_current_route_addr():
    return (
        make_soup()
        .find('ul',{'class':'next_hops'})
        .find('input', {'checked':'checked'})
        ['value']
    )

def set_route(addr):
    res = requests.post('https://network.feral.io/reroute', data=dict(nh=addr))
    if '''<aside class="alert error">''' in res.content:
        raise Exception('A valid next hop was not selected. Fuhgeddaboudit...')
    return res

def get_current_routes():
    reroute_ul = make_soup().find('ul',{'class':'next_hops'})
    route_addrs = map(lambda x: x['value'], reroute_ul.findAll('input'))
    route_names = map(lambda x: x.find('span').previous_element.strip(), reroute_ul.findAll('label'))
    return zip(route_names, route_addrs)

def wait_for_change_to(addr, attempts=5, timeout=0.2):
    for attempt in range(attempts):
        current = get_current_route_addr()
        if current==addr: return None
        time.sleep(timeout)
    s = 'Route did not change after {n} checks. Last route was: {curr} and you asked for {addr}.'
    raise Exception(s.format(n=attempts, curr=current, addr=addr))


best_speed, best_route = -1.0, []
for name, addr in get_current_routes():
    sys.stdout.write('\nTesting download speed from {name} ({addr})'.format(name=name, addr=addr))
    sys.stdout.flush()

    set_route(addr)
    wait_for_change_to(addr)
    mbps = get_download_speed()
    
    sys.stdout.write(' ... {mbps:0.3f} MB/s.'.format(mbps=mbps))
    sys.stdout.flush()

    if mbps > best_speed:
        best_route = (name, addr)
        best_speed = mbps


# set best route
mbps = best_speed
name, addr = best_route
sys.stdout.write(
    '\nThe best speed ({mbps:0.3f} MB/s) was obtained via {name} ({addr}). Setting that route...'
    .format(name=name, addr=addr, mbps=mbps)
)
sys.stdout.flush()

set_route(addr)
wait_for_change_to(addr)
sys.stdout.write('Done!')

@userdocs
Copy link

userdocs commented Feb 10, 2018

You know what? The byte-sized app works for Feral, i tested it to confirm it updates the https://network.feral.io/reroute after running.

https://bytesized-hosting.com/pages/rerouting (i used the x64 binary)

It makes sense it would as they are running from Feral's network so in theory the the result should be the same.

Try it and see for yourself.

@frankthetank7254
Copy link
Owner

i put in a ticket with feral to see if they had any plans to re-enable the old speedtest files, then this will start working again

@userdocs
Copy link

userdocs commented Feb 11, 2018

I think the byte sized app has one file. It changes the route then downloads it, repeating until the test is complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants