check for oserror when binding local ips

This commit is contained in:
Kevin Froman 2019-01-08 01:25:56 -06:00
parent 8c72242eaf
commit 75c8abd9e0
2 changed files with 18 additions and 6 deletions

View File

@ -20,7 +20,7 @@
import flask, cgi
from flask import request, Response, abort, send_from_directory
from gevent.pywsgi import WSGIServer
import sys, random, threading, hmac, hashlib, base64, time, math, os, json
import sys, random, threading, hmac, hashlib, base64, time, math, os, json, socket
import core
from onionrblockapi import Block
import onionrutils, onionrexceptions, onionrcrypto, blockimporter, onionrevents as events, logger, config, onionr
@ -48,8 +48,18 @@ def setBindIP(filePath):
hostOctets = [str(127), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF))]
data = '.'.join(hostOctets)
# Try to bind IP. Some platforms like Mac block non normal 127.x.x.x
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind((data, 0))
except OSError:
logger.warn('Your platform appears to not support random local host addresses 127.x.x.x. Falling back to 127.0.0.1.')
data = '127.0.0.1'
s.close()
with open(filePath, 'w') as bindFile:
bindFile.write(data)
return data
class PublicAPI:

View File

@ -737,7 +737,7 @@ class Block:
return (blocks[-1], blocks)
return blocks[-1]
def exists(hash):
def exists(bHash):
'''
Checks if a block is saved to file or not
@ -751,7 +751,7 @@ class Block:
'''
# no input data? scrap it.
if hash is None:
if bHash is None:
return False
'''
if type(hash) == Block:
@ -759,8 +759,10 @@ class Block:
else:
blockfile = onionrcore.Core().dataDir + 'blocks/%s.dat' % hash
'''
if isinstance(bHash, Block):
bHash = bHash.getHash()
ret = isinstance(onionrstorage.getData(onionrcore.Core(), hash.getHash()), type(None))
ret = isinstance(onionrstorage.getData(onionrcore.Core(), bHash), type(None))
return not ret