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

added comments in app.py #52

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 7 additions & 1 deletion dataserv/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

# Helper functions
def secs_to_mins(seconds):
"""Convert seconds to seconds, minutes, or hours."""
if seconds < 60:
return "{0} second(s)".format(int(seconds))
elif seconds < 3600:
Expand All @@ -29,6 +30,7 @@ def secs_to_mins(seconds):


def online_farmers():
"""Return a list of farmers who have been online in the past ONLINE_TIME minutes."""
# maximum number of minutes since the last check in for
# the farmer to be considered an online farmer
online_time = app.config["ONLINE_TIME"]
Expand Down Expand Up @@ -56,12 +58,14 @@ def index():

@app.route('/api/register/<btc_addr>', methods=["GET"])
def register(btc_addr):
"""Register farmer into the database."""
logger.info("CALLED /api/register/{0}".format(btc_addr))
return register_with_payout(btc_addr, btc_addr)


@app.route('/api/register/<btc_addr>/<payout_addr>', methods=["GET"])
def register_with_payout(btc_addr, payout_addr):
"""Authenticate farmer, add farmer to database, and return response."""
logger.info("CALLED /api/register/{0}/{1}".format(btc_addr, payout_addr))
error_msg = "Registration Failed: {0}"
try:
Expand All @@ -86,6 +90,7 @@ def register_with_payout(btc_addr, payout_addr):

@app.route('/api/ping/<btc_addr>', methods=["GET"])
def ping(btc_addr):
"""Ping the farmer with the specified bitcoin address."""
logger.info("CALLED /api/ping/{0}".format(btc_addr))
error_msg = "Ping Failed: {0}"
try:
Expand Down Expand Up @@ -148,13 +153,14 @@ def online_json():
@app.route('/api/total', methods=["GET"])
@cache.cached(timeout=app.config["CACHING_TIME"], unless=disable_caching)
def total():
"""Return total number of terabytes currently being managed by the node."""
logger.info("CALLED /api/total")

# Add up number of shards
total_shards = sum([farmer.height for farmer in online_farmers()])

# BYTE_SIZE / 1 TB
total_size = (total_shards * (app.config["BYTE_SIZE"] / (1024 ** 4)))
total_size = (total_shards * (app.config["SHARD_BYTE_SIZE"] / (1024 ** 4)))

# Increment by 1 every TOTAL_UPDATE minutes
epoch_mins = (datetime.datetime.utcnow() - datetime.datetime(1970, 1, 1)).\
Expand Down
2 changes: 1 addition & 1 deletion dataserv/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
SQLALCHEMY_DATABASE_URI = "sqlite:///dataserv.db"

DATA_DIR = 'data/'
BYTE_SIZE = 1024*1024*128 # 128 MB FIXME rename, very confusing name
SHARD_BYTE_SIZE = 1024*1024*128 # 128 MB
HEIGHT_LIMIT = 200000 # around 25 TB

ADDRESS = "16ZcxFDdkVJR1P8GMNmWFyhS4EKrRMsWNG" # unique per server address
Expand Down